예제 #1
0
void UmlClassItem::remove_comments(QCString & s)
{
  int index1 = 0;
  
  while ((index1 = s.find('/', index1)) != -1) {
    int index2;
    
    switch (((const char *) s)[index1 + 1]) {
    case '/':
      if ((index2 = s.find('\n', index1 + 2)) != -1)
	s.remove(index1, index2 - index1 + 1);
      else
	s.truncate(index1);
      break;
    case '*':
      if ((index2 = s.find("*/", index1 + 2)) != -1)
	s.replace(index1, index2 - index1 + 1, " ");
      else
	s.truncate(index1);
      break;
    default:
      index1 += 1;
    }
  }
}
예제 #2
0
void UmlOperation::write_cpp_returntype(FileOut & out, QCString decl) {
  // doesn't manage function pointer
  // manage keywords
  int index;
  
  if ((index = decl.find("${static}")) != -1)
    decl.remove(index, 9);
  
  if ((index = decl.find("${friend}")) != -1)
    decl.remove(index, 9);
  
  if ((index = decl.find("${virtual}")) != -1)
    decl.remove(index, 10);
  
  if ((index = decl.find("${inline}")) != -1)
    decl.remove(index, 9);
  
  if ((index = decl.find("${(}")) == -1)
    decl = "${type} ${name}";
  else
    decl.truncate(index);
  
  UmlTypeSpec t = returnType();
  
  if ((t.type != 0) ||
      !(t.explicit_type = CppSettings::type(t.explicit_type)).isEmpty())
    write_type(out, t, decl, "${name}", "${type}");
}
예제 #3
0
void UmlOperation::write_java_returntype(FileOut & out, QCString decl) {
// manage keywords
int index;

if ((index = decl.find("${visibility}")) != -1)
  decl.remove(index, 13);

if ((index = decl.find("${final}")) != -1)
  decl.remove(index, 8);

if ((index = decl.find("${static}")) != -1)
  decl.remove(index, 9);

if ((index = decl.find("${abstract}")) != -1)
  decl.remove(index, 11);

if ((index = decl.find("${synchronized}")) != -1)
  decl.remove(index, 15);

if ((index = decl.find("${@}")) != -1)
  decl.remove(index, 4);

if ((index = decl.find("${(}")) == -1)
  decl = "${type} ${name}";
else
  decl.truncate(index);

UmlTypeSpec t = returnType();

if ((t.type != 0) ||
    !(t.explicit_type = JavaSettings::type(t.explicit_type)).isEmpty())
  write_type(out, t, decl, "${name}", "${type}");
}
예제 #4
0
bool endsWith(QCString &id, char c)
{
    if(id.length() && (id[id.length() - 1] == c))
    {
        id.truncate(id.length() - 1);
        return true;
    }
    return false;
}
예제 #5
0
void UmlClassItem::remove_arrays(QCString & s)
{
  int index1 = 0;
  
  while ((index1 = s.find('[', index1)) != -1) {
    int index2 = index1 = s.find(']', index1 + 1);
    
    if (index2 == -1) {
      s.truncate(index1);
      return;
    }
    else
      s.replace(index1, index2 - index1 + 1, " ");
  }
}
예제 #6
0
int KConfigBase::readListEntry(const char *pKey, QStrList &list, char sep) const
{
    if(!hasKey(pKey))
        return 0;

    QCString str_list = readEntryUtf8(pKey);
    if(str_list.isEmpty())
        return 0;

    list.clear();
    QCString value = "";
    int len = str_list.length();

    for(int i = 0; i < len; i++)
    {
        if(str_list[i] != sep && str_list[i] != '\\')
        {
            value += str_list[i];
            continue;
        }
        if(str_list[i] == '\\')
        {
            i++;
            if(i < len)
                value += str_list[i];
            continue;
        }
        // if we fell through to here, we are at a separator.  Append
        // contents of value to the list
        // !!! Sergey A. Sukiyazov <*****@*****.**> !!!
        // A QStrList may contain values in 8bit locale cpecified
        // encoding
        list.append(value);
        value.truncate(0);
    }

    if(str_list[len - 1] != sep || (len > 1 && str_list[len - 2] == '\\'))
        list.append(value);
    return list.count();
}
예제 #7
0
void UmlClassItem::remove_preprocessor(QCString & s)
{
  int index = 0;
  
  while ((index = s.find('#', index)) != -1) {
    // remove all up to the end of line
    int index2 = index + 1;
    int index3;
    
    while ((index3 = s.find('\n', index2)) != -1) {
      // manage multi lines #define
      if (((const char *) s)[index3 - 1] != '\\')
	break;
      else
	index2 = index3 + 1;
    }
    
    // the \n is still here to hava a separator
    if (index3 == -1)
      s.truncate(index);
    else
      s.remove(index, index3 - index);
  }
}
예제 #8
0
int main( int argc, char** argv )
{
	QString defaultContext = "@default";
	MetaTranslator fetchedTor;
	QCString codec;
	QStringList tsFileNames;

	bool verbose = FALSE;
	bool noObsolete = FALSE;
	bool metSomething = FALSE;
	int numFiles = 0;
	bool standardSyntax = TRUE;
	bool metTsFlag = FALSE;

	int i;

	for ( i = 1; i < argc; i++ )
	{
		if ( qstrcmp( argv[i], "-ts" ) == 0 )
			standardSyntax = FALSE;
	}

	for ( i = 1; i < argc; i++ )
	{
		if ( qstrcmp( argv[i], "-help" ) == 0 )
		{
			printUsage();
			return 0;
		}
		else if ( qstrcmp( argv[i], "-noobsolete" ) == 0 )
		{
			noObsolete = TRUE;
			continue;
		}
		else if ( qstrcmp( argv[i], "-verbose" ) == 0 )
		{
			verbose = TRUE;
			continue;
		}
		else if ( qstrcmp( argv[i], "-version" ) == 0 )
		{
			fprintf( stderr, "lupdate version %s\n", QT_VERSION_STR );
			return 0;
		}
		else if ( qstrcmp( argv[i], "-ts" ) == 0 )
		{
			metTsFlag = TRUE;
			continue;
		}

		numFiles++;

		QString fullText;

		if ( !metTsFlag )
		{
			QFile f( argv[i] );
			if ( !f.open( IO_ReadOnly ) )
			{
				fprintf( stderr, "lupdate error: Cannot open file '%s': %s\n", argv[i], strerror( errno ) );
				return 1;
			}

			QTextStream t( &f );
			fullText = t.read();
			f.close();
		}

		QString oldDir = QDir::currentDirPath();
		QDir::setCurrent( QFileInfo( argv[i] ).dirPath() );

		if ( standardSyntax )
		{
			fetchedTor = MetaTranslator();
			codec.truncate( 0 );
			tsFileNames.clear();

			QMap<QString, QString> tagMap = proFileTagMap( fullText );
			QMap<QString, QString>::Iterator it;

			for ( it = tagMap.begin(); it != tagMap.end(); ++it )
			{
				QStringList toks = QStringList::split( ' ', it.data() );
				QStringList::Iterator t;

				for ( t = toks.begin(); t != toks.end(); ++t )
				{
					if ( it.key() == "HEADERS" || it.key() == "SOURCES" )
					{
						fetchtr_cpp( *t, &fetchedTor, defaultContext, TRUE );
						metSomething = TRUE;
					}
					else if ( it.key() == "INTERFACES" || it.key() == "FORMS" )
					{
						fetchtr_ui( *t, &fetchedTor, defaultContext, TRUE );
						fetchtr_cpp( *t + ".h", &fetchedTor, defaultContext, FALSE );
						metSomething = TRUE;
					}
					else if ( it.key() == "TRANSLATIONS" )
					{
						tsFileNames.append( *t );
						metSomething = TRUE;
					}
					else if ( it.key() == "CODEC" || it.key() == "DEFAULTCODEC" )
					{
						codec = ( *t ).latin1();
					}
					else if ( it.key() == "WPDEFINITIONS" )
					{
						lookForDefinitions( *t, "*.xml", &fetchedTor, &fetchtr_xml );
					}
					else if ( it.key() == "WPSCRIPTS" )
					{
						lookForDefinitions( *t, "*.py", &fetchedTor, &fetchtr_py );
					}
				}
			}
			
			updateTsFiles( fetchedTor, tsFileNames, codec, noObsolete, verbose );

			if ( !metSomething )
			{
				fprintf( stderr, "lupdate warning: File '%s' does not look like a"
			 " project file\n", argv[i] );
			}
			else if ( tsFileNames.isEmpty() )
			{
				fprintf( stderr, "lupdate warning: Met no 'TRANSLATIONS' entry in"
			 " project file '%s'\n", argv[i] );
			}
		}
		else
		{
			if ( metTsFlag )
			{
				if ( QString( argv[i] ).lower().endsWith( ".ts" ) )
				{
					QFileInfo fi( argv[i] );
					if ( !fi.exists() || fi.isWritable() )
					{
						tsFileNames.append( argv[i] );
					}
					else
					{
						fprintf( stderr, "lupdate warning: For some reason, I cannot"
				 " save '%s'\n", argv[i] );
					}
				}
				else
				{
					fprintf( stderr, "lupdate error: File '%s' lacks .ts extension\n", argv[i] );
				}
			}
			else
			{
				QFileInfo fi( argv[i] );
				if ( QString( argv[i] ).lower().endsWith( ".ui" ) )
				{
					fetchtr_ui( fi.fileName(), &fetchedTor, defaultContext, TRUE );
					fetchtr_cpp( QString( fi.fileName() ) + ".h", &fetchedTor, defaultContext, FALSE );
				}
				else if ( QString( argv[i] ).lower().endsWith( ".xml" ) )
				{
					fetchtr_xml( fi.fileName(), &fetchedTor, 0, TRUE );
				}
				else if ( QString( argv[i] ).lower().endsWith( ".py" ) )
				{
					fetchtr_py( fi.fileName(), &fetchedTor, 0, TRUE );
				}
				else
				{
					fetchtr_cpp( fi.fileName(), &fetchedTor, defaultContext, TRUE );
				}
			}
		}
		QDir::setCurrent( oldDir );
	}

	if ( !standardSyntax )
		updateTsFiles( fetchedTor, tsFileNames, codec, noObsolete, verbose );

	if ( numFiles == 0 )
	{
		printUsage();
		return 1;
	}
	return 0;
}
예제 #9
0
//-----------------------------------------------------------------------------
// Used by KPIM::splitAddress(...) and KPIM::getFirstEmailAddress(...).
KPIM::EmailParseResult splitAddressInternal( const QCString& address,
                                             QCString & displayName,
                                             QCString & addrSpec,
                                             QCString & comment,
                                             bool allowMultipleAddresses )
{
//  kdDebug() << "KMMessage::splitAddress( " << address << " )" << endl;

  displayName = "";
  addrSpec = "";
  comment = "";

  if ( address.isEmpty() )
    return KPIM::AddressEmpty;

  // The following is a primitive parser for a mailbox-list (cf. RFC 2822).
  // The purpose is to extract a displayable string from the mailboxes.
  // Comments in the addr-spec are not handled. No error checking is done.

  enum { TopLevel, InComment, InAngleAddress } context = TopLevel;
  bool inQuotedString = false;
  int commentLevel = 0;
  bool stop = false;

  for ( char* p = address.data(); *p && !stop; ++p ) {
    switch ( context ) {
    case TopLevel : {
      switch ( *p ) {
      case '"' : inQuotedString = !inQuotedString;
                 displayName += *p;
                 break;
      case '(' : if ( !inQuotedString ) {
                   context = InComment;
                   commentLevel = 1;
                 }
                 else
                   displayName += *p;
                 break;
      case '<' : if ( !inQuotedString ) {
                   context = InAngleAddress;
                 }
                 else
                   displayName += *p;
                 break;
      case '\\' : // quoted character
                 displayName += *p;
                 ++p; // skip the '\'
                 if ( *p )
                   displayName += *p;
                 else
                   return KPIM::UnexpectedEnd;
                 break;
          case ',' :
          case ';' : if ( !inQuotedString ) {
                   if ( allowMultipleAddresses )
                     stop = true;
                   else
                     return KPIM::UnexpectedComma;
                 }
                 else
                   displayName += *p;
                 break;
      default :  displayName += *p;
      }
      break;
    }
    case InComment : {
      switch ( *p ) {
      case '(' : ++commentLevel;
                 comment += *p;
                 break;
      case ')' : --commentLevel;
                 if ( commentLevel == 0 ) {
                   context = TopLevel;
                   comment += ' '; // separate the text of several comments
                 }
                 else
                   comment += *p;
                 break;
      case '\\' : // quoted character
                 comment += *p;
                 ++p; // skip the '\'
                 if ( *p )
                   comment += *p;
                 else
                   return KPIM::UnexpectedEnd;
                 break;
      default :  comment += *p;
      }
      break;
    }
    case InAngleAddress : {
      switch ( *p ) {
      case '"' : inQuotedString = !inQuotedString;
                 addrSpec += *p;
                 break;
      case '>' : if ( !inQuotedString ) {
                   context = TopLevel;
                 }
                 else
                   addrSpec += *p;
                 break;
      case '\\' : // quoted character
                 addrSpec += *p;
                 ++p; // skip the '\'
                 if ( *p )
                   addrSpec += *p;
                 else
                   return KPIM::UnexpectedEnd;
                 break;
      default :  addrSpec += *p;
      }
      break;
    }
    } // switch ( context )
  }
  // check for errors
  if ( inQuotedString )
    return KPIM::UnbalancedQuote;
  if ( context == InComment )
    return KPIM::UnbalancedParens;
  if ( context == InAngleAddress )
    return KPIM::UnclosedAngleAddr;

  displayName = displayName.stripWhiteSpace();
  comment = comment.stripWhiteSpace();
  addrSpec = addrSpec.stripWhiteSpace();

  if ( addrSpec.isEmpty() ) {
    if ( displayName.isEmpty() )
      return KPIM::NoAddressSpec;
    else {
      addrSpec = displayName;
      displayName.truncate( 0 );
    }
  }
/*
  kdDebug() << "display-name : \"" << displayName << "\"" << endl;
  kdDebug() << "comment      : \"" << comment << "\"" << endl;
  kdDebug() << "addr-spec    : \"" << addrSpec << "\"" << endl;
*/
  return KPIM::AddressOk;
}
예제 #10
0
/*! Reads a fragment of code from file \a fileName starting at 
 * line \a startLine and ending at line \a endLine (inclusive). The fragment is
 * stored in \a result. If FALSE is returned the code fragment could not be
 * found.
 *
 * The file is scanned for a opening bracket ('{') from \a startLine onward
 * The line actually containing the bracket is returned via startLine.
 * The file is scanned for a closing bracket ('}') from \a endLine backward.
 * The line actually containing the bracket is returned via endLine.
 * Note that for VHDL code the bracket search is not done.
 */
