Download raw body.
gotwebd.conf: add varset and include
On September 25, 2022 2:48:12 PM MDT, Omar Polo <op@omarpolo.com> wrote:
>On 2022/09/25 21:19:57 +0200, Stefan Sperling <stsp@stsp.name> wrote:
>> I think it makes more sense to wait with adding the include feature
>> until we see a real need for it. Someone might eventually ask for it
>> and present a case, and then we can easily add it.
>> To me this seems like one of those features that look simple but may
>> have consequences nobody saw ahead of time, leading to problems down
>> the road which would not exist if the concepts had been kept simple.
>
>after thinking a bit I agree with you, there's no rush and less code
>is better :)
>
>here's a smaller diff only covering the macros then
>
>diff /home/op/w/got-main
>commit - e02bf8ada9fce6518a7ad40401425a26bdaadbb4
>path + /home/op/w/got-main
>blob - db41a6d395d3330ea9e08eca17fb286d7186eba5
>file + gotwebd/gotwebd.8
>--- 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 @@ Do not daemonize and log to stderr.
> .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
>file + gotwebd/gotwebd.conf.5
>--- gotwebd/gotwebd.conf.5
>+++ gotwebd/gotwebd.conf.5
>@@ -29,6 +29,16 @@ Paths mentioned in
> .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 - 84e9b08cfad055d23554ebba81fc37fa15e8cdc9
>file + gotwebd/parse.y
>--- gotwebd/parse.y
>+++ gotwebd/parse.y
>@@ -131,12 +131,32 @@ grammar :
>
> %%
>
>-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 {
> if (strcasecmp($1, "1") == 0 ||
> strcasecmp($1, "yes") == 0 ||
>
I didn't think it needed them, so I pulled them. I'm temporarily on a cell phone with no ability to review, so whatever the consensus thinks is fine by me. But I don't understand the need to stay like all of the other parse.y's just because that's the way it is. Have a good week folks.
--
Tracey Emery
Sent from my phone.
gotwebd.conf: add varset and include