From 4a74019ccbd44626eb96fe751f406ff3fbe30735 Mon Sep 17 00:00:00 2001 From: chatty Date: Mon, 25 Jan 1999 17:06:33 +0000 Subject: Added ReadTables and ResetTables --- irtable.c | 82 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 81 insertions(+), 1 deletion(-) (limited to 'irtable.c') diff --git a/irtable.c b/irtable.c index c62aa95..4bd4977 100644 --- a/irtable.c +++ b/irtable.c @@ -7,8 +7,12 @@ * * Tables for decoding events * + * Authors: Stephane Chatty + * * $Id$ * + * Please refer to file version.h for the + * copyright notice regarding this software */ #include "irtable.h" @@ -35,7 +39,6 @@ static IrTableCell* CodeToCell [CODECELLS]; static int Initialized = 0; - IrTable* IrCreateTable () { @@ -143,3 +146,80 @@ IrTableTranslateCode (const unsigned char* code, IrTable** table, const char** k return (int) (c); } +void +IrResetTables (void) +{ +#if 0 /* THIS CODE TRIGGERS A MEMORY BUG */ + /* WE'LL SEE TO THAT LATER */ + + /* free all cells in hash tables */ + if (Initialized) { + /* erase hash tables */ + IrTableCell** cc; + for (cc = CodeToCell; cc < CodeToCell + CODECELLS; ++cc) { + IrTableCell* c = *cc; + while (c) { + IrTableCell* old = c; + c = c->next; + free ((char*) old->key); + free (old); + } + } + + for (cc = KeyToCell; cc < KeyToCell + CODECELLS; ++cc) { + IrTableCell* c = *cc; + while (c) { + IrTableCell* old = c; + c = c->next; + free ((char*) old->key); + free (old); + } + } + } +#endif + /* initialize hash tables to zero */ + Initialized = 1; + memset (KeyToCell, 0, sizeof (KeyToCell)); + memset (CodeToCell, 0, sizeof (CodeToCell)); + + /* should also free tables */ + +} + +void +IrReadTables (const char* dirname) +{ + char indexname[512]; + char filebuf [512]; + char absfilebuf [1024]; + FILE* index; + int res; + int nbline = 0; + + strcpy (indexname, dirname); + strcat (indexname, "/tables.dir"); + index = fopen (indexname, "r"); + + + if (!index) { + char errmsg [1024]; + sprintf (errmsg, "Cannot open index file %s", indexname); + perror (errmsg); + fprintf (stderr, "No table loaded\n"); + return; + } + + /* scan index file, and launch parsing of every file listed in the index */ + while ((res = fscanf (index, "%512s", filebuf)) != EOF) { + ++nbline; + if (!res) { + fprintf (stderr, "Malformatted line in %s, line %d:\n", indexname, nbline); + continue; + } + strcpy (absfilebuf, dirname); + strcat (absfilebuf, "/"); + strcat (absfilebuf, filebuf); + IrTableReadFile (absfilebuf); + } +} + -- cgit v1.1