1 /* $Id: mktable.c,v 1.15 2007/05/31 01:19:50 inu Exp $ */
12 defhash(HashItem_ss *, int, hss_i)
15 #define keycomp(x,y) ((x)==(y))
17 /* XXX: we assume sizeof(unsigned long) >= sizeof(void *) */
19 hashfunc(HashItem_ss * x)
21 return (unsigned long)x;
25 defhashfunc(HashItem_ss *, int, hss_i)
29 main(int argc, char *argv[], char **envp)
33 HashItem_ss **hashitems, *hi;
41 fprintf(stderr, "usage: %s hashsize file.tab > file.c\n", argv[0]);
46 fprintf(stderr, "hash size should be positive\n");
49 if ((f = fopen(argv[2], "r")) == NULL) {
50 fprintf(stderr, "Can't open %s\n", argv[2]);
54 if (strrchr(p, '/') != NULL)
55 p = strrchr(p, '/') + 1;
56 fbase = Strnew_charp(p);
57 if (strchr(fbase->ptr, '.'))
58 while (Strlastchar(fbase) != '.')
62 hash = newHash_ss(size);
63 printf("#include \"hash.h\"\n");
68 Strremovetrailingspaces(s);
69 if (Strcmp_charp(s, "%%") == 0)
78 Strremovefirstspaces(s);
79 Strremovetrailingspaces(s);
81 for (p = s->ptr; *p; p++) {
84 Strcat_char(name, *p);
86 while (*p && IS_SPACE(*p))
88 putHash_ss(hash, name->ptr, p);
93 hashitems = (HashItem_ss **) GC_malloc(sizeof(HashItem_ss *) * n);
94 rhash = newHash_hss_i(n * 2);
96 for (i = 0; i < hash->size; i++) {
97 for (hi = hash->tab[i]; hi != NULL; hi = hi->next) {
99 putHash_hss_i(rhash, hi, j);
103 printf("static HashItem_si MyHashItem[] = {\n");
104 for (i = 0; i < j; i++) {
105 printf(" /* %d */ {\"%s\",%s,", i,
106 hashitems[i]->key, hashitems[i]->value);
107 if (hashitems[i]->next == NULL) {
111 printf("&MyHashItem[%d]},\n",
112 getHash_hss_i(rhash, hashitems[i]->next, -1));
115 printf("};\n\nstatic HashItem_si *MyHashItemTbl[] = {\n");
117 for (i = 0; i < hash->size; i++) {
119 printf(" &MyHashItem[%d],\n",
120 getHash_hss_i(rhash, hash->tab[i], -1));
125 printf("Hash_si %s = {%d, MyHashItemTbl};\n", fbase->ptr, hash->size);