diff options
-rw-r--r-- | client/client.c | 7 | ||||
-rw-r--r-- | lib/draw/curses.c | 10 | ||||
-rw-r--r-- | lib/filter.c | 9 | ||||
-rw-r--r-- | lib/internal.h | 1 | ||||
-rw-r--r-- | lib/util.c | 13 |
5 files changed, 33 insertions, 7 deletions
diff --git a/client/client.c b/client/client.c index c031c0b..8e670b1 100644 --- a/client/client.c +++ b/client/client.c @@ -26,13 +26,16 @@ static void readItemsToMenuFromStdin(bmMenu *menu) } buffer[allocated - step + read - 1] = 0; - char *s; - for (s = strtok(buffer, "\n"); s; s = strtok(NULL, "\n")) { + size_t pos; + char *s = buffer; + while ((pos = strcspn(s, "\n")) != 0) { + s[pos] = 0; bmItem *item = bmItemNew(s); if (!item) break; bmMenuAddItem(menu, item); + s += pos + 1; } free(buffer); diff --git a/lib/draw/curses.c b/lib/draw/curses.c index 26754be..3b99cd9 100644 --- a/lib/draw/curses.c +++ b/lib/draw/curses.c @@ -1,14 +1,18 @@ #include "../internal.h" -#define _XOPEN_SOURCE 700 + +#define _XOPEN_SOURCE 500 +#include <signal.h> /* sigaction */ +#include <stdarg.h> /* vsnprintf */ +#undef _XOPEN_SOURCE + #include <wchar.h> +#include <unistd.h> #include <string.h> #include <stdlib.h> #include <locale.h> #include <ncurses.h> #include <dlfcn.h> -#include <signal.h> #include <assert.h> -#include <unistd.h> #if _WIN32 static const char *TTY = "CON"; diff --git a/lib/filter.c b/lib/filter.c index 836ad83..811451b 100644 --- a/lib/filter.c +++ b/lib/filter.c @@ -54,12 +54,17 @@ static char* _bmFilterTokenize(bmMenu *menu, char ***outTokv, unsigned int *outT if (!(buffer = _bmStrdup(menu->filter))) goto fail; - char *s, **tmp = NULL; + size_t pos = 0; unsigned int tokc = 0, tokn = 0; - for (s = strtok(buffer, " "); s; tmp[tokc - 1] = s, s = strtok(NULL, " "), tokv = tmp) + char *s = buffer, **tmp = NULL; + while ((pos = _bmStripToken(s, " ")) != 0) { if (++tokc > tokn && !(tmp = realloc(tmp, ++tokn * sizeof(char*)))) goto fail; + tmp[tokc - 1] = s; + s += pos + 1; + } + *outTokv = tmp; *outTokc = tokc; return buffer; diff --git a/lib/internal.h b/lib/internal.h index b3ca87c..1ed13b4 100644 --- a/lib/internal.h +++ b/lib/internal.h @@ -163,6 +163,7 @@ int _bmItemListRemoveItem(struct _bmItemList *list, const bmItem *item); /* util.c */ char* _bmStrdup(const char *s); +size_t _bmStripToken(char *string, const char *token); int _bmStrupcmp(const char *hay, const char *needle); int _bmStrnupcmp(const char *hay, const char *needle, size_t len); char* _bmStrupstr(const char *hay, const char *needle); @@ -28,6 +28,19 @@ char* _bmStrdup(const char *string) } /** + * Replaces next token in string with '\0' and returns position for the replaced token. + * + * @param string C "string" where token will be replaced. + * @return Position of the replaced token. + */ +size_t _bmStripToken(char *string, const char *token) +{ + size_t len = strcspn(string, token); + string[len] = 0; + return len; +} + +/** * Portable case-insensitive strcmp. * * @param hay C "string" to match against. |