From 02e5f92113a696cfb449eecb37fd1227c9522a84 Mon Sep 17 00:00:00 2001 From: Brian Wellington Date: Thu, 21 Feb 2002 00:44:16 +0000 Subject: [PATCH] isc_lex_setsourcename(), for use when lexing buffers or streams --- lib/isc/include/isc/lex.h | 17 ++++++++++++++++- lib/isc/lex.c | 25 ++++++++++++++++++++++--- 2 files changed, 38 insertions(+), 4 deletions(-) diff --git a/lib/isc/include/isc/lex.h b/lib/isc/include/isc/lex.h index 13ad7186a9..2251235d33 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.28 2002/02/20 03:35:33 marka Exp $ */ +/* $Id: lex.h,v 1.29 2002/02/21 00:44:16 bwelling Exp $ */ #ifndef ISC_LEX_H #define ISC_LEX_H 1 @@ -376,6 +376,21 @@ isc_lex_getsourceline(isc_lex_t *lex); * Current line number or 0 if no current source. */ +isc_result_t +isc_lex_setsourcename(isc_lex_t *lex, const char *name); +/* + * Assigns a new name to the input source. + * + * Requires: + * + * 'lex' is a valid lexer. + * + * Returns: + * ISC_R_SUCCESS + * ISC_R_NOMEMORY + * ISC_R_NOTFOUND - there are no sources. + */ + isc_boolean_t isc_lex_isfile(isc_lex_t *lex); /* diff --git a/lib/isc/lex.c b/lib/isc/lex.c index 6e1f040719..ffc3a45277 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.72 2001/12/13 06:13:44 marka Exp $ */ +/* $Id: lex.c,v 1.73 2002/02/21 00:44:14 bwelling Exp $ */ #include @@ -869,7 +869,7 @@ isc_lex_getsourcename(isc_lex_t *lex) { source = HEAD(lex->sources); if (source == NULL) - return(NULL); + return (NULL); return (source->name); } @@ -882,11 +882,30 @@ isc_lex_getsourceline(isc_lex_t *lex) { source = HEAD(lex->sources); if (source == NULL) - return(0); + return (0); return (source->line); } + +isc_result_t +isc_lex_setsourcename(isc_lex_t *lex, const char *name) { + inputsource *source; + char *newname; + + REQUIRE(VALID_LEX(lex)); + source = HEAD(lex->sources); + + if (source == NULL) + return(ISC_R_NOTFOUND); + newname = isc_mem_strdup(lex->mctx, name); + if (newname == NULL) + return (ISC_R_NOMEMORY); + isc_mem_free(lex->mctx, source->name); + source->name = newname; + return (ISC_R_SUCCESS); +} + isc_boolean_t isc_lex_isfile(isc_lex_t *lex) { inputsource *source;