*/
void scan_to_eol(LEX *lc)
{
- Dmsg0(150, "start scan to eof\n");
+ Dmsg0(900, "start scan to eof\n");
while (lex_get_token(lc, T_ALL) != T_EOL)
{ }
- Dmsg0(150, "done scan to eof\n");
+ Dmsg0(900, "done scan to eof\n");
}
va_end(arg_ptr);
if (lc->line_no > lc->begin_line_no) {
- sprintf(more, _("Problem probably begins at Line %d.\n"), lc->begin_line_no);
+ bsnprintf(more, sizeof(more),
+ _("Problem probably begins at line %d.\n"), lc->begin_line_no);
} else {
more[0] = 0;
}
e_msg(file, line, M_ERROR_TERM, 0, _("Config error: %s\n\
- : Line %d, col %d of file %s\n%s\n%s"),
+ : line %d, col %d of file %s\n%s\n%s"),
buf, lc->line_no, lc->col_no, lc->fname, lc->line, more);
}
{
LEX *of;
- Dmsg1(40, "Close lex file: %s\n", lf->fname);
+ Dmsg1(900, "Close lex file: %s\n", lf->fname);
if (lf == NULL) {
Emsg0(M_ABORT, 0, "Close of NULL file\n");
}
of = lf->next;
fclose(lf->fd);
- Dmsg1(49, "Close cfg file %s\n", lf->fname);
+ Dmsg1(900, "Close cfg file %s\n", lf->fname);
free(lf->fname);
if (of) {
of->options = lf->options; /* preserve options */
memcpy(lf, of, sizeof(LEX));
- Dmsg1(49, "Restart scan of cfg file %s\n", of->fname);
+ Dmsg1(900, "Restart scan of cfg file %s\n", of->fname);
} else {
of = lf;
lf = NULL;
Emsg2(M_ERROR_TERM, 0, _("Cannot open config file %s: %s\n"),
fname, strerror(errno));
}
- Dmsg1(49, "Open config file: %s\n", fname);
+ Dmsg1(900, "Open config file: %s\n", fname);
nf = (LEX *)malloc(sizeof(LEX));
if (lf) {
memcpy(nf, lf, sizeof(LEX));
} else {
lf->scan_error = s_err;
}
- Dmsg1(49, "Return lex=%x\n", lf);
+ Dmsg1(900, "Return lex=%x\n", lf);
return lf;
}
{
if (lf->str_len >= MAXSTRING-3) {
Emsg3(M_ERROR_TERM, 0, _(
- "Token too long, file: %s, line %d, begins at line %d\n"),
+ _("Config token too long, file: %s, line %d, begins at line %d\n")),
lf->fname, lf->line_no, lf->begin_line_no);
}
lf->str[lf->str_len++] = ch;
static char *lex_state_to_str(int state)
{
switch (state) {
- case lex_none: return "none";
- case lex_comment: return "comment";
- case lex_number: return "number";
- case lex_ip_addr: return "ip_addr";
- case lex_identifier: return "identifier";
- case lex_string: return "string";
- case lex_quoted_string: return "quoted_string";
- default: return "??????";
+ case lex_none: return "none";
+ case lex_comment: return "comment";
+ case lex_number: return "number";
+ case lex_ip_addr: return "ip_addr";
+ case lex_identifier: return "identifier";
+ case lex_string: return "string";
+ case lex_quoted_string: return "quoted_string";
+ default: return "??????";
}
}
#endif
char *lex_tok_to_str(int token)
{
switch(token) {
- case L_EOF: return "L_EOF";
- case L_EOL: return "L_EOL";
- case T_NONE: return "T_NONE";
- case T_NUMBER: return "T_NUMBER";
- case T_IPADDR: return "T_IPADDR";
- case T_IDENTIFIER: return "T_IDENTIFIER";
- case T_UNQUOTED_STRING: return "T_UNQUOTED_STRING";
- case T_QUOTED_STRING: return "T_QUOTED_STRING";
- case T_BOB: return "T_BOB";
- case T_EOB: return "T_EOB";
- case T_EQUALS: return "T_EQUALS";
- case T_ERROR: return "T_ERROR";
- case T_EOF: return "T_EOF";
- case T_COMMA: return "T_COMMA";
- case T_EOL: return "T_EOL";
- default: return "??????";
+ case L_EOF: return "L_EOF";
+ case L_EOL: return "L_EOL";
+ case T_NONE: return "T_NONE";
+ case T_NUMBER: return "T_NUMBER";
+ case T_IPADDR: return "T_IPADDR";
+ case T_IDENTIFIER: return "T_IDENTIFIER";
+ case T_UNQUOTED_STRING: return "T_UNQUOTED_STRING";
+ case T_QUOTED_STRING: return "T_QUOTED_STRING";
+ case T_BOB: return "T_BOB";
+ case T_EOB: return "T_EOB";
+ case T_EQUALS: return "T_EQUALS";
+ case T_ERROR: return "T_ERROR";
+ case T_EOF: return "T_EOF";
+ case T_COMMA: return "T_COMMA";
+ case T_EOL: return "T_EOL";
+ default: return "??????";
}
}
static uint32_t scan_pint(LEX *lf, char *str)
{
- double dval = 0;
+ int64_t val = 0;
if (!is_a_number(str)) {
scan_err1(lf, "expected a positive integer number, got: %s", str);
/* NOT REACHED */
} else {
errno = 0;
- dval = strtod(str, NULL);
- if (errno != 0 || dval < 0) {
+ val = str_to_int64(str);
+ if (errno != 0 || val < 0) {
scan_err1(lf, "expected a postive integer number, got: %s", str);
/* NOT REACHED */
}
}
- return (uint32_t)dval;
+ return (uint32_t)val;
}
/*
int token = T_NONE;
int esc_next = FALSE;
- Dmsg0(290, "enter lex_get_token\n");
+ Dmsg0(900, "enter lex_get_token\n");
while (token == T_NONE) {
ch = lex_get_char(lf);
switch (lf->state) {
- case lex_none:
- Dmsg2(290, "Lex state lex_none ch=%d,%x\n", ch, ch);
- if (B_ISSPACE(ch))
- break;
- if (B_ISALPHA(ch)) {
- if (lf->options & LOPT_NO_IDENT)
- lf->state = lex_string;
- else
- lf->state = lex_identifier;
- begin_str(lf, ch);
- break;
- }
- if (B_ISDIGIT(ch)) {
- lf->state = lex_number;
- begin_str(lf, ch);
- break;
- }
- Dmsg0(290, "Enter lex_none switch\n");
- switch (ch) {
- case L_EOF:
- token = T_EOF;
- Dmsg0(290, "got L_EOF set token=T_EOF\n");
- break;
- case '#':
- lf->state = lex_comment;
- break;
- case '{':
- token = T_BOB;
- begin_str(lf, ch);
- break;
- case '}':
- token = T_EOB;
- begin_str(lf, ch);
- break;
- case '"':
- lf->state = lex_quoted_string;
- begin_str(lf, 0);
- break;
- case '=':
- token = T_EQUALS;
- begin_str(lf, ch);
- break;
- case ',':
- token = T_COMMA;
- begin_str(lf, ch);
- break;
- case ';':
- token = T_EOL; /* treat ; like EOL */
- break;
- case L_EOL:
- Dmsg0(290, "got L_EOL set token=T_EOL\n");
- token = T_EOL;
- break;
- case '@':
- lf->state = lex_include;
- begin_str(lf, 0);
- break;
- default:
- lf->state = lex_string;
- begin_str(lf, ch);
- break;
- }
+ case lex_none:
+ Dmsg2(900, "Lex state lex_none ch=%d,%x\n", ch, ch);
+ if (B_ISSPACE(ch))
break;
- case lex_comment:
- Dmsg1(290, "Lex state lex_comment ch=%x\n", ch);
- if (ch == L_EOL) {
- lf->state = lex_none;
- token = T_EOL;
- } else if (ch == L_EOF) {
- token = T_ERROR;
- }
- break;
- case lex_number:
- Dmsg2(290, "Lex state lex_number ch=%x %c\n", ch, ch);
- if (ch == L_EOF) {
- token = T_ERROR;
- break;
- }
- /* Might want to allow trailing specifications here */
- if (B_ISDIGIT(ch)) {
- add_str(lf, ch);
- break;
- }
-
- /* A valid number can be terminated by the following */
- if (B_ISSPACE(ch) || ch == L_EOL || ch == ',' || ch == ';') {
- token = T_NUMBER;
- lf->state = lex_none;
- } else {
+ if (B_ISALPHA(ch)) {
+ if (lf->options & LOPT_NO_IDENT)
lf->state = lex_string;
- }
- lex_unget_char(lf);
+ else
+ lf->state = lex_identifier;
+ begin_str(lf, ch);
break;
- case lex_ip_addr:
- if (ch == L_EOF) {
- token = T_ERROR;
- break;
- }
- Dmsg1(290, "Lex state lex_ip_addr ch=%x\n", ch);
+ }
+ if (B_ISDIGIT(ch)) {
+ lf->state = lex_number;
+ begin_str(lf, ch);
break;
- case lex_string:
- Dmsg1(290, "Lex state lex_string ch=%x\n", ch);
- if (ch == L_EOF) {
- token = T_ERROR;
- break;
- }
- if (ch == '\n' || ch == L_EOL || ch == '=' || ch == '}' || ch == '{' ||
- ch == ';' || ch == ',' || ch == '#' || (B_ISSPACE(ch)) ) {
- lex_unget_char(lf);
- token = T_UNQUOTED_STRING;
- lf->state = lex_none;
- break;
- }
- add_str(lf, ch);
+ }
+ Dmsg0(900, "Enter lex_none switch\n");
+ switch (ch) {
+ case L_EOF:
+ token = T_EOF;
+ Dmsg0(900, "got L_EOF set token=T_EOF\n");
+ break;
+ case '#':
+ lf->state = lex_comment;
+ break;
+ case '{':
+ token = T_BOB;
+ begin_str(lf, ch);
+ break;
+ case '}':
+ token = T_EOB;
+ begin_str(lf, ch);
+ break;
+ case '"':
+ lf->state = lex_quoted_string;
+ begin_str(lf, 0);
break;
- case lex_identifier:
- Dmsg2(290, "Lex state lex_identifier ch=%x %c\n", ch, ch);
- if (B_ISALPHA(ch)) {
- add_str(lf, ch);
- break;
- } else if (B_ISSPACE(ch)) {
- break;
- } else if (ch == '\n' || ch == L_EOL || ch == '=' || ch == '}' || ch == '{' ||
- ch == ';' || ch == ',' || ch == '"' || ch == '#') {
- lex_unget_char(lf);
- token = T_IDENTIFIER;
- lf->state = lex_none;
- break;
- } else if (ch == L_EOF) {
- token = T_ERROR;
- lf->state = lex_none;
- begin_str(lf, ch);
- break;
- }
- /* Some non-alpha character => string */
+ case '=':
+ token = T_EQUALS;
+ begin_str(lf, ch);
+ break;
+ case ',':
+ token = T_COMMA;
+ begin_str(lf, ch);
+ break;
+ case ';':
+ token = T_EOL; /* treat ; like EOL */
+ break;
+ case L_EOL:
+ Dmsg0(900, "got L_EOL set token=T_EOL\n");
+ token = T_EOL;
+ break;
+ case '@':
+ lf->state = lex_include;
+ begin_str(lf, 0);
+ break;
+ default:
lf->state = lex_string;
+ begin_str(lf, ch);
+ break;
+ }
+ break;
+ case lex_comment:
+ Dmsg1(900, "Lex state lex_comment ch=%x\n", ch);
+ if (ch == L_EOL) {
+ lf->state = lex_none;
+ token = T_EOL;
+ } else if (ch == L_EOF) {
+ token = T_ERROR;
+ }
+ break;
+ case lex_number:
+ Dmsg2(900, "Lex state lex_number ch=%x %c\n", ch, ch);
+ if (ch == L_EOF) {
+ token = T_ERROR;
+ break;
+ }
+ /* Might want to allow trailing specifications here */
+ if (B_ISDIGIT(ch)) {
add_str(lf, ch);
break;
- case lex_quoted_string:
- Dmsg2(290, "Lex state lex_quoted_string ch=%x %c\n", ch, ch);
- if (ch == L_EOF) {
- token = T_ERROR;
- break;
- }
- if (ch == L_EOL) {
- esc_next = FALSE;
- break;
- }
- if (esc_next) {
- add_str(lf, ch);
- esc_next = FALSE;
- break;
- }
- if (ch == '\\') {
- esc_next = TRUE;
- break;
- }
- if (ch == '"') {
- token = T_QUOTED_STRING;
- lf->state = lex_none;
- break;
- }
+ }
+
+ /* A valid number can be terminated by the following */
+ if (B_ISSPACE(ch) || ch == L_EOL || ch == ',' || ch == ';') {
+ token = T_NUMBER;
+ lf->state = lex_none;
+ } else {
+ lf->state = lex_string;
+ }
+ lex_unget_char(lf);
+ break;
+ case lex_ip_addr:
+ if (ch == L_EOF) {
+ token = T_ERROR;
+ break;
+ }
+ Dmsg1(900, "Lex state lex_ip_addr ch=%x\n", ch);
+ break;
+ case lex_string:
+ Dmsg1(900, "Lex state lex_string ch=%x\n", ch);
+ if (ch == L_EOF) {
+ token = T_ERROR;
+ break;
+ }
+ if (ch == '\n' || ch == L_EOL || ch == '=' || ch == '}' || ch == '{' ||
+ ch == '\r' || ch == ';' || ch == ',' || ch == '#' || (B_ISSPACE(ch)) ) {
+ lex_unget_char(lf);
+ token = T_UNQUOTED_STRING;
+ lf->state = lex_none;
+ break;
+ }
+ add_str(lf, ch);
+ break;
+ case lex_identifier:
+ Dmsg2(900, "Lex state lex_identifier ch=%x %c\n", ch, ch);
+ if (B_ISALPHA(ch)) {
add_str(lf, ch);
break;
- case lex_include: /* scanning a filename */
- if (ch == L_EOF) {
- token = T_ERROR;
- break;
- }
- if (B_ISSPACE(ch) || ch == '\n' || ch == L_EOL || ch == '}' || ch == '{' ||
- ch == ';' || ch == ',' || ch == '"' || ch == '#') {
- lf->state = lex_none;
- lf = lex_open_file(lf, lf->str, NULL);
- break;
- }
+ } else if (B_ISSPACE(ch)) {
+ break;
+ } else if (ch == '\n' || ch == L_EOL || ch == '=' || ch == '}' || ch == '{' ||
+ ch == '\r' || ch == ';' || ch == ',' || ch == '"' || ch == '#') {
+ lex_unget_char(lf);
+ token = T_IDENTIFIER;
+ lf->state = lex_none;
+ break;
+ } else if (ch == L_EOF) {
+ token = T_ERROR;
+ lf->state = lex_none;
+ begin_str(lf, ch);
+ break;
+ }
+ /* Some non-alpha character => string */
+ lf->state = lex_string;
+ add_str(lf, ch);
+ break;
+ case lex_quoted_string:
+ Dmsg2(900, "Lex state lex_quoted_string ch=%x %c\n", ch, ch);
+ if (ch == L_EOF) {
+ token = T_ERROR;
+ break;
+ }
+ if (ch == L_EOL) {
+ esc_next = FALSE;
+ break;
+ }
+ if (esc_next) {
add_str(lf, ch);
+ esc_next = FALSE;
+ break;
+ }
+ if (ch == '\\') {
+ esc_next = TRUE;
break;
+ }
+ if (ch == '"') {
+ token = T_QUOTED_STRING;
+ lf->state = lex_none;
+ break;
+ }
+ add_str(lf, ch);
+ break;
+ case lex_include: /* scanning a filename */
+ if (ch == L_EOF) {
+ token = T_ERROR;
+ break;
+ }
+ if (B_ISSPACE(ch) || ch == '\n' || ch == L_EOL || ch == '}' || ch == '{' ||
+ ch == ';' || ch == ',' || ch == '"' || ch == '#') {
+ lf->state = lex_none;
+ lf = lex_open_file(lf, lf->str, NULL);
+ break;
+ }
+ add_str(lf, ch);
+ break;
}
- Dmsg4(290, "ch=%d state=%s token=%s %c\n", ch, lex_state_to_str(lf->state),
+ Dmsg4(900, "ch=%d state=%s token=%s %c\n", ch, lex_state_to_str(lf->state),
lex_tok_to_str(token), ch);
}
- Dmsg2(290, "lex returning: line %d token: %s\n", lf->line_no, lex_tok_to_str(token));
+ Dmsg2(900, "lex returning: line %d token: %s\n", lf->line_no, lex_tok_to_str(token));
lf->token = token;
/*
break;
}
errno = 0;
- lf->int32_val = (int32_t)strtod(lf->str, NULL);
+ lf->int32_val = (int32_t)str_to_int64(lf->str);
if (errno != 0) {
scan_err2(lf, "expected an integer number, got %s: %s",
lex_tok_to_str(token), lf->str);
break;
case T_INT64:
- Dmsg2(400, "int64=:%s: %f\n", lf->str, strtod(lf->str, NULL));
+ Dmsg2(900, "int64=:%s: %f\n", lf->str, strtod(lf->str, NULL));
if (token != T_NUMBER || !is_a_number(lf->str)) {
scan_err2(lf, "expected an integer number, got %s: %s",
lex_tok_to_str(token), lf->str);
break;
}
errno = 0;
- lf->int64_val = (int64_t)strtod(lf->str, NULL);
+ lf->int64_val = str_to_int64(lf->str);
if (errno != 0) {
scan_err2(lf, "expected an integer number, got %s: %s",
lex_tok_to_str(token), lf->str);
scan_err3(lf, "name %s length %d too long, max is %d\n", lf->str,
lf->str_len, MAX_RES_NAME_LENGTH);
token = T_ERROR;
- } else {
- token = T_NAME;
}
break;