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
36 * @(#)scanner.c 8.1 (Berkeley) 6/6/93
37 * $FreeBSD: src/usr.bin/window/scanner.c,v 1.2.14.2 2001/05/17 09:46:29 obrien Exp $
38 * $DragonFly: src/usr.bin/window/scanner.c,v 1.2 2003/06/17 04:29:34 dillon Exp $
55 if (cx
.x_bol
&& c
!= EOF
) {
64 return *cx
.x_bufp
++ & 0xff;
78 return ungetc(c
, cx
.x_fp
);
80 if (cx
.x_bufp
> cx
.x_buf
)
81 return *--cx
.x_bufp
= c
;
91 register char *p
= buf
;
122 switch (c
= s_gettok1()) {
137 case '1': case '2': case '3': case '4':
138 case '5': case '6': case '7': case '8': case '9':
139 cx
.x_val
.v_num
= c
- '0';
172 cx
.x_token
= T_MINUS
;
200 cx
.x_token
= T_COMMA
;
204 cx
.x_token
= T_QUEST
;
208 cx
.x_token
= T_COLON
;
220 if (isalpha(c
) || c
== '_' || c
== '.') {
232 if (c
== '\n' || c
== EOF
) {
237 case 2: /* unquoted string */
246 switch (c
= s_gettok1()) {
248 (void) s_ungetc(' ');
252 if (p
< buf
+ sizeof buf
- 1)
257 if (isalnum(c
) || c
== '_' || c
== '.') {
258 if (p
< buf
+ sizeof buf
- 1)
268 if (buf
[1] == 'f' && buf
[2] == 0)
272 if (buf
[1] == 'h' && buf
[2] == 'e'
273 && buf
[3] == 'n' && buf
[4] == 0)
277 if (buf
[1] == 'n' && buf
[2] == 'd'
278 && buf
[3] == 'i' && buf
[4] == 'f'
280 cx
.x_token
= T_ENDIF
;
281 else if (buf
[1] == 'l' && buf
[2] == 's')
282 if (buf
[3] == 'i' && buf
[4] == 'f'
284 cx
.x_token
= T_ELSIF
;
285 else if (buf
[3] == 'e' && buf
[4] == 0)
289 if (cx
.x_token
== T_STR
290 && (cx
.x_val
.v_str
= str_cpy(buf
)) == 0) {
298 case 3: /* " quoted string */
307 switch (c
= s_gettok1()) {
309 case -2: /* newlines are invisible */
312 if (p
< buf
+ sizeof buf
- 1)
317 if (p
< buf
+ sizeof buf
- 1)
322 case 4: /* ' quoted string */
331 switch (c
= s_gettok1()) {
333 case -2: /* newlines are invisible */
336 if (p
< buf
+ sizeof buf
- 1)
341 if (p
< buf
+ sizeof buf
- 1)
353 case '0': case '1': case '2': case '3': case '4':
354 case '5': case '6': case '7':
355 cx
.x_val
.v_num
= c
- '0';
359 cx
.x_val
.v_num
= c
- '0';
368 case 11: /* decimal number */
370 case '0': case '1': case '2': case '3': case '4':
371 case '5': case '6': case '7': case '8': case '9':
372 cx
.x_val
.v_num
= cx
.x_val
.v_num
* 10 + c
- '0';
380 case 12: /* hex number */
382 case '0': case '1': case '2': case '3': case '4':
383 case '5': case '6': case '7': case '8': case '9':
384 cx
.x_val
.v_num
= cx
.x_val
.v_num
* 16 + c
- '0';
386 case 'a': case 'b': case 'c': case 'd': case 'e': case 'f':
387 cx
.x_val
.v_num
= cx
.x_val
.v_num
* 16 + c
- 'a' + 10;
389 case 'A': case 'B': case 'C': case 'D': case 'E': case 'F':
390 cx
.x_val
.v_num
= cx
.x_val
.v_num
* 16 + c
- 'A' + 10;
398 case 13: /* octal number */
400 case '0': case '1': case '2': case '3': case '4':
401 case '5': case '6': case '7':
402 cx
.x_val
.v_num
= cx
.x_val
.v_num
* 8 + c
- '0';
450 cx
.x_token
= T_ASSIGN
;
469 cx
.x_token
= T_ANDAND
;
498 cx
.x_token
= T_DOLLAR
;
515 c
= s_getc(); /* got \ */
533 case '0': case '1': case '2': case '3': case '4':
534 case '5': case '6': case '7':
538 c
= s_getc(); /* got \[0-7] */
539 if (c
< '0' || c
> '7') {
544 c
= s_getc(); /* got \[0-7][0-7] */
545 if (c
< '0' || c
> '7') {
549 return n
* 8 + c
- '0';