]>
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 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
31 * Revision 1.1.1.1 1998/09/22 21:05:48 wsanchez
32 * Import of Mac OS X kernel (~semeria)
34 * Revision 1.1.1.1 1998/03/07 02:26:09 wsanchez
35 * Import of OSF Mach kernel (~mburg)
37 * Revision 1.1.11.3 1996/01/09 19:15:49 devrcs
38 * Change 'register foo' to 'register int foo'.
39 * [1995/12/01 21:42:12 jfraser]
41 * Merged '64-bit safe' changes from DEC alpha port.
42 * [1995/11/21 18:03:11 jfraser]
44 * Revision 1.1.11.2 1995/01/06 19:10:21 devrcs
45 * mk6 CR668 - 1.3b26 merge
46 * * Revision 1.1.4.6 1994/05/06 18:39:20 tmt
47 * Merged osc1.3dec/shared with osc1.3b19
48 * Merge Alpha changes into osc1.312b source code.
51 * Cleanup to quiet gcc warnings.
53 * [1994/11/04 08:49:35 dwm]
55 * Revision 1.1.11.1 1994/09/23 01:19:59 ezf
56 * change marker to not FREE
57 * [1994/09/22 21:10:14 ezf]
59 * Revision 1.1.4.4 1993/08/11 20:37:55 elliston
60 * Add ANSI Prototypes. CR #9523.
61 * [1993/08/11 03:33:26 elliston]
63 * Revision 1.1.4.3 1993/07/27 18:27:38 elliston
64 * Add ANSI prototypes. CR #9523.
65 * [1993/07/27 18:12:13 elliston]
67 * Revision 1.1.4.2 1993/06/02 23:11:27 jeffc
68 * Added to OSF/1 R1.3 from NMK15.0.
69 * [1993/06/02 20:56:32 jeffc]
71 * Revision 1.1 1992/09/30 02:01:10 robert
78 * Revision 2.5 91/10/09 16:00:20 af
79 * Revision 2.4.3.1 91/10/05 13:06:25 jeffreyh
80 * Added relational operator tokens and string constant etc.
81 * Added input switching functions for macro and conditional command.
82 * Moved skip_to_eol() from db_command.c and added db_last_lp to print
83 * skipped input data as a warning message.
84 * Added last input repetition support to db_read_line.
85 * Changed db_lex() to always set db_tok_string for error message.
88 * Revision 2.4.3.1 91/10/05 13:06:25 jeffreyh
89 * Added relational operator tokens and string constant etc.
90 * Added input switching functions for macro and conditional command.
91 * Moved skip_to_eol() from db_command.c and added db_last_lp to print
92 * skipped input data as a warning message.
93 * Added last input repetition support to db_read_line.
94 * Changed db_lex() to always set db_tok_string for error message.
97 * Revision 2.4 91/05/14 15:34:23 mrt
98 * Correcting copyright
100 * Revision 2.3 91/02/05 17:06:36 mrt
101 * Changed to new Mach copyright
102 * [91/01/31 16:18:20 mrt]
104 * Revision 2.2 90/08/27 21:51:10 dbg
105 * Add 'dotdot' token.
108 * Allow backslash to quote any character into an identifier.
109 * Allow colon in identifier for symbol table qualification.
119 * Mach Operating System
120 * Copyright (c) 1991,1990 Carnegie Mellon University
121 * All Rights Reserved.
123 * Permission to use, copy, modify and distribute this software and its
124 * documentation is hereby granted, provided that both the copyright
125 * notice and this permission notice appear in all copies of the
126 * software, derivative works or modified versions, and any portions
127 * thereof, and that both notices appear in supporting documentation.
129 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
130 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
131 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
133 * Carnegie Mellon requests users of this software to return to
135 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
136 * School of Computer Science
137 * Carnegie Mellon University
138 * Pittsburgh PA 15213-3890
140 * any improvements or extensions that they make and grant Carnegie Mellon
141 * the rights to redistribute these changes.
146 * Author: David B. Golub, Carnegie Mellon University
152 #include <string.h> /* For strcpy(), strncmp(), strlen() */
153 #include <ddb/db_lex.h>
154 #include <ddb/db_command.h>
155 #include <ddb/db_input.h>
156 #include <ddb/db_output.h> /* For db_printf() */
158 char db_line
[DB_LEX_LINE_SIZE
];
159 char db_last_line
[DB_LEX_LINE_SIZE
];
160 char *db_lp
, *db_endlp
;
162 int db_look_char
= 0;
163 db_expr_t db_look_token
= 0;
166 /* Prototypes for functions local to this file. XXX -- should be static!
168 void db_flush_line(void);
169 void db_unread_char(int c
);
173 db_read_line(char *repeat_last
)
177 i
= db_readline(db_line
, sizeof(db_line
));
179 return (0); /* EOI */
181 if (strncmp(db_line
, repeat_last
, strlen(repeat_last
)) == 0) {
182 strcpy(db_line
, db_last_line
);
183 db_printf("%s", db_line
);
185 } else if (db_line
[0] != '\n' && db_line
[0] != 0)
186 strcpy(db_last_line
, db_line
);
189 db_endlp
= db_lp
+ i
;
211 db_endlp
= buffer
+ size
;
217 db_save_lex_context(register struct db_lex_context
*lp
)
220 lp
->l_eptr
= db_endlp
;
221 lp
->l_char
= db_look_char
;
222 lp
->l_token
= db_look_token
;
226 db_restore_lex_context(register struct db_lex_context
*lp
)
230 db_endlp
= lp
->l_eptr
;
231 db_look_char
= lp
->l_char
;
232 db_look_token
= lp
->l_token
;
240 if (db_look_char
!= 0) {
244 else if (db_lp
>= db_endlp
)
252 db_unread_char(int c
)
258 db_unread_token(int t
)
281 db_expr_t db_tok_number
;
282 char db_tok_string
[TOK_STRING_SIZE
];
284 db_expr_t db_radix
= 16;
294 #define DB_DISP_SKIP 40 /* number of chars to display skip */
306 for (skip
= 0; t
!= tEOL
&& t
!= tSEMI_COLON
&& t
!= tEOF
; skip
++)
308 if (t
== tSEMI_COLON
)
311 while (p
< db_last_lp
&& (*p
== ' ' || *p
== '\t'))
313 db_printf("Warning: Skipped input data \"");
314 for (n
= 0; n
< DB_DISP_SKIP
&& p
< db_last_lp
; n
++)
315 db_printf("%c", *p
++);
316 if (n
>= DB_DISP_SKIP
)
329 while (c
<= ' ' || c
> '~') {
330 if (c
== '\n' || c
== -1)
338 if (c
>= '0' && c
<= '9') {
346 if (c
== 'O' || c
== 'o')
348 else if (c
== 'T' || c
== 't')
350 else if (c
== 'X' || c
== 'x')
362 if (c
>= '0' && c
<= ((r
== 8) ? '7' : '9'))
364 else if (r
== 16 && ((c
>= 'A' && c
<= 'F') ||
365 (c
>= 'a' && c
<= 'f'))) {
367 digit
= c
- 'a' + 10;
369 digit
= c
- 'A' + 10;
373 db_tok_number
= db_tok_number
* r
+ digit
;
375 if (cp
< &db_tok_string
[sizeof(db_tok_string
)-1])
379 if ((c
>= '0' && c
<= '9') ||
380 (c
>= 'A' && c
<= 'Z') ||
381 (c
>= 'a' && c
<= 'z') ||
384 db_printf("Bad character '%c' after number %s\n",
393 if ((c
>= 'A' && c
<= 'Z') ||
394 (c
>= 'a' && c
<= 'z') ||
395 c
== '_' || c
== '\\' || c
== ':')
400 if (c
== '\n' || c
== -1)
401 db_error("Bad '\\' at the end of line\n");
406 if ((c
>= 'A' && c
<= 'Z') ||
407 (c
>= 'a' && c
<= 'z') ||
408 (c
>= '0' && c
<= '9') ||
409 c
== '_' || c
== '\\' || c
== ':' || c
== '.')
413 if (c
== '\n' || c
== -1)
414 db_error("Bad '\\' at the end of line\n");
417 if (cp
== db_tok_string
+sizeof(db_tok_string
)) {
418 db_error("String too long\n");
477 while (c
!= '"' && c
> 0 && c
!= '\n') {
478 if (cp
>= &db_tok_string
[sizeof(db_tok_string
)-1]) {
479 db_error("Too long string\n");
494 db_printf("Bad escape sequence '\\%c'\n", c
);
505 db_error("Non terminated string constant\n");
558 return (tGREATER_EQ
);
564 return (tSEMI_COLON
);
568 strcpy(db_tok_string
, "<EOL>");
571 db_printf("Bad character '%c'\n", c
);