void buildVariableDict(ClassDef *inst, ClassDef *cl)
{
	 MemberList *instPort=NULL;
	 MemberList *classPort=NULL;
      
	  instPortDict.clear();
	  classPortDict.clear();
   
    if(inst!=NULL)
        instPort=inst->getMemberList(MemberListType_variableMembers); 
	 
	if(cl!=NULL)
	 classPort=cl->getMemberList(MemberListType_variableMembers); 


	  if(instPort)
		  {
            MemberListIterator mnii(*instPort);
            MemberDef *md;
			for (mnii.toFirst();(md=mnii.current());++mnii){
				//printf("\n Inst: %s %s %s",md->name().data(),md->getOutputFileBase().data(),md->getReference().data());
				 instPortDict.insert(md->name().data(),md);
				}
		  }

	  if(classPort)
		  {
             MemberListIterator mnii(*classPort);
			 MemberDef *md;
			 for (mnii.toFirst();(md=mnii.current());++mnii){
			//	 printf("\n Class: %s %s %s",md->name().data(),md->getOutputFileBase().data(),md->getReference().data());
				 classPortDict.insert(md->name().data(),md);
				 }
		  }
}//funct
Пример #2
0
void init_images()
{
  DiagramPixmap.setAutoDelete(TRUE);
  DiagramPixmap.clear();
  
  DiagramScaledPixmap.setAutoDelete(TRUE);
  DiagramScaledPixmap.clear();
}
void buildVariableDict(ClassDef *cd)
{
   
if(cd==0) return;
variableDict.clear();

	MemberList* ml=cd->getMemberList(MemberListType_variableMembers); 
     if(ml)
		  {
             MemberListIterator mnii(*ml);
			 MemberDef *md;
             for (mnii.toFirst();(md=mnii.current());++mnii)
             {
               VerilogDocGen::adjustMemberName(md);
                variableDict.insert(md->name().data(),md);
              }
		 }

     ml=cd->getMemberList(MemberListType_pubMethods); 
	 if(ml)
		  {
             MemberListIterator mnii(*ml);
			 MemberDef *md;
             for (mnii.toFirst();(md=mnii.current());++mnii)
                variableDict.insert(md->name().data(),md);
		 }
}
void 
VerilogDocGen::buildGlobalVerilogVariableDict(const FileDef* fd,bool clear,int level)
{
   if(fd==0)return;
   
   if(clear)
   {
     globalMemDict.clear();
     classInnerDict.clear();
   }

 
   MemberDef *md=NULL;
   MemberList *ml=	fd->getMemberList(MemberListType_decVarMembers);
   if(ml!=NULL) 
   {
   MemberListIterator fmni(*ml);
      
	for (fmni.toFirst();(md=fmni.current());++fmni)
	{
		VerilogDocGen::adjustMemberName(md);
		//if(stricmp(md->typeString(),"include")==0)
		/*
	    if(!findIncludeName(md->name().data()))
		{
			//	printf("\n insert %s",md->name());	
			    includeMemList.append(md);
		}
		*/
   //		printf("\n %s ....  ",md->name().data());
   //		ClassDef *ch=md->getClassDef();
   //		if(ch==0)
		globalMemDict.insert(md->name().data(),md);
	}
   }

   ml=	fd->getMemberList( MemberListType_decFuncMembers);
   if(ml!=0)
   {
   MemberListIterator fmni(*ml);
   for (fmni.toFirst();(md=fmni.current());++fmni)
	{
		VerilogDocGen::adjustMemberName(md);
		globalMemDict.insert(md->name().data(),md);
	}
   }
  } 
Пример #5
0
/*! Finalizes the HTML help. This will finish and close the
 *  contents file (index.hhc) and the index file (index.hhk).
 *  \sa initialize()
 */
