]>
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_OSREFERENCE_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
10 * License may not be used to create, or enable the creation or
11 * redistribution of, unlawful or unlicensed copies of an Apple operating
12 * system, or to circumvent, violate, or enable the circumvention or
13 * violation of, any terms of an Apple operating system software license
16 * Please obtain a copy of the License at
17 * http://www.opensource.apple.com/apsl/ and read it before using this
20 * The Original Code and all software distributed under the License are
21 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
22 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
23 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
24 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
25 * Please see the License for the specific language governing rights and
26 * limitations under the License.
28 * @APPLE_LICENSE_OSREFERENCE_HEADER_END@
36 * Revision 1.1.1.1 1998/09/22 21:05:48 wsanchez
37 * Import of Mac OS X kernel (~semeria)
39 * Revision 1.1.1.1 1998/03/07 02:26:09 wsanchez
40 * Import of OSF Mach kernel (~mburg)
42 * Revision 1.1.11.3 1996/01/09 19:15:49 devrcs
43 * Change 'register foo' to 'register int foo'.
44 * [1995/12/01 21:42:12 jfraser]
46 * Merged '64-bit safe' changes from DEC alpha port.
47 * [1995/11/21 18:03:11 jfraser]
49 * Revision 1.1.11.2 1995/01/06 19:10:21 devrcs
50 * mk6 CR668 - 1.3b26 merge
51 * * Revision 1.1.4.6 1994/05/06 18:39:20 tmt
52 * Merged osc1.3dec/shared with osc1.3b19
53 * Merge Alpha changes into osc1.312b source code.
56 * Cleanup to quiet gcc warnings.
58 * [1994/11/04 08:49:35 dwm]
60 * Revision 1.1.11.1 1994/09/23 01:19:59 ezf
61 * change marker to not FREE
62 * [1994/09/22 21:10:14 ezf]
64 * Revision 1.1.4.4 1993/08/11 20:37:55 elliston
65 * Add ANSI Prototypes. CR #9523.
66 * [1993/08/11 03:33:26 elliston]
68 * Revision 1.1.4.3 1993/07/27 18:27:38 elliston
69 * Add ANSI prototypes. CR #9523.
70 * [1993/07/27 18:12:13 elliston]
72 * Revision 1.1.4.2 1993/06/02 23:11:27 jeffc
73 * Added to OSF/1 R1.3 from NMK15.0.
74 * [1993/06/02 20:56:32 jeffc]
76 * Revision 1.1 1992/09/30 02:01:10 robert
83 * Revision 2.5 91/10/09 16:00:20 af
84 * Revision 2.4.3.1 91/10/05 13:06:25 jeffreyh
85 * Added relational operator tokens and string constant etc.
86 * Added input switching functions for macro and conditional command.
87 * Moved skip_to_eol() from db_command.c and added db_last_lp to print
88 * skipped input data as a warning message.
89 * Added last input repetition support to db_read_line.
90 * Changed db_lex() to always set db_tok_string for error message.
93 * Revision 2.4.3.1 91/10/05 13:06:25 jeffreyh
94 * Added relational operator tokens and string constant etc.
95 * Added input switching functions for macro and conditional command.
96 * Moved skip_to_eol() from db_command.c and added db_last_lp to print
97 * skipped input data as a warning message.
98 * Added last input repetition support to db_read_line.
99 * Changed db_lex() to always set db_tok_string for error message.
102 * Revision 2.4 91/05/14 15:34:23 mrt
103 * Correcting copyright
105 * Revision 2.3 91/02/05 17:06:36 mrt
106 * Changed to new Mach copyright
107 * [91/01/31 16:18:20 mrt]
109 * Revision 2.2 90/08/27 21:51:10 dbg
110 * Add 'dotdot' token.
113 * Allow backslash to quote any character into an identifier.
114 * Allow colon in identifier for symbol table qualification.
124 * Mach Operating System
125 * Copyright (c) 1991,1990 Carnegie Mellon University
126 * All Rights Reserved.
128 * Permission to use, copy, modify and distribute this software and its
129 * documentation is hereby granted, provided that both the copyright
130 * notice and this permission notice appear in all copies of the
131 * software, derivative works or modified versions, and any portions
132 * thereof, and that both notices appear in supporting documentation.
134 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
135 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
136 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
138 * Carnegie Mellon requests users of this software to return to
140 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
141 * School of Computer Science
142 * Carnegie Mellon University
143 * Pittsburgh PA 15213-3890
145 * any improvements or extensions that they make and grant Carnegie Mellon
146 * the rights to redistribute these changes.
151 * Author: David B. Golub, Carnegie Mellon University
157 #include <string.h> /* For strcpy(), strncmp(), strlen() */
158 #include <ddb/db_lex.h>
159 #include <ddb/db_command.h>
160 #include <ddb/db_input.h>
161 #include <ddb/db_output.h> /* For db_printf() */
163 char db_line
[DB_LEX_LINE_SIZE
];
164 char db_last_line
[DB_LEX_LINE_SIZE
];
165 char *db_lp
, *db_endlp
;
167 int db_look_char
= 0;
168 db_expr_t db_look_token
= 0;
171 /* Prototypes for functions local to this file. XXX -- should be static!
173 void db_flush_line(void);
174 void db_unread_char(int c
);
178 db_read_line(char *repeat_last
)
182 i
= db_readline(db_line
, sizeof(db_line
));
184 return (0); /* EOI */
186 if (strncmp(db_line
, repeat_last
, strlen(repeat_last
)) == 0) {
187 strcpy(db_line
, db_last_line
);
188 db_printf("%s", db_line
);
190 } else if (db_line
[0] != '\n' && db_line
[0] != 0)
191 strcpy(db_last_line
, db_line
);
194 db_endlp
= db_lp
+ i
;
216 db_endlp
= buffer
+ size
;
222 db_save_lex_context(register struct db_lex_context
*lp
)
225 lp
->l_eptr
= db_endlp
;
226 lp
->l_char
= db_look_char
;
227 lp
->l_token
= db_look_token
;
231 db_restore_lex_context(register struct db_lex_context
*lp
)
235 db_endlp
= lp
->l_eptr
;
236 db_look_char
= lp
->l_char
;
237 db_look_token
= lp
->l_token
;
245 if (db_look_char
!= 0) {
249 else if (db_lp
>= db_endlp
)
257 db_unread_char(int c
)
263 db_unread_token(int t
)
286 db_expr_t db_tok_number
;
287 char db_tok_string
[TOK_STRING_SIZE
];
289 db_expr_t db_radix
= 16;
299 #define DB_DISP_SKIP 40 /* number of chars to display skip */
311 for (skip
= 0; t
!= tEOL
&& t
!= tSEMI_COLON
&& t
!= tEOF
; skip
++)
313 if (t
== tSEMI_COLON
)
316 while (p
< db_last_lp
&& (*p
== ' ' || *p
== '\t'))
318 db_printf("Warning: Skipped input data \"");
319 for (n
= 0; n
< DB_DISP_SKIP
&& p
< db_last_lp
; n
++)
320 db_printf("%c", *p
++);
321 if (n
>= DB_DISP_SKIP
)
334 while (c
<= ' ' || c
> '~') {
335 if (c
== '\n' || c
== -1)
343 if (c
>= '0' && c
<= '9') {
351 if (c
== 'O' || c
== 'o')
353 else if (c
== 'T' || c
== 't')
355 else if (c
== 'X' || c
== 'x')
367 if (c
>= '0' && c
<= ((r
== 8) ? '7' : '9'))
369 else if (r
== 16 && ((c
>= 'A' && c
<= 'F') ||
370 (c
>= 'a' && c
<= 'f'))) {
372 digit
= c
- 'a' + 10;
374 digit
= c
- 'A' + 10;
378 db_tok_number
= db_tok_number
* r
+ digit
;
380 if (cp
< &db_tok_string
[sizeof(db_tok_string
)-1])
384 if ((c
>= '0' && c
<= '9') ||
385 (c
>= 'A' && c
<= 'Z') ||
386 (c
>= 'a' && c
<= 'z') ||
389 db_printf("Bad character '%c' after number %s\n",
398 if ((c
>= 'A' && c
<= 'Z') ||
399 (c
>= 'a' && c
<= 'z') ||
400 c
== '_' || c
== '\\' || c
== ':')
405 if (c
== '\n' || c
== -1)
406 db_error("Bad '\\' at the end of line\n");
411 if ((c
>= 'A' && c
<= 'Z') ||
412 (c
>= 'a' && c
<= 'z') ||
413 (c
>= '0' && c
<= '9') ||
414 c
== '_' || c
== '\\' || c
== ':' || c
== '.')
418 if (c
== '\n' || c
== -1)
419 db_error("Bad '\\' at the end of line\n");
422 if (cp
== db_tok_string
+sizeof(db_tok_string
)) {
423 db_error("String too long\n");
482 while (c
!= '"' && c
> 0 && c
!= '\n') {
483 if (cp
>= &db_tok_string
[sizeof(db_tok_string
)-1]) {
484 db_error("Too long string\n");
499 db_printf("Bad escape sequence '\\%c'\n", c
);
510 db_error("Non terminated string constant\n");
563 return (tGREATER_EQ
);
569 return (tSEMI_COLON
);
573 strcpy(db_tok_string
, "<EOL>");
576 db_printf("Bad character '%c'\n", c
);