]>
git.saurik.com Git - apple/xnu.git/blob - osfmk/ddb/db_lex.c
8a1ec12614eb168f17e7d5ffcbe53c2db57b6d14
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_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. Please obtain a copy of the License at
10 * http://www.opensource.apple.com/apsl/ and read it before using this
13 * The Original Code and all software distributed under the License are
14 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
15 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
16 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
17 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
18 * Please see the License for the specific language governing rights and
19 * limitations under the License.
21 * @APPLE_LICENSE_HEADER_END@
29 * Revision 1.1.1.1 1998/09/22 21:05:48 wsanchez
30 * Import of Mac OS X kernel (~semeria)
32 * Revision 1.1.1.1 1998/03/07 02:26:09 wsanchez
33 * Import of OSF Mach kernel (~mburg)
35 * Revision 1.1.11.3 1996/01/09 19:15:49 devrcs
36 * Change 'register foo' to 'register int foo'.
37 * [1995/12/01 21:42:12 jfraser]
39 * Merged '64-bit safe' changes from DEC alpha port.
40 * [1995/11/21 18:03:11 jfraser]
42 * Revision 1.1.11.2 1995/01/06 19:10:21 devrcs
43 * mk6 CR668 - 1.3b26 merge
44 * * Revision 1.1.4.6 1994/05/06 18:39:20 tmt
45 * Merged osc1.3dec/shared with osc1.3b19
46 * Merge Alpha changes into osc1.312b source code.
49 * Cleanup to quiet gcc warnings.
51 * [1994/11/04 08:49:35 dwm]
53 * Revision 1.1.11.1 1994/09/23 01:19:59 ezf
54 * change marker to not FREE
55 * [1994/09/22 21:10:14 ezf]
57 * Revision 1.1.4.4 1993/08/11 20:37:55 elliston
58 * Add ANSI Prototypes. CR #9523.
59 * [1993/08/11 03:33:26 elliston]
61 * Revision 1.1.4.3 1993/07/27 18:27:38 elliston
62 * Add ANSI prototypes. CR #9523.
63 * [1993/07/27 18:12:13 elliston]
65 * Revision 1.1.4.2 1993/06/02 23:11:27 jeffc
66 * Added to OSF/1 R1.3 from NMK15.0.
67 * [1993/06/02 20:56:32 jeffc]
69 * Revision 1.1 1992/09/30 02:01:10 robert
76 * Revision 2.5 91/10/09 16:00:20 af
77 * Revision 2.4.3.1 91/10/05 13:06:25 jeffreyh
78 * Added relational operator tokens and string constant etc.
79 * Added input switching functions for macro and conditional command.
80 * Moved skip_to_eol() from db_command.c and added db_last_lp to print
81 * skipped input data as a warning message.
82 * Added last input repetition support to db_read_line.
83 * Changed db_lex() to always set db_tok_string for error message.
86 * Revision 2.4.3.1 91/10/05 13:06:25 jeffreyh
87 * Added relational operator tokens and string constant etc.
88 * Added input switching functions for macro and conditional command.
89 * Moved skip_to_eol() from db_command.c and added db_last_lp to print
90 * skipped input data as a warning message.
91 * Added last input repetition support to db_read_line.
92 * Changed db_lex() to always set db_tok_string for error message.
95 * Revision 2.4 91/05/14 15:34:23 mrt
96 * Correcting copyright
98 * Revision 2.3 91/02/05 17:06:36 mrt
99 * Changed to new Mach copyright
100 * [91/01/31 16:18:20 mrt]
102 * Revision 2.2 90/08/27 21:51:10 dbg
103 * Add 'dotdot' token.
106 * Allow backslash to quote any character into an identifier.
107 * Allow colon in identifier for symbol table qualification.
117 * Mach Operating System
118 * Copyright (c) 1991,1990 Carnegie Mellon University
119 * All Rights Reserved.
121 * Permission to use, copy, modify and distribute this software and its
122 * documentation is hereby granted, provided that both the copyright
123 * notice and this permission notice appear in all copies of the
124 * software, derivative works or modified versions, and any portions
125 * thereof, and that both notices appear in supporting documentation.
127 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
128 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
129 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
131 * Carnegie Mellon requests users of this software to return to
133 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
134 * School of Computer Science
135 * Carnegie Mellon University
136 * Pittsburgh PA 15213-3890
138 * any improvements or extensions that they make and grant Carnegie Mellon
139 * the rights to redistribute these changes.
144 * Author: David B. Golub, Carnegie Mellon University
150 #include <string.h> /* For strcpy(), strncmp(), strlen() */
151 #include <ddb/db_lex.h>
152 #include <ddb/db_command.h>
153 #include <ddb/db_input.h>
154 #include <ddb/db_output.h> /* For db_printf() */
156 char db_line
[DB_LEX_LINE_SIZE
];
157 char db_last_line
[DB_LEX_LINE_SIZE
];
158 char *db_lp
, *db_endlp
;
160 int db_look_char
= 0;
161 db_expr_t db_look_token
= 0;
164 /* Prototypes for functions local to this file. XXX -- should be static!
166 void db_flush_line(void);
167 void db_unread_char(int c
);
171 db_read_line(char *repeat_last
)
175 i
= db_readline(db_line
, sizeof(db_line
));
177 return (0); /* EOI */
179 if (strncmp(db_line
, repeat_last
, strlen(repeat_last
)) == 0) {
180 strcpy(db_line
, db_last_line
);
181 db_printf("%s", db_line
);
183 } else if (db_line
[0] != '\n' && db_line
[0] != 0)
184 strcpy(db_last_line
, db_line
);
187 db_endlp
= db_lp
+ i
;
209 db_endlp
= buffer
+ size
;
215 db_save_lex_context(register struct db_lex_context
*lp
)
218 lp
->l_eptr
= db_endlp
;
219 lp
->l_char
= db_look_char
;
220 lp
->l_token
= db_look_token
;
224 db_restore_lex_context(register struct db_lex_context
*lp
)
228 db_endlp
= lp
->l_eptr
;
229 db_look_char
= lp
->l_char
;
230 db_look_token
= lp
->l_token
;
238 if (db_look_char
!= 0) {
242 else if (db_lp
>= db_endlp
)
250 db_unread_char(int c
)
256 db_unread_token(int t
)
279 db_expr_t db_tok_number
;
280 char db_tok_string
[TOK_STRING_SIZE
];
282 db_expr_t db_radix
= 16;
292 #define DB_DISP_SKIP 40 /* number of chars to display skip */
304 for (skip
= 0; t
!= tEOL
&& t
!= tSEMI_COLON
&& t
!= tEOF
; skip
++)
306 if (t
== tSEMI_COLON
)
309 while (p
< db_last_lp
&& (*p
== ' ' || *p
== '\t'))
311 db_printf("Warning: Skipped input data \"");
312 for (n
= 0; n
< DB_DISP_SKIP
&& p
< db_last_lp
; n
++)
313 db_printf("%c", *p
++);
314 if (n
>= DB_DISP_SKIP
)
327 while (c
<= ' ' || c
> '~') {
328 if (c
== '\n' || c
== -1)
336 if (c
>= '0' && c
<= '9') {
344 if (c
== 'O' || c
== 'o')
346 else if (c
== 'T' || c
== 't')
348 else if (c
== 'X' || c
== 'x')
360 if (c
>= '0' && c
<= ((r
== 8) ? '7' : '9'))
362 else if (r
== 16 && ((c
>= 'A' && c
<= 'F') ||
363 (c
>= 'a' && c
<= 'f'))) {
365 digit
= c
- 'a' + 10;
367 digit
= c
- 'A' + 10;
371 db_tok_number
= db_tok_number
* r
+ digit
;
373 if (cp
< &db_tok_string
[sizeof(db_tok_string
)-1])
377 if ((c
>= '0' && c
<= '9') ||
378 (c
>= 'A' && c
<= 'Z') ||
379 (c
>= 'a' && c
<= 'z') ||
382 db_printf("Bad character '%c' after number %s\n",
391 if ((c
>= 'A' && c
<= 'Z') ||
392 (c
>= 'a' && c
<= 'z') ||
393 c
== '_' || c
== '\\' || c
== ':')
398 if (c
== '\n' || c
== -1)
399 db_error("Bad '\\' at the end of line\n");
404 if ((c
>= 'A' && c
<= 'Z') ||
405 (c
>= 'a' && c
<= 'z') ||
406 (c
>= '0' && c
<= '9') ||
407 c
== '_' || c
== '\\' || c
== ':' || c
== '.')
411 if (c
== '\n' || c
== -1)
412 db_error("Bad '\\' at the end of line\n");
415 if (cp
== db_tok_string
+sizeof(db_tok_string
)) {
416 db_error("String too long\n");
475 while (c
!= '"' && c
> 0 && c
!= '\n') {
476 if (cp
>= &db_tok_string
[sizeof(db_tok_string
)-1]) {
477 db_error("Too long string\n");
492 db_printf("Bad escape sequence '\\%c'\n", c
);
503 db_error("Non terminated string constant\n");
556 return (tGREATER_EQ
);
562 return (tSEMI_COLON
);
566 strcpy(db_tok_string
, "<EOL>");
569 db_printf("Bad character '%c'\n", c
);