| lh | 9ed821d | 2023-04-07 01:36:19 -0700 | [diff] [blame] | 1 | /* | 
 | 2 |  * Copyright (C) 2006 Rich Felker <dalias@aerifal.cx> | 
 | 3 |  * | 
 | 4 |  * Licensed under the LGPL v2.1, see the file COPYING.LIB in this tarball. | 
 | 5 |  */ | 
 | 6 |  | 
 | 7 | #include <stdlib.h> | 
 | 8 | #include <string.h> | 
 | 9 |  | 
 | 10 |  | 
 | 11 | int getsubopt(char **opt, char *const *keys, char **val) | 
 | 12 | { | 
 | 13 | 	char *s = *opt; | 
 | 14 | 	int i; | 
 | 15 |  | 
 | 16 | 	*val = NULL; | 
 | 17 | 	*opt = strchr(s, ','); | 
 | 18 | 	if (*opt) *(*opt)++ = 0; | 
 | 19 | 	else *opt = s + strlen(s); | 
 | 20 |  | 
 | 21 | 	for (i=0; keys[i]; i++) { | 
 | 22 | 		size_t l = strlen(keys[i]); | 
 | 23 | 		if (strncmp(keys[i], s, l)) continue; | 
 | 24 | 		if (s[l] == '=') | 
 | 25 | 			*val = s + l; | 
 | 26 | 		else if (s[l]) continue; | 
 | 27 | 		return i; | 
 | 28 | 	} | 
 | 29 | 	return -1; | 
 | 30 | } |