From 61d7701742047bbb6be9677d2a59f63f307b8f80 Mon Sep 17 00:00:00 2001 From: H.G.Muller Date: Sun, 29 Oct 2017 20:34:37 +0100 Subject: [PATCH] Locate engine list in separate file 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 | 5 +++++ backend.c | 11 +++++++++++ backend.h | 1 + dialogs.c | 3 ++- frontend.h | 2 ++ menus.c | 1 + 6 files changed, 22 insertions(+), 1 deletions(-) diff --git a/args.h b/args.h index fbdd498..cdf51aa 100644 --- 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); diff --git a/backend.c b/backend.c index 79774fa..43d9b1f 100644 --- 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); } diff --git a/backend.h b/backend.h index ff06dee..befa893 100644 --- 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)); diff --git a/dialogs.c b/dialogs.c index af11b49..cb3d3e8 100644 --- 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(""); diff --git a/frontend.h b/frontend.h index fbc2e9c..a195f2e 100644 --- a/frontend.h +++ b/frontend.h @@ -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 --- a/menus.c +++ b/menus.c @@ -387,6 +387,7 @@ DebugProc () void EditEngineProc () { + if(*engineListFile) ParseSettingsFile(engineListFile, &engineListFile); EditAnyPopUp(firstChessProgramNames, &firstChessProgramNames, _("Registered Engines")); } -- 1.7.0.4