xref: /csrg-svn/usr.bin/pascal/libpc/READE.c (revision 3869)
11682Smckusick /* Copyright (c) 1979 Regents of the University of California */
21682Smckusick 
3*3869Smckusic static char sccsid[] = "@(#)READE.c 1.5 06/10/81";
41682Smckusick 
51682Smckusick #include "h00vars.h"
61682Smckusick 
73020Smckusic long
81682Smckusick READE(curfile, name)
91682Smckusick 
101682Smckusick 	register struct iorec	*curfile;
111682Smckusick 	char			*name;
121682Smckusick {
131682Smckusick 	register short	*sptr;
141682Smckusick 	register int	len;
151682Smckusick 	register int	nextlen;
161682Smckusick 	register int	cnt;
171682Smckusick 	char		*cp;
181682Smckusick 	char		namebuf[NAMSIZ];
192223Smckusic 	int		retval;
201682Smckusick 
211682Smckusick 	if (curfile->funit & FWRITE) {
22*3869Smckusic 		ERROR("%s: Attempt to read, but open for writing\n",
23*3869Smckusic 			curfile->pfname);
241682Smckusick 		return;
251682Smckusick 	}
261682Smckusick 	UNSYNC(curfile);
272223Smckusic 	retval = fscanf(curfile->fbuf,
281682Smckusick 	    "%*[ \t\n]%74[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789]",
292223Smckusic 	    namebuf);
302223Smckusic 	if (retval == EOF) {
31*3869Smckusic 		ERROR("%s: Tried to read past end of file\n", curfile->pfname);
322223Smckusic 		return;
332223Smckusic 	}
34*3869Smckusic 	if (retval == 0)
35*3869Smckusic 		goto ename;
362309Smckusic 	curfile->funit &= ~EOLN;
371682Smckusick 	curfile->funit |= SYNC;
381682Smckusick 	for (len = 0; len < NAMSIZ && namebuf[len]; len++)
391682Smckusick 		/* void */;
401682Smckusick 	len++;
411682Smckusick 	sptr = (short *)name;
421682Smckusick 	cnt = *sptr++;
431682Smckusick 	cp = name + sizeof (short) + *sptr;
441682Smckusick 	do	{
451682Smckusick 		nextlen = *sptr++;
461682Smckusick 		nextlen = *sptr - nextlen;
471682Smckusick 		if (nextlen == len && RELEQ(len, namebuf, cp)) {
481682Smckusick 			return *((short *) name) - cnt;
491682Smckusick 		}
503020Smckusic 		cp += (int)nextlen;
511682Smckusick 	} while (--cnt);
52*3869Smckusic ename:
53*3869Smckusic 	ERROR("Unknown name \"%s\" found on enumerated type read\n", namebuf);
541682Smckusick }
55