-
Notifications
You must be signed in to change notification settings - Fork 34
/
Copy pathstropt.3
130 lines (130 loc) · 2.05 KB
/
stropt.3
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
.fp 5 CW
.de Af
.ds ;G \\*(;G\\f\\$1\\$3\\f\\$2
.if !\\$4 .Af \\$2 \\$1 "\\$4" "\\$5" "\\$6" "\\$7" "\\$8" "\\$9"
..
.de aF
.ie \\$3 .ft \\$1
.el \{\
.ds ;G \&
.nr ;G \\n(.f
.Af "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6" "\\$7" "\\$8" "\\$9"
\\*(;G
.ft \\n(;G \}
..
.de L
.aF 5 \\n(.f "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6" "\\$7"
..
.de LR
.aF 5 1 "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6" "\\$7"
..
.de RL
.aF 1 5 "\\$1" "\\$2" "\\$3" "\\$4" "\\$5" "\\$6" "\\$7"
..
.de EX \" start example
.ta 1i 2i 3i 4i 5i 6i
.PP
.RS
.PD 0
.ft 5
.nf
..
.de EE \" end example
.fi
.ft
.PD
.RE
.PP
..
.TH STROPT 3
.SH NAME
stropt \- table driven option expression evaluator
.SH SYNOPSIS
.L "#include <namval.h>"
.br
.L "int stropt(const char* s, struct namval* tab, int siz,
.br
.L " int (*fun)(void* a, struct namval* p, int n, char* v),"
.br
.L " void* a)"
.SH DESCRIPTION
.I stropt
parses option expressions in the null-terminated string
.I s
using the option names in
.IR tab .
.I tab
is an array of
.B "struct namval"
name value pairs:
.EX
char* name;
int value;
.EE
The last entry must be followed by a sentinel with
.B name
set to 0.
.PP
An option expression contains 0 or more of [\fBno\fP]\fIname\fP[=\fIvalue\fP]
separate by
.B space
or
.BR tab ,
where
.I name
must be one of the option names in
.IR tab ,
.I value
is an optional value, and
.B no
is for Boolean options.
Each option is passed to
.I fun
for processing.
.I a
is the
.L void*
pointer that is passed from the
.I stropt
call but is otherwise not interpreted.
.I p
points to the option name value pair from
.IR tab .
.I n
is 0 if
.B no
preceded the option
.I name
and
.I v
points to the beginning of the option
.I value
in
.IR s .
and
If
.I name
is not found in
.I tab
then
.I fun
is called with
.I p
pointing to an internal
.I namval
entry with
.I p\->name
pointing to the unknown option and
.I p\->value
set to the
.I value
of the sentinel entry in
.IR tab .
.PP
If
.I fun
returns non-zero then this value is returned and no further
options are processed.
Otherwise
.I stropt
returns 0 after processing all options.