diff options
author | chatty | 1999-01-19 18:20:36 +0000 |
---|---|---|
committer | chatty | 1999-01-19 18:20:36 +0000 |
commit | 5466043190dac5b352df63942d26c1e2614dd9af (patch) | |
tree | abcef774cc8e27fc0c541d4a0be00947c28be35a /irtable.c | |
parent | a9a15b453b5dcca597fa4aeee5a2376ce1154b15 (diff) | |
download | irbox-5466043190dac5b352df63942d26c1e2614dd9af.zip irbox-5466043190dac5b352df63942d26c1e2614dd9af.tar.gz irbox-5466043190dac5b352df63942d26c1e2614dd9af.tar.bz2 irbox-5466043190dac5b352df63942d26c1e2614dd9af.tar.xz |
Added collision handling in tables.
Added initialisation of arrays
Diffstat (limited to 'irtable.c')
-rw-r--r-- | irtable.c | 50 |
1 files changed, 42 insertions, 8 deletions
@@ -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; } |