Commit Diff
Diff:
40dc608f1fa19319e07a762a416073d6c9b5e2c2
13ed2fb63f4915da96fcc7f8022480561a87567e
Commit:
13ed2fb63f4915da96fcc7f8022480561a87567e
Tree:
dc7268a73cf98a4cac38626d8f267defc2a19e3e
Author:
Omar Polo <op@omarpolo.com>
Date:
Wed Jan 27 16:45:45 2021 UTC
Message:
improve configuration parsing error
commit - 40dc608f1fa19319e07a762a416073d6c9b5e2c2
commit + 13ed2fb63f4915da96fcc7f8022480561a87567e
blob - 5668a4fd8a4d0771d06a5630b9ce59b3f1d7423c
blob + 272a39d3499d0115c4ef3b9d777e29e152bba6db
--- gmid.c
+++ gmid.c
@@ -32,7 +32,7 @@ int exfd, foreground, goterror;
struct vhost hosts[HOSTSLEN];
-int exfd, foreground, goterror;
+int exfd, foreground;
struct conf conf;
@@ -292,37 +292,6 @@ yyerror(const char *msg)
}
void
-yyerror(const char *msg)
-{
- goterror = 1;
- fprintf(stderr, "%d: %s\n", yylineno, msg);
-}
-
-int
-parse_portno(const char *p)
-{
- const char *errstr;
- int n;
-
- n = strtonum(p, 0, UINT16_MAX, &errstr);
- if (errstr != NULL)
- errx(1, "port number is %s: %s", errstr, p);
- return n;
-}
-
-void
-parse_conf(const char *path)
-{
- if ((yyin = fopen(path, "r")) == NULL)
- fatal("cannot open config %s", path);
- yyparse();
- fclose(yyin);
-
- if (goterror)
- exit(1);
-}
-
-void
load_vhosts(void)
{
struct vhost *h;
blob - 9e1eac56d82e945e73c31d808b036798188bf323
blob + a2f87942c64d032eb3ac8008b271ea50e3de0a6e
--- gmid.h
+++ gmid.h
@@ -171,9 +171,6 @@ void yyerror(const char*);
void mkdirs(const char*);
char *data_dir(void);
void load_local_cert(const char*, const char*);
-void yyerror(const char*);
-int parse_portno(const char*);
-void parse_conf(const char*);
void load_vhosts(void);
int make_socket(int, int);
void setup_tls(void);
@@ -188,6 +185,10 @@ extern int yylex(void);
extern int yyparse(void);
extern int yylex(void);
+void yyerror(const char*);
+int parse_portno(const char*);
+void parse_conf(const char*);
+
/* mime.c */
void init_mime(struct mime*);
void add_mime(struct mime*, const char*, const char*);
blob - f7e041d20e78bf48c7a58a601b7b971c85b95495
blob + a2e4bf9dc4c56d491d54fbf72ed83ca3c8c9b566
--- lex.l
+++ lex.l
@@ -76,7 +76,7 @@ auto return TAUTO;
[ \t]+ ;
-. errx(1, "%d: unexpected character %c", yylineno, *yytext);
+. yyerror("unexpected character"); exit(1);
%%
blob - b626c1b676ead5fe5f4ee6a82f8b64a3142d3f50
blob + 7929e5317f47d66c1de000faec574415f84bcaf5
--- parse.y
+++ parse.y
@@ -33,8 +33,13 @@ extern void yyerror(const char*);
struct location *loc = &hosts[0].locations[0];
size_t iloc = 0;
-extern void yyerror(const char*);
+int goterror = 0;
+const char *config_path;
+void yyerror(const char*);
+int parse_portno(const char*);
+void parse_conf(const char*);
+
%}
/* for bison: */
@@ -145,3 +150,37 @@ locopt : TDEFAULT TTYPE TSTRING {
}
| TAUTO TINDEX TBOOL { loc->auto_index = $3 ? 1 : -1; }
;
+
+%%
+
+void
+yyerror(const char *msg)
+{
+ goterror = 1;
+ fprintf(stderr, "%s:%d: %s\n", config_path, yylineno, msg);
+}
+
+int
+parse_portno(const char *p)
+{
+ const char *errstr;
+ int n;
+
+ n = strtonum(p, 0, UINT16_MAX, &errstr);
+ if (errstr != NULL)
+ errx(1, "port number is %s: %s", errstr, p);
+ return n;
+}
+
+void
+parse_conf(const char *path)
+{
+ config_path = path;
+ if ((yyin = fopen(path, "r")) == NULL)
+ fatal("cannot open config %s", path);
+ yyparse();
+ fclose(yyin);
+
+ if (goterror)
+ exit(1);
+}
Omar Polo