-extern void write_keybindings_to_file(FILE * file, struct KeyBindingDB * kbd)
-{
- char * f_name = "write_keybindings_to_file()";
- uint16_t linemax = 0;
- struct KeyBinding * kb_p = kbd->kbs;
- while (0 != kb_p)
- {
- if (strlen(kb_p->command->dsc_short) > linemax)
- {
- linemax = strlen(kb_p->command->dsc_short);
- }
- kb_p = kb_p->next;
- }
- linemax = linemax + 6; /* + 6 = + 3 digits + ' ' + '\n' + '\0' */
- char line[linemax];
- kb_p = kbd->kbs;
- while (0 != kb_p)
- {
- sprintf(line, "%d %s\n", kb_p->keycode, kb_p->command->dsc_short);
- try_fwrite(line, sizeof(char), strlen(line), file, f_name);
- kb_p = kb_p->next;
- }
- try_fwrite(world.delim, strlen(world.delim), 1, file, f_name);
-}
-
-
-
-extern void read_keybindings_from_file(char * line, uint32_t linemax,
- FILE * file, struct KeyBindingDB * kbd)
-{
- char * f_name = "read_keybindings_from_file()";
- 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 (1)
- {
- 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->keycode = atoi(line);
- loc_last_ptr = & kb_p->next;
- }
-}
-
-
-
-extern void free_keybindings(struct KeyBinding * kb_start)
-{
- if (0 == kb_start)
- {
- return;
- }
- struct KeyBinding * kb_p = kb_start->next;
- if (0 != kb_p)
- {
- free_keybindings(kb_p);
- }
- free(kb_start);
-}
-
-
-