getsubopt.c 412 B

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