From 084ca94a939409b9c3c6c2e618052e433175e7cb Mon Sep 17 00:00:00 2001 From: Allanis Date: Sun, 25 May 2014 19:43:19 +0100 Subject: [PATCH] [Change] Code cleanup and doxygen. --- src/lstd.c | 15 +++++++++++++-- src/lstd.h | 1 + src/options.c | 4 ++++ src/toolkit.c | 6 +++--- 4 files changed, 21 insertions(+), 5 deletions(-) diff --git a/src/lstd.c b/src/lstd.c index 6de1e7e..71765ad 100644 --- a/src/lstd.c +++ b/src/lstd.c @@ -5,6 +5,8 @@ */ #include "lstd.h" +#define lstd_checkascii(k) ((k & 0xff) == k) /**< Check to see if k is in ascii area. */ + /** * @brief Check to see if a key is alpha. * @param k Key to check. @@ -23,9 +25,9 @@ int lstd_isalpha(SDLKey k) { } /** - * @brief Like isalnum but for keysyms. + * @brief Check to see if a key is alphanumeric. * @param k Key to check. - * @return 1 if is alnum. + * @return 1 if is alphanumeric. */ int lstd_isalnum(SDLKey k) { int ret; @@ -43,3 +45,12 @@ int lstd_isalnum(SDLKey k) { return ret; } +/** + * @brief Check to see if a key is a control character. + * @param k Key to check. + * @param 1 if is a control character. + */ +int lstd_iscntrl(SDLKey k) { + return lstd_checkascii(k) ? iscntrl(k) : 0; +} + diff --git a/src/lstd.h b/src/lstd.h index 217700e..0990aa9 100644 --- a/src/lstd.h +++ b/src/lstd.h @@ -3,4 +3,5 @@ int lstd_isalpha(SDLKey k); int lstd_isalnum(SDLKey k); +int lstd_iscntrl(SDLKey k); diff --git a/src/options.c b/src/options.c index a7a0e28..c61cc7f 100644 --- a/src/options.c +++ b/src/options.c @@ -174,6 +174,8 @@ static void menuKeybinds_update(unsigned int wid, char* name) { /** * @brief Callback to set the sound level. + * @param wid Window calling the callback. + * @param str Name of the widget calling the callback. */ static void opt_setSFXLevel(unsigned int wid, char* str) { double vol; @@ -183,6 +185,8 @@ static void opt_setSFXLevel(unsigned int wid, char* str) { /** * @brief Callback to set the music level. + * @param wid Window calling the callback. + * @param str Name of the widget calling the callback. */ static void opt_setMusicLevel(unsigned int wid, char* str) { double vol; diff --git a/src/toolkit.c b/src/toolkit.c index fa6564f..9ae00a1 100644 --- a/src/toolkit.c +++ b/src/toolkit.c @@ -1975,7 +1975,7 @@ static int toolkit_inputInput(Uint8 type, Widget* inp, SDLKey key) { return 0; mods = SDL_GetModState(); - if(inp->dat.inp.oneline && isascii(key)) { + if(inp->dat.inp.oneline) { /* Backspace -> delete text. */ if((key == SDLK_BACKSPACE) && (inp->dat.inp.pos > 0)) { inp->dat.inp.input[--inp->dat.inp.pos] = '\0'; @@ -1993,11 +1993,11 @@ static int toolkit_inputInput(Uint8 type, Widget* inp, SDLKey key) { inp->dat.inp.input[inp->dat.inp.pos++] = '\n'; /* Uppder case characters. */ - else if(isalpha(key) && (mods & (KMOD_LSHIFT | KMOD_RSHIFT))) + else if(lstd_isalpha(key) && (mods & (KMOD_LSHIFT | KMOD_RSHIFT))) inp->dat.inp.input[inp->dat.inp.pos++] = toupper(key); /* Rest. */ - else if(!iscntrl(key)) + else if(!lstd_iscntrl(key)) inp->dat.inp.input[inp->dat.inp.pos++] = key; /* Didn't get a useful key. */