Implement less kludgy way for conditional string options
authorH.G.Muller <hgm@hgm-xboard.(none)>
Wed, 30 Nov 2016 13:46:07 +0000 (14:46 +0100)
committerH.G.Muller <hgm@hgm-xboard.(none)>
Fri, 13 Jan 2017 15:39:24 +0000 (16:39 +0100)
A new option -replace can now define a string, and when the existing value
of the next encountered string option does not exactly match that, the
latter is ignored. The @@@@@ kludge for conditionally replacing empty
strings is removed, as this can now be achieved through -replace "".
The value of -replace is reset to NULL (not ""!) as soon as it has been
used for comparison, irrespective of the result. This makes -replace a
'hyper-volatile' option.
 The conditional setting of UCI2WB as -uxiAdapter in xboard.conf is now
changed to use this mechanism.

args.h
xboard.conf

diff --git a/args.h b/args.h
index c518fad..c6914b0 100644 (file)
--- a/args.h
+++ b/args.h
@@ -617,6 +617,7 @@ ArgDescriptor argDescriptors[] = {
   { "epd", ArgTrue, (void *) &appData.epd, FALSE, INVALID },
   { "inscriptions", ArgString, (void *) &appData.inscriptions, FALSE, (ArgIniType) "" },
   { "autoInstall", ArgString, (void *) &appData.autoInstall, XBOARD, (ArgIniType) "" },
+  { "replace", ArgString, (void *) &replace, FALSE, (ArgIniType) NULL },
   { "fixedSize", ArgBoolean, (void *) &appData.fixedSize, TRUE, (ArgIniType) FALSE },
   { "showMoveTime", ArgBoolean, (void *) &appData.moveTime, TRUE, (ArgIniType) FALSE },
 
@@ -1182,9 +1183,10 @@ ParseArgs(GetFunc get, void *cl)
         ASSIGN(*(char **) ad->argLoc, buf);
         break;
       }
-      if(!strncmp(argValue, "@@@@@", 5)) { // conditional string argument
-        if(*(char**) ad->argLoc == 0) { ASSIGN(*(char **) ad->argLoc, argValue+5); } // only used to replace empty string
-       break;
+      if(replace) { // previous -replace option makes this string option conditional
+       char *p = replace;
+       free(replace); replace = NULL; // but expires in the process
+        if(strcmp(*(char**) ad->argLoc, p)) break; // only use to replace the given string
       }
       ASSIGN(*(char **) ad->argLoc, argValue);
       break;
index 457cd81..1541626 100644 (file)
@@ -154,4 +154,5 @@ dialog text pops up help on it}
 ;
 ; use uci2wb as UxI adapter for who has not specified differently
 ;
--uxiAdapter {@@@@@uci2wb -%variant "%fcp" "%fd"}
+-replace ""
+-uxiAdapter {uci2wb -%variant "%fcp" "%fd"}