Locate engine list in separate file
authorH.G.Muller <hgm@hgm-xboard.(none)>
Sun, 29 Oct 2017 19:34:37 +0000 (20:34 +0100)
committerH.G.Muller <hgm@hgm-xboard.(none)>
Sun, 29 Oct 2017 19:46:21 +0000 (20:46 +0100)
The option -firstChessProgramNames, which contains the list of registered
engines, can now be kept in a dedicated settings file. This file will
be read at startup after the normal settings file and command-line
arguments. It will also be read and saved when dialogs altering the
engine list are used (Load Engine and Edit Engine List). This will
effectively cause changes in the engine list made by any XBoard instance
to be instantly broadcasted to all other instances. The name of this
engine-list file can be specified by the new persistent option -engineList.
If this is set to an empty string (the default), this new feature will
not be used, and the list in the normal settings file will be used
as always. This list is currently still written in the user settings file,
together with the other settings.

args.h
backend.c
backend.h
dialogs.c
frontend.h
menus.c

diff --git a/args.h b/args.h
index fbdd498..cdf51aa 100644 (file)
--- a/args.h
+++ b/args.h
@@ -113,6 +113,7 @@ char *secondEngineLine;
 char *icsNick;
 char *theme;
 char *replace;
+char *engineListFile;
 
 void EnsureOnScreen(int *x, int *y, int minX, int minY);
 char StringGet(void *getClosure);
@@ -518,6 +519,7 @@ ArgDescriptor argDescriptors[] = {
   { "secondChessProgramNames", ArgString, (void *) &secondChessProgramNames,
     !XBOARD, (ArgIniType) SCP_NAMES },
   { "themeNames", ArgString, (void *) &appData.themeNames, TRUE, (ArgIniType) "native -upf false -ub false -ubt false -pid \"\"\n" },
+  { "engineList", ArgFilename, (void *) &engineListFile, TRUE, (ArgIniType) "" },
   { "addMasterOption", ArgMaster, NULL, FALSE, INVALID },
   { "installEngine", ArgInstall, (void *) &firstChessProgramNames, FALSE, (ArgIniType) "" },
   { "installTheme", ArgInstall, (void *) &appData.themeNames, FALSE, (ArgIniType) "" },
@@ -1436,6 +1438,9 @@ InitAppData(char *lpCmdLine)
   /* Parse command line */
   ParseArgs(StringGet, &lpCmdLine);
 
+  /* if separate engine list is used, parse that too */
+  if(*engineListFile) ParseSettingsFile(engineListFile, &engineListFile);
+
   if(appData.viewer && appData.viewerOptions[0]) ParseArgsFromString(appData.viewerOptions);
   if(appData.tourney && appData.tourneyOptions[0]) ParseArgsFromString(appData.tourneyOptions);
   chessProgram |= GetEngineLine(firstEngineLine, 0) || GetEngineLine(secondEngineLine, 1);
index 79774fa..43d9b1f 100644 (file)
--- a/backend.c
+++ b/backend.c
@@ -940,6 +940,16 @@ FloatToFront(char **list, char *engineLine)
 }
 
 void
+SaveEngineList ()
+{
+       FILE *f;
+       if(*engineListFile && (f = fopen(engineListFile, "w"))) {
+         fprintf(f, "-firstChessProgramNames {%s}\n", firstChessProgramNames);
+         fclose(f);
+       }
+}
+
+void
 AddToEngineList (int i)
 {
        int len;
@@ -962,6 +972,7 @@ AddToEngineList (int i)
        if(insert != q) insert[-1] = NULLCHAR;
        snprintf(firstChessProgramNames, len, "%s\n%s\n%s", q, buf, insert);
        if(q)   free(q);
+       SaveEngineList();
        FloatToFront(&appData.recentEngineList, buf);
        ASSIGN(currentEngine[i], buf);
 }
index ff06dee..befa893 100644 (file)
--- a/backend.h
+++ b/backend.h
@@ -418,6 +418,7 @@ extern char *currentEngine[];
 extern Boolean partnerUp, twoBoards;
 extern char engineVariant[];
 void SaveEngineSettings P((int n));
+void SaveEngineList P((void));
 char *EngineDefinedVariant P((ChessProgramState *cps, int n));
 void SettingsPopUp P((ChessProgramState *cps)); // [HGM] really in front-end, but CPS not known in frontend.h
 int WaitForEngine P((ChessProgramState *cps, DelayedEventCallback x));
index af11b49..cb3d3e8 100644 (file)
--- a/dialogs.c
+++ b/dialogs.c
@@ -1216,7 +1216,7 @@ static int
 NewTagsCallback (int n)
 {
     if(bookUp) SaveToBook(tagsText), DisplayBook(currentMove); else
-    if(resPtr) { ASSIGN(*resPtr, tagsText); } else
+    if(resPtr) { ASSIGN(*resPtr, tagsText); if(resPtr == &firstChessProgramNames) SaveEngineList(); } else
     ReplaceTags(tagsText, &gameInfo);
     return 1;
 }
@@ -1557,6 +1557,7 @@ EngSel (int n, int sel)
 static void
 LoadEngineProc (int engineNr, char *title)
 {
+   if(*engineListFile) ParseSettingsFile(engineListFile, &engineListFile); // contains engine list
    isUCI = isUSI = storeVariant = v1 = useNick = False; addToList = hasBook = True; // defaults
    secondEng = engineNr;
    if(engineLine)   free(engineLine);   engineLine = strdup("");
index fbc2e9c..a195f2e 100644 (file)
@@ -126,6 +126,7 @@ int LoadGameTimerRunning P((void));
 int StopLoadGameTimer P((void));
 void StartLoadGameTimer P((long millisec));
 void AutoSaveGame P((void));
+Boolean ParseSettingsFile P((char *name, char **addr));
 
 void ScheduleDelayedEvent P((DelayedEventCallback cb, long millisec));
 DelayedEventCallback GetDelayedEvent P((void));
@@ -215,6 +216,7 @@ void ChangeDragPiece P((ChessSquare piece));
 void CopyFENToClipboard P((void));
 extern char *programName;
 extern int commentUp;
+extern char *engineListFile;
 extern char *firstChessProgramNames;
 extern char *icsTextMenuString;
 extern int mute;
diff --git a/menus.c b/menus.c
index fbc7893..2854021 100644 (file)
--- a/menus.c
+++ b/menus.c
@@ -387,6 +387,7 @@ DebugProc ()
 void
 EditEngineProc ()
 {
+    if(*engineListFile) ParseSettingsFile(engineListFile, &engineListFile);
     EditAnyPopUp(firstChessProgramNames, &firstChessProgramNames, _("Registered Engines"));
 }