diff options
| author | Franklin Wei <git@fwei.tk> | 2018-04-24 18:06:44 -0400 |
|---|---|---|
| committer | Franklin Wei <git@fwei.tk> | 2018-04-24 19:06:30 -0400 |
| commit | 8f23493e08febc09c370b1d90d891953fa43ddf7 (patch) | |
| tree | 99fcf3e896c96c969bf2b424af8e327a3cf74787 /apps/plugins/puzzles/src/misc.c | |
| parent | ef0fb52113447c15f97eb8c707f56db4074eb578 (diff) | |
| download | rockbox-8f23493e08febc09c370b1d90d891953fa43ddf7.zip rockbox-8f23493e08febc09c370b1d90d891953fa43ddf7.tar.gz rockbox-8f23493e08febc09c370b1d90d891953fa43ddf7.tar.bz2 rockbox-8f23493e08febc09c370b1d90d891953fa43ddf7.tar.xz | |
puzzles: resync with upstream
This brings the upstream version to b3da238 (though some of my own
changes are included on top of that).
Change-Id: Ida73e8cd86765413147ce891af3cc2b7aeda2b2a
Diffstat (limited to 'apps/plugins/puzzles/src/misc.c')
| -rw-r--r-- | apps/plugins/puzzles/src/misc.c | 66 |
1 files changed, 66 insertions, 0 deletions
diff --git a/apps/plugins/puzzles/src/misc.c b/apps/plugins/puzzles/src/misc.c index 83671a2..6b4414f 100644 --- a/apps/plugins/puzzles/src/misc.c +++ b/apps/plugins/puzzles/src/misc.c @@ -21,6 +21,15 @@ void free_cfg(config_item *cfg) sfree(cfg); } +void free_keys(key_label *keys, int nkeys) +{ + int i; + + for(i = 0; i < nkeys; i++) + sfree(keys->label); + sfree(keys); +} + /* * The Mines (among others) game descriptions contain the location of every * mine, and can therefore be used to cheat. @@ -169,6 +178,25 @@ unsigned char *hex2bin(const char *in, int outlen) return ret; } +char *fgetline(FILE *fp) +{ + char *ret = snewn(512, char); + int size = 512, len = 0; + while (fgets(ret + len, size - len, fp)) { + len += strlen(ret + len); + if (ret[len-1] == '\n') + break; /* got a newline, we're done */ + size = len + 512; + ret = sresize(ret, size, char); + } + if (len == 0) { /* first fgets returned NULL */ + sfree(ret); + return NULL; + } + ret[len] = '\0'; + return ret; +} + void game_mkhighlight_specific(frontend *fe, float *ret, int background, int highlight, int lowlight) { @@ -380,4 +408,42 @@ int ftoa(char *buf, float f) return sprintf(buf, "%d.%06d", (int)f, abs((int)((f - (int)f)*1e6))); } +/* Returns a dynamically allocated label for a generic button. + * Game-specific buttons should go into the `label' field of key_label + * instead. */ +char *button2label(int button) +{ + /* check if it's a keyboard button */ + if(('A' <= button && button <= 'Z') || + ('a' <= button && button <= 'z') || + ('0' <= button && button <= '9') ) + { + char str[2]; + str[0] = button; + str[1] = '\0'; + return dupstr(str); + } + + switch(button) + { + case CURSOR_UP: + return dupstr("Up"); + case CURSOR_DOWN: + return dupstr("Down"); + case CURSOR_LEFT: + return dupstr("Left"); + case CURSOR_RIGHT: + return dupstr("Right"); + case CURSOR_SELECT: + return dupstr("Select"); + case '\b': + return dupstr("Clear"); + default: + fatal("unknown generic key"); + } + + /* should never get here */ + return NULL; +} + /* vim: set shiftwidth=4 tabstop=8: */ |