db_lex.c (139747) | db_lex.c (174914) |
---|---|
1/*- 2 * Mach Operating System 3 * Copyright (c) 1991,1990 Carnegie Mellon University 4 * All Rights Reserved. 5 * 6 * Permission to use, copy, modify and distribute this software and its 7 * documentation is hereby granted, provided that both the copyright 8 * notice and this permission notice appear in all copies of the --- 18 unchanged lines hidden (view full) --- 27 * Author: David B. Golub, Carnegie Mellon University 28 * Date: 7/90 29 */ 30/* 31 * Lexical analyzer. 32 */ 33 34#include <sys/cdefs.h> | 1/*- 2 * Mach Operating System 3 * Copyright (c) 1991,1990 Carnegie Mellon University 4 * All Rights Reserved. 5 * 6 * Permission to use, copy, modify and distribute this software and its 7 * documentation is hereby granted, provided that both the copyright 8 * notice and this permission notice appear in all copies of the --- 18 unchanged lines hidden (view full) --- 27 * Author: David B. Golub, Carnegie Mellon University 28 * Date: 7/90 29 */ 30/* 31 * Lexical analyzer. 32 */ 33 34#include <sys/cdefs.h> |
35__FBSDID("$FreeBSD: head/sys/ddb/db_lex.c 139747 2005-01-06 01:34:41Z imp $"); | 35__FBSDID("$FreeBSD: head/sys/ddb/db_lex.c 174914 2007-12-26 09:33:19Z rwatson $"); |
36 37#include <sys/param.h> | 36 37#include <sys/param.h> |
38#include <sys/libkern.h> |
|
38 39#include <ddb/ddb.h> 40#include <ddb/db_lex.h> 41 | 39 40#include <ddb/ddb.h> 41#include <ddb/db_lex.h> 42 |
42static char db_line[120]; | 43static char db_line[DB_MAXLINE]; |
43static char * db_lp, *db_endlp; 44 45static int db_lex(void); 46static void db_flush_line(void); 47static int db_read_char(void); 48static void db_unread_char(int); 49 50int --- 4 unchanged lines hidden (view full) --- 55 i = db_readline(db_line, sizeof(db_line)); 56 if (i == 0) 57 return (0); /* EOI */ 58 db_lp = db_line; 59 db_endlp = db_lp + i; 60 return (i); 61} 62 | 44static char * db_lp, *db_endlp; 45 46static int db_lex(void); 47static void db_flush_line(void); 48static int db_read_char(void); 49static void db_unread_char(int); 50 51int --- 4 unchanged lines hidden (view full) --- 56 i = db_readline(db_line, sizeof(db_line)); 57 if (i == 0) 58 return (0); /* EOI */ 59 db_lp = db_line; 60 db_endlp = db_lp + i; 61 return (i); 62} 63 |
64/* 65 * Simulate a line of input into DDB. 66 */ 67void 68db_inject_line(const char *command) 69{ 70 71 strlcpy(db_line, command, sizeof(db_line)); 72 db_lp = db_line; 73 db_endlp = db_lp + strlen(command); 74} 75 76/* 77 * In rare cases, we may want to pull the remainder of the line input 78 * verbatim, rather than lexing it. For example, when assigning literal 79 * values associated with scripts. In that case, return a static pointer to 80 * the current location in the input buffer. The caller must be aware that 81 * the contents are not stable if other lex/input calls are made. 82 */ 83char * 84db_get_line(void) 85{ 86 87 return (db_lp); 88} 89 |
|
63static void 64db_flush_line() 65{ 66 db_lp = db_line; 67 db_endlp = db_line; 68} 69 70static int db_look_char = 0; --- 188 unchanged lines hidden (view full) --- 259 case ',': 260 return (tCOMMA); 261 case '"': 262 return (tDITTO); 263 case '$': 264 return (tDOLLAR); 265 case '!': 266 return (tEXCL); | 90static void 91db_flush_line() 92{ 93 db_lp = db_line; 94 db_endlp = db_line; 95} 96 97static int db_look_char = 0; --- 188 unchanged lines hidden (view full) --- 286 case ',': 287 return (tCOMMA); 288 case '"': 289 return (tDITTO); 290 case '$': 291 return (tDOLLAR); 292 case '!': 293 return (tEXCL); |
294 case ';': 295 return (tSEMI); |
|
267 case '<': 268 c = db_read_char(); 269 if (c == '<') 270 return (tSHIFT_L); 271 db_unread_char(c); 272 break; 273 case '>': 274 c = db_read_char(); 275 if (c == '>') 276 return (tSHIFT_R); 277 db_unread_char(c); 278 break; 279 case -1: 280 return (tEOF); 281 } 282 db_printf("Bad character\n"); 283 db_flush_lex(); 284 return (tEOF); 285} | 296 case '<': 297 c = db_read_char(); 298 if (c == '<') 299 return (tSHIFT_L); 300 db_unread_char(c); 301 break; 302 case '>': 303 c = db_read_char(); 304 if (c == '>') 305 return (tSHIFT_R); 306 db_unread_char(c); 307 break; 308 case -1: 309 return (tEOF); 310 } 311 db_printf("Bad character\n"); 312 db_flush_lex(); 313 return (tEOF); 314} |