Changed the 'help' string after pressing F1 to 'more help' since it
[cboard.git] / src / rcfile.c
blob65c202eb9acbd195b73ce83588b6883ea7c39f5d
1 /* vim:tw=78:ts=8:sw=4:set ft=c: */
2 /*
3 Copyright (C) 2002-2007 Ben Kibbey <bjk@luxsci.net>
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
19 #include <stdio.h>
20 #include <stdlib.h>
21 #include <string.h>
22 #include <ctype.h>
23 #include <sys/types.h>
24 #include <sys/stat.h>
25 #include <errno.h>
26 #include <err.h>
28 #ifdef HAVE_CONFIG_H
29 #include <config.h>
30 #endif
32 #ifdef HAVE_CURSES_H
33 #include <curses.h>
34 #endif
36 #ifdef HAVE_STRINGS_H
37 #include <strings.h>
38 #endif
40 #include "chess.h"
41 #include "conf.h"
42 #include "misc.h"
43 #include "colors.h"
44 #include "keys.h"
45 #include "rcfile.h"
47 #ifdef WITH_DMALLOC
48 #include <dmalloc.h>
49 #endif
51 static int attributes(const char *filename, int line, char *str)
53 char *tmp;
54 int attrs = 0;
56 while ((tmp = strsep(&str, ",")) != NULL) {
57 if (strcasecmp(tmp, "BOLD") == 0)
58 attrs |= A_BOLD;
59 else if (strcasecmp(tmp, "REVERSE") == 0)
60 attrs |= A_REVERSE;
61 else if (strcasecmp(tmp, "NONE") == 0)
62 attrs |= A_NORMAL;
63 else if (strcasecmp(tmp, "DIM") == 0)
64 attrs |= A_DIM;
65 else if (strcasecmp(tmp, "STANDOUT") == 0)
66 attrs |= A_STANDOUT;
67 else if (strcasecmp(tmp, "UNDERLINE") == 0)
68 attrs |= A_UNDERLINE;
69 else if (strcasecmp(tmp, "BLINK") == 0)
70 attrs |= A_BLINK;
71 else if (strcasecmp(tmp, "INVISIBLE") == 0)
72 attrs |= A_INVIS;
73 else
74 errx(EXIT_FAILURE, "%s(%i): invalid attribute \"%s\"", filename,
75 line, tmp);
78 return attrs;
81 static short color_name(const char *filename, int line, const char *color)
83 if (strcasecmp(color, "BLACK") == 0)
84 return COLOR_BLACK;
85 else if (strcasecmp(color, "WHITE") == 0)
86 return COLOR_WHITE;
87 else if (strcasecmp(color, "GREEN") == 0)
88 return COLOR_GREEN;
89 else if (strcasecmp(color, "YELLOW") == 0)
90 return COLOR_YELLOW;
91 else if (strcasecmp(color, "MAGENTA") == 0)
92 return COLOR_MAGENTA;
93 else if (strcasecmp(color, "BLUE") == 0)
94 return COLOR_BLUE;
95 else if (strcasecmp(color, "RED") == 0)
96 return COLOR_RED;
97 else if (strcasecmp(color, "CYAN") == 0)
98 return COLOR_CYAN;
99 else if (strcasecmp(color, "-") == 0)
101 else
102 errx(EXIT_FAILURE, "%s(%i): invalid color \"%s\"", filename, line,
103 color);
105 return -1;
108 static void parse_color(const char *filename, int line, const char *str,
109 struct color_s *c)
111 char fg[16], bg[16], attr[64], nattr[64];
112 int n;
114 if ((n = sscanf(str, "%[a-zA-Z-] %[a-zA-Z-] %[a-zA-Z,-] %[a-zA-Z,-]", fg, bg,
115 attr, nattr)) < 2)
116 errx(EXIT_FAILURE, "%s(%i): parse error", filename, line);
118 if ((n = color_name(filename, line, fg)) >= 0)
119 c->fg = n;
121 if ((n = color_name(filename, line, bg)) >= 0)
122 c->bg = n;
124 c->attrs = c->nattrs = 0;
126 if (n > 2)
127 c->attrs = attributes(filename, line, attr);
129 if (n > 3)
130 c->nattrs = attributes(filename, line, nattr);
133 static int on_or_off(const char *filename, int lines, const char *str)
135 if (strcasecmp(str, "on") == 0 || strcasecmp(str, "1") == 0 ||
136 strcasecmp(str, "yes") == 0 || strcasecmp(str, "true") == 0)
137 return 1;
139 if (strcasecmp(str, "off") == 0 || strcasecmp(str, "0") == 0 ||
140 strcasecmp(str, "no") == 0 || strcasecmp(str, "false") == 0)
141 return 0;
143 errx(EXIT_FAILURE, "%s(%i): invalid value \"%s\"", filename, lines, str);
146 void copydatafile(const char *dst, const char *src)
148 FILE *fp, *ofp;
149 char buf[LINE_MAX], *s;
151 snprintf(buf, sizeof(buf), "%s/%s", DATA_PATH, src);
153 if ((fp = fopen(buf, "r")) == NULL) {
154 if (errno != ENOENT)
155 warn("%s", buf);
156 return;
159 if ((ofp = fopen(dst, "w+")) == NULL) {
160 fclose(fp);
161 warn("%s", dst);
162 return;
165 while ((s = fgets(buf, sizeof(buf), fp)) != NULL)
166 fprintf(ofp, "%s", s);
168 fclose(fp);
169 fclose(ofp);
172 static char *fancy_key_name(int c)
174 static char buf[12];
175 char *p;
177 strncpy(buf, keyname(c), sizeof(buf));
178 p = buf;
180 if (*p == '^' && *(p + 1) == '[')
181 return "Escape";
183 if (*p == '^' && *(p + 1) == 'J')
184 return "Enter";
186 if (strncasecmp(p, "KEY_", 4) == 0) {
187 for (p = buf; *p; p++)
188 *p = tolower(*p);
190 p = buf;
191 p += 4;
193 if (*p == 'f') {
194 char *t = buf + 4;
196 p += 2;
198 while (isdigit(*p))
199 *++t = *p++;
201 *++t = 0;
202 p = buf + 4;
204 else if (strcmp(p, "ppage") == 0)
205 return "PgUp";
206 else if (strcmp(p, "npage") == 0)
207 return "PgDown";
209 *p = toupper(*p);
210 return p;
213 if (*p == ' ')
214 return "Space";
216 return p;
219 void add_key_binding(struct key_s ***dst, key_func *func, int c, char *desc,
220 int repeat)
222 int i = 0;
223 struct key_s **k = *dst;
225 if (k)
226 for (i = 0; k[i]; i++);
228 k = Realloc(k, (i + 2) * sizeof(struct key_s *));
229 k[i] = Calloc(1, sizeof(struct key_s));
230 k[i]->f = func;
231 k[i]->c = c;
232 k[i]->r = repeat;
233 k[i]->key = strdup(fancy_key_name(c));
235 if (desc)
236 k[i]->d = strdup(desc);
238 i++;
239 k[i] = NULL;
240 *dst = k;
243 void set_default_keys()
245 add_key_binding(&history_keys, do_history_jump_next, KEY_UP, "history jump next", 1);
246 add_key_binding(&history_keys, do_history_jump_prev, KEY_DOWN, "history jump previous", 1);
247 add_key_binding(&history_keys, do_history_next, KEY_RIGHT, "next move", 1);
248 add_key_binding(&history_keys, do_history_prev, KEY_LEFT, "previous move", 1);
249 add_key_binding(&history_keys, do_history_half_move_toggle, ' ', "toggle half move (ply) stepping", 0);
250 add_key_binding(&history_keys, do_history_jump, 'j', "jump to move number", 1);
251 add_key_binding(&history_keys, do_history_find_new, '/', "new move text expression", 0);
252 add_key_binding(&history_keys, do_history_find_next, ']', "find next move text expression", 1);
253 add_key_binding(&history_keys, do_history_find_prev, '[', "find previous move text expression", 1);
254 add_key_binding(&history_keys, do_history_annotate, CTRL('a'), "annotate the previous move", 0);
255 add_key_binding(&history_keys, do_history_rav_next, '+', "next variation of the previous move", 0);
256 add_key_binding(&history_keys, do_history_rav_prev, '-', "previous variation of the previous move", 0);
257 add_key_binding(&history_keys, do_history_menu, 'M', "move history tree", 0);
258 add_key_binding(&history_keys, do_history_help, KEY_F(1), "more help", 0);
259 add_key_binding(&history_keys, do_history_help, CTRL('g'), NULL, 0);
260 add_key_binding(&history_keys, do_history_toggle, 'h', "exit history mode", 0);
262 add_key_binding(&edit_keys, do_edit_select, ' ', "select piece for movement", 0);
263 add_key_binding(&edit_keys, do_edit_commit, '\n', "commit selected piece", 0);
264 add_key_binding(&edit_keys, do_edit_cancel_selected, KEY_ESCAPE, "cancel selected piece", 0);
265 add_key_binding(&edit_keys, do_edit_delete, 'd', "remove the piece under the cursor", 0);
266 add_key_binding(&edit_keys, do_edit_insert, 'i', "insert piece", 0);
267 add_key_binding(&edit_keys, do_edit_toggle_castle, 'c', "toggle castling availability", 0);
268 add_key_binding(&edit_keys, do_edit_enpassant, 'p', "toggle enpassant square", 0);
269 add_key_binding(&edit_keys, do_edit_switch_turn, 'w', "toggle turn", 0);
270 add_key_binding(&edit_keys, do_edit_help, KEY_F(1), "more help", 0);
271 add_key_binding(&history_keys, do_edit_help, CTRL('g'), NULL, 0);
272 add_key_binding(&edit_keys, do_edit_exit, 'e', "exit edit mode", 0);
274 add_key_binding(&play_keys, do_play_select, ' ', "select piece for movement", 0);
275 add_key_binding(&play_keys, do_play_commit, '\n', "commit selected piece", 0);
276 add_key_binding(&play_keys, do_play_cancel_selected, KEY_ESCAPE, "cancel selected piece", 0);
277 add_key_binding(&play_keys, do_play_set_clock, 'C', "set clock", 0);
278 add_key_binding(&play_keys, do_play_switch_turn, 'w', "switch turn", 0);
279 add_key_binding(&play_keys, do_play_undo, 'u', "undo previous move", 1);
280 add_key_binding(&play_keys, do_play_go, 'g', "force the chess engine to make the next move", 0);
281 add_key_binding(&play_keys, do_play_send_command, '|', "send a command to the chess engine", 0);
282 add_key_binding(&play_keys, do_play_toggle_engine, 'E', "toggle engine/engine play", 0);
283 add_key_binding(&play_keys, do_play_toggle_human, 'H', "toggle human/human play", 0);
284 add_key_binding(&play_keys, do_play_toggle_pause, 'p', "toggle pausing of this game", 0);
285 add_key_binding(&play_keys, do_play_history_mode, 'h', "enter history mode", 0);
286 add_key_binding(&play_keys, do_play_edit_mode, 'e', "enter edit mode", 0);
287 add_key_binding(&play_keys, do_play_help, KEY_F(1), "more help", 0);
288 add_key_binding(&play_keys, do_play_help, CTRL('g'), NULL, 0);
290 add_key_binding(&global_keys, do_global_tag_edit, CTRL('t'), "edit roster tags", 0);
291 add_key_binding(&global_keys, do_global_tag_view, 't', "view roster tags", 0);
292 add_key_binding(&global_keys, do_global_find_new, '?', "new find game expression", 0);
293 add_key_binding(&global_keys, do_global_find_next, '}', "find next game", 1);
294 add_key_binding(&global_keys, do_global_find_prev, '{', "find previous game", 1);
295 add_key_binding(&global_keys, do_global_new_game, CTRL('n'), "new game or round", 0);
296 add_key_binding(&global_keys, do_global_new_all, CTRL('k'), "new game from scratch", 0);
297 add_key_binding(&global_keys, do_global_copy_game, CTRL('i'), "copy current game", 0);
298 add_key_binding(&global_keys, do_global_next_game, '>', "next game", 1);
299 add_key_binding(&global_keys, do_global_prev_game, '<', "previous game", 1);
300 add_key_binding(&global_keys, do_global_game_jump, 'J', "jump to game", 1);
301 add_key_binding(&global_keys, do_global_toggle_delete, 'X', "toggle delete flag", 1);
302 add_key_binding(&global_keys, do_global_delete_game, CTRL('X'), "delete the current or flagged games", 0);
303 add_key_binding(&global_keys, do_global_resume_game, CTRL('r'), "load a PGN file", 0);
304 add_key_binding(&global_keys, do_global_save_game, 's', "save game", 0);
305 add_key_binding(&global_keys, do_global_toggle_board_details, CTRL('d'), "toggle board details", 0);
306 add_key_binding(&global_keys, do_global_toggle_strict_castling, CTRL('p'), "toggle strict castling", 0);
307 add_key_binding(&global_keys, do_global_toggle_engine_window, 'W', "toggle chess engine IO window", 0);
308 #ifdef WITH_LIBPERL
309 add_key_binding(&global_keys, do_global_perl, CTRL('O'), "Call PERL subroutine", 0);
310 #endif
311 add_key_binding(&global_keys, do_global_about, KEY_F(10), "version information", 0);
312 add_key_binding(&global_keys, do_global_quit, 'Q', "quit", 0);
315 void set_config_defaults()
317 struct stat st;
319 config.pattern = strdup("*.[Pp][Gg][Nn]*");
320 config.engine_cmd = strdup("gnuchess --xboard");
321 config.engine_protocol = 1;
322 config.jumpcount = 5;
323 config.linegraphics = 1;
324 config.saveprompt = 1;
325 config.deleteprompt = 1;
326 config.validmoves = 1;
327 config.details = 1;
329 set_default_colors();
331 if (stat(config.nagfile, &st) == -1) {
332 if (errno == ENOENT)
333 copydatafile(config.nagfile, "nag.data");
334 else
335 warn("%s", config.nagfile);
338 if (stat(config.ccfile, &st) == -1) {
339 if (errno == ENOENT)
340 copydatafile(config.ccfile, "cc.data");
341 else
342 warn("%s", config.ccfile);
346 static void update_key(struct key_s **dst, struct custom_key_s config_key,
347 int c, char *desc)
349 int i;
351 for (i = 0; dst[i]; i++) {
352 if (dst[i]->f == config_key.func) {
353 dst[i]->c = c;
355 if (dst[i]->key)
356 free(dst[i]->key);
358 dst[i]->key = strdup(fancy_key_name(c));
360 if (desc && dst[i]->d)
361 free(dst[i]->d);
363 if (desc)
364 dst[i]->d = strdup(desc);
366 goto done;
370 add_key_binding(&dst, config_key.func, c, (desc) ? desc : "no description",
371 config_key.r);
373 done:
374 return;
377 static int parse_key(const char *filename, int lines, char **key)
379 char *p = *key;
380 char *orig = *key;
381 int c = 0;
383 if (!key || !key[0])
384 return 0;
386 if (*p == '\"') {
387 if (orig[strlen(orig) - 1] != '\"')
388 errx(EXIT_FAILURE, "%s(%i): unbalanced quotes", filename, lines);
390 p++;
391 orig[strlen(orig) - 1] = 0;
394 if (*p == '<') {
395 p++;
397 if (strncasecmp(p, "up", 2) == 0) {
398 c = KEY_UP;
399 p += 2;
401 else if (strncasecmp(p, "down", 4) == 0) {
402 c = KEY_DOWN;
403 p += 4;
405 else if (strncasecmp(p, "left", 4) == 0) {
406 c = KEY_LEFT;
407 p += 4;
409 else if (strncasecmp(p, "right", 5) == 0) {
410 c = KEY_RIGHT;
411 p += 5;
413 else if (strncasecmp(p, "home", 4) == 0) {
414 c = KEY_HOME;
415 p += 4;
417 else if (strncasecmp(p, "end", 3) == 0) {
418 c = KEY_END;
419 p += 3;
421 else if (strncasecmp(p, "delete", 6) == 0) {
422 c = KEY_DC;
423 p += 6;
425 else if (strncasecmp(p, "pgup", 4) == 0) {
426 c = KEY_PPAGE;
427 p += 4;
429 else if (strncasecmp(p, "pgdn", 4) == 0) {
430 c = KEY_NPAGE;
431 p += 4;
433 else if (strncasecmp(p, "insert", 5) == 0) {
434 c = KEY_IC;
435 p += 5;
437 else if (strncasecmp(p, "space", 5) == 0) {
438 c = ' ';
439 p += 5;
441 else if (strncasecmp(p, "escape", 6) == 0) {
442 c = KEY_ESCAPE;
443 p += 6;
445 else if (strncasecmp(p, "enter", 5) == 0) {
446 c = '\n';
447 p += 5;
449 else if (*p == '^') {
450 p++;
451 c = CTRL(*p++);
453 else if (*p == 'F' || *p == 'f') {
454 c = KEY_F(atoi(++p));
455 p += integer_len(atoi(p));
458 if (!c)
459 c = *p++;
461 if (*p++ != '>')
462 errx(EXIT_FAILURE, "%s(%i): parse error \"%s\"", filename, lines,
463 orig);
465 else if (*p == '\\') {
466 p++;
467 c = *p++;
469 else
470 c = *p++;
472 orig += strlen(orig) - strlen(p);
473 *key = orig;
474 return c;
477 static void parse_key_binding(const char *filename, int lines, char *val)
479 char mode[64], key[16], func[64], desc[64];
480 int n;
481 int m = 0;
482 int c = 0;
483 int f;
484 int i;
485 char *p;
487 n = sscanf(val, "%s %s %s %s", mode, key, func, desc);
489 if (n < 3)
490 errx(EXIT_FAILURE, "%s(%i): too few arguments", filename, lines);
492 if (strcasecmp(mode, "history") == 0)
493 m = MODE_HISTORY;
494 else if (strcasecmp(mode, "play") == 0)
495 m = MODE_PLAY;
496 else if (strcasecmp(mode, "edit") == 0)
497 m = MODE_EDIT;
498 else
499 errx(EXIT_FAILURE, "%s(%i): invalid game mode \"%s\"", filename, lines,
500 mode);
502 p = key;
503 c = parse_key(filename, lines, &p);
505 if (m != -1) {
506 for (i = 0; global_keys[i]; i++) {
507 if (global_keys[i]->c == c)
508 errx(EXIT_FAILURE, "%s(%i): key \"%s\" conflicts with a global "
509 "key", filename, lines, key);
513 for (f = -2, i = 0; config_keys[i].name; i++) {
514 if (strcmp(config_keys[i].name, func) == 0 &&
515 config_keys[i].mode == m) {
516 f = i;
517 break;
521 if (f == -2)
522 errx(EXIT_FAILURE, "%s(%i): invalid command \"%s\"", filename, lines,
523 func);
525 switch (m) {
526 case MODE_PLAY:
527 update_key(play_keys, config_keys[f], c, (n > 3) ? desc : NULL);
528 break;
529 case MODE_HISTORY:
530 update_key(history_keys, config_keys[f], c, (n > 3) ? desc : NULL);
531 break;
532 case MODE_EDIT:
533 update_key(edit_keys, config_keys[f], c, (n > 3) ? desc : NULL);
534 break;
535 default:
536 update_key(global_keys, config_keys[f], c, (n > 3) ? desc : NULL);
537 break;
541 static void parse_macro(const char *filename, int lines, char *val)
543 char mode[16], key[8], keys[256] = {0};
544 int n;
545 int m;
546 int c;
547 int i = 0;
548 char *p;
550 n = sscanf(val, "%s %s %255c", mode, key, keys);
552 if (n != 3)
553 errx(EXIT_FAILURE, "%s(%i): too few arguments", filename, lines);
555 if (strcasecmp(mode, "history") == 0)
556 m = MODE_HISTORY;
557 else if (strcasecmp(mode, "play") == 0)
558 m = MODE_PLAY;
559 else if (strcasecmp(mode, "edit") == 0)
560 m = MODE_EDIT;
561 else if (strcasecmp(mode, "any") == 0)
562 m = -1;
563 else
564 errx(EXIT_FAILURE, "%s(%i): invalid game mode \"%s\"", filename, lines,
565 mode);
567 p = key;
568 c = parse_key(filename, lines, &p);
570 if (macros)
571 for (i = 0; macros[i]; i++);
573 macros = Realloc(macros, (i + 2) * sizeof(struct macro_s));
574 macros[i] = Calloc(1, sizeof(struct macro_s));
575 macros[i]->c = c;
576 macros[i]->mode = m;
577 p = keys;
579 while ((c = parse_key(filename, lines, &p)) != 0) {
580 macros[i]->keys = Realloc(macros[i]->keys, (macros[i]->total + 2) *
581 sizeof(int));
582 macros[i]->keys[macros[i]->total++] = c;
585 macros[++i] = NULL;
588 void parse_rcfile(const char *filename)
590 FILE *fp;
591 char *line, buf[LINE_MAX];
592 int lines = 0;
593 char *altengine = NULL;
594 int init = 0;
595 int k = 0;
596 int c;
598 if ((fp = fopen(filename, "r")) == NULL)
599 err(EXIT_FAILURE, "%s", filename);
601 while ((line = fgets(buf, sizeof(buf), fp)) != NULL) {
602 int n;
603 char var[30], val[LINE_MAX - sizeof(var) - 1];
604 char token[MAX_PGN_LINE_LEN + 1], value[MAX_PGN_LINE_LEN + 1];
605 char *p;
607 lines++;
608 line = trim(line);
610 if (!line[0] || line[0] == '#')
611 continue;
613 if ((n = sscanf(line, "%s %[^\n]", var, val)) != 2)
614 errx(EXIT_FAILURE, "%s(%i): parse error %i", filename, lines,n);
616 p = strdup(trim(val));
617 strncpy(val, p, sizeof(val));
618 free(p);
619 p = strdup(trim(var));
620 strncpy(var, p, sizeof(var));
621 free(p);
623 if (strcmp(var, "jump_count") == 0) {
624 if (!isinteger(val))
625 errx(EXIT_FAILURE, "%s(%i): value is not an integer", filename,
626 lines);
628 config.jumpcount = atoi(val);
630 else if (strcmp(var, "engine_init") == 0) {
631 config.einit = Realloc(config.einit, (init + 2) * sizeof(char *));
632 config.einit[init++] = strdup(val);
633 config.einit[init] = NULL;
635 else if (strcmp(var, "pattern") == 0) {
636 free(config.pattern);
637 config.pattern = strdup(val);
639 else if (strcmp(var, "mpl") == 0) {
640 if (!isinteger(val))
641 errx(EXIT_FAILURE, "%s(%i): value is not an integer", filename,
642 lines);
643 pgn_config_set(PGN_MPL, atoi(val));
645 else if (strcmp(var, "stop_on_error") == 0)
646 pgn_config_set(PGN_STOP_ON_ERROR, on_or_off(filename, lines, val));
647 else if (strcmp(var, "tag") == 0) {
648 if ((n = sscanf(val, "%s %s ", token, value)) < 1 ||
649 n > 2)
650 errx(EXIT_FAILURE, "%s(%i): invalid value \"%s\"", filename,
651 lines, val);
653 if (n == 1)
654 value[0] = 0;
655 else {
656 p = val + strlen(token);
657 strncpy(value, p, sizeof(value));
660 for (n = 0; n < strlen(token); n++) {
661 if (!isalnum(token[n]) && token[n] != '_')
662 errx(EXIT_FAILURE,
663 "%s(%i): token names must match 0-9A-Za-z_.",
664 filename, lines);
667 token[0] = toupper(token[0]);
668 pgn_tag_add(&config.tag, token, value);
670 else if (strcmp(var, "save_directory") == 0)
671 config.savedirectory = strdup(val);
672 else if (strcmp(var, "line_graphics") == 0)
673 config.linegraphics = on_or_off(filename, lines, val);
674 else if (strcmp(var, "save_prompt") == 0)
675 config.saveprompt = on_or_off(filename, lines, val);
676 else if (strcmp(var, "delete_prompt") == 0)
677 config.deleteprompt = on_or_off(filename, lines, val);
678 else if (strcmp(var, "valid_moves") == 0)
679 config.validmoves = on_or_off(filename, lines, val);
680 else if (strcmp(var, "board_details") == 0)
681 config.details = on_or_off(filename, lines, val);
682 else if (strcmp(var, "strict_castling") == 0)
683 pgn_config_set(PGN_STRICT_CASTLING, on_or_off(filename, lines, val));
684 else if (strcmp(var, "engine_cmd") == 0)
685 altengine = strdup(val);
686 else if (strcmp(var, "engine_protocol") == 0) {
687 if (!isinteger(val))
688 errx(EXIT_FAILURE, "%s(%i): value is not an integer", filename,
689 lines);
691 config.engine_protocol = atoi(val);
693 if (config.engine_protocol != 1 && config.engine_protocol != 2)
694 errx(EXIT_FAILURE, "%s(%i): invalid value", filename, lines);
696 else if (strcmp(var, "color_board_window") == 0)
697 parse_color(filename, lines, val, &config.color[CONF_BDWINDOW]);
698 else if (strcmp(var, "color_board_selected") == 0)
699 parse_color(filename, lines, val, &config.color[CONF_BSELECTED]);
700 else if (strcmp(var, "color_board_white_moves") == 0)
701 parse_color(filename, lines, val, &config.color[CONF_BMOVESW]);
702 else if (strcmp(var, "color_board_black_moves") == 0)
703 parse_color(filename, lines, val, &config.color[CONF_BMOVESB]);
704 else if (strcmp(var, "color_board_count") == 0)
705 parse_color(filename, lines, val, &config.color[CONF_BCOUNT]);
706 else if (strcmp(var, "color_board_cursor") == 0)
707 parse_color(filename, lines, val, &config.color[CONF_BCURSOR]);
708 else if (strcmp(var, "color_board_black") == 0)
709 parse_color(filename, lines, val, &config.color[CONF_BBLACK]);
710 else if (strcmp(var, "color_board_white") == 0)
711 parse_color(filename, lines, val, &config.color[CONF_BWHITE]);
712 else if (strcmp(var, "color_board_graphics") == 0)
713 parse_color(filename, lines, val, &config.color[CONF_BGRAPHICS]);
714 else if (strcmp(var, "color_board_coords") == 0)
715 parse_color(filename, lines, val, &config.color[CONF_BCOORDS]);
716 else if (strcmp(var, "color_board_castling") == 0)
717 parse_color(filename, lines, val, &config.color[CONF_BCASTLING]);
718 else if (strcmp(var, "color_board_enpassant") == 0)
719 parse_color(filename, lines, val, &config.color[CONF_BENPASSANT]);
720 else if (strcmp(var, "color_status_window") == 0)
721 parse_color(filename, lines, val, &config.color[CONF_SWINDOW]);
722 else if (strcmp(var, "color_status_title") == 0)
723 parse_color(filename, lines, val, &config.color[CONF_STITLE]);
724 else if (strcmp(var, "color_status_border") == 0)
725 parse_color(filename, lines, val, &config.color[CONF_SBORDER]);
726 else if (strcmp(var, "color_status_notify") == 0)
727 parse_color(filename, lines, val, &config.color[CONF_SNOTIFY]);
728 else if (strcmp(var, "color_status_engine") == 0)
729 parse_color(filename, lines, val, &config.color[CONF_SENGINE]);
730 else if (strcmp(var, "color_tag_window") == 0)
731 parse_color(filename, lines, val, &config.color[CONF_TWINDOW]);
732 else if (strcmp(var, "color_tag_title") == 0)
733 parse_color(filename, lines, val, &config.color[CONF_TTITLE]);
734 else if (strcmp(var, "color_tag_border") == 0)
735 parse_color(filename, lines, val, &config.color[CONF_TBORDER]);
736 else if (strcmp(var, "color_history_window") == 0)
737 parse_color(filename, lines, val, &config.color[CONF_HWINDOW]);
738 else if (strcmp(var, "color_history_title") == 0)
739 parse_color(filename, lines, val, &config.color[CONF_HTITLE]);
740 else if (strcmp(var, "color_history_border") == 0)
741 parse_color(filename, lines, val, &config.color[CONF_HBORDER]);
742 else if (strcmp(var, "color_message_window") == 0)
743 parse_color(filename, lines, val, &config.color[CONF_MWINDOW]);
744 else if (strcmp(var, "color_message_title") == 0)
745 parse_color(filename, lines, val, &config.color[CONF_MTITLE]);
746 else if (strcmp(var, "color_message_border") == 0)
747 parse_color(filename, lines, val, &config.color[CONF_MBORDER]);
748 else if (strcmp(var, "color_message_prompt") == 0)
749 parse_color(filename, lines, val, &config.color[CONF_MPROMPT]);
750 else if (strcmp(var, "color_input_window") == 0)
751 parse_color(filename, lines, val, &config.color[CONF_IWINDOW]);
752 else if (strcmp(var, "color_input_title") == 0)
753 parse_color(filename, lines, val, &config.color[CONF_ITITLE]);
754 else if (strcmp(var, "color_input_border") == 0)
755 parse_color(filename, lines, val, &config.color[CONF_IBORDER]);
756 else if (strcmp(var, "color_input_prompt") == 0)
757 parse_color(filename, lines, val, &config.color[CONF_IPROMPT]);
758 else if (strcmp(var, "color_menu") == 0)
759 parse_color(filename, lines, val, &config.color[CONF_MENU]);
760 else if (strcmp(var, "color_menu_selected") == 0)
761 parse_color(filename, lines, val, &config.color[CONF_MENUS]);
762 else if (strcmp(var, "color_menu_highlight") == 0)
763 parse_color(filename, lines, val, &config.color[CONF_MENUH]);
764 else if (strcmp(var, "color_menu_graphics") == 0)
765 parse_color(filename, lines, val,
766 &config.color[CONF_HISTORY_MENU_LG]);
767 else if (strcmp(var, "bind") == 0)
768 parse_key_binding(filename, lines, val);
769 else if (strcmp(var, "macro") == 0)
770 parse_macro(filename, lines, val);
771 else if (strcmp(var, "cbind") == 0) {
772 config.keys = Realloc(config.keys, (k + 2) *
773 sizeof(struct config_key_s *));
774 config.keys[k] = Calloc(1, sizeof(struct config_key_s));
775 p = val;
776 n = 0;
778 while (*p && !isspace(*p))
779 p++, n++;
781 c = *p;
782 *p = 0;
783 p -= n;
785 if (strcasecmp(p, "none") == 0)
786 config.keys[k]->type = KEY_DEFAULT;
787 else if (strcasecmp(p, "repeat") == 0)
788 config.keys[k]->type = KEY_REPEAT;
789 else if (strcasecmp(p, "set") == 0)
790 config.keys[k]->type = KEY_SET;
791 else
792 errx(EXIT_FAILURE, "%s(%i): invalid value \"%s\"", filename,
793 lines, p);
795 p = val + n;
796 *p = c;
798 while (*p && isspace(*p))
799 p++;
801 config.keys[k]->c = *p++;
803 while (isspace(*p))
804 p++;
806 config.keys[k++]->str = strdup(p);
807 config.keys[k] = NULL;
809 else
810 errx(EXIT_FAILURE, "%s(%i): invalid parameter \"%s\"", filename,
811 lines, var);
814 fclose(fp);
816 if (altengine) {
817 free(config.engine_cmd);
818 config.engine_cmd = NULL;
819 config.engine_cmd = altengine;