コード例 #1
0
static void printTracePosition( TA_TracePosition *tracePosition, FILE *out )
{
   const char *filename;
   int seperatorChar;

   if( !tracePosition )
      return;

   /* Strip off the path. */
   if( !tracePosition->filename )
      filename = NULL;
   else
   {
      seperatorChar = TA_SeparatorASCII();
      filename = strrchr( tracePosition->filename, seperatorChar );
      if( !filename )
         filename = tracePosition->filename;

      if( filename[0] == seperatorChar && seperatorChar != '\0' )
         filename++;
   }

   fprintf( out, "(%03d)Line:[%04d][%s,%s]\n",
              tracePosition->repetition,
              tracePosition->lineNb,
              tracePosition->funcname?tracePosition->funcname:"(null)",
              filename?filename:"(null)" );
}
コード例 #2
0
/**** Local functions definitions.     ****/
static unsigned int calcHash( const char *string, TA_CharCase caseType )
{
   unsigned int i;
   unsigned int retValue = 0;
   unsigned char tmp;

   for( i=0; i < 10; i++ )
   {
      tmp = string[i];

      if( tmp )
      {
         if( caseType == UPPER_CASE )
            tmp = (unsigned char)toupper( tmp );
         else if( caseType == PATH && TA_IsSeparatorChar(tmp) )
            tmp = TA_SeparatorASCII();
         
         retValue += tmp;
      }
      else
         return retValue%NB_CACHE_ENTRY;
   }

   return retValue%NB_CACHE_ENTRY;
}
コード例 #3
0
static TA_String *stringAllocInternal( const char *string,
                                       unsigned int newStringLength,
                                       TA_CharCase caseType )
{
   unsigned int size, i;
   char *str;

   /* Not in the cache, or could have reach duplicaton limit.
    * No choice to do an allocation.
    */
   size = ( newStringLength + 2 ) * sizeof( unsigned char );

   str = (char *)TA_Malloc( size );

   if( str != NULL )
   {
      if( caseType == UPPER_CASE )
      {
         for( i=0; i < newStringLength; i++ )
            str[i+1] = (unsigned char)toupper( string[i] );
      }
      else if( caseType == PATH )
      {
         for( i=0; i < newStringLength; i++ )
         {
            if( TA_IsSeparatorChar(string[i]) )
               str[i+1] = TA_SeparatorASCII();
            else
               str[i+1] = string[i];
         }
      }
      else
      {
         for( i=0; i < newStringLength; i++ )
            str[i+1] = string[i];
      }

      str[newStringLength+1] = '\0';
      str[0] = 1;
   }

   return (TA_String *)str;
}
コード例 #4
0
/**** Global functions definitions.   ****/
TA_RetCode TA_FileIndexParsePath( TA_FileIndexPriv *fileIndexPriv, TA_String *path )
{
   typedef enum { INIT_PROCESSING,
                  FIX_PROCESSING,
                  FIELD_PROCESSING,
                  WILD_PROCESSING,
                  SEP_PROCESSING } State;

   TA_PROLOG
   State currentState;
   const char *currentTokenStart;
   unsigned int length;
   char *str;
   char *pos;
   char sepTmp[2];
   TA_RetCode retCode;
   unsigned int tokenSize;
   TA_TokenId tokenId;
   const char *sourcePattern;

   TA_TRACE_BEGIN(  TA_FileIndexParsePath );

   TA_ASSERT( path != NULL );

   sepTmp[1] = '\0';
   sourcePattern = TA_StringToChar( path );

   /* The following macro should help for the readability of the parsing logic.
    * These macro are used only inside this function.
    */
   #define RETURN(y) {TA_Free(str); TA_TRACE_RETURN( y );}
   #define REJECT_STATE(x,y) { if(currentState==x)RETURN(y);  }
   #define CHANGE_STATE(x) {currentState=x; currentTokenStart=pos+1;}

   #define ADD_TOKEN(id,value) \
   { \
      retCode = addToken(fileIndexPriv,id,value); \
      if( retCode != TA_SUCCESS) RETURN(retCode); \
   }

   #define FLUSH_FIX() \
   { \
      retCode = flushFixPart(fileIndexPriv,currentTokenStart,pos); \
      if( retCode != TA_SUCCESS ) RETURN(retCode); \
   }

   /* This function build a list representing the tokens
    * of the sourcePattern.
    *
    * Example:  "C:\a\*AZD?\[S]\data.txt" becomes
    *
    *            TokenId      Value
    *            TA_TOK_FIX       "C:"
    *            TA_TOK_SEP       "\"
    *            TA_TOK_FIX       "a"
    *            TA_TOK_SEP       "\"
    *            TA_TOK_WILD      "*"
    *            TA_TOK_FIX       "AZD"
    *            TA_TOK_WILD_CHAR "?"
    *            TA_TOK_SEP       "\"
    *            TA_TOK_S         "?*"
    *            TA_TOK_SEP       "\"
    *            TA_TOK_FIX       "data.txt"
    *            TA_TOK_END       (null)
    *
    *        In the values, the '?' and '*' character represent MS-DOS kind
    *        of wildcards:
    *             '?' is any character (but only one).
    *             '*' zero or more of any character
    */
   if( sourcePattern == NULL )
      return TA_INVALID_PATH;

   length = strlen( sourcePattern ) + 1;

   if( (length <= 1) || (length > 2048) )
      return TA_INVALID_PATH;

   str = (char *)TA_Malloc( length );
   strcpy( str, sourcePattern );

   pos = str;
   currentState = INIT_PROCESSING;
   currentTokenStart = pos;

   while( *pos != '\0' )
   {

      if( (*pos == '\\') || (*pos == '/') )
      {
         /* Handle directories separator character. */
         REJECT_STATE( FIELD_PROCESSING, TA_INVALID_FIELD );
         REJECT_STATE( SEP_PROCESSING, TA_INVALID_PATH );

         FLUSH_FIX();

#if 0
!!! Needed?
         /* Check that the string prior to the separator
          * does not terminate with a dot '.'
          */
         if( currentState != INIT_PROCESSING )
         {
            if( *(pos-1) == '.' )
               RETURN( TA_INVALID_PATH );
         }
#endif
         /* Transform into the directory delimiter
          * used on the host file system.
          */
         sepTmp[0] = (char)TA_SeparatorASCII();
         ADD_TOKEN( TA_TOK_SEP, sepTmp );

         CHANGE_STATE( SEP_PROCESSING );
      }
      else switch( *pos )