示例#1
0
文件: Queen.c 项目: clitetailor/Queen
void Queen(int * board, int n)
{
	Stack * StateStack;
	if ( CreateStack(&StateStack, sizeof(State), n * n) == false )
	{
		printf("Loi: Khong du bo nho!\n");
		exit(0);
	}
	
	int i, k;
	
	i = 0;
	k = 0;
	
	State * state;
	
	do
	{
		if (k < n)
		{
			for (i = 0; i < n; ++i)
			{
				state = CreateState(k, i);
				push(StateStack, state);
			}
		}
		
		state = pop(StateStack);
		k = state->k;
		i = state->i;
		board[k] = i;
		
		free(state);
		
		if (k == n - 1)
		{
			do
			{
				if (CheckBoard(board, n) == true)
				{
					Mark(board, n);
				}
				
				state = pop(StateStack);
				k = state->k;
				i = state->i;
				board[k] = i;
				
				free(state);
				
			} while (k == n-1);
		}
		
		++k;
		
	} while (CheckEmpty(StateStack) != true);
	
	DestroyStack(StateStack);
}
示例#2
0
void OrderOfOperations::on_remove_clicked()
{
    if (!CheckEmpty()) return;
    int idx = this->ui->oplist->currentIndex().row();
    this->data.stg2_ops.erase(this->data.stg2_ops.begin() + idx);
    strlist.removeAt(idx);
    model->setStringList(strlist);
}
示例#3
0
文件: dir.c 项目: taysom/tau
static void DeleteChildren (dir_s *dir)
{
	chdir(dir->name);
	while (!CheckEmpty(dir)) {
		rmdir(dir->file[0].name);
		RemoveFile(dir, dir->file[0].name);
	}
	chdir("..");
}
//检查1245
BOOL CStringChecker::CheckDirName( LPCTSTR cStr )
{
// 	BOOL b;
// 	b = CheckEmpty(cStr);
// 	if(!b) return b;
// 	b = CheckWindowsRuler(cStr);
// 	if(!b) return b;
// 	b = CheckSpacePoint(cStr);
// 	if(!b) return b;
// 	b = CheckLength(cStr, 20);
// 	return b;

	//char str[] = "^[a-zA-Z_\\xB0-\\xF7\\xA1-\\xFE][a-zA-Z0-9_\\xB0-\\xF7\\xA1-\\xFE]*$";
	//BOOL b = RegexMatch(cStr, str);

	BOOL b = TRUE;
 	LPCTSTR p = cStr;
 	unsigned char c = *p;
 	//if(c >= '0' && c <= '9') b =FALSE;
 	//else 
 		while(c = *p++)
 	{
 		if((c < '0' || c > '9') && (c < 'a' || c > 'z') && (c < 'A' || c > 'Z') && c != '_' )
 		{
 			if(
				(c >= 0xB0 && c<= 0xF7 && UCHAR(*p) >= 0xA1 && UCHAR(*p) <= 0xFE)
				|| (c == 0xA6 && UCHAR(*p) >= 0xA1 && UCHAR(*p) <= 0xFE)				
				)
			{//属于汉字范围(16-87区)或希腊字母(6区)
 				p++;
 				continue;
 			}
			if (c=='-') // 允许文件夹名称有中画线杠'-'
				continue;
 			b = FALSE;
 			break;
 		}
 	}
 
 	if(CString(cStr).FindOneOf(CStringCheckerConfig::CheckFilter) != -1)
 	{//字符查找
 		b = FALSE;
 	}
 
 	if(!b)
 	{
 		SetLastErr(CStringCheckerConfig::CheckErrorDir);
 		return b; 
 	}
	b = CheckEmpty(cStr);
	if(!b) return b;
	b = CheckLength(cStr, 20);
	return b;
}
示例#5
0
void ReadMixedItem(CCfgCalc*& tReader, const TCHAR* sTitle, bool bCanEmpty,
                   const string& tDefault)
{
    SetItemTitle(sTitle);
    string sValue = g_pTabFile->GetString(g_iLine, sTitle);
    trimend(sValue);
    CheckEmpty(tReader, sValue, bCanEmpty, tDefault);
    if(!sValue.empty())
    {
        SetValue(tReader, sValue, false);
    }
}
示例#6
0
CupcakeWar::CupcakeWar(QWidget* parent)
    : ConfigWindowBase(parent),
      nutritions({"Grape", "Kiwi", "Orange", "Pineapple", "Raspberry", "Straberry"}),
      other_attr_val(4, 0)
{
    add_level();
    for (int i = 0; i < (int)nutritions.size(); ++i) {
        QCheckBox* qcb = new QCheckBox(nutritions[i], this);
        QLineEdit* txt = new QLineEdit(this);
        qcb->move(400, 100 + i * 40);
        txt->move(500, 100 + i * 40);
        selection.push_back(std::make_pair(qcb, txt));
        txt->setValidator(validator);
        connect(qcb, SIGNAL(clicked()), this, SLOT(SetVal()));
        connect(qcb, SIGNAL(clicked()), this, SLOT(CheckEmpty()));
        connect(txt, SIGNAL(editingFinished()), this, SLOT(SetVal()));
        connect(txt, SIGNAL(textEdited(QString)), this, SLOT(CheckEmpty()));
    }

    for(int i = 0; i < 4; ++i) {
        QLineEdit* txt = new QLineEdit(this);
        txt->move(200, 100 + i * 40);
        QLabel *name = new QLabel(i == 0 ? "flour amount"
                                         : i == 1 ? "milk amount"
                                                  : i == 2 ? "max"
                                                           : "min", this);
        name->move(100, 100 + i * 40);
        other_attr.push_back(txt);
        connect(txt, SIGNAL(editingFinished()), this, SLOT(SetVal()));
    }

    grade = new QComboBox(this);
    QLabel *name = new QLabel("grade", this);
    name->move(100, 100 + 4 * 40);
    grade->move(200, 100 + 4 * 40);
    grade->addItems({"3", "4", "5", "6", "7", "8"});

    // connect(list_view, SIGNAL(level_added()), this, SLOT(add_level()));
    // connect(list_view->selectionModel(), SIGNAL(currentChanged(QModelIndex,QModelIndex)), this, SLOT(Update(QModelIndex)));
}
示例#7
0
void ReadItem(string& tReader, const TCHAR* sTitle, bool bCanEmpty,
              const string& tDefault, FIELD_CHECKER_STRING pFunFieldChecker)
{
    SetItemTitle(sTitle);
    string sValue = g_pTabFile->GetString(g_iLine, sTitle);
    size_t l = sValue.size();
    if(l > 1 && sValue[0] == '"' && sValue[l - 1] == '"') sValue = sValue.substr(1, l - 2);
    trimend(sValue);
    CheckEmpty(tReader, sValue, bCanEmpty, tDefault);
    if(!sValue.empty())
    {
        SetValue(tReader, sValue);
    }
    CheckField(tReader, pFunFieldChecker);
}
示例#8
0
void ReadItem(uint32& tReader, const TCHAR* sTitle, bool bCanEmpty,
              uint32 tDefault, FIELD_CHECKER pFunFieldChecker, uint32 fFieldCheckerParam)
{
    SetItemTitle(sTitle);
    string sValue = g_pTabFile->GetString(g_iLine, sTitle);
    CheckEmpty(tReader, sValue, bCanEmpty, tDefault);
    if(!sValue.empty())
    {
        int32 tTempReader;
        SetValue(tTempReader, sValue);
        CheckUIntType(tTempReader);
        tReader = tTempReader;
    }
    CheckField(tReader, pFunFieldChecker, fFieldCheckerParam);
}
示例#9
0
void ReadItem(CCfgCalc*& tReader, const TCHAR* sTitle, bool bCanEmpty,
              float tDefault, FIELD_CHECKER pFunFieldChecker, float fFieldCheckerParam)
{
    SetItemTitle(sTitle);
    string sValue = g_pTabFile->GetString(g_iLine, sTitle);
    trimend(sValue);
    CheckEmpty(tReader, sValue, bCanEmpty, tDefault);
    if(!sValue.empty())
    {
        SetValue(tReader, sValue);
    }
    if(pFunFieldChecker && tReader->IsSingleNumber())
    {
        float fTemp = float(tReader->GetDblValue());
        CheckField(fTemp, pFunFieldChecker, fFieldCheckerParam);
    }
}
int MiniMax(int b[9])							
{														//MINimize MAXimum Loss

	int bestMove[9];						//maximum 9 possible moves				
	int moveVal;
	int bestMoveVal=-10;                
	int index=0;							//for random bestMove(if more than 1 bestMoves exist)
	randomize();							//random number initialising

	for(int p=0;p<9;p++)
	{
		if(CheckEmpty(b,p))
		{
			b[p]=2;

			moveVal=HumanMove(b);
			
			if(moveVal > bestMoveVal)       
			{
				bestMoveVal = moveVal;
				index=0;
				bestMove[index]=p;

			}
			else if(moveVal == bestMoveVal)       
			{
				bestMoveVal = moveVal;
				bestMove[++index]=p;
				
			}

			b[p]=0;
		}

	}

		if(index>0)									//Select a random move 
		{
			index = rand() % index;						
		}

	cout<<"\nI am considering:"<<bestMove[index];
	delay(1000);
	return bestMove[index];
}
//AI move    MAX      X=2
int AiMove(int b[9])										//returns MAXIMUM of scores for a move
{
	int bestValue=(-100);        			
	int stateValue=CheckStatus(b);

	
	if(stateValue!=20)         					 
	{
		if(stateValue==1)
		{stateValue=(10);}
		else if(stateValue==(-1))
		{stateValue=(-10);}

		return stateValue;
	}
	

	for(int j=0;j<9;j++)
	{
		if(CheckEmpty(b,j))
		{
			b[j]=2;
			
			int val=HumanMove(b);
			
			if (val >= bestValue)  		
			{
				bestValue = val;
			}

			b[j]=0;
			
			
		}
	}

	return bestValue;
}
//Human move     MIN    O=1
int HumanMove(int b[9])									//returns MINIMUM of the scores for a move 
{
	int bestValue=100;                        
	int stateValue=CheckStatus(b);

	
	if(stateValue!=20)       			 		
	{
		if(stateValue==1)
		{stateValue=(10);}
		else if(stateValue==(-1))
		{stateValue=(-10);}

		return stateValue;
	}
	

	for(int k=0;k<9;k++)
	{
		if(CheckEmpty(b,k))
		{
			b[k]=1;
			//delay(500);
			int val=AiMove(b);

			if (val <= bestValue)  				
			{
				bestValue = val;
			}

			b[k]=0;
		}
	}

	return bestValue;
}
示例#13
0
void Margolus::Calculation(cuint& dx, cuint& dy, cuint& dz) {
//#pragma omp parallel for
    for (uint ix = dx; ix < GetSizeX() - 1; ix += 2) {
        for (uint iy = dy; iy < GetSizeY() - 1; iy += 2) {
            for (uint iz = dz; iz < GetSizeZ() - 1; iz += 2) {
                if (CheckEmpty(ix, iy, iz)) {
                    continue;
                }
                blockSize3D = 1;
                CreateRotateNotBlock3D(blocks3D[0], ix, iy, iz);
                if (modifierMove && CheckMod(ix, iy, iz)) {
                    if (CheckActive (ix, iy)) {
                        if (CheckCanRotate3D(ClockWiceX, ix, iy, iz)) {
                            CreateRotateBlock3D(blocks3D[blockSize3D], ClockWiceX, ix, iy, iz, false, true);
                            ++blockSize3D;
                            CreateRotateBlock3D(blocks3D[blockSize3D], ClockWiceX, ix, iy, iz, true, true);
                            ++blockSize3D;
                            CreateRotateBlock3D(blocks3D[blockSize3D], ClockWiceX, ix, iy, iz);
                            ++blockSize3D;
                        }
                        if (CheckCanRotate3D(CounterClockWiceX, ix, iy, iz)) {
                            CreateRotateBlock3D(blocks3D[blockSize3D], CounterClockWiceX, ix, iy, iz, false, true);
                            ++blockSize3D;
                            CreateRotateBlock3D(blocks3D[blockSize3D], CounterClockWiceX, ix, iy, iz, true, true);
                            ++blockSize3D;
                            CreateRotateBlock3D(blocks3D[blockSize3D], CounterClockWiceX, ix, iy, iz);
                            ++blockSize3D;
                        }
                        if (CheckCanRotate3D(ClockWiceY, ix, iy, iz)) {
                            CreateRotateBlock3D(blocks3D[blockSize3D], ClockWiceY, ix, iy, iz, false, true);
                            ++blockSize3D;
                            CreateRotateBlock3D(blocks3D[blockSize3D], ClockWiceY, ix, iy, iz, true, true);
                            ++blockSize3D;
                            CreateRotateBlock3D(blocks3D[blockSize3D], ClockWiceY, ix, iy, iz);
                            ++blockSize3D;
                        }
                        if (CheckCanRotate3D(CounterClockWiceY, ix, iy, iz)) {
                            CreateRotateBlock3D(blocks3D[blockSize3D], CounterClockWiceY, ix, iy, iz, false, true);
                            ++blockSize3D;
                            CreateRotateBlock3D(blocks3D[blockSize3D], CounterClockWiceY, ix, iy, iz, true, true);
                            ++blockSize3D;
                            CreateRotateBlock3D(blocks3D[blockSize3D], CounterClockWiceY, ix, iy, iz);
                            ++blockSize3D;
                        }
                        if (CheckCanRotate3D(ClockWiceZ, ix, iy, iz)) {
                            CreateRotateBlock3D(blocks3D[blockSize3D], ClockWiceZ, ix, iy, iz, false, true);
                            ++blockSize3D;
                            CreateRotateBlock3D(blocks3D[blockSize3D], ClockWiceZ, ix, iy, iz, true, true);
                            ++blockSize3D;
                            CreateRotateBlock3D(blocks3D[blockSize3D], ClockWiceZ, ix, iy, iz);
                            ++blockSize3D;
                        }
                        if (CheckCanRotate3D(CounterClockWiceZ, ix, iy, iz)) {
                            CreateRotateBlock3D(blocks3D[blockSize3D], CounterClockWiceZ, ix, iy, iz, false, true);
                            ++blockSize3D;
                            CreateRotateBlock3D(blocks3D[blockSize3D], CounterClockWiceZ, ix, iy, iz, true, true);
                            ++blockSize3D;
                            CreateRotateBlock3D(blocks3D[blockSize3D], CounterClockWiceZ, ix, iy, iz);
                            ++blockSize3D;
                        }
                    } else {
                        CreateRotateBlock3D(blocks3D[blockSize3D], ClockWiceX, ix, iy, iz, false, true);
                        ++blockSize3D;
                        CreateRotateBlock3D(blocks3D[blockSize3D], CounterClockWiceX, ix, iy, iz, false, true);
                        ++blockSize3D;
                        CreateRotateBlock3D(blocks3D[blockSize3D], ClockWiceY, ix, iy, iz, false, true);
                        ++blockSize3D;
                        CreateRotateBlock3D(blocks3D[blockSize3D], CounterClockWiceY, ix, iy, iz, false, true);
                        ++blockSize3D;
                        CreateRotateBlock3D(blocks3D[blockSize3D], ClockWiceZ, ix, iy, iz, false, true);
                        ++blockSize3D;
                        CreateRotateBlock3D(blocks3D[blockSize3D], CounterClockWiceZ, ix, iy, iz, false, true);
                        ++blockSize3D;
                    }
                } else {
                    if (CheckCanRotate3D(ClockWiceX, ix, iy, iz)) {
                        CreateRotateBlock3D(blocks3D[blockSize3D], ClockWiceX, ix, iy, iz);
                        ++blockSize3D;
                    }
                    if (CheckCanRotate3D(CounterClockWiceX, ix, iy, iz)) {
                        CreateRotateBlock3D(blocks3D[blockSize3D], CounterClockWiceX, ix, iy, iz);
                        ++blockSize3D;
                    }
                    if (CheckCanRotate3D(ClockWiceY, ix, iy, iz)) {
                        CreateRotateBlock3D(blocks3D[blockSize3D], ClockWiceY, ix, iy, iz);
                        ++blockSize3D;
                    }
                    if (CheckCanRotate3D(CounterClockWiceY, ix, iy, iz)) {
                        CreateRotateBlock3D(blocks3D[blockSize3D], CounterClockWiceY, ix, iy, iz);
                        ++blockSize3D;
                    }
                    if (CheckCanRotate3D(ClockWiceZ, ix, iy, iz)) {
                        CreateRotateBlock3D(blocks3D[blockSize3D], ClockWiceZ, ix, iy, iz);
                        ++blockSize3D;
                    }
                    if (CheckCanRotate3D(CounterClockWiceZ, ix, iy, iz)) {
                        CreateRotateBlock3D(blocks3D[blockSize3D], CounterClockWiceZ, ix, iy, iz);
                        ++blockSize3D;
                    }
                }
                double Z = 0.0;
                // + Energy
                for (uint i = 0; i < blockSize3D; ++i) {
                    double energy = CalculationBlockEnergy(blocks3D[i], ix, iy, iz); //кДж/моль
                    blocks3D[i].energy = exp(-energy / (R * *T));
                    Z += blocks3D[i].energy;
                }
                //normalization
                double sumProbability = 0.0;
                double rnd = (double)(rand()) / RAND_MAX;
                for (uint i = 0; i < blockSize3D; ++i) {
                    sumProbability += blocks3D[i].energy / Z;
                    if (rnd <= sumProbability) {
                        ChangeBlock(blocks3D[i], ix, iy, iz);
                        break;
                    }
                }
            }
        }
    }
}
示例#14
0
//-----------------------------------------------------------------------------
// Command_Decode
//-----------------------------------------------------------------------------
//
// Return Value : Error code
// Parameters   : Pointer to input string
//
// Parses the command string and calls the appropriate functions.
//
//-----------------------------------------------------------------------------
uint8_t CommandDecode(char * instr)
{
	char * cp;						// character pointer
	const DEVICE_FAMILY *dfptr;		// pointer to current device family
	const DERIVATIVE_ENTRY *deptr;	// pointer to current derivative
	uint8_t command_number = 99;	// number of command encoded in 'instr'
	uint8_t result = INVALID_COMMAND;

	printf("Command: %s\n", instr);
	command_number = 0xFF;
	if (instr[0] >= '0' && instr[0] <= '9')
	{
		// if first char is a digit, then interpret it as a command number
		command_number = atoi (instr);
	}

	{
		// interpret command as a string and find command number
		// or find command by command_number
		const COMMAND *ctptr = Commands;
		while (ctptr->name != NULL)
		{
			if (command_number != 0xFF)
			{
				if (ctptr->number == command_number)
					break;
			}
			else if (strncmp (instr, ctptr->name, ctptr->name_size) == 0)
			{	// we've found the command, so record its number and exit
				command_number = ctptr->number;
				break;
			}
			ctptr++;
		}
		if (ctptr->name != NULL)
		{
			if (ctptr->need_discover && !FamilyFound)
			{
				result = DEVICE_UNDISCOVERED;
				command_number = 0xFE;	// Unknown command
			}
		}
		else
			command_number = 0xFF;	// Unknown command
	}

	// Now we have a command number, so act on it.
	switch (command_number)
	{
		case 0:	// Device Autodetect
		{
			uint8_t deviceId = 0xFF;		// initialize device and derivative
			uint8_t revisionId = 0xFF;
			uint8_t derivativeId = 0xFF;	// id's to invalid selections

			printf("Device Autodetect\n");
			Start_Stopwatch();
			if (NO_ERROR == (result = C2_Halt ())
			&&	NO_ERROR == (result = C2_Discover (&deviceId, &revisionId, &derivativeId))
				)
			{
				CommandsList = KnownFamilies[FamilyNumber].InitStrings;
			}
			Stop_Stopwatch();
			printf("Device ID     : %02X\n", deviceId);
			printf("Revision ID   : %02X\n", revisionId);
			printf("Derivative ID : %02X\n", derivativeId);
			break;
		}
		case 1:	// Print Menu
		{
			printf("? stub\n");
			Start_Stopwatch();
			Display_Menu();
			Stop_Stopwatch();
			result = NO_ERROR;
			break;
		}
		case 2:	// Wait ms
		{
			uint16_t wait_time;
			cp = GetNextWord(instr);
			if (NO_ERROR == (result = CheckEmpty(cp)))
			{
				wait_time = atoi (cp);
				printf("Waiting %d ms\n", wait_time);
				Start_Stopwatch();
				Wait_ms (wait_time);
				Stop_Stopwatch();
				printf("Stopwatch_ms is %u\n", Stopwatch_ms);
				result = NO_ERROR;
			}
			break;
		}
		case 3:	// Wait us
		{
			uint16_t wait_time;
			cp = GetNextWord(instr);
			if (NO_ERROR == (result = CheckEmpty(cp)))
			{
				wait_time = atoi (cp);

				printf("Waiting %d us\n", wait_time);
				Start_Stopwatch();
				Wait_us (wait_time);
				Stop_Stopwatch();
				printf("Stopwatch_us is %u\n", Stopwatch_us);

				result = NO_ERROR;
			}
			break;
		}
		case 4:	// Start Stopwatch
		{
			printf("Start Stopwatch\n");
			result = Start_Stopwatch();
			break;
		}
		case 5:	// Stop Stopwatch
		{
			printf("Stop Stopwatch\n");
			result = Stop_Stopwatch();
			printf("Stopwatch_ms is %u\n", Stopwatch_ms);
			printf("Stopwatch_us is %u\n", Stopwatch_us);
			break;
		}
		case 6:	// Set Timeout ms
		{
			uint16_t wait_time;
			printf("Set Timeout ms:\n");
			cp = GetNextWord(instr);
			if (NO_ERROR == (result = CheckEmpty(cp)))
			{
				wait_time = atoi (cp);

				printf("Timing out for %d ms\n", wait_time);
				Start_Stopwatch();
				SetTimeout_ms (wait_time);
				SetTimeout_us (1);
				while (!IsDoneTimeout_ms())
					;
				Stop_Stopwatch();
				printf("Stopwatch_ms is %u\n", Stopwatch_ms);
				result = NO_ERROR;
			}
			break;
		}
		case 7:	// Set Timeout us
		{
			uint16_t wait_time;
			printf("Set Timeout us\n");
			cp = GetNextWord(instr);
			if (NO_ERROR == (result = CheckEmpty(cp)))
			{
				wait_time = atoi(cp);

				printf("Timing out for %d us\n", wait_time);
				Start_Stopwatch();
				SetTimeout_us(wait_time);
				while (!IsDoneTimeout_us())
					;
				Stop_Stopwatch();
				printf("Stopwatch_us is %u\n", Stopwatch_us);

				result = NO_ERROR;
			}
			break;
		}
		case 8:		// Pin init
		{
			printf("Pin Init\n");
			result = Pin_Init();
			break;
		}
		case 9:		// C2 Reset
		{
			printf("C2 Reset\n");
			result = C2_Reset();
			break;
		}
		case 10:	// C2 Write Address
		{
			uint16_t addr;
			cp = GetNextWord(instr);
			if (NO_ERROR == (result = CheckEmpty(cp)))
			{
				addr = atox (cp);

				printf("C2 Write Address: %02X\n", addr);
				Start_Stopwatch();
				result = C2_WriteAR(addr);
				Stop_Stopwatch();
			}
			break;
		}
		case 11:	// C2 Read Address
		{
			Start_Stopwatch();
			result = C2_ReadAR();
			Stop_Stopwatch();
			printf("C2 Read Address: %02X\n", (uint16_t) C2_AR);
			break;
		}
		case 12:	// C2 Write Data
		{
			uint8_t data;
			cp = GetNextWord(instr);
			if (NO_ERROR == (result = CheckEmpty(cp)))
			{
				data = atox (cp);

				printf("C2 Write Data: %02X\n", (uint16_t) data);
				Start_Stopwatch ();
				result = C2_WriteDR (data, C2_WRITE_DR_TIMEOUT_US);
				Stop_Stopwatch ();
			}
			break;
		}
		case 13:	// C2 Read Data
		{
			Start_Stopwatch ();
			result = C2_ReadDR (C2_READ_DR_TIMEOUT_US);
			Stop_Stopwatch ();
			printf("C2 Read Data: %02X\n", (uint16_t) C2_DR);
			break;
		}
		case 14:	// C2 Reset and Halt
		{
			printf("C2 Reset and Halt\n");
			result = C2_Halt ();
			break;
		}
		case 15:	// C2 Get Device ID
		{
			uint8_t devId;

			printf("C2 Get Device ID\n");
			Start_Stopwatch ();
			result = C2_GetDevID (&devId);
			Stop_Stopwatch ();
			printf("Device ID is %u, 0x%04X\n", devId, devId);
			break;
		}
		case 16:	// C2 Get Revision ID
		{
			uint8_t revid;
			printf("C2 Get Revision ID\n");
			Start_Stopwatch ();
			result = C2_GetRevID (&revid);
			Stop_Stopwatch ();
			printf("Revision ID is %u, 0x%04X\n", revid, revid);
			break;
		}
		case 17:	// C2 Read SFR
		{
			uint8_t sfr_value, sfr_address;
			cp = GetNextWord(instr);
			if (NO_ERROR == (result = CheckEmpty(cp)))
			{
				sfr_address = atox (cp);

				Start_Stopwatch ();
				result = C2_ReadSFR (sfr_address, &sfr_value);
				Stop_Stopwatch ();
				printf("C2 Read SFR(%02X) %02X\n", (uint16_t) sfr_address, (uint16_t) sfr_value);
			}
			break;
		}
		case 18:	// C2 Write SFR
		{
			uint8_t sfr_address, sfr_value;

			cp = GetNextWord(instr);
			if (NO_ERROR == (result = CheckEmpty(cp)))
			{
				sfr_address = atox (cp);
				cp = GetNextWord(cp);
				if (NO_ERROR == (result = CheckEmpty(cp)))
				{
					sfr_value = atox (cp);

					printf("C2 Write %02X to SFR(%02X)\n", (uint16_t) sfr_value, (uint16_t) sfr_address);
					Start_Stopwatch ();
					result = C2_WriteSFR (sfr_address, sfr_value);
					Stop_Stopwatch ();
				}
			}
			break;
		}
		case 19:	// C2 Read Direct
		{
			uint8_t sfr_value, sfr_address;
			cp = GetNextWord(instr);
			if (NO_ERROR == (result = CheckEmpty(cp)))
			{
				sfr_address = atox (cp);

				Start_Stopwatch ();
				result = C2_ReadDirect (sfr_address, &sfr_value, C2_DIRECT);
				Stop_Stopwatch ();
				printf("C2 Read Direct(%02X) %02X\n", (uint16_t) sfr_address, (uint16_t) sfr_value);
			}
			break;
		}
		case 20:	// C2 Write Direct <address> <value>
		{
			uint8_t sfr_address, sfr_value;

			cp = GetNextWord(instr);
			if (NO_ERROR == (result = CheckEmpty(cp)))
			{
				sfr_address = atox (cp);
				cp = GetNextWord(cp);
				if (NO_ERROR == (result = CheckEmpty(cp)))
				{
					sfr_value = atox (cp);

					printf("C2 Write %02x to Direct(%02X)\n", (uint16_t) sfr_value, (uint16_t) sfr_address);
					Start_Stopwatch ();
					result = C2_WriteDirect (sfr_address, sfr_value, C2_DIRECT);
					Stop_Stopwatch ();
				}
			}
			break;
		}
		case 21:	// C2 Read Indirect
		{
			uint8_t sfr_value, sfr_address;
			
			cp = GetNextWord(instr);
			if (NO_ERROR == (result = CheckEmpty(cp)))
			{
				sfr_address = atox (cp);

				Start_Stopwatch ();
				result = C2_ReadDirect (sfr_address, &sfr_value, C2_INDIRECT);
				Stop_Stopwatch ();
				printf("C2 Read Indirect(%02X) %02X\n", (uint16_t) sfr_address, (uint16_t) sfr_value);
			}
			break;
		}
		case 22:	// C2 Write Indirect
		{
			uint8_t sfr_address;
			uint8_t sfr_value;

			cp = GetNextWord(instr);
			if (NO_ERROR == (result = CheckEmpty(cp)))
			{
				sfr_address = atox (cp);
				cp = GetNextWord(cp);
				if (NO_ERROR == (result = CheckEmpty(cp)))
				{
					sfr_value = atox (cp);

					printf("C2 Write %02x to Indirect(%02X)\n", (uint16_t) sfr_value, (uint16_t) sfr_address);
					Start_Stopwatch ();
					result = C2_WriteDirect (sfr_address, sfr_value, C2_INDIRECT);
					Stop_Stopwatch ();
				}
			}
			break;
		}
		case 23:	// C2 Discover
		{
			uint8_t j, deviceId, revisionId, derivativeId;

			printf("C2 Discover\n");
			Start_Stopwatch ();
			result = C2_Discover (&deviceId, &revisionId, &derivativeId);
			Stop_Stopwatch ();

			if (result != NO_ERROR)
				break;

			dfptr = &(KnownFamilies[FamilyNumber]);
			deptr = &(KnownFamilies[FamilyNumber].DerivativeList[DerivativeNumber]);

			printf("Family Information:\n");
			printf("Device ID: 0x%04X\n", dfptr->DEVICE_ID);
			printf("Family string: %s\n", dfptr->FAMILY_STRING);
			printf("Mem Type: %u\n", (uint16_t) dfptr->MEM_TYPE);
			printf("Page Size: %u\n", dfptr->PAGE_SIZE);
			printf("Has SFLE: %u\n", (uint16_t) dfptr->HAS_SFLE);
			printf("Security Type: %u\n", (uint16_t) dfptr->SECURITY_TYPE);
			printf("FPDAT address: 0x%02X\n", (uint16_t) dfptr->FPDAT);
			printf("Device ID: 0x%04X\n", dfptr->DEVICE_ID);
			printf("Init strings:\n");
			for (j = 0; ; j++)
			{
				if (dfptr->InitStrings[j] == NULL)
					break;
				printf("%s\n", dfptr->InitStrings[j]);
			}
			printf("\n");
			printf("Derivative Information\n");
			printf("----------------------\n");
			printf("Derivative ID        : %02X\n", deptr->DERIVATIVE_ID);
			printf("Derivative String    : %s\n", deptr->DERIVATIVE_STRING);
			printf("Features String      : %s\n", deptr->FEATURES_STRING);
			printf("Package String       : %s \n", deptr->PACKAGE_STRING);
			printf("Code Start Address   : %05X\n", deptr->CODE_START);
			printf("Code Size            : %05X\n", deptr->CODE_SIZE);
			printf("Write Lock Byte Addr : %05X\n", deptr->WRITELOCKBYTEADDR);
			printf("Read Lock Byte Addr  : %05X\n", deptr->READLOCKBYTEADDR);
			printf("Code 2 Start Address : %05X\n", deptr->CODE2_START);
			printf("Code 2 Size          : %05X\n", deptr->CODE2_SIZE);
			printf("\n");

			break;
		}
		case 24:	// Run Init String
		{
			result = NO_ERROR;
			printf("Execute Device Init String:\n");
			if (FamilyFound == true)
				CommandsList = KnownFamilies[FamilyNumber].InitStrings;
			else
				printf("Device not connected.\n");
			break;
		}
		case 25:	// C2 Flash Read <start addr> <length>
		{
			uint32_t addr;
			uint16_t length;

			printf("C2 Flash Read\n");
			cp = GetNextWord(instr);
			if (NO_ERROR == (result = CheckEmpty(cp)))
			{
				addr = atolx (cp);
				cp = GetNextWord(cp);
				if (NO_ERROR == (result = CheckEmpty(cp)))
				{
					length = atoi (cp);
					if (length > sizeof (BinDest))
						length = sizeof (BinDest);

					printf(
						"Reading %u bytes starting at address 0x%05lX\n",
						length,
						(unsigned long)addr
					);
					Start_Stopwatch ();
					result = C2_FLASH_Read (BinDest, addr, length);
					Stop_Stopwatch ();

					BIN2HEXSTR (HexDest, BinDest, length);
					printf("Memory contents are %s\n", HexDest);
				}
			}
			break;
		}
		case 26:	// C2 OTP Read <start addr> <length>
		{
			uint32_t addr;
			uint16_t length;

			printf("C2 OTP Read\n");
			cp = GetNextWord(instr);
			if (NO_ERROR == (result = CheckEmpty(cp)))
			{
				addr = atolx (cp);
				cp = GetNextWord(cp);
				if (NO_ERROR == (result = CheckEmpty(cp)))
				{
					length = atoi (cp);

					if (length > sizeof (BinDest))
						length = sizeof (BinDest);

					printf("Reading %u bytes starting at address 0x%05lX\n",
						length,
						(unsigned long)addr
					);
					Start_Stopwatch ();
					result = C2_OTP_Read (BinDest, addr, length);
					Stop_Stopwatch ();

					BIN2HEXSTR (HexDest, BinDest, length);
					printf("Memory contents are %s\n", HexDest);
				}
			}
			break;
		}
		case 27:	// C2 Flash Write <start addr> <hex string>
		{
			uint32_t addr;
			uint8_t length;

			printf("C2 Flash Write\n");
			cp = GetNextWord(instr);
			if (NO_ERROR == (result = CheckEmpty(cp)))
			{
				addr = atolx (cp);
				cp = GetNextWord(cp);
				if (NO_ERROR == (result = CheckEmpty(cp)))
				{
					// warning! 'dest' could be overtaken by a long string
					if (NO_ERROR == (result = HEXSTR2BIN (BinDest, cp, &length, sizeof(BinDest))))
					{
						printf("Writing %u bytes starting at address 0x%05X\n", length, addr);
						// printf("Writing the following string: %s\n", cp);
						Start_Stopwatch ();
						result = C2_FLASH_Write (addr, BinDest, length);
						Stop_Stopwatch ();
					}
				}
			}
			break;
		}
		case 28:	// C2 OTP Write <start addr> <hex string>
		{
			uint32_t addr;
			uint8_t length;

			printf("C2 OTP Write\n");
			cp = GetNextWord(instr);
			if (NO_ERROR == (result = CheckEmpty(cp)))
			{
				addr = atolx (cp);
				cp = GetNextWord(cp);
				if (NO_ERROR == (result = CheckEmpty(cp)))
				{

					if (NO_ERROR != (result = HEXSTR2BIN (BinDest, cp, &length, sizeof(BinDest))))
					{
						printf("Hex string too long");
						break;
					}

					printf(
						"Writing %u bytes starting at address 0x%05lX\n",
						(uint16_t) length,
						(unsigned long)addr
					);
					printf("Writing the following string: %s\n", cp);
					Start_Stopwatch ();
					result = C2_OTP_Write (addr, BinDest, length);
					Stop_Stopwatch ();
				}
			}
			break;
		}
		case 29:	// C2 Page Erase <address in page to erase>
		{
			uint32_t addr;

			printf("C2 Flash Page Erase\n");
			cp = GetNextWord(instr);
			if (NO_ERROR == (result = CheckEmpty(cp)))
			{
				addr = atolx (cp);

				printf("Erasing page containing address 0x%05X\n", addr);
				Start_Stopwatch ();
				result = C2_FLASH_PageErase (addr);
				Stop_Stopwatch ();
			}
			break;
		}
		case 30:	// C2 Device Erase
		{
			printf("C2 Flash Device Erase\n");

			printf("Erasing device...\n");
			Start_Stopwatch ();
			result = C2_FLASH_DeviceErase ();
			Stop_Stopwatch ();

			break;
		}
		case 31:	// C2 Flash Blank Check
		{
			uint32_t addr;
			uint32_t length;

			printf("C2 Flash Blank Check\n");

			addr = KnownFamilies[FamilyNumber].DerivativeList[DerivativeNumber].CODE_START;
			length = KnownFamilies[FamilyNumber].DerivativeList[DerivativeNumber].CODE_SIZE;

			printf("Checking starting at address 0x%05X for 0x%05X bytes: ", addr, length);
			Start_Stopwatch ();
			result = C2_FLASH_BlankCheck (addr, length);
			Stop_Stopwatch ();

			printf((result == DEVICE_IS_BLANK) ? "OK\n" : "Fail\n");
			break;
		}
		case 32:	// C2 OTP Blank Check
		{
			uint32_t addr;
			uint32_t length;

			printf("C2 OTP Blank Check\n");

			addr = KnownFamilies[FamilyNumber].DerivativeList[DerivativeNumber].CODE_START;
			length = KnownFamilies[FamilyNumber].DerivativeList[DerivativeNumber].CODE_SIZE;

			printf("Checking starting at address 0x%05X for 0x%05X bytes: ", addr, length);

			Start_Stopwatch ();
			result = C2_OTP_BlankCheck (addr, length);
			Stop_Stopwatch ();

			printf((result == NO_ERROR) ? "OK\n" : "Fail\n");
			break;
		}
		case 33:	// C2 Get Lock Byte value
		{
			printf("C2 Get Lock Byte\n");
			break;
		}
		case 34:	// Write Target to HEX
		{
			printf("Write Target to HEX:\n");
			Start_Stopwatch ();
			result = OP_Write_TARGET2HEX();
			Stop_Stopwatch ();

			break;
		}
		case 36:	// Write HEX to Target
		{
			HEX_RECORD hex;

			printf("Write HEX to Target:\n");

			cp = GetNextWord(instr);
			if (NO_ERROR == (result = CheckEmpty(cp)))
			{
				hex.Buf = BinDest;
				result = HEX_Decode(&hex, cp, sizeof(BinDest));
				if (result == NO_ERROR && hex.RECLEN != 0)
				{
					printf("Writing %u bytes starting at address 0x%05X\n", hex.RECLEN, hex.OFFSET.U16);
					Start_Stopwatch ();
					result = C2_FLASH_Write (hex.OFFSET.U16, hex.Buf, hex.RECLEN);
					Stop_Stopwatch ();
				}
				else if (result == EOF_HEX_RECORD)
					result = NO_ERROR;
			}
			break;
		}
		case 35:	// Read SFRs and directs
		{
			uint8_t row;
			uint8_t col;
			uint8_t value;

			Start_Stopwatch ();
			for (row = 0xF8; row != 0x00; row = row - 8)
			{
				for (col = 0; col != 0x08; col++)
				{
					if (NO_ERROR != (result = C2_ReadDirect ((row+col), &value, C2_DIRECT)))
						break;

					if (col == 0)
						printf("\n0X%02X: %02X", (uint16_t) (row), (uint16_t) value);
					else
						printf(" %02X", (uint16_t) value);
				}
			}
			printf("\n\n");
			Stop_Stopwatch ();
			break;
		}
		case 0xFE:
			break;
		default:
		{
			result = INVALID_COMMAND;
		}
	}
	printf("Result: %02X %s\n", result, GetErrorName(result));
	return result;
}
BOOL CStringChecker::CheckParamName( LPCTSTR cStr )
{
	{
		CString sCheckString(cStr);
		if (sCheckString.Find("双击添加参数") != -1)
		{
			SetLastErr(CStringCheckerConfig::CheckErrorParamCustom);
			return FALSE;
		}
	}

	BOOL b = TRUE;
	LPCTSTR p = cStr;
	int nlenth =0;
	unsigned char c = *p;

	nlenth = strlen(cStr);
	if (cStr[0]==0x20||cStr[nlenth-1]==0x20)
	{
		SetLastErr(CStringCheckerConfig::CheckErrorParam);
		return FALSE;
	}
		
	{
		char str[] = "^\\d+$";
		CString strTemp(cStr);
		//空格,点和斜杠不能和纯数字一起用
		strTemp.Replace(' ', '1');
		strTemp.Replace('.', '1');
		strTemp.Replace('\\', '1');
		//strTemp.Replace('-', '1');
		b = !RegexMatch(strTemp, str);
	}
	if(!b)
	{

	}
	else while(c = *p++)
	{
		 
		if((c < '0' || c > '9') && (c < 'a' || c > 'z') && (c < 'A' || c > 'Z') && \
			(c != '_')&& (c!='\\') && (c!='.') &&(c!=' ') &&(c!='-') )//允许参数名含有减号、.和\。
		{
			if(
				(c >= 0xB0 && c<= 0xF7 && UCHAR(*p) >= 0xA1 && UCHAR(*p) <= 0xFE)
				|| (c == 0xA6 && UCHAR(*p) >= 0xA1 && UCHAR(*p) <= 0xFE))
			{//属于汉字范围(16-87区)或希腊字母(6区)
				p++;
				continue;
			}

			b = FALSE;
			break;
		}
	}

	if(!b)
	{
		SetLastErr(CStringCheckerConfig::CheckErrorParam);
		return b; 
	}
	b = CheckEmpty(cStr);
	if(!b) return b;
	b = CheckLength(cStr, 50);
	return b;
}
//检查12345
BOOL CStringChecker::CheckNodeName( LPCTSTR cStr )
{
// 	BOOL b;
// 	b = CheckEmpty(cStr);
// 	if(!b) return b;
// 	b = CheckWindowsRuler(cStr);
// 	if(!b) return b;
// 	b = CheckSpacePoint(cStr);
// 	if(!b) return b;
// 	b = CheckFirstNumber(cStr);
// 	if(!b) return b;
// 	b = CheckLength(cStr, 50);
// 	return b;

	//char str[] = "^[a-zA-Z_\\xB0-\\xF7\\xA1-\\xFE][a-zA-Z0-9_\\xB0-\\xF7\\xA1-\\xFE]*$";
	//BOOL b = RegexMatch(cStr, str);

	BOOL b = TRUE;
	LPCTSTR p = cStr;
	unsigned char c = *p;
	//if(c >= '0' && c <= '9') b =FALSE;
	//if(CheckIntNumber(cStr))b = FALSE;
	{
		char str[] = "^\\d+$";
		CString strTemp(cStr);
		//strTemp.Replace('-', '1');
		b = !RegexMatch(strTemp, str);
	}
	if(!b )
	{

	}
	else while(c = *p++)
	{
		if((c < '0' || c > '9') && (c < 'a' || c > 'z') && (c < 'A' || c > 'Z') && c != '_'  && c != '-') //允许参数名含有减号
		//if((c < '0' || c > '9') && (c < 'a' || c > 'z') && (c < 'A' || c > 'Z') && c != '_' )
		{
			if(
				(c >= 0xB0 && c<= 0xF7 && UCHAR(*p) >= 0xA1 && UCHAR(*p) <= 0xFE)
				|| (c == 0xA6 && UCHAR(*p) >= 0xA1 && UCHAR(*p) <= 0xFE)
				)
			{//属于汉字范围(16-87区)或希腊字母(6区)
				p++;
				continue;
			}
			b = FALSE;
			break;
		}
	}

	if(CString(cStr).FindOneOf(CStringCheckerConfig::CheckFilter) != -1)
	{//字符查找
		b = FALSE;
	}

	if(!b)
	{
		SetLastErr(CStringCheckerConfig::CheckErrorNode);
		return b; 
	}
	b = CheckEmpty(cStr);
	if(!b) return b;
	b = CheckLength(cStr, 50);
	return b;
}