void HtmlHelp::finalize()
{
  // end the contents file
  cts << "</UL>\n";
  cts << "</BODY>\n";
  cts << "</HTML>\n";
  cts.unsetDevice();
  cf->close();
  delete cf;
  
  index->writeFields(kts);
  
  // end the index file
  kts << "</UL>\n";
  kts << "</BODY>\n";
  kts << "</HTML>\n";
  kts.unsetDevice();
  kf->close();
  delete kf;

  createProjectFile();
  s_languageDict.clear();
}
Пример #6
0
/**
 * Add entries to a variable. Will just add the variables to the existing line, removing duplicates
 * Will preserve += constructs and make sure that the variable only has one copy of the value across
 * all += constructs
 * @param fileName
 * @param variables key=value string of entries to add
 * @param add true= add these key,value pairs, false = remove. You can have empty values for an add - the whole line is
 * removed. For adding, we will not add an empty line.
 */
void AutoProjectTool::addRemoveMakefileam(const QString &fileName, QMap<QString, QString> variables,  bool add)
{
	// input file reading
	QFile fin(fileName);
	if (!fin.open(IO_ReadOnly))
	{
		return ;
	}
	QTextStream ins(&fin);

	// output file writing.
	QFile fout(fileName + "#");
	if (!fout.open(IO_WriteOnly))
	{
		fin.close();
		return ;
	}
	QTextStream outs(&fout);

	// variables
	QRegExp re("^(#kdevelop:[ \t]*)?([A-Za-z][@A-Za-z0-9_]*)[ \t]*([:\\+]?=)[ \t]*(.*)$");

	// build key=map of values to add
	// map can be empty.we never add an empty key, but do remove empty keys from the file..
	QDict< QMap<QString, bool> > interest;
	for (QMap<QString, QString>::Iterator it0 = variables.begin(); it0 != variables.end(); ++it0)
	{
		kdDebug(9020) << "key (" << add<<"): " << it0.key() << "="<< it0.data() << endl;

		QMap<QString, bool>* set = new QMap<QString, bool>();
		if (!it0.data().stripWhiteSpace().isEmpty())
		{
			QStringList variableList = QStringList::split(' ', it0.data());

			for (uint i = 0; i < variableList.count(); i++)
			{
				set->insert(variableList[i], true);
			}
		}
		interest.insert(it0.key(), set);
	}

	bool multiLine = false;
	QString lastLhs;
	QStringList lastRhs;
	QMap<QString, QString> seenLhs;
	while (!fin.atEnd())
	{
		QString s = ins.readLine();
		if (re.exactMatch(s))
		{
			QString lhs = re.cap(2);
			QMap<QString, bool>* ourRhs = interest.find(lhs);

			if (!ourRhs)
			{
				// not interested in this line at all
				// write it out as is..
				outs << s << endl;
			}
			else
			{
				// we are interested in this line..
				QString rhs = re.cap(4).stripWhiteSpace();
				if (rhs[ rhs.length() - 1 ] == '\\')
				{
					// save it for when we have the whole line..
					multiLine = true;
					lastLhs = lhs;
					rhs.setLength(rhs.length() - 1);
					lastRhs += QStringList::split(" ", rhs);
				}
				else
				{
					// deal with it now.

					QStringList bits = QStringList::split(" ", rhs);
					if (add)
					{
						// we are adding our interested values to this line and writing it

						// add this line to we we want to add to remove duplicates.
						for (uint index = 0; index < bits.size(); index++)
						{
							QMap<QString, bool>::iterator findEntry = ourRhs->find(bits[index]);
							if (findEntry == ourRhs->end())
							{
								// we haven't seen it, so add it, so we don't add it again later..
								ourRhs->insert(bits[index], true);
							}
							// else we have this value in our 'to add list' , it is either already been
							// added, so we don't want to add it again, or it hasn't been added, in which
							// case we will do so soon. so we can ignore this now..
						}
						// now write the line out if it is not going to be empty.
						QString newLine(lhs);
						if (seenLhs.find(lhs) == seenLhs.end())
						{
							newLine += " = ";
							seenLhs[lhs] = "";
						}
						else
						{
							newLine += " += ";
						}

						int len = newLine.length();
						bool added = false;
						QValueList<QString> keys = ourRhs->keys();
						for (uint count = 0; count < keys.size(); count++)
						{
							// if out entry is true, add it..
							if ((*ourRhs)[keys[count]])
							{
								added = true;
								len += keys[count].length() + 1;
								if (len > 80)
								{
									newLine += "\\\n\t";
									len = 8;
								}
								newLine += keys[count];
								newLine += ' ';
								// set our value so we don't add it again.
								(*ourRhs)[keys[count]] = false;
							}
						}
						// only print it out if there was a value to add..
						if (added)
						{
							newLine.setLength(newLine.length() - 1);
							outs << newLine << endl;
						}
					}
					else
					{
						// we are removing our interested values from this line

						// special case - no values, remove the line..
						if (!ourRhs->empty())
						{
							// check if any of these values are down to remove.
							QString newLine(lhs);
							if (seenLhs.find(lhs) == seenLhs.end())
							{
								newLine += " = ";
								seenLhs[lhs] = "";
							}
							else
							{
								newLine += " += ";
							}

							int len = newLine.length();
							bool added = false;
							for (QStringList::Iterator posIter = bits.begin(); posIter != bits.end();posIter++)
							{
								QMap<QString, bool>::iterator findEntry = ourRhs->find(*posIter);
								if (findEntry == ourRhs->end())
								{
									// we do not want to remove it..
									added = true;
									len += (*posIter).length() + 1;
									if (len > 80)
									{
										newLine += "\\\n\t";
										len = 8;
									}
									newLine += (*posIter);
									newLine += ' ';
								}
								// else we have this value in our 'to remove list', so don't add it.
							}
							// only print it out if there was a value on it..
							if (added)
							{
								newLine.setLength(newLine.length() - 1);
								outs << newLine << endl;
							}
						}
					}//if (add)
				}//if ( rhs[ rhs.length() - 1 ] == '\\'  )
			}//if ( found == interest.end())
		}
		else if (multiLine)
		{
			s = s.stripWhiteSpace();
			// we are only here if were interested in this line..
			if (s[s.length()-1] == '\\')
			{
				s.setLength(s.length() - 1);
				// still more multi line we wait for..
			}
			else
			{
				// end of the multi line..
				multiLine = false;
			}
			lastRhs += QStringList::split(" ", s);

			if (!multiLine)
			{
				// now we have to deal with this multiLine value..
				// ourRhs will always be a value, as we only get multiLine if we're interested in it..
				QMap<QString, bool>* ourRhs = interest.find(lastLhs);

				if (add)
				{
					// we are adding our interested values to this line and writing it

					// add this line to we we want to add to remove duplicates.
					for (uint index = 0; index < lastRhs.size(); index++)
					{
						QMap<QString, bool>::iterator findEntry = ourRhs->find(lastRhs[index]);
						if (findEntry == ourRhs->end())
						{
							// we haven't seen it, so add it, so we don't add it again later..
							ourRhs->insert(lastRhs[index], true);
						}
						// else we have this value in our 'to add list' , it is either already been
						// added, so we don't want to add it again, or it hasn't been added, in which
						// case we will do so soon. so we can ignore this now..
					}
					// now write the line out if it is not going to be empty.
					QString newLine(lastLhs);
					if (seenLhs.find(lastLhs) == seenLhs.end())
					{
						newLine += " = ";
						seenLhs[lastLhs] = "";
					}
					else
					{
						newLine += " += ";
					}

					int len = newLine.length();
					bool added = false;
					QValueList<QString> keys = ourRhs->keys();
					for (uint count = 0; count < keys.size(); count++)
					{
						// if out entry is true, add it..
						if ((*ourRhs)[keys[count]])
						{
							added = true;
							len += keys[count].length() + 1;
							if (len > 80)
							{
								newLine += "\\\n\t";
								len = 8;
							}
							newLine += keys[count];
							newLine += ' ';
							// set our value so we don't add it again.
							(*ourRhs)[keys[count]] = false;
						}
					}
					// only print it out if there was a value to add..
					if (added)
					{
						newLine.setLength(newLine.length() - 1);
						outs << newLine << endl;
					}
				}
				else
				{
					// we are removing our interested values from this line
					// special case - no values, remove the line..
					if (!ourRhs->empty())
					{
						// check if any of these values are down to remove.
						QString newLine(lastLhs);
						if (seenLhs.find(lastLhs) == seenLhs.end())
						{
							newLine += " = ";
							seenLhs[lastLhs] = "";
						}
						else
						{
							newLine += " += ";
						}
						int len = newLine.length();
						bool added = false;
						for (QStringList::Iterator posIter = lastRhs.begin(); posIter != lastRhs.end();posIter++)
						{
							QMap<QString, bool>::iterator findEntry = ourRhs->find(*posIter);
							if (findEntry == ourRhs->end())
							{
								// we do not want to remove it..
								added = true;
								len += (*posIter).length() + 1;
								if (len > 80)
								{
									newLine += "\\\n\t";
									len = 8;
								}
								newLine += (*posIter);
								newLine += ' ';
							}
							// else we have this value in our 'to remove list', so don't add it.
						}
						// only print it out if there was a value on it..
						if (added)
						{
							newLine.setLength(newLine.length() - 1);
							outs << newLine << endl;
						}
					}
				}

				lastLhs.setLength(0);
				lastRhs.clear();
			}
		}
		else
		{
			// can write this line out..
			// not a match, not a multi line,
			outs << s << endl;
		}
	}

	if (add)
	{
		QDictIterator<QMap<QString, bool> > it(interest);
		for (; it.current(); ++it)
		{
			QString lhs = it.currentKey();
			QMap<QString, bool>* ourRhs = it.current();

			QString newLine(lhs);
			if (seenLhs.find(lhs) == seenLhs.end())
			{
				newLine += " = ";
				seenLhs[lastLhs] = "";
			}
			else
			{
				newLine += " += ";
			}
			int len = newLine.length();
			bool added = false;
			QValueList<QString> keys = ourRhs->keys();
			for (uint count = 0; count < keys.size(); count++)
			{
				if ((*ourRhs)[keys[count]])
				{
					added = true;
					len += keys[count].length() + 1;
					if (len > 80)
					{
						newLine += "\\\n\t";
						len = 8;
					}
					newLine += keys[count];
					newLine += ' ';
					// set our value so we don't add it again.
					(*ourRhs)[keys[count]] = false;
				}
			}
			// only print it out if there was a value to add..
			if (added)
			{
				newLine.setLength(newLine.length() - 1);
				outs << newLine << endl;
			}
		}
	}
	interest.setAutoDelete(true);
	interest.clear();

	fin.close();
	fout.close();

	QDir().rename(fileName + "#", fileName);
}
Пример #7
0
/**
 * Reads all path= entries from the smb.conf file
 * and fills the sharedPaths dict with the values
 */
