]>
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_OSREFERENCE_LICENSE_HEADER_START@
6 * This file contains Original Code and/or Modifications of Original Code
7 * as defined in and that are subject to the Apple Public Source License
8 * Version 2.0 (the 'License'). You may not use this file except in
9 * compliance with the License. The rights granted to you under the License
10 * may not be used to create, or enable the creation or redistribution of,
11 * unlawful or unlicensed copies of an Apple operating system, or to
12 * circumvent, violate, or enable the circumvention or violation of, any
13 * terms of an Apple operating system software license agreement.
15 * Please obtain a copy of the License at
16 * http://www.opensource.apple.com/apsl/ and read it before using this file.
18 * The Original Code and all software distributed under the License are
19 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
20 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
21 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
22 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
23 * Please see the License for the specific language governing rights and
24 * limitations under the License.
26 * @APPLE_OSREFERENCE_LICENSE_HEADER_END@
34 * Revision 1.1.1.1 1998/09/22 21:05:48 wsanchez
35 * Import of Mac OS X kernel (~semeria)
37 * Revision 1.1.1.1 1998/03/07 02:26:09 wsanchez
38 * Import of OSF Mach kernel (~mburg)
40 * Revision 1.1.11.3 1996/01/09 19:15:49 devrcs
41 * Change 'register foo' to 'register int foo'.
42 * [1995/12/01 21:42:12 jfraser]
44 * Merged '64-bit safe' changes from DEC alpha port.
45 * [1995/11/21 18:03:11 jfraser]
47 * Revision 1.1.11.2 1995/01/06 19:10:21 devrcs
48 * mk6 CR668 - 1.3b26 merge
49 * * Revision 1.1.4.6 1994/05/06 18:39:20 tmt
50 * Merged osc1.3dec/shared with osc1.3b19
51 * Merge Alpha changes into osc1.312b source code.
54 * Cleanup to quiet gcc warnings.
56 * [1994/11/04 08:49:35 dwm]
58 * Revision 1.1.11.1 1994/09/23 01:19:59 ezf
59 * change marker to not FREE
60 * [1994/09/22 21:10:14 ezf]
62 * Revision 1.1.4.4 1993/08/11 20:37:55 elliston
63 * Add ANSI Prototypes. CR #9523.
64 * [1993/08/11 03:33:26 elliston]
66 * Revision 1.1.4.3 1993/07/27 18:27:38 elliston
67 * Add ANSI prototypes. CR #9523.
68 * [1993/07/27 18:12:13 elliston]
70 * Revision 1.1.4.2 1993/06/02 23:11:27 jeffc
71 * Added to OSF/1 R1.3 from NMK15.0.
72 * [1993/06/02 20:56:32 jeffc]
74 * Revision 1.1 1992/09/30 02:01:10 robert
81 * Revision 2.5 91/10/09 16:00:20 af
82 * Revision 2.4.3.1 91/10/05 13:06:25 jeffreyh
83 * Added relational operator tokens and string constant etc.
84 * Added input switching functions for macro and conditional command.
85 * Moved skip_to_eol() from db_command.c and added db_last_lp to print
86 * skipped input data as a warning message.
87 * Added last input repetition support to db_read_line.
88 * Changed db_lex() to always set db_tok_string for error message.
91 * Revision 2.4.3.1 91/10/05 13:06:25 jeffreyh
92 * Added relational operator tokens and string constant etc.
93 * Added input switching functions for macro and conditional command.
94 * Moved skip_to_eol() from db_command.c and added db_last_lp to print
95 * skipped input data as a warning message.
96 * Added last input repetition support to db_read_line.
97 * Changed db_lex() to always set db_tok_string for error message.
100 * Revision 2.4 91/05/14 15:34:23 mrt
101 * Correcting copyright
103 * Revision 2.3 91/02/05 17:06:36 mrt
104 * Changed to new Mach copyright
105 * [91/01/31 16:18:20 mrt]
107 * Revision 2.2 90/08/27 21:51:10 dbg
108 * Add 'dotdot' token.
111 * Allow backslash to quote any character into an identifier.
112 * Allow colon in identifier for symbol table qualification.
122 * Mach Operating System
123 * Copyright (c) 1991,1990 Carnegie Mellon University
124 * All Rights Reserved.
126 * Permission to use, copy, modify and distribute this software and its
127 * documentation is hereby granted, provided that both the copyright
128 * notice and this permission notice appear in all copies of the
129 * software, derivative works or modified versions, and any portions
130 * thereof, and that both notices appear in supporting documentation.
132 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
133 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
134 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
136 * Carnegie Mellon requests users of this software to return to
138 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
139 * School of Computer Science
140 * Carnegie Mellon University
141 * Pittsburgh PA 15213-3890
143 * any improvements or extensions that they make and grant Carnegie Mellon
144 * the rights to redistribute these changes.
149 * Author: David B. Golub, Carnegie Mellon University
155 #include <string.h> /* For strcpy(), strncmp(), strlen() */
156 #include <ddb/db_lex.h>
157 #include <ddb/db_command.h>
158 #include <ddb/db_input.h>
159 #include <ddb/db_output.h> /* For db_printf() */
161 char db_line
[DB_LEX_LINE_SIZE
];
162 char db_last_line
[DB_LEX_LINE_SIZE
];
163 char *db_lp
, *db_endlp
;
165 int db_look_char
= 0;
166 db_expr_t db_look_token
= 0;
169 /* Prototypes for functions local to this file. XXX -- should be static!
171 void db_flush_line(void);
172 void db_unread_char(int c
);
176 db_read_line(char *repeat_last
)
180 i
= db_readline(db_line
, sizeof(db_line
));
182 return (0); /* EOI */
184 if (strncmp(db_line
, repeat_last
, strlen(repeat_last
)) == 0) {
185 strcpy(db_line
, db_last_line
);
186 db_printf("%s", db_line
);
188 } else if (db_line
[0] != '\n' && db_line
[0] != 0)
189 strcpy(db_last_line
, db_line
);
192 db_endlp
= db_lp
+ i
;
214 db_endlp
= buffer
+ size
;
220 db_save_lex_context(register struct db_lex_context
*lp
)
223 lp
->l_eptr
= db_endlp
;
224 lp
->l_char
= db_look_char
;
225 lp
->l_token
= db_look_token
;
229 db_restore_lex_context(register struct db_lex_context
*lp
)
233 db_endlp
= lp
->l_eptr
;
234 db_look_char
= lp
->l_char
;
235 db_look_token
= lp
->l_token
;
243 if (db_look_char
!= 0) {
247 else if (db_lp
>= db_endlp
)
255 db_unread_char(int c
)
261 db_unread_token(int t
)
284 db_expr_t db_tok_number
;
285 char db_tok_string
[TOK_STRING_SIZE
];
287 db_expr_t db_radix
= 16;
297 #define DB_DISP_SKIP 40 /* number of chars to display skip */
309 for (skip
= 0; t
!= tEOL
&& t
!= tSEMI_COLON
&& t
!= tEOF
; skip
++)
311 if (t
== tSEMI_COLON
)
314 while (p
< db_last_lp
&& (*p
== ' ' || *p
== '\t'))
316 db_printf("Warning: Skipped input data \"");
317 for (n
= 0; n
< DB_DISP_SKIP
&& p
< db_last_lp
; n
++)
318 db_printf("%c", *p
++);
319 if (n
>= DB_DISP_SKIP
)
332 while (c
<= ' ' || c
> '~') {
333 if (c
== '\n' || c
== -1)
341 if (c
>= '0' && c
<= '9') {
349 if (c
== 'O' || c
== 'o')
351 else if (c
== 'T' || c
== 't')
353 else if (c
== 'X' || c
== 'x')
365 if (c
>= '0' && c
<= ((r
== 8) ? '7' : '9'))
367 else if (r
== 16 && ((c
>= 'A' && c
<= 'F') ||
368 (c
>= 'a' && c
<= 'f'))) {
370 digit
= c
- 'a' + 10;
372 digit
= c
- 'A' + 10;
376 db_tok_number
= db_tok_number
* r
+ digit
;
378 if (cp
< &db_tok_string
[sizeof(db_tok_string
)-1])
382 if ((c
>= '0' && c
<= '9') ||
383 (c
>= 'A' && c
<= 'Z') ||
384 (c
>= 'a' && c
<= 'z') ||
387 db_printf("Bad character '%c' after number %s\n",
396 if ((c
>= 'A' && c
<= 'Z') ||
397 (c
>= 'a' && c
<= 'z') ||
398 c
== '_' || c
== '\\' || c
== ':')
403 if (c
== '\n' || c
== -1)
404 db_error("Bad '\\' at the end of line\n");
409 if ((c
>= 'A' && c
<= 'Z') ||
410 (c
>= 'a' && c
<= 'z') ||
411 (c
>= '0' && c
<= '9') ||
412 c
== '_' || c
== '\\' || c
== ':' || c
== '.')
416 if (c
== '\n' || c
== -1)
417 db_error("Bad '\\' at the end of line\n");
420 if (cp
== db_tok_string
+sizeof(db_tok_string
)) {
421 db_error("String too long\n");
480 while (c
!= '"' && c
> 0 && c
!= '\n') {
481 if (cp
>= &db_tok_string
[sizeof(db_tok_string
)-1]) {
482 db_error("Too long string\n");
497 db_printf("Bad escape sequence '\\%c'\n", c
);
508 db_error("Non terminated string constant\n");
561 return (tGREATER_EQ
);
567 return (tSEMI_COLON
);
571 strcpy(db_tok_string
, "<EOL>");
574 db_printf("Bad character '%c'\n", c
);