2 * Fortune Cookie Comparison
4 * (c) 1996 Martin Mares, <mj@atrey.karlin.mff.cuni.cz>
24 die("Out of memory!\n");
36 static struct woord *words[HASH];
37 static unsigned lastid;
51 for(p = words[h]; p; p = p->next)
52 if (!strcasecmp(p->w, wd))
54 p = xmalloc(sizeof(struct woord) + strlen(wd));
72 static struct fortune *forts[FHASH];
75 comp(unsigned *p, unsigned *q)
86 addfort(char *fn, unsigned line, unsigned *fort, unsigned len)
91 // printf("Adding %s:%d (%d)\n", fn, line, len);
92 qsort(fort, len, sizeof(unsigned), (void *) comp);
97 for(foo=forts[h]; foo; foo=foo->next)
98 if (len == foo->count && !memcmp(fort, foo->words, sizeof(unsigned)*len))
100 printf("Possible DUP %s:%d with %s:%d\n", fn, line, foo->fn, foo->line);
103 foo = xmalloc(sizeof(struct fortune) + sizeof(unsigned)*len);
104 foo->next = forts[h];
109 memcpy(foo->words, fort, len * sizeof(unsigned));
115 struct woord *name = findword(fn);
120 unsigned posn, lino, cnt, xxx;
127 die("open failed!\n");
128 xxx = lino = posn = cnt = 0;
135 c = strchr(line, '\n');
138 if (line[0] == '%' && !line[1])
142 addfort(name->w, posn, forty, cnt);
154 while (*c && (*c < 'A' || *c > 'Z') && (*c < 'a' || *c > 'z') && (*c < '0' || *c > '9'))
159 while ((*c >= 'a' && *c <= 'z') || (*c >= 'A' && *c <= 'Z') || (*c >= '0' && *c <= '9'))
170 forty[cnt++] = wo->id;
175 printf("%d lines, %d fortunes\n", lino, xxx);
179 main(int argc, char **argv)
182 die("Nothing to do.\n");