File size: 1,152 Bytes
910db9a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 | #include "rcparser.h"
static void makeKeybind(ned_keybinds* kb, wchar_t key, wchar_t* val)
{
if (wcscmp(val, L"UP"))
ned_keybinds_push(kb, ned_keybind_new(key, NED_COMMAND_UP));
else if (wcscmp(val, L"DOWN"))
ned_keybinds_push(kb, ned_keybind_new(key, NED_COMMAND_DOWN));
else if (wcscmp(val, L"LEFT"))
ned_keybinds_push(kb, ned_keybind_new(key, NED_COMMAND_LEFT));
else if (wcscmp(val, L"RIGHT"))
ned_keybinds_push(kb, ned_keybind_new(key, NED_COMMAND_RIGHT));
else if (wcscmp(val, L"SAVE"))
ned_keybinds_push(kb, ned_keybind_new(key, NED_COMMAND_SAVE));
}
ned_keybinds* ned_rcparse(wchar_t* rcstr)
{
ned_keybinds* kb = ned_keybinds_new();
size_t i = 0;
wchar_t c = NULL;
wchar_t prev = NULL;
wchar_t key = 0;
wchar_t* val = NULL;
size_t vallen = 0;
while (1)
{
c = val[i];
if (c == L'=')
{
key = prev;
}
else if (key != 0 && c != L'\n')
{
++vallen;
val = realloc(val, vallen);
val[vallen-1] = c;
}
else if (c == L'\n')
{
val = realloc(val, vallen+1);
val[vallen] = 0;
makeKeybind(kb, key, val);
key = 0;
val = NULL;
vallen = 0;
}
prev = c;
++i;
}
return kb;
}
|