dmenu/patch/highpriority.c

36 lines
852 B
C
Raw Normal View History

2020-08-05 14:54:01 +02:00
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;
2020-08-05 14:54:01 +02:00
token = strtok(source, delim);
2020-08-05 14:54:01 +02:00
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));
}
2020-08-05 14:54:01 +02:00
if (!(list[listlength] = strdup(token)))
die("Unable to strdup %zu bytes\n", strlen(token) + 1);
2020-08-05 14:54:01 +02:00
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;
2024-07-16 21:42:32 +02:00
}