summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--irtable.c50
-rw-r--r--irtable.h10
2 files changed, 47 insertions, 13 deletions
diff --git a/irtable.c b/irtable.c
index 9be02fa..c62aa95 100644
--- a/irtable.c
+++ b/irtable.c
@@ -1,3 +1,16 @@
+/*
+ *
+ * IRBOX, an Ivy driver for infra-red remote controls
+ *
+ * Copyright 1998-1999
+ * Centre d'Etudes de la Navigation Aerienne
+ *
+ * Tables for decoding events
+ *
+ * $Id$
+ *
+ */
+
#include "irtable.h"
#include "irdev.h"
#include <stdlib.h>
@@ -14,11 +27,23 @@ struct _irtablecell {
};
+#define KEYCELLS 127
+#define CODECELLS 1023
+
+static IrTableCell* KeyToCell [KEYCELLS];
+static IrTableCell* CodeToCell [CODECELLS];
+static int Initialized = 0;
+
IrTable*
IrCreateTable ()
{
+ if (!Initialized) {
+ Initialized = 1;
+ memset (KeyToCell, 0, sizeof (KeyToCell));
+ memset (CodeToCell, 0, sizeof (CodeToCell));
+ }
return (IrTable*) malloc (sizeof (IrTable));
}
@@ -41,12 +66,6 @@ IrTableAddBrand (IrTable* t, const char* b)
-#define KEYCELLS 127
-#define CODECELLS 1023
-
-static IrTableCell* KeyToCell [KEYCELLS];
-static IrTableCell* CodeToCell [CODECELLS];
-
static unsigned int
IrHashKey (const char* key)
{
@@ -73,9 +92,9 @@ IrTableAddKey (IrTable* t, const char* k, int c0, int c1, int c2, int c3 , int c
{
IrTableCell* c = (IrTableCell*) malloc (sizeof (IrTableCell));
IrTableCell** cc;
+ IrTableCell* p;
c->table = t;
- c->key = strdup (k);
c->code[0] = c0;
c->code[1] = c1;
c->code[2] = c2;
@@ -83,7 +102,22 @@ IrTableAddKey (IrTable* t, const char* k, int c0, int c1, int c2, int c3 , int c
c->code[4] = c4;
c->code[5] = c5;
cc = CodeToCell + IrHashCode (c->code);
- /* GERER LES COLLISIONS */
+
+ /* collision handling */
+ p = *cc;
+ while (p) {
+ if (strncmp (p->code, c->code, 6) == 0) {
+ fprintf (stderr, "Code for key \'%s\' on %s", k, t->name);
+ fprintf (stderr, " was already registered");
+ fprintf (stderr, " for key \'%s\' on %s\n", p->key, p->table->name);
+ free (c);
+ return;
+ }
+ p = p->next;
+ }
+
+ /* fine, we can keep on storing that key */
+ c->key = strdup (k);
c->next = *cc;
*cc = c;
}
diff --git a/irtable.h b/irtable.h
index ed751fd..565f6c8 100644
--- a/irtable.h
+++ b/irtable.h
@@ -1,13 +1,13 @@
/*
*
- * IRBOX, an Ivy driver for infra-red remote controls
+ * IRBOX, an Ivy driver for infra-red remote controls
*
- * Copyright 1998-1999
- * Centre d'Etudes de la Navigation Aerienne
+ * Copyright 1998-1999
+ * Centre d'Etudes de la Navigation Aerienne
*
- * Tables for decoding events
+ * Tables for decoding events
*
- * $Id$
+ * $Id$
*
*/