2 * SPDX-License-Identifier: MIT-CMU
4 * Mach Operating System
5 * Copyright (c) 1991,1990 Carnegie Mellon University
8 * Permission to use, copy, modify and distribute this software and its
9 * documentation is hereby granted, provided that both the copyright
10 * notice and this permission notice appear in all copies of the
11 * software, derivative works or modified versions, and any portions
12 * thereof, and that both notices appear in supporting documentation.
14 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS
15 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
16 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
18 * Carnegie Mellon requests users of this software to return to
20 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
21 * School of Computer Science
22 * Carnegie Mellon University
23 * Pittsburgh PA 15213-3890
25 * any improvements or extensions that they make and grant Carnegie the
26 * rights to redistribute these changes.
29 * Author: David B. Golub, Carnegie Mellon University
36 #include <sys/cdefs.h>
37 __FBSDID("$FreeBSD$");
39 #include <sys/param.h>
40 #include <sys/libkern.h>
44 #include <ddb/db_lex.h>
46 static char db_line[DB_MAXLINE];
47 static char * db_lp, *db_endlp;
49 static int db_lex(int);
50 static void db_flush_line(void);
51 static int db_read_char(void);
52 static void db_unread_char(int);
59 i = db_readline(db_line, sizeof(db_line));
68 * Simulate a line of input into DDB.
71 db_inject_line(const char *command)
74 strlcpy(db_line, command, sizeof(db_line));
76 db_endlp = db_lp + strlen(command);
80 * In rare cases, we may want to pull the remainder of the line input
81 * verbatim, rather than lexing it. For example, when assigning literal
82 * values associated with scripts. In that case, return a static pointer to
83 * the current location in the input buffer. The caller must be aware that
84 * the contents are not stable if other lex/input calls are made.
100 static int db_look_char = 0;
107 if (db_look_char != 0) {
111 else if (db_lp >= db_endlp)
125 static int db_look_token = 0;
128 db_unread_token(int t)
134 db_read_token_flags(int flags)
138 MPASS((flags & ~(DRT_VALID_FLAGS_MASK)) == 0);
149 db_expr_t db_tok_number;
150 char db_tok_string[TOK_STRING_SIZE];
152 db_expr_t db_radix = 16;
165 int c, n, radix_mode;
166 bool lex_wspace, lex_hex_numbers;
168 switch (flags & DRT_RADIX_MASK) {
169 case DRT_DEFAULT_RADIX:
178 case DRT_HEXADECIMAL:
183 lex_wspace = ((flags & DRT_WSPACE) != 0);
184 lex_hex_numbers = ((flags & DRT_HEX) != 0);
187 for (n = 0; c <= ' ' || c > '~'; n++) {
188 if (c == '\n' || c == -1)
192 if (lex_wspace && n != 0) {
197 if ((c >= '0' && c <= '9') ||
199 ((c >= 'a' && c <= 'f') ||
200 (c >= 'A' && c <= 'F')))) {
204 if (radix_mode != -1)
210 if (c == 'O' || c == 'o')
212 else if (c == 'T' || c == 't')
214 else if (c == 'X' || c == 'x')
224 if (c >= '0' && c <= ((r == 8) ? '7' : '9'))
226 else if (r == 16 && ((c >= 'A' && c <= 'F') ||
227 (c >= 'a' && c <= 'f'))) {
229 digit = c - 'a' + 10;
231 digit = c - 'A' + 10;
235 db_tok_number = db_tok_number * r + digit;
238 if ((c >= '0' && c <= '9') ||
239 (c >= 'A' && c <= 'Z') ||
240 (c >= 'a' && c <= 'z') ||
243 db_error("Bad character in number\n");
250 if ((c >= 'A' && c <= 'Z') ||
251 (c >= 'a' && c <= 'z') ||
252 c == '_' || c == '\\')
260 if (c == '\n' || c == -1)
261 db_error("Bad escape\n");
266 if ((c >= 'A' && c <= 'Z') ||
267 (c >= 'a' && c <= 'z') ||
268 (c >= '0' && c <= '9') ||
269 c == '_' || c == '\\' || c == ':' || c == '.')
273 if (c == '\n' || c == -1)
274 db_error("Bad escape\n");
277 if (cp == db_tok_string+sizeof(db_tok_string)) {
278 db_error("String too long\n");
331 return (tLOG_NOT_EQ);
338 return (tCOLONCOLON);
368 return (tGREATER_EQ);
378 db_printf("Bad character\n");