xref: /csrg-svn/usr.bin/pascal/libpc/READE.c (revision 62096)
140865Sbostic /*-
2*62096Sbostic  * Copyright (c) 1979, 1993
3*62096Sbostic  *	The Regents of the University of California.  All rights reserved.
440865Sbostic  *
540865Sbostic  * %sccs.include.redist.c%
640865Sbostic  */
71682Smckusick 
840865Sbostic #ifndef lint
9*62096Sbostic static char sccsid[] = "@(#)READE.c	8.1 (Berkeley) 06/06/93";
1040865Sbostic #endif /* not lint */
111682Smckusick 
121682Smckusick #include "h00vars.h"
131682Smckusick 
143020Smckusic long
READE(curfile,name)151682Smckusick READE(curfile, name)
161682Smckusick 
171682Smckusick 	register struct iorec	*curfile;
181682Smckusick 	char			*name;
191682Smckusick {
201682Smckusick 	register short	*sptr;
211682Smckusick 	register int	len;
221682Smckusick 	register int	nextlen;
231682Smckusick 	register int	cnt;
241682Smckusick 	char		*cp;
251682Smckusick 	char		namebuf[NAMSIZ];
262223Smckusic 	int		retval;
271682Smckusick 
281682Smckusick 	if (curfile->funit & FWRITE) {
293869Smckusic 		ERROR("%s: Attempt to read, but open for writing\n",
303869Smckusic 			curfile->pfname);
311682Smckusick 	}
321682Smckusick 	UNSYNC(curfile);
332223Smckusic 	retval = fscanf(curfile->fbuf,
341682Smckusick 	    "%*[ \t\n]%74[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789]",
352223Smckusic 	    namebuf);
362223Smckusic 	if (retval == EOF) {
373869Smckusic 		ERROR("%s: Tried to read past end of file\n", curfile->pfname);
382223Smckusic 	}
393869Smckusic 	if (retval == 0)
403869Smckusic 		goto ename;
411682Smckusick 	for (len = 0; len < NAMSIZ && namebuf[len]; len++)
421682Smckusick 		/* void */;
431682Smckusick 	len++;
441682Smckusick 	sptr = (short *)name;
451682Smckusick 	cnt = *sptr++;
461682Smckusick 	cp = name + sizeof (short) + *sptr;
471682Smckusick 	do	{
481682Smckusick 		nextlen = *sptr++;
491682Smckusick 		nextlen = *sptr - nextlen;
501682Smckusick 		if (nextlen == len && RELEQ(len, namebuf, cp)) {
511682Smckusick 			return *((short *) name) - cnt;
521682Smckusick 		}
533020Smckusic 		cp += (int)nextlen;
541682Smckusick 	} while (--cnt);
553869Smckusic ename:
563869Smckusic 	ERROR("Unknown name \"%s\" found on enumerated type read\n", namebuf);
5736533Smckusick 	return 0;
581682Smckusick }
59