int main( int argc, char **argv ) { if ( argc < 2 ) { qWarning( "Usage:\n\t%s [--images] files", argv[0] ); return 1; } QFile output; bool images = FALSE; output.open( IO_WriteOnly, stdout ); QTextStream out( &output ); EmbedImageList list_image; QList<Embed> list; list.setAutoDelete( TRUE ); list_image.setAutoDelete( TRUE ); // Embed data for all input files out << "/* Generated by qembed */\n"; srand( time(0) ); long l = rand(); out << "#ifndef _" << l << endl; out << "#define _" << l << endl; for ( int i=1; i<argc; i++ ) { QString arg = argv[i]; if ( arg == "--images" ) { if ( !images ) { out << "#include <qimage.h>\n"; out << "#include <stdlib.h>\n"; images = TRUE; } } else { QFile f( argv[i] ); if ( !f.open(IO_ReadOnly) ) { qWarning( "Cannot open file %s, ignoring it", argv[i] ); continue; } QByteArray a( f.size() ); if ( f.readBlock(a.data(), f.size()) != (int)f.size() ) { qWarning( "Cannot read file %s, ignoring it", argv[i] ); f.close(); continue; } if ( images ) { QImage img; if ( !img.loadFromData(a) ) { qWarning( "Cannot read image from file %s, ignoring it", argv[i] ); f.close(); continue; } EmbedImage *e = new EmbedImage; e->width = img.width(); e->height = img.height(); e->depth = img.depth(); e->numColors = img.numColors(); e->colorTable = new QRgb[e->numColors]; e->alpha = img.hasAlphaBuffer(); memcpy(e->colorTable, img.colorTable(), e->numColors*sizeof(QRgb)); QFileInfo fi(argv[i]); e->name = fi.baseName(); e->cname = convertFileNameToCIdentifier( e->name.latin1() ); list_image.append( e ); QString s; if ( e->depth == 32 ) { out << s.sprintf( "static const QRgb %s_data[] = {", (const char *)e->cname ); embedData( (QRgb*)img.bits(), e->width*e->height, &output ); } else { if ( e->depth == 1 ) img = img.convertBitOrder(QImage::BigEndian); out << s.sprintf( "static const unsigned char %s_data[] = {", (const char *)e->cname ); embedData( img.bits(), img.numBytes(), &output ); } out << "\n};\n\n"; if ( e->numColors ) { out << s.sprintf( "static const QRgb %s_ctable[] = {", (const char *)e->cname ); embedData( e->colorTable, e->numColors, &output ); out << "\n};\n\n"; } } else { Embed *e = new Embed; e->size = f.size(); e->name = argv[i]; e->cname = convertFileNameToCIdentifier( argv[i] ); list.append( e ); QString s; out << s.sprintf( "static const unsigned int %s_len = %d;\n", (const char *)e->cname, e->size ); out << s.sprintf( "static const unsigned char %s_data[] = {", (const char *)e->cname ); embedData( a, &output ); out << "\n};\n\n"; } f.close(); } } // Generate summery if ( list.count() > 0 ) { out << "#include <qcstring.h>\n"; if ( !images ) out << "#include <qdict.h>\n"; out << "static struct Embed {\n" " unsigned int size;\n" " const unsigned char *data;\n" " const char *name;\n" "} embed_vec[] = {\n"; Embed *e = list.first(); while ( e ) { out << " { " << e->size << ", " << e->cname << "_data, " << "\"" << e->name << "\" },\n"; e = list.next(); } out << " { 0, 0, 0 }\n};\n"; out << "\n" "inline const QByteArray& qembed_findData(const char* name)\n" "{\n" " static QDict<QByteArray> dict;\n" " QByteArray* ba = dict.find(name);\n" " if ( !ba ) {\n" " for (int i=0; embed_vec[i].data; i++) {\n" " if ( 0==strcmp(embed_vec[i].name, name) ) {\n" " ba = new QByteArray;\n" " ba->setRawData( (char*)embed_vec[i].data,\n" " embed_vec[i].size );\n" " break;\n" " }\n" " }\n" " if ( !ba ) {\n" " static QByteArray dummy;\n" " return dummy;\n" " }\n" " }\n" " return *ba;\n" "}\n\n"; } if ( list_image.count() > 0 ) { out << "static struct EmbedImage {\n" " int width, height, depth;\n" " const unsigned char *data;\n" " int numColors;\n" " const QRgb *colorTable;\n" " bool alpha;\n" " const char *name;\n" "} embed_image_vec[] = {\n"; list_image.sort(); EmbedImage *e = list_image.first(); while ( e ) { out << " { " << e->width << ", " << e->height << ", " << e->depth << ", " << "(const unsigned char*)" << e->cname << "_data, " << e->numColors << ", "; if ( e->numColors ) out << e->cname << "_ctable, "; else out << "0, "; if ( e->alpha ) out << "TRUE, "; else out << "FALSE, "; out << "\"" << e->name << "\" },\n"; e = list_image.next(); } out << "};\n"; out << "\n" "static int cmpEmbedImage(const void *a, const void *b)\n" "{\n" " const EmbedImage* ea = (const EmbedImage*)a;\n" " const EmbedImage* eb = (const EmbedImage*)b;\n" " return strcmp(ea->name,eb->name);\n" "}\n" "inline const QImage& qembed_findImage(const char* name)\n" "{\n" " EmbedImage key; key.name = name;\n" " EmbedImage* r = (EmbedImage*)bsearch( &key, embed_image_vec,\n" " sizeof(embed_image_vec)/sizeof(EmbedImage), sizeof(EmbedImage), cmpEmbedImage );\n" " QImage* img;\n" " if ( r ) {\n" " img = new QImage((uchar*)r->data,\n" " r->width,\n" " r->height,\n" " r->depth,\n" " (QRgb*)r->colorTable,\n" " r->numColors,\n" " QImage::BigEndian\n" " );\n" " if ( r->alpha )\n" " img->setAlphaBuffer(TRUE);\n" " } else {\n" " static QImage dummy;\n" " img = &dummy;\n" " }\n" " return *img;\n" "}\n\n"; } out << "#endif" << endl; return 0; }
QPoint Reversi::ai(const int player) { const int choices[8][8] = { {100, -100, 50, 30, 30, 50, -100, 100,}, {-100, -100, -50, -50, -50, -50, -100, -100,}, {50, -50, 10, 10, 10, 10, -50, 50,}, {30, -50, 10, 0, 0, 10, -50, 30,}, {30, -50, 10, 0, 0, 10, -50, 30,}, {50, -50, 10, 10, 10, 10, -50, 50,}, {-100, -100, -50, -50, -50, -50, -100, -100,}, {100, -100, 50, 30, 30, 50, -100, 100,}, }; QPointArray spaces = availableSpaces(player); if (spaces.size() == 0) return BoardGame::ai(player); int values[spaces.size()]; for (unsigned int i = 0; i < spaces.size(); i++) { QPoint p(spaces[i]); values[i] = choices[p.y()][p.x()] + reversible(p, player) * 5; } int max = 0; for (unsigned int i = 0; i < spaces.size(); i++) if (values[i] > values[max]) max = i; QList<int> equals; equals.setAutoDelete(true); for (unsigned int i = 0; i < spaces.size(); i++) if (values[i] == values[max]) equals.append(new int(i)); return spaces[*equals.at(rand() % equals.count())]; }
void CSSStyleDeclarationImpl::setProperty ( const DOMString &propertyString) { QList<CSSProperty> *props = parseProperties(propertyString.unicode(), propertyString.unicode()+propertyString.length()); if(!props || !props->count()) { kdDebug( 6080 ) << "no properties returned!" << endl; return; } props->setAutoDelete(false); unsigned int i = 0; if(!m_lstValues) { m_lstValues = new QList<CSSProperty>; m_lstValues->setAutoDelete( true ); } while(i < props->count()) { //kdDebug( 6080 ) << "setting property" << endl; CSSProperty *prop = props->at(i); removeProperty(prop->m_id); m_lstValues->append(prop); i++; } delete props; if (m_node) m_node->setChanged(true); }
BackupAndRestore::BackupAndRestore( QWidget* parent, const char* name, WFlags fl) : BackupAndRestoreBase(parent, name, fl) { backupList->header()->hide(); restoreList->header()->hide(); locationList->header()->hide(); connect( backupButton, SIGNAL( clicked() ), this, SLOT( backup() ) ); connect( restoreButton, SIGNAL( clicked() ), this, SLOT( restore() ) ); connect( backupList, SIGNAL( clicked( QListViewItem* ) ), this, SLOT( selectItem( QListViewItem* ) ) ); connect( restoreSource, SIGNAL( activated( int ) ), this, SLOT( sourceDirChanged( int ) ) ); connect( addLocationButton, SIGNAL( clicked() ), this, SLOT( addLocation() ) ); connect( removeLocationButton, SIGNAL( clicked() ), this, SLOT( removeLocation() ) ); connect( selectLocationButton, SIGNAL( clicked() ), this, SLOT( selectLocation() ) ); //add directorys for backing up applicationSettings = new QListViewItem(backupList, "Application Settings", "", "Settings/"); selectItem(applicationSettings); applicationSettings = new QListViewItem(backupList, "Application Data", "", "Applications/"); selectItem(applicationSettings); documents= new QListViewItem(backupList, "Documents", "", "Documents/"); selectItem(documents); scanForApplicationSettings(); refreshLocations(); refreshBackupLocations(); sourceDirChanged(restoreSource->currentItem()); // Read the list of items to ignore. QList<QString> dontBackupList; dontBackupList.setAutoDelete(true); Config config("BackupAndRestore"); config.setGroup("DontBackup"); int total = config.readNumEntry("Total", 0); for(int i = 0; i < total; i++) { dontBackupList.append(new QString(config.readEntry(QString("%1").arg(i), ""))); } QList<QListViewItem> list; getAllItems(backupList->firstChild(), list); for(uint i = 0; i < list.count(); i++) { QString text = list.at(i)->text(HEADER_NAME); for(uint i2 = 0; i2 < dontBackupList.count(); i2++) { if(*dontBackupList.at(i2) == text) { selectItem(list.at(i)); break; } } } QPEApplication::showWidget( this ); }
void VHDLLanguageScanner::parseInput(const char *fileName,const char *fileBuf,Entry *root, bool ,QStrList&) { g_thisParser=this; bool inLine=false; inputString=fileBuf; // fprintf(stderr,"\n ============= %s\n ==========\n",fileBuf); if (strlen(fileName)==0) { inLine=true; } yyFileName+=fileName; bool xilinx_ucf=isConstraintFile(yyFileName,".ucf"); bool altera_qsf=isConstraintFile(yyFileName,".qsf"); // support XILINX(ucf) and ALTERA (qsf) file if (xilinx_ucf) { VhdlDocGen::parseUCF(fileBuf,root,yyFileName,FALSE); return; } if (altera_qsf) { VhdlDocGen::parseUCF(fileBuf,root,yyFileName,TRUE); return; } libUse.setAutoDelete(true); yyLineNr=1; VhdlParser::current_root=root; VhdlParser::lastCompound=0; VhdlParser::lastEntity=0; VhdlParser::currentCompound=0; VhdlParser::lastEntity=0; VhdlParser::current=new Entry(); VhdlParser::initEntry(VhdlParser::current); groupEnterFile(fileName,yyLineNr); lineParse=new int[200]; // Dimitri: dangerous constant: should be bigger than largest token id in VhdlParserConstants.h VhdlParserIF::parseVhdlfile(fileBuf,inLine); delete VhdlParser::current; VhdlParser::current=0; if (!inLine) VhdlParser::mapLibPackage(root); delete[] lineParse; yyFileName.resize(0); libUse.clear(); VhdlDocGen::resetCodeVhdlParserState(); }
void Korn::dialogClosed(int ret ) { QList<KornBox> *list = _optionsDialog->list(); if( _noConfig && !ret) { ret = KMsgBox::yesNo(0, i18n("korn: no config set"), i18n("Would you like to restart korn with\n" "the automatically generated configuration?"), KMsgBox::QUESTION, i18n("Yes, Restart"), i18n("No, Exit")); if( ret == 2 ) { delete _optionsDialog; _optionsDialog = 0; qApp->quit(); return; } } if ( ret ) { // Here we should compare lists to see if any have // been deleted. If they have, they should be deleted // from the config as well. // NOTE: No such KConfig feature exists as yet. 9/Jun/97 writeOut ( list ); list->setAutoDelete( TRUE ); list->clear(); delete list; execvp( qApp->argv()[0], qApp->argv() ); } list->setAutoDelete( TRUE ); list->clear(); delete list; delete _optionsDialog; _optionsDialog = 0; }
QList<ArgumentList> *unmarshalArgumentLists(StorageIntf *s) { uint i; uint count = unmarshalUInt(s); if (count==NULL_LIST) return 0; // null list QList<ArgumentList> *result = new QList<ArgumentList>; result->setAutoDelete(TRUE); assert(count<1000000); //printf("unmarshalArgumentLists: %d\n",count); for (i=0;i<count;i++) { result->append(unmarshalArgumentList(s)); } return result; }
QList<Grouping> *unmarshalGroupingList(StorageIntf *s) { uint i; uint count = unmarshalUInt(s); if (count==NULL_LIST) return 0; // null list QList<Grouping> *result = new QList<Grouping>; result->setAutoDelete(TRUE); assert(count<1000000); for (i=0;i<count;i++) { QCString name = unmarshalQCString(s); Grouping::GroupPri_t prio = (Grouping::GroupPri_t)unmarshalInt(s); result->append(new Grouping(name,prio)); } return result; }
QList<ListItemInfo> *unmarshalItemInfoList(StorageIntf *s) { uint i; uint count = unmarshalUInt(s); if (count==NULL_LIST) return 0; // null list QList<ListItemInfo> *result = new QList<ListItemInfo>; result->setAutoDelete(TRUE); assert(count<1000000); for (i=0;i<count;i++) { ListItemInfo *lii = new ListItemInfo; lii->type = unmarshalQCString(s); lii->itemId = unmarshalInt(s); result->append(lii); } return result; }
QList<BaseInfo> *unmarshalBaseInfoList(StorageIntf *s) { uint i; uint count = unmarshalUInt(s); if (count==NULL_LIST) return 0; // null list QList<BaseInfo> *result = new QList<BaseInfo>; result->setAutoDelete(TRUE); assert(count<1000000); for (i=0;i<count;i++) { QCString name = unmarshalQCString(s); Protection prot = (Protection)unmarshalInt(s); Specifier virt = (Specifier)unmarshalInt(s); result->append(new BaseInfo(name,prot,virt)); } return result; }
QList<SectionInfo> *unmarshalSectionInfoList(StorageIntf *s) { uint i; uint count = unmarshalUInt(s); if (count==NULL_LIST) return 0; // null list QList<SectionInfo> *result = new QList<SectionInfo>; result->setAutoDelete(TRUE); assert(count<1000000); for (i=0; i<count; i++) { QCString label = unmarshalQCString(s); QCString title = unmarshalQCString(s); QCString ref = unmarshalQCString(s); SectionInfo::SectionType type = (SectionInfo::SectionType)unmarshalInt(s); QCString fileName = unmarshalQCString(s); result->append(new SectionInfo(fileName,label,title,type,ref)); } return result; }
void KFinder::itemList( QList<KFinderItem> &_list ) { _list.clear(); QList<KFinderNode> nodeList; nodeList.setAutoDelete( FALSE ); nodeList.append( finderWin->node ); KFinderNode *n; KFinderItem *item; QListIterator<KFinderNode> it(nodeList); for ( ; it.current(); ++it ) { n = it.current(); for ( item = n->first(); item != 0L; item = n->next() ) { _list.append( item ); nodeList.append( item->node() ); } } }
void CiteDict::generatePage() const { //printf("** CiteDict::generatePage() count=%d\n",m_ordering.count()); // do not generate an empty citations page if (isEmpty()) return; // nothing to cite // 1. generate file with markers and citations to OUTPUT_DIRECTORY QFile f; QCString outputDir = Config_getString("OUTPUT_DIRECTORY"); QCString citeListFile = outputDir+"/citelist.doc"; f.setName(citeListFile); if (!f.open(IO_WriteOnly)) { err("could not open file %s for writing\n",citeListFile.data()); } FTextStream t(&f); t << "<!-- BEGIN CITATIONS -->" << endl; t << "<!--" << endl; QDictIterator<CiteInfo> it(m_entries); CiteInfo *ci; for (it.toFirst();(ci=it.current());++it) { t << "\\citation{" << ci->label << "}" << endl; } t << "-->" << endl; t << "<!-- END CITATIONS -->" << endl; t << "<!-- BEGIN BIBLIOGRAPHY -->" << endl; t << "<!-- END BIBLIOGRAPHY -->" << endl; f.close(); // 2. generate bib2xhtml QCString bib2xhtmlFile = outputDir+"/bib2xhtml.pl"; f.setName(bib2xhtmlFile); QCString bib2xhtml = bib2xhtml_pl; if (!f.open(IO_WriteOnly)) { err("could not open file %s for writing\n",bib2xhtmlFile.data()); } f.writeBlock(bib2xhtml, bib2xhtml.length()); f.close(); // 3. generate doxygen.bst QCString doxygenBstFile = outputDir+"/doxygen.bst"; QCString bstData = doxygen_bst; f.setName(doxygenBstFile); if (!f.open(IO_WriteOnly)) { err("could not open file %s for writing\n",doxygenBstFile.data()); } f.writeBlock(bstData, bstData.length()); f.close(); // 4. for html we just copy the bib files to the output so that // bibtex can find them without path (bibtex doesn't support path's // with spaces!) QList<QCString> tempFiles; tempFiles.setAutoDelete(TRUE); QDir thisDir; if (Config_getBool("GENERATE_HTML")) { // copy bib files to the latex output dir QStrList &citeDataList = Config_getList("CITE_BIB_FILES"); QCString bibOutputDir = outputDir+"/"; QFileInfo fo(bibOutputDir); const char *bibdata = citeDataList.first(); while (bibdata) { QCString bibFile = bibdata; if (!bibFile.isEmpty() && bibFile.right(4)!=".bib") bibFile+=".bib"; QFileInfo fi(bibFile); if (fi.exists() && fi.dirPath(TRUE)!=fo.absFilePath()) { if (!bibFile.isEmpty()) { QCString destFile=bibOutputDir+fi.fileName().data(); copyFile(bibFile,destFile); tempFiles.append(new QCString(destFile)); } } else if (!fi.exists()) { err("bib file %s not found!\n",bibFile.data()); } bibdata = citeDataList.next(); } } QCString oldDir = QDir::currentDirPath().utf8(); QDir::setCurrent(outputDir); // 5. run bib2xhtml perl script on the generated file which will insert the // bibliography in citelist.doc portable_system("perl","\""+bib2xhtmlFile+"\" "+getListOfBibFiles(" ",FALSE)+" \""+ citeListFile+"\""); QDir::setCurrent(oldDir); // 6. read back the file f.setName(citeListFile); if (!f.open(IO_ReadOnly)) { err("could not open file %s/citelist.doc for reading\n",outputDir.data()); } bool insideBib=FALSE; QCString doc; QFileInfo fi(citeListFile); QCString input(fi.size()+1); f.readBlock(input.data(),fi.size()); f.close(); input.at(fi.size())='\0'; int p=0,s; //printf("input=[%s]\n",input.data()); while ((s=input.find('\n',p))!=-1) { QCString line = input.mid(p,s-p); //printf("p=%d s=%d line=[%s]\n",p,s,line.data()); p=s+1; if (line.find("<!-- BEGIN BIBLIOGRAPHY")!=-1) insideBib=TRUE; else if (line.find("<!-- END BIBLIOGRAPH")!=-1) insideBib=FALSE; else if (insideBib) doc+=line+"\n"; int i; // determine text to use at the location of the @cite command if (insideBib && (i=line.find("<a name=\"CITEREF_"))!=-1) { int j=line.find("\">["); int k=line.find("]</a>"); if (j!=-1 && k!=-1) { QCString label = line.mid(i+17,j-i-17); QCString number = line.mid(j+2,k-j-1); CiteInfo *ci = m_entries.find(label); //printf("label='%s' number='%s' => %p\n",label.data(),number.data(),ci); if (ci) { ci->text = number; } } } } //printf("doc=[%s]\n",doc.data()); // 7. add it as a page addRelatedPage(CiteConsts::fileName, theTranslator->trCiteReferences(),doc,0,CiteConsts::fileName,1,0,0,0); // 8. for latex we just copy the bib files to the output and let // latex do this work. if (Config_getBool("GENERATE_LATEX")) { // copy bib files to the latex output dir QStrList &citeDataList = Config_getList("CITE_BIB_FILES"); QCString latexOutputDir = Config_getString("LATEX_OUTPUT")+"/"; const char *bibdata = citeDataList.first(); while (bibdata) { QCString bibFile = bibdata; if (!bibFile.isEmpty() && bibFile.right(4)!=".bib") bibFile+=".bib"; QFileInfo fi(bibFile); if (fi.exists()) { if (!bibFile.isEmpty()) { copyFile(bibFile,latexOutputDir+fi.fileName().data()); } } else { err("bib file %s not found!\n",bibFile.data()); } bibdata = citeDataList.next(); } } // 9. Remove temporary files thisDir.remove(citeListFile); thisDir.remove(doxygenBstFile); thisDir.remove(bib2xhtmlFile); while (!tempFiles.isEmpty()) { QCString *s=tempFiles.take(0); thisDir.remove(*s); } }
int DoIt(const char* outFile, const char* regFile, const char* maskFile, const char* resultFile, int mask_x, int mask_y, int mask_size_x, int mask_size_y) { // Read maskfile FILE *mfp = fopen(maskFile, "r"); // FILE *mfp=fopen("/project/geoaida/tmp/mask.pbm","r"); if (!mfp) { fprintf(stderr, "mask file %s not found\n", maskFile); return 1; } GaMaskImage mask; mask.read(mfp); fclose(mfp); // read regionfile // QFile rfp("/project/geoaida/tmp/reglist.dest"); QFile rfp(regFile); if (!rfp.open(IO_ReadOnly)) { fprintf(stderr, "regionfile %s not founed\n", regFile); return 1; } // Read and process regions QList < ArgDict > regionList; regionList.setAutoDelete(true); MLParser parser(&rfp); QString keywords[] = { "region", "" }; const MLTagTable nodeTagTable(keywords); const int TOK_REGION = 1; int tag; do { tag = parser.tag(nodeTagTable); ArgDict *args; switch (tag) { case TOK_REGION:{ args = parser.args(); if (processRegion (*args, mask, mask_x, mask_y, mask_size_x, mask_size_y)) regionList.append(args); else delete args; break; } case -TOK_REGION: break; case MLParser::END_OF_FILE: break; default:{ args = parser.args(); delete args; qDebug("Unknown keyword %s in line %d", parser.lasttagstr().latin1(), parser.lineNumber()); break; } } } while (tag != MLParser::END_OF_FILE); rfp.close(); // Write labels if (outFile) { if (labelImageDict.count() > 1) { fprintf(stderr, "regionmask: Cannot generate multiple labelfiles\n"); return 1; } else { if (regionList.count()>0) { ArgDict *dict = regionList.first(); QString *oldfile = (*dict)["file"]; QString *labelfile = new QString(); if (resultFile) labelfile->sprintf("%s", resultFile); else labelfile->sprintf("%s.plm", outFile); LabelImage *im = labelImageDict.take(*oldfile); labelImageDict.replace(*labelfile, im); QListIterator < ArgDict > it(regionList); for (; it.current(); ++it) { ArgDict *argDict = it.current(); assert(argDict); argDict->replace("file", labelfile); } } } rfp.setName(outFile); } else { printf("regionmask: overwriting %s\n",regFile); outFile = regFile; } QDictIterator < LabelImage > git(labelImageDict); if (regionList.count()>0) { for (; git.current(); ++git) { LabelImage *im = git.current(); qDebug("Writing %s", git.currentKey().latin1()); im->image.write(git.currentKey().latin1()); } } // Write regions if (!rfp.open(IO_WriteOnly)) { fprintf(stderr, "cannot open regionfile %s for writing\n", outFile); return 1; } if (regionList.count()>0) { QListIterator < ArgDict > it(regionList); QTextStream ts(&rfp); for (; it.current(); ++it) { ArgDict *argDict = it.current(); assert(argDict); ts << "<region "; ts << (*argDict); ts << " />" << endl; } } rfp.close(); labelImageDict.setAutoDelete(true); labelImageDict.clear(); regionList.setAutoDelete(true); return 0; }
int DoIt(const char* outFile, const char* regFile, const char* maskFile, const char* resultFile, int mask_x, int mask_y, int mask_size_x, int mask_size_y) { // Read maskfile FILE *mfp = fopen(maskFile, "r"); // FILE *mfp=fopen("/project/geoaida/tmp/mask.pbm","r"); if (!mfp) { fprintf(stderr, "mask file %s not found\n", maskFile); return 1; } GaMaskImage mask; mask.read(mfp); fclose(mfp); QList<ArgDict> *regionSourceList=readRegionFile(regFile); if (!regionSourceList) return 1; QList<ArgDict> regionList; // Process regions for (ArgDict* arg = regionSourceList->first(); arg; arg=regionSourceList->next()) { ArgDict* args=new ArgDict(*arg); if (processRegion (*args, mask, mask_x, mask_y, mask_size_x, mask_size_y)) regionList.append(args); else delete args; } // Write labels QFile rfp(outFile ? outFile : regFile); if (outFile) { if (labelImageDict.count() > 1) { fprintf(stderr, "regionmask: Cannot generate multiple labelfiles\n"); return 1; } else { if (regionList.count()>0) { ArgDict *dict = regionList.first(); QString *oldfile = (*dict)["file"]; QString *labelfile = new QString(); if (resultFile) labelfile->sprintf("%s", resultFile); else labelfile->sprintf("%s.plm", outFile); LabelImage *im = labelImageDict.take(*oldfile); labelImageDict.replace(*labelfile, im); QListIterator < ArgDict > it(regionList); for (; it.current(); ++it) { ArgDict *argDict = it.current(); assert(argDict); argDict->replace("file", labelfile); } } } } else { printf("regionmask: overwriting %s\n",regFile); outFile = regFile; } QDictIterator < LabelImage > git(labelImageDict); if (regionList.count()>0) { for (; git.current(); ++git) { LabelImage *im = git.current(); qDebug("Writing %s", git.currentKey().latin1()); im->image.write(git.currentKey().latin1()); } } // Write regions if (!rfp.open(IO_WriteOnly)) { fprintf(stderr, "cannot open regionfile %s for writing\n", outFile); return 1; } if (regionList.count()>0) { QListIterator < ArgDict > it(regionList); QTextStream ts(&rfp); for (; it.current(); ++it) { ArgDict *argDict = it.current(); assert(argDict); ts << "<region "; ts << (*argDict); ts << " />" << endl; } } rfp.close(); labelImageDict.setAutoDelete(true); labelImageDict.clear(); regionList.setAutoDelete(true); return 0; }