dmenu

Kris's build of dmenu
git clone git clone https://git.krisyotam.com/krisyotam/dmenu.git
Log | Files | Refs | README | LICENSE

highpriority.c (852B)


      1 static char **hpitems = NULL;
      2 static int hplength = 0;
      3 
      4 static char **
      5 tokenize(char *source, const char *delim, int *llen)
      6 {
      7 	int listlength = 0, list_size = 0;
      8 	char **list = NULL, *token;
      9 
     10 	token = strtok(source, delim);
     11 	while (token) {
     12 		if (listlength + 1 >= list_size) {
     13 			if (!(list = realloc(list, (list_size += 8) * sizeof(*list))))
     14 				die("Unable to realloc %zu bytes\n", list_size * sizeof(*list));
     15 		}
     16 		if (!(list[listlength] = strdup(token)))
     17 			die("Unable to strdup %zu bytes\n", strlen(token) + 1);
     18 		token = strtok(NULL, delim);
     19 		listlength++;
     20 	}
     21 
     22 	*llen = listlength;
     23 	return list;
     24 }
     25 
     26 static int
     27 arrayhas(char **list, int length, char *item) {
     28 	for (int i = 0; i < length; i++) {
     29 		int len1 = strlen(list[i]);
     30 		int len2 = strlen(item);
     31 		if (fstrncmp(list[i], item, len1 > len2 ? len2 : len1) == 0)
     32 			return 1;
     33 	}
     34 	return 0;
     35 }