From 10e22ebcc3629be94d37bf408157e2c5ee5740e0 Mon Sep 17 00:00:00 2001 From: Andreas Gustafsson Date: Sat, 9 Dec 2000 02:05:26 +0000 Subject: [PATCH] 605. [func] New function isc_lex_getlasttokentext(). --- CHANGES | 3 +++ lib/isc/include/isc/lex.h | 17 ++++++++++++++++- lib/isc/lex.c | 33 ++++++++++++++++++++++++++++++--- 3 files changed, 49 insertions(+), 4 deletions(-) diff --git a/CHANGES b/CHANGES index 5dccbd696f..9c546da5df 100644 --- a/CHANGES +++ b/CHANGES @@ -1,3 +1,6 @@ + + 605. [func] New function isc_lex_getlasttokentext(). + 604. [bug] The named.conf parser could print incorrect line numbers when long comments were present. diff --git a/lib/isc/include/isc/lex.h b/lib/isc/include/isc/lex.h index 00574e89a9..bf46be43c2 100644 --- a/lib/isc/include/isc/lex.h +++ b/lib/isc/include/isc/lex.h @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: lex.h,v 1.23 2000/11/08 01:55:30 bwelling Exp $ */ +/* $Id: lex.h,v 1.24 2000/12/09 02:05:26 gson Exp $ */ #ifndef ISC_LEX_H #define ISC_LEX_H 1 @@ -335,6 +335,21 @@ isc_lex_ungettoken(isc_lex_t *lex, isc_token_t *tokenp); * There is no ungotten token already. */ +void +isc_lex_getlasttokentext(isc_lex_t *lex, isc_token_t *tokenp, isc_region_t *r); +/* + * Returns a region containing the text of the last token returned. + * + * Requires: + * 'lex' is a valid lexer. + * + * 'lex' has an input source. + * + * 'tokenp' points to a valid token. + * + * A token has been gotten and not ungotten. + */ + char * isc_lex_getsourcename(isc_lex_t *lex); /* diff --git a/lib/isc/lex.c b/lib/isc/lex.c index 402e99794c..85d712fdce 100644 --- a/lib/isc/lex.c +++ b/lib/isc/lex.c @@ -15,7 +15,7 @@ * WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ -/* $Id: lex.c,v 1.55 2000/12/09 00:41:33 bwelling Exp $ */ +/* $Id: lex.c,v 1.56 2000/12/09 02:05:25 gson Exp $ */ #include @@ -38,6 +38,7 @@ typedef struct inputsource { isc_boolean_t need_close; isc_boolean_t at_eof; isc_buffer_t * pushback; + unsigned int ignored; void * input; char * name; unsigned long line; @@ -213,6 +214,7 @@ new_source(isc_lex_t *lex, isc_boolean_t is_file, isc_boolean_t need_close, isc_mem_put(lex->mctx, source, sizeof *source); return (result); } + source->ignored = 0; source->line = 1; ISC_LIST_INITANDPREPEND(lex->sources, source, link); @@ -452,10 +454,15 @@ isc_lex_gettoken(isc_lex_t *lex, unsigned int options, isc_token_t *tokenp) { } } - if (!source->at_eof) + if (!source->at_eof) { + if (state == lexstate_start) + /* Token has not started yet. */ + source->ignored = + isc_buffer_consumedlength(source->pushback); c = isc_buffer_getuint8(source->pushback); - else + } else { c = EOF; + } if (c == '\n') source->line++; @@ -795,6 +802,26 @@ isc_lex_ungettoken(isc_lex_t *lex, isc_token_t *tokenp) { source->at_eof = ISC_FALSE; } +void +isc_lex_getlasttokentext(isc_lex_t *lex, isc_token_t *tokenp, isc_region_t *r) +{ + inputsource *source; + + REQUIRE(VALID_LEX(lex)); + source = HEAD(lex->sources); + REQUIRE(source != NULL); + REQUIRE(tokenp != NULL); + REQUIRE(isc_buffer_consumedlength(source->pushback) != 0 || + tokenp->type == isc_tokentype_eof); + + UNUSED(tokenp); + + INSIST(source->ignored <= isc_buffer_consumedlength(source->pushback)); + r->base = isc_buffer_base(source->pushback) + source->ignored; + r->length = isc_buffer_consumedlength(source->pushback) - source->ignored; +} + + char * isc_lex_getsourcename(isc_lex_t *lex) { inputsource *source;