1 /* vim:tw=78:ts=8:sw=4:set ft=c: */
3 Copyright (C) 2002-2018 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
27 #include <sys/types.h>
45 attributes (const char *filename
, int line
, char *str
)
50 while ((tmp
= strsep (&str
, ",")) != NULL
)
52 if (strcasecmp (tmp
, "BOLD") == 0)
54 else if (strcasecmp (tmp
, "REVERSE") == 0)
56 else if (strcasecmp (tmp
, "NONE") == 0)
58 else if (strcasecmp (tmp
, "DIM") == 0)
60 else if (strcasecmp (tmp
, "STANDOUT") == 0)
62 else if (strcasecmp (tmp
, "UNDERLINE") == 0)
64 else if (strcasecmp (tmp
, "BLINK") == 0)
66 else if (strcasecmp (tmp
, "INVISIBLE") == 0)
69 errx (EXIT_FAILURE
, _("%s(%i): invalid attribute \"%s\""), filename
,
77 color_name (const char *filename
, int line
, const char *color
)
79 if (strcasecmp (color
, "BLACK") == 0)
81 else if (strcasecmp (color
, "WHITE") == 0)
83 else if (strcasecmp (color
, "GREEN") == 0)
85 else if (strcasecmp (color
, "YELLOW") == 0)
87 else if (strcasecmp (color
, "MAGENTA") == 0)
89 else if (strcasecmp (color
, "BLUE") == 0)
91 else if (strcasecmp (color
, "RED") == 0)
93 else if (strcasecmp (color
, "CYAN") == 0)
95 else if (strcasecmp (color
, "-") == 0)
98 errx (EXIT_FAILURE
, _("%s(%i): invalid color \"%s\""), filename
, line
,
105 parse_color (const char *filename
, int line
, const char *str
,
108 char fg
[16], bg
[16], attr
[64], nattr
[64];
112 sscanf (str
, "%[a-zA-Z-] %[a-zA-Z-] %[a-zA-Z,-] %[a-zA-Z,-]", fg
, bg
,
114 errx (EXIT_FAILURE
, _("%s(%i): parse error"), filename
, line
);
116 if ((n
= color_name (filename
, line
, fg
)) >= 0)
119 if ((n
= color_name (filename
, line
, bg
)) >= 0)
122 c
->attrs
= c
->nattrs
= 0;
125 c
->attrs
= attributes (filename
, line
, attr
);
128 c
->nattrs
= attributes (filename
, line
, nattr
);
132 on_or_off (const char *filename
, int lines
, const char *str
)
134 if (strcasecmp (str
, "on") == 0 || strcasecmp (str
, "1") == 0 ||
135 strcasecmp (str
, "yes") == 0 || strcasecmp (str
, "true") == 0)
138 if (strcasecmp (str
, "off") == 0 || strcasecmp (str
, "0") == 0 ||
139 strcasecmp (str
, "no") == 0 || strcasecmp (str
, "false") == 0)
142 errx (EXIT_FAILURE
, _("%s(%i): invalid value \"%s\""), filename
, lines
,
147 copydatafile (const char *dst
, const char *src
)
150 char buf
[LINE_MAX
], *s
;
152 snprintf (buf
, sizeof (buf
), "%s/%s", DATA_PATH
, src
);
154 if ((fp
= fopen (buf
, "r")) == NULL
)
161 if ((ofp
= fopen (dst
, "w+")) == NULL
)
168 while ((s
= fgets (buf
, sizeof (buf
), fp
)) != NULL
)
169 fprintf (ofp
, "%s", s
);
176 fancy_key_name (wint_t c
)
178 static char buf
[64] = { 0 };
181 strncpy (buf
, keyname (c
) ? keyname (c
) : key_name (c
), sizeof (buf
) - 1);
184 if (*p
== '^' && *(p
+ 1) == '[')
187 if (*p
== '^' && *(p
+ 1) == 'J')
190 if (strncasecmp (p
, "KEY_", 4) == 0)
192 for (p
= buf
; *p
; p
++)
210 else if (strcmp (p
, "ppage") == 0)
212 else if (strcmp (p
, "npage") == 0)
226 add_key_binding (struct key_s
***dst
, key_func
* func
, wint_t c
,
227 char *desc
, int repeat
)
230 struct key_s
**k
= *dst
;
233 for (i
= 0; k
[i
]; i
++);
235 k
= Realloc (k
, (i
+ 2) * sizeof (struct key_s
*));
236 k
[i
] = Calloc (1, sizeof (struct key_s
));
240 k
[i
]->key
= str_to_wchar (fancy_key_name (c
));
243 k
[i
]->d
= str_to_wchar (desc
);
253 add_key_binding (&history_keys
, do_history_jump_next
, KEY_UP
,
254 _("history jump next"), 1);
255 add_key_binding (&history_keys
, do_history_jump_prev
, KEY_DOWN
,
256 _("history jump previous"), 1);
257 add_key_binding (&history_keys
, do_history_next
, KEY_RIGHT
, _("next move"),
259 add_key_binding (&history_keys
, do_history_prev
, KEY_LEFT
,
260 _("previous move"), 1);
261 add_key_binding (&history_keys
, do_history_half_move_toggle
, ' ',
262 _("toggle half move (ply) stepping"), 0);
263 add_key_binding (&history_keys
, do_history_rotate_board
, 'r',
264 _("rotate board"), 0);
265 add_key_binding (&history_keys
, do_history_jump
, 'j',
266 _("jump to move number"), 1);
267 add_key_binding (&history_keys
, do_history_find_new
, '/',
268 _("new move text expression"), 0);
269 add_key_binding (&history_keys
, do_history_find_next
, ']',
270 _("find next move text expression"), 1);
271 add_key_binding (&history_keys
, do_history_find_prev
, '[',
272 _("find previous move text expression"), 1);
273 add_key_binding (&history_keys
, do_history_annotate
, CTRL_KEY ('a'),
274 _("annotate the previous move"), 0);
275 add_key_binding (&history_keys
, do_history_rav_next
, '+',
276 _("next variation of the previous move"), 0);
277 add_key_binding (&history_keys
, do_history_rav_prev
, '-',
278 _("previous variation of the previous move"), 0);
279 add_key_binding (&history_keys
, do_history_menu
, 'M',
280 _("move history tree"), 0);
281 add_key_binding (&history_keys
, do_history_help
, KEY_F (1), _("more help"),
283 add_key_binding (&history_keys
, do_history_help
, CTRL_KEY ('g'), NULL
, 0);
284 add_key_binding (&history_keys
, do_history_toggle
, 'h',
285 _("exit history mode"), 0);
287 add_key_binding (&edit_keys
, do_edit_select
, ' ',
288 _("select piece for movement"), 0);
289 add_key_binding (&edit_keys
, do_edit_commit
, '\n',
290 _("commit selected piece"), 0);
291 add_key_binding (&edit_keys
, do_edit_cancel_selected
, KEY_ESCAPE
,
292 _("cancel selected piece"), 0);
293 add_key_binding (&edit_keys
, do_edit_delete
, 'd',
294 _("remove the piece under the cursor"), 0);
295 add_key_binding (&edit_keys
, do_edit_insert
, 'i', _("insert piece"), 0);
296 add_key_binding (&edit_keys
, do_edit_toggle_castle
, 'c',
297 _("toggle castling availability"), 0);
298 add_key_binding (&edit_keys
, do_edit_enpassant
, 'p',
299 _("toggle enpassant square"), 0);
300 add_key_binding (&edit_keys
, do_edit_switch_turn
, 'w', _("toggle turn"), 0);
301 add_key_binding (&edit_keys
, do_edit_help
, KEY_F (1), _("more help"), 0);
302 add_key_binding (&edit_keys
, do_edit_help
, CTRL_KEY ('g'), NULL
, 0);
303 add_key_binding (&edit_keys
, do_edit_exit
, 'e', _("exit edit mode"), 0);
305 add_key_binding (&play_keys
, do_play_select
, ' ',
306 _("select piece for movement"), 0);
307 add_key_binding (&play_keys
, do_play_commit
, '\n',
308 _("commit selected piece"), 0);
309 add_key_binding (&play_keys
, do_play_cancel_selected
, KEY_ESCAPE
,
310 _("cancel selected piece"), 0);
311 add_key_binding (&play_keys
, do_play_set_clock
, 'C', _("set clock"), 0);
312 // add_key_binding(&play_keys, do_play_switch_turn, 'w', _("switch turn"), 0);
313 add_key_binding (&play_keys
, do_play_undo
, 'u', _("undo previous move"), 1);
314 add_key_binding (&play_keys
, do_play_go
, 'g',
315 _("force the chess engine to make the next move"), 0);
316 add_key_binding (&play_keys
, do_play_send_command
, '|',
317 _("send a command to the chess engine"), 0);
318 add_key_binding (&play_keys
, do_play_toggle_eh_mode
, 'w',
319 _("toggle engine/human play"), 0);
320 add_key_binding (&play_keys
, do_play_toggle_engine
, 'E',
321 _("toggle engine/engine play"), 0);
322 add_key_binding (&play_keys
, do_play_toggle_human
, 'H',
323 _("toggle human/human play"), 0);
324 add_key_binding (&play_keys
, do_play_toggle_pause
, 'p',
325 _("toggle pausing of this game"), 0);
326 add_key_binding (&play_keys
, do_play_history_mode
, 'h',
327 _("enter history mode"), 0);
328 add_key_binding (&play_keys
, do_play_edit_mode
, 'e', _("enter edit mode"),
330 add_key_binding (&play_keys
, do_play_help
, KEY_F (1), _("more help"), 0);
331 add_key_binding (&play_keys
, do_play_help
, CTRL_KEY ('g'), NULL
, 0);
333 add_key_binding (&global_keys
, do_global_tag_edit
, CTRL_KEY ('t'),
334 _("edit roster tags"), 0);
335 add_key_binding (&global_keys
, do_global_tag_view
, 't',
336 _("view roster tags"), 0);
337 add_key_binding (&global_keys
, do_global_find_new
, '?',
338 _("new find game expression"), 0);
339 add_key_binding (&global_keys
, do_global_find_next
, '}',
340 _("find next game"), 1);
341 add_key_binding (&global_keys
, do_global_find_prev
, '{',
342 _("find previous game"), 1);
343 add_key_binding (&global_keys
, do_global_new_game
, CTRL_KEY ('n'),
344 _("new game or round"), 0);
345 add_key_binding (&global_keys
, do_global_new_all
, CTRL_KEY ('k'),
346 _("new game from scratch"), 0);
347 add_key_binding (&global_keys
, do_global_copy_game
, CTRL_KEY ('i'),
348 _("copy current game"), 0);
349 add_key_binding (&global_keys
, do_global_next_game
, '>', _("next game"), 1);
350 add_key_binding (&global_keys
, do_global_prev_game
, '<', _("previous game"),
352 add_key_binding (&global_keys
, do_global_game_jump
, 'J', _("jump to game"),
354 add_key_binding (&global_keys
, do_global_toggle_delete
, 'X',
355 _("toggle delete flag"), 1);
356 add_key_binding (&global_keys
, do_global_delete_game
, CTRL_KEY ('X'),
357 _("delete the current or flagged games"), 0);
358 add_key_binding (&global_keys
, do_global_resume_game
, CTRL_KEY ('r'),
359 _("load a PGN file"), 0);
360 add_key_binding (&global_keys
, do_global_save_game
, 's', _("save game"), 0);
361 add_key_binding (&global_keys
, do_global_toggle_board_details
,
362 CTRL_KEY ('d'), _("toggle board details"), 0);
363 add_key_binding (&global_keys
, do_global_toggle_strict_castling
,
364 CTRL_KEY ('p'), _("toggle strict castling"), 0);
365 add_key_binding (&global_keys
, do_global_toggle_engine_window
, 'W',
366 _("toggle chess engine IO window"), 0);
368 add_key_binding (&global_keys
, do_global_perl
, CTRL_KEY ('O'),
369 _("Call PERL subroutine"), 0);
371 add_key_binding (&global_keys
, do_global_about
, KEY_F (10),
372 _("version information"), 0);
373 add_key_binding (&global_keys
, do_global_redraw
, CTRL_KEY ('L'),
374 _("redraw the screen"), 0);
375 add_key_binding (&global_keys
, NULL
, KEY_F (1), _("more help"), 0);
376 add_key_binding (&global_keys
, NULL
, CTRL_KEY ('g'), NULL
, 0);
377 add_key_binding (&global_keys
, do_global_quit
, 'Q', _("quit"), 0);
381 set_config_defaults ()
385 config
.pattern
= strdup ("*.[Pp][Gg][Nn]*");
386 config
.engine_cmd
= strdup ("gnuchess --xboard");
387 config
.engine_protocol
= 1;
388 config
.jumpcount
= 5;
389 config
.linegraphics
= 1;
390 config
.saveprompt
= 1;
391 config
.deleteprompt
= 1;
392 config
.validmoves
= 1;
394 config
.showattacks
= 1;
395 config
.coordsyleft
= TRUE
;
396 config
.fmpolyglot
= FALSE
;
397 config
.boardleft
= TRUE
;
398 config
.exitdialogbox
= TRUE
;
399 config
.enginecmdblacktag
= TRUE
;
400 config
.bprevmove
= TRUE
;
401 config
.utf8_pieces
= 1;
403 set_default_colors ();
405 if (stat (config
.nagfile
, &st
) == -1)
408 copydatafile (config
.nagfile
, "nag.data");
410 warn ("%s", config
.nagfile
);
413 if (stat (config
.ccfile
, &st
) == -1)
416 copydatafile (config
.ccfile
, "cc.data");
418 warn ("%s", config
.ccfile
);
423 update_key (struct key_s
**dst
, struct custom_key_s config_key
,
424 wint_t c
, char *desc
)
428 for (i
= 0; dst
[i
]; i
++)
430 if (dst
[i
]->f
== config_key
.func
)
437 dst
[i
]->key
= str_to_wchar (fancy_key_name (c
));
441 dst
[i
]->d
= str_to_wchar (desc
);
448 add_key_binding (&dst
, config_key
.func
, c
,
449 (desc
) ? desc
: _("no description"), config_key
.r
);
455 static struct known_key_s
484 KEY_ESCAPE
, "escape"},
492 parse_key (const char *filename
, int lines
, int word
, wchar_t ** key
)
494 wchar_t *p
= key
? *key
: NULL
;
495 wchar_t *orig
= key
? *key
: NULL
;
499 if (!key
|| !wcslen (*key
))
502 if (*p
== '\"' && !isspace (*(p
+1)))
514 for (i
= 0; known_keys
[i
].name
; i
++)
516 wchar_t *wc
= str_to_wchar (known_keys
[i
].name
);
518 if (!wcsncasecmp (p
, wc
, wcslen (wc
)))
521 p
+= strlen (known_keys
[i
].name
);
536 else if (*p
== 'F' || *p
== 'f')
538 char *str
= wchar_to_str (++p
);
540 c
= KEY_F (atoi (str
));
541 p
+= integer_len (atoi (str
));
550 errx (EXIT_FAILURE
, _("%s(%i): parse error \"%ls\""), filename
,
561 if (quote
&& *p
!= '\"')
562 errx (EXIT_FAILURE
, _("%s(%i): parse error \"%ls\""), filename
,
567 if (word
&& *p
&& !isspace (*p
))
568 errx (EXIT_FAILURE
, _("%s(%i): parse error \"%ls\""), filename
,
571 orig
+= wcslen (orig
) - wcslen (p
);
577 parse_key_binding (const char *filename
, int lines
, char *val
)
579 char mode
[64], func
[64];
580 wchar_t desc
[64] = { 0 };
590 n
= sscanf (val
, "%s %ls %s %63lc", mode
, key
, func
, desc
);
593 errx (EXIT_FAILURE
, _("%s(%i): too few arguments"), filename
, lines
);
595 if (strcasecmp (mode
, "history") == 0)
597 else if (strcasecmp (mode
, "play") == 0)
599 else if (strcasecmp (mode
, "edit") == 0)
602 errx (EXIT_FAILURE
, _("%s(%i): invalid game mode \"%s\""), filename
,
606 c
= parse_key (filename
, lines
, 1, &p
);
610 for (i
= 0; global_keys
[i
]; i
++)
612 if (global_keys
[i
]->c
== c
)
614 _("%s(%i): key \"%ls\" conflicts with a global key"),
615 filename
, lines
, key
);
619 for (f
= -2, i
= 0; config_keys
[i
].name
; i
++)
621 if (strcmp (config_keys
[i
].name
, func
) == 0 && config_keys
[i
].mode
== m
)
629 errx (EXIT_FAILURE
, _("%s(%i): invalid command \"%s\""), filename
,
632 str
= wchar_to_str (desc
);
637 update_key (play_keys
, config_keys
[f
], c
, (n
> 3) ? str
: NULL
);
640 update_key (history_keys
, config_keys
[f
], c
, (n
> 3) ? str
: NULL
);
643 update_key (edit_keys
, config_keys
[f
], c
, (n
> 3) ? str
: NULL
);
646 update_key (global_keys
, config_keys
[f
], c
, (n
> 3) ? str
: NULL
);
654 parse_macro_desc (const char *filename
, int lines
, wchar_t **val
)
658 wchar_t *buf
= Malloc (256 * sizeof (wchar_t));
664 for (p
= *val
; p
&& *p
; p
++)
677 else if (isspace (*p
) && !quote
)
683 if (!isspace (*p
) || !*(p
+1))
685 fprintf(stderr
, _ ("%s(%i): parse error\n"), filename
, lines
);
699 parse_macro (const char *filename
, int lines
, char *val
)
702 wchar_t keys
[2048] = { 0 }, key
[8];
709 n
= sscanf (val
, "%s %ls %2047lc", mode
, key
, keys
);
712 errx (EXIT_FAILURE
, _("%s(%i): too few arguments"), filename
, lines
);
714 if (strcasecmp (mode
, "history") == 0)
716 else if (strcasecmp (mode
, "play") == 0)
718 else if (strcasecmp (mode
, "edit") == 0)
720 else if (strcasecmp (mode
, "any") == 0)
723 errx (EXIT_FAILURE
, _("%s(%i): invalid game mode \"%s\""), filename
,
727 c
= parse_key (filename
, lines
, 1, &p
);
730 for (i
= 0; macros
[i
]; i
++);
732 macros
= Realloc (macros
, (i
+ 2) * sizeof (struct macro_s
*));
733 macros
[i
] = Calloc (1, sizeof (struct macro_s
));
738 macros
[i
]->desc
= parse_macro_desc (filename
, lines
, &p
);
739 if (!macros
[i
]->desc
)
742 while ((c
= parse_key (filename
, lines
, 0, &p
)) != 0)
744 macros
[i
]->keys
= Realloc (macros
[i
]->keys
, (macros
[i
]->total
+ 2) *
746 macros
[i
]->keys
[macros
[i
]->total
++] = c
;
753 parse_rcfile (const char *filename
)
756 char *line
, buf
[LINE_MAX
];
758 char *altengine
= NULL
;
763 if ((fp
= fopen (filename
, "r")) == NULL
)
764 err (EXIT_FAILURE
, "%s", filename
);
766 while ((line
= fgets (buf
, sizeof (buf
), fp
)) != NULL
)
769 char var
[30] = { 0 }, val
[LINE_MAX
- sizeof (var
) - 1] =
772 char token
[MAX_PGN_LINE_LEN
+ 1] = { 0 };
773 char value
[MAX_PGN_LINE_LEN
+ 1] = { 0 };
779 if (!line
[0] || line
[0] == '#')
782 if ((n
= sscanf (line
, "%s %[^\n]", var
, val
)) != 2)
783 errx (EXIT_FAILURE
, _("%s(%i): parse error %i"), filename
, lines
, n
);
785 p
= strdup (trim (val
));
786 strncpy (val
, p
, sizeof (val
) - 1);
788 p
= strdup (trim (var
));
789 strncpy (var
, p
, sizeof (var
) - 1);
792 if (strcmp (var
, "jump_count") == 0)
794 if (!isinteger (val
))
795 errx (EXIT_FAILURE
, _("%s(%i): value is not an integer"),
798 config
.jumpcount
= atoi (val
);
800 else if (strcmp (var
, "engine_init") == 0)
803 Realloc (config
.einit
, (init
+ 2) * sizeof (wchar_t *));
804 config
.einit
[init
++] = str_to_wchar (val
);
805 config
.einit
[init
] = NULL
;
807 else if (strcmp (var
, "pattern") == 0)
809 free (config
.pattern
);
810 config
.pattern
= strdup (val
);
812 else if (strcmp (var
, "mpl") == 0)
814 if (!isinteger (val
))
815 errx (EXIT_FAILURE
, _("%s(%i): value is not an integer"),
817 pgn_config_set (PGN_MPL
, atoi (val
));
819 else if (strcmp (var
, "stop_on_error") == 0)
820 pgn_config_set (PGN_STOP_ON_ERROR
, on_or_off (filename
, lines
, val
));
821 else if (strcmp (var
, "tag") == 0)
823 if ((n
= sscanf (val
, "%s %s ", token
, value
)) < 1 || n
> 2)
824 errx (EXIT_FAILURE
, _("%s(%i): invalid value \"%s\""), filename
,
831 p
= val
+ strlen (token
);
832 strncpy (value
, p
, sizeof (value
) - 1);
835 for (n
= 0; n
< strlen (token
); n
++)
837 if (!isalnum (token
[n
]) && token
[n
] != '_')
839 _("%s(%i): token names must match 0-9A-Za-z_."),
843 token
[0] = toupper (token
[0]);
844 pgn_tag_add (&config
.tag
, token
, value
);
846 else if (strcmp (var
, "save_directory") == 0)
847 config
.savedirectory
= strdup (val
);
848 else if (strcmp (var
, "line_graphics") == 0)
849 config
.linegraphics
= on_or_off (filename
, lines
, val
);
850 else if (strcmp (var
, "save_prompt") == 0)
851 config
.saveprompt
= on_or_off (filename
, lines
, val
);
852 else if (strcmp (var
, "delete_prompt") == 0)
853 config
.deleteprompt
= on_or_off (filename
, lines
, val
);
854 else if (strcmp (var
, "valid_moves") == 0)
855 config
.validmoves
= on_or_off (filename
, lines
, val
);
856 else if (strcmp (var
, "board_details") == 0)
857 config
.details
= on_or_off (filename
, lines
, val
);
858 else if (strcmp (var
, "show_attacks") == 0)
859 config
.showattacks
= on_or_off (filename
, lines
, val
);
860 else if (strcmp (var
, "coords_y_left") == 0)
861 config
.coordsyleft
= on_or_off (filename
, lines
, val
);
862 else if (strcmp (var
, "fm_polyglot") == 0)
863 config
.fmpolyglot
= on_or_off (filename
, lines
, val
);
864 else if (strcmp (var
, "board_left") == 0)
865 config
.boardleft
= on_or_off (filename
, lines
, val
);
866 else if (strcmp (var
, "exit_dialog_box") == 0)
867 config
.exitdialogbox
= on_or_off (filename
, lines
, val
);
868 else if (strcmp (var
, "engine_cmd_blacktag") == 0)
869 config
.enginecmdblacktag
= on_or_off (filename
, lines
, val
);
870 else if (strcmp (var
, "board_prev_move") == 0)
871 config
.bprevmove
= on_or_off (filename
, lines
, val
);
872 else if (strcmp (var
, "strict_castling") == 0)
873 pgn_config_set (PGN_STRICT_CASTLING
,
874 on_or_off (filename
, lines
, val
));
875 else if (strcmp (var
, "engine_cmd") == 0)
876 altengine
= strdup (val
);
877 else if (strcmp (var
, "engine_protocol") == 0)
879 if (!isinteger (val
))
880 errx (EXIT_FAILURE
, _("%s(%i): value is not an integer"),
883 config
.engine_protocol
= atoi (val
);
885 if (config
.engine_protocol
!= 1 && config
.engine_protocol
!= 2)
886 errx (EXIT_FAILURE
, _("%s(%i): invalid value"), filename
, lines
);
888 else if (strcmp (var
, "utf8_pieces") == 0)
889 config
.utf8_pieces
= on_or_off (filename
, lines
, val
);
890 else if (strcmp (var
, "turn_cmd") == 0)
891 config
.turn_cmd
= strdup (val
);
892 else if (strcmp (var
, "color_board_window") == 0)
893 parse_color (filename
, lines
, val
, &config
.color
[CONF_BDWINDOW
]);
894 else if (strcmp (var
, "color_board_selected") == 0)
895 parse_color (filename
, lines
, val
, &config
.color
[CONF_BSELECTED
]);
896 else if (strcmp (var
, "color_board_white_moves") == 0)
897 parse_color (filename
, lines
, val
, &config
.color
[CONF_BMOVESW
]);
898 else if (strcmp (var
, "color_board_black_moves") == 0)
899 parse_color (filename
, lines
, val
, &config
.color
[CONF_BMOVESB
]);
900 else if (strcmp (var
, "color_board_count") == 0)
901 parse_color (filename
, lines
, val
, &config
.color
[CONF_BCOUNT
]);
902 else if (strcmp (var
, "color_board_cursor") == 0)
903 parse_color (filename
, lines
, val
, &config
.color
[CONF_BCURSOR
]);
904 else if (strcmp (var
, "color_board_black") == 0)
905 parse_color (filename
, lines
, val
, &config
.color
[CONF_BBLACK
]);
906 else if (strcmp (var
, "color_board_white") == 0)
907 parse_color (filename
, lines
, val
, &config
.color
[CONF_BWHITE
]);
908 else if (strcmp (var
, "color_board_graphics") == 0)
909 parse_color (filename
, lines
, val
, &config
.color
[CONF_BGRAPHICS
]);
910 else if (strcmp (var
, "color_board_coords") == 0)
911 parse_color (filename
, lines
, val
, &config
.color
[CONF_BCOORDS
]);
912 else if (strcmp (var
, "color_board_castling") == 0)
913 parse_color (filename
, lines
, val
, &config
.color
[CONF_BCASTLING
]);
914 else if (strcmp (var
, "color_board_enpassant") == 0)
915 parse_color (filename
, lines
, val
, &config
.color
[CONF_BENPASSANT
]);
916 else if (strcmp (var
, "color_board_attack") == 0)
917 parse_color (filename
, lines
, val
, &config
.color
[CONF_BATTACK
]);
918 else if (strcmp (var
, "color_board_prev_move") == 0)
919 parse_color (filename
, lines
, val
, &config
.color
[CONF_BPREVMOVE
]);
920 else if (strcmp (var
, "color_status_window") == 0)
921 parse_color (filename
, lines
, val
, &config
.color
[CONF_SWINDOW
]);
922 else if (strcmp (var
, "color_status_title") == 0)
923 parse_color (filename
, lines
, val
, &config
.color
[CONF_STITLE
]);
924 else if (strcmp (var
, "color_status_border") == 0)
925 parse_color (filename
, lines
, val
, &config
.color
[CONF_SBORDER
]);
926 else if (strcmp (var
, "color_status_notify") == 0)
927 parse_color (filename
, lines
, val
, &config
.color
[CONF_SNOTIFY
]);
928 else if (strcmp (var
, "color_status_engine") == 0)
929 parse_color (filename
, lines
, val
, &config
.color
[CONF_SENGINE
]);
930 else if (strcmp (var
, "color_tag_window") == 0)
931 parse_color (filename
, lines
, val
, &config
.color
[CONF_TWINDOW
]);
932 else if (strcmp (var
, "color_tag_title") == 0)
933 parse_color (filename
, lines
, val
, &config
.color
[CONF_TTITLE
]);
934 else if (strcmp (var
, "color_tag_border") == 0)
935 parse_color (filename
, lines
, val
, &config
.color
[CONF_TBORDER
]);
936 else if (strcmp (var
, "color_history_window") == 0)
937 parse_color (filename
, lines
, val
, &config
.color
[CONF_HWINDOW
]);
938 else if (strcmp (var
, "color_history_title") == 0)
939 parse_color (filename
, lines
, val
, &config
.color
[CONF_HTITLE
]);
940 else if (strcmp (var
, "color_history_border") == 0)
941 parse_color (filename
, lines
, val
, &config
.color
[CONF_HBORDER
]);
942 else if (strcmp (var
, "color_message_window") == 0)
943 parse_color (filename
, lines
, val
, &config
.color
[CONF_MWINDOW
]);
944 else if (strcmp (var
, "color_message_title") == 0)
945 parse_color (filename
, lines
, val
, &config
.color
[CONF_MTITLE
]);
946 else if (strcmp (var
, "color_message_border") == 0)
947 parse_color (filename
, lines
, val
, &config
.color
[CONF_MBORDER
]);
948 else if (strcmp (var
, "color_message_prompt") == 0)
949 parse_color (filename
, lines
, val
, &config
.color
[CONF_MPROMPT
]);
950 else if (strcmp (var
, "color_input_window") == 0)
951 parse_color (filename
, lines
, val
, &config
.color
[CONF_IWINDOW
]);
952 else if (strcmp (var
, "color_input_title") == 0)
953 parse_color (filename
, lines
, val
, &config
.color
[CONF_ITITLE
]);
954 else if (strcmp (var
, "color_input_border") == 0)
955 parse_color (filename
, lines
, val
, &config
.color
[CONF_IBORDER
]);
956 else if (strcmp (var
, "color_input_prompt") == 0)
957 parse_color (filename
, lines
, val
, &config
.color
[CONF_IPROMPT
]);
958 else if (strcmp (var
, "color_menu") == 0)
959 parse_color (filename
, lines
, val
, &config
.color
[CONF_MENU
]);
960 else if (strcmp (var
, "color_menu_selected") == 0)
961 parse_color (filename
, lines
, val
, &config
.color
[CONF_MENUS
]);
962 else if (strcmp (var
, "color_menu_highlight") == 0)
963 parse_color (filename
, lines
, val
, &config
.color
[CONF_MENUH
]);
964 else if (strcmp (var
, "color_menu_graphics") == 0)
965 parse_color (filename
, lines
, val
,
966 &config
.color
[CONF_HISTORY_MENU_LG
]);
967 else if (strcmp (var
, "bind") == 0)
968 parse_key_binding (filename
, lines
, val
);
969 else if (strcmp (var
, "macro") == 0)
970 parse_macro (filename
, lines
, val
);
971 else if (strcmp (var
, "cbind") == 0)
973 config
.keys
= Realloc (config
.keys
, (k
+ 2) *
974 sizeof (struct config_key_s
*));
975 config
.keys
[k
] = Calloc (1, sizeof (struct config_key_s
));
979 while (*p
&& !isspace (*p
))
986 if (strcasecmp (p
, "none") == 0)
987 config
.keys
[k
]->type
= KEY_DEFAULT
;
988 else if (strcasecmp (p
, "repeat") == 0)
989 config
.keys
[k
]->type
= KEY_REPEAT
;
990 else if (strcasecmp (p
, "set") == 0)
991 config
.keys
[k
]->type
= KEY_SET
;
993 errx (EXIT_FAILURE
, _("%s(%i): invalid value \"%s\""), filename
,
999 while (*p
&& isspace (*p
))
1002 config
.keys
[k
]->c
= *p
++;
1004 while (isspace (*p
))
1007 config
.keys
[k
++]->str
= str_to_wchar (p
);
1008 config
.keys
[k
] = NULL
;
1011 errx (EXIT_FAILURE
, _("%s(%i): invalid parameter \"%s\""), filename
,
1019 free (config
.engine_cmd
);
1020 config
.engine_cmd
= NULL
;
1021 config
.engine_cmd
= altengine
;
1024 if (config
.enginecmdblacktag
)
1025 pgn_tag_add (&config
.tag
, (char *) "Black", config
.engine_cmd
);