Commit | Line | Data |
---|---|---|
0d78ca85 KB |
1 | /*- |
2 | * Copyright (c) 1979 The Regents of the University of California. | |
3 | * All rights reserved. | |
4 | * | |
5 | * %sccs.include.redist.c% | |
6 | */ | |
0148435a | 7 | |
0d78ca85 KB |
8 | #ifndef lint |
9 | static char sccsid[] = "@(#)READE.c 1.8 (Berkeley) %G%"; | |
10 | #endif /* not lint */ | |
0148435a KM |
11 | |
12 | #include "h00vars.h" | |
0148435a | 13 | |
492cc5d3 | 14 | long |
0148435a KM |
15 | READE(curfile, name) |
16 | ||
17 | register struct iorec *curfile; | |
18 | char *name; | |
19 | { | |
0148435a KM |
20 | register short *sptr; |
21 | register int len; | |
22 | register int nextlen; | |
23 | register int cnt; | |
24 | char *cp; | |
25 | char namebuf[NAMSIZ]; | |
53909d1e | 26 | int retval; |
0148435a KM |
27 | |
28 | if (curfile->funit & FWRITE) { | |
86997b19 KM |
29 | ERROR("%s: Attempt to read, but open for writing\n", |
30 | curfile->pfname); | |
0148435a KM |
31 | } |
32 | UNSYNC(curfile); | |
53909d1e | 33 | retval = fscanf(curfile->fbuf, |
0148435a | 34 | "%*[ \t\n]%74[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789]", |
53909d1e KM |
35 | namebuf); |
36 | if (retval == EOF) { | |
86997b19 | 37 | ERROR("%s: Tried to read past end of file\n", curfile->pfname); |
0148435a | 38 | } |
86997b19 KM |
39 | if (retval == 0) |
40 | goto ename; | |
0148435a KM |
41 | for (len = 0; len < NAMSIZ && namebuf[len]; len++) |
42 | /* void */; | |
43 | len++; | |
44 | sptr = (short *)name; | |
45 | cnt = *sptr++; | |
46 | cp = name + sizeof (short) + *sptr; | |
47 | do { | |
48 | nextlen = *sptr++; | |
49 | nextlen = *sptr - nextlen; | |
50 | if (nextlen == len && RELEQ(len, namebuf, cp)) { | |
51 | return *((short *) name) - cnt; | |
52 | } | |
492cc5d3 | 53 | cp += (int)nextlen; |
0148435a | 54 | } while (--cnt); |
86997b19 KM |
55 | ename: |
56 | ERROR("Unknown name \"%s\" found on enumerated type read\n", namebuf); | |
a745d566 | 57 | return 0; |
0148435a | 58 | } |