예제 #1
0
void MetaModule::GetVersion( int& major, int& minor, int& release, int& build,
                             IsoString& language, IsoString& status ) const
{
   // Set undefined states for all variables, in case of error.
   major = minor = release = build = 0;
   language.Clear();
   status.Clear();

   IsoString vs( Version() );

   // A version string must begin with a version marker
   if ( vs.Length() < LengthOfVersionMarker )
      return;

   // Split the string of version numbers into tokens separated by dots
   StringList tokens;
   vs.Break( tokens, '.', false/*trim*/, LengthOfVersionMarker );

   // Required: MM.mm.rr.bbbb.LLL
   // Optional: .<status>
   if ( tokens.Length() < 5 || tokens.Length() > 6 )
      return;

   // Extract version numbers
   try
   {
      int MM   = tokens[0].ToInt( 10 );
      int mm   = tokens[1].ToInt( 10 );
      int rr   = tokens[2].ToInt( 10 );
      int bbbb = tokens[3].ToInt( 10 );

      major = MM;
      minor = mm;
      release = rr;
      build = bbbb;
   }
   catch ( ... ) // silently eat all parse exceptions here
   {
      return;
   }

   // Language code
   language = tokens[4]; // ### TODO: Verify validity of ISO 639.2 code

   // Optional status word
   if ( tokens.Length() == 6 )
      status = tokens[5];  // ### TODO: Verify validity of the status word
}
예제 #2
0
static IsoString GetDemangledFunctionName( const char* symbol, IsoString& addrStr )
{
   IsoString symbolStr( symbol );
   addrStr.Clear();

   // Get mangled function name. Example:
   //    /opt/PixInsight/bin/lib/libQtGui.so.4(_ZN7QWidget5eventEP6QEvent+0x411) [0x7fa271347811]
   StringList tokens;
   symbolStr.Break( tokens, '(' , true/*trim*/ );
   if ( tokens.Length() != 2 )
      return symbolStr;

   // Take second token and split again.
   StringList tokens2;
   tokens[1].Break( tokens2, '+' , true/*trim*/ );
   if ( tokens2.Length() != 2 )
      return symbolStr;

   // If there is no function name, do not set the addr string.
   if ( !tokens2[0].IsEmpty() )
   {
      addrStr = tokens2[1];
      addrStr.DeleteChar( '(' );
      addrStr.DeleteChar( ')' );
   }

   // The first token of tokens2 contains the mangled string. Demangle it.
   size_t funcnameSize = 256;
   char funcname[ funcnameSize ];
   int status;
   IsoString token( tokens2[0] );
   const char* demangledFuncname = abi::__cxa_demangle( token.c_str(), funcname, &funcnameSize, &status );
   return (status == 0) ? IsoString( demangledFuncname ) : symbolStr;
}
예제 #3
0
FilterParser::token_list FilterParser::Tokenize( const IsoStringList& linesUTF8 )
{
   token_list tokenList;
   bool blockComment = false;
   int row = 0;
   for ( IsoStringList::const_iterator i = linesUTF8.Begin(); i < linesUTF8.End(); ++i, ++row )
   {
      IsoString token;
      int tokenCol = 0;
      for ( IsoString::const_iterator j = i->Begin(); j < i->End(); ++j )
      {
         if ( blockComment )
         {
            if ( *j == '*' )
               if ( ++j < i->End() )
                  if ( *j == '/' )
                  {
                     blockComment = false;
                     /*
                      * Uncomment the next line to turn block comments into
                      * separators.
                      *
                     tokenCol = j - i->Begin() + 1;
                      */
                  }
         }
         else
         {
            bool lineComment = false;
            switch ( *j )
            {
            case ' ':
            case '\t':
               if ( !token.IsEmpty() )
               {
                  tokenList.Add( Token( token, row, tokenCol ) );
                  token.Clear();
               }
               for ( IsoString::const_iterator k = j; ++k < i->End(); ++j )
                  if ( *k != ' ' && *k != '\t' )
                     break;
               tokenCol = j - i->Begin() + 1;
               break;
               /*
            case ',':
               if ( token.IsEmpty() )
                  throw SourceCodeError( "Expected a token before ','", row+1, int( j - i->Begin() + 1 ) );
               tokenList.Add( Token( token, row, tokenCol ) );
               token.Clear();
               tokenCol = j - i->Begin() + 1;
               break;
               */
            case '{':
            case '}':
               if ( !token.IsEmpty() )
               {
                  tokenList.Add( Token( token, row, tokenCol ) );
                  token.Clear();
               }
               tokenList.Add( Token( IsoString( *j ), row, int( j - i->Begin() ) ) );
               tokenCol = j - i->Begin() + 1;
               break;
            case '/':
               if ( ++j < i->End() )
               {
                  if ( *j == '/' )
                     lineComment = true;
                  else if ( *j == '*' )
                  {
                     blockComment = true;
                     /*
                      * Uncomment the next lines to turn block comments into
                      * separators.
                      *
                     if ( !token.IsEmpty() )
                     {
                        tokenList.Add( Token( token, row, tokenCol ) );
                        token.Clear();
                     }
                      */
                  }
                  else
                     token += *--j;
               }
               break;
            default:
               token += *j;
               break;
            }
            if ( lineComment )
               break;
         }
      }

      if ( !token.IsEmpty() )
         tokenList.Add( Token( token, row, tokenCol ) );
   }
   return tokenList;
}