mirror of
https://gitlab.isc.org/isc-projects/bind9
synced 2025-08-31 14:35:26 +00:00
Instead of storing parentheses deltas, just copy lex->paren_count and
restore it on ungettoken(). This is much easier (thanks, Mark).
This commit is contained in:
@@ -15,7 +15,7 @@
|
|||||||
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
* WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
/* $Id: lex.c,v 1.51 2000/11/18 21:15:23 bwelling Exp $ */
|
/* $Id: lex.c,v 1.52 2000/11/20 00:41:50 bwelling Exp $ */
|
||||||
|
|
||||||
#include <config.h>
|
#include <config.h>
|
||||||
|
|
||||||
@@ -37,7 +37,6 @@ typedef struct inputsource {
|
|||||||
isc_boolean_t need_close;
|
isc_boolean_t need_close;
|
||||||
isc_boolean_t at_eof;
|
isc_boolean_t at_eof;
|
||||||
isc_buffer_t * pushback;
|
isc_buffer_t * pushback;
|
||||||
unsigned int pushback_parens;
|
|
||||||
void * input;
|
void * input;
|
||||||
char * name;
|
char * name;
|
||||||
unsigned long line;
|
unsigned long line;
|
||||||
@@ -59,6 +58,7 @@ struct isc_lex {
|
|||||||
isc_boolean_t comment_ok;
|
isc_boolean_t comment_ok;
|
||||||
isc_boolean_t last_was_eol;
|
isc_boolean_t last_was_eol;
|
||||||
unsigned int paren_count;
|
unsigned int paren_count;
|
||||||
|
unsigned int saved_paren_count;
|
||||||
isc_lexspecials_t specials;
|
isc_lexspecials_t specials;
|
||||||
LIST(struct inputsource) sources;
|
LIST(struct inputsource) sources;
|
||||||
};
|
};
|
||||||
@@ -106,6 +106,7 @@ isc_lex_create(isc_mem_t *mctx, size_t max_token, isc_lex_t **lexp) {
|
|||||||
lex->comment_ok = ISC_TRUE;
|
lex->comment_ok = ISC_TRUE;
|
||||||
lex->last_was_eol = ISC_TRUE;
|
lex->last_was_eol = ISC_TRUE;
|
||||||
lex->paren_count = 0;
|
lex->paren_count = 0;
|
||||||
|
lex->saved_paren_count = 0;
|
||||||
memset(lex->specials, 0, 256);
|
memset(lex->specials, 0, 256);
|
||||||
INIT_LIST(lex->sources);
|
INIT_LIST(lex->sources);
|
||||||
lex->magic = LEX_MAGIC;
|
lex->magic = LEX_MAGIC;
|
||||||
@@ -203,7 +204,6 @@ new_source(isc_lex_t *lex, isc_boolean_t is_file, isc_boolean_t need_close,
|
|||||||
return (ISC_R_NOMEMORY);
|
return (ISC_R_NOMEMORY);
|
||||||
}
|
}
|
||||||
source->pushback = NULL;
|
source->pushback = NULL;
|
||||||
source->pushback_parens = 0;
|
|
||||||
result = isc_buffer_allocate(lex->mctx, &source->pushback,
|
result = isc_buffer_allocate(lex->mctx, &source->pushback,
|
||||||
lex->max_token);
|
lex->max_token);
|
||||||
if (result != ISC_R_SUCCESS) {
|
if (result != ISC_R_SUCCESS) {
|
||||||
@@ -330,9 +330,7 @@ pushback(inputsource *source, int c) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
static isc_result_t
|
static isc_result_t
|
||||||
pushandgrow(isc_lex_t *lex, inputsource *source, int c, unsigned int options,
|
pushandgrow(isc_lex_t *lex, inputsource *source, int c) {
|
||||||
lexstate state)
|
|
||||||
{
|
|
||||||
if (isc_buffer_availablelength(source->pushback) == 0) {
|
if (isc_buffer_availablelength(source->pushback) == 0) {
|
||||||
isc_buffer_t *tbuf = NULL;
|
isc_buffer_t *tbuf = NULL;
|
||||||
unsigned int oldlen;
|
unsigned int oldlen;
|
||||||
@@ -350,14 +348,6 @@ pushandgrow(isc_lex_t *lex, inputsource *source, int c, unsigned int options,
|
|||||||
source->pushback = tbuf;
|
source->pushback = tbuf;
|
||||||
}
|
}
|
||||||
isc_buffer_putuint8(source->pushback, (isc_uint8_t)c);
|
isc_buffer_putuint8(source->pushback, (isc_uint8_t)c);
|
||||||
if ((options & ISC_LEXOPT_DNSMULTILINE) != 0 &&
|
|
||||||
state == lexstate_start)
|
|
||||||
{
|
|
||||||
if (c == '(')
|
|
||||||
source->pushback_parens++;
|
|
||||||
else if (c == ')')
|
|
||||||
source->pushback_parens--;
|
|
||||||
}
|
|
||||||
return (ISC_R_SUCCESS);
|
return (ISC_R_SUCCESS);
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -387,6 +377,8 @@ isc_lex_gettoken(isc_lex_t *lex, unsigned int options, isc_token_t *tokenp) {
|
|||||||
source = HEAD(lex->sources);
|
source = HEAD(lex->sources);
|
||||||
REQUIRE(tokenp != NULL);
|
REQUIRE(tokenp != NULL);
|
||||||
|
|
||||||
|
lex->saved_paren_count = lex->paren_count;
|
||||||
|
|
||||||
if (source == NULL) {
|
if (source == NULL) {
|
||||||
if ((options & ISC_LEXOPT_NOMORE) != 0) {
|
if ((options & ISC_LEXOPT_NOMORE) != 0) {
|
||||||
tokenp->type = isc_tokentype_nomore;
|
tokenp->type = isc_tokentype_nomore;
|
||||||
@@ -412,7 +404,6 @@ isc_lex_gettoken(isc_lex_t *lex, unsigned int options, isc_token_t *tokenp) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
isc_buffer_compact(source->pushback);
|
isc_buffer_compact(source->pushback);
|
||||||
source->pushback_parens = 0;
|
|
||||||
|
|
||||||
saved_options = options;
|
saved_options = options;
|
||||||
if ((options & ISC_LEXOPT_DNSMULTILINE) != 0 && lex->paren_count > 0)
|
if ((options & ISC_LEXOPT_DNSMULTILINE) != 0 && lex->paren_count > 0)
|
||||||
@@ -451,8 +442,7 @@ isc_lex_gettoken(isc_lex_t *lex, unsigned int options, isc_token_t *tokenp) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (c != EOF) {
|
if (c != EOF) {
|
||||||
source->result = pushandgrow(lex, source, c,
|
source->result = pushandgrow(lex, source, c);
|
||||||
options, state);
|
|
||||||
if (source->result != ISC_R_SUCCESS)
|
if (source->result != ISC_R_SUCCESS)
|
||||||
return (source->result);
|
return (source->result);
|
||||||
}
|
}
|
||||||
@@ -792,10 +782,7 @@ isc_lex_ungettoken(isc_lex_t *lex, isc_token_t *tokenp) {
|
|||||||
UNUSED(tokenp);
|
UNUSED(tokenp);
|
||||||
|
|
||||||
isc_buffer_first(source->pushback);
|
isc_buffer_first(source->pushback);
|
||||||
if (source->pushback_parens > 0) {
|
lex->paren_count = lex->saved_paren_count;
|
||||||
lex->paren_count -= source->pushback_parens;
|
|
||||||
INSIST(lex->paren_count >= 0);
|
|
||||||
}
|
|
||||||
source->at_eof = ISC_FALSE;
|
source->at_eof = ISC_FALSE;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user