/* * function used to rehash the entire hash table * if the frequency of clash increases beyond a fixed point */ symbol_table* rehash_symbol_table(symbol_table *st) { if(st->num_element < st->size) { return st; } symbol_table *new_st = (symbol_table*)malloc(sizeof(symbol_table)); if(new_st == NULL) return st; new_st->size = 2*st->size; new_st->table = (symbol_list *)malloc(new_st->size*sizeof(symbol_list)); int i,index; symbol_list list,temp,t1; for(i=0;i<st->size;i++) { list = st->table[i]; while(list != NULL) { temp = list->next; index = hash_function_symbol_table(list->identifier, list->scope, new_st); t1 = new_st->table[index]; new_st->table[index] = list; list->next = t1; list = temp; } } free_symbol_table(st); return new_st; }
int main (int argc, char **argv) { FILE *stream; signed short c; char cache_file_ln[256]; int line_length, line_nr; int status; if (argc != 2) fprintf(stderr, "%s: Argc != 2\n", argv[0]); stream = fopen(argv[1], "r"); if (stream == NULL) fprintf(stderr, "File % cannot be opened\n", argv[1]); tmp = fopen("tmp", "w"); if (tmp == NULL) fprintf(stderr, "tmp file cannot be opened\n"); status = line_length = line_nr = 0; memset(cache_file_ln, 0, 256); root = (struct symbols *) create_symbol_table(); printf("root symbol address: %p\n\n", root); while (status != EOF) { c = fgetc(stream); if (c != '\n' && c != EOF) { cache_file_ln[line_length++] = c; if (line_length >= 256) fprintf(stderr, "Line (%d) too large!\n", line_nr + 1); } else { if (c == EOF) status = EOF; else if (c == '\n') cache_file_ln[line_length] = c; if (line_length >= 1) { int err = parse_line(cache_file_ln, line_length); if (err == OVERFLOW_DETECTED) fprintf(stderr, "Overflow!\n"); } line_length = 0; memset(cache_file_ln, 0, 256); line_nr++; } } puts("\n"); print_all_symbols(root); free_symbol_table(root); fclose(tmp); fclose(stream); return 0; }
int main(int argc, char* argv[]) { create_symbol_table(); register_builtins(); greeting(); yyparse(); free_symbol_table(); printf("\n"); return 0; }
static void free_ptrace_map_info_data(map_info_t* mi) { map_info_data_t* data = (map_info_data_t*)mi->data; if (data) { if (data->symbol_table) { free_symbol_table(data->symbol_table); } #ifdef CORKSCREW_HAVE_ARCH free_ptrace_map_info_data_arch(mi, data); #endif free(data); mi->data = NULL; } }
/* * deallocate a symbol_table linked list */ void free_symbol_table_list( SYMBOL_TABLE *symbol_table_list) { SYMBOL_TABLE *symbol_table_next; /* * deallocate the symbol_table linked list structure */ while( symbol_table_list) { symbol_table_next = symbol_table_list->next; free_symbol_table( symbol_table_list); symbol_table_list = symbol_table_next; } return; }
/* Free the memory used by one block */ libspectrum_error libspectrum_tape_block_free( libspectrum_tape_block *block ) { size_t i; switch( block->type ) { case LIBSPECTRUM_TAPE_BLOCK_ROM: libspectrum_free( block->types.rom.data ); break; case LIBSPECTRUM_TAPE_BLOCK_TURBO: libspectrum_free( block->types.turbo.data ); break; case LIBSPECTRUM_TAPE_BLOCK_PURE_TONE: break; case LIBSPECTRUM_TAPE_BLOCK_PULSES: libspectrum_free( block->types.pulses.lengths ); break; case LIBSPECTRUM_TAPE_BLOCK_PURE_DATA: libspectrum_free( block->types.pure_data.data ); break; case LIBSPECTRUM_TAPE_BLOCK_RAW_DATA: libspectrum_free( block->types.raw_data.data ); break; case LIBSPECTRUM_TAPE_BLOCK_GENERALISED_DATA: free_symbol_table( &block->types.generalised_data.pilot_table ); free_symbol_table( &block->types.generalised_data.data_table ); libspectrum_free( block->types.generalised_data.pilot_symbols ); libspectrum_free( block->types.generalised_data.pilot_repeats ); libspectrum_free( block->types.generalised_data.data ); break; case LIBSPECTRUM_TAPE_BLOCK_PAUSE: break; case LIBSPECTRUM_TAPE_BLOCK_GROUP_START: libspectrum_free( block->types.group_start.name ); break; case LIBSPECTRUM_TAPE_BLOCK_GROUP_END: break; case LIBSPECTRUM_TAPE_BLOCK_JUMP: break; case LIBSPECTRUM_TAPE_BLOCK_LOOP_START: break; case LIBSPECTRUM_TAPE_BLOCK_LOOP_END: break; case LIBSPECTRUM_TAPE_BLOCK_SELECT: for( i=0; i<block->types.select.count; i++ ) { libspectrum_free( block->types.select.descriptions[i] ); } libspectrum_free( block->types.select.descriptions ); libspectrum_free( block->types.select.offsets ); break; case LIBSPECTRUM_TAPE_BLOCK_STOP48: break; case LIBSPECTRUM_TAPE_BLOCK_SET_SIGNAL_LEVEL: break; case LIBSPECTRUM_TAPE_BLOCK_COMMENT: libspectrum_free( block->types.comment.text ); break; case LIBSPECTRUM_TAPE_BLOCK_MESSAGE: libspectrum_free( block->types.message.text ); break; case LIBSPECTRUM_TAPE_BLOCK_ARCHIVE_INFO: for( i=0; i<block->types.archive_info.count; i++ ) { libspectrum_free( block->types.archive_info.strings[i] ); } libspectrum_free( block->types.archive_info.ids ); libspectrum_free( block->types.archive_info.strings ); break; case LIBSPECTRUM_TAPE_BLOCK_HARDWARE: libspectrum_free( block->types.hardware.types ); libspectrum_free( block->types.hardware.ids ); libspectrum_free( block->types.hardware.values ); break; case LIBSPECTRUM_TAPE_BLOCK_CUSTOM: libspectrum_free( block->types.custom.description ); libspectrum_free( block->types.custom.data ); break; /* Block types not present in .tzx follow here */ case LIBSPECTRUM_TAPE_BLOCK_RLE_PULSE: libspectrum_free( block->types.rle_pulse.data ); break; case LIBSPECTRUM_TAPE_BLOCK_PULSE_SEQUENCE: libspectrum_free( block->types.pulse_sequence.lengths ); libspectrum_free( block->types.pulse_sequence.pulse_repeats ); break; case LIBSPECTRUM_TAPE_BLOCK_DATA_BLOCK: libspectrum_free( block->types.data_block.data ); libspectrum_free( block->types.data_block.bit0_pulses ); libspectrum_free( block->types.data_block.bit1_pulses ); break; case LIBSPECTRUM_TAPE_BLOCK_CONCAT: /* This should never occur */ default: libspectrum_print_error( LIBSPECTRUM_ERROR_LOGIC, "%s: unknown block type %d", __func__, block->type ); return LIBSPECTRUM_ERROR_LOGIC; } libspectrum_free( block ); return LIBSPECTRUM_ERROR_NONE; }