From ab5657cabfb597cd28f038dcf3245ab9947d4e14 Mon Sep 17 00:00:00 2001 From: James Brister Date: Tue, 8 Jun 1999 12:45:23 +0000 Subject: [PATCH] Support bases other than 10 in numbers (using option ISC_LEXOPT_CNUMBER) Fixed bug in keeping track of input line numbers inside comments. --- lib/isc/include/isc/lex.h | 6 +++++- lib/isc/lex.c | 14 +++++++++++--- 2 files changed, 16 insertions(+), 4 deletions(-) diff --git a/lib/isc/include/isc/lex.h b/lib/isc/include/isc/lex.h index 996b75199c..3e4d52c379 100644 --- a/lib/isc/include/isc/lex.h +++ b/lib/isc/include/isc/lex.h @@ -74,7 +74,7 @@ ISC_LANG_BEGINDECLS #define ISC_LEXOPT_INITIALWS 0x04 /* Want initial whitespace. */ #define ISC_LEXOPT_NUMBER 0x08 /* Recognize numbers. */ #define ISC_LEXOPT_QSTRING 0x10 /* Recognize qstrings. */ -#define ISC_LEXOPT_ESCAPE 0x20 /* Recognize escapes. */ + /* * The ISC_LEXOPT_DNSMULTILINE option handles the processing of '(' and ')' in * the DNS master file format. If this option is set, then the @@ -85,6 +85,10 @@ ISC_LANG_BEGINDECLS #define ISC_LEXOPT_DNSMULTILINE 0x20 /* Handle '(' and ')'. */ #define ISC_LEXOPT_NOMORE 0x40 /* Want "no more" token. */ +#define ISC_LEXOPT_CNUMBER 0x80 /* Regognise octal and hex */ +#define ISC_LEXOPT_ESCAPE 0x100 /* Recognize escapes. */ + + /* * Various commenting styles, which may be changed at any time with * isc_lex_setcomments(). diff --git a/lib/isc/lex.c b/lib/isc/lex.c index 6f76fa3780..33ba4011f9 100644 --- a/lib/isc/lex.c +++ b/lib/isc/lex.c @@ -381,6 +381,10 @@ isc_lex_gettoken(isc_lex_t *lex, unsigned int options, isc_token_t *tokenp) { } } + if (c == '\n') { + source->line++; + } + if (lex->comment_ok && !no_comments) { if (!escaped && c == ';' && ((lex->comments & ISC_LEXCOMMENT_DNSMASTERFILE) @@ -434,7 +438,6 @@ isc_lex_gettoken(isc_lex_t *lex, unsigned int options, isc_token_t *tokenp) { tokenp->type = isc_tokentype_eol; done = ISC_TRUE; } - source->line++; lex->last_was_eol = ISC_TRUE; } else if (c == '\r') { if ((options & ISC_LEXOPT_EOL) != 0) @@ -493,7 +496,7 @@ isc_lex_gettoken(isc_lex_t *lex, unsigned int options, isc_token_t *tokenp) { INSIST(source->char_count < 2); source->chars[source->char_count++] = c; - ulong = strtoul(lex->data, &e, 10); + ulong = strtoul(lex->data, &e, 0); if (*e == 0) { tokenp->type = isc_tokentype_number; @@ -513,8 +516,13 @@ isc_lex_gettoken(isc_lex_t *lex, unsigned int options, isc_token_t *tokenp) { } done = ISC_TRUE; continue; - } else + } else if (!(options & ISC_LEXOPT_CNUMBER) || + ((c != 'x' && c != 'X') || + (curr != &lex->data[1]) || + (lex->data[0] != '0'))) { + /* Above test supports hex numbers */ state = lexstate_string; + } } if (remaining > 0) { *curr++ = c;