From abccb87c91e00e929d34714268f2414c7decc986 Mon Sep 17 00:00:00 2001 From: Ben Kibbey Date: Sat, 16 Jun 2018 14:28:28 -0700 Subject: [PATCH] Add config option "turn_cmd". To run a command, such as a program to play a sound, when it is a humans turn. --- doc/cboard.6.in | 9 +++++++-- doc/config.example | 4 ++++ src/conf.h | 1 + src/engine.c | 17 ++++++++++++++++- src/rcfile.c | 2 ++ 5 files changed, 30 insertions(+), 3 deletions(-) diff --git a/doc/cboard.6.in b/doc/cboard.6.in index a240211..b6c9cf9 100644 --- a/doc/cboard.6.in +++ b/doc/cboard.6.in @@ -1,4 +1,4 @@ -.\" Copyright (C) 2002-2013 Ben Kibbey +.\" Copyright (C) 2002-2018 Ben Kibbey .\" .\" This program is free software; you can redistribute it and/or modify .\" it under the terms of the GNU General Public License as published by @@ -17,7 +17,7 @@ \\$2 \(laURL: \\$1 \(ra\\$3 .. .if \n[.g] .mso www.tmac -.TH CBOARD 6 "Dec 12 2014" "@VERSION@" "Curses Chess Board" +.TH CBOARD 6 "Jun 16 2018" "@VERSION@" "Curses Chess Board" .SH NAME .B cboard @@ -174,6 +174,11 @@ Send the "go" command to the chess engine during the first move. Fixes a quirk when using polyglot(1). .TP +.I turn_cmd [] [...] +A command to be run when it is a human turn when playing a against a chess +engine. + +.TP .I bind [] This allows you to change the default key bindings for each game mode. Each game diff --git a/doc/config.example b/doc/config.example index 2f305c1..5c7d2a0 100644 --- a/doc/config.example +++ b/doc/config.example @@ -95,6 +95,10 @@ # Whether to enable UTF-8 board pieces. #utf8_pieces on +# Command to be run when it is a human turn. Only effective for human/engine +# play. +#turn_cmd = paplay /path/to/some/sound.wav + # Below are color and attribute settings. These parameters may contain up to # four values. The first and second are the foreground and background color # names which must be one of: black, white, red, magenta, yellow, blue, cyan, diff --git a/src/conf.h b/src/conf.h index 088af1c..af3ea16 100644 --- a/src/conf.h +++ b/src/conf.h @@ -102,6 +102,7 @@ struct char enginecmdblacktag; int utf8_pieces; // For the board only. char bprevmove; + char *turn_cmd; // Command to be run when its human turn. } config; #endif diff --git a/src/engine.c b/src/engine.c index 476d890..efd10f8 100644 --- a/src/engine.c +++ b/src/engine.c @@ -528,7 +528,22 @@ parse_xboard_line (GAME g, char *str) } if (g->side == g->turn) - RETURN (d); + { + if (config.turn_cmd) + { + switch (fork ()) + { + case 0: + system (config.turn_cmd); + _exit (0); + case -1: + default: + break; + } + } + + RETURN (d); + } d->engine->status = ENGINE_THINKING; } diff --git a/src/rcfile.c b/src/rcfile.c index 32a192e..56c0ff7 100644 --- a/src/rcfile.c +++ b/src/rcfile.c @@ -830,6 +830,8 @@ parse_rcfile (const char *filename) } else if (strcmp (var, "utf8_pieces") == 0) config.utf8_pieces = on_or_off (filename, lines, val); + else if (strcmp (var, "turn_cmd") == 0) + config.turn_cmd = strdup (val); else if (strcmp (var, "color_board_window") == 0) parse_color (filename, lines, val, &config.color[CONF_BDWINDOW]); else if (strcmp (var, "color_board_selected") == 0) -- 2.11.4.GIT