diff --git a/include/table.h b/include/table.h index ca451eb..590fd75 100644 --- a/include/table.h +++ b/include/table.h @@ -51,6 +51,13 @@ typedef struct table_entry table_entry; * @param table the table to initialize. */ void table_init(table* table); +/** + * Searches for the given string in the table. + * @param table the table to search. + * @param string the string to search for. + * @return the table entry, or NULL if an entry was not found. + */ +table_entry* table_search(table* table, const char* string); /** * Frees the resources allocated by the * given table. diff --git a/src/table.c b/src/table.c index 6c0a960..396b350 100644 --- a/src/table.c +++ b/src/table.c @@ -5,7 +5,14 @@ void table_init(table* table) { ht_init(&table->table); table->parent = NULL; } - +table_entry* table_search(table* table, const char* string) { + void* to_return = NULL; + do { + to_return = ht_get(&table->table, string); + table = table->parent; + } while(table && to_return == NULL); + return to_return; +} void table_free(table* table) { ht_free(&table->table); }