]> git.sur5r.net Git - bacula/bacula/blobdiff - bacula/src/lib/lex.c
Win32 BackupRead/Write, begin adding Base, Jmsg knows about console, autochanger...
[bacula/bacula] / bacula / src / lib / lex.c
index d1c94f26eee3500f961d7adb57b61dd09529cf17..88dcfe1b4e7cd7bb885d86c4e175854fd15dd4c1 100644 (file)
@@ -71,8 +71,7 @@ static void s_err(char *file, int line, LEX *lc, char *msg, ...)
  * Free the current file, and retrieve the contents
  * of the previous packet if any.
  */
-LEX *
-lex_close_file(LEX *lf)
+LEX *lex_close_file(LEX *lf)
 {
    LEX *of;
 
@@ -107,8 +106,7 @@ lex_close_file(LEX *lf)
  * the next field.
  *
  */
-LEX *
-lex_open_file(LEX *lf, char *filename, LEX_ERROR_HANDLER *scan_error) 
+LEX *lex_open_file(LEX *lf, char *filename, LEX_ERROR_HANDLER *scan_error) 
              
 {
    LEX *nf;
@@ -150,11 +148,11 @@ lex_open_file(LEX *lf, char *filename, LEX_ERROR_HANDLER *scan_error)
  *    L_EOF if end of file
  *    L_EOL if end of line
  */
-int
-lex_get_char(LEX *lf)
+int lex_get_char(LEX *lf)
 {
-   if (lf->ch == L_EOF)
+   if (lf->ch == L_EOF) {
       Emsg0(M_ABORT, 0, "get_char: called after EOF\n");
+   }
    if (lf->ch == L_EOL) {
       if (fgets(lf->line, MAXSTRING, lf->fd) == NULL) {
         lf->ch = L_EOF;
@@ -176,8 +174,7 @@ lex_get_char(LEX *lf)
    return lf->ch;
 }
 
-void
-lex_unget_char(LEX *lf)
+void lex_unget_char(LEX *lf)
 {
    lf->col_no--;      
    if (lf->ch == L_EOL)
@@ -213,8 +210,7 @@ static void begin_str(LEX *lf, int ch)
 }
 
 #ifdef DEBUG
-static char *
-lex_state_to_str(int state)
+static char *lex_state_to_str(int state)
 {
    switch (state) {
       case lex_none:          return "none";
@@ -233,8 +229,7 @@ lex_state_to_str(int state)
  * Convert a lex token to a string
  * used for debug/error printing.
  */
-char *
-lex_tok_to_str(int token)
+char *lex_tok_to_str(int token)
 {
    switch(token) {
       case L_EOF:             return "L_EOF";
@@ -291,9 +286,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
@@ -301,7 +296,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;
@@ -357,18 +352,24 @@ lex_get_token(LEX *lf, int expect)
            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 (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 {
@@ -377,12 +378,20 @@ lex_get_token(LEX *lf, int expect)
            lex_unget_char(lf);
            break;
         case lex_ip_addr:
+           if (ch == L_EOF) {
+              token = T_ERROR;
+              break;
+           }
             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 == L_EOF) {
+              token = T_ERROR;
+              break;
+           }
             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;
@@ -392,10 +401,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 == '#') {
@@ -415,6 +424,10 @@ lex_get_token(LEX *lf, int expect)
            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;
@@ -436,7 +449,11 @@ 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 (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);
@@ -536,7 +553,7 @@ lex_get_token(LEX *lf, int expect)
 
    case T_STRING:
       if (token != T_IDENTIFIER && token != T_UNQUOTED_STRING && token != T_QUOTED_STRING) {
-         scan_err2(lf, "expected a name, got %s: %s",
+         scan_err2(lf, "expected a string, got %s: %s",
               lex_tok_to_str(token), lf->str);
         token = T_ERROR;
       } else {