1*40865Sbostic /*- 2*40865Sbostic * Copyright (c) 1979 The Regents of the University of California. 3*40865Sbostic * All rights reserved. 4*40865Sbostic * 5*40865Sbostic * %sccs.include.redist.c% 6*40865Sbostic */ 71682Smckusick 8*40865Sbostic #ifndef lint 9*40865Sbostic static char sccsid[] = "@(#)READE.c 1.8 (Berkeley) 04/09/90"; 10*40865Sbostic #endif /* not lint */ 111682Smckusick 121682Smckusick #include "h00vars.h" 131682Smckusick 143020Smckusic long 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