11682Smckusick /* Copyright (c) 1979 Regents of the University of California */ 21682Smckusick 3*36533Smckusick static char sccsid[] = "@(#)READE.c 1.7 01/09/89"; 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) { 223869Smckusic ERROR("%s: Attempt to read, but open for writing\n", 233869Smckusic curfile->pfname); 241682Smckusick } 251682Smckusick UNSYNC(curfile); 262223Smckusic retval = fscanf(curfile->fbuf, 271682Smckusick "%*[ \t\n]%74[abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789]", 282223Smckusic namebuf); 292223Smckusic if (retval == EOF) { 303869Smckusic ERROR("%s: Tried to read past end of file\n", curfile->pfname); 312223Smckusic } 323869Smckusic if (retval == 0) 333869Smckusic goto ename; 341682Smckusick for (len = 0; len < NAMSIZ && namebuf[len]; len++) 351682Smckusick /* void */; 361682Smckusick len++; 371682Smckusick sptr = (short *)name; 381682Smckusick cnt = *sptr++; 391682Smckusick cp = name + sizeof (short) + *sptr; 401682Smckusick do { 411682Smckusick nextlen = *sptr++; 421682Smckusick nextlen = *sptr - nextlen; 431682Smckusick if (nextlen == len && RELEQ(len, namebuf, cp)) { 441682Smckusick return *((short *) name) - cnt; 451682Smckusick } 463020Smckusic cp += (int)nextlen; 471682Smckusick } while (--cnt); 483869Smckusic ename: 493869Smckusic ERROR("Unknown name \"%s\" found on enumerated type read\n", namebuf); 50*36533Smckusick return 0; 511682Smckusick } 52