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 $
30 * Author: David B. Golub, Carnegie Mellon University
36 #include <sys/param.h>
37 #include <sys/systm.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;
122 * Convert the number to a string in the current radix.
123 * This replaces the non-standard %n printf() format.
127 db_num_to_str(db_expr_t val)
131 * 2 chars for "0x", 1 for a sign ("-")
132 * up to 21 chars for a 64-bit number:
133 * % echo 2^64 | bc | wc -c
135 * and 1 char for a terminal NUL
141 ksnprintf(buf, sizeof(buf), "%" DDB_EXPR_FMT "x", val);
142 else if (db_radix == 8)
143 ksnprintf(buf, sizeof(buf), "%" DDB_EXPR_FMT "o", val);
145 ksnprintf(buf, sizeof(buf), "%" DDB_EXPR_FMT "u", val);
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 == ':')
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");
309 db_printf("Bad character\n");