1 /* @(#)scanner.c 8.1 (Berkeley) 6/6/93 */
2 /* $NetBSD: scanner.c,v 1.9 2003/08/07 11:17:29 agc Exp $ */
5 * Copyright (c) 1983, 1993
6 * The Regents of the University of California. All rights reserved.
8 * This code is derived from software contributed to Berkeley by
9 * Edward Wang at The University of California, Berkeley.
11 * Redistribution and use in source and binary forms, with or without
12 * modification, are permitted provided that the following conditions
14 * 1. Redistributions of source code must retain the above copyright
15 * notice, this list of conditions and the following disclaimer.
16 * 2. Redistributions in binary form must reproduce the above copyright
17 * notice, this list of conditions and the following disclaimer in the
18 * documentation and/or other materials provided with the distribution.
19 * 3. Neither the name of the University nor the names of its contributors
20 * may be used to endorse or promote products derived from this software
21 * without specific prior written permission.
23 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
24 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
25 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
26 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
27 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
28 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
29 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
30 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
31 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
32 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
41 #include "window_string.h"
55 if (cx.x_bol && c != EOF) {
64 return *cx.x_bufp++ & 0xff;
69 return(0); /* XXX: placate gcc */
80 return ungetc(c, cx.x_fp);
82 if (cx.x_bufp > cx.x_buf)
83 return *--cx.x_bufp = c;
88 return(0); /* XXX: placate gcc */
119 case 'a': case 'b': case 'c': case 'd': case 'e':
120 case 'f': case 'g': case 'h': case 'i': case 'j':
121 case 'k': case 'l': case 'm': case 'n': case 'o':
122 case 'p': case 'q': case 'r': case 's': case 't':
123 case 'u': case 'v': case 'w': case 'x': case 'y':
125 case 'A': case 'B': case 'C': case 'D': case 'E':
126 case 'F': case 'G': case 'H': case 'I': case 'J':
127 case 'K': case 'L': case 'M': case 'N': case 'O':
128 case 'P': case 'Q': case 'R': case 'S': case 'T':
129 case 'U': case 'V': case 'W': case 'X': case 'Y':
142 switch (c = s_gettok1()) {
157 case '1': case '2': case '3': case '4':
158 case '5': case '6': case '7': case '8': case '9':
159 cx.x_val.v_num = c - '0';
192 cx.x_token = T_MINUS;
220 cx.x_token = T_COMMA;
224 cx.x_token = T_QUEST;
228 cx.x_token = T_COLON;
247 if (c == '\n' || c == EOF) {
252 case 2: /* unquoted string */
254 case 'a': case 'b': case 'c': case 'd': case 'e':
255 case 'f': case 'g': case 'h': case 'i': case 'j':
256 case 'k': case 'l': case 'm': case 'n': case 'o':
257 case 'p': case 'q': case 'r': case 's': case 't':
258 case 'u': case 'v': case 'w': case 'x': case 'y':
260 case 'A': case 'B': case 'C': case 'D': case 'E':
261 case 'F': case 'G': case 'H': case 'I': case 'J':
262 case 'K': case 'L': case 'M': case 'N': case 'O':
263 case 'P': case 'Q': case 'R': case 'S': case 'T':
264 case 'U': case 'V': case 'W': case 'X': case 'Y':
267 case '0': case '1': case '2': case '3': case '4':
268 case '5': case '6': case '7': case '8': case '9':
269 if (p < buf + sizeof buf - 1)
279 switch (c = s_gettok1()) {
281 (void) s_ungetc(' ');
285 if (p < buf + sizeof buf - 1)
297 if (buf[1] == 'f' && buf[2] == 0)
301 if (buf[1] == 'h' && buf[2] == 'e'
302 && buf[3] == 'n' && buf[4] == 0)
306 if (buf[1] == 'n' && buf[2] == 'd'
307 && buf[3] == 'i' && buf[4] == 'f'
309 cx.x_token = T_ENDIF;
311 if (buf[1] == 'l' && buf[2] == 's') {
315 cx.x_token = T_ELSIF;
326 if (cx.x_token == T_STR
327 && (cx.x_val.v_str = str_cpy(buf)) == 0) {
335 case 3: /* " quoted string */
345 switch (c = s_gettok1()) {
347 case -2: /* newlines are invisible */
350 if (p < buf + sizeof buf - 1)
355 if (p < buf + sizeof buf - 1)
360 case 4: /* ' quoted string */
370 switch (c = s_gettok1()) {
372 case -2: /* newlines are invisible */
375 if (p < buf + sizeof buf - 1)
380 if (p < buf + sizeof buf - 1)
392 case '0': case '1': case '2': case '3': case '4':
393 case '5': case '6': case '7':
394 cx.x_val.v_num = c - '0';
398 cx.x_val.v_num = c - '0';
407 case 11: /* decimal number */
409 case '0': case '1': case '2': case '3': case '4':
410 case '5': case '6': case '7': case '8': case '9':
411 cx.x_val.v_num = cx.x_val.v_num * 10 + c - '0';
419 case 12: /* hex number */
421 case '0': case '1': case '2': case '3': case '4':
422 case '5': case '6': case '7': case '8': case '9':
423 cx.x_val.v_num = cx.x_val.v_num * 16 + c - '0';
425 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
426 cx.x_val.v_num = cx.x_val.v_num * 16 + c - 'a' + 10;
428 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
429 cx.x_val.v_num = cx.x_val.v_num * 16 + c - 'A' + 10;
437 case 13: /* octal number */
439 case '0': case '1': case '2': case '3': case '4':
440 case '5': case '6': case '7':
441 cx.x_val.v_num = cx.x_val.v_num * 8 + c - '0';
489 cx.x_token = T_ASSIGN;
508 cx.x_token = T_ANDAND;
537 cx.x_token = T_DOLLAR;
555 c = s_getc(); /* got \ */
573 case '0': case '1': case '2': case '3': case '4':
574 case '5': case '6': case '7':
578 c = s_getc(); /* got \[0-7] */
579 if (c < '0' || c > '7') {
584 c = s_getc(); /* got \[0-7][0-7] */
585 if (c < '0' || c > '7') {
589 return n * 8 + c - '0';