/** Update version Open text file RELEASE-NOTES from the home folder Find line that contains the string "Apache Tomcat Version " Get the rest of the text on that line as the version */ void TomcatAppServerInstance::UpdateVersion() { const string cTomcatVersionPrecursor("Apache Tomcat Version "); SCXFilePath filename(m_homePath); filename.Append(L"RELEASE-NOTES"); try { string filecontent; SCXHandle<istream> mystream = m_deps->OpenVersionFile(filename.Get()); bool foundVersion = false; while (!foundVersion && SCXStream::IsGood(*mystream)) { string tmp; getline(*mystream, tmp); size_t pos = tmp.find(cTomcatVersionPrecursor); if (string::npos != pos) { foundVersion = true; string version = tmp.substr(pos + cTomcatVersionPrecursor.length()); SetVersion(StrStrip(StrFromUTF8(version), L" \t\n\r")); } } } catch (SCXFilePathNotFoundException&) { SCX_LOGERROR(m_log, wstring(L"TomcatAppServerInstance::UpdateVersion() - ").append(GetId()).append(L" - Could not find file: ").append(filename)); } catch (SCXUnauthorizedFileSystemAccessException&) { SCX_LOGERROR(m_log, wstring(L"TomcatAppServerInstance::UpdateVersion() - ").append(GetId()).append(L" - not authorized to open file: ").append(filename)); } }
/* Very much inspired by Kismet's config parser */ void ConfigParser::parse_file(char* filename) { if(debugLevel) fprintf(stderr, "Reading confilg file: %s\n", filename); std::ifstream configfile; configfile.open(filename, std::ifstream::in); if (!configfile) { fprintf(stderr, "ERROR: Reading config file '%s': %d (%s)\n", filename, errno, strerror(errno)); return; } std::string confline; while (!configfile.eof()) { std::getline(configfile, confline); std::string parsestr = StrStrip(confline); std::string key, value; if (parsestr.length() == 0) continue; if (parsestr[0] == '#') continue; unsigned int eq; if ((eq = parsestr.find("=")) > parsestr.length()) { key = parsestr; value = ""; } else { key = StrStrip(parsestr.substr(0, eq)); value = StrStrip(parsestr.substr(eq+1, parsestr.length())); set(key, value); } } configfile.close(); }
printf("CountWords:%s:\n",ptr); free(ptr); ptr=Insert("LIGNE TEXTE","DE ","7","\0"); printf("Insert:%s:\n",ptr); free(ptr); ptr=Insert(" ","DE ","1","\0"); printf("Insert:%s:\n",ptr); free(ptr); ptr=Insert("","DE ","1","\0"); printf("Insert:%s:\n",ptr); free(ptr); ptr=StrStrip("LIGNEA DEA TEAXATEA","A","\0"); printf("StrStrip:%s:\n",ptr); free(ptr); ptr=StrStrip("LIGNEA DEA TEATEAXATEA","II","\0"); printf("StrStrip:%s:\n",ptr); free(ptr); ptr=StrStrip(" ","A","\0"); printf("StrStrip:%s:\n",ptr); free(ptr); ptr=StrStrip("","A","\0"); printf("StrStrip:%s:\n",ptr); free(ptr);
void ChangeLocationForm::handleControlSelect(const EventType& event) { bool pretendCancelPressed = true; char_t * newLocation = NULL; if (okButton == event.data.ctlSelect.controlID) { newLocation = locationField_.textCopy(); if (NULL == newLocation) goto ClosePopup; StrStrip(newLocation); if (StrEmpty(newLocation)) goto ClosePopup; LookupManager* lookupManager = application().lookupManager; Preferences& prefs = application().preferences(); switch (whenOk_) { case moviesMode: { const String& curLocation = prefs.moviesLocation; // TODO: now that there's a chance, that the text we use is // different than the string user gave, maybe it's a good idea // to popup a confirmation dialog box with "Get movies for location $FOO" // and "OK", "Cancel" so that the user has a chance to preview // location he gave. Changing locations shouldn't be frequent so // we can annoy users like that. // "Cancel" would get us back to entering location form // change only if different than previous if (!equalsIgnoreCase(newLocation, curLocation)) lookupManager->fetchMovies(newLocation); break; } case weatherMode: { const String& curLocation = prefs.weatherPreferences.weatherLocation; // change only if different than previous if (!equalsIgnoreCase(curLocation, newLocation)) lookupManager->fetchWeather(newLocation, newLocation); break; } } pretendCancelPressed = false; } ClosePopup: if( NULL != newLocation) free(newLocation); closePopup(); if (cancelButton == event.data.ctlSelect.controlID || pretendCancelPressed) { Preferences& prefs = application().preferences(); switch (whenOk_) { case moviesMode: if (prefs.moviesLocation.empty()) application().runMainForm(); break; case weatherMode: if (prefs.weatherPreferences.weatherLocationToServer.empty()) application().runMainForm(); break; } } }