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.
27 * Author: David B. Golub, Carnegie Mellon University
34 #include <sys/cdefs.h>
35 __FBSDID("$FreeBSD$");
37 #include <sys/param.h>
38 #include <sys/libkern.h>
41 #include <ddb/db_lex.h>
43 static char db_line
[DB_MAXLINE
];
44 static char * db_lp
, *db_endlp
;
46 static int db_lex(void);
47 static void db_flush_line(void);
48 static int db_read_char(void);
49 static void db_unread_char(int);
56 i
= db_readline(db_line
, sizeof(db_line
));
65 * Simulate a line of input into DDB.
68 db_inject_line(const char *command
)
71 strlcpy(db_line
, command
, sizeof(db_line
));
73 db_endlp
= db_lp
+ strlen(command
);
77 * In rare cases, we may want to pull the remainder of the line input
78 * verbatim, rather than lexing it. For example, when assigning literal
79 * values associated with scripts. In that case, return a static pointer to
80 * the current location in the input buffer. The caller must be aware that
81 * the contents are not stable if other lex/input calls are made.
97 static int db_look_char
= 0;
104 if (db_look_char
!= 0) {
108 else if (db_lp
>= db_endlp
)
122 static int db_look_token
= 0;
145 db_expr_t db_tok_number
;
146 char db_tok_string
[TOK_STRING_SIZE
];
148 db_expr_t db_radix
= 16;
164 while (c
<= ' ' || c
> '~') {
165 if (c
== '\n' || c
== -1)
170 if (c
>= '0' && c
<= '9') {
178 if (c
== 'O' || c
== 'o')
180 else if (c
== 'T' || c
== 't')
182 else if (c
== 'X' || c
== 'x')
192 if (c
>= '0' && c
<= ((r
== 8) ? '7' : '9'))
194 else if (r
== 16 && ((c
>= 'A' && c
<= 'F') ||
195 (c
>= 'a' && c
<= 'f'))) {
197 digit
= c
- 'a' + 10;
199 digit
= c
- 'A' + 10;
203 db_tok_number
= db_tok_number
* r
+ digit
;
206 if ((c
>= '0' && c
<= '9') ||
207 (c
>= 'A' && c
<= 'Z') ||
208 (c
>= 'a' && c
<= 'z') ||
211 db_error("Bad character in number\n");
218 if ((c
>= 'A' && c
<= 'Z') ||
219 (c
>= 'a' && c
<= 'z') ||
220 c
== '_' || c
== '\\')
228 if (c
== '\n' || c
== -1)
229 db_error("Bad escape\n");
234 if ((c
>= 'A' && c
<= 'Z') ||
235 (c
>= 'a' && c
<= 'z') ||
236 (c
>= '0' && c
<= '9') ||
237 c
== '_' || c
== '\\' || c
== ':' || c
== '.')
241 if (c
== '\n' || c
== -1)
242 db_error("Bad escape\n");
245 if (cp
== db_tok_string
+sizeof(db_tok_string
)) {
246 db_error("String too long\n");
299 return (tLOG_NOT_EQ
);
330 return (tGREATER_EQ
);
340 db_printf("Bad character\n");