2 * Copyright (c) 1983, 1993
3 * The Regents of the University of California. All rights reserved.
5 * This code is derived from software contributed to Berkeley by
6 * Edward Wang at The University of California, Berkeley.
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
11 * 1. Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * 3. All advertising materials mentioning features or use of this software
17 * must display the following acknowledgement:
18 * This product includes software developed by the University of
19 * California, Berkeley and its contributors.
20 * 4. Neither the name of the University nor the names of its contributors
21 * may be used to endorse or promote products derived from this software
22 * without specific prior written permission.
24 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
25 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
26 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
27 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
28 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
29 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
30 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
31 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
32 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
33 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
38 static char sccsid[] = "@(#)scanner.c 8.1 (Berkeley) 6/6/93";
54 if (cx.x_bol && c != EOF) {
63 return *cx.x_bufp++ & 0xff;
77 return ungetc(c, cx.x_fp);
79 if (cx.x_bufp > cx.x_buf)
80 return *--cx.x_bufp = c;
90 register char *p = buf;
121 switch (c = s_gettok1()) {
136 case '1': case '2': case '3': case '4':
137 case '5': case '6': case '7': case '8': case '9':
138 cx.x_val.v_num = c - '0';
171 cx.x_token = T_MINUS;
199 cx.x_token = T_COMMA;
203 cx.x_token = T_QUEST;
207 cx.x_token = T_COLON;
219 if (isalpha(c) || c == '_' || c == '.') {
231 if (c == '\n' || c == EOF) {
236 case 2: /* unquoted string */
245 switch (c = s_gettok1()) {
247 (void) s_ungetc(' ');
251 if (p < buf + sizeof buf - 1)
256 if (isalnum(c) || c == '_' || c == '.') {
257 if (p < buf + sizeof buf - 1)
267 if (buf[1] == 'f' && buf[2] == 0)
271 if (buf[1] == 'h' && buf[2] == 'e'
272 && buf[3] == 'n' && buf[4] == 0)
276 if (buf[1] == 'n' && buf[2] == 'd'
277 && buf[3] == 'i' && buf[4] == 'f'
279 cx.x_token = T_ENDIF;
280 else if (buf[1] == 'l' && buf[2] == 's')
281 if (buf[3] == 'i' && buf[4] == 'f'
283 cx.x_token = T_ELSIF;
284 else if (buf[3] == 'e' && buf[4] == 0)
288 if (cx.x_token == T_STR
289 && (cx.x_val.v_str = str_cpy(buf)) == 0) {
297 case 3: /* " quoted string */
306 switch (c = s_gettok1()) {
308 case -2: /* newlines are invisible */
311 if (p < buf + sizeof buf - 1)
316 if (p < buf + sizeof buf - 1)
321 case 4: /* ' quoted string */
330 switch (c = s_gettok1()) {
332 case -2: /* newlines are invisible */
335 if (p < buf + sizeof buf - 1)
340 if (p < buf + sizeof buf - 1)
352 case '0': case '1': case '2': case '3': case '4':
353 case '5': case '6': case '7':
354 cx.x_val.v_num = c - '0';
358 cx.x_val.v_num = c - '0';
367 case 11: /* decimal number */
369 case '0': case '1': case '2': case '3': case '4':
370 case '5': case '6': case '7': case '8': case '9':
371 cx.x_val.v_num = cx.x_val.v_num * 10 + c - '0';
379 case 12: /* hex number */
381 case '0': case '1': case '2': case '3': case '4':
382 case '5': case '6': case '7': case '8': case '9':
383 cx.x_val.v_num = cx.x_val.v_num * 16 + c - '0';
385 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
386 cx.x_val.v_num = cx.x_val.v_num * 16 + c - 'a' + 10;
388 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
389 cx.x_val.v_num = cx.x_val.v_num * 16 + c - 'A' + 10;
397 case 13: /* octal number */
399 case '0': case '1': case '2': case '3': case '4':
400 case '5': case '6': case '7':
401 cx.x_val.v_num = cx.x_val.v_num * 8 + c - '0';
449 cx.x_token = T_ASSIGN;
468 cx.x_token = T_ANDAND;
497 cx.x_token = T_DOLLAR;
514 c = s_getc(); /* got \ */
532 case '0': case '1': case '2': case '3': case '4':
533 case '5': case '6': case '7':
537 c = s_getc(); /* got \[0-7] */
538 if (c < '0' || c > '7') {
543 c = s_getc(); /* got \[0-7][0-7] */
544 if (c < '0' || c > '7') {
548 return n * 8 + c - '0';