]> git.ipfire.org Git - thirdparty/bird.git/commitdiff
Conf: Show the line:char position where the syntax error happens
authorJan Maria Matejka <mq@ucw.cz>
Tue, 11 Sep 2018 14:55:41 +0000 (16:55 +0200)
committerJan Maria Matejka <mq@ucw.cz>
Tue, 11 Sep 2018 15:35:13 +0000 (17:35 +0200)
conf/cf-lex.l
conf/conf.c
conf/conf.h
sysdep/unix/main.c

index c3154b363bca4122dcf384e0a0f19bfa7278c12c..9bbb3660a45efac9b9f4127265972da58aea0da6 100644 (file)
@@ -100,6 +100,7 @@ static struct include_file_stack *ifs_head;
 #define YY_INPUT(buf,result,max) result = cf_read_hook(buf, max, ifs->fd);
 #define YY_NO_UNPUT
 #define YY_FATAL_ERROR(msg) cf_error(msg)
+#define YY_USER_ACTION ifs->chno += yyleng; ifs->toklen = yyleng;
 
 static void cf_include(char *arg, int alen);
 static int check_eof(void);
@@ -313,7 +314,7 @@ else: {
 
 {WHITE}+
 
-\n     ifs->lino++;
+\n     ifs->lino++; ifs->chno = 0;
 
 #      BEGIN(COMMENT);
 
@@ -323,13 +324,14 @@ else: {
 
 <COMMENT>\n {
   ifs->lino++;
+  ifs->chno = 0;
   BEGIN(INITIAL);
 }
 
 <COMMENT>.
 
 <CCOMM>\*\/    BEGIN(INITIAL);
-<CCOMM>\n      ifs->lino++;
+<CCOMM>\n      ifs->lino++; ifs->chno = 0;
 <CCOMM>\/\*    cf_error("Comment nesting not supported");
 <CCOMM><<EOF>> cf_error("Unterminated comment");
 <CCOMM>.
index 885e2e7e0ebf2b17ed85494d76239875cd729c0c..8dbefe96beb7a695b9b4b764950d65843837c3df 100644 (file)
@@ -512,6 +512,7 @@ cf_error(const char *msg, ...)
   va_end(args);
   new_config->err_msg = cfg_strdup(buf);
   new_config->err_lino = ifs->lino;
+  new_config->err_chno = ifs->chno - ifs->toklen + 1;
   new_config->err_file_name = ifs->file_name;
   cf_lex_unwind();
   longjmp(conf_jmpbuf, 1);
index f174d352d22a62c490d13ca665ddc96acc84615d..5689fb67272488d9c27c441111f8d930d2288c09 100644 (file)
@@ -47,6 +47,7 @@ struct config {
   u32 watchdog_timeout;                        /* Watchdog timeout (in seconds, 0 = disabled) */
   char *err_msg;                       /* Parser error message */
   int err_lino;                                /* Line containing error */
+  int err_chno;                                /* Character where the parser stopped */
   char *err_file_name;                 /* File name containing error */
   char *file_name;                     /* Name of main configuration file */
   int file_fd;                         /* File descriptor of main configuration file */
@@ -139,6 +140,8 @@ struct include_file_stack {
   char *file_name;                     /* File name */
   int fd;                              /* File descriptor */
   int lino;                            /* Current line num */
+  int chno;                            /* Current char num (on current line) */
+  int toklen;                          /* Current token length */
   int depth;                           /* Include depth, 0 = cannot include */
 
   struct include_file_stack *prev;     /* Previous record in stack */
@@ -147,7 +150,6 @@ struct include_file_stack {
 
 extern struct include_file_stack *ifs;
 
-
 int cf_lex(void);
 void cf_lex_init(int is_cli, struct config *c);
 void cf_lex_unwind(void);
index 0912a9c5369a0568ee395800a48f8b825c604ea9..d2380501a521013990f5f32a54ec31243e3928b4 100644 (file)
@@ -213,7 +213,7 @@ read_config(void)
   if (!unix_read_config(&conf, config_name))
     {
       if (conf->err_msg)
-       die("%s, line %d: %s", conf->err_file_name, conf->err_lino, conf->err_msg);
+       die("%s:%d:%d %s", conf->err_file_name, conf->err_lino, conf->err_chno, conf->err_msg);
       else
        die("Unable to open configuration file %s: %m", config_name);
     }
@@ -230,7 +230,7 @@ async_config(void)
   if (!unix_read_config(&conf, config_name))
     {
       if (conf->err_msg)
-       log(L_ERR "%s, line %d: %s", conf->err_file_name, conf->err_lino, conf->err_msg);
+       log(L_ERR "%s:%d:%d %s", conf->err_file_name, conf->err_lino, conf->err_chno, conf->err_msg);
       else
        log(L_ERR "Unable to open configuration file %s: %m", config_name);
       config_free(conf);
@@ -251,7 +251,7 @@ cmd_read_config(char *name)
   if (!unix_read_config(&conf, name))
     {
       if (conf->err_msg)
-       cli_msg(8002, "%s, line %d: %s", conf->err_file_name, conf->err_lino, conf->err_msg);
+       cli_msg(8002, "%s:%d:%d %s", conf->err_file_name, conf->err_lino, conf->err_chno, conf->err_msg);
       else
        cli_msg(8002, "%s: %m", name);
       config_free(conf);