int CmdProcessing(void) { _fputts(_T("Best command prompt>> "), stdout); _getts(cmdString); TCHAR * token = _tcstok(cmdString, seps); int tokenNum = 0; while (token != NULL) { _tcscpy( cmdTokenList[tokenNum++], StrLower(token) ); token = _tcstok(NULL, seps); } if (!_tcscmp(cmdTokenList[0], _T("exit"))) { return TRUE; } else if (!_tcscmp(cmdTokenList[0], _T("추가 되는 명령어 1"))) { } else if (!_tcscmp(cmdTokenList[0], _T("추가 되는 명령어 2"))) { } else { _tprintf(ERROR_CMD, cmdTokenList[0]); } return 0; }
int _tmain(int argc, TCHAR** argv) { // 数独のゲーム盤を生成 SuDokuGame sudoku; std::stack<SuDokuGame> games; dispGame(sudoku); // ゲーム版にコマンドを入力 while (1) { _tprintf(_T("#")); TCHAR buf[80]; _getts(buf); _tstring t = buf; if (t == _T("q")) break; if (t == _T("p")) { sudoku.ReparseAll(); dispGame(sudoku); break; } if (t == _T(".")) { sudoku = games.top(); games.pop(); continue; } if (t.size() != 3) continue; int row = t[0] - '0'; int col = t[1] - '0'; int val = t[2] - '0'; games.push(sudoku); // 今の状態を記録して次に進める sudoku.FixCell(row - 1, col - 1, val); dispGame(sudoku); } return 0; }
int _tmain(int argc, TCHAR** argv) { if(argc==1) { _tprintf(_T("\nDo you want to run tests from a folder containing Chinese characters to test UNICODE compatibility (y/n)?\n")); _tprintf(_T("Your choice > ")); TCHAR szAnswer[1024]=_T(""); #if _MSC_VER>=1400 _getts_s(szAnswer, 1024); #else _getts(szAnswer); #endif if(_tcscmp(szAnswer, _T("y"))==0 || _tcscmp(szAnswer, _T("Y"))==0) { // Relaunch this process from another working directory containing UNICODE symbols in path. // This is needed to test all functionality on UNICODE compatibility. g_bRunningFromUNICODEFolder = TRUE; } if(g_bRunningFromUNICODEFolder) { _tprintf(_T("Launching tests in another process:\n")); if(g_bRunningFromUNICODEFolder) _tprintf(_T(" - with working directory having UNICODE symbols in path\n")); return fork(); } } else { int argnum; for(argnum=1; argnum<argc; argnum++) { TCHAR* szArg = argv[argnum]; if(_tcscmp(szArg, _T("/unicode"))==0) g_bRunningFromUNICODEFolder = TRUE; } } printf("\n=== Automated tests for CrashRpt v.%d.%d.%d ===\n\n", CRASHRPT_VER/1000, (CRASHRPT_VER%1000)/100, (CRASHRPT_VER%1000)%100); CTestRegistry* pRegistry = CTestRegistry::GetRegistry(); CTestSuite* pTopSuite = pRegistry->GetTopSuite(); // Print the list of test suites printf("The list of avaliable test suites:\n"); UINT nSuiteCount = pTopSuite->GetChildSuiteCount(); UINT i; for(i=0; i<nSuiteCount; i++) { CTestSuite* pSuite = pTopSuite->GetChildSuite(i); std::string sSuiteName; std::string sDescription; pSuite->GetSuiteInfo(sSuiteName, sDescription); printf(" - %s : %s\n", sSuiteName.c_str(), sDescription.c_str()); } printf("\nEnter which test suites to run (separate names by space) or enter empty line to run all test suites.\n"); printf("Your choice > "); char szSuiteList[1024]=""; #if _MSC_VER>=1400 gets_s(szSuiteList, 1024); #else gets(szSuiteList); #endif // Create the list of test suites to run std::string sSuiteList = szSuiteList; std::vector<std::string> aTokens = explode(sSuiteList); std::set<std::string> aTestSuitesToRun; for(i=0; i<aTokens.size(); i++) aTestSuitesToRun.insert(aTokens[i]); // Determine how many tests to run std::vector<std::string> test_list = pTopSuite->GetTestList(aTestSuitesToRun, true); size_t nTestsToRun = test_list.size(); printf("\nRunning tests...\n"); DWORD dwStartTicks = GetTickCount(); pTopSuite->Run(aTestSuitesToRun); DWORD dwFinishTicks = GetTickCount(); double dTimeElapsed = (dwFinishTicks-dwStartTicks)/1000.0; printf("\n=== Summary ===\n\n"); // Print all errors (if exist) std::vector<std::string> error_list = pTopSuite->GetErrorList(true); if(error_list.size()>0) { printf("Error list:\n"); for(i=0; i<error_list.size(); i++) { printf("%d: %s\n", i+1, error_list[i].c_str()); } } printf("\n Time elapsed: %0.2f sec.\n", dTimeElapsed); printf(" Test count: %d\n", nTestsToRun); size_t nErrorCount = error_list.size(); printf(" Tests passed: %d\n", nTestsToRun-nErrorCount); printf(" Tests failed: %d\n", nErrorCount); // Wait for key press _getch(); // Return non-zero value if there were errors return nErrorCount==0?0:1; }
int _tmain(int argc, TCHAR** argv) { if(argc==1) { _tprintf(_T("\nDo you want to run tests from a folder cotaining Chineese characters to test UNICODE compatibility (y/n)?\n")); _tprintf(_T("Your choice > ")); TCHAR szAnswer[1024]=_T(""); #if _MSC_VER>=1400 _getts_s(szAnswer, 1024); #else _getts(szAnswer); #endif if(_tcscmp(szAnswer, _T("y"))==0 || _tcscmp(szAnswer, _T("Y"))==0) { // Relaunch this process from another working directory containing UNICODE symbols in path. // This is needed to test all functionality on UNICODE compatibility. g_bRunningFromUNICODEFolder = TRUE; } if(g_bRunningFromUNICODEFolder) { _tprintf(_T("Launching tests in another process:\n")); if(g_bRunningFromUNICODEFolder) _tprintf(_T(" - with working directory having UNICODE symbols in path\n")); return fork(); } } else { int argnum; for(argnum=1; argnum<argc; argnum++) { TCHAR* szArg = argv[argnum]; if(_tcscmp(szArg, _T("/unicode"))==0) g_bRunningFromUNICODEFolder = TRUE; } } printf("\n=== Automated tests for CrashRpt v.%d.%d.%d ===\n\n", CRASHRPT_VER/1000, (CRASHRPT_VER%1000)/100, (CRASHRPT_VER%1000)%100); printf("The list of avaliable test suites:\n"); // Print the list of test suites std::map<std::string, std::string>::iterator siter; for(siter=g_pTestSuiteList->begin(); siter!=g_pTestSuiteList->end(); siter++) { printf(" - %s : %s\n", siter->first.c_str(), siter->second.c_str()); } printf("\nEnter which test suites to run (separate names by space) or enter empty line to run all test suites.\n"); printf("Your choice > "); char szSuiteList[1024]=""; #if _MSC_VER>=1400 gets_s(szSuiteList, 1024); #else gets(szSuiteList); #endif // Create the list of test suites to run std::string sSuiteList = szSuiteList; std::vector<std::string> aTokens = explode(sSuiteList); std::set<std::string> aTestSuitesToRun; size_t i; for(i=0; i<aTokens.size(); i++) aTestSuitesToRun.insert(aTokens[i]); // Determine how many tests to run size_t nTestsToRun = 0; if(aTestSuitesToRun.size()==0) { nTestsToRun = g_pTestList->size(); } else { std::map<std::string, PFNTEST>::iterator iter; for(iter=g_pTestList->begin(); iter!=g_pTestList->end(); iter++) { std::string sName = iter->first; size_t pos = sName.find(':'); std::string sTestSuite = sName.substr(0, pos); std::set<std::string>::iterator sit = aTestSuitesToRun.find(sTestSuite); if(sit!=aTestSuitesToRun.end()) { nTestsToRun++; } } } if(nTestsToRun==0) { printf("\nNo tests selected, exiting.\n"); return 0; } printf("\nRunning tests...\n"); // Walk through all registered test and run each one std::map<std::string, PFNTEST>::iterator iter; int n = 1; for(iter=g_pTestList->begin(); iter!=g_pTestList->end(); iter++) { std::string sName = iter->first; size_t pos = sName.find(':'); std::string sTestSuite = sName.substr(0, pos); std::set<std::string>::iterator sit = aTestSuitesToRun.find(sTestSuite); if(aTestSuitesToRun.size()==0 || sit!=aTestSuitesToRun.end()) { printf("- %d/%d: %s ...\n", n, nTestsToRun, iter->first.c_str()); n++; iter->second(); } } printf("\n=== Summary ===\n\n"); // Print all errors (if exist) if(g_pErrorList!=NULL) { size_t i; for(i=0; i<g_pErrorList->size(); i++) { printf("Error %d: %s\n", i, (*g_pErrorList)[i].c_str()); } } printf("\n Test count: %d\n", nTestsToRun); size_t nErrorCount = g_pErrorList!=NULL?g_pErrorList->size():0; printf(" Tests passed: %d\n", nTestsToRun-nErrorCount); printf(" Tests failed: %d\n", nErrorCount); // Wait for key press _getch(); // Clean up if(g_pTestSuiteList!=NULL) delete g_pTestSuiteList; if(g_pTestList!=NULL) delete g_pTestList; if(g_pErrorList) delete g_pErrorList; // Return non-zero value if there were errors return nErrorCount==0?0:1; }
BOOL Config(int argc, _TCHAR* argv[]) { EventLog log; HKEY key; LONG result = RegOpenKeyEx(HKEY_LOCAL_MACHINE, _T("SYSTEM\\CurrentControlSet\\Services\\EasyDynamicDNS"), 0, KEY_READ | KEY_WRITE, &key); if (result == ERROR_SUCCESS) { tstring command = _T("show"); if (argc > 0) command = argv[0]; if (_tcsicmp(command.c_str(), _T("show")) == 0) { if (argc > 1) _tprintf(_T("Syntax error; use \"/config help\" for more information.\n")); else { DWORD timeout = LoadTimeout(key); _tprintf(_T("Update dynamic DNS domains every %d minutes.\n\n"), timeout / (1000 * 60)); int i = 0; BOOL found; do { DomainInfo info; found = LoadConfig(key, i, info); if (found == TRUE) { _tprintf(_T("Entry #%d\n"), i); _tprintf(_T(" Host Name: %s\n"), info.hostname.c_str()); _tprintf(_T(" Top Level Domain: %s\n"), info.tld.c_str()); _tprintf(_T(" My IP Address: %s\n"), (info.myip.length() > 0 ? info.myip.c_str() : _T("<my PC's address>"))); _tprintf(_T(" MX: %s\n"), info.mx.c_str()); _tprintf(_T(" Back MX: %s\n"), info.backmx.c_str()); _tprintf(_T(" Wildcard: %s\n"), info.wildcard.c_str()); _tprintf(_T(" easyDNS URL: %s\n"), (info.easydnsurl.length() > 0 ? info.easydnsurl.c_str() : _T("http://members.easydns.com/dyn/dyndns.php"))); _tprintf(_T(" HTTP Timeout: %d sec\n"), info.httpTimeout / 1000); _tprintf(_T(" Username: %s\n"), info.username.c_str()); _tprintf(_T(" Password: ********\n")); _tprintf(_T(" Proxy: %s\n"), info.proxy.c_str()); _tprintf(_T(" Proxy Port: %d\n"), info.proxyPort); } i++; } while (i < 100); } } else if (_tcsicmp(command.c_str(), _T("add")) == 0) { if (argc != 13) _tprintf(_T("Syntax error; use \"/config help\" for more information.\n")); else { int i = 0; BOOL found; do { DomainInfo info; found = LoadConfig(key, i, info); if (found != TRUE) { info.hostname = argv[1]; info.tld = argv[2]; info.myip = argv[3]; info.mx = argv[4]; info.backmx = argv[5]; info.wildcard = argv[6]; if (argv[7][0] != 0) info.easydnsurl = argv[7]; info.httpTimeout = atoi(argv[8]) * 1000; info.username = argv[9]; info.password = argv[10]; //info.domain = argv[11]; info.proxy = argv[11]; info.proxyPort = atoi(argv[12]); if (AddConfig(key, i, info) != TRUE) { TCHAR x[50]; wsprintf(x, _T("DomainInfo%03d"), i); _tprintf(_T("Error saving to registry\n")); RegDeleteKey(key, x); } } i++; } while (i < 100 && found == TRUE); if (found == TRUE) _tprintf(_T("There is not room for another entry.\n")); } } else if (_tcsicmp(command.c_str(), _T("prompt")) == 0) { if (argc != 1) _tprintf(_T("Syntax error; use \"/config help\" for more information.\n")); else { int i = 0; BOOL found; do { DomainInfo info; found = LoadConfig(key, i, info); if (found != TRUE) { TCHAR buf[256]; _tprintf("Enter your setup as described below. This program does not do much validation;\n" "please follow the instructions carefully.\n\n"); _tprintf("Host Name = the full hostname being updated (REQUIRED)\n"); info.hostname = _getts(buf); _tprintf("Top Level Domain = the root domain of your hostname, for example if your\n" "hostname is \"example.co.uk\" you should set \"tld\" to \"co.uk\". This field\n" "can be omitted in cases of second level domains like example.com\n"); info.tld = _getts(buf); _tprintf("My IP Address = the IP address of the client to be updated. Send \"0.0.0.0\"\n" "to set record to an offline state (sets record to \"offline.easydns.com\"). If\n" "you are behind a firewall or NAT set this to 1.1.1.1 and our system will detect\n" "your remote IP for you. Leave blank to use your PC's address.\n"); info.myip = _getts(buf); _tprintf("MX = use this parameter as the MX handler for the domain being updated, it\n" "defaults to preference 5. (OPTIONAL)\n"); info.mx = _getts(buf); _tprintf("Back MX = either \"YES\" or \"NO\", if \"YES\" we set smtp.easydns.com to\n" "be a backup mail spool for domain being updated at preference 100. (OPTIONAL)\n"); info.backmx = _getts(buf); _tprintf("Wildcard = either \"ON\" or \"OFF\", if \"ON\" sets a wildcard host record for\n" "the domain being updated equal to the IP address specified in \"myip\" (OPTIONAL)\n"); info.wildcard = _getts(buf); _tprintf("easyDNS URL = the url to send the update to; defaults to\n" "http://members.easydns.com/dyn/dyndns.php (OPTIONAL)\n"); info.easydnsurl = _getts(buf); _tprintf("HTTP Timeout = Number of seconds to allow the request to complete. 0 for\n" "no timeout.\n"); info.httpTimeout = atoi(_getts(buf)) * 1000; _tprintf("Username = easyDNS user name (REQUIRED)\n"); info.username = _getts(buf); _tprintf("Password = easyDNS password (which is stored securely) (REQUIRED)\n"); info.password = _getts(buf); _tprintf("Proxy = proxy server (leave blank if you don't have one)\n"); info.proxy = _getts(buf); _tprintf("Proxy Port = proxy port; 0 if you don't have one\n"); info.proxyPort = atoi(_getts(buf)); if (AddConfig(key, i, info) != TRUE) { TCHAR x[50]; wsprintf(x, _T("DomainInfo%03d"), i); _tprintf(_T("Error saving to registry\n")); RegDeleteKey(key, x); } } i++; } while (i < 100 && found == TRUE); if (found == TRUE) _tprintf(_T("There is not room for another entry.\n")); } } else if (_tcsicmp(command.c_str(), _T("delete")) == 0) { if (argc != 2) _tprintf(_T("Syntax error; use \"/config help\" for more information.\n")); else { int i = atoi(argv[1]); TCHAR x[50]; wsprintf(x, _T("DomainInfo%03d"), i); if (RegDeleteKey(key, x) != ERROR_SUCCESS) _tprintf(_T("Item %d not found.\n"), i); } } else if (_tcsicmp(command.c_str(), _T("clear")) == 0) { if (argc != 1) _tprintf(_T("Syntax error; use \"/config help\" for more information.\n")); else { for (int i = 0; i < 100; i++) { TCHAR x[50]; wsprintf(x, _T("DomainInfo%03d"), i); RegDeleteKey(key, x); } } } else if (_tcsicmp(command.c_str(), _T("timeout")) == 0) { if (argc != 2) _tprintf(_T("Syntax error; use \"/config help\" for more information.\n")); else { int i = atoi(argv[1]) * 1000 * 60; if (SaveTimeout(key, i) != TRUE) _tprintf(_T("Unable to set timeout.\n")); } } else { _tprintf(_T("Subcommands:\n")); _tprintf(_T("\tprompt: prompt for setup with help\n")); _tprintf(_T("\tadd hostname tld myip mx backmx wildcard easydnsurl httpTimeoutSec username password proxy proxyPort\n")); _tprintf(_T("\tdelete n: delete entry number n\n")); _tprintf(_T("\tclear: erase the entired configuration (be careful!)\n")); _tprintf(_T("\ttimeout n: set the timeout to n minutes\n")); _tprintf(_T("\thelp: show this text\n")); _tprintf(_T("\tshow: display the configuration\n")); } RegCloseKey(key); } else { log.LogLastError("Unable to open registry, please install first"); _tprintf(_T("Unable to open registry\n")); return FALSE; } return TRUE; }