static bool readCodeFragment(const char *fileName,
                      int &startLine,int &endLine,QCString &result)
{
  static bool vhdlOpt           = Config_getBool("OPTIMIZE_OUTPUT_VHDL");
  static bool filterSourceFiles = Config_getBool("FILTER_SOURCE_FILES");
  //printf("readCodeFragment(%s,%d,%d)\n",fileName,startLine,endLine);
  if (fileName==0 || fileName[0]==0) return FALSE; // not a valid file name
  QCString filter = getFileFilter(fileName,TRUE);
  FILE *f=0;
  bool usePipe = !filter.isEmpty() && filterSourceFiles;
  if (!usePipe) // no filter given or wanted
  {
    f = portable_fopen(fileName,"r");
  }
  else // use filter
  {
    QCString cmd=filter+" \""+fileName+"\"";
    Debug::print(Debug::ExtCmd,0,"Executing popen(`%s`)\n",cmd.data());
    f = portable_popen(cmd,"r");
  }
  bool found=vhdlOpt;  // for VHDL no bracket search is possible
  if (f)
  {
    int c=0;
    int col=0;
    int lineNr=1;
    // skip until the startLine has reached
    while (lineNr<startLine && !feof(f))
    {
      while ((c=fgetc(f))!='\n' && c!=EOF) /* skip */;
      lineNr++; 
    }
    if (!feof(f))
    {
      // skip until the opening bracket or lonely : is found
      char cn=0;
      while (lineNr<=endLine && !feof(f) && !found)
      {
        int pc=0;
        while ((c=fgetc(f))!='{' && c!=':' && c!=EOF) 
        {
          //printf("parsing char `%c'\n",c);
          if (c=='\n') 
          {
            lineNr++,col=0; 
          }
          else if (c=='\t') 
          {
            col+=Config_getInt("TAB_SIZE") - (col%Config_getInt("TAB_SIZE"));
          }
          else if (pc=='/' && c=='/') // skip single line comment
          {
            while ((c=fgetc(f))!='\n' && c!=EOF) pc=c;
            if (c=='\n') lineNr++,col=0;
          }
          else if (pc=='/' && c=='*') // skip C style comment
          {
            while (((c=fgetc(f))!='/' || pc!='*') && c!=EOF) 
            {
              if (c=='\n') lineNr++,col=0;
              pc=c;
            }
          }
          else
          {
            col++;
          }
          pc = c;
        }
        if (c==':')
        {
          cn=fgetc(f);
          if (cn!=':') found=TRUE;
        }
        else if (c=='{')
        {
          found=TRUE;
        }
      }
      //printf(" -> readCodeFragment(%s,%d,%d) lineNr=%d\n",fileName,startLine,endLine,lineNr);
      if (found) 
      {
        // For code with more than one line,
        // fill the line with spaces until we are at the right column
        // so that the opening brace lines up with the closing brace
        if (endLine!=startLine)
        {
          QCString spaces;
          spaces.fill(' ',col);
          result+=spaces;
        }
        // copy until end of line
        result+=c;
        if (c==':') 
        {
          result+=cn;
          if (cn=='\n') lineNr++;
        }
        startLine=lineNr;
        const int maxLineLength=4096;
        char lineStr[maxLineLength];
        do 
        {
          //printf("reading line %d in range %d-%d\n",lineNr,startLine,endLine);
          int size_read;
          do 
          {
            // read up to maxLineLength-1 bytes, the last byte being zero
            char *p = fgets(lineStr, maxLineLength,f);
            //printf("  read %s",p);
            if (p) 
            {
              size_read=qstrlen(p); 
            }
            else  // nothing read
            {
              size_read=-1;
              lineStr[0]='\0';
            }
            result+=lineStr;
          } while (size_read == (maxLineLength-1));

          lineNr++; 
        } while (lineNr<=endLine && !feof(f));

        // strip stuff after closing bracket
        int newLineIndex = result.findRev('\n');
        int braceIndex   = result.findRev('}');
        if (braceIndex > newLineIndex) 
        {
          result.truncate(braceIndex+1);
        }
        endLine=lineNr-1;
      }
    }
    if (usePipe) 
    {
      portable_pclose(f); 
    }
    else 
    {
      fclose(f);
    }
  }
  result = transcodeCharacterStringToUTF8(result);
  return found;
}
예제 #11
0
// iso9660 + RR use some latin1 variant. So we need to cut the desc fields
// counting 8bit chars. The GUI should take care of restricting the length
// and the charset
static void truncateTheHardWay( QString& s, int max )
{
  QCString cs = s.utf8();
  cs.truncate(max);
  s = QString::fromUtf8( cs );
}
예제 #12
0
bool KoApplication::start()
{
    ResetStarting resetStarting; // reset m_starting to false when we're done
    Q_UNUSED( resetStarting );

    // Find the *.desktop file corresponding to the kapp instance name
    KoDocumentEntry entry = KoDocumentEntry( KoDocument::readNativeService() );
    if ( entry.isEmpty() )
    {
        kdError( 30003 ) << instanceName() << "part.desktop not found." << endl;
        kdError( 30003 ) << "Run 'kde-config --path services' to see which directories were searched, assuming kde startup had the same environment as your current shell." << endl;
        kdError( 30003 ) << "Check your installation (did you install KOffice in a different prefix than KDE, without adding the prefix to /etc/kderc ?)" << endl;
        return false;
    }

    // Get the command line arguments which we have to parse
    KCmdLineArgs *args= KCmdLineArgs::parsedArgs();
    int argsCount = args->count();

    KCmdLineArgs *koargs = KCmdLineArgs::parsedArgs("koffice");
    QCString dpiValues = koargs->getOption( "dpi" );
    if ( !dpiValues.isEmpty() ) {
        int sep = dpiValues.find( QRegExp( "[x, ]" ) );
        int dpiX;
        int dpiY = 0;
        bool ok = true;
        if ( sep != -1 ) {
            dpiY = dpiValues.mid( sep+1 ).toInt( &ok );
            dpiValues.truncate( sep );
        }
        if ( ok ) {
            dpiX = dpiValues.toInt( &ok );
            if ( ok ) {
                if ( !dpiY ) dpiY = dpiX;
                KoGlobal::setDPI( dpiX, dpiY );
            }
        }
    }

    // No argument -> create an empty document
    if ( !argsCount ) {
        KoDocument* doc = entry.createDoc( 0, "Document" );
        if ( !doc )
            return false;
        KoMainWindow *shell = new KoMainWindow( doc->instance() );
        shell->show();
        QObject::connect(doc, SIGNAL(sigProgress(int)), shell, SLOT(slotProgress(int)));
        // for initDoc to fill in the recent docs list
        // and for KoDocument::slotStarted
        doc->addShell( shell );

        if ( doc->checkAutoSaveFile() ) {
          shell->setRootDocument( doc );
        } else {
          doc->showStartUpWidget( shell );
        }

        // FIXME This needs to be moved someplace else
	QObject::disconnect(doc, SIGNAL(sigProgress(int)), shell, SLOT(slotProgress(int)));
    } else {
        bool print = koargs->isSet("print");
	bool doTemplate = koargs->isSet("template");
        koargs->clear();

        // Loop through arguments

        short int n=0; // number of documents open
        short int nPrinted = 0;
        for(int i=0; i < argsCount; i++ )
        {
            // For now create an empty document
            KoDocument* doc = entry.createDoc( 0 );
            if ( doc )
            {
                // show a shell asap
                KoMainWindow *shell = new KoMainWindow( doc->instance() );
                if (!print)
                    shell->show();
		// are we just trying to open a template?
		if ( doTemplate ) {
		  QStringList paths;
		  if ( args->url(i).isLocalFile() && QFile::exists(args->url(i).path()) )
		  {
		    paths << QString(args->url(i).path());
		    kdDebug(30003) << "using full path..." << endl;
		  } else {
		     QString desktopName(args->arg(i));
		     QString appName = KGlobal::instance()->instanceName();

		     paths = KGlobal::dirs()->findAllResources("data", appName +"/templates/*/" + desktopName );
		     if ( paths.isEmpty()) {
			   paths = KGlobal::dirs()->findAllResources("data", appName +"/templates/" + desktopName );
	             }
		     if ( paths.isEmpty()) {
		        KMessageBox::error(0L, i18n("No template found for: %1 ").arg(desktopName) );
		        delete shell;
		     } else if ( paths.count() > 1 ) {
		        KMessageBox::error(0L,  i18n("Too many templates found for: %1").arg(desktopName) );
		        delete shell;
		     }
		  }

                  if ( !paths.isEmpty() ) {
		     KURL templateBase;
		     templateBase.setPath(paths[0]);
		     KDesktopFile templateInfo(paths[0]);

		     QString templateName = templateInfo.readURL();
		     KURL templateURL;
		     templateURL.setPath( templateBase.directory() + "/" + templateName );
		     if ( shell->openDocument(doc, templateURL )) {
		       doc->resetURL();
		       doc->setEmpty();
                       doc->setTitleModified();
		       kdDebug(30003) << "Template loaded..." << endl;
		       n++;
		     } else {
		        KMessageBox::error(0L, i18n("Template %1 failed to load.").arg(templateURL.prettyURL()) );
 		        delete shell;
		     }
		  }
                // now try to load
                } else if ( shell->openDocument( doc, args->url(i) ) ) {
                    if ( print ) {
                        shell->print(false /*we want to get the dialog*/);
                        // delete shell; done by ~KoDocument
                        nPrinted++;
		    } else {
                        // Normal case, success
                        n++;
                    }
                } else {
                    // .... if failed
                    // delete doc; done by openDocument
                    // delete shell; done by ~KoDocument
                }
            }
        }
        if ( print )
            return nPrinted > 0;
        if (n == 0) // no doc, e.g. all URLs were malformed
            return false;
    }

    args->clear();
    // not calling this before since the program will quit there.
    return true;
}