Added support for using a null byte as the dmenu separator

This commit is contained in:
Scoopta 2020-01-31 22:37:59 -08:00
parent 7c44d9ec4b
commit 2f4f53fa44

View File

@ -37,6 +37,8 @@ void wofi_dmenu_init(struct mode* this, struct map* config) {
if(strcmp(separator, "\\n") == 0) { if(strcmp(separator, "\\n") == 0) {
separator = "\n"; separator = "\n";
} else if(strcmp(separator, "\\0") == 0) {
separator = "\0";
} }
wl_list_init(&widgets); wl_list_init(&widgets);
@ -49,31 +51,20 @@ void wofi_dmenu_init(struct mode* this, struct map* config) {
struct map* entry_map = map_init(); struct map* entry_map = map_init();
char* buffer = NULL;
char* line = NULL; char* line = NULL;
size_t size = 0; size_t size = 0;
while(getline(&line, &size, stdin) != -1) { while(getdelim(&line, &size, separator[0], stdin) != -1) {
if(buffer == NULL) { char* delim = strchr(line, separator[0]);
buffer = strdup(line); if(delim != NULL) {
} else { *delim = 0;
char* old = buffer;
buffer = utils_concat(2, buffer, line);
free(old);
} }
struct cache_line* node = malloc(sizeof(struct cache_line));
node->line = strdup(line);
wl_list_insert(&entries, &node->link);
map_put(entry_map, line, "true");
} }
free(line); free(line);
char* save_ptr;
char* str = strtok_r(buffer, separator, &save_ptr);
do {
struct cache_line* node = malloc(sizeof(struct cache_line));
node->line = strdup(str);
wl_list_insert(&entries, &node->link);
map_put(entry_map, str, "true");
} while((str = strtok_r(NULL, separator, &save_ptr)) != NULL);
free(buffer);
struct cache_line* node, *tmp; struct cache_line* node, *tmp;
wl_list_for_each_safe(node, tmp, cache, link) { wl_list_for_each_safe(node, tmp, cache, link) {
if(map_contains(entry_map, node->line)) { if(map_contains(entry_map, node->line)) {