mirror of
https://github.com/isc-projects/bind9.git
synced 2026-06-09 08:22:04 -04:00
isc_lex_getsourcename()
isc_lex_getsourceline() convert uint#_tobuffer() to use isc_buffer_putuint#()
This commit is contained in:
parent
2cd8a160b9
commit
e4653123ec
4 changed files with 80 additions and 21 deletions
|
|
@ -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) ? "<none>" : name);
|
||||
}
|
||||
if (token.type == isc_tokentype_eof)
|
||||
isc_lex_close(lex);
|
||||
|
|
|
|||
|
|
@ -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 <config.h>
|
||||
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -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 */
|
||||
|
|
|
|||
|
|
@ -18,7 +18,9 @@
|
|||
#include <config.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <limits.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include <sys/types.h>
|
||||
|
||||
|
|
@ -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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue