-/* $NetBSD: vocab.c,v 1.6 1998/08/24 22:26:23 hubertf Exp $ */
+/* $NetBSD: vocab.c,v 1.10 2000/01/09 17:17:19 jsm Exp $ */
/*-
* Copyright (c) 1991, 1993
#if 0
static char sccsid[] = "@(#)vocab.c 8.1 (Berkeley) 5/31/93";
#else
-__RCSID("$NetBSD: vocab.c,v 1.6 1998/08/24 22:26:23 hubertf Exp $");
+__RCSID("$NetBSD: vocab.c,v 1.10 2000/01/09 17:17:19 jsm Exp $");
#endif
#endif /* not lint */
/* Re-coding of advent in C: data structure routines */
+#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include "hdr.h"
int
vocab(word, type, value) /* look up or store a word */
- char *word;
+ const char *word;
int type; /* -2 for store, -1 for user word, >=0 for
* canned lookup */
int value; /* used for storing only */
{
int adr;
- char *s, *t;
+ const char *s;
+ char *t;
int hash, i;
struct hashtab *h;
goto exitloop2;
h->val = value;
h->atab = malloc(length(word));
+ if (h->atab == NULL)
+ err(1, NULL);
for (s = word, t = h->atab; *s;)
*t++ = *s++ ^ '=';
*t = 0 ^ '=';
/* the word matched o.k. */
return (h->val);
default: /* looking up known word */
- if (h->val == 0) {
- printf("Unable to find %s in vocab\n", word);
- exit(0);
- }
+ if (h->val == 0)
+ errx(1,"Unable to find %s in vocab", word);
for (s = word, t = h->atab; *t ^ '=';)
if ((*s++ ^ '=') != *t++)
goto exitloop2;
}
exitloop2: /* hashed entry does not match */
- if (adr + 1 == hash || (adr == HTSIZE && hash == 0)) {
- printf("Hash table overflow\n");
- exit(0);
- }
+ if (adr + 1 == hash || (adr == HTSIZE && hash == 0))
+ errx(1,"Hash table overflow");
}
}