X-Git-Url: https://plomlompom.com/repos/test.html?a=blobdiff_plain;f=src%2Fclient%2Finterface_conf.c;h=e3bfd022a5db6d3c61c1757d1819cb894935849a;hb=7e43b1fff89706212291384ddaa762fa30b02cb4;hp=69ef9eb54675fe2f009359e0de502727103801df;hpb=c53b42dfc7e4de104f9189428dd5b9a0d431c00a;p=plomrogue
diff --git a/src/client/interface_conf.c b/src/client/interface_conf.c
index 69ef9eb..e3bfd02 100644
--- a/src/client/interface_conf.c
+++ b/src/client/interface_conf.c
@@ -7,10 +7,14 @@
#include /* UINT8_MAX, uint8_t, uint32_t */
#include /* EXIT_SUCCESS, atoi(), exit(), free() */
#include /* FILE, sprintf() */
-#include /* memset(), strchr(), strcmp(), strdup(), strlen() */
+#include /* strchr(), strcmp(), strdup(), strlen() */
#include /* optarg, getopt() */
-#include "../common/parse_file.h" /* EDIT_STARTED, parse_file(), set_val(),
- * token_from_line()
+#include "../common/parse_file.h" /* EDIT_STARTED, parse_file(),parse_flagval(),
+ * token_from_line(), parsetest_singlechar(),
+ * parse_and_reduce_to_readyflag(),
+ * parsetest_defcontext(),parse_unknown_arg(),
+ * parsetest_too_many_values(),
+ * parse_id_uniq(), parse_init_entry()
*/
#include "../common/readwrite.h" /* try_fopen(), try_fclose_unlink_rename(),
* try_fwrite()
@@ -20,7 +24,7 @@
#include "array_append.h" /* array_append() */
#include "cleanup.h" /* set_cleanup_flag() */
#include "command_db.h" /* get_command() */
-#include "keybindings.h" /* KeyBinding, KeyBindingDB, get_command_to_keycode() */
+#include "keybindings.h" /* KeyBinding, KeyBindingDB, get_command_to_keycode()*/
#include "map.h" /* map_center() */
#include "wincontrol.h" /* toggle_window() */
#include "windows.h" /* Win, free_winDB(), make_v_screen_and_init_win_sizes() */
@@ -98,18 +102,17 @@ static uint8_t start_kbd(char * token0, char * token1, char * str_kbd,
/* Helper to tokens_into_entries(), sets specific entry member data. "token0"
* and the state of flags determine what entry member to edit; "win" and "kbdb"
* are entries to write "token1" data into (as is the global "tmp_active"). If
- * "token0" is "KEY", a keybinding is defined and "token2" is read / must not be
- * NULL. In that case, the line read is checked against having a 4th token.
+ * "token0" is "str_key", a keybinding is defined and "token2" is read/must not
+ * be NULL. In that case, the line read is checked against having a 4th token.
*/
-static uint8_t set_members(char * token0, char * token1, char * token2,
- uint8_t * win_flags, uint8_t * ord_flags,
- uint8_t kbd_flags,
+static uint8_t set_members(char * token0, char * token1, uint8_t * win_flags,
+ uint8_t * ord_flags,uint8_t kbd_flags,char * str_key,
struct Win * win, struct KeyBindingDB * kbdb);
/* Add keybinding defined in "token1" as keycode and "token2" as command to
* "kbdb" if "flags" are set to EDIT_STARTED.
*/
-static void set_keybindings(char * token1, char * token2, uint8_t flags,
+static void set_keybindings(char * token1, uint8_t flags,
struct KeyBindingDB * kbdb);
@@ -140,7 +143,7 @@ static void write_def(FILE * file, char * prefix, uint8_t quotes, char * val,
char type)
{
char * f_name = "write_def()";
- char * val_str;
+ char * val_str = NULL;
int test_val_str = 1;
if ('s' == type)
{
@@ -179,6 +182,7 @@ static void tokens_into_entries(char * token0, char * token1)
char * str_win = "WINDOW";
char * str_ord = "WIN_ORDER";
char * str_kbd = "KEYBINDINGS";
+ char * str_key = "KEY";
static uint8_t win_flags = READY_WIN;
static uint8_t ord_flags = READY_ORD;
static uint8_t kbd_flags = READY_KBD;
@@ -187,29 +191,25 @@ static void tokens_into_entries(char * token0, char * token1)
if (!token0 || !strcmp(token0, str_win) || !strcmp(token0, str_ord)
|| !strcmp(token0, str_kbd))
{
- err_line( ((win_flags & READY_WIN) ^ READY_WIN)
- || ((ord_flags & READY_ORD) ^ READY_ORD)
- || ((kbd_flags & READY_KBD) ^ READY_KBD),
- "Last definition block not yet finished yet.");
+ parse_and_reduce_to_readyflag(&win_flags, READY_WIN);
+ parse_and_reduce_to_readyflag(&ord_flags, READY_ORD);
+ parse_and_reduce_to_readyflag(&kbd_flags, READY_KBD);
write_if_win(&win);
- ord_flags = READY_ORD;
- win_flags = READY_WIN;
- kbd_flags = READY_KBD;
}
- if (!token0)
+ if (token0)
{
- return;
- }
- char * token2 = token_from_line(NULL);
- err_line(strcmp(token0, "KEY") && NULL != token2, "Too many values.");
- if ( start_win(token0, token1, str_win, &win_flags, &win)
- || start_ord(token0, token1, str_ord, &ord_flags)
- || start_kbd(token0, token1, str_kbd, &kbd_flags, &kbdb)
- || set_members(token0, token1, token2, &win_flags, &ord_flags,
- kbd_flags, win, kbdb));
- else
- {
- err_line(1, "Unknown argument.");
+ if (strcmp(token0, str_key))
+ {
+ parsetest_too_many_values();
+ }
+ if (!( start_win(token0, token1, str_win, &win_flags, &win)
+ || start_ord(token0, token1, str_ord, &ord_flags)
+ || start_kbd(token0, token1, str_kbd, &kbd_flags, &kbdb)
+ || set_members(token0, token1, &win_flags, &ord_flags, kbd_flags,
+ str_key, win, kbdb)))
+ {
+ parse_unknown_arg();
+ }
}
}
@@ -245,14 +245,9 @@ static uint8_t start_win(char * token0, char * token1, char * str_win,
{
return 0;
}
- char * f_name = "start_win()";
- char * err_uniq = "Declaration of ID already used.";
- *win_flags = EDIT_STARTED;
- *win = try_malloc(sizeof(struct Win), f_name);
- memset(*win, 0, sizeof(struct Win));
- err_line(1 != strlen(token1), "Value must be single ASCII character.");
- err_line( world.winDB.ids
- && (NULL != strchr(world.winDB.ids, token1[0])), err_uniq);
+ *win = (struct Win *) parse_init_entry(win_flags, sizeof(struct Win));
+ parsetest_singlechar(token1);
+ parse_id_uniq(world.winDB.ids && (NULL!=strchr(world.winDB.ids,token1[0])));
(*win)->id = token1[0];
return 1;
}
@@ -312,40 +307,38 @@ static uint8_t start_kbd(char * token0, char * token1, char * str_kbd,
-static uint8_t set_members(char * token0, char * token1, char * token2,
- uint8_t * win_flags, uint8_t * ord_flags,
- uint8_t kbd_flags,
+static uint8_t set_members(char * token0, char * token1, uint8_t * win_flags,
+ uint8_t * ord_flags,uint8_t kbd_flags,char * str_key,
struct Win * win, struct KeyBindingDB * kbdb)
{
- if ( set_val(token0, token1, "NAME", win_flags,
- NAME_SET, 's', (char *) &win->title)
- || set_val(token0, token1, "WIDTH", win_flags,
- WIDTH_SET, 'i', (char *) &win->target_width)
- || set_val(token0, token1, "HEIGHT", win_flags,
- HEIGHT_SET, 'i', (char *) &win->target_height));
- else if (set_val(token0, token1, "BREAK", win_flags,
- BREAK_SET, '8', (char *) &win->linebreak))
+ if ( parse_flagval(token0, token1, "NAME", win_flags,
+ NAME_SET, 's', (char *) &win->title)
+ || parse_flagval(token0, token1, "WIDTH", win_flags,
+ WIDTH_SET, 'i', (char *) &win->target_width)
+ || parse_flagval(token0, token1, "HEIGHT", win_flags,
+ HEIGHT_SET, 'i', (char *) &win->target_height));
+ else if (parse_flagval(token0, token1, "BREAK", win_flags,
+ BREAK_SET, '8', (char *) &win->linebreak))
{
err_line(2 < win->linebreak, "Value must be 0, 1 or 2.");
}
- else if (set_val(token0, token1, "WIN_FOCUS", ord_flags,
- FOCUS_SET, 'c', &tmp_active))
+ else if (parse_flagval(token0, token1, "WIN_FOCUS", ord_flags,
+ FOCUS_SET, 'c', &tmp_active))
{
char * err_null = "Value not empty as it should be.";
char * err_outside = "ID not found in WIN_ORDER ID series.";
err_line(!strlen(tmp_order) && tmp_active, err_null);
err_line(!strchr(tmp_order, tmp_active), err_outside);
}
- else if (!strcmp(token0, "KEY"))
+ else if (!strcmp(token0, str_key))
{
- err_line(NULL != token_from_line(NULL), "Too many values.");
- if (* win_flags & EDIT_STARTED)
+ if (*win_flags & EDIT_STARTED)
{
- set_keybindings(token1, token2, * win_flags, &win->kb);
+ set_keybindings(token1, *win_flags, &win->kb);
}
else
{
- set_keybindings(token1, token2, kbd_flags, kbdb);
+ set_keybindings(token1, kbd_flags, kbdb);
}
}
else
@@ -357,13 +350,14 @@ static uint8_t set_members(char * token0, char * token1, char * token2,
-static void set_keybindings(char * token1, char * token2, uint8_t flags,
+static void set_keybindings(char * token1, uint8_t flags,
struct KeyBindingDB * kbdb)
{
- char * err_out = "Outside appropriate definition's context.";
- char * err_code = "Invalid keycode. Must be >= 0 and < 1000.";
- err_line(!(flags & EDIT_STARTED), err_out);
+ char * token2 = token_from_line(NULL);
err_line(!token2, "No binding to key given.");
+ parsetest_too_many_values();
+ char * err_code = "Invalid keycode. Must be >= 0 and < 1000.";
+ parsetest_defcontext(flags);
char * err_many = "No more than 255 keybindings allowed in one section.";
err_line(UINT8_MAX == kbdb->n_of_kbs, err_many);
struct KeyBinding kb;
@@ -495,4 +489,3 @@ extern void reload_interface_conf()
map_center();
world.winDB.v_screen_offset = 0;
}
-