* Version $Id$
*
*/
-
/*
- Copyright (C) 2000-2005 Kern Sibbald
+ Copyright (C) 2000-2006 Kern Sibbald
This program is free software; you can redistribute it and/or
- modify it under the terms of the GNU General Public License as
- published by the Free Software Foundation; either version 2 of
- the License, or (at your option) any later version.
+ modify it under the terms of the GNU General Public License
+ version 2 as amended with additional clauses defined in the
+ file LICENSE in the main source directory.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- General Public License for more details.
-
- You should have received a copy of the GNU General Public
- License along with this program; if not, write to the Free
- Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
- MA 02111-1307, USA.
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ the file LICENSE for additional details.
*/
+
#include "bacula.h"
#include "lex.h"
extern int debug_level;
+/* Debug level for this source file */
+static const int dbglvl = 5000;
+
/*
* Scan to "logical" end of line. I.e. end of line,
* or semicolon, but stop on T_EOB (same as end of
void scan_to_eol(LEX *lc)
{
int token;
- Dmsg0(2000, "start scan to eof\n");
+ Dmsg0(dbglvl, "start scan to eof\n");
while ((token = lex_get_token(lc, T_ALL)) != T_EOL) {
if (token == T_EOB) {
lex_unget_char(lc);
bvsnprintf(buf, sizeof(buf), msg, arg_ptr);
va_end(arg_ptr);
- if (lc->err_type == 0) { /* M_ERROR_TERM by default */
+ if (lc->err_type == 0) { /* M_ERROR_TERM by default */
lc->err_type = M_ERROR_TERM;
}
if (lf == NULL) {
Emsg0(M_ABORT, 0, _("Close of NULL file\n"));
}
- Dmsg1(2000, "Close lex file: %s\n", lf->fname);
+ Dmsg1(dbglvl, "Close lex file: %s\n", lf->fname);
of = lf->next;
fclose(lf->fd);
- Dmsg1(2000, "Close cfg file %s\n", lf->fname);
+ Dmsg1(dbglvl, "Close cfg file %s\n", lf->fname);
free(lf->fname);
if (of) {
of->options = lf->options; /* preserve options */
memcpy(lf, of, sizeof(LEX));
- Dmsg1(2000, "Restart scan of cfg file %s\n", of->fname);
+ Dmsg1(dbglvl, "Restart scan of cfg file %s\n", of->fname);
} else {
of = lf;
lf = NULL;
char *fname = bstrdup(filename);
- if ((fd = fopen(fname, "r")) == NULL) {
+ if ((fd = fopen(fname, "rb")) == NULL) {
return NULL;
}
Dmsg1(400, "Open config file: %s\n", fname);
lf->fname = fname;
lf->state = lex_none;
lf->ch = L_EOL;
- Dmsg1(2000, "Return lex=%x\n", lf);
+ Dmsg1(dbglvl, "Return lex=%x\n", lf);
return lf;
}
} else {
lf->col_no++;
}
- Dmsg2(2000, "lex_get_char: %c %d\n", lf->ch, lf->ch);
+ Dmsg2(dbglvl, "lex_get_char: %c %d\n", lf->ch, lf->ch);
return lf->ch;
}
void lex_unget_char(LEX *lf)
{
- lf->col_no--;
- if (lf->ch == L_EOL)
- lf->ch = 0;
+ if (lf->ch == L_EOL) {
+ lf->ch = 0; /* End of line, force read of next one */
+ } else {
+ lf->col_no--; /* Backup to re-read char */
+ }
+
}
int token = T_NONE;
bool esc_next = false;
- Dmsg0(2000, "enter lex_get_token\n");
+ Dmsg0(dbglvl, "enter lex_get_token\n");
while (token == T_NONE) {
ch = lex_get_char(lf);
switch (lf->state) {
case lex_none:
- Dmsg2(2000, "Lex state lex_none ch=%d,%x\n", ch, ch);
+ Dmsg2(dbglvl, "Lex state lex_none ch=%d,%x\n", ch, ch);
if (B_ISSPACE(ch))
break;
if (B_ISALPHA(ch)) {
begin_str(lf, ch);
break;
}
- Dmsg0(2000, "Enter lex_none switch\n");
+ Dmsg0(dbglvl, "Enter lex_none switch\n");
switch (ch) {
case L_EOF:
token = T_EOF;
- Dmsg0(2000, "got L_EOF set token=T_EOF\n");
+ Dmsg0(dbglvl, "got L_EOF set token=T_EOF\n");
break;
case '#':
lf->state = lex_comment;
}
break;
case L_EOL:
- Dmsg0(2000, "got L_EOL set token=T_EOL\n");
+ Dmsg0(dbglvl, "got L_EOL set token=T_EOL\n");
if (expect != T_SKIP_EOL) {
token = T_EOL;
}
}
break;
case lex_comment:
- Dmsg1(2000, "Lex state lex_comment ch=%x\n", ch);
+ Dmsg1(dbglvl, "Lex state lex_comment ch=%x\n", ch);
if (ch == L_EOL) {
lf->state = lex_none;
if (expect != T_SKIP_EOL) {
}
break;
case lex_number:
- Dmsg2(2000, "Lex state lex_number ch=%x %c\n", ch, ch);
+ Dmsg2(dbglvl, "Lex state lex_number ch=%x %c\n", ch, ch);
if (ch == L_EOF) {
token = T_ERROR;
break;
token = T_ERROR;
break;
}
- Dmsg1(2000, "Lex state lex_ip_addr ch=%x\n", ch);
+ Dmsg1(dbglvl, "Lex state lex_ip_addr ch=%x\n", ch);
break;
case lex_string:
- Dmsg1(2000, "Lex state lex_string ch=%x\n", ch);
+ Dmsg1(dbglvl, "Lex state lex_string ch=%x\n", ch);
if (ch == L_EOF) {
token = T_ERROR;
break;
add_str(lf, ch);
break;
case lex_identifier:
- Dmsg2(2000, "Lex state lex_identifier ch=%x %c\n", ch, ch);
+ Dmsg2(dbglvl, "Lex state lex_identifier ch=%x %c\n", ch, ch);
if (B_ISALPHA(ch)) {
add_str(lf, ch);
break;
add_str(lf, ch);
break;
case lex_quoted_string:
- Dmsg2(2000, "Lex state lex_quoted_string ch=%x %c\n", ch, ch);
+ Dmsg2(dbglvl, "Lex state lex_quoted_string ch=%x %c\n", ch, ch);
if (ch == L_EOF) {
token = T_ERROR;
break;
add_str(lf, ch);
break;
}
- Dmsg4(2000, "ch=%d state=%s token=%s %c\n", ch, lex_state_to_str(lf->state),
+ Dmsg4(dbglvl, "ch=%d state=%s token=%s %c\n", ch, lex_state_to_str(lf->state),
lex_tok_to_str(token), ch);
}
- Dmsg2(2000, "lex returning: line %d token: %s\n", lf->line_no, lex_tok_to_str(token));
+ Dmsg2(dbglvl, "lex returning: line %d token: %s\n", lf->line_no, lex_tok_to_str(token));
lf->token = token;
/*
break;
case T_INT64:
- Dmsg2(2000, "int64=:%s: %f\n", lf->str, strtod(lf->str, NULL));
+ Dmsg2(dbglvl, "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);