void HTMLWriter::_begin(section_type_t s) { QList<QStringList> values=tag(s); if (!values.empty()) indent_begin(s); QList<QStringList>::const_iterator itValues=values.end(); while (itValues!=values.begin()) { --itValues; stream << "<" ; bool first=true; for (QStringList::const_iterator it=(*itValues).begin();it!=(*itValues).end();++it) { ASSERT(! (*it).contains('>')); if (!first) stream << " " ; stream << *it; first=false; } if (!no_class.contains(s)) stream << " " << "class=\"" << sectionName(s) << "\"" ; stream << ">" ; } no_ident_this_section=false; }
void ElfSectionManager::AddSection(ElfSection & aSection){ EnsureSectionStringTableSectionAdded(); if (aSection.GetName().size() > 0){ // rename sections for GDB (yuk!) String sectionName(aSection.GetName()); String ro("ER_RO"); String text(".text"); if (sectionName == ro){ sectionName = text; } else { String rw("ER_RW"); String data(".data"); if (sectionName == rw){ sectionName = data; } else { String zi("ER_ZI"); String bss(".bss"); if (sectionName == zi) sectionName = bss; } } size_t nameOffset = iStringTable.AddName(sectionName); aSection.SetNameOffset(nameOffset); } else { // use the initial Null String. size_t nameOffset = iStringTable.AllocateInitialNullString(); aSection.SetNameOffset(nameOffset); } aSection.SetIndex(iSections.size()); iSections.push_back(aSection); iElf32Header.AddSectionHdr(); }
std::string ServerSettings::getSectionForServerCredentials(const ServerSettingsCredentials & credentials) const { //This should be expanded to a more complex way of assuring that the section returned is correct for the server credentials. std::stringstream ss; ss << "hostname_" << credentials.getHostName() << "_servername_" << credentials.getServerName(); std::string sectionName(ss.str()); mConfig->clean(sectionName); return sectionName; }
void PostgreSQLConfig::print( std::ostream& os, size_t indent ) const { std::string indStr( indent, ' ' ); os << indStr << sectionName() << ":" << std::endl; if ( ! m_ID.empty() ) os << indStr << " ID: " << m_ID << std::endl; if ( m_host.empty()) os << indStr << " Database host: local unix domain socket" << std::endl; else os << indStr << " Database host: " << m_host << ":" << m_port << std::endl; os << indStr << " Database name: " << (m_dbName.empty() ? "(not specified - server user default)" : m_dbName) << std::endl; os << indStr << " Database user: "******"(not specified - same as server user)" : m_user) << ", password: "******"(not specified - no password used)" : m_password) << std::endl; if ( ! m_sslMode.empty()) os << indStr << " Database connection SSL mode: " << m_sslMode << std::endl; if ( ! m_sslCert.empty()) { os << indStr << " Client SSL certificate file: " << m_sslCert << std::endl; if ( ! m_sslMode.empty()) os << indStr << " Client SSL key file: " << m_sslKey << std::endl; } if ( ! m_sslRootCert.empty()) os << indStr << " SSL root CA file: " << m_sslRootCert << std::endl; if ( ! m_sslCRL.empty()) os << indStr << " SSL CRL file: " << m_sslCRL << std::endl; if ( m_connectTimeout == 0 ) os << indStr << " Connect timeout: 0 (wait indefinitely)" << std::endl; else os << indStr << " Connect timeout: " << m_connectTimeout << "s" << std::endl; os << indStr << " Database connections: " << m_connections << std::endl; if ( m_acquireTimeout == 0 ) os << indStr << " Acquire database connection timeout: 0 (wait indefinitely)" << std::endl; else os << indStr << " Acquire database connection timeout: " << m_acquireTimeout << "s" << std::endl; if ( m_statementTimeout == 0 ) os << indStr << " Default statement execution timeout: 0 (wait indefinitely)" << std::endl; else os << indStr << " Default statement execution timeout: " << m_statementTimeout << "ms" << std::endl; }
void HTMLWriter::endHeader() { if (!getIconFile().isEmpty()) { stream << "<link rel=\"shortcut icon\" href=\""<< getIconFile() <<"\" type=\"image/x-icon\">" ; writeLineFormating() ; stream << "<link rel=\"icon\" href=\""<< getIconFile() <<"\" type=\"image/x-icon\">" ; writeLineFormating() ; } stream << "<title>"<< getTitle() << "</title>" ; writeLineFormating() ; if (!getCssFile().isEmpty()) { stream << "<link rel=\"stylesheet\" type=\"text/css\" href=\""<< getCssFile() << "\">" ; writeLineFormating() ; } else { stream << "<style type=\"text/css\">" ; writeLineFormating() ; for (QMap<section_type_t,QStringList>::const_iterator it=styles.begin();it!=styles.end();++it) { QString html_class=sectionName(it.key()); QStringList attributes=it.value(); stream << "." << html_class << " {"; for (QStringList::const_iterator itAttribute=attributes.begin();itAttribute!=attributes.end();++itAttribute) { stream << *itAttribute << "; "; } stream << "}" ; writeLineFormating() ; } stream << "</style>" ; writeLineFormating() ; } stream << "</head>" ; writeLineFormating() ; }
//****************************************************************************** bool CIniFile::Load( //Loads the INI file // //Params: const WCHAR *wszSetFilename) //(in) { char buffer[MAX_PROFILE_STRING*2+2]; wstrFilename = wszSetFilename; this->bLoaded = true; this->bDirty = false; FILE* pFile = CFiles::Open(wstrFilename.c_str(), "r"); if (NULL == pFile) return false; string curSection; while (true) { fgets(buffer, (MAX_PROFILE_STRING+1)*2+1, pFile); if (feof(pFile)) break; if (buffer[0] == '[') { string sectionName(&buffer[1]); unsigned int end = sectionName.find_first_of(']'); if (end != string::npos) { sectionName.erase(end); curSection = sectionName; } else { // Can't find the closing ] in a section name return false; } } else { string line(buffer); bool bIsWhitespace = true; for (string::iterator c = line.begin(); c != line.end(); ++c) { if (!isspace(*c)) { bIsWhitespace = false; break; } } if (bIsWhitespace) continue; // It's a key/value pair, not a section name unsigned int equalsPos = line.find_first_of('='); if (equalsPos == string::npos) { // No = in the line return false; } else { string key = line.substr(0, equalsPos); string value = line.substr(equalsPos+1); string::iterator last = value.end(); last--; value.erase(last); // Now add the pair to the correct section. // See if the section already exists. map<string, CIniSection>::iterator sec; sec = sections.find(curSection); if (sec != sections.end()) { // Section exists sec->second.WriteString(key.c_str(), value.c_str()); } else { // Section doesn't exist - make a new one CIniSection newSection(curSection.c_str()); newSection.WriteString(key.c_str(), value.c_str()); sections.insert(pair<string,CIniSection>(curSection, newSection)); // [curSection] = newSection; } } } } return true; }
std::string ExifTags::makeKey(uint16 tag, IfdId ifdId) { return std::string(ifdItem(ifdId)) + "." + std::string(sectionName(tag, ifdId)) + "." + std::string(tagName(tag, ifdId)); }
// Method to store conf data in this class' data map void ConfDataReader::loadData(void) throw(ConfigurationException) { // By default, section name is "DEFAULT" std::string sectionName("DEFAULT"); // Do this until end-of-file reached or something else happens while(1) { try { std::string line; std::string variable; std::string value; formattedGetLine(line, true); // If line is too long, we throw an exception if (line.size()>255) { ConfigurationException e( "Line too long in configuration file '" + filename + "'." ); GPSTK_THROW(e); } // Skip the blank line if(line.size()<1) continue; // Let's find and strip comment lines if( (StringUtils::firstWord(line)[0] == '#') || (StringUtils::firstWord(line)[0] == ';') ) { formattedGetLine(line, true); } // Let's strip comments at the end of lines std::string::size_type idx(line.find('#')); if( !(idx == std::string::npos) ) { line = line.substr(0, idx); } idx = line.find(';'); if( !(idx == std::string::npos) ) { line = line.substr(0, idx); } // Remove trailing and leading blanks line = StringUtils::strip(line); // Skip blank lines if (line.size()==0) { continue; } // Let's start to get data out of file // First, handle section names // Test if this line declares a new section. Check for '[' idx = line.find('['); if( !(idx == std::string::npos) ) { // Now, check if there is a closing ']' std::string::size_type idx2(line.find(']')); if( !(idx2 == std::string::npos) ) { // Extract name and remove trailing and leading blanks line = StringUtils::strip( line.substr(idx+1, idx2-idx-1) ); // Check if section name is appropriate if( checkName(line) ) { // Update 'sectionName': make it uppercase sectionName = StringUtils::upperCase(line); } else { // Throw an exception if section name isn't appropriate ConfigurationException e( "Section name '" + line + "' in configuration file '" + filename + "' does not comply with rules."); GPSTK_THROW(e); } // If this was a section line, continue with next line continue; } else { // Throw an exception if section line is not closed ConfigurationException e( "Section line '" + line + "' in configuration file '" + filename + "' was improperly closed" ); GPSTK_THROW(e); } } // Second, handle variables // Separate variable name from value. Look for separators idx = line.find('='); if( idx == std::string::npos ) { idx = line.find(':'); } // If we found a separator, keep processing if( !(idx == std::string::npos) ) { // Read variable and value variable = StringUtils::strip( line.substr(0, idx) ); value = StringUtils::strip( line.substr(idx+1) ); // Now separate comments // Work on 'variable' std::string varComment; idx = variable.find(','); if( !(idx == std::string::npos) ) { varComment = StringUtils::strip(variable.substr(idx+1)); variable = StringUtils::strip(variable.substr(0, idx)); } // Check if variable name is appropriate if( checkName(variable) ) { // Make 'variable' uppercase variable = StringUtils::upperCase(variable); } else { // Throw an exception if variable name isn't appropriate ConfigurationException e( "Variable name '" + variable + "' in configuration file '" + filename + "' does not comply with rules."); GPSTK_THROW(e); } // Now work on 'value' std::string valueComment; idx = value.find(','); if( !(idx == std::string::npos) ) { valueComment = StringUtils::strip(value.substr(idx+1)); value = StringUtils::strip(value.substr(0, idx)); } // Store configuration data variableData varData; varData.varComment = varComment; varData.value = value; varData.valueComment = valueComment; confData[sectionName][variable] = varData; } } // End of try block catch (ConfigurationException& e) { GPSTK_THROW(e); } catch (EndOfFile& e) { // Initialize itCurrentSection itCurrentSection = confData.begin(); return; } catch (...) { return; } } // End of 'while(1)' } // End of method 'ConfDataReader::loadData()'
TBool CDataWrapperBase::GetCommandStringParameterL(const TDesC& aSectName, const TDesC& aKeyName, TPtrC& aResult) { TBool ret=EFalse; if ( aSectName.Length()!=0 ) { ret=CDataWrapper::GetStringFromConfig(aSectName, aKeyName, aResult); for ( TInt index=iInclude.Count(); (index>0) && (!ret); ) { ret=iInclude[--index]->FindVar(aSectName, aKeyName, aResult); } } if ( ret ) { if ( aResult.Match(KMatch)!=KErrNotFound ) { // We have an entry of the format // entry =*{section,entry}* // where * is one or more characters // We need to construct this from other data in the ini file replacing {*,*} // with the data from // [section] // entry =some_value HBufC* buffer=HBufC::NewLC(aResult.Length()); buffer->Des().Copy(aResult); TInt startLength=KStart().Length(); TInt sparatorLength=KSeparator().Length(); TInt endLength=KEnd().Length(); TInt bufferLength; TInt start; TInt sparator; TInt end; TPtrC remaining; TLex lex; do { bufferLength=buffer->Length(); start=buffer->Find(KStart); remaining.Set(buffer->Des().Right(bufferLength-start-startLength)); sparator=remaining.Find(KSeparator); remaining.Set(remaining.Right(remaining.Length()-sparator-sparatorLength)); sparator += (start + startLength); end=remaining.Find(KEnd) + sparator + sparatorLength; TPtrC sectionName(buffer->Ptr()+start+startLength, sparator-start-startLength); TPtrC keyName(buffer->Ptr()+sparator+sparatorLength, end-sparator-sparatorLength); sectionName.Set(TLex(sectionName).NextToken()); keyName.Set(TLex(keyName).NextToken()); TInt entrySize=0; TPtrC entryData; TBool found=CDataWrapper::GetStringFromConfig(sectionName, keyName, entryData); for ( TInt index=iInclude.Count(); (index>0) && (!found); ) { found=iInclude[--index]->FindVar(sectionName, keyName, entryData); } if ( found ) { entrySize=entryData.Length(); } TInt newLength=start + bufferLength - end - endLength + entrySize; HBufC* bufferNew=HBufC::NewLC(newLength); bufferNew->Des().Copy(buffer->Ptr(), start); if ( entrySize>0 ) { bufferNew->Des().Append(entryData); } bufferNew->Des().Append(buffer->Ptr() + end + endLength, bufferLength - end - endLength); CleanupStack::Pop(bufferNew); CleanupStack::PopAndDestroy(buffer); buffer=bufferNew; CleanupStack::PushL(buffer); } while ( buffer->Match(KMatch)!=KErrNotFound ); iBuffer.Append(buffer); CleanupStack::Pop(buffer); aResult.Set(*buffer); INFO_PRINTF4(KDataRead, &aSectName, &aKeyName , &aResult); } } return ret; }
bool MigrateOldConfig() { if (!(FlagListManager::GetFlagListManager()->GetBuildCaps() & FlagListManager::BUILD_CAPS_SDL)) { // Nothing to do, we have an old build return true; } wxFileName newName = GetPlatformDefaultConfigFilePathNew(); newName.SetFullName(FSO_CONFIG_FILENAME); if (wxFile::Exists(newName.GetFullPath())) { // New file already exists, nothing to do here return true; } wxLogStatus(_T("Migrating old configuration...")); #if IS_WIN32 // On Windows this is implemented by iterating through the registry and copying the values to the config file wxString keyName; HKEY useKey = GetRegistryKeyname(keyName); LONG ret = ERROR_SUCCESS; HKEY regHandle = 0; ret = RegOpenKeyExW(useKey, keyName.wc_str(), 0, KEY_READ, ®Handle ); if (ret != ERROR_SUCCESS) { // Key does not exists or some other error, assume it doesn't exist return true; // No old config, nothing to do here } wxStringInputStream configBlankInputStream(_T("")); wxFileConfig outConfig(configBlankInputStream, wxMBConvUTF8()); copyValuesIntoConfig(regHandle, outConfig, REG_KEY_DEFAULT_FOLDER_CFG); for (DWORD i = 0;; ++i) { WCHAR subkey[255]; DWORD subkeyLen = 255; LONG res = RegEnumKeyExW(regHandle, i, subkey, &subkeyLen, NULL, NULL, NULL, NULL); if (res != ERROR_SUCCESS) break; HKEY handle; res = RegOpenKeyExW(regHandle, subkey, 0, KEY_READ, &handle); if (res != ERROR_SUCCESS) { continue; } wxString sectionName(subkey, subkeyLen); sectionName = wxString::FromAscii("/") + sectionName; copyValuesIntoConfig(handle, outConfig, sectionName); RegCloseKey(handle); } RegCloseKey(regHandle); wxLogStatus(_T("Writing fs2_open.ini to %s"), newName.GetFullPath().c_str()); wxFFileOutputStream outFileStream(newName.GetFullPath()); outConfig.Save(outFileStream, wxMBConvUTF8()); #else wxFileName oldName = GetPlatformDefaultConfigFilePathOld(); oldName.SetFullName(FSO_CONFIG_FILENAME); if (!wxFile::Exists(oldName.GetFullPath())) { // Old file does not exist, probably first run. return true; } if (!wxCopyFile(oldName.GetFullPath(), newName.GetFullPath())) { wxLogError(_T("Failed to copy old configuration file to new location!")); return false; } #endif wxLogStatus(_T("Migration finished.")); return true; }
PRBool nsEudoraWin32::ImportSettings( nsIFile *pIniFile, nsIMsgAccount **localMailAccount) { PRBool result = PR_FALSE; nsresult rv; nsCOMPtr<nsIMsgAccountManager> accMgr = do_GetService(NS_MSGACCOUNTMANAGER_CONTRACTID, &rv); if (NS_FAILED(rv)) { IMPORT_LOG0( "*** Failed to create a account manager!\n"); return( PR_FALSE); } // Eudora info is arranged by key, 1 for the default, then persona's for additional // accounts. // Start with the first one, then do each persona nsCString iniPath; pIniFile->GetNativePath(iniPath); if (iniPath.IsEmpty()) return( PR_FALSE); UINT valInt; SimpleBufferTonyRCopiedOnce section; DWORD sSize; DWORD sOffset = 0; DWORD start; nsCString sectionName("Settings"); int popCount = 0; int accounts = 0; DWORD allocSize = 0; do { allocSize += 2048; section.Allocate( allocSize); sSize = ::GetPrivateProfileSection( "Personalities", section.m_pBuffer, allocSize, iniPath.get()); } while (sSize == (allocSize - 2)); nsIMsgAccount * pAccount; do { if (!sectionName.IsEmpty()) { pAccount = nsnull; valInt = ::GetPrivateProfileInt( sectionName.get(), "UsesPOP", 1, iniPath.get()); if (valInt) { // This is a POP account if (BuildPOPAccount( accMgr, sectionName.get(), iniPath.get(), &pAccount)) { accounts++; popCount++; if (popCount > 1) { if (localMailAccount && *localMailAccount) { NS_RELEASE( *localMailAccount); *localMailAccount = nsnull; } } else { if (localMailAccount) { *localMailAccount = pAccount; NS_IF_ADDREF( pAccount); } } } } else { valInt = ::GetPrivateProfileInt( sectionName.get(), "UsesIMAP", 0, iniPath.get()); if (valInt) { // This is an IMAP account if (BuildIMAPAccount( accMgr, sectionName.get(), iniPath.get(), &pAccount)) accounts++; } } if (pAccount && (sOffset == 0)) accMgr->SetDefaultAccount( pAccount); NS_IF_RELEASE( pAccount); } sectionName.Truncate(); while ((sOffset < sSize) && (section.m_pBuffer[sOffset] != '=')) sOffset++; sOffset++; start = sOffset; while ((sOffset < sSize) && (section.m_pBuffer[sOffset] != 0)) sOffset++; if (sOffset > start) { sectionName.Append( section.m_pBuffer + start, sOffset - start); sectionName.Trim( kWhitespace); } } while (sOffset < sSize); // Now save the new acct info to pref file. rv = accMgr->SaveAccountInfo(); NS_ASSERTION(NS_SUCCEEDED(rv), "Can't save account info to pref file"); return( accounts != 0); }
void pEchoConfiguration::print( std::ostream& os, size_t /*indent*/ ) const { os << sectionName() << std::endl; os << " Idle timeout: " << timeout << std::endl; }
string CIniFile::getSectionName( S32 const sectionId) const { return sectionName(sectionId); }
/*! Attempts to load settings from a file. Old data is not cleared! You will need to explicitly call clear() for this purpose. Returns false and sets the lastErrorCode property on error. */ bool XmlPreferences::load(const QString& filename) { d->lastErrorCode = NoError; xmlDocPtr doc = xmlParseFile(filename.toLatin1().data()); if (doc == 0) return false; xmlNodePtr cur = xmlDocGetRootElement(doc); if (cur == 0) { xmlFreeDoc(doc); return false; } if (xmlStrcmp((cur)->name, (const xmlChar*) "xml-preferences")) { xmlFreeDoc(doc); return false; } xmlChar* attr = 0; QString version; attr = xmlGetProp(cur, (const xmlChar*) "xmlp-version"); if (attr != 0) { bool ok; quint8 xmlPrefV = QString((const char*) attr).toInt(&ok); xmlFree(attr); if (ok) { if (xmlPrefV != d->xmlPrefVersion) { d->lastErrorCode = IncompatibleFileVersion; return false; } } } // Check product version if (d->version != 0) { quint8 version = 0; xmlNodePtr childNode = cur->xmlChildrenNode; while (childNode != 0) { if (xmlStrcmp(childNode->name, (const xmlChar*) "product-info") == 0) { attr = xmlGetProp(childNode, (const xmlChar*) "version"); if (attr != 0) { bool ok; version = QString((const char*) attr).toUShort(&ok); xmlFree(attr); if (!ok) version = 0; break; } } childNode = childNode->next; } if (!d->checkApplicationVersion(version)) { xmlFreeDoc(doc); d->lastErrorCode = IncompatibleProductVersion; return false; } } xmlNodePtr childNode = cur->xmlChildrenNode; while (childNode != 0) { if (xmlStrcmp(childNode->name, (const xmlChar*) "preferences") != 0) { childNode = childNode->next; continue; } xmlNodePtr prefNode = childNode->xmlChildrenNode; while (prefNode != 0) { if (xmlStrcmp(prefNode->name, (const xmlChar*) "section") != 0) { prefNode = prefNode->next; continue; } attr = xmlGetProp(prefNode, (const xmlChar*) "name"); if (attr == 0) { prefNode = prefNode->next; continue; } // Find or create the right section QString sectionName((const char*) attr); XmlPreferencesPrivate::SectionTable::Iterator sectionIterator = d->data.find(sectionName); if (sectionIterator == d->data.end()) { // Create a new section XmlPreferencesPrivate::Section section; d->parseSection(doc, prefNode, section); d->data.insert(sectionName, section); } else d->parseSection(doc, prefNode, sectionIterator.value()); xmlFree(attr); prefNode = prefNode->next; } childNode = childNode->next; } xmlFreeDoc(doc); return true; }
QString KCharSelectData::section(CharSelectData* charselect, uint16_t unicode) { return sectionName(sectionIndex(blockIndex(c))); }