diff --git a/bin/tests/lex_test.c b/bin/tests/lex_test.c index 23ad3a2874..1760256228 100644 --- a/bin/tests/lex_test.c +++ b/bin/tests/lex_test.c @@ -137,8 +137,11 @@ main(int argc, char *argv[]) { while ((result = isc_lex_gettoken(lex, options, &token)) == ISC_R_SUCCESS && !done) { if (!quiet) { + char *name = isc_lex_getsourcename(lex); print_token(&token, stdout); - printf("\n"); + printf(" line = %d file = %s\n", + isc_lex_getsourceline(lex), + (name == NULL) ? "" : name); } if (token.type == isc_tokentype_eof) isc_lex_close(lex); diff --git a/lib/dns/rdata.c b/lib/dns/rdata.c index 734cfd738b..265e20f19f 100644 --- a/lib/dns/rdata.c +++ b/lib/dns/rdata.c @@ -15,7 +15,7 @@ * SOFTWARE. */ - /* $Id: rdata.c,v 1.27 1999/02/05 04:57:19 marka Exp $ */ + /* $Id: rdata.c,v 1.28 1999/02/05 06:41:20 marka Exp $ */ #include @@ -714,11 +714,7 @@ uint32_tobuffer(isc_uint32_t value, isc_buffer_t *target) { isc_buffer_available(target, ®ion); if (region.length < 4) return (DNS_R_NOSPACE); - region.base[0] = (value >> 24) & 0xff; - region.base[1] = (value >> 16) & 0xff; - region.base[2] = (value >> 8) & 0xff; - region.base[3] = value & 0xff; - isc_buffer_add(target, 4); + isc_buffer_putuint32(target, value); return (DNS_R_SUCCESS); } @@ -731,9 +727,7 @@ uint16_tobuffer(isc_uint32_t value, isc_buffer_t *target) { isc_buffer_available(target, ®ion); if (region.length < 2) return (DNS_R_NOSPACE); - region.base[0] = (value >> 8) & 0xff; - region.base[1] = value & 0xff; - isc_buffer_add(target, 2); + isc_buffer_putuint16(target, value); return (DNS_R_SUCCESS); } diff --git a/lib/isc/include/isc/lex.h b/lib/isc/include/isc/lex.h index 269891223e..e1b5f70736 100644 --- a/lib/isc/include/isc/lex.h +++ b/lib/isc/include/isc/lex.h @@ -311,6 +311,30 @@ isc_lex_ungettoken(isc_lex_t *lex, isc_token_t *tokenp); * There is no ungotten token already. */ -/* XXX need a way to get the filename and linenumber of the current source. */ +char * +isc_lex_getsourcename(isc_lex_t *lex); +/* + * Return the input source name. + * + * Requires: + * 'lex' is a valid lexer. + * + * Returns: + * source name or NULL if no current source. + * result valid while current input source exists. + */ + + +int +isc_lex_getsourceline(isc_lex_t *lex); +/* + * Return the input source name. + * + * Requires: + * 'lex' is a valid lexer. + * + * Returns: + * Current line number or 0 if no current source. + */ #endif /* ISC_LEX_H */ diff --git a/lib/isc/lex.c b/lib/isc/lex.c index 774f88ca86..00c5d4ac20 100644 --- a/lib/isc/lex.c +++ b/lib/isc/lex.c @@ -18,7 +18,9 @@ #include #include +#include #include +#include #include @@ -302,7 +304,8 @@ isc_lex_gettoken(isc_lex_t *lex, unsigned int options, isc_token_t *tokenp) { char *curr, *prev; size_t remaining; unsigned long ulong; - unsigned int i, saved_options; + unsigned int saved_options; + char *e; /* * Get the next token. @@ -427,6 +430,7 @@ 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) @@ -485,16 +489,24 @@ 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; - tokenp->type = - isc_tokentype_number; - ulong = 0; - for (i = 0; - i < lex->max_token - remaining; - i++) { - ulong *= 10; - ulong += lex->data[i] - '0'; + ulong = strtoul(lex->data, &e, 10); + if (*e == 0) { + tokenp->type = + isc_tokentype_number; + tokenp->value.as_ulong = + ulong; + } else { + isc_tokenvalue_t *v; + + tokenp->type = + isc_tokentype_string; + v = &(tokenp->value); + v->as_textregion.base = + lex->data; + v->as_textregion.length = + lex->max_token - + remaining; } - tokenp->value.as_ulong = ulong; done = ISC_TRUE; continue; } else @@ -635,3 +647,29 @@ isc_lex_ungettoken(isc_lex_t *lex, isc_token_t *tokenp) { source->token = *tokenp; source->have_token = ISC_TRUE; } + +char * +isc_lex_getsourcename(isc_lex_t *lex) { + inputsource *source; + + REQUIRE(VALID_LEX(lex)); + source = HEAD(lex->sources); + + if (source == NULL) + return(NULL); + + return (source->name); +} + +int +isc_lex_getsourceline(isc_lex_t *lex) { + inputsource *source; + + REQUIRE(VALID_LEX(lex)); + source = HEAD(lex->sources); + + if (source == NULL) + return(0); + + return (source->line); +}