]>
git.saurik.com Git - apple/shell_cmds.git/blob - window/scanner.c
ea0ae55ccc99fc6a98a2ad44ed9132dda31d1a96
1 /* $NetBSD: scanner.c,v 1.5 1998/08/25 20:59:43 ross 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. All advertising materials mentioning features or use of this software
19 * must display the following acknowledgement:
20 * This product includes software developed by the University of
21 * California, Berkeley and its contributors.
22 * 4. Neither the name of the University nor the names of its contributors
23 * may be used to endorse or promote products derived from this software
24 * without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
27 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
28 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
29 * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
30 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
31 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
32 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
33 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
34 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
35 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
39 #include <sys/cdefs.h>
42 static char sccsid
[] = "@(#)scanner.c 8.1 (Berkeley) 6/6/93";
44 __RCSID("$NetBSD: scanner.c,v 1.5 1998/08/25 20:59:43 ross Exp $");
51 #include "window_string.h"
53 int s_getc
__P((void));
54 int s_gettok1
__P((void));
55 int s_ungetc
__P((int));
65 if (cx
.x_bol
&& c
!= EOF
) {
74 return *cx
.x_bufp
++ & 0xff;
79 return(0); /* XXX: placate gcc */
91 return ungetc(c
, cx
.x_fp
);
93 if (cx
.x_bufp
> cx
.x_buf
)
94 return *--cx
.x_bufp
= c
;
99 return(0); /* XXX: placate gcc */
130 case 'a': case 'b': case 'c': case 'd': case 'e':
131 case 'f': case 'g': case 'h': case 'i': case 'j':
132 case 'k': case 'l': case 'm': case 'n': case 'o':
133 case 'p': case 'q': case 'r': case 's': case 't':
134 case 'u': case 'v': case 'w': case 'x': case 'y':
136 case 'A': case 'B': case 'C': case 'D': case 'E':
137 case 'F': case 'G': case 'H': case 'I': case 'J':
138 case 'K': case 'L': case 'M': case 'N': case 'O':
139 case 'P': case 'Q': case 'R': case 'S': case 'T':
140 case 'U': case 'V': case 'W': case 'X': case 'Y':
153 switch (c
= s_gettok1()) {
168 case '1': case '2': case '3': case '4':
169 case '5': case '6': case '7': case '8': case '9':
170 cx
.x_val
.v_num
= c
- '0';
203 cx
.x_token
= T_MINUS
;
231 cx
.x_token
= T_COMMA
;
235 cx
.x_token
= T_QUEST
;
239 cx
.x_token
= T_COLON
;
258 if (c
== '\n' || c
== EOF
) {
263 case 2: /* unquoted string */
265 case 'a': case 'b': case 'c': case 'd': case 'e':
266 case 'f': case 'g': case 'h': case 'i': case 'j':
267 case 'k': case 'l': case 'm': case 'n': case 'o':
268 case 'p': case 'q': case 'r': case 's': case 't':
269 case 'u': case 'v': case 'w': case 'x': case 'y':
271 case 'A': case 'B': case 'C': case 'D': case 'E':
272 case 'F': case 'G': case 'H': case 'I': case 'J':
273 case 'K': case 'L': case 'M': case 'N': case 'O':
274 case 'P': case 'Q': case 'R': case 'S': case 'T':
275 case 'U': case 'V': case 'W': case 'X': case 'Y':
278 case '0': case '1': case '2': case '3': case '4':
279 case '5': case '6': case '7': case '8': case '9':
280 if (p
< buf
+ sizeof buf
- 1)
290 switch (c
= s_gettok1()) {
292 (void) s_ungetc(' ');
296 if (p
< buf
+ sizeof buf
- 1)
307 if (buf
[1] == 'f' && buf
[2] == 0)
311 if (buf
[1] == 'h' && buf
[2] == 'e'
312 && buf
[3] == 'n' && buf
[4] == 0)
316 if (buf
[1] == 'n' && buf
[2] == 'd'
317 && buf
[3] == 'i' && buf
[4] == 'f'
319 cx
.x_token
= T_ENDIF
;
321 if (buf
[1] == 'l' && buf
[2] == 's') {
325 cx
.x_token
= T_ELSIF
;
336 if (cx
.x_token
== T_STR
337 && (cx
.x_val
.v_str
= str_cpy(buf
)) == 0) {
345 case 3: /* " quoted string */
354 switch (c
= s_gettok1()) {
356 case -2: /* newlines are invisible */
359 if (p
< buf
+ sizeof buf
- 1)
364 if (p
< buf
+ sizeof buf
- 1)
369 case 4: /* ' quoted string */
378 switch (c
= s_gettok1()) {
380 case -2: /* newlines are invisible */
383 if (p
< buf
+ sizeof buf
- 1)
388 if (p
< buf
+ sizeof buf
- 1)
400 case '0': case '1': case '2': case '3': case '4':
401 case '5': case '6': case '7':
402 cx
.x_val
.v_num
= c
- '0';
406 cx
.x_val
.v_num
= c
- '0';
415 case 11: /* decimal number */
417 case '0': case '1': case '2': case '3': case '4':
418 case '5': case '6': case '7': case '8': case '9':
419 cx
.x_val
.v_num
= cx
.x_val
.v_num
* 10 + c
- '0';
427 case 12: /* hex number */
429 case '0': case '1': case '2': case '3': case '4':
430 case '5': case '6': case '7': case '8': case '9':
431 cx
.x_val
.v_num
= cx
.x_val
.v_num
* 16 + c
- '0';
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;
436 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
437 cx
.x_val
.v_num
= cx
.x_val
.v_num
* 16 + c
- 'A' + 10;
445 case 13: /* octal number */
447 case '0': case '1': case '2': case '3': case '4':
448 case '5': case '6': case '7':
449 cx
.x_val
.v_num
= cx
.x_val
.v_num
* 8 + c
- '0';
497 cx
.x_token
= T_ASSIGN
;
516 cx
.x_token
= T_ANDAND
;
545 cx
.x_token
= T_DOLLAR
;
563 c
= s_getc(); /* got \ */
581 case '0': case '1': case '2': case '3': case '4':
582 case '5': case '6': case '7':
586 c
= s_getc(); /* got \[0-7] */
587 if (c
< '0' || c
> '7') {
592 c
= s_getc(); /* got \[0-7][0-7] */
593 if (c
< '0' || c
> '7') {
597 return n
* 8 + c
- '0';