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";
57 if (cx.x_bol && c != EOF) {
66 return *cx.x_bufp++ & 0xff;
80 return ungetc(c, cx.x_fp);
82 if (cx.x_bufp > cx.x_buf)
83 return *--cx.x_bufp = c;
93 register char *p = buf;
124 switch (c = s_gettok1()) {
139 case '1': case '2': case '3': case '4':
140 case '5': case '6': case '7': case '8': case '9':
141 cx.x_val.v_num = c - '0';
174 cx.x_token = T_MINUS;
202 cx.x_token = T_COMMA;
206 cx.x_token = T_QUEST;
210 cx.x_token = T_COLON;
222 if (isalpha(c) || c == '_' || c == '.') {
234 if (c == '\n' || c == EOF) {
239 case 2: /* unquoted string */
248 switch (c = s_gettok1()) {
250 (void) s_ungetc(' ');
254 if (p < buf + sizeof buf - 1)
259 if (isalnum(c) || c == '_' || c == '.') {
260 if (p < buf + sizeof buf - 1)
270 if (buf[1] == 'f' && buf[2] == 0)
274 if (buf[1] == 'h' && buf[2] == 'e'
275 && buf[3] == 'n' && buf[4] == 0)
279 if (buf[1] == 'n' && buf[2] == 'd'
280 && buf[3] == 'i' && buf[4] == 'f'
282 cx.x_token = T_ENDIF;
283 else if (buf[1] == 'l' && buf[2] == 's')
284 if (buf[3] == 'i' && buf[4] == 'f'
286 cx.x_token = T_ELSIF;
287 else if (buf[3] == 'e' && buf[4] == 0)
291 if (cx.x_token == T_STR
292 && (cx.x_val.v_str = str_cpy(buf)) == 0) {
300 case 3: /* " quoted string */
309 switch (c = s_gettok1()) {
311 case -2: /* newlines are invisible */
314 if (p < buf + sizeof buf - 1)
319 if (p < buf + sizeof buf - 1)
324 case 4: /* ' quoted string */
333 switch (c = s_gettok1()) {
335 case -2: /* newlines are invisible */
338 if (p < buf + sizeof buf - 1)
343 if (p < buf + sizeof buf - 1)
355 case '0': case '1': case '2': case '3': case '4':
356 case '5': case '6': case '7':
357 cx.x_val.v_num = c - '0';
361 cx.x_val.v_num = c - '0';
370 case 11: /* decimal number */
372 case '0': case '1': case '2': case '3': case '4':
373 case '5': case '6': case '7': case '8': case '9':
374 cx.x_val.v_num = cx.x_val.v_num * 10 + c - '0';
382 case 12: /* hex number */
384 case '0': case '1': case '2': case '3': case '4':
385 case '5': case '6': case '7': case '8': case '9':
386 cx.x_val.v_num = cx.x_val.v_num * 16 + c - '0';
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;
391 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
392 cx.x_val.v_num = cx.x_val.v_num * 16 + c - 'A' + 10;
400 case 13: /* octal number */
402 case '0': case '1': case '2': case '3': case '4':
403 case '5': case '6': case '7':
404 cx.x_val.v_num = cx.x_val.v_num * 8 + c - '0';
452 cx.x_token = T_ASSIGN;
471 cx.x_token = T_ANDAND;
500 cx.x_token = T_DOLLAR;
517 c = s_getc(); /* got \ */
535 case '0': case '1': case '2': case '3': case '4':
536 case '5': case '6': case '7':
540 c = s_getc(); /* got \[0-7] */
541 if (c < '0' || c > '7') {
546 c = s_getc(); /* got \[0-7][0-7] */
547 if (c < '0' || c > '7') {
551 return n * 8 + c - '0';