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_toggle
, 'h',
282 _("exit history mode"), 0);
284 add_key_binding (&edit_keys
, do_edit_select
, ' ',
285 _("select piece for movement"), 0);
286 add_key_binding (&edit_keys
, do_edit_commit
, '\n',
287 _("commit selected piece"), 0);
288 add_key_binding (&edit_keys
, do_edit_cancel_selected
, KEY_ESCAPE
,
289 _("cancel selected piece"), 0);
290 add_key_binding (&edit_keys
, do_edit_delete
, 'd',
291 _("remove the piece under the cursor"), 0);
292 add_key_binding (&edit_keys
, do_edit_insert
, 'i', _("insert piece"), 0);
293 add_key_binding (&edit_keys
, do_edit_toggle_castle
, 'c',
294 _("toggle castling availability"), 0);
295 add_key_binding (&edit_keys
, do_edit_enpassant
, 'p',
296 _("toggle enpassant square"), 0);
297 add_key_binding (&edit_keys
, do_edit_switch_turn
, 'w', _("toggle turn"), 0);
298 add_key_binding (&edit_keys
, do_edit_exit
, 'e', _("exit edit mode"), 0);
300 add_key_binding (&play_keys
, do_play_select
, ' ',
301 _("select piece for movement"), 0);
302 add_key_binding (&play_keys
, do_play_commit
, '\n',
303 _("commit selected piece"), 0);
304 add_key_binding (&play_keys
, do_play_cancel_selected
, KEY_ESCAPE
,
305 _("cancel selected piece"), 0);
306 add_key_binding (&play_keys
, do_play_set_clock
, 'C', _("set clock"), 0);
307 // add_key_binding(&play_keys, do_play_switch_turn, 'w', _("switch turn"), 0);
308 add_key_binding (&play_keys
, do_play_undo
, 'u', _("undo previous move"), 1);
309 add_key_binding (&play_keys
, do_play_go
, 'g',
310 _("force the chess engine to make the next move"), 0);
311 add_key_binding (&play_keys
, do_play_send_command
, '|',
312 _("send a command to the chess engine"), 0);
313 add_key_binding (&play_keys
, do_play_toggle_eh_mode
, 'w',
314 _("toggle engine/human play"), 0);
315 add_key_binding (&play_keys
, do_play_toggle_engine
, 'E',
316 _("toggle engine/engine play"), 0);
317 add_key_binding (&play_keys
, do_play_toggle_human
, 'H',
318 _("toggle human/human play"), 0);
319 add_key_binding (&play_keys
, do_play_toggle_pause
, 'p',
320 _("toggle pausing of this game"), 0);
321 add_key_binding (&play_keys
, do_play_history_mode
, 'h',
322 _("enter history mode"), 0);
323 add_key_binding (&play_keys
, do_play_edit_mode
, 'e', _("enter edit mode"),
325 add_key_binding (&play_keys
, do_play_toggle_strict_castling
,
326 CTRL_KEY ('p'), _("toggle strict castling"), 0);
328 add_key_binding (&global_keys
, do_global_tag_edit
, CTRL_KEY ('t'),
329 _("edit roster tags"), 0);
330 add_key_binding (&global_keys
, do_global_tag_view
, 't',
331 _("view roster tags"), 0);
332 add_key_binding (&global_keys
, do_global_find_new
, '?',
333 _("new find game expression"), 0);
334 add_key_binding (&global_keys
, do_global_find_next
, '}',
335 _("find next game"), 1);
336 add_key_binding (&global_keys
, do_global_find_prev
, '{',
337 _("find previous game"), 1);
338 add_key_binding (&global_keys
, do_global_new_game
, CTRL_KEY ('n'),
339 _("new game or round"), 0);
340 add_key_binding (&global_keys
, do_global_new_all
, CTRL_KEY ('k'),
341 _("new game from scratch"), 0);
342 add_key_binding (&global_keys
, do_global_copy_game
, CTRL_KEY ('i'),
343 _("copy current game"), 0);
344 add_key_binding (&global_keys
, do_global_next_game
, '>', _("next game"), 1);
345 add_key_binding (&global_keys
, do_global_prev_game
, '<', _("previous game"),
347 add_key_binding (&global_keys
, do_global_game_jump
, 'J', _("jump to game"),
349 add_key_binding (&global_keys
, do_global_toggle_delete
, 'X',
350 _("toggle delete flag"), 1);
351 add_key_binding (&global_keys
, do_global_delete_game
, CTRL_KEY ('X'),
352 _("delete the current or flagged games"), 0);
353 add_key_binding (&global_keys
, do_global_resume_game
, CTRL_KEY ('r'),
354 _("load a PGN file"), 0);
355 add_key_binding (&global_keys
, do_global_save_game
, 's', _("save game"), 0);
356 add_key_binding (&global_keys
, do_global_toggle_board_details
,
357 CTRL_KEY ('d'), _("toggle board details"), 0);
358 add_key_binding (&global_keys
, do_global_toggle_engine_window
, 'W',
359 _("toggle chess engine IO window"), 0);
361 add_key_binding (&global_keys
, do_global_perl
, CTRL_KEY ('O'),
362 _("Call PERL subroutine"), 0);
364 add_key_binding (&global_keys
, do_global_about
, KEY_F (10),
365 _("version information"), 0);
366 add_key_binding (&global_keys
, do_global_redraw
, CTRL_KEY ('L'),
367 _("redraw the screen"), 0);
368 add_key_binding (&global_keys
, do_global_help
, KEY_F (1), NULL
, 0);
369 add_key_binding (&global_keys
, do_global_quit
, 'Q', _("quit"), 0);
373 set_config_defaults ()
377 config
.pattern
= strdup ("*.[Pp][Gg][Nn]*");
378 config
.engine_cmd
= strdup ("gnuchess --xboard");
379 config
.engine_protocol
= 1;
380 config
.jumpcount
= 5;
381 config
.linegraphics
= 1;
382 config
.saveprompt
= 1;
383 config
.deleteprompt
= 1;
384 config
.validmoves
= 1;
386 config
.showattacks
= 1;
387 config
.coordsyleft
= TRUE
;
388 config
.fmpolyglot
= FALSE
;
389 config
.boardleft
= TRUE
;
390 config
.exitdialogbox
= TRUE
;
391 config
.enginecmdblacktag
= TRUE
;
392 config
.bprevmove
= TRUE
;
393 config
.utf8_pieces
= 1;
395 set_default_colors ();
397 if (stat (config
.nagfile
, &st
) == -1)
400 copydatafile (config
.nagfile
, "nag.data");
402 warn ("%s", config
.nagfile
);
405 if (stat (config
.ccfile
, &st
) == -1)
408 copydatafile (config
.ccfile
, "cc.data");
410 warn ("%s", config
.ccfile
);
415 update_key (struct key_s
**dst
, struct custom_key_s config_key
,
416 wint_t c
, char *desc
)
420 for (i
= 0; dst
[i
]; i
++)
422 if (dst
[i
]->f
== config_key
.func
)
429 dst
[i
]->key
= str_to_wchar (fancy_key_name (c
));
433 dst
[i
]->d
= str_to_wchar (desc
);
440 add_key_binding (&dst
, config_key
.func
, c
,
441 (desc
) ? desc
: _("no description"), config_key
.r
);
447 static struct known_key_s
476 KEY_ESCAPE
, "escape"},
484 parse_key (const char *filename
, int lines
, int word
, wchar_t ** key
)
486 wchar_t *p
= key
? *key
: NULL
;
487 wchar_t *orig
= key
? *key
: NULL
;
491 if (!key
|| !wcslen (*key
))
494 if (*p
== '\"' && !isspace (*(p
+1)))
506 for (i
= 0; known_keys
[i
].name
; i
++)
508 wchar_t *wc
= str_to_wchar (known_keys
[i
].name
);
510 if (!wcsncasecmp (p
, wc
, wcslen (wc
)))
513 p
+= strlen (known_keys
[i
].name
);
528 else if (*p
== 'F' || *p
== 'f')
530 char *str
= wchar_to_str (++p
);
532 c
= KEY_F (atoi (str
));
533 p
+= integer_len (atoi (str
));
542 errx (EXIT_FAILURE
, _("%s(%i): parse error \"%ls\""), filename
,
553 if (quote
&& *p
!= '\"')
554 errx (EXIT_FAILURE
, _("%s(%i): parse error \"%ls\""), filename
,
559 if (word
&& *p
&& !isspace (*p
))
560 errx (EXIT_FAILURE
, _("%s(%i): parse error \"%ls\""), filename
,
563 orig
+= wcslen (orig
) - wcslen (p
);
569 parse_key_binding (const char *filename
, int lines
, char *val
)
571 char mode
[64], func
[64];
572 wchar_t desc
[64] = { 0 };
582 n
= sscanf (val
, "%s %ls %s %63lc", mode
, key
, func
, desc
);
585 errx (EXIT_FAILURE
, _("%s(%i): too few arguments"), filename
, lines
);
587 if (strcasecmp (mode
, "history") == 0)
589 else if (strcasecmp (mode
, "play") == 0)
591 else if (strcasecmp (mode
, "edit") == 0)
593 else if (strcasecmp (mode
, "any") == 0)
596 errx (EXIT_FAILURE
, _("%s(%i): invalid game mode \"%s\""), filename
,
600 c
= parse_key (filename
, lines
, 1, &p
);
604 for (i
= 0; global_keys
[i
]; i
++)
606 if (global_keys
[i
]->c
== c
)
608 _("%s(%i): key \"%ls\" conflicts with a global key"),
609 filename
, lines
, key
);
613 for (f
= -2, i
= 0; config_keys
[i
].name
; i
++)
615 if (strcmp (config_keys
[i
].name
, func
) == 0 && config_keys
[i
].mode
== m
)
623 errx (EXIT_FAILURE
, _("%s(%i): invalid command \"%s\""), filename
,
626 str
= wchar_to_str (desc
);
631 update_key (play_keys
, config_keys
[f
], c
, (n
> 3) ? str
: NULL
);
634 update_key (history_keys
, config_keys
[f
], c
, (n
> 3) ? str
: NULL
);
637 update_key (edit_keys
, config_keys
[f
], c
, (n
> 3) ? str
: NULL
);
640 update_key (global_keys
, config_keys
[f
], c
, (n
> 3) ? str
: NULL
);
648 parse_macro_desc (const char *filename
, int lines
, wchar_t **val
)
652 wchar_t *buf
= Malloc (256 * sizeof (wchar_t));
658 for (p
= *val
; p
&& *p
; p
++)
671 else if (isspace (*p
) && !quote
)
677 if (!isspace (*p
) || !*(p
+1))
679 fprintf(stderr
, _ ("%s(%i): parse error\n"), filename
, lines
);
693 parse_macro (const char *filename
, int lines
, char *val
)
696 wchar_t keys
[2048] = { 0 }, key
[8];
703 n
= sscanf (val
, "%s %ls %2047lc", mode
, key
, keys
);
706 errx (EXIT_FAILURE
, _("%s(%i): too few arguments"), filename
, lines
);
708 if (strcasecmp (mode
, "history") == 0)
710 else if (strcasecmp (mode
, "play") == 0)
712 else if (strcasecmp (mode
, "edit") == 0)
714 else if (strcasecmp (mode
, "any") == 0)
717 errx (EXIT_FAILURE
, _("%s(%i): invalid game mode \"%s\""), filename
,
721 c
= parse_key (filename
, lines
, 1, &p
);
724 for (i
= 0; macros
[i
]; i
++);
726 macros
= Realloc (macros
, (i
+ 2) * sizeof (struct macro_s
*));
727 macros
[i
] = Calloc (1, sizeof (struct macro_s
));
732 macros
[i
]->desc
= parse_macro_desc (filename
, lines
, &p
);
733 if (!macros
[i
]->desc
)
736 while ((c
= parse_key (filename
, lines
, 0, &p
)) != 0)
738 macros
[i
]->keys
= Realloc (macros
[i
]->keys
, (macros
[i
]->total
+ 2) *
740 macros
[i
]->keys
[macros
[i
]->total
++] = c
;
747 parse_rcfile (const char *filename
)
750 char *line
, buf
[LINE_MAX
];
752 char *altengine
= NULL
;
757 if ((fp
= fopen (filename
, "r")) == NULL
)
758 err (EXIT_FAILURE
, "%s", filename
);
760 while ((line
= fgets (buf
, sizeof (buf
), fp
)) != NULL
)
763 char var
[30] = { 0 }, val
[LINE_MAX
- sizeof (var
) - 1] =
766 char token
[MAX_PGN_LINE_LEN
+ 1] = { 0 };
767 char value
[MAX_PGN_LINE_LEN
+ 1] = { 0 };
773 if (!line
[0] || line
[0] == '#')
776 if ((n
= sscanf (line
, "%s %[^\n]", var
, val
)) != 2)
777 errx (EXIT_FAILURE
, _("%s(%i): parse error %i"), filename
, lines
, n
);
779 p
= strdup (trim (val
));
780 strncpy (val
, p
, sizeof (val
) - 1);
782 p
= strdup (trim (var
));
783 strncpy (var
, p
, sizeof (var
) - 1);
786 if (strcmp (var
, "jump_count") == 0)
788 if (!isinteger (val
))
789 errx (EXIT_FAILURE
, _("%s(%i): value is not an integer"),
792 config
.jumpcount
= atoi (val
);
794 else if (strcmp (var
, "engine_init") == 0)
797 Realloc (config
.einit
, (init
+ 2) * sizeof (wchar_t *));
798 config
.einit
[init
++] = str_to_wchar (val
);
799 config
.einit
[init
] = NULL
;
801 else if (strcmp (var
, "pattern") == 0)
803 free (config
.pattern
);
804 config
.pattern
= strdup (val
);
806 else if (strcmp (var
, "mpl") == 0)
808 if (!isinteger (val
))
809 errx (EXIT_FAILURE
, _("%s(%i): value is not an integer"),
811 pgn_config_set (PGN_MPL
, atoi (val
));
813 else if (strcmp (var
, "stop_on_error") == 0)
814 pgn_config_set (PGN_STOP_ON_ERROR
, on_or_off (filename
, lines
, val
));
815 else if (strcmp (var
, "tag") == 0)
817 if ((n
= sscanf (val
, "%s %s ", token
, value
)) < 1 || n
> 2)
818 errx (EXIT_FAILURE
, _("%s(%i): invalid value \"%s\""), filename
,
825 p
= val
+ strlen (token
);
826 strncpy (value
, p
, sizeof (value
) - 1);
829 for (n
= 0; n
< strlen (token
); n
++)
831 if (!isalnum (token
[n
]) && token
[n
] != '_')
833 _("%s(%i): token names must match 0-9A-Za-z_."),
837 token
[0] = toupper (token
[0]);
838 pgn_tag_add (&config
.tag
, token
, value
);
840 else if (strcmp (var
, "save_directory") == 0)
841 config
.savedirectory
= strdup (val
);
842 else if (strcmp (var
, "line_graphics") == 0)
843 config
.linegraphics
= on_or_off (filename
, lines
, val
);
844 else if (strcmp (var
, "save_prompt") == 0)
845 config
.saveprompt
= on_or_off (filename
, lines
, val
);
846 else if (strcmp (var
, "delete_prompt") == 0)
847 config
.deleteprompt
= on_or_off (filename
, lines
, val
);
848 else if (strcmp (var
, "valid_moves") == 0)
849 config
.validmoves
= on_or_off (filename
, lines
, val
);
850 else if (strcmp (var
, "board_details") == 0)
851 config
.details
= on_or_off (filename
, lines
, val
);
852 else if (strcmp (var
, "show_attacks") == 0)
853 config
.showattacks
= on_or_off (filename
, lines
, val
);
854 else if (strcmp (var
, "coords_y_left") == 0)
855 config
.coordsyleft
= on_or_off (filename
, lines
, val
);
856 else if (strcmp (var
, "fm_polyglot") == 0)
857 config
.fmpolyglot
= on_or_off (filename
, lines
, val
);
858 else if (strcmp (var
, "board_left") == 0)
859 config
.boardleft
= on_or_off (filename
, lines
, val
);
860 else if (strcmp (var
, "exit_dialog_box") == 0)
861 config
.exitdialogbox
= on_or_off (filename
, lines
, val
);
862 else if (strcmp (var
, "engine_cmd_blacktag") == 0)
863 config
.enginecmdblacktag
= on_or_off (filename
, lines
, val
);
864 else if (strcmp (var
, "board_prev_move") == 0)
865 config
.bprevmove
= on_or_off (filename
, lines
, val
);
866 else if (strcmp (var
, "strict_castling") == 0)
867 pgn_config_set (PGN_STRICT_CASTLING
,
868 on_or_off (filename
, lines
, val
));
869 else if (strcmp (var
, "engine_cmd") == 0)
870 altengine
= strdup (val
);
871 else if (strcmp (var
, "engine_protocol") == 0)
873 if (!isinteger (val
))
874 errx (EXIT_FAILURE
, _("%s(%i): value is not an integer"),
877 config
.engine_protocol
= atoi (val
);
879 if (config
.engine_protocol
!= 1 && config
.engine_protocol
!= 2)
880 errx (EXIT_FAILURE
, _("%s(%i): invalid value"), filename
, lines
);
882 else if (strcmp (var
, "utf8_pieces") == 0)
883 config
.utf8_pieces
= on_or_off (filename
, lines
, val
);
884 else if (strcmp (var
, "turn_cmd") == 0)
885 config
.turn_cmd
= strdup (val
);
886 else if (strcmp (var
, "color_board_window") == 0)
887 parse_color (filename
, lines
, val
, &config
.color
[CONF_BDWINDOW
]);
888 else if (strcmp (var
, "color_board_selected") == 0)
889 parse_color (filename
, lines
, val
, &config
.color
[CONF_BSELECTED
]);
890 else if (strcmp (var
, "color_board_white_moves") == 0)
891 parse_color (filename
, lines
, val
, &config
.color
[CONF_BMOVESW
]);
892 else if (strcmp (var
, "color_board_black_moves") == 0)
893 parse_color (filename
, lines
, val
, &config
.color
[CONF_BMOVESB
]);
894 else if (strcmp (var
, "color_board_count") == 0)
895 parse_color (filename
, lines
, val
, &config
.color
[CONF_BCOUNT
]);
896 else if (strcmp (var
, "color_board_cursor") == 0)
897 parse_color (filename
, lines
, val
, &config
.color
[CONF_BCURSOR
]);
898 else if (strcmp (var
, "color_board_black") == 0)
899 parse_color (filename
, lines
, val
, &config
.color
[CONF_BBLACK
]);
900 else if (strcmp (var
, "color_board_white") == 0)
901 parse_color (filename
, lines
, val
, &config
.color
[CONF_BWHITE
]);
902 else if (strcmp (var
, "color_board_graphics") == 0)
903 parse_color (filename
, lines
, val
, &config
.color
[CONF_BGRAPHICS
]);
904 else if (strcmp (var
, "color_board_coords") == 0)
905 parse_color (filename
, lines
, val
, &config
.color
[CONF_BCOORDS
]);
906 else if (strcmp (var
, "color_board_castling") == 0)
907 parse_color (filename
, lines
, val
, &config
.color
[CONF_BCASTLING
]);
908 else if (strcmp (var
, "color_board_enpassant") == 0)
909 parse_color (filename
, lines
, val
, &config
.color
[CONF_BENPASSANT
]);
910 else if (strcmp (var
, "color_board_attack") == 0)
911 parse_color (filename
, lines
, val
, &config
.color
[CONF_BATTACK
]);
912 else if (strcmp (var
, "color_board_prev_move") == 0)
913 parse_color (filename
, lines
, val
, &config
.color
[CONF_BPREVMOVE
]);
914 else if (strcmp (var
, "color_status_window") == 0)
915 parse_color (filename
, lines
, val
, &config
.color
[CONF_SWINDOW
]);
916 else if (strcmp (var
, "color_status_title") == 0)
917 parse_color (filename
, lines
, val
, &config
.color
[CONF_STITLE
]);
918 else if (strcmp (var
, "color_status_border") == 0)
919 parse_color (filename
, lines
, val
, &config
.color
[CONF_SBORDER
]);
920 else if (strcmp (var
, "color_status_notify") == 0)
921 parse_color (filename
, lines
, val
, &config
.color
[CONF_SNOTIFY
]);
922 else if (strcmp (var
, "color_status_engine") == 0)
923 parse_color (filename
, lines
, val
, &config
.color
[CONF_SENGINE
]);
924 else if (strcmp (var
, "color_tag_window") == 0)
925 parse_color (filename
, lines
, val
, &config
.color
[CONF_TWINDOW
]);
926 else if (strcmp (var
, "color_tag_title") == 0)
927 parse_color (filename
, lines
, val
, &config
.color
[CONF_TTITLE
]);
928 else if (strcmp (var
, "color_tag_border") == 0)
929 parse_color (filename
, lines
, val
, &config
.color
[CONF_TBORDER
]);
930 else if (strcmp (var
, "color_history_window") == 0)
931 parse_color (filename
, lines
, val
, &config
.color
[CONF_HWINDOW
]);
932 else if (strcmp (var
, "color_history_title") == 0)
933 parse_color (filename
, lines
, val
, &config
.color
[CONF_HTITLE
]);
934 else if (strcmp (var
, "color_history_border") == 0)
935 parse_color (filename
, lines
, val
, &config
.color
[CONF_HBORDER
]);
936 else if (strcmp (var
, "color_message_window") == 0)
937 parse_color (filename
, lines
, val
, &config
.color
[CONF_MWINDOW
]);
938 else if (strcmp (var
, "color_message_title") == 0)
939 parse_color (filename
, lines
, val
, &config
.color
[CONF_MTITLE
]);
940 else if (strcmp (var
, "color_message_border") == 0)
941 parse_color (filename
, lines
, val
, &config
.color
[CONF_MBORDER
]);
942 else if (strcmp (var
, "color_message_prompt") == 0)
943 parse_color (filename
, lines
, val
, &config
.color
[CONF_MPROMPT
]);
944 else if (strcmp (var
, "color_input_window") == 0)
945 parse_color (filename
, lines
, val
, &config
.color
[CONF_IWINDOW
]);
946 else if (strcmp (var
, "color_input_title") == 0)
947 parse_color (filename
, lines
, val
, &config
.color
[CONF_ITITLE
]);
948 else if (strcmp (var
, "color_input_border") == 0)
949 parse_color (filename
, lines
, val
, &config
.color
[CONF_IBORDER
]);
950 else if (strcmp (var
, "color_input_prompt") == 0)
951 parse_color (filename
, lines
, val
, &config
.color
[CONF_IPROMPT
]);
952 else if (strcmp (var
, "color_menu") == 0)
953 parse_color (filename
, lines
, val
, &config
.color
[CONF_MENU
]);
954 else if (strcmp (var
, "color_menu_selected") == 0)
955 parse_color (filename
, lines
, val
, &config
.color
[CONF_MENUS
]);
956 else if (strcmp (var
, "color_menu_highlight") == 0)
957 parse_color (filename
, lines
, val
, &config
.color
[CONF_MENUH
]);
958 else if (strcmp (var
, "color_menu_graphics") == 0)
959 parse_color (filename
, lines
, val
,
960 &config
.color
[CONF_HISTORY_MENU_LG
]);
961 else if (strcmp (var
, "bind") == 0)
962 parse_key_binding (filename
, lines
, val
);
963 else if (strcmp (var
, "macro") == 0)
964 parse_macro (filename
, lines
, val
);
965 else if (strcmp (var
, "cbind") == 0)
967 config
.keys
= Realloc (config
.keys
, (k
+ 2) *
968 sizeof (struct config_key_s
*));
969 config
.keys
[k
] = Calloc (1, sizeof (struct config_key_s
));
973 while (*p
&& !isspace (*p
))
980 if (strcasecmp (p
, "none") == 0)
981 config
.keys
[k
]->type
= KEY_DEFAULT
;
982 else if (strcasecmp (p
, "repeat") == 0)
983 config
.keys
[k
]->type
= KEY_REPEAT
;
984 else if (strcasecmp (p
, "set") == 0)
985 config
.keys
[k
]->type
= KEY_SET
;
987 errx (EXIT_FAILURE
, _("%s(%i): invalid value \"%s\""), filename
,
993 while (*p
&& isspace (*p
))
996 config
.keys
[k
]->c
= *p
++;
1001 config
.keys
[k
++]->str
= str_to_wchar (p
);
1002 config
.keys
[k
] = NULL
;
1005 errx (EXIT_FAILURE
, _("%s(%i): invalid parameter \"%s\""), filename
,
1013 free (config
.engine_cmd
);
1014 config
.engine_cmd
= NULL
;
1015 config
.engine_cmd
= altengine
;
1018 if (config
.enginecmdblacktag
)
1019 pgn_tag_add (&config
.tag
, (char *) "Black", config
.engine_cmd
);
1022 static struct key_s
*
1023 find_key (struct key_s
**keys
, key_func f
)
1027 for (i
= 0; keys
[i
]; i
++)
1029 if (keys
[i
]->f
== f
)
1037 key_lookup (struct key_s
**keys
, key_func f
)
1039 struct key_s
*k
= find_key (keys
, f
);
1041 return k
? k
->key
: NULL
;
1045 keycode_lookup (struct key_s
**keys
, key_func f
)
1047 struct key_s
*k
= find_key (keys
, f
);
1049 return k
? k
->c
: 0;