"GOT", but the "O" is a cute, smiling pufferfish. Index | Thread | Search

From:
Stefan Sperling <stsp@stsp.name>
Subject:
gotd.conf varset
To:
gameoftrees@openbsd.org
Date:
Sat, 4 Nov 2023 11:48:16 +0100

Download raw body.

Thread
  • Stefan Sperling:

    gotd.conf varset

This makes it possible to set variables in gotd.conf.
We already have symset() but it was not reachable.
Code obtained from gotwebd/parse.y.  ok?

diff /home/stsp/src/got
commit - ac4f092c7c8e090ee733c90b8b0f0274872c8662
path + /home/stsp/src/got
blob - cc7231514a823861b662e419be141a4492c833fd
file + gotd/parse.y
--- gotd/parse.y
+++ gotd/parse.y
@@ -127,10 +127,29 @@ typedef struct {
 
 grammar		:
 		| grammar '\n'
+		| grammar varset '\n'
 		| grammar main '\n'
 		| grammar repository '\n'
 		;
 
+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);
+		}
+		;
+
 timeout		: NUMBER {
 			if ($1 < 0) {
 				yyerror("invalid timeout: %lld", $1);