summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
Diffstat (limited to 'lib')
-rw-r--r--lib/draw/curses.c10
-rw-r--r--lib/filter.c9
-rw-r--r--lib/internal.h1
-rw-r--r--lib/util.c13
4 files changed, 28 insertions, 5 deletions
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);
diff --git a/lib/util.c b/lib/util.c
index a77e2ff..49f9175 100644
--- a/lib/util.c
+++ b/lib/util.c
@@ -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.