X-Git-Url: https://plomlompom.com/repos/index.html?a=blobdiff_plain;f=keybindings.c;h=b6ff412c6f734fbb48093d7ddcdf9cc539af27e8;hb=02b0be5f5500784e03d060fad82746da00e78edc;hp=1906d1d0c797c79a63e2528b6efb4fd321ab39e7;hpb=122747fbbdc061942de2fc2bca901a44a6b4ab61;p=plomrogue
diff --git a/keybindings.c b/keybindings.c
index 1906d1d..b6ff412 100644
--- a/keybindings.c
+++ b/keybindings.c
@@ -1,6 +1,7 @@
+#include
+#include
#include
#include
-#include
#include "windows.h"
#include "roguelike.h"
#include "keybindings.h"
@@ -8,10 +9,10 @@
void init_keybindings(struct World * world) {
// Initialize keybindings from file "keybindings".
FILE * file = fopen("keybindings", "r");
- int lines = 0;
+ uint16_t lines = 0;
int c = 0;
- int linemax = 0;
- int c_count = 0;
+ uint16_t linemax = 0;
+ uint16_t c_count = 0;
while (EOF != c) {
c_count++;
c = getc(file);
@@ -23,7 +24,7 @@ void init_keybindings(struct World * world) {
struct KeyBinding * keybindings = malloc(lines * sizeof(struct KeyBinding));
fseek(file, 0, SEEK_SET);
char * command = malloc(linemax);
- int commcount = 0;
+ uint16_t commcount = 0;
char * cmdptr;
while (fgets(command, linemax, file)) {
keybindings[commcount].key = atoi(command);
@@ -46,8 +47,8 @@ void save_keybindings(struct World * world) {
struct KeysWinData * keyswindata = (struct KeysWinData *) world->keyswindata;
struct KeyBinding * keybindings = world->keybindings;
FILE * file = fopen("keybindings", "w");
- int linemax = 0;
- int i;
+ uint16_t linemax = 0;
+ uint16_t i;
for (i = 0; i <= keyswindata->max; i++)
if (strlen(keybindings[i].name) > linemax)
linemax = strlen(keybindings[i].name);
@@ -59,14 +60,14 @@ void save_keybindings(struct World * world) {
free(line);
fclose(file); }
-int get_action_key (struct KeyBinding * keybindings, char * name) {
+uint16_t get_action_key (struct KeyBinding * keybindings, char * name) {
// Return key matching name in keybindings.
- int i = 0;
+ uint16_t i = 0;
while (strcmp(keybindings[i].name, name) )
i++;
return keybindings[i].key; }
-char * get_keyname(int keycode) {
+char * get_keyname(uint16_t keycode) {
// Translate some keycodes to readable names of max 9 chars.
char * keyname;
keyname = malloc(15);
@@ -93,7 +94,7 @@ char * get_keyname(int keycode) {
else if (keycode == KEY_BACKSPACE)
sprintf(keyname, "BACKSPACE");
else if (keycode >= KEY_F0 && keycode <= KEY_F(63)) {
- int f = keycode - KEY_F0;
+ uint16_t f = keycode - KEY_F0;
sprintf(keyname, "F%d", f); }
else if (keycode == KEY_DC)
sprintf(keyname, "DELETE");
@@ -112,7 +113,7 @@ char * get_keyname(int keycode) {
void keyswin_mod_key (struct World * world, struct WinMeta * win_meta) {
// In keybindings window, mark selection modifiable, modify key. Ensure max of three digits in key code field.
world->keyswindata->edit = 1;
- draw_all_windows (win_meta);
+ draw_all_wins (win_meta);
int key = getch();
if (key < 1000)
world->keybindings[world->keyswindata->select].key = key;