summaryrefslogtreecommitdiff
path: root/irtable.c
diff options
context:
space:
mode:
authorchatty1999-01-19 13:07:40 +0000
committerchatty1999-01-19 13:07:40 +0000
commita9a15b453b5dcca597fa4aeee5a2376ce1154b15 (patch)
tree827650e3958849146e821e7d56846e9f50a26f0b /irtable.c
parentd5c5e0bcd952c2b58fd02409d01b10da83872ef0 (diff)
downloadirbox-a9a15b453b5dcca597fa4aeee5a2376ce1154b15.zip
irbox-a9a15b453b5dcca597fa4aeee5a2376ce1154b15.tar.gz
irbox-a9a15b453b5dcca597fa4aeee5a2376ce1154b15.tar.bz2
irbox-a9a15b453b5dcca597fa4aeee5a2376ce1154b15.tar.xz
Added grammar and management of translation tables for events
irbox.c -> irman.c
Diffstat (limited to 'irtable.c')
-rw-r--r--irtable.c111
1 files changed, 111 insertions, 0 deletions
diff --git a/irtable.c b/irtable.c
new file mode 100644
index 0000000..9be02fa
--- /dev/null
+++ b/irtable.c
@@ -0,0 +1,111 @@
+#include "irtable.h"
+#include "irdev.h"
+#include <stdlib.h>
+#include <stdio.h>
+#include <string.h>
+
+typedef struct _irtablecell IrTableCell;
+
+struct _irtablecell {
+ IrTable* table;
+ unsigned char code[6];
+ const char* key;
+ IrTableCell* next;
+};
+
+
+
+
+IrTable*
+IrCreateTable ()
+{
+ return (IrTable*) malloc (sizeof (IrTable));
+}
+
+void
+IrTableName (IrTable* t, const char* n)
+{
+ t->name = strdup (n);
+}
+
+void
+IrTableType (IrTable* t, const char* type)
+{
+ t->type = strdup (type);
+}
+
+void
+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)
+{
+ register unsigned int h = 0;
+ register const char* p = key;
+ while (*p)
+ h += (h << 3) + *p++; /* this hash function was stolen from Tcl */
+ return h % KEYCELLS;
+}
+
+static unsigned int
+IrHashCode (const unsigned char* code)
+{
+ register unsigned int h = 0;
+ register const unsigned char* p = code;
+ register const unsigned char* q = p+6;
+ while (p < q)
+ h += (h << 3) + *p++; /* A ADAPTER */
+ return h % CODECELLS;
+}
+
+void
+IrTableAddKey (IrTable* t, const char* k, int c0, int c1, int c2, int c3 , int c4, int c5)
+{
+ IrTableCell* c = (IrTableCell*) malloc (sizeof (IrTableCell));
+ IrTableCell** cc;
+
+ c->table = t;
+ c->key = strdup (k);
+ c->code[0] = c0;
+ c->code[1] = c1;
+ c->code[2] = c2;
+ c->code[3] = c3;
+ c->code[4] = c4;
+ c->code[5] = c5;
+ cc = CodeToCell + IrHashCode (c->code);
+ /* GERER LES COLLISIONS */
+ c->next = *cc;
+ *cc = c;
+}
+
+int
+IrTableTranslateCode (const unsigned char* code, IrTable** table, const char** key)
+{
+ IrTableCell* c;
+
+ c = CodeToCell [IrHashCode (code)];
+ while (c) {
+ if (strncmp (code, c->code, 6) == 0)
+ break;
+ c = c->next;
+ }
+ if (c) {
+ if (table) *table = c->table;
+ if (key) *key = c->key;
+ } else {
+ if (table) *table = 0;
+ if (key) *key = 0;
+ }
+ return (int) (c);
+}
+