X-Git-Url: https://plomlompom.com/repos/test.html?a=blobdiff_plain;f=keybindings.c;h=3e1b19ab9ff545b8d4728b481729b8f5751955f2;hb=165320332a172d597e9b312d6b5d17af6abaa507;hp=1906d1d0c797c79a63e2528b6efb4fd321ab39e7;hpb=122747fbbdc061942de2fc2bca901a44a6b4ab61;p=plomrogue
diff --git a/keybindings.c b/keybindings.c
index 1906d1d..3e1b19a 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");