diff options
-rw-r--r-- | irtable.c | 82 | ||||
-rw-r--r-- | irtable.h | 7 |
2 files changed, 88 insertions, 1 deletions
@@ -7,8 +7,12 @@ * * Tables for decoding events * + * Authors: Stephane Chatty <chatty@cenatoulouse.dgac.fr> + * * $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); + } +} + @@ -7,8 +7,12 @@ * * Tables for decoding events * + * Authors: Stephane Chatty <chatty@cenatoulouse.dgac.fr> + * * $Id$ * + * Please refer to file version.h for the + * copyright notice regarding this software */ #ifndef irtable_h_ @@ -19,6 +23,9 @@ typedef struct { const char* type; } IrTable; +extern void IrResetTables (void); +extern void IrReadTables (const char*); + extern IrTable* IrTableReadFile (const char*); extern IrTable* IrCreateTable (); extern void IrTableName (IrTable*, const char*); |