/////////////////////////////////////////////////////////////// // // SharedUtil_String_Tests // // Test behaviour of strings // /////////////////////////////////////////////////////////////// void SharedUtil_String_Tests ( void ) { // Formatting { SString strTemp1 ( "name:" PRSinS, "dave" ); SString strTemp2 ( "name:" PRWinS, L"dave" ); WString wstrTemp3 ( L"name:" PRSinW, "dave" ); WString wstrTemp4 ( L"name:" PRWinW, L"dave" ); assert ( strTemp1 == "name:dave" ); assert ( strTemp2 == "name:dave" ); assert ( wstrTemp3 == L"name:dave" ); assert ( wstrTemp4 == L"name:dave" ); } // To/From Ansi { SString strTemp1 = "abcABC 123"; WString wstrTemp2 = "defDEF 456"; WString wstrTemp3 = L"ghiGHI 789"; assert ( wstrTemp2 == L"defDEF 456" ); SString strTemp2 = wstrTemp2.ToAnsi (); SString strTemp3 = wstrTemp3.ToAnsi (); assert ( strTemp2 == "defDEF 456" ); assert ( strTemp3 == "ghiGHI 789" ); } }
Foam::string Foam::equationReader::stringPreconditioner ( const string& rawText ) { string rawWorking(rawText); // Negative exponent workaround for (label i = 0; i < 10; i++) { string strTemp(name(i)); string strTempU(name(i)); string strTemp2(name(i)); strTemp.append("e-"); strTempU.append("E-"); strTemp2.append("&"); stringReplaceAll(rawWorking, strTemp, strTemp2); stringReplaceAll(rawWorking, strTempU, strTemp2); } stringReplaceAll(rawWorking, "^", " : "); stringReplaceAll(rawWorking, "(", " ( "); stringReplaceAll(rawWorking, ")", " ) "); stringReplaceAll(rawWorking, "+", " + "); stringReplaceAll(rawWorking, "-", " - "); stringReplaceAll(rawWorking, "&", "e-"); stringReplaceAll(rawWorking, "*", " * "); stringReplaceAll(rawWorking, "/", " / "); stringReplaceAll(rawWorking, ",", " , "); return rawWorking; }
/////////////////////////////////////////////////////////////// // // SharedUtil_String_Tests // // Test behaviour of strings // /////////////////////////////////////////////////////////////// void SharedUtil_String_Tests ( void ) { // Formatting { SString strTemp1 ( "name:" PRSinS, "dave" ); SString strTemp2 ( "name:" PRWinS, L"dave" ); WString wstrTemp3 ( L"name:" PRSinW, "dave" ); WString wstrTemp4 ( L"name:" PRWinW, L"dave" ); assert ( strTemp1 == "name:dave" ); assert ( strTemp2 == "name:dave" ); assert ( wstrTemp3 == L"name:dave" ); assert ( wstrTemp4 == L"name:dave" ); } // To/From Ansi { SString strTemp1 = "abcABC 123"; WString wstrTemp2 = "defDEF 456"; WString wstrTemp3 = L"ghiGHI 789"; assert ( wstrTemp2 == L"defDEF 456" ); SString strTemp2 = wstrTemp2.ToAnsi (); SString strTemp3 = wstrTemp3.ToAnsi (); assert ( strTemp2 == "defDEF 456" ); assert ( strTemp3 == "ghiGHI 789" ); } // Escaping URL arguments { TEST_FUNCTION SStringX strInputA( (const char*)a, sizeof( a ) ); SString strEscaped = EscapeURLArgument( strInputA ); SString strUnescaped = UnescapeString ( strEscaped, '%' ); assert ( strEscaped == result ); assert ( strInputA == strUnescaped ); TEST_VARS const uchar a[5]; const char* result; TEST_DATA { {0x00, 0x10, 0x20, 0x21, 0x22}, "%00%10%20%21%22" }, { {0x7F, 0x80, 0x81, 0xFE, 0xFF}, "%7F%80%81%FE%FF" },
int WINAPI WinMain(HINSTANCE hinst, HINSTANCE hinstExePrev, LPSTR pszCmdLine, int nCmdShow) { // ***** To debug this application **** // set fDebug to 1, then recompile (in debug mode) // and run the program in a debugger like any windows .exe // The exact same code executes as if the user clicked the // 'start' button in the NT services manager. int fDebug = 0; int nArgc = __argc; #ifdef UNICODE LPCTSTR *ppArgv = (LPCTSTR*) CommandLineToArgvW(GetCommandLine(), &nArgc); #else LPCTSTR *ppArgv = (LPCTSTR*) __argv; #endif BOOL fStartService = (nArgc < 2); int i; int bInstall = 0; int bRemove = 0; int bChange = 0; GString strPort("10888"); GString strBoot; GString strRoot("NotUsed"); for (i = 1; i < nArgc; i++) { if ((ppArgv[i][0] == __TEXT('-')) || (ppArgv[i][0] == __TEXT('/'))) { // Command line switch if (lstrcmpi(&ppArgv[i][1], __TEXT("install")) == 0) bInstall = 1; if (lstrcmpi(&ppArgv[i][1], __TEXT("remove")) == 0) bRemove = 1; if (lstrcmpi(&ppArgv[i][1], __TEXT("change")) == 0) bChange = 1; GString strTemp(&ppArgv[i][1],strlen("desc:")); if (strTemp.CompareNoCase("desc:") == 0) { strServerDescription = &ppArgv[i][1+strlen("desc:")]; } GString strTemp2(&ppArgv[i][1],strlen("name:")); if (strTemp2.CompareNoCase("name:") == 0) { strServerName = &ppArgv[i][1+strlen("name:")]; } GString strTemp3(&ppArgv[i][1],strlen("pass:"******"pass:"******"pass:"******"boot:")); if (strTemp4.CompareNoCase("boot:") == 0) { strBoot = &ppArgv[i][1+strlen("boot:")]; } GString strTemp5(&ppArgv[i][1],strlen("port:")); if (strTemp5.CompareNoCase("port:") == 0) { strPort = &ppArgv[i][1+strlen("port:")]; } GString strTemp6(&ppArgv[i][1],strlen("root:")); if (strTemp6.CompareNoCase("root:") == 0) { strRoot = &ppArgv[i][1+strlen("root:")]; } } } if (bChange) { ModifyStartupFile(strBoot,strServerPassword,strRoot,strPort); } if (bInstall) { GString strThisEXEName(GetThisEXEName()); // uuencode strBoot BUFFER b; BufferInit(&b); uuencode((unsigned char *)(const char *)strBoot, (int)strBoot.Length(), &b); GString strEncodedBoot((char *)b.pBuf, b.cLen); BufferTerminate(&b); // open the registry, save the coded boot key, close the registry HKEY hk; if (RegCreateKey(HKEY_CLASSES_ROOT,(const char *)strThisEXEName,&hk) == ERROR_SUCCESS) { RegSetValue(hk,NULL,REG_SZ,(const char *)strEncodedBoot,0); RegCloseKey(hk); } // use root of file system to store the startup file // unless specified otherwise by environment setting GString strOutFile("c:\\"); strOutFile += strThisEXEName; if (getenv(strThisEXEName)) { strOutFile += getenv(strThisEXEName); } // create the startup file GString strTempFile; strTempFile << strServerPassword << "&&" << strRoot << "&&" << strPort; strTempFile.ToFile("tempfile"); GString strErrorOut; FileEncrypt(strBoot, "tempfile", strOutFile, strErrorOut); unlink("tempfile"); InstallService(); } if (bRemove) { RemoveService(); GString strThisEXEName(GetThisEXEName()); // remove the registry entry RegDeleteKey(HKEY_CLASSES_ROOT,(const char *)strThisEXEName); // remove the startup file GString strOutFile("c:\\"); strOutFile += strThisEXEName; if (getenv(strThisEXEName)) { strOutFile += getenv(strThisEXEName); } unlink(strOutFile); } strcpy(pzServer,strServerName); if (fDebug) { // Running as EXE not as service, just run the service for debugging TimeServiceMain(0, NULL); } if (fStartService) { SERVICE_TABLE_ENTRY ServiceTable[] = { { pzServer, TimeServiceMain }, { NULL, NULL } // End of list }; StartServiceCtrlDispatcher(ServiceTable); } return(0); }