X-Git-Url: https://git.sur5r.net/?a=blobdiff_plain;ds=sidebyside;f=bacula%2Fsrc%2Flib%2Flex.c;h=6e9118d054cbb383a36a4aa1af4d69280f54ad52;hb=82151d934f8b46ff7133b084808f288c81edd372;hp=c98766d310b9feb1502dc82b669dbb6eb346c858;hpb=e53be911eaed3564909002be3995d5106d25f4ef;p=bacula%2Fbacula diff --git a/bacula/src/lib/lex.c b/bacula/src/lib/lex.c index c98766d310..6e9118d054 100644 --- a/bacula/src/lib/lex.c +++ b/bacula/src/lib/lex.c @@ -50,14 +50,20 @@ static void s_err(char *file, int line, LEX *lc, char *msg, ...) { va_list arg_ptr; char buf[MAXSTRING]; + char more[MAXSTRING]; va_start(arg_ptr, msg); bvsnprintf(buf, sizeof(buf), msg, arg_ptr); va_end(arg_ptr); - e_msg(file, line, M_ERROR_TERM, 0, "Config error: %s\n\ - : Line %d, col %d of file %s\n%s\n", - buf, lc->line_no, lc->col_no, lc->fname, lc->line); + if (lc->line_no > lc->begin_line_no) { + sprintf(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"), + buf, lc->line_no, lc->col_no, lc->fname, lc->line, more); } @@ -70,18 +76,18 @@ lex_close_file(LEX *lf) { LEX *of; - Dmsg1(20, "Close lex file: %s\n", lf->fname); + Dmsg1(40, "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(29, "Close cfg file %s\n", lf->fname); + Dmsg1(49, "Close cfg file %s\n", lf->fname); free(lf->fname); if (of) { of->options = lf->options; /* preserve options */ memcpy(lf, of, sizeof(LEX)); - Dmsg1(29, "Restart scan of cfg file %s\n", of->fname); + Dmsg1(49, "Restart scan of cfg file %s\n", of->fname); } else { of = lf; lf = NULL; @@ -111,9 +117,10 @@ lex_open_file(LEX *lf, char *filename, LEX_ERROR_HANDLER *scan_error) if ((fd = fopen(fname, "r")) == NULL) { - Emsg2(M_ABORT, 0, "Cannot open config file %s: %s\n", fname, strerror(errno)); + Emsg2(M_ERROR_TERM, 0, _("Cannot open config file %s: %s\n"), + fname, strerror(errno)); } - Dmsg1(29, "Open config file: %s\n", fname); + Dmsg1(49, "Open config file: %s\n", fname); nf = (LEX *)malloc(sizeof(LEX)); if (lf) { memcpy(nf, lf, sizeof(LEX)); @@ -133,7 +140,7 @@ lex_open_file(LEX *lf, char *filename, LEX_ERROR_HANDLER *scan_error) } else { lf->scan_error = s_err; } - Dmsg1(29, "Return lex=%x\n", lf); + Dmsg1(49, "Return lex=%x\n", lf); return lf; } @@ -184,7 +191,9 @@ lex_unget_char(LEX *lf) static void add_str(LEX *lf, int ch) { if (lf->str_len >= MAXSTRING-3) { - Emsg2(M_ABORT, 0, "Token too long, file: %s, line %s\n", lf->fname, lf->line_no); + Emsg3(M_ERROR_TERM, 0, _( + "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; lf->str[lf->str_len] = 0; @@ -197,8 +206,10 @@ static void begin_str(LEX *lf, int ch) { lf->str_len = 0; lf->str[0] = 0; - if (ch != 0) + if (ch != 0) { add_str(lf, ch); + } + lf->begin_line_no = lf->line_no; /* save start string line no */ } #ifdef DEBUG @@ -247,14 +258,16 @@ lex_tok_to_str(int token) static uint32_t scan_pint(LEX *lf, char *str) { - double dval; + double dval = 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) { scan_err1(lf, "expected a postive integer number, got: %s", str); + /* NOT REACHED */ } } return (uint32_t)dval; @@ -278,9 +291,9 @@ lex_get_token(LEX *lf, int expect) switch (lf->state) { case lex_none: Dmsg2(290, "Lex state lex_none ch=%d,%x\n", ch, ch); - if (ISSPACE(ch)) + if (B_ISSPACE(ch)) break; - if (ISALPHA(ch)) { + if (B_ISALPHA(ch)) { if (lf->options & LOPT_NO_IDENT) lf->state = lex_string; else @@ -288,7 +301,7 @@ lex_get_token(LEX *lf, int expect) begin_str(lf, ch); break; } - if (ISDIGIT(ch)) { + if (B_ISDIGIT(ch)) { lf->state = lex_number; begin_str(lf, ch); break; @@ -349,13 +362,13 @@ lex_get_token(LEX *lf, int expect) case lex_number: Dmsg2(290, "Lex state lex_number ch=%x %c\n", ch, ch); /* Might want to allow trailing specifications here */ - if (ISDIGIT(ch)) { + if (B_ISDIGIT(ch)) { add_str(lf, ch); break; } /* A valid number can be terminated by the following */ - if (ISSPACE(ch) || ch == L_EOL || ch == ',' || ch == ';') { + if (B_ISSPACE(ch) || ch == L_EOL || ch == ',' || ch == ';') { token = T_NUMBER; lf->state = lex_none; } else { @@ -369,7 +382,7 @@ lex_get_token(LEX *lf, int expect) case lex_string: Dmsg1(290, "Lex state lex_string ch=%x\n", ch); if (ch == '\n' || ch == L_EOL || ch == '=' || ch == '}' || ch == '{' || - ch == ';' || ch == ',' || ch == '#' || (ISSPACE(ch)) ) { + ch == ';' || ch == ',' || ch == '#' || (B_ISSPACE(ch)) ) { lex_unget_char(lf); token = T_UNQUOTED_STRING; lf->state = lex_none; @@ -379,10 +392,10 @@ lex_get_token(LEX *lf, int expect) break; case lex_identifier: Dmsg2(290, "Lex state lex_identifier ch=%x %c\n", ch, ch); - if (ISALPHA(ch)) { + if (B_ISALPHA(ch)) { add_str(lf, ch); break; - } else if (ISSPACE(ch)) { + } else if (B_ISSPACE(ch)) { break; } else if (ch == '\n' || ch == L_EOL || ch == '=' || ch == '}' || ch == '{' || ch == ';' || ch == ',' || ch == '"' || ch == '#') { @@ -423,7 +436,7 @@ lex_get_token(LEX *lf, int expect) add_str(lf, ch); break; case lex_include: /* scanning a filename */ - if (ISSPACE(ch) || ch == '\n' || ch == L_EOL || ch == '}' || ch == '{' || + 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);