aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRyan Libby <rlibby@FreeBSD.org>2021-02-24 23:56:16 +0000
committerRyan Libby <rlibby@FreeBSD.org>2021-02-24 23:56:16 +0000
commitd8404b7ec36d4974e7ac586df1d74be4ef6b141e (patch)
treeda61cf8897bfd8fd78970f74adcfa61792b66091
parentd85c9cef1380f4f135aee95ad8c1f4d3eca74c5b (diff)
downloadsrc-d8404b7ec36d4974e7ac586df1d74be4ef6b141e.tar.gz
src-d8404b7ec36d4974e7ac586df1d74be4ef6b141e.zip
ddb: just move cursor when the lexer backs up
Get rid of db_look_char because it's not compatible with db_get_line(). This fixes the following issue: db> script lockinfo=show alllocks db> run lockinfo db:0:lockinfo> how alllocks No such command; use "help" to list available commands Reported by: markj Reviewed by: markj Sponsored by: Dell EMC Isilon Differential Revision: https://reviews.freebsd.org/D28725
-rw-r--r--sys/ddb/db_lex.c27
1 files changed, 16 insertions, 11 deletions
diff --git a/sys/ddb/db_lex.c b/sys/ddb/db_lex.c
index 457790ee8605..215e7cd7f2ab 100644
--- a/sys/ddb/db_lex.c
+++ b/sys/ddb/db_lex.c
@@ -97,18 +97,12 @@ db_flush_line()
db_endlp = db_line;
}
-static int db_look_char = 0;
-
static int
db_read_char(void)
{
int c;
- if (db_look_char != 0) {
- c = db_look_char;
- db_look_char = 0;
- }
- else if (db_lp >= db_endlp)
+ if (db_lp >= db_endlp)
c = -1;
else
c = *db_lp++;
@@ -116,10 +110,22 @@ db_read_char(void)
}
static void
-db_unread_char(c)
- int c;
+db_unread_char(int c)
{
- db_look_char = c;
+
+ if (c == -1) {
+ /* Unread EOL at EOL is okay. */
+ if (db_lp < db_endlp)
+ db_error("db_unread_char(-1) before end of line\n");
+ } else {
+ if (db_lp > db_line) {
+ db_lp--;
+ if (*db_lp != c)
+ db_error("db_unread_char() wrong char\n");
+ } else {
+ db_error("db_unread_char() at beginning of line\n");
+ }
+ }
}
static int db_look_token = 0;
@@ -155,7 +161,6 @@ void
db_flush_lex(void)
{
db_flush_line();
- db_look_char = 0;
db_look_token = 0;
}