Exemple #1
0
TA_RetCode TA_FuncTableAlloc( const char *group, TA_StringTable **table )
{
   TA_RetCode retCode;
   unsigned int i;
   TA_StringTable *stringTable;
   unsigned int groupId; /* TA_GroupId */
   unsigned int groupSize;
   const char *stringPtr;
   TA_StringTablePriv *stringTablePriv;

   if( (group == NULL) || (table == NULL ) )
   {
      return TA_BAD_PARAM;
   }

   *table = NULL;
   stringPtr = NULL;

   /* Get information on the group. */
   retCode = getGroupId( group, &groupId );
   if( retCode != TA_SUCCESS )
   {
      return retCode;
   }

   retCode = getGroupSize( (TA_GroupId)groupId, &groupSize );
   if( retCode != TA_SUCCESS )
   {
      return retCode;
   }

   /* Allocate the table. */

   stringTable = (TA_StringTable *)TA_Malloc( sizeof(TA_StringTable) + sizeof(TA_StringTablePriv) );
   if( !stringTable )
   {
      *table = NULL;
      return TA_ALLOC_ERR;
   }

   memset( stringTable, 0, sizeof(TA_StringTable) + sizeof(TA_StringTablePriv) );
   stringTablePriv = (TA_StringTablePriv *)(((char *)stringTable)+sizeof(TA_StringTable));
   stringTablePriv->magicNumber = TA_STRING_TABLE_FUNC_MAGIC_NB;
   stringTable->hiddenData = stringTablePriv;

   /* From this point, TA_FuncTableFree can be safely called. */
   stringTable->size = groupSize;
   if( groupSize != 0 )
   {
      stringTable->string = (const char **)TA_Malloc( (stringTable->size) *
                                                      sizeof(const char *) );

      if( stringTable->string == NULL )
      {
         *table = NULL;
         TA_FuncTableFree( stringTable );
         return TA_ALLOC_ERR;
      }

      memset( (void *)stringTable->string, 0,
              (stringTable->size) * sizeof(const char *) );

      for( i=0; i < stringTable->size; i++ )
      {
         retCode = getFuncNameByIdx( (TA_GroupId)groupId, i, &stringPtr );

         if( retCode != TA_SUCCESS )
         {
            *table = NULL;
            TA_FuncTableFree( stringTable );
            return TA_ALLOC_ERR;
         }

         (stringTable->string)[i] = stringPtr;
      }
   }

   /* Return the table to the caller. */
   *table = stringTable;

   return TA_SUCCESS;
}
Exemple #2
0
TA_RetCode TA_FuncTableAlloc( TA_Libc *libHandle, const char *group, TA_StringTable **table )
{
   TA_PROLOG;
   TA_RetCode retCode;
   unsigned int i;
   TA_StringTable *stringTable;
   unsigned int groupId; /* TA_GroupId */
   unsigned int groupSize;
   const char *stringPtr;
   TA_StringTableFuncHidden *stringTableHidden;
   TA_TRACE_BEGIN( libHandle, TA_FuncTableAlloc );

   if( (group == NULL) || (table == NULL ) )
   {
      TA_TRACE_RETURN( TA_BAD_PARAM );
   }

   *table = NULL;

   /* Get information on the group. */
   #ifdef TA_GEN_CODE
      retCode = getGroupId( libHandle, group, &groupId );
   #else
      retCode = getGroupId( group, &groupId );
   #endif
   if( retCode != TA_SUCCESS )
   {
      TA_TRACE_RETURN( retCode );
   }

   #ifdef TA_GEN_CODE
      retCode = getGroupSize( libHandle, (TA_GroupId)groupId, &groupSize );
   #else
      retCode = getGroupSize( (TA_GroupId)groupId, &groupSize );
   #endif
   if( retCode != TA_SUCCESS )
   {
      TA_TRACE_RETURN( retCode );
   }

   /* Allocate the table. */
   stringTable = (TA_StringTable *)TA_Malloc( libHandle, sizeof(TA_StringTable) );
   if( !stringTable )
   {
      TA_TRACE_RETURN( TA_ALLOC_ERR );
   }

   stringTableHidden = (TA_StringTableFuncHidden *)TA_Malloc( libHandle, sizeof(TA_StringTableFuncHidden) );
   if( !stringTable )
   {
      TA_Free( libHandle, stringTable );
      TA_TRACE_RETURN( TA_ALLOC_ERR );
   }

   stringTable->hiddenData = stringTableHidden;
   stringTableHidden->libHandle = libHandle;
   stringTableHidden->magicNb = TA_STRING_TABLE_FUNC_MAGIC_NB;

   /* From this point, TA_FuncTableFree can be safely called. */
   stringTable->size = groupSize;
   if( groupSize == 0 )
      stringTable->string = NULL;
   else
   {
      stringTable->string = (const char **)TA_Malloc( libHandle, (stringTable->size) *
                                                      sizeof(const char *) );

      if( stringTable->string == NULL )
      {
         TA_FuncTableFree( stringTable );
         TA_TRACE_RETURN( TA_ALLOC_ERR );
      }

      memset( (void *)stringTable->string, 0,
              (stringTable->size) * sizeof(const char *) );

      for( i=0; i < stringTable->size; i++ )
      {
         #ifdef TA_GEN_CODE
            retCode = getFuncNameByIdx( libHandle, (TA_GroupId)groupId, i, &stringPtr );
         #else
            retCode = getFuncNameByIdx( (TA_GroupId)groupId, i, &stringPtr );
         #endif

         if( retCode != TA_SUCCESS )
         {
            TA_FuncTableFree( stringTable );
            TA_TRACE_RETURN( TA_ALLOC_ERR );
         }

         (stringTable->string)[i] = stringPtr;
      }
   }

   /* Return the table to the caller. */
   *table = stringTable;

   TA_TRACE_RETURN( TA_SUCCESS );
}