| 1 | /* |
| 2 | Rebindable key mappings. |
| 3 | */ |
| 4 | |
| 5 | |
| 6 | #ifdef HAVE_CONFIG_Hcxx . . $ `<built-in>:481:9`! |
| 7 | # include "config.h"cxx . . $ `<file>/config.h`/ |
| 8 | #endif |
| 9 | #include <stdio.h> |
| 10 | #include <stdlib.h> |
| 11 | #include <string.h> |
| 12 | #include <stdint.h> |
| 13 | #include <SDL/SDL_keyboard.h> |
| 14 | #include <SDL/SDL_keysym.h> |
| 15 | |
| 16 | #include "sexpr/sexp.h"cxx . . $ `<file>/src/sexpr/sexp.h`/ |
| 17 | #include "binds.h"cxx . . $ `<file>/src/binds.h`/ |
| 18 | |
| 19 | |
| 20 | oeskeymap_tcxx . . $ oeskeymap_t# oeskeymapcxx . . $ oeskeymap. = { 0, }; |
| 21 | sexp_tcxx . . $ sexp_t# *addlkeyscxx . . $ addlkeys. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 22 | |
| 23 | |
| 24 | |
| 25 | int |
| 26 | oeskeymap_nopcxx . . $ oeskeymap_nop(7864480464b09eea). (int val) |
| 27 | { |
| 28 | return 0; |
| 29 | } |
| 30 | |
| 31 | |
| 32 | /* Set up binds map. */ |
| 33 | int |
| 34 | oeskeymap_from_sexpcxx . . $ oeskeymap_from_sexp(4bfcdbe09bc7686d). (oeskeymap_tcxx . . $ oeskeymap_t# *self, sexp_tcxx . . $ sexp_t# *alist) |
| 35 | { |
| 36 | sexp_tcxx . . $ sexp_t# *se, *pair; |
| 37 | const char *sym, *bindname, *sc; |
| 38 | oes_xlat_tcxx . . $ oes_xlat_t# *x; |
| 39 | int keycode; |
| 40 | float scale; |
| 41 | oesbind_tcxx . . $ oesbind_t# binding; |
| 42 | //char buf[1024] = { 0, }; |
| 43 | |
| 44 | //printf("Keymap from sexp:\n"); |
| 45 | //print_sexp(buf, sizeof(buf), alist); |
| 46 | //printf("%s\n", buf); |
| 47 | if (!alist) return 0; |
| 48 | alist = alist->listcxx . . $ elt#list.; |
| 49 | sym = alist->valcxx . . $ elt#val.; |
| 50 | //printf("sym looks like '%s'\n", sym); |
| 51 | if (strcasecmp(sym, "bindmap")) /* must start with 'bindmap */ |
| 52 | return 0; |
| 53 | se = alist->nextcxx . . $ elt#next.; |
| 54 | for (; se; se = se->nextcxx . . $ elt#next.) |
| 55 | { |
| 56 | pair = se->listcxx . . $ elt#list.; |
| 57 | if (pair->tycxx . . $ elt#ty. != SEXP_VALUEcxx . . $ SEXP_VALUE.) |
| 58 | continue; |
| 59 | sym = pair->valcxx . . $ elt#val.; |
| 60 | bindname = pair->nextcxx . . $ elt#next.->valcxx . . $ elt#val.; |
| 61 | sc = pair->nextcxx . . $ elt#next.->nextcxx . . $ elt#next. ? pair->nextcxx . . $ elt#next.->nextcxx . . $ elt#next.->valcxx . . $ elt#val. : NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 62 | keycode = oeskeymap_resolvecxx . . $ oeskeymap_resolve(5c4306d8553b3696).(sym); |
| 63 | //printf("BINDLINE: %s, %s, %s\n", sym, bindname, sc); |
| 64 | x = oesxlatcxx . . $ oesxlat.; |
| 65 | binding = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 66 | while (x->symbolcxx . . $ oes_xlat_t#symbol.) |
| 67 | { |
| 68 | //printf("Checking intern bindfunc '%s' to '%s'\n", x->symbol, bindname); |
| 69 | if (0 == strcasecmp(x->symbolcxx . . $ oes_xlat_t#symbol., bindname)) |
| 70 | { |
| 71 | binding = x->bindingcxx . . $ oes_xlat_t#binding.; |
| 72 | break; |
| 73 | } |
| 74 | x++; |
| 75 | } |
| 76 | scale = sc ? atofcxx . . $ atof(9b0361fcbc284e4f).(sc) : 1.0f; |
| 77 | //printf("SETTING keymap[%d] = %08X x %f\n", keycode, binding, scale); |
| 78 | oeskeymap_setcxx . . $ oeskeymap_set(f63c713ba6d28aa7).(&oeskeymapcxx . . $ oeskeymap., keycode, binding, scale); |
| 79 | } |
| 80 | return 1; |
| 81 | } |
| 82 | |
| 83 | int |
| 84 | oeskeymap_loadcxx . . $ oeskeymap_load(6003e71dff3b69f1). (oeskeymap_tcxx . . $ oeskeymap_t# *self, const char *fname) |
| 85 | { |
| 86 | FILE *bindfile; |
| 87 | sexp_iowrap_tcxx . . $ sexp_iowrap_t# *io; |
| 88 | sexp_tcxx . . $ sexp_t# *se; |
| 89 | |
| 90 | //printf("LOADING FROM BINDFILE '%s'\n", fname); |
| 91 | if (!(bindfile = fopen(fname, "r"))) |
| 92 | { |
| 93 | //printf("Could not open '%s'\n", fname); |
| 94 | return 0; |
| 95 | } |
| 96 | io = init_iowrap(fileno(bindfile)); |
| 97 | // se = read_one_sexp(io); |
| 98 | se = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 99 | while (!oeskeymap_from_sexpcxx . . $ oeskeymap_from_sexp(4bfcdbe09bc7686d).(self, se)) |
| 100 | { |
| 101 | //printf("1 SEXP FROM BINDFILE\n"); |
| 102 | if (se) destroy_sexp(se); |
| 103 | se = read_one_sexp(io); |
| 104 | if (!se) break; |
| 105 | } |
| 106 | destroy_iowrap(io); |
| 107 | fclose(bindfile); |
| 108 | return 1; |
| 109 | } |
| 110 | |
| 111 | oeskeymap_tcxx . . $ oeskeymap_t# * |
| 112 | oeskeymap_initcxx . . $ oeskeymap_init(4554ac8aee1e3e31). (oeskeymap_tcxx . . $ oeskeymap_t# *self) |
| 113 | { |
| 114 | FILE *keysfile; |
| 115 | sexp_iowrap_tcxx . . $ sexp_iowrap_t# *io; |
| 116 | sexp_tcxx . . $ sexp_t# *se; |
| 117 | int i; |
| 118 | char *keysname="keys.cfg"; |
| 119 | char *keyspath; |
| 120 | |
| 121 | if (!self) |
| 122 | { |
| 123 | self = (oeskeymap_tcxx . . $ oeskeymap_t#*)calloccxx . . $ calloc(95acc9b79bb49189).(1, sizeof(*self)); |
| 124 | if (!self) return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 125 | } |
| 126 | for (i = 0; i < OESKEYMAPSIZEcxx . . $ `src/binds.h:9:9`!; i++) |
| 127 | { |
| 128 | // (*self)[i] = oeskeymap_nop; |
| 129 | (*self)[i] = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 130 | } |
| 131 | |
| 132 | if (addlkeyscxx . . $ addlkeys.) return self; |
| 133 | |
| 134 | keyspath=(char*)calloccxx . . $ calloc(95acc9b79bb49189).(1,strlen(GAMEDATADIRcxx . . $ `config.h:5:9`!)+1+strlen(keysname)+1); |
| 135 | sprintf(keyspath,"%s/%s",GAMEDATADIRcxx . . $ `config.h:5:9`!,keysname); |
| 136 | if (!(keysfile = fopen(keyspath, "r"))) { |
| 137 | fprintf(stderrcxx . . $ `<external>/232824719582829767/stdio.h:155:9`!,"Cannot open key config '%s'\n",keyspath); |
| 138 | exitcxx . . $ exit(44ed87f96534fad7).(1); |
| 139 | } |
| 140 | freecxx . . $ free(bd21765a0afc8e3c).(keyspath); |
| 141 | keyspath=NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 142 | |
| 143 | io = init_iowrap(fileno(keysfile)); |
| 144 | se = read_one_sexp(io); |
| 145 | if (se->tycxx . . $ elt#ty. == SEXP_LISTcxx . . $ SEXP_LIST.) |
| 146 | addlkeyscxx . . $ addlkeys. = se; |
| 147 | else |
| 148 | addlkeyscxx . . $ addlkeys. = NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 149 | destroy_iowrap(io); |
| 150 | fclose(keysfile); |
| 151 | |
| 152 | return self; |
| 153 | } |
| 154 | |
| 155 | int |
| 156 | oeskeymap_setcxx . . $ oeskeymap_set(f63c713ba6d28aa7). (oeskeymap_tcxx . . $ oeskeymap_t# *self, int key, oesbind_tcxx . . $ oesbind_t# binding, float scale) |
| 157 | { |
| 158 | if (key < 0) return 0; |
| 159 | if (key >= OESKEYMAPSIZEcxx . . $ `src/binds.h:9:9`!) return 0; |
| 160 | (*self)[key] = binding; |
| 161 | return key; |
| 162 | } |
| 163 | |
| 164 | oesbind_tcxx . . $ oesbind_t# |
| 165 | oeskeymap_getcxx . . $ oeskeymap_get(3f28065ff06886e1). (oeskeymap_tcxx . . $ oeskeymap_t# *self, int key) |
| 166 | { |
| 167 | if (key < 0) return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 168 | if (key >= OESKEYMAPSIZEcxx . . $ `src/binds.h:9:9`!) return NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!; |
| 169 | return (*self)[key]; |
| 170 | } |
| 171 | |
| 172 | const char * |
| 173 | oeskeymap_lookupcxx . . $ oeskeymap_lookup(f7ae7e56280f18ae). (int keycode) |
| 174 | { |
| 175 | static char keyname[256]; |
| 176 | sexp_tcxx . . $ sexp_t# *se; |
| 177 | int i; |
| 178 | |
| 179 | *keyname = 0; |
| 180 | if (keycode < 0) |
| 181 | { |
| 182 | snprintf(keyname, sizeof(keyname), "0x%04X", keycode); |
| 183 | return keyname; |
| 184 | } |
| 185 | if (keycode < SDLK_LASTcxx . . $ SDLK_LAST.) |
| 186 | { |
| 187 | snprintf(keyname, sizeof(keyname), "%s", SDL_GetKeyName((SDLKeycxx . . $ SDLKey#)keycode)); |
| 188 | return keyname; |
| 189 | } |
| 190 | se = addlkeyscxx . . $ addlkeys.->listcxx . . $ elt#list.; |
| 191 | i = 1; |
| 192 | while (se) |
| 193 | { |
| 194 | if (keycode == (SDLK_LASTcxx . . $ SDLK_LAST. + i)) |
| 195 | { |
| 196 | snprintf(keyname, sizeof(keyname), "%s", se->valcxx . . $ elt#val.); |
| 197 | return keyname; |
| 198 | } |
| 199 | se = se->nextcxx . . $ elt#next.; |
| 200 | } |
| 201 | snprintf(keyname, sizeof(keyname), "0x%04X", keycode); |
| 202 | return keyname; |
| 203 | } |
| 204 | |
| 205 | int |
| 206 | oeskeymap_resolvecxx . . $ oeskeymap_resolve(5c4306d8553b3696). (const char *keysym) |
| 207 | { |
| 208 | char lookup[256]; |
| 209 | const char *keyname; |
| 210 | int i; |
| 211 | int addlcode; |
| 212 | sexp_tcxx . . $ sexp_t# *se; |
| 213 | |
| 214 | /* Try with "SDLK_" prefix */ |
| 215 | snprintf(lookup, sizeof(lookup), "SDLK_%s", keysym); |
| 216 | //printf("oeskeymap_resolve: Looking for %s\n", lookup); |
| 217 | for (i = 0; i < SDLK_LASTcxx . . $ SDLK_LAST.; i++) |
| 218 | { |
| 219 | keyname = SDL_GetKeyName((SDLKeycxx . . $ SDLKey#)i); |
| 220 | //printf(" Checking '%s' against (%d)'%s'\n", lookup, i, keyname); |
| 221 | if (0 == strcasecmp(lookup, keyname)) |
| 222 | { |
| 223 | return i; |
| 224 | } |
| 225 | } |
| 226 | /* Not found with SDLK_ prefix. Try again without prefix. */ |
| 227 | snprintf(lookup, sizeof(lookup), "%s", keysym); |
| 228 | for (i = 0; i < SDLK_LASTcxx . . $ SDLK_LAST.; i++) |
| 229 | { |
| 230 | keyname = SDL_GetKeyName((SDLKeycxx . . $ SDLKey#)i); |
| 231 | //printf(" Checking '%s' against (%d)'%s'\n", lookup, i, keyname); |
| 232 | if (0 == strcasecmp(lookup, keyname)) |
| 233 | { |
| 234 | return i; |
| 235 | } |
| 236 | } |
| 237 | /* Not found as SDL key. Try additional keysyms. */ |
| 238 | se = addlkeyscxx . . $ addlkeys.->listcxx . . $ elt#list.; |
| 239 | addlcode = SDLK_LASTcxx . . $ SDLK_LAST. + 1; |
| 240 | snprintf(lookup, sizeof(lookup), "%s", keysym); |
| 241 | while (se) |
| 242 | { |
| 243 | if (se->tycxx . . $ elt#ty. == SEXP_LISTcxx . . $ SEXP_LIST.) |
| 244 | { |
| 245 | /* sym/code pair */ |
| 246 | keyname = se->listcxx . . $ elt#list.->valcxx . . $ elt#val.; |
| 247 | //printf(" Checking '%s' against [pair](%d)'%s'\n", lookup, i, keyname); |
| 248 | if (0 == strcasecmp(lookup, keyname)) |
| 249 | { |
| 250 | return strtolcxx . . $ strtol(8cc4c7acb13e570c).(se->listcxx . . $ elt#list.->nextcxx . . $ elt#next.->valcxx . . $ elt#val., NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, 0); |
| 251 | } |
| 252 | } |
| 253 | else |
| 254 | { |
| 255 | /* bare sym */ |
| 256 | keyname = se->valcxx . . $ elt#val.; |
| 257 | //printf(" Checking '%s' against [addl](%d)'%s'\n", lookup, addlcode, keyname); |
| 258 | if (0 == strcasecmp(lookup, keyname)) |
| 259 | { |
| 260 | return addlcode; |
| 261 | } |
| 262 | addlcode++; |
| 263 | } |
| 264 | se = se->nextcxx . . $ elt#next.; |
| 265 | } |
| 266 | /* Not found as additional keysym either. Interpret as integer. */ |
| 267 | i = strtolcxx . . $ strtol(8cc4c7acb13e570c).(keyname, NULLcxx . . $ `/usr/lib/gcc/x86_64-linux-gnu/15/include/stddef.h:416:9`!, 0); |
| 268 | return i; |
| 269 | } |
| 270 | |
| 271 | |
| 272 | |
| 273 | int |
| 274 | oeskeymap_testcxx . . $ oeskeymap_test(b126dc7c1de90089).() |
| 275 | { |
| 276 | oesbind_tcxx . . $ oesbind_t# x; |
| 277 | oeskeymap_initcxx . . $ oeskeymap_init(4554ac8aee1e3e31).(&oeskeymapcxx . . $ oeskeymap.); |
| 278 | x = oeskeymap_getcxx . . $ oeskeymap_get(3f28065ff06886e1).(&oeskeymapcxx . . $ oeskeymap., 0); |
| 279 | printf("BIND 0 = FUNC %p\n", x); |
| 280 | return 0; |
| 281 | } |