diff options
author | Jose Antonio Ortega Ruiz <jao@gnu.org> | 2001-06-18 22:54:29 +0000 |
---|---|---|
committer | Jose Antonio Ortega Ruiz <jao@gnu.org> | 2001-06-18 22:54:29 +0000 |
commit | fed5d59e6b5b6d73a17e04cdd630130326adc617 (patch) | |
tree | 83cfb39cdc04bf186c9b2d4838812590e92bef16 /mixlib | |
parent | 8a51387cd162a37bac2a51d50ef7b857fa25db01 (diff) | |
download | mdk-fed5d59e6b5b6d73a17e04cdd630130326adc617.tar.gz mdk-fed5d59e6b5b6d73a17e04cdd630130326adc617.tar.bz2 |
(add_symbol_) symbol value correctly recovered (including sign)
Diffstat (limited to 'mixlib')
-rw-r--r-- | mixlib/mix_symbol_table.c | 84 |
1 files changed, 42 insertions, 42 deletions
diff --git a/mixlib/mix_symbol_table.c b/mixlib/mix_symbol_table.c index 4f33420..debf04b 100644 --- a/mixlib/mix_symbol_table.c +++ b/mixlib/mix_symbol_table.c @@ -1,7 +1,7 @@ /* -*-c-*- -------------- mix_symbol_table.c : * Implementation of the functions declared in mix_symbol_table.h * ------------------------------------------------------------------ - * Copyright (C) 2000 Free Software Foundation, Inc. + * Copyright (C) 2000, 2001 Free Software Foundation, Inc. * * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -26,27 +26,27 @@ /* Create an empty table */ mix_symbol_table_t * -mix_symbol_table_new(void) +mix_symbol_table_new (void) { - return g_hash_table_new(g_str_hash, g_str_equal); + return g_hash_table_new (g_str_hash, g_str_equal); } /* Create a table and populate it with the contents of a table stored - in -file- using mix_symbol_table_print(table, MIX_SYM_LINE, file) + in -file- using mix_symbol_table_print (table, MIX_SYM_LINE, file) */ mix_symbol_table_t * -mix_symbol_table_new_from_file(FILE *file) +mix_symbol_table_new_from_file (FILE *file) { - mix_symbol_table_t *result = mix_symbol_table_new(); + mix_symbol_table_t *result = mix_symbol_table_new (); if ( result != NULL ) { gchar sym[MIX_SYM_MAX_LEN + 1]; glong val; - while ( getc(file) == ',' ) + while ( getc (file) == ',' ) { - if ( fscanf(file, "%s =%ld", sym, &val) != EOF ) - mix_symbol_table_add(result, sym, mix_word_new(val)); + if ( fscanf (file, "%s =%ld", sym, &val) != EOF ) + mix_symbol_table_add (result, sym, mix_word_new (val)); } } return result; @@ -54,30 +54,30 @@ mix_symbol_table_new_from_file(FILE *file) /* Delete a table */ static void -delete_hash_keys_(gpointer key, gpointer value, gpointer data) +delete_hash_keys_ (gpointer key, gpointer value, gpointer data) { - g_free(key); + g_free (key); } void -mix_symbol_table_delete(mix_symbol_table_t *table) +mix_symbol_table_delete (mix_symbol_table_t *table) { - g_hash_table_foreach(table, delete_hash_keys_, NULL); - g_hash_table_destroy(table); + g_hash_table_foreach (table, delete_hash_keys_, NULL); + g_hash_table_destroy (table); } /* add/remove symbols from other table */ static void -add_symbol_(gpointer symbol, gpointer value, gpointer target) +add_symbol_ (gpointer symbol, gpointer value, gpointer target) { mix_symbol_table_t *t = (mix_symbol_table_t *)target; gchar *s = (gchar *)symbol; - mix_word_t v = mix_word_new(GPOINTER_TO_UINT(value)); + mix_word_t v = (mix_word_t)GPOINTER_TO_UINT (value); mix_symbol_table_insert (t, s, v); } static void -remove_symbol_(gpointer symbol, gpointer value, gpointer target) +remove_symbol_ (gpointer symbol, gpointer value, gpointer target) { mix_symbol_table_t *t = (mix_symbol_table_t *)target; gchar *s = (gchar *)symbol; @@ -111,18 +111,18 @@ mix_symbol_table_substract_table (mix_symbol_table_t *table, /* Add/remove symbols one by one */ gint -mix_symbol_table_add(mix_symbol_table_t *table, +mix_symbol_table_add (mix_symbol_table_t *table, const gchar *sym, mix_word_t value) { gpointer key, val; if ( table == NULL || sym == NULL ) return MIX_SYM_FAIL; - if ( strlen(sym) > MIX_SYM_MAX_LEN ) return MIX_SYM_LONG; + if ( strlen (sym) > MIX_SYM_MAX_LEN ) return MIX_SYM_LONG; - if ( !g_hash_table_lookup_extended(table, sym, &key, &val) ) + if ( !g_hash_table_lookup_extended (table, sym, &key, &val) ) { - key = g_strdup(sym); - g_hash_table_insert(table, key, (gpointer)value); + key = g_strdup (sym); + g_hash_table_insert (table, key, (gpointer)value); return MIX_SYM_OK; } else @@ -131,24 +131,24 @@ mix_symbol_table_add(mix_symbol_table_t *table, /* Add or modify symbol if it exists */ gint -mix_symbol_table_insert(mix_symbol_table_t *table, +mix_symbol_table_insert (mix_symbol_table_t *table, const gchar *sym, mix_word_t new_value) { gpointer key, val; if ( table == NULL || sym == NULL ) return MIX_SYM_FAIL; - if ( strlen(sym) > MIX_SYM_MAX_LEN ) return MIX_SYM_LONG; + if ( strlen (sym) > MIX_SYM_MAX_LEN ) return MIX_SYM_LONG; - if ( !g_hash_table_lookup_extended(table, sym, &key, &val) ) - key = g_strdup(sym); - g_hash_table_insert(table, key, (gpointer)new_value); + if ( !g_hash_table_lookup_extended (table, sym, &key, &val) ) + key = g_strdup (sym); + g_hash_table_insert (table, key, (gpointer)new_value); return MIX_SYM_OK; } /* Symbols lookup */ gboolean -mix_symbol_table_is_defined(const mix_symbol_table_t *table, const gchar *sym) +mix_symbol_table_is_defined (const mix_symbol_table_t *table, const gchar *sym) { gpointer key, val; return g_hash_table_lookup_extended((GHashTable *)table, sym, &key, &val); @@ -156,43 +156,43 @@ mix_symbol_table_is_defined(const mix_symbol_table_t *table, const gchar *sym) /* Print table */ #define is_local_sym_(sym) \ - ((sym) && (strlen(sym)==2) && (sym[1] == 'B') && isdigit(sym[0])) + ((sym) && (strlen (sym)==2) && (sym[1] == 'B') && isdigit (sym[0])) static gboolean skip_ = FALSE; static void -print_sym_rows_(gpointer symbol, gpointer value, gpointer file) +print_sym_rows_ (gpointer symbol, gpointer value, gpointer file) { char *s = (char *)symbol; - if (skip_ && !is_local_sym_(s)) { - mix_word_t word = (mix_word_t)GPOINTER_TO_UINT(value); + if (skip_ && !is_local_sym_ (s)) { + mix_word_t word = (mix_word_t)GPOINTER_TO_UINT (value); fprintf((FILE *)file, "%s: %s%ld\n", s, - mix_word_is_negative(word)? "-":"", - mix_word_magnitude(word)); + mix_word_is_negative (word)? "-":"", + mix_word_magnitude (word)); } } static void -print_sym_line_(gpointer symbol, gpointer value, gpointer file) +print_sym_line_ (gpointer symbol, gpointer value, gpointer file) { char *s = (char *)symbol; - if (skip_ && !is_local_sym_(s)) { - mix_word_t word = (mix_word_t)GPOINTER_TO_UINT(value); + if (skip_ && !is_local_sym_ (s)) { + mix_word_t word = (mix_word_t)GPOINTER_TO_UINT (value); fprintf((FILE *)file, ",%s =%s%ld", s, - mix_word_is_negative(word)? "-":"", - mix_word_magnitude(word)); + mix_word_is_negative (word)? "-":"", + mix_word_magnitude (word)); } } void -mix_symbol_table_print(const mix_symbol_table_t *table, gint mode, +mix_symbol_table_print (const mix_symbol_table_t *table, gint mode, FILE *file, gboolean skiplocal) { GHFunc func = (mode == MIX_SYM_LINE)? print_sym_line_ : print_sym_rows_; skip_ = skiplocal; if ( table != NULL ) - g_hash_table_foreach((GHashTable *)table, func, (gpointer)file); - if ( mode == MIX_SYM_LINE ) putc(';', file); /* to mark end-of-table */ + g_hash_table_foreach ((GHashTable *)table, func, (gpointer)file); + if ( mode == MIX_SYM_LINE ) putc (';', file); /* to mark end-of-table */ } |