1 /* vim:tw=78:ts=8:sw=4:set ft=c: */
3 Copyright (C) 2002-2006 Ben Kibbey <bjk@arbornet.org>
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation; either version 2 of the License, or
8 (at your option) any later version.
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 GNU General Public License for more details.
15 You should have received a copy of the GNU General Public License
16 along with this program; if not, write to the Free Software
17 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
26 #ifdef HAVE_SYS_PARAM_H
27 #include <sys/param.h>
38 #if defined(__linux__) && defined(HAVE_VASPRINTF)
39 extern int vasprintf(char **, const char *, va_list);
45 #ifdef _POSIX2_LINE_MAX
46 #define LINE_MAX _POSIX2_LINE_MAX
47 #elif defined(_POSIX_LINE_MAX)
48 #define LINE_MAX _POSIX_LINE_MAX
55 #define ACK (curses_initialized && message("ack", "ack", "ack"))
56 #define ACK2 message("ack2", "ack2", "ack2")
59 #define NARRAY(arr) (sizeof(arr) / sizeof(arr[0]))
60 #define CTRL(x) ((x) & 0x1f)
61 #define KEY_ESCAPE CTRL('[')
63 #define CALCPOSY(y) ((y > LINES - 1) ? 0 : LINES / 2 - y / 2)
64 #define CALCPOSX(x) (COLS / 2 - x / 2)
65 #define CENTERX(x, str) (x / 2 - strlen(str) / 2)
67 #define VALIDFILE(f) ((f >= 1 && f <= 8) ? 1 : 0)
68 #define ROWTOBOARD(r) (8 - r)
69 #define COLTOBOARD(c) (c - 1)
70 #define ROWTOINT(r) (r - '0')
71 #define COLTOINT(c) (c - ('a' - 1))
73 #define SET_FLAG(var, f) (var |= f)
74 #define CLEAR_FLAG(var, f) (var &= ~(f))
75 #define TOGGLE_FLAG(var, f) (var ^= (f))
76 #define TEST_FLAG(var, f) (var & f)
79 #define GF_PERROR 0x0001 /* Parse error for this game. */
80 #define GF_DELETE 0x0002 /* Flagged for deletion ('x' command). */
81 #define GF_MODIFIED 0x0004 /* Modified tags or history. */
82 #define GF_ENPASSANT 0x0008 /* For En Passant validation. */
83 #define GF_GAMEOVER 0x0010 /* End of game. */
84 #define GF_WK 0x0020 /* For castling validation ... */
92 OPEN_SQUARE
, PAWN
, BISHOP
, ROOK
, KNIGHT
, QUEEN
, KING
, MAX_PIECES
100 TAG_EVENT
, TAG_SITE
, TAG_DATE
, TAG_ROUND
, TAG_WHITE
, TAG_BLACK
, TAG_RESULT
104 GNUCHESS
, CRAFTY
, MAX_ENGINES
107 typedef struct board_matrix
{
114 BOOK_OFF
, BOOK_PREFER
, BOOK_BEST
, BOOK_WORST
, BOOK_RANDOM
, BOOK_MAX
118 ENGINE_OFFLINE
= -1, ENGINE_READY
, ENGINE_THINKING
, ENGINE_INITIALIZING
122 MODE_HISTORY
, MODE_PLAY
, MODE_EDIT
125 #define cmessage(title, prompt, args...) \
126 dump_message(title, prompt, 1, NULL, NULL, NULL, 0, ##args)
128 #define message(title, prompt, args...) \
129 dump_message(title, prompt, 0, NULL, NULL, NULL, 0, ##args)
131 #define show_message(title, prompt, ehelp, func, arg, key, args...) \
132 dump_message(title, prompt, 0, ehelp, func, arg, key, ##args)
134 #define SEND_TO_ENGINE(fmt, args...) (engine_initialized && !noengine) ? \
135 send_to_engine(fmt, ##args) : 0
137 #define get_input_str(title, init) \
138 get_input(title, init, 1, 0, NULL, NULL, NULL, 0, -1, 20)
140 #define get_input_str_clear(title, init) \
141 get_input(title, init, 1, 1, NULL, NULL, NULL, 0, -1, 20)
151 typedef struct tags
{
156 typedef struct history
{
157 char move
[MAX_PGN_MOVE_LEN
+ 1];
159 int nag
[MAX_PGN_NAG
];
162 /* This is an array of 'games' structures. One for each game in a file, or
165 typedef struct games
{
184 /* This holds the selected piece info. */
199 CONF_BWHITE
, CONF_BBLACK
, CONF_BSELECTED
, CONF_BCURSOR
, CONF_BGRAPHICS
,
200 CONF_BCOORDS
, CONF_BMOVESW
, CONF_BMOVESB
, CONF_BCOUNT
, CONF_BDWINDOW
,
201 CONF_TWINDOW
, CONF_TTITLE
, CONF_TBORDER
,
202 CONF_SWINDOW
, CONF_STITLE
, CONF_SBORDER
, CONF_SNOTIFY
, CONF_SENGINE
,
203 CONF_HWINDOW
, CONF_HTITLE
, CONF_HBORDER
,
204 CONF_MWINDOW
, CONF_MTITLE
, CONF_MBORDER
, CONF_MPROMPT
,
205 CONF_IWINDOW
, CONF_ITITLE
, CONF_IBORDER
, CONF_IPROMPT
,
212 int attrs
; /* Attributes for a color terminal. */
213 int nattrs
; /* Attributes for a non-color terminal. */
227 char ics_server
[MAXHOSTNAMELEN
];
241 struct colors color
[CONF_MAX_COLORS
];
247 PGN_FILE
, FEN_FILE
, EPD_FILE
250 /* Chess engine file descriptors. 0 = from, 1 = to. */
255 int curses_initialized
;
256 char loadfile
[FILENAME_MAX
];
258 int gindex
, gtotal
; /* Current game and total number of games. */
259 int engine_initialized
;
260 int oldhistorytotal
; /* This is a failsafe when resuming a game. */
265 FIELD_TYPE_ALNUM
, FIELD_TYPE_ALPHA
, FIELD_TYPE_INTEGER
,
266 FIELD_TYPE_NUMERIC
, FIELD_TYPE_REGEXP
, FIELD_TYPE_IPV4
, FIELD_TYPE_ENUM
,
267 FIELD_TYPE_PGN_TAG_NAME
, FIELD_TYPE_PGN_DATE
, FIELD_TYPE_PGN_ROUND
270 char *get_input(const char *, const char *, int, int, const char *,
271 char *(*)(void *), void *, chtype
, int, ...);
272 void *Calloc(size_t, size_t);
273 void *Realloc(void *, size_t);
274 int dump_message(const char *, const char *, int, const char *,
275 void (*)(void *), void *, int, const char *, ...);
279 #define DUMP(fmt, args...) (write_debug_output(0, fmt, ## args))
280 #define DUMP_F(fmt, args...) (write_debug_output(1, fmt, ## args))
281 void write_debug_output(int, const char *, ...);
282 void dump_board(int, BOARD
);
283 void dump_flags(int);