From 97e135bdd832be05ef86b2a45b11b2a8adda7b47 Mon Sep 17 00:00:00 2001 From: H.G. Muller Date: Wed, 18 Nov 2009 19:29:57 -0800 Subject: [PATCH] 2nd step for moving option parsing from winboard to the backend This is the next step in option-setting refactoring: All options that are defined in XBoard are now included in the WinBoard ArgDescriptor list. The handling of sound option has been harmonized: the sound names now all initially go to the appData array, (as in XB) in stead of directly to the WB-specific variables, and LoadAllSounds now takes care of the copying. A new routine ExportSounds copies them back before saving settings (which, in XBoard, could be a no-op). The definition of defaults for the XB-only options has been moved to common.h. --- common.h | 18 ++++++-- winboard/winboard.c | 111 ++++++++++++++++++++++++++++++++------------------ xboard.h | 7 +--- 3 files changed, 86 insertions(+), 50 deletions(-) diff --git a/common.h b/common.h index 18c3b38..03f7bb0 100644 --- a/common.h +++ b/common.h @@ -168,10 +168,18 @@ int pclose(FILE *); #define JAIL_SQUARE_COLOR "#808080" #define HIGHLIGHT_SQUARE_COLOR "#FFFF00" #define PREMOVE_HIGHLIGHT_COLOR "#FF0000" +#define LOWTIMEWARNING_COLOR "#FF0000" #define BELLCHAR '\007' #define NULLCHAR '\000' #define FEATURE_TIMEOUT 10000 /*ms*/ +/* Default to no flashing (the "usual" XBoard behavior) */ +#define FLASH_COUNT 0 /* Number of times to flash */ +#define FLASH_RATE 5 /* Flashes per second */ + +/* Default delay per character (in msec) while sending login script */ +#define MS_LOGIN_DELAY 0 + /* Zippy defaults */ #define ZIPPY_TALK FALSE #define ZIPPY_PLAY FALSE @@ -443,7 +451,7 @@ typedef struct { ICS logon script (xboard only) */ Boolean colorize; /* If True, use the following colors to color text */ /* Strings for colors, as "fg, bg, bold" (strings used in xboard only) */ - char *colorShout; + char *colorShout; // [HGM] IMPORTANT: order must conform to ColorClass definition char *colorSShout; char *colorChannel1; char *colorChannel; @@ -454,7 +462,7 @@ typedef struct { char *colorSeek; char *colorNormal; char *soundProgram; /* sound-playing program */ - char *soundShout; + char *soundShout; // [HGM] IMPORTANT: order must be as in ColorClass char *soundSShout; char *soundChannel1; char *soundChannel; @@ -463,12 +471,13 @@ typedef struct { char *soundChallenge; char *soundRequest; char *soundSeek; - char *soundMove; + char *soundMove; // [HGM] IMPORTANT: order must be as in SoundClass + char *soundBell; + char *soundIcsAlarm; char *soundIcsWin; char *soundIcsLoss; char *soundIcsDraw; char *soundIcsUnfinished; - char *soundIcsAlarm; Boolean reuseFirst; Boolean reuseSecond; Boolean animateDragging; /* If True, animate mouse dragging of pieces */ @@ -611,6 +620,7 @@ typedef struct { char *wrapContSeq; /* continuation sequence when xboard wraps text */ Boolean useInternalWrap; /* use internal wrapping -- noJoin usurps this if set */ Boolean pasteSelection; /* paste X selection instead of clipboard */ + int nrVariations; /* [HGM] multivar */ } AppData, *AppDataPtr; /* [AS] PGN tags (for showing in the game list) */ diff --git a/winboard/winboard.c b/winboard/winboard.c index 6f1d434..ee5fa0c 100644 --- a/winboard/winboard.c +++ b/winboard/winboard.c @@ -903,6 +903,8 @@ typedef struct { int junk; +#define XBOARD FALSE + ArgDescriptor argDescriptors[] = { /* positional arguments */ { "loadGameFile", ArgFilename, (LPVOID) &appData.loadGameFile, FALSE, INVALID }, @@ -952,7 +954,30 @@ ArgDescriptor argDescriptors[] = { { "fd", ArgFilename, (LPVOID) &appData.firstDirectory, FALSE, INVALID }, { "secondDirectory", ArgFilename, (LPVOID) &appData.secondDirectory, FALSE, (ArgIniType) SECOND_DIRECTORY }, { "sd", ArgFilename, (LPVOID) &appData.secondDirectory, FALSE, INVALID }, - /*!!bitmapDirectory?*/ + + /* some options only used by the XBoard front end, and ignored in WinBoard */ + /* Their saving is controlled by XBOARD, which in WinBoard is defined as FALSE */ + { "internetChessServerInputBox", ArgBoolean, (LPVOID) &appData.icsInputBox, XBOARD, (ArgIniType) FALSE }, + { "icsinput", ArgTrue, (LPVOID) &appData.icsInputBox, FALSE, INVALID }, + { "xicsinput", ArgFalse, (LPVOID) &appData.icsInputBox, FALSE, INVALID }, + { "cmail", ArgString, (LPVOID) &appData.cmailGameName, FALSE, (ArgIniType) "" }, + { "soundProgram", ArgFilename, (LPVOID) &appData.soundProgram, XBOARD, (ArgIniType) "play" }, + { "fontSizeTolerance", ArgInt, (LPVOID) &appData.fontSizeTolerance, XBOARD, (ArgIniType) 4 }, + { "lowTimeWarningColor", ArgColor, (LPVOID) &appData.lowTimeWarningColor, XBOARD, + (ArgIniType) LOWTIMEWARNING_COLOR }, + { "lowTimeWarning", ArgBoolean, (LPVOID) &appData.lowTimeWarning, XBOARD, (ArgIniType) FALSE }, + { "titleInWindow", ArgBoolean, (LPVOID) &appData.titleInWindow, XBOARD, (ArgIniType) FALSE }, + { "title", ArgTrue, (LPVOID) &appData.titleInWindow, FALSE, INVALID }, + { "xtitle", ArgFalse, (LPVOID) &appData.titleInWindow, FALSE, INVALID }, + { "flashCount", ArgInt, (LPVOID) &appData.flashCount, XBOARD, (ArgIniType) FLASH_COUNT }, + { "flashRate", ArgInt, (LPVOID) &appData.flashRate, XBOARD, (ArgIniType) FLASH_RATE }, + { "pixmapDirectory", ArgFilename, (LPVOID) &appData.pixmapDirectory, XBOARD, (ArgIniType) "" }, + { "pixmap", ArgFilename, (LPVOID) &appData.pixmapDirectory, FALSE, INVALID }, + { "bitmapDirectory", ArgFilename, (LPVOID) &appData.bitmapDirectory, XBOARD, (ArgIniType) "" }, + { "bm", ArgFilename, (LPVOID) &appData.bitmapDirectory, FALSE, INVALID }, + { "msLoginDelay", ArgInt, (LPVOID) &appData.msLoginDelay, XBOARD, (ArgIniType) MS_LOGIN_DELAY }, + { "pasteSelection", ArgBoolean, (LPVOID) &appData.pasteSelection, XBOARD, (ArgIniType) FALSE }, + { "remoteShell", ArgFilename, (LPVOID) &appData.remoteShell, FALSE, (ArgIniType) REMOTE_SHELL }, { "rsh", ArgFilename, (LPVOID) &appData.remoteShell, FALSE, INVALID }, { "remoteUser", ArgString, (LPVOID) &appData.remoteUser, FALSE, INVALID }, @@ -982,6 +1007,8 @@ ArgDescriptor argDescriptors[] = { { "xtelnet", ArgFalse, (LPVOID) &appData.useTelnet, FALSE, INVALID }, { "-telnet", ArgFalse, (LPVOID) &appData.useTelnet, FALSE, INVALID }, { "telnetProgram", ArgFilename, (LPVOID) &appData.telnetProgram, FALSE, (ArgIniType) TELNET_PROGRAM }, + { "internetChessserverHelper", ArgFilename, (LPVOID) &appData.icsHelper, + FALSE, INVALID }, // for XB { "icshelper", ArgFilename, (LPVOID) &appData.icsHelper, FALSE, (ArgIniType) "" }, { "gateway", ArgString, (LPVOID) &appData.gateway, FALSE, (ArgIniType) "" }, { "loadGameFile", ArgFilename, (LPVOID) &appData.loadGameFile, FALSE, (ArgIniType) "" }, @@ -1060,6 +1087,10 @@ ArgDescriptor argDescriptors[] = { { "size", ArgBoardSize, (LPVOID) &boardSize, FALSE, INVALID }, { "ringBellAfterMoves", ArgBoolean, (LPVOID) &appData.ringBellAfterMoves, FALSE, (ArgIniType) TRUE }, /* historical; kept only so old winboard.ini files will parse */ + { "bell", ArgTrue, (LPVOID) &appData.ringBellAfterMoves, FALSE, INVALID }, // for XB + { "xbell", ArgFalse, (LPVOID) &appData.ringBellAfterMoves, FALSE, INVALID }, // for XB + { "movesound", ArgTrue, (LPVOID) &appData.ringBellAfterMoves, FALSE, INVALID }, // for XB + { "xmovesound", ArgFalse, (LPVOID) &appData.ringBellAfterMoves, FALSE, INVALID }, // for XB { "alwaysOnTop", ArgBoolean, (LPVOID) &alwaysOnTop, TRUE, INVALID }, { "top", ArgTrue, (LPVOID) &alwaysOnTop, FALSE, INVALID }, { "xtop", ArgFalse, (LPVOID) &alwaysOnTop, FALSE, INVALID }, @@ -1169,35 +1200,23 @@ ArgDescriptor argDescriptors[] = { { "colorSeek", ArgAttribs, (LPVOID) ColorSeek, TRUE, INVALID }, { "colorNormal", ArgAttribs, (LPVOID) ColorNormal, TRUE, INVALID }, { "colorBackground", ArgColor, (LPVOID) &consoleBackgroundColor, TRUE, INVALID }, - { "soundShout", ArgFilename, - (LPVOID) &textAttribs[ColorShout].sound.name, TRUE, INVALID }, - { "soundSShout", ArgFilename, - (LPVOID) &textAttribs[ColorSShout].sound.name, TRUE, INVALID }, - { "soundChannel1", ArgFilename, - (LPVOID) &textAttribs[ColorChannel1].sound.name, TRUE, INVALID }, - { "soundChannel", ArgFilename, - (LPVOID) &textAttribs[ColorChannel].sound.name, TRUE, INVALID }, - { "soundKibitz", ArgFilename, - (LPVOID) &textAttribs[ColorKibitz].sound.name, TRUE, INVALID }, - { "soundTell", ArgFilename, - (LPVOID) &textAttribs[ColorTell].sound.name, TRUE, INVALID }, - { "soundChallenge", ArgFilename, - (LPVOID) &textAttribs[ColorChallenge].sound.name, TRUE, INVALID }, - { "soundRequest", ArgFilename, - (LPVOID) &textAttribs[ColorRequest].sound.name, TRUE, INVALID }, - { "soundSeek", ArgFilename, - (LPVOID) &textAttribs[ColorSeek].sound.name, TRUE, INVALID }, - { "soundMove", ArgFilename, (LPVOID) &sounds[(int)SoundMove].name, TRUE, INVALID }, - { "soundBell", ArgFilename, (LPVOID) &sounds[(int)SoundBell].name, TRUE, INVALID }, - { "soundIcsWin", ArgFilename, (LPVOID) &sounds[(int)SoundIcsWin].name, TRUE, INVALID }, - { "soundIcsLoss", ArgFilename, - (LPVOID) &sounds[(int)SoundIcsLoss].name, TRUE, INVALID }, - { "soundIcsDraw", ArgFilename, - (LPVOID) &sounds[(int)SoundIcsDraw].name, TRUE, INVALID }, - { "soundIcsUnfinished", ArgFilename, - (LPVOID) &sounds[(int)SoundIcsUnfinished].name, TRUE, INVALID }, - { "soundIcsAlarm", ArgFilename, - (LPVOID) &sounds[(int)SoundAlarm].name, TRUE, INVALID }, + { "soundShout", ArgFilename, (LPVOID) &appData.soundShout, TRUE, (ArgIniType) "" }, + { "soundSShout", ArgFilename, (LPVOID) &appData.soundSShout, TRUE, (ArgIniType) "" }, + { "soundCShout", ArgFilename, (LPVOID) &appData.soundSShout, TRUE, (ArgIniType) "" }, // for XB + { "soundChannel1", ArgFilename, (LPVOID) &appData.soundChannel1, TRUE, (ArgIniType) "" }, + { "soundChannel", ArgFilename, (LPVOID) &appData.soundChannel, TRUE, (ArgIniType) "" }, + { "soundKibitz", ArgFilename, (LPVOID) &appData.soundKibitz, TRUE, (ArgIniType) "" }, + { "soundTell", ArgFilename, (LPVOID) &appData.soundTell, TRUE, (ArgIniType) "" }, + { "soundChallenge", ArgFilename, (LPVOID) &appData.soundChallenge, TRUE, (ArgIniType) "" }, + { "soundRequest", ArgFilename, (LPVOID) &appData.soundRequest, TRUE, (ArgIniType) "" }, + { "soundSeek", ArgFilename, (LPVOID) &appData.soundSeek, TRUE, (ArgIniType) "" }, + { "soundMove", ArgFilename, (LPVOID) &appData.soundMove, TRUE, (ArgIniType) "" }, + { "soundBell", ArgFilename, (LPVOID) &appData.soundBell, TRUE, (ArgIniType) SOUND_BELL }, + { "soundIcsWin", ArgFilename, (LPVOID) &appData.soundIcsWin, TRUE, (ArgIniType) "" }, + { "soundIcsLoss", ArgFilename, (LPVOID) &appData.soundIcsLoss, TRUE, (ArgIniType) "" }, + { "soundIcsDraw", ArgFilename, (LPVOID) &appData.soundIcsDraw, TRUE, (ArgIniType) "" }, + { "soundIcsUnfinished", ArgFilename, (LPVOID) &appData.soundIcsUnfinished, TRUE, (ArgIniType) "" }, + { "soundIcsAlarm", ArgFilename, (LPVOID) &appData.soundIcsAlarm, TRUE, (ArgIniType) "" }, { "reuseFirst", ArgBoolean, (LPVOID) &appData.reuseFirst, FALSE, (ArgIniType) TRUE }, { "reuse", ArgTrue, (LPVOID) &appData.reuseFirst, FALSE, INVALID }, { "xreuse", ArgFalse, (LPVOID) &appData.reuseFirst, FALSE, INVALID }, @@ -1886,29 +1905,27 @@ SetDefaultTextAttribs() VOID SetDefaultSounds() -{ +{ // [HGM] only sounds for which no option exists ColorClass cc; - SoundClass sc; - for (cc = (ColorClass)0; cc < NColorClasses; cc++) { + for (cc = ColorNormal; cc < NColorClasses; cc++) { textAttribs[cc].sound.name = strdup(""); textAttribs[cc].sound.data = NULL; } - for (sc = (SoundClass)0; sc < NSoundClasses; sc++) { - sounds[sc].name = strdup(""); - sounds[sc].data = NULL; - } - sounds[(int)SoundBell].name = strdup(SOUND_BELL); } VOID LoadAllSounds() -{ +{ // [HGM] import name from appData first ColorClass cc; SoundClass sc; - for (cc = (ColorClass)0; cc < NColorClasses; cc++) { + for (cc = (ColorClass)0; cc < ColorNormal; cc++) { + textAttribs[cc].sound.name = strdup((&appData.soundShout)[cc]); + textAttribs[cc].sound.data = NULL; MyLoadSound(&textAttribs[cc].sound); } for (sc = (SoundClass)0; sc < NSoundClasses; sc++) { + sounds[sc].name = strdup((&appData.soundMove)[sc]); + sounds[sc].data = NULL; MyLoadSound(&sounds[sc]); } } @@ -2153,6 +2170,17 @@ SaveFontArg(FILE *f, ArgDescriptor *ad) } } +VOID +ExportSounds() +{ // [HGM] copy the names from the internal WB variables to appData + ColorClass cc; + SoundClass sc; + for (cc = (ColorClass)0; cc < ColorNormal; cc++) + (&appData.soundShout)[cc] = textAttribs[cc].sound.name; + for (sc = (SoundClass)0; sc < NSoundClasses; sc++) + (&appData.soundMove)[sc] = sounds[sc].name; +} + void SaveAttribsArg(FILE *f, ArgDescriptor *ad) { // here the "argLoc" defines a table index. It could have contained the 'ta' pointer itself, though @@ -2223,6 +2251,9 @@ SaveSettings(char* name) wpEngineOutput.visible = EngineOutputIsUp(); GetActualPlacement(engineOutputDialog, &wpEngineOutput); + // [HGM] in WB we have to copy sound names to appData first + ExportSounds(); + for (ad = argDescriptors; ad->argName != NULL; ad++) { if (!ad->save) continue; switch (ad->argType) { diff --git a/xboard.h b/xboard.h index 5806d53..9f3cdd7 100644 --- a/xboard.h +++ b/xboard.h @@ -107,12 +107,7 @@ typedef struct { #define FIRST_CHESS_PROGRAM "fairymax" #define SECOND_CHESS_PROGRAM "fairymax" -/* Default to no flashing (the "usual" XBoard behavior) */ -#define FLASH_COUNT 0 /* Number of times to flash */ -#define FLASH_RATE 5 /* Flashes per second */ - -/* Default delay per character (in msec) while sending login script */ -#define MS_LOGIN_DELAY 0 +#define XBOARD True typedef int (*FileProc) P((FILE *f, int n, char *title)); void CatchDeleteWindow(Widget w, String procname); -- 1.7.0.4