2 * Mach Operating System
3 * Copyright (c) 1991,1990 Carnegie Mellon University
6 * Permission to use, copy, modify and distribute this software and its
7 * documentation is hereby granted, provided that both the copyright
8 * notice and this permission notice appear in all copies of the
9 * software, derivative works or modified versions, and any portions
10 * thereof, and that both notices appear in supporting documentation.
12 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS
13 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
14 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
16 * Carnegie Mellon requests users of this software to return to
18 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
19 * School of Computer Science
20 * Carnegie Mellon University
21 * Pittsburgh PA 15213-3890
23 * any improvements or extensions that they make and grant Carnegie the
24 * rights to redistribute these changes.
26 * $FreeBSD: src/sys/ddb/db_lex.c,v 1.18 1999/08/28 00:41:08 peter Exp $
27 * $DragonFly: src/sys/ddb/db_lex.c,v 1.5 2005/12/23 21:35:44 swildner Exp $
31 * Author: David B. Golub, Carnegie Mellon University
37 #include <sys/param.h>
40 #include <ddb/db_lex.h>
42 static char db_line
[120];
43 static char * db_lp
, *db_endlp
;
45 static int db_lex (void);
46 static void db_flush_line (void);
47 static int db_read_char (void);
48 static void db_unread_char (int);
55 i
= db_readline(db_line
, sizeof(db_line
));
70 static int db_look_char
= 0;
77 if (db_look_char
!= 0) {
81 else if (db_lp
>= db_endlp
)
94 static int db_look_token
= 0;
97 db_unread_token(int t
)
116 db_expr_t db_tok_number
;
117 char db_tok_string
[TOK_STRING_SIZE
];
119 db_expr_t db_radix
= 16;
135 while (c
<= ' ' || c
> '~') {
136 if (c
== '\n' || c
== -1)
141 if (c
>= '0' && c
<= '9') {
149 if (c
== 'O' || c
== 'o')
151 else if (c
== 'T' || c
== 't')
153 else if (c
== 'X' || c
== 'x')
163 if (c
>= '0' && c
<= ((r
== 8) ? '7' : '9'))
165 else if (r
== 16 && ((c
>= 'A' && c
<= 'F') ||
166 (c
>= 'a' && c
<= 'f'))) {
168 digit
= c
- 'a' + 10;
170 digit
= c
- 'A' + 10;
174 db_tok_number
= db_tok_number
* r
+ digit
;
177 if ((c
>= '0' && c
<= '9') ||
178 (c
>= 'A' && c
<= 'Z') ||
179 (c
>= 'a' && c
<= 'z') ||
182 db_error("Bad character in number\n");
189 if ((c
>= 'A' && c
<= 'Z') ||
190 (c
>= 'a' && c
<= 'z') ||
191 c
== '_' || c
== '\\')
199 if (c
== '\n' || c
== -1)
200 db_error("Bad escape\n");
205 if ((c
>= 'A' && c
<= 'Z') ||
206 (c
>= 'a' && c
<= 'z') ||
207 (c
>= '0' && c
<= '9') ||
208 c
== '_' || c
== '\\' || c
== ':')
212 if (c
== '\n' || c
== -1)
213 db_error("Bad escape\n");
216 if (cp
== db_tok_string
+sizeof(db_tok_string
)) {
217 db_error("String too long\n");
280 db_printf("Bad character\n");