summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorchatty1999-01-25 17:06:33 +0000
committerchatty1999-01-25 17:06:33 +0000
commit4a74019ccbd44626eb96fe751f406ff3fbe30735 (patch)
treef39d72fb4562b25b72affa52408545dc4a49febd
parent5466043190dac5b352df63942d26c1e2614dd9af (diff)
downloadirbox-4a74019ccbd44626eb96fe751f406ff3fbe30735.zip
irbox-4a74019ccbd44626eb96fe751f406ff3fbe30735.tar.gz
irbox-4a74019ccbd44626eb96fe751f406ff3fbe30735.tar.bz2
irbox-4a74019ccbd44626eb96fe751f406ff3fbe30735.tar.xz
Added ReadTables and ResetTables
-rw-r--r--irtable.c82
-rw-r--r--irtable.h7
2 files changed, 88 insertions, 1 deletions
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 <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);
+ }
+}
+
diff --git a/irtable.h b/irtable.h
index 565f6c8..fc2ed4d 100644
--- a/irtable.h
+++ b/irtable.h
@@ -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*);