X-Git-Url: https://plomlompom.com/repos/?a=blobdiff_plain;f=src%2Fclient%2Fkeybindings.c;h=eb67f26755b3967a5b06b6c497278e42af218a5b;hb=d6093b3a7d57aa34d3ee2a84112c59328bf1feed;hp=7207641d457b585a62e07a2c62db5d155dd68c45;hpb=fb9b40f0535b28b37b64983240c4b78e74ee9a2c;p=plomrogue diff --git a/src/client/keybindings.c b/src/client/keybindings.c index 7207641..eb67f26 100644 --- a/src/client/keybindings.c +++ b/src/client/keybindings.c @@ -3,13 +3,14 @@ #include "keybindings.h" #include /* keycode defines, cbreak(), halfdelay(), getch() */ #include /* NULL */ -#include /* FILE, sprintf(), snprintf() */ #include /* uint8_t, uint16_t, uint32_t */ +#include /* FILE, sprintf() */ #include /* free(), atoi() */ #include /* strlen(), strchr(), strcmp() */ -#include "../common/readwrite.h" /* textfile_sizes(), try_fgets(),try_fwrite()*/ +#include "../common/readwrite.h" /* try_fwrite()*/ #include "../common/try_malloc.h" /* try_malloc() */ -#include "wincontrol.h" /* get_winconf_by_win() */ +#include "command_db.h" /* get_command() */ +#include "err_try_fgets.h" /* err_try_fgets(), err_line() */ #include "windows.h" /* draw_all_wins() */ #include "world.h" /* global world */ @@ -82,8 +83,8 @@ static struct KeyBindingDB * char_selected_kb_db(char c) } else if ('w' == c) { - struct WinConf * wc = get_winconf_by_win(world.wins.win_active); - kbd = &wc->kb; + struct Win * w = get_win_by_id(world.winDB.active); + kbd = &w->kb; } return kbd; } @@ -159,8 +160,7 @@ extern char * get_keyname_to_keycode(uint16_t keycode) -extern void write_keybindings_to_file(FILE * file, struct KeyBindingDB * kbd, - char * delim) +extern void write_keybindings_to_file(FILE * file, struct KeyBindingDB * kbd) { char * f_name = "write_keybindings_to_file()"; uint16_t linemax = 0; @@ -182,7 +182,7 @@ extern void write_keybindings_to_file(FILE * file, struct KeyBindingDB * kbd, try_fwrite(line, sizeof(char), strlen(line), file, f_name); kb_p = kb_p->next; } - try_fwrite(delim, strlen(delim), 1, file, f_name); + try_fwrite(world.delim, strlen(world.delim), 1, file, f_name); } @@ -191,26 +191,40 @@ extern void read_keybindings_from_file(char * line, uint32_t linemax, FILE * file, struct KeyBindingDB * kbd) { char * f_name = "read_keybindings_from_file()"; - char * cmdptr; + char * context = "Failed reading keybindings from interface config file. "; + char * err_space = "Line illegally ends in whitespace."; + char * err_nospace = "No whitespace found in line."; + char * err_int = "Line starts not with a decimal number in digits."; + char * err_toolarge = "Keycode number too large, must be below 1000."; + char * err_cmd = "No such command in command DB."; struct KeyBinding ** loc_last_ptr = &kbd->kbs; * loc_last_ptr = 0; - while (try_fgets(line, linemax + 1, file, f_name)) + while (1) { - if (!strcmp("%\n", line)) + err_try_fgets(line, linemax, file, context, "0nf"); + if (!strcmp(world.delim, line)) { break; } + err_line(' ' == line[strlen(line) - 2], line, context, err_space); + char * ptr_space; + err_line(!(ptr_space = strchr(line, ' ')), line, context, err_nospace); + uint8_t i = 0; + err_line(0 == (ptr_space - line), line, context, err_int); + for (; i < (ptr_space - line); i++) + { + err_line(line[i] < '0' || '9' < line[i], line, context, err_int); + } + err_line(i > 3, line, context, err_toolarge); * loc_last_ptr = try_malloc(sizeof(struct KeyBinding), f_name); struct KeyBinding * kb_p = * loc_last_ptr; + line[strlen(line) - 1] = '\0'; + kb_p->command = get_command(ptr_space + 1); + err_line(!(kb_p->command), line, context, err_cmd); kb_p->next = 0; kb_p->key = atoi(line); - cmdptr = strchr(line, ' ') + 1; - cmdptr[strlen(cmdptr) - 1] = '\0'; - kb_p->command = get_command(cmdptr); loc_last_ptr = & kb_p->next; } - kbd->edit = 0; - kbd->select = 0; }