/* Re-coding of advent in C: data structure routines */
static char sccsid
[] = " vocab.c 4.1 82/05/11 ";
if (from
>0 && from
<=300) carry(object
,from
);
{ if (place
[object
]== -1) return;
if (atloc
[where
]==object
)
{ atloc
[where
]=link
[object
];
for (temp
=atloc
[where
]; link
[temp
]!=object
; temp
=link
[temp
]);
{ if (object
>100) fixed
[object
-100]=where
;
{ if (place
[object
]== -1) holdng
--;
link
[object
]=atloc
[where
];
vocab(word
,type
,value
) /* look up or store a word */
int type
; /* -2 for store, -1 for user word, >=0 for canned lookup*/
int value
; /* used for storing only */
for (hash
=0,s
=word
,i
=0; i
<5 &&*s
; i
++) /* some kind of hash */
hash
+= *s
++; /* add all chars in the word */
hash
= (hash
*3719)&077777; /* pulled that one out of a hat */
hash
%= HTSIZE
; /* put it into range of table */
for(adr
=hash
;; adr
++) /* look for entry in table */
{ if (adr
==HTSIZE
) adr
=0; /* wrap around */
h
= &voc
[adr
]; /* point at the entry */
{ case -2: /* fill in entry */
if (h
->val
) /* already got an entry? */
h
->atab
=malloc(length(word
));
for (s
=word
,t
=h
->atab
; *s
;)
/* encrypt slightly to thwart core reader */
/* printf("Stored \"%s\" (%d ch) as entry %d\n", */
/* word, length(word), adr); */
return(0); /* entry unused */
case -1: /* looking up user word */
if (h
->val
==0) return(-1); /* not found */
for (s
=word
, t
=h
->atab
;*t
^ '=';)
if ((*s
++ ^ '=') != *t
++)
if ((*s
^ '=') != *t
&& s
-word
<5) goto exitloop2
;
/* the word matched o.k. */
default: /* looking up known word */
{ printf("Unable to find %s in vocab\n",word
);
for (s
=word
, t
=h
->atab
;*t
^ '=';)
if ((*s
++ ^ '=') != *t
++) goto exitloop2
;
/* the word matched o.k. */
if (h
->val
/1000 != type
) continue;
exitloop2
: /* hashed entry does not match */
if (adr
+1==hash
|| (adr
==HTSIZE
&& hash
==0))
{ printf("Hash table overflow\n");
copystr(w1
,w2
) /* copy one string to another */
weq(w1
,w2
) /* compare words */
char *w1
,*w2
; /* w1 is user, w2 is system */
for (i
=0; i
<5; i
++) /* compare at most 5 chars */
if (*s
++ != *t
++) return(FALSE
);
length(str
) /* includes 0 at end */
for (n
=0,s
=str
; *s
++;) n
++;
prht() /* print hash table */
for (i
=0; i
<HTSIZE
/10+1; i
++)
{ if (i
*10+j
>=HTSIZE
) break;
for (l
=0, c
=h
->atab
; l
<5; l
++)
if ((*c
^ '=')) putchar(*c
++ ^ '=');