2 * (c) copyright 1987 by the Vrije Universiteit, Amsterdam, The Netherlands.
3 * See the copyright notice in the ACK home directory, in the file "Copyright".
5 /* $Id: read.c,v 1.8 1994/06/24 12:25:57 ceriel Exp $ */
13 #define INP_NPUSHBACK 1
15 #include <inp_pkg.spec>
16 #include <inp_pkg.body>
22 /* Two dangerous macro's. They replace a single statement by
25 #define loadchar(ch) LoadChar(ch); if (ch=='\n') LineNr++
26 #define pushback(ch) PushBack(); if (ch=='\n') LineNr--
28 /* all the ReadX() functions return 0 upon EOI */
29 PRIVATE int ReadString();
30 PRIVATE int ReadInt();
31 PRIVATE int ReadArgs();
32 PRIVATE int ReadArg();
40 /* A low-level function which just reads a definition */
42 if (!ReadString(id->id_name, ':', NAMESIZE))
44 if (!ReadInt(&id->id_statnr))
48 loadchar(id->id_class);
49 if (id->id_class == EOI)
53 if (is_class(id, CL_FUNC|CL_DEF) || is_class(id, CL_FUNC|CL_USAGE)) {
54 /* read the argument information */
56 if (!ReadInt(&id->id_nrargs))
59 if (!ReadArgs(id->id_nrargs, id->id_argtps))
61 if (id->id_class == FC) {
63 if (!ReadInt(&id->id_valused))
67 /* function definition */
68 if (!ReadInt(&id->id_valreturned))
77 if (!ReadString(id->id_type, ':', TYPESIZE))
79 if (!ReadInt(&id->id_line))
83 if (!ReadString(id->id_file, '\n', FNAMESIZE))
89 ReadString(buf, delim, maxsize)
92 /* Reads a string until 'delim' is encountered; delim is
94 If 'maxsize-1' is exceeded or the string contains a newline
95 panic() is called (unless delim == newline).
96 A '\0' is appended to the string.
102 while (nread < maxsize - 1) {
109 panic("incomplete line in intermediate file");
112 buf[nread++] = (char)ch;
116 panic("line too long in intermediate file");
126 /* Reads a decimal integer until a character which is not
127 * a digit is encountered.
128 * Non-digits except minus-sign in front of the number are discarded.
129 * Doesn't check on overflow.
130 * Just a minus-sign is interpreted as 0. (To prevent a look-ahead.)
138 } while (!isdigit(ch) && ch != '-');
146 while (isdigit(ch)) {
147 res = 10*res + ch - '0';
151 *ip = (negative ? -res : res);
156 ReadArgs(nrargs, buf)
159 /* Reads a string into buf with format
160 <type1>:<type2>: ... :<typeN>:\0
161 Note: format must include the final colon.
167 /* variable # of args */
168 nrargs = -nrargs - 1;
171 for (i = 0; i < nrargs; i++) {
174 if (!ReadArg(buf, ARGTPSSIZE-charcount-1))
194 case '"': /* formal format or actual string */
196 if (!ReadString(buf, ch, size-1))
203 default: /* normal type */
205 return ReadString(buf, ':', size);
218 panic("bad format in intermediate file, '%c' expected; '%c' read",