1 /***********************************************************************
3 * This software is part of the ast package *
4 * Copyright (c) 1985-2010 AT&T Intellectual Property *
5 * and is licensed under the *
6 * Common Public License, Version 1.0 *
7 * by AT&T Intellectual Property *
9 * A copy of the License is available at *
10 * http://www.opensource.org/licenses/cpl1.0.txt *
11 * (with md5 checksum 059e8cd6165cb4c31e351f2b69388fd9) *
13 * Information and Software Systems Research *
17 * Glenn Fowler <gsf@research.att.com> *
18 * David Korn <dgk@research.att.com> *
19 * Phong Vo <kpv@research.att.com> *
21 ***********************************************************************/
32 * parse option expression in s using options in tab with element size siz
33 * first element in tab must be a char*
36 * [no]name[[:]=['"]value["']][, ]...
38 * f is called for each option
40 * (*f)(void* a, char* p, int n, char* v)
43 * p matching tab entry, or name if no table
44 * n 0 if option had ``no'' prefix, -1 if :=, 1 otherwise
45 * v option value pointer
47 * for unmatched options p is 0 and v is the offending option
49 * names in s may be shorter than tab names
50 * longer names must have a prefix that matches a tab name
51 * the first match is returned
52 * \ escapes value using chresc()
56 stropt(const char* as
, const void* tab
, int siz
, int(*f
)(void*, const void*, int, const char*), void* a
)
72 else if (!(x
= s
= strdup(as
))) n
= -1;
77 while (isspace(*s
) || *s
== ',') s
++;
78 if (*s
== 'n' && *(s
+ 1) == 'o')
91 for (p
= (char**)tab
; t
= *p
; p
= (char**)((char*)p
+ siz
))
93 for (v
= s
; *t
&& *t
++ == *v
; v
++);
94 if (!*t
|| isspace(*v
) || *v
== ',' || *v
== '=')
96 if (*v
== ':' && *(v
+ 1) == '=')
114 while (*v
&& !isspace(*v
) && *v
!= '=' && *v
!= ',')
115 if (*v
++ == ':' && *v
== '=')
132 *t
++ = chresc(s
- 1, &e
);
149 else if (c
== ',' || isspace(c
))
151 else if (c
== '"' || c
== '\'')
181 n
= p
? (*f
)(a
, p
, n
, v
) : (*f
)(a
, p
, v
- u
, u
);