bool KSambaSharePrivate::readSmbConf() {
  QFile f(smbConf);

  kdDebug(7000) << "KSambaShare::readSmbConf " << smbConf << endl;
  
  if (!f.open(IO_ReadOnly)) {
    kdError() << "KSambaShare: Could not open " << smbConf << endl;
    return false;
  }
  
  sharedPaths.clear();

  QTextStream s(&f);

  bool continuedLine = false; // is true if the line before ended with a backslash
  QString completeLine;

  while (!s.eof())
  {
    QString currentLine = s.readLine().stripWhiteSpace();

    if (continuedLine) {
      completeLine += currentLine;
      continuedLine = false;
    }      
    else
      completeLine = currentLine;

    // is the line continued in the next line ?
    if ( completeLine[completeLine.length()-1] == '\\' )
    {
      continuedLine = true;
      // remove the ending backslash
      completeLine.truncate( completeLine.length()-1 ); 
      continue;
    }
    
    // comments or empty lines
    if (completeLine.isEmpty() ||
        '#' == completeLine[0] ||
        ';' == completeLine[0])
    {
      continue;
    }

    // parameter
    int i = completeLine.find('=');

    if (i>-1)
    {
      QString name = completeLine.left(i).stripWhiteSpace().lower();
      QString value = completeLine.mid(i+1).stripWhiteSpace();

      if (name == KGlobal::staticQString("path")) {
        // Handle quotation marks
        if ( value[0] == '"' )
          value.remove(0,1);
         
        if ( value[value.length()-1] == '"' )
          value.truncate(value.length()-1);        
        
        // Normalize path
        if ( value[value.length()-1] != '/' )
             value += '/';
             
        bool b = true;             
        sharedPaths.insert(value,&b);
        kdDebug(7000) << "KSambaShare: Found path: " << value << endl;
      }
    }
  }

  f.close();

  return true;  

}
Пример #8
0
/*! This will create a contents file (index.hhc) and a index file (index.hhk)
 *  and write the header of those files. 
 *  It also creates a project file (index.hhp)
 *  \sa finalize()
 */
