1 /* $NetBSD: scanner.c,v 1.8 2002/06/14 01:06:54 wiz Exp $ */
4 * Copyright (c) 1983, 1993
5 * The Regents of the University of California. All rights reserved.
7 * This code is derived from software contributed to Berkeley by
8 * Edward Wang at The University of California, Berkeley.
10 * Redistribution and use in source and binary forms, with or without
11 * modification, are permitted provided that the following conditions
13 * 1. Redistributions of source code must retain the above copyright
14 * notice, this list of conditions and the following disclaimer.
15 * 2. Redistributions in binary form must reproduce the above copyright
16 * notice, this list of conditions and the following disclaimer in the
17 * documentation and/or other materials provided with the distribution.
18 * 3. Neither the name of the University nor the names of its contributors
19 * may be used to endorse or promote products derived from this software
20 * without specific prior written permission.
22 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
23 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
24 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
25 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
26 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
27 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
28 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
29 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
30 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
31 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 #include <sys/cdefs.h>
38 static char sccsid
[] = "@(#)scanner.c 8.1 (Berkeley) 6/6/93";
40 __RCSID("$NetBSD: scanner.c,v 1.8 2002/06/14 01:06:54 wiz Exp $");
49 #include "window_string.h"
63 if (cx
.x_bol
&& c
!= EOF
) {
72 return *cx
.x_bufp
++ & 0xff;
77 return(0); /* XXX: placate gcc */
88 return ungetc(c
, cx
.x_fp
);
90 if (cx
.x_bufp
> cx
.x_buf
)
91 return *--cx
.x_bufp
= c
;
96 return(0); /* XXX: placate gcc */
127 case 'a': case 'b': case 'c': case 'd': case 'e':
128 case 'f': case 'g': case 'h': case 'i': case 'j':
129 case 'k': case 'l': case 'm': case 'n': case 'o':
130 case 'p': case 'q': case 'r': case 's': case 't':
131 case 'u': case 'v': case 'w': case 'x': case 'y':
133 case 'A': case 'B': case 'C': case 'D': case 'E':
134 case 'F': case 'G': case 'H': case 'I': case 'J':
135 case 'K': case 'L': case 'M': case 'N': case 'O':
136 case 'P': case 'Q': case 'R': case 'S': case 'T':
137 case 'U': case 'V': case 'W': case 'X': case 'Y':
150 switch (c
= s_gettok1()) {
165 case '1': case '2': case '3': case '4':
166 case '5': case '6': case '7': case '8': case '9':
167 cx
.x_val
.v_num
= c
- '0';
200 cx
.x_token
= T_MINUS
;
228 cx
.x_token
= T_COMMA
;
232 cx
.x_token
= T_QUEST
;
236 cx
.x_token
= T_COLON
;
255 if (c
== '\n' || c
== EOF
) {
260 case 2: /* unquoted string */
262 case 'a': case 'b': case 'c': case 'd': case 'e':
263 case 'f': case 'g': case 'h': case 'i': case 'j':
264 case 'k': case 'l': case 'm': case 'n': case 'o':
265 case 'p': case 'q': case 'r': case 's': case 't':
266 case 'u': case 'v': case 'w': case 'x': case 'y':
268 case 'A': case 'B': case 'C': case 'D': case 'E':
269 case 'F': case 'G': case 'H': case 'I': case 'J':
270 case 'K': case 'L': case 'M': case 'N': case 'O':
271 case 'P': case 'Q': case 'R': case 'S': case 'T':
272 case 'U': case 'V': case 'W': case 'X': case 'Y':
275 case '0': case '1': case '2': case '3': case '4':
276 case '5': case '6': case '7': case '8': case '9':
277 if (p
< buf
+ sizeof buf
- 1)
287 switch (c
= s_gettok1()) {
289 (void) s_ungetc(' ');
293 if (p
< buf
+ sizeof buf
- 1)
304 if (buf
[1] == 'f' && buf
[2] == 0)
308 if (buf
[1] == 'h' && buf
[2] == 'e'
309 && buf
[3] == 'n' && buf
[4] == 0)
313 if (buf
[1] == 'n' && buf
[2] == 'd'
314 && buf
[3] == 'i' && buf
[4] == 'f'
316 cx
.x_token
= T_ENDIF
;
318 if (buf
[1] == 'l' && buf
[2] == 's') {
322 cx
.x_token
= T_ELSIF
;
333 if (cx
.x_token
== T_STR
334 && (cx
.x_val
.v_str
= str_cpy(buf
)) == 0) {
342 case 3: /* " quoted string */
351 switch (c
= s_gettok1()) {
353 case -2: /* newlines are invisible */
356 if (p
< buf
+ sizeof buf
- 1)
361 if (p
< buf
+ sizeof buf
- 1)
366 case 4: /* ' quoted string */
375 switch (c
= s_gettok1()) {
377 case -2: /* newlines are invisible */
380 if (p
< buf
+ sizeof buf
- 1)
385 if (p
< buf
+ sizeof buf
- 1)
397 case '0': case '1': case '2': case '3': case '4':
398 case '5': case '6': case '7':
399 cx
.x_val
.v_num
= c
- '0';
403 cx
.x_val
.v_num
= c
- '0';
412 case 11: /* decimal number */
414 case '0': case '1': case '2': case '3': case '4':
415 case '5': case '6': case '7': case '8': case '9':
416 cx
.x_val
.v_num
= cx
.x_val
.v_num
* 10 + c
- '0';
424 case 12: /* hex number */
426 case '0': case '1': case '2': case '3': case '4':
427 case '5': case '6': case '7': case '8': case '9':
428 cx
.x_val
.v_num
= cx
.x_val
.v_num
* 16 + c
- '0';
430 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
431 cx
.x_val
.v_num
= cx
.x_val
.v_num
* 16 + c
- 'a' + 10;
433 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
434 cx
.x_val
.v_num
= cx
.x_val
.v_num
* 16 + c
- 'A' + 10;
442 case 13: /* octal number */
444 case '0': case '1': case '2': case '3': case '4':
445 case '5': case '6': case '7':
446 cx
.x_val
.v_num
= cx
.x_val
.v_num
* 8 + c
- '0';
494 cx
.x_token
= T_ASSIGN
;
513 cx
.x_token
= T_ANDAND
;
542 cx
.x_token
= T_DOLLAR
;
560 c
= s_getc(); /* got \ */
578 case '0': case '1': case '2': case '3': case '4':
579 case '5': case '6': case '7':
583 c
= s_getc(); /* got \[0-7] */
584 if (c
< '0' || c
> '7') {
589 c
= s_getc(); /* got \[0-7][0-7] */
590 if (c
< '0' || c
> '7') {
594 return n
* 8 + c
- '0';