From 4d04bc8a6c2d5e410d519b25164613c5e5c2d160 Mon Sep 17 00:00:00 2001 From: H.G. Muller Date: Sat, 10 Sep 2011 14:01:58 +0200 Subject: [PATCH] Add -afterGame option This option specifies a command line to be executed after each game of a tournament. To execute the line, the function RunCommand() was added in the front-end. For XBoard this was a simple call to system(); for WinBoard part of the StartChildProcess code was cloned (without the pipe stuff). --- args.h | 1 + backend.c | 1 + common.h | 1 + frontend.h | 1 + winboard/winboard.c | 31 +++++++++++++++++++++++++++++++ xboard.c | 6 ++++++ 6 files changed, 41 insertions(+), 0 deletions(-) diff --git a/args.h b/args.h index bbdaeeb..e22ebfc 100644 --- a/args.h +++ b/args.h @@ -578,6 +578,7 @@ ArgDescriptor argDescriptors[] = { { "syncAfterRound", ArgBoolean, (void *) &appData.roundSync, FALSE, (ArgIniType) FALSE }, { "syncAfterCycle", ArgBoolean, (void *) &appData.cycleSync, FALSE, (ArgIniType) TRUE }, { "seedBase", ArgInt, (void *) &appData.seedBase, FALSE, (ArgIniType) 1 }, + { "afterGame", ArgString, (void *) &appData.afterGame, FALSE, INVALID }, /* [HGM] board-size, adjudication and misc. options */ { "oneClickMove", ArgBoolean, (void *) &appData.oneClick, TRUE, (ArgIniType) FALSE }, diff --git a/backend.c b/backend.c index e3b32e6..9f58b18 100644 --- a/backend.c +++ b/backend.c @@ -10437,6 +10437,7 @@ GameEnds(result, resultDetails, whosays) if(waitingForGame) resChar = ' '; // quit while waiting for round sync: unreserve already reserved game if(appData.tourneyFile[0]){ // [HGM] we are in a tourney; update tourney file with game result + if(appData.afterGame && appData.afterGame[0]) RunCommand(appData.afterGame); ReserveGame(nextGame, resChar); // sets nextGame if(nextGame > appData.matchGames) appData.tourneyFile[0] = 0, ranking = TourneyStandings(3); // tourney is done else ranking = strdup("busy"); //suppress popup when aborted but not finished diff --git a/common.h b/common.h index b45fcf1..98a6149 100644 --- a/common.h +++ b/common.h @@ -667,6 +667,7 @@ typedef struct { char *processes; char *results; char *participants; + char *afterGame; int tourneyType; int tourneyCycles; int seedBase; diff --git a/frontend.h b/frontend.h index 483356a..ec0a4ea 100644 --- a/frontend.h +++ b/frontend.h @@ -143,6 +143,7 @@ int RightClick P((ClickType c, int x, int y, int *col, int *row)); int StartChildProcess P((char *cmdLine, char *dir, ProcRef *pr)); void DestroyChildProcess P((ProcRef pr, int/*boolean*/ signal)); void InterruptChildProcess P((ProcRef pr)); +void RunCommand P((char *buf)); int OpenTelnet P((char *host, char *port, ProcRef *pr)); int OpenTCP P((char *host, char *port, ProcRef *pr)); diff --git a/winboard/winboard.c b/winboard/winboard.c index 223a6f8..83fd4bd 100644 --- a/winboard/winboard.c +++ b/winboard/winboard.c @@ -8853,6 +8853,37 @@ IDLE_PRIORITY_CLASS 0x00000040 return 0x00000040; } +void RunCommand(char *cmdLine) +{ + /* Now create the child process. */ + STARTUPINFO siStartInfo; + PROCESS_INFORMATION piProcInfo; + + siStartInfo.cb = sizeof(STARTUPINFO); + siStartInfo.lpReserved = NULL; + siStartInfo.lpDesktop = NULL; + siStartInfo.lpTitle = NULL; + siStartInfo.dwFlags = STARTF_USESTDHANDLES; + siStartInfo.cbReserved2 = 0; + siStartInfo.lpReserved2 = NULL; + siStartInfo.hStdInput = NULL; + siStartInfo.hStdOutput = NULL; + siStartInfo.hStdError = NULL; + + CreateProcess(NULL, + cmdLine, /* command line */ + NULL, /* process security attributes */ + NULL, /* primary thread security attrs */ + TRUE, /* handles are inherited */ + DETACHED_PROCESS|CREATE_NEW_PROCESS_GROUP, + NULL, /* use parent's environment */ + NULL, + &siStartInfo, /* STARTUPINFO pointer */ + &piProcInfo); /* receives PROCESS_INFORMATION */ + + CloseHandle(piProcInfo.hThread); +} + /* Start a child process running the given program. The process's standard output can be read from "from", and its standard input can be written to "to". diff --git a/xboard.c b/xboard.c index 4a88774..4a6d7f0 100644 --- a/xboard.c +++ b/xboard.c @@ -7263,6 +7263,12 @@ EchoOff() } void +RunCommand(char *buf) +{ + system(buf); +} + +void Colorize(cc, continuation) ColorClass cc; int continuation; -- 1.7.0.4