]> git.sur5r.net Git - bacula/bacula/commitdiff
Add start line for lex errors
authorKern Sibbald <kern@sibbald.com>
Tue, 17 Sep 2002 08:04:40 +0000 (08:04 +0000)
committerKern Sibbald <kern@sibbald.com>
Tue, 17 Sep 2002 08:04:40 +0000 (08:04 +0000)
git-svn-id: https://bacula.svn.sourceforge.net/svnroot/bacula/trunk@154 91ce42f0-d328-0410-95d8-f526ca767f89

bacula/src/lib/lex.c
bacula/src/lib/lex.h

index 85a3b3915df6781c2acef54b799403effde0de5b..d1c94f26eee3500f961d7adb57b61dd09529cf17 100644 (file)
@@ -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);
 }
 
 
@@ -185,7 +191,9 @@ lex_unget_char(LEX *lf)
 static void add_str(LEX *lf, int ch)
 {
    if (lf->str_len >= MAXSTRING-3) {
-      Emsg2(M_ERROR_TERM, 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;
@@ -198,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
index f73beed6152a7c793b16cb7a15d29dc8b721c20b..f063797be637268d2aa0ce3fa958b8302613e4bf 100644 (file)
 #define _LEX_H
 
 /* Lex get_char() return values */
-#define L_EOF                         (-1)
-#define L_EOL                         (-2)
+#define L_EOF                        (-1)
+#define L_EOL                        (-2)
 
 /* Internal tokens */
-#define T_NONE                        100                              
+#define T_NONE                       100                              
 
 /* Tokens returned by get_token() */
-#define T_EOF                         101
-#define T_NUMBER                      102
-#define T_IPADDR                      103
-#define T_IDENTIFIER                  104
-#define T_UNQUOTED_STRING             105
-#define T_QUOTED_STRING               106
-#define T_BOB                         108  /* begin block */
-#define T_EOB                         109  /* end of block */
-#define T_EQUALS                      110
-#define T_COMMA                       111
-#define T_EOL                         112
-#define T_SEMI                        113
-#define T_ERROR                       200
+#define T_EOF                        101
+#define T_NUMBER                     102
+#define T_IPADDR                     103
+#define T_IDENTIFIER                 104
+#define T_UNQUOTED_STRING            105
+#define T_QUOTED_STRING              106
+#define T_BOB                        108  /* begin block */
+#define T_EOB                        109  /* end of block */
+#define T_EQUALS                     110
+#define T_COMMA                      111
+#define T_EOL                        112
+#define T_SEMI                       113
+#define T_ERROR                      200
 /*
  * The following will be returned only if
  * the appropriate expect flag has been set   
  */
-#define T_PINT32                      114  /* positive integer */
-#define T_PINT32_RANGE                115  /* positive integer range */
-#define T_INT32                       116  /* integer */
-#define T_INT64                       117  /* 64 bit integer */
-#define T_NAME                        118  /* name max 128 chars */
-#define T_STRING                      119  /* string */
+#define T_PINT32                     114  /* positive integer */
+#define T_PINT32_RANGE               115  /* positive integer range */
+#define T_INT32                      116  /* integer */
+#define T_INT64                      117  /* 64 bit integer */
+#define T_NAME                       118  /* name max 128 chars */
+#define T_STRING                     119  /* string */
 
-#define T_ALL                           0  /* no expectations */
+#define T_ALL                          0  /* no expectations */
 
 /* Lexical state */
 enum lex_state {
@@ -78,28 +78,29 @@ enum lex_state {
 };
 
 /* Lex scan options */
-#define LOPT_NO_IDENT            0x1  /* No Identifiers -- use string */
+#define LOPT_NO_IDENT           0x1  /* No Identifiers -- use string */
 
 /* Lexical context */
 typedef struct s_lex_context {
-   struct s_lex_context *next;        /* pointer to next lexical context */
-   int options;                       /* scan options */
-   char *fname;                       /* filename */
-   FILE *fd;                          /* file descriptor */
-   char line[MAXSTRING];              /* input line */
-   char str[MAXSTRING];               /* string being scanned */
-   int str_len;                       /* length of string */
-   int line_no;                       /* file line number */
-   int col_no;                        /* char position on line */
-   enum lex_state state;              /* lex_state variable */
-   int ch;                            /* last char/L_VAL returned by get_char */
+   struct s_lex_context *next;       /* pointer to next lexical context */
+   int options;                      /* scan options */
+   char *fname;                      /* filename */
+   FILE *fd;                         /* file descriptor */
+   char line[MAXSTRING];             /* input line */
+   char str[MAXSTRING];              /* string being scanned */
+   int str_len;                      /* length of string */
+   int line_no;                      /* file line number */
+   int col_no;                       /* char position on line */
+   int begin_line_no;                /* line no of beginning of string */
+   enum lex_state state;             /* lex_state variable */
+   int ch;                           /* last char/L_VAL returned by get_char */
    int token;
    uint32_t pint32_val;
    uint32_t pint32_val2;
    int32_t int32_val;
    int64_t int64_val;
    void (*scan_error)(char *file, int line, struct s_lex_context *lc, char *msg, ...);
-   void *caller_ctx;                  /* caller private data */
+   void *caller_ctx;                 /* caller private data */
 } LEX;
 
 typedef void (LEX_ERROR_HANDLER)(char *file, int line, LEX *lc, char *msg, ...);