- case lex_none:
- Dmsg2(290, "Lex state lex_none ch=%d,%x\n", ch, ch);
- if (ISSPACE(ch))
- break;
- if (ISALPHA(ch)) {
- if (lf->options & LOPT_NO_IDENT)
- lf->state = lex_string;
- else
- lf->state = lex_identifier;
- begin_str(lf, ch);
- break;
- }
- if (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;
- }
- 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;
- }
- break;
- 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)) {
- add_str(lf, ch);
- break;
- }
-
- /* A valid number can be terminated by the following */
- if (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:
- Dmsg1(290, "Lex state lex_ip_addr ch=%x\n", ch);
- break;
- 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)) ) {
- lex_unget_char(lf);
- token = T_UNQUOTED_STRING;
- lf->state = lex_none;
- break;
- }
- add_str(lf, ch);
- break;
- case lex_identifier:
- Dmsg2(290, "Lex state lex_identifier ch=%x %c\n", ch, ch);
- if (ISALPHA(ch)) {
- add_str(lf, ch);
- break;
- } else if (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 */
- lf->state = lex_string;
- 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_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 (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;
+ case lex_none:
+ Dmsg2(dbglvl, "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->options & LOPT_STRING) {
+ lf->state = lex_string;
+ } else {
+ lf->state = lex_identifier;
+ }
+ begin_str(lf, ch);
+ break;
+ }
+ if (B_ISDIGIT(ch)) {
+ if (lf->options & LOPT_STRING) {
+ lf->state = lex_string;
+ } else {
+ lf->state = lex_number;
+ }
+ begin_str(lf, ch);
+ break;
+ }
+ Dmsg0(dbglvl, "Enter lex_none switch\n");
+ switch (ch) {
+ case L_EOF:
+ token = T_EOF;
+ Dmsg0(dbglvl, "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 ';':
+ if (expect != T_SKIP_EOL) {
+ token = T_EOL; /* treat ; like EOL */
+ }
+ break;
+ case L_EOL:
+ Dmsg0(dbglvl, "got L_EOL set token=T_EOL\n");
+ if (expect != T_SKIP_EOL) {
+ token = T_EOL;
+ }
+ break;
+ case '@':
+ lf->state = lex_include;
+ begin_str(lf, 0);
+ break;
+ case 0xEF: /* probably a UTF-8 BOM */
+ case 0xFF: /* probably a UTF-16le BOM */
+ case 0xFE: /* probably a UTF-16be BOM (error)*/
+ if (lf->line_no != 1 || lf->col_no != 1)
+ {
+ lf->state = lex_string;
+ begin_str(lf, ch);
+ } else {
+ bom_bytes_seen = 1;
+ if (ch == 0xEF) {
+ lf->state = lex_utf8_bom;
+ } else if (ch == 0xFF) {
+ lf->state = lex_utf16_le_bom;
+ } else {
+ scan_err0(lf, _("This config file appears to be in an "
+ "unsupported Unicode format (UTF-16be). Please resave as UTF-8\n"));
+ return T_ERROR;
+ }
+ }
+ break;
+ default:
+ lf->state = lex_string;
+ begin_str(lf, ch);
+ break;
+ }
+ break;
+ case lex_comment:
+ Dmsg1(dbglvl, "Lex state lex_comment ch=%x\n", ch);
+ if (ch == L_EOL) {
+ lf->state = lex_none;
+ if (expect != T_SKIP_EOL) {
+ token = T_EOL;
+ }
+ } else if (ch == L_EOF) {
+ token = T_ERROR;
+ }
+ break;
+ case lex_number:
+ Dmsg2(dbglvl, "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 {
+ lf->state = lex_string;
+ }
+ lex_unget_char(lf);
+ break;
+ case lex_ip_addr:
+ if (ch == L_EOF) {
+ token = T_ERROR;
+ break;
+ }
+ Dmsg1(dbglvl, "Lex state lex_ip_addr ch=%x\n", ch);
+ break;
+ case lex_string:
+ Dmsg1(dbglvl, "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(dbglvl, "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 == '\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(dbglvl, "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_quoted_string:
+ if (ch == L_EOF) {
+ token = T_ERROR;
+ break;
+ }
+ if (esc_next) {
+ add_str(lf, ch);
+ esc_next = false;
+ break;
+ }
+ if (ch == '\\') {
+ esc_next = true;
+ break;
+ }
+ if (ch == '"') {
+ /* Keep the original LEX so we can print an error if the included file can't be opened. */
+ LEX* lfori = lf;
+ /* Skip the double quote when restarting parsing */
+ lex_get_char(lf);
+
+ lf->state = lex_none;
+ lf = lex_open_file(lf, lf->str, lf->scan_error);
+ if (lf == NULL) {
+ berrno be;
+ scan_err2(lfori, _("Cannot open included config file %s: %s\n"),
+ lfori->str, be.bstrerror());
+ return T_ERROR;
+ }
+ break;
+ }
+ add_str(lf, ch);
+ break;
+ case lex_include: /* scanning a filename */
+ if (ch == L_EOF) {
+ token = T_ERROR;
+ break;
+ }
+ if (ch == '"') {
+ lf->state = lex_include_quoted_string;
+ break;
+ }
+
+
+ if (B_ISSPACE(ch) || ch == '\n' || ch == L_EOL || ch == '}' || ch == '{' ||
+ ch == ';' || ch == ',' || ch == '"' || ch == '#') {
+ /* Keep the original LEX so we can print an error if the included file can't be opened. */
+ LEX* lfori = lf;
+
+ lf->state = lex_none;
+ lf = lex_open_file(lf, lf->str, lf->scan_error);
+ if (lf == NULL) {
+ berrno be;
+ scan_err2(lfori, _("Cannot open included config file %s: %s\n"),
+ lfori->str, be.bstrerror());
+ return T_ERROR;
+ }
+ break;
+ }
+ add_str(lf, ch);
+ break;
+ case lex_utf8_bom:
+ /* we only end up in this state if we have read an 0xEF
+ as the first byte of the file, indicating we are probably
+ reading a UTF-8 file */
+ if (ch == 0xBB && bom_bytes_seen == 1) {
+ bom_bytes_seen++;
+ } else if (ch == 0xBF && bom_bytes_seen == 2) {
+ token = T_UTF8_BOM;
+ lf->state = lex_none;
+ } else {
+ token = T_ERROR;
+ }
+ break;
+ case lex_utf16_le_bom:
+ /* we only end up in this state if we have read an 0xFF
+ as the first byte of the file -- indicating that we are
+ probably dealing with an Intel based (little endian) UTF-16 file*/
+ if (ch == 0xFE) {
+ token = T_UTF16_BOM;
+ lf->state = lex_none;
+ } else {
+ token = T_ERROR;
+ }
+ break;