]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/ddb/db_lex.c
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
28 * Revision 1.1.1.1 1998/09/22 21:05:48 wsanchez
29 * Import of Mac OS X kernel (~semeria)
31 * Revision 1.1.1.1 1998/03/07 02:26:09 wsanchez
32 * Import of OSF Mach kernel (~mburg)
34 * Revision 1.1.11.3 1996/01/09 19:15:49 devrcs
35 * Change 'register foo' to 'register int foo'.
36 * [1995/12/01 21:42:12 jfraser]
38 * Merged '64-bit safe' changes from DEC alpha port.
39 * [1995/11/21 18:03:11 jfraser]
41 * Revision 1.1.11.2 1995/01/06 19:10:21 devrcs
42 * mk6 CR668 - 1.3b26 merge
43 * * Revision 1.1.4.6 1994/05/06 18:39:20 tmt
44 * Merged osc1.3dec/shared with osc1.3b19
45 * Merge Alpha changes into osc1.312b source code.
48 * Cleanup to quiet gcc warnings.
50 * [1994/11/04 08:49:35 dwm]
52 * Revision 1.1.11.1 1994/09/23 01:19:59 ezf
53 * change marker to not FREE
54 * [1994/09/22 21:10:14 ezf]
56 * Revision 1.1.4.4 1993/08/11 20:37:55 elliston
57 * Add ANSI Prototypes. CR #9523.
58 * [1993/08/11 03:33:26 elliston]
60 * Revision 1.1.4.3 1993/07/27 18:27:38 elliston
61 * Add ANSI prototypes. CR #9523.
62 * [1993/07/27 18:12:13 elliston]
64 * Revision 1.1.4.2 1993/06/02 23:11:27 jeffc
65 * Added to OSF/1 R1.3 from NMK15.0.
66 * [1993/06/02 20:56:32 jeffc]
68 * Revision 1.1 1992/09/30 02:01:10 robert
75 * Revision 2.5 91/10/09 16:00:20 af
76 * Revision 2.4.3.1 91/10/05 13:06:25 jeffreyh
77 * Added relational operator tokens and string constant etc.
78 * Added input switching functions for macro and conditional command.
79 * Moved skip_to_eol() from db_command.c and added db_last_lp to print
80 * skipped input data as a warning message.
81 * Added last input repetition support to db_read_line.
82 * Changed db_lex() to always set db_tok_string for error message.
85 * Revision 2.4.3.1 91/10/05 13:06:25 jeffreyh
86 * Added relational operator tokens and string constant etc.
87 * Added input switching functions for macro and conditional command.
88 * Moved skip_to_eol() from db_command.c and added db_last_lp to print
89 * skipped input data as a warning message.
90 * Added last input repetition support to db_read_line.
91 * Changed db_lex() to always set db_tok_string for error message.
94 * Revision 2.4 91/05/14 15:34:23 mrt
95 * Correcting copyright
97 * Revision 2.3 91/02/05 17:06:36 mrt
98 * Changed to new Mach copyright
99 * [91/01/31 16:18:20 mrt]
101 * Revision 2.2 90/08/27 21:51:10 dbg
102 * Add 'dotdot' token.
105 * Allow backslash to quote any character into an identifier.
106 * Allow colon in identifier for symbol table qualification.
116 * Mach Operating System
117 * Copyright (c) 1991,1990 Carnegie Mellon University
118 * All Rights Reserved.
120 * Permission to use, copy, modify and distribute this software and its
121 * documentation is hereby granted, provided that both the copyright
122 * notice and this permission notice appear in all copies of the
123 * software, derivative works or modified versions, and any portions
124 * thereof, and that both notices appear in supporting documentation.
126 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
127 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
128 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
130 * Carnegie Mellon requests users of this software to return to
132 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
133 * School of Computer Science
134 * Carnegie Mellon University
135 * Pittsburgh PA 15213-3890
137 * any improvements or extensions that they make and grant Carnegie Mellon
138 * the rights to redistribute these changes.
143 * Author: David B. Golub, Carnegie Mellon University
149 #include <string.h> /* For strcpy(), strncmp(), strlen() */
150 #include <ddb/db_lex.h>
151 #include <ddb/db_command.h>
152 #include <ddb/db_input.h>
153 #include <ddb/db_output.h> /* For db_printf() */
155 char db_line
[DB_LEX_LINE_SIZE
];
156 char db_last_line
[DB_LEX_LINE_SIZE
];
157 char *db_lp
, *db_endlp
;
159 int db_look_char
= 0;
160 db_expr_t db_look_token
= 0;
163 /* Prototypes for functions local to this file. XXX -- should be static!
165 void db_flush_line(void);
166 void db_unread_char(int c
);
170 db_read_line(char *repeat_last
)
174 i
= db_readline(db_line
, sizeof(db_line
));
176 return (0); /* EOI */
178 if (strncmp(db_line
, repeat_last
, strlen(repeat_last
)) == 0) {
179 strcpy(db_line
, db_last_line
);
180 db_printf("%s", db_line
);
182 } else if (db_line
[0] != '\n' && db_line
[0] != 0)
183 strcpy(db_last_line
, db_line
);
186 db_endlp
= db_lp
+ i
;
208 db_endlp
= buffer
+ size
;
214 db_save_lex_context(register struct db_lex_context
*lp
)
217 lp
->l_eptr
= db_endlp
;
218 lp
->l_char
= db_look_char
;
219 lp
->l_token
= db_look_token
;
223 db_restore_lex_context(register struct db_lex_context
*lp
)
227 db_endlp
= lp
->l_eptr
;
228 db_look_char
= lp
->l_char
;
229 db_look_token
= lp
->l_token
;
237 if (db_look_char
!= 0) {
241 else if (db_lp
>= db_endlp
)
249 db_unread_char(int c
)
255 db_unread_token(int t
)
278 db_expr_t db_tok_number
;
279 char db_tok_string
[TOK_STRING_SIZE
];
281 db_expr_t db_radix
= 16;
291 #define DB_DISP_SKIP 40 /* number of chars to display skip */
303 for (skip
= 0; t
!= tEOL
&& t
!= tSEMI_COLON
&& t
!= tEOF
; skip
++)
305 if (t
== tSEMI_COLON
)
308 while (p
< db_last_lp
&& (*p
== ' ' || *p
== '\t'))
310 db_printf("Warning: Skipped input data \"");
311 for (n
= 0; n
< DB_DISP_SKIP
&& p
< db_last_lp
; n
++)
312 db_printf("%c", *p
++);
313 if (n
>= DB_DISP_SKIP
)
326 while (c
<= ' ' || c
> '~') {
327 if (c
== '\n' || c
== -1)
335 if (c
>= '0' && c
<= '9') {
343 if (c
== 'O' || c
== 'o')
345 else if (c
== 'T' || c
== 't')
347 else if (c
== 'X' || c
== 'x')
359 if (c
>= '0' && c
<= ((r
== 8) ? '7' : '9'))
361 else if (r
== 16 && ((c
>= 'A' && c
<= 'F') ||
362 (c
>= 'a' && c
<= 'f'))) {
364 digit
= c
- 'a' + 10;
366 digit
= c
- 'A' + 10;
370 db_tok_number
= db_tok_number
* r
+ digit
;
372 if (cp
< &db_tok_string
[sizeof(db_tok_string
)-1])
376 if ((c
>= '0' && c
<= '9') ||
377 (c
>= 'A' && c
<= 'Z') ||
378 (c
>= 'a' && c
<= 'z') ||
381 db_printf("Bad character '%c' after number %s\n",
390 if ((c
>= 'A' && c
<= 'Z') ||
391 (c
>= 'a' && c
<= 'z') ||
392 c
== '_' || c
== '\\' || c
== ':')
397 if (c
== '\n' || c
== -1)
398 db_error("Bad '\\' at the end of line\n");
403 if ((c
>= 'A' && c
<= 'Z') ||
404 (c
>= 'a' && c
<= 'z') ||
405 (c
>= '0' && c
<= '9') ||
406 c
== '_' || c
== '\\' || c
== ':' || c
== '.')
410 if (c
== '\n' || c
== -1)
411 db_error("Bad '\\' at the end of line\n");
414 if (cp
== db_tok_string
+sizeof(db_tok_string
)) {
415 db_error("String too long\n");
474 while (c
!= '"' && c
> 0 && c
!= '\n') {
475 if (cp
>= &db_tok_string
[sizeof(db_tok_string
)-1]) {
476 db_error("Too long string\n");
491 db_printf("Bad escape sequence '\\%c'\n", c
);
502 db_error("Non terminated string constant\n");
555 return (tGREATER_EQ
);
561 return (tSEMI_COLON
);
565 strcpy(db_tok_string
, "<EOL>");
568 db_printf("Bad character '%c'\n", c
);