~kris/suckless

dmenu

ref: 541dead59a544fbd15390ad35f6412ca6ac64d32 dmenu/patch/highpriority.c -rw-r--r-- 852 bytes
541dead5 — Kris Yotam Add PNG_IMAGES_PATCH for inline image previews 2 months ago
                                                                                
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
static char **hpitems = NULL;
static int hplength = 0;

static char **
tokenize(char *source, const char *delim, int *llen)
{
	int listlength = 0, list_size = 0;
	char **list = NULL, *token;

	token = strtok(source, delim);
	while (token) {
		if (listlength + 1 >= list_size) {
			if (!(list = realloc(list, (list_size += 8) * sizeof(*list))))
				die("Unable to realloc %zu bytes\n", list_size * sizeof(*list));
		}
		if (!(list[listlength] = strdup(token)))
			die("Unable to strdup %zu bytes\n", strlen(token) + 1);
		token = strtok(NULL, delim);
		listlength++;
	}

	*llen = listlength;
	return list;
}

static int
arrayhas(char **list, int length, char *item) {
	for (int i = 0; i < length; i++) {
		int len1 = strlen(list[i]);
		int len2 = strlen(item);
		if (fstrncmp(list[i], item, len1 > len2 ? len2 : len1) == 0)
			return 1;
	}
	return 0;
}