1 #include <stdlib.h>
2 #include <string.h>
3 
getsubopt(char ** opt,char * const * keys,char ** val)4 int getsubopt(char** opt, char* const* keys, char** val) {
5     char* s = *opt;
6     int i;
7 
8     *val = NULL;
9     *opt = strchr(s, ',');
10     if (*opt)
11         *(*opt)++ = 0;
12     else
13         *opt = s + strlen(s);
14 
15     for (i = 0; keys[i]; i++) {
16         size_t l = strlen(keys[i]);
17         if (strncmp(keys[i], s, l))
18             continue;
19         if (s[l] == '=')
20             *val = s + l + 1;
21         else if (s[l])
22             continue;
23         return i;
24     }
25     return -1;
26 }
27