/*----------------------------------------------------------------------- File : lexemetable.c Author: Stephan Schulz (schulz@eprover.org) Contents Implementation of a tanle for storing strings. Copyright 2016 by the author. This code is released under the GNU General Public Licence. Changes <1> Mon Mar 28 19:47:28 CEST 2016 New -----------------------------------------------------------------------*/ #include "lexemetable.h" /*---------------------------------------------------------------------*/ /* Global Variables */ /*---------------------------------------------------------------------*/ LexTable lextable={0, 0, NULL}; /*---------------------------------------------------------------------*/ /* Forward Declarations */ /*---------------------------------------------------------------------*/ /*---------------------------------------------------------------------*/ /* Internal Functions */ /*---------------------------------------------------------------------*/ /*---------------------------------------------------------------------*/ /* Exported Functions */ /*---------------------------------------------------------------------*/ /*----------------------------------------------------------------------- // // Function: LexTableFree() // // Free all the dynamic memory of the LexTable. // // Global Variables: - // // Side Effects : Memory management // /----------------------------------------------------------------------*/ void LexTableFree(LexTable_p table) { int i; assert(table); if(table->table) { for(i=0; inext_entry; i++) { free(table->table[i]); } free(table->table); } } /*----------------------------------------------------------------------- // // Function: LexTableAddLexeme() // // Add a lexeme to the LexTable. // // Global Variables: - // // Side Effects : Memory operations // /----------------------------------------------------------------------*/ char* LexTableAddLexeme(LexTable_p table, char* lexeme) { assert(table); assert(lexeme); char* lexcopy; if(table->next_entry == table->size) { /* Table is full, expand */ if(table->size==0) { table->size = LEX_TABLE_INITIAL_SIZE; } else { table->size *= 2; } table->table = realloc(table->table, table->size*sizeof(char*)); } lexcopy = strdup(lexeme); table->table[table->next_entry++] = lexcopy; return lexcopy; } /*---------------------------------------------------------------------*/ /* End of File */ /*---------------------------------------------------------------------*/