void HtmlHelp::initialize()
{
  const char *str = Config_getString("CHM_INDEX_ENCODING");
  if (!str) str = "CP1250"; // use safe and likely default
  m_fromUtf8 = portable_iconv_open(str,"UTF-8"); 
  if (m_fromUtf8==(void *)(-1))
  {
    err("Error: unsupported character conversion for CHM_INDEX_ENCODING: '%s'->'UTF-8'\n", str);
    exit(1);
  }

  /* open the contents file */
  QCString fName = Config_getString("HTML_OUTPUT") + "/index.hhc";
  cf = new QFile(fName);
  if (!cf->open(IO_WriteOnly))
  {
    err("Could not open file %s for writing\n",fName.data());
    exit(1);
  }
  /* Write the header of the contents file */
  cts.setDevice(cf);
  cts << "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n"
         "<HTML><HEAD></HEAD><BODY>\n"
         "<OBJECT type=\"text/site properties\">\n"
         "<param name=\"FrameName\" value=\"right\">\n"
         "</OBJECT>\n"
         "<UL>\n";
  
  /* open the contents file */
  fName = Config_getString("HTML_OUTPUT") + "/index.hhk";
  kf = new QFile(fName);
  if (!kf->open(IO_WriteOnly))
  {
    err("Could not open file %s for writing\n",fName.data());
    exit(1);
  }
  /* Write the header of the contents file */
  kts.setDevice(kf);
  kts << "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML//EN\">\n"
         "<HTML><HEAD></HEAD><BODY>\n"
         "<OBJECT type=\"text/site properties\">\n"
         "<param name=\"FrameName\" value=\"right\">\n"
         "</OBJECT>\n"
         "<UL>\n";

  /* language codes for Html help
     0x405 Czech
     0x406 Danish
     0x413 Dutch
     0xC09 English (Australia)
     0x809 English (Britain)
     0x1009 English (Canada)
     0x1809 English (Ireland)
     0x1409 English (New Zealand)
     0x1C09 English (South Africa)
     0x409 English (United States)
     0x40B Finnish
     0x40C French
     0x407 German
     0x408 Greece
     0x40E Hungarian
     0x410 Italian
     0x814 Norwegian
     0x415 Polish
     0x816 Portuguese(Portugal)
     0x416 Portuguese(Brazil)
     0x419 Russian
     0x80A Spanish(Mexico)
     0xC0A Spanish(Modern Sort)
     0x40A Spanish(Traditional Sort)
     0x41D Swedish
     0x41F Turkey
     0x411 Japanese
     0x412 Korean
     0x804 Chinese (PRC)
     0x404 Chinese (Taiwan)

     New LCIDs:
	 0x421 Indonesian
	 0x41A Croatian
	 0x418 Romanian
	 0x424 Slovenian
	 0x41B Slovak
	 0x422 Ukrainian
	 0x81A Serbian (Serbia, Latin)
	 0x403 Catalan
	 0x427 Lithuanian
	 0x436 Afrikaans
	 0x42A Vietnamese
	 0x429 Persian (Iran)
	 0xC01 Arabic (Egypt) - I don't know which version of arabic is used inside translator_ar.h ,
     so I have chosen Egypt at random

  */
  s_languageDict.setAutoDelete(TRUE);
  s_languageDict.clear();
  s_languageDict.insert("czech",       new QCString("0x405 Czech"));
  s_languageDict.insert("danish",      new QCString("0x406 Danish"));
  s_languageDict.insert("dutch",       new QCString("0x413 Dutch"));
  s_languageDict.insert("finnish",     new QCString("0x40B Finnish"));
  s_languageDict.insert("french",      new QCString("0x40C French"));
  s_languageDict.insert("german",      new QCString("0x407 German"));
  s_languageDict.insert("greek",       new QCString("0x408 Greece"));
  s_languageDict.insert("hungarian",   new QCString("0x40E Hungarian"));
  s_languageDict.insert("italian",     new QCString("0x410 Italian"));
  s_languageDict.insert("norwegian",   new QCString("0x814 Norwegian"));
  s_languageDict.insert("polish",      new QCString("0x415 Polish"));
  s_languageDict.insert("portuguese",  new QCString("0x816 Portuguese(Portugal)"));
  s_languageDict.insert("brazil",      new QCString("0x416 Portuguese(Brazil)"));
  s_languageDict.insert("russian",     new QCString("0x419 Russian"));
  s_languageDict.insert("spanish",     new QCString("0x40A Spanish(Traditional Sort)"));
  s_languageDict.insert("swedish",     new QCString("0x41D Swedish"));
  s_languageDict.insert("turkish",     new QCString("0x41F Turkey"));
  s_languageDict.insert("japanese",    new QCString("0x411 Japanese"));
  s_languageDict.insert("japanese-en", new QCString("0x411 Japanese"));
  s_languageDict.insert("korean",      new QCString("0x412 Korean"));
  s_languageDict.insert("korean-en",   new QCString("0x412 Korean"));
  s_languageDict.insert("chinese",     new QCString("0x804 Chinese (PRC)"));
  s_languageDict.insert("chinese-traditional", new QCString("0x404 Chinese (Taiwan)"));

  // new LCIDs
  s_languageDict.insert("indonesian",  new QCString("0x412 Indonesian"));
  s_languageDict.insert("croatian",    new QCString("0x41A Croatian"));
  s_languageDict.insert("romanian",    new QCString("0x418 Romanian"));
  s_languageDict.insert("slovene",     new QCString("0x424 Slovenian"));
  s_languageDict.insert("slovak",      new QCString("0x41B Slovak"));
  s_languageDict.insert("ukrainian",   new QCString("0x422 Ukrainian"));
  s_languageDict.insert("serbian",     new QCString("0x81A Serbian (Serbia, Latin)"));
  s_languageDict.insert("catalan",     new QCString("0x403 Catalan"));
  s_languageDict.insert("lithuanian",  new QCString("0x427 Lithuanian"));
  s_languageDict.insert("afrikaans",   new QCString("0x436 Afrikaans"));
  s_languageDict.insert("vietnamese",  new QCString("0x42A Vietnamese"));
  s_languageDict.insert("persian",     new QCString("0x429 Persian (Iran)"));
  s_languageDict.insert("arabic",      new QCString("0xC01 Arabic (Egypt)"));
}
Пример #9
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);

  // 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;
}
Пример #10
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;
}