+#include <stdlib.h>
+#include <stdint.h>
#include <ncurses.h>
#include <string.h>
-#include <stdlib.h>
#include "windows.h"
#include "roguelike.h"
#include "keybindings.h"
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);
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);
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);
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);
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");