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)
296 if (buf
[1] == 'f' && buf
[2] == 0)
300 if (buf
[1] == 'h' && buf
[2] == 'e'
301 && buf
[3] == 'n' && buf
[4] == 0)
305 if (buf
[1] == 'n' && buf
[2] == 'd'
306 && buf
[3] == 'i' && buf
[4] == 'f'
308 cx
.x_token
= T_ENDIF
;
310 if (buf
[1] == 'l' && buf
[2] == 's') {
314 cx
.x_token
= T_ELSIF
;
325 if (cx
.x_token
== T_STR
326 && (cx
.x_val
.v_str
= str_cpy(buf
)) == 0) {
334 case 3: /* " quoted string */
343 switch (c
= s_gettok1()) {
345 case -2: /* newlines are invisible */
348 if (p
< buf
+ sizeof buf
- 1)
353 if (p
< buf
+ sizeof buf
- 1)
358 case 4: /* ' quoted string */
367 switch (c
= s_gettok1()) {
369 case -2: /* newlines are invisible */
372 if (p
< buf
+ sizeof buf
- 1)
377 if (p
< buf
+ sizeof buf
- 1)
389 case '0': case '1': case '2': case '3': case '4':
390 case '5': case '6': case '7':
391 cx
.x_val
.v_num
= c
- '0';
395 cx
.x_val
.v_num
= c
- '0';
404 case 11: /* decimal number */
406 case '0': case '1': case '2': case '3': case '4':
407 case '5': case '6': case '7': case '8': case '9':
408 cx
.x_val
.v_num
= cx
.x_val
.v_num
* 10 + c
- '0';
416 case 12: /* hex number */
418 case '0': case '1': case '2': case '3': case '4':
419 case '5': case '6': case '7': case '8': case '9':
420 cx
.x_val
.v_num
= cx
.x_val
.v_num
* 16 + c
- '0';
422 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
423 cx
.x_val
.v_num
= cx
.x_val
.v_num
* 16 + c
- 'a' + 10;
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;
434 case 13: /* octal number */
436 case '0': case '1': case '2': case '3': case '4':
437 case '5': case '6': case '7':
438 cx
.x_val
.v_num
= cx
.x_val
.v_num
* 8 + c
- '0';
486 cx
.x_token
= T_ASSIGN
;
505 cx
.x_token
= T_ANDAND
;
534 cx
.x_token
= T_DOLLAR
;
552 c
= s_getc(); /* got \ */
570 case '0': case '1': case '2': case '3': case '4':
571 case '5': case '6': case '7':
575 c
= s_getc(); /* got \[0-7] */
576 if (c
< '0' || c
> '7') {
581 c
= s_getc(); /* got \[0-7][0-7] */
582 if (c
< '0' || c
> '7') {
586 return n
* 8 + c
- '0';