int scanDirectory(const char *directory, FILE *fp) { DIR *dir; struct dirent *file; int successful = 0; if ((dir = opendir(directory)) == NULL) { fprintf(stderr, "Unable to open directory %s\n", directory); return -1; } successful=chdir(directory); successful=0; do { file = readdir(dir); if (file == NULL) break; if (file->d_name[0] != '.') successful += (writeSection(file->d_name, fp) == 0) ? 1 : 0; } while(1); closedir(dir); return successful; }
void writeSection( std::string const& className, std::string const& rootName, SectionNode const& sectionNode ) { std::string name = trim( sectionNode.stats.sectionInfo.name ); if( !rootName.empty() ) name = rootName + "/" + name; if( !sectionNode.assertions.empty() || !sectionNode.stdOut.empty() || !sectionNode.stdErr.empty() ) { XmlWriter::ScopedElement e = xml.scopedElement( "testcase" ); if( className.empty() ) { xml.writeAttribute( "classname", name ); xml.writeAttribute( "name", "root" ); } else { xml.writeAttribute( "classname", className ); xml.writeAttribute( "name", name ); } xml.writeAttribute( "time", Catch::toString( sectionNode.stats.durationInSeconds ) ); writeAssertions( sectionNode ); if( !sectionNode.stdOut.empty() ) xml.scopedElement( "system-out" ).writeText( trim( sectionNode.stdOut ), false ); if( !sectionNode.stdErr.empty() ) xml.scopedElement( "system-err" ).writeText( trim( sectionNode.stdErr ), false ); } for( SectionNode::ChildSections::const_iterator it = sectionNode.childSections.begin(), itEnd = sectionNode.childSections.end(); it != itEnd; ++it ) if( className.empty() ) writeSection( name, "", **it ); else writeSection( className, name, **it ); }
int IniComparator::process(const Box16 &b, const std::string &key) { std::ostringstream os; os << b.left << " " << b.top << " " << b.right << " " << b.bottom; if (isLoadingBaseDat) return baseIni.SetValue(currentSection.c_str(), key.c_str(), os.str().c_str()); const std::string val = os.str(); const std::string baseVal(baseIni.GetValue(currentSection.c_str(), key.c_str(), "")); if (baseVal != val) { writeSection(); return IniWriter::process(val, key); } else return 0; //Identical, no write }
void writeTestCase( TestCaseNode const& testCaseNode ) { TestCaseStats const& stats = testCaseNode.value; // All test cases have exactly one section - which represents the // test case itself. That section may have 0-n nested sections assert( testCaseNode.children.size() == 1 ); SectionNode const& rootSection = *testCaseNode.children.front(); std::string className = stats.testInfo.className; if( className.empty() ) { if( rootSection.childSections.empty() ) className = "global"; } writeSection( className, "", rootSection ); }
/*! This function updates .ini file in two stages. It copies original .ini file into temporary one line by line, replacing/deleting/adding lines as necessary. Then it copies temporary file into original one and deletes temporary file. */ bool TEIniFile::update() { close(); if (!f.open(IO_ReadWrite)) return false; QString tempfn=f.name()+".tmp"; QFile tempf(tempfn); if (!tempf.open(IO_ReadWrite | IO_Truncate)) return false; QTextStream tsorg; bool skipsec=false; tsorg.setEncoding(QTextStream::UnicodeUTF8); tsorg.setDevice(&f); ts.setDevice(&tempf); // writeXXX function hardwired to write into ts. So we set it appropriatedly. // prepare QMap<QString,bool> secProcd, valueProcd; // processedp flag's maps QMapIterator<QString,type_ValueList> it1; for(it1=SectionList.begin();it1!=SectionList.end();++it1) { secProcd[it1.key()]=false; } // scan form sections QString line, sec; type_Processing pr = P_NONE; // nothing done yet type_ValueList ValueList; while (!((line = tsorg.readLine()).isNull())) { if ((pr == P_NONE) || (pr == P_SECTION)) { // trim line line = line.stripWhiteSpace(); // skip if empty if (line.isEmpty()) { writeBreak(); continue; } // skip if comment if (line.startsWith("#")) { writeComment(line.mid(1)); continue; } // check if section if (line.startsWith("[") && line.endsWith("]")) { if (pr == P_SECTION) { // update previous section // write new values type_ValueList::iterator it; type_ValueList & curSec=SectionList[sec]; type_ValueList & curSecDef=SectionListDef[sec]; for(it=curSec.begin();it!=curSec.end();++it) { if (!valueProcd[it.key()]) { // this value was not processed yet, hence it's new or just default. if (curSecDef.find(it.key())==curSecDef.end() || curSecDef[it.key()]!=it.data()) // if it equals default value, skip it. ts << it.key() << "\t" << it.data() << "\n"; valueProcd[it.key()]=true; // it is for completeness' sake, so it don't really necessary (yet?). } } secProcd[sec]=true; } // section found! valueProcd.clear(); // get ready for next section pr = P_SECTION; sec = line.mid(1, line.length()-2).stripWhiteSpace(); writeSection(sec); skipsec=SectionList.find(sec)==SectionList.end() || secProcd[sec]==true; // Skip deleted or already processed section type_ValueList & curSec=SectionList[sec]; type_ValueList::iterator it; for(it=curSec.begin();it!=curSec.end();++it) { valueProcd[it.key()]=false; } ValueList.clear(); continue; } if (pr == P_SECTION) { // read name if (skipsec) continue; QString nam; int j = 0, l = (int)line.length(); QChar c; while ( (j < l) && !((c = line.ref((uint)j)).isSpace()) ) { nam += c; j++; } // read value bool rawData=false; bool doubleQuotes=false; QString val; val = line.mid((uint)j).stripWhiteSpace(); if (val == "data{") { rawData=true; // read raw data... val = ""; while (!((line = ts.readLine()).isNull())) { if (line == "}data") { ValueList[nam] = val; break; } val += line + "\n"; } } else { // test for "" if (val.startsWith("\"") && val.endsWith("\"")) { doubleQuotes=true; val = val.mid(1, val.length()-2).stripWhiteSpace(); } ValueList[nam] = val; } if (SectionList[sec].find(nam)!=SectionList[sec].end() && valueProcd[nam]==false) { // write modified value if (rawData) writeData(nam,SectionList[sec][nam]); else if (doubleQuotes) writeString(nam,SectionList[sec][nam]); else ts << nam << "\t" << SectionList[sec][nam] << "\n"; valueProcd[nam]=true; } } else writeComment(line); } } if (pr == P_SECTION) { // update last section // write new values type_ValueList::iterator it; type_ValueList & curSec=SectionList[sec]; type_ValueList & curSecDef=SectionListDef[sec]; for(it=curSec.begin();it!=curSec.end();++it) { if (!valueProcd[it.key()]) { // this value was not processed yet, hence it's new. if (curSecDef.find(it.key())==curSecDef.end() || curSecDef[it.key()]!=it.data()) ts << it.key() << "\t" << it.data() << "\n"; valueProcd[it.key()]=true; // it is for completeness' sake, so it don't really necessary (yet?). } } secProcd[sec]=true; } QMapIterator<QString,bool> it; for(it=secProcd.begin();it!=secProcd.end();++it) { QString sec=it.key(); if (!it.data()) { writeSection(sec); type_ValueList & curSec=SectionList[sec]; type_ValueList & curSecDef=SectionListDef[sec]; type_ValueList::iterator it1; for(it1=curSec.begin();it1!=curSec.end();++it1) if (curSecDef.find(it1.key())==curSecDef.end() || curSecDef[it1.key()]!=it1.data()) ts << it1.key() << "\t" << it1.data() << "\n"; } } tempf.flush(); if (!tempf.reset()) return false; f.close(); if (!f.open(IO_WriteOnly | IO_Truncate)) return false; const int N=64*1024; char * buf=new char[N]; Q_LONG len; while(true) { len=tempf.readBlock(buf,N); if (len<=0) break; f.writeBlock(buf,(Q_ULONG)len); } delete [] buf; f.close(); tempf.close(); tempf.remove(); ts.setDevice(&f); return len>=0; }
static int iiMRCwriteSectionFloat(ImodImageFile *inFile, char *buf, int inSection) { return writeSection(inFile, buf, inSection, 1); }