Commit Diff


commit - 885707edec53f628c3039c20031c89670d36d2f6
commit + cfab1835584d3f69e858d421c192731cef8848d4
blob - db41a6d395d3330ea9e08eca17fb286d7186eba5
blob + 76ea436987a66394ecc52ea2dbee229a0fd42e1b
--- gotwebd/gotwebd.8
+++ gotwebd/gotwebd.8
@@ -22,7 +22,7 @@
 .Sh SYNOPSIS
 .Nm
 .Op Fl dnv
-.Op Fl D Ar macro=value
+.Op Fl D Ar macro Ns = Ns Ar value
 .Op Fl f Ar file
 .Sh DESCRIPTION
 .Nm
@@ -38,8 +38,14 @@ provides the following options:
 .Bl -tag -width tenletters
 .It Fl d
 Do not daemonize and log to stderr.
-.It Fl D Ar macro=value
-Override the value of a macro used in the configuration file.
+.It Fl D Ar macro Ns = Ns Ar value
+Define
+.Ar macro
+to be set to
+.Ar value .
+Overrides the definition of
+.Ar macro
+in the configuration file.
 .It Fl f Ar file
 Set the path to the configuration file.
 If not specified, the file
blob - b0f31dc628d54ccc683a1c5b00750a7362ebc124
blob + 82d73b6a9ce6b79982f543208398c56d6464e96d
--- gotwebd/gotwebd.conf.5
+++ gotwebd/gotwebd.conf.5
@@ -29,6 +29,16 @@ Any lines beginning with a
 .Sq #
 are treated as comments and ignored.
 .Pp
+Macros can be defined that are later expanded in context.
+Macro names must start with a letter, digit, or underscore, and may
+contain any of those characters, but may not be reserved words.
+Macros are not expanded inside quotes.
+For example:
+.Bd -literal -offset indent
+lan_addr = "192.168.0.1"
+listen on $lan_addr
+.Ed
+.Pp
 Paths mentioned in
 .Nm
 must be relative to
blob - ff344f27c72a411f63bffb62b5c4a456fb6603ff
blob + 0f2104fd08adfe765d0eb0291769ef85ac01c9f2
--- gotwebd/parse.y
+++ gotwebd/parse.y
@@ -130,10 +130,30 @@ typedef struct {
 
 %%
 
-grammar		:
+grammar		: /* empty */
 		| grammar '\n'
+		| grammar varset '\n'
 		| grammar main '\n'
 		| grammar server '\n'
+		| grammar error '\n'		{ file->errors++; }
+		;
+
+varset		: STRING '=' STRING	{
+			char *s = $1;
+			while (*s++) {
+				if (isspace((unsigned char)*s)) {
+					yyerror("macro name cannot contain "
+					    "whitespace");
+					free($1);
+					free($3);
+					YYERROR;
+				}
+			}
+			if (symset($1, $3, 0) == -1)
+				fatal("cannot store variable");
+			free($1);
+			free($3);
+		}
 		;
 
 boolean		: STRING {