27
27
#endif
28
28
29
29
#define spec_is_named_type (x ) \
30
- ((x)->type == ADOPT_BOOL || \
31
- (x)->type == ADOPT_SWITCH || \
32
- (x)->type == ADOPT_VALUE || \
33
- (x)->type == ADOPT_VALUE_OPTIONAL )
30
+ ((x)->type == ADOPT_TYPE_BOOL || \
31
+ (x)->type == ADOPT_TYPE_SWITCH || \
32
+ (x)->type == ADOPT_TYPE_VALUE || \
33
+ (x)->type == ADOPT_TYPE_VALUE_OPTIONAL )
34
34
35
35
INLINE (const adopt_spec * ) spec_byname (
36
36
adopt_parser * parser , const char * name , size_t namelen )
37
37
{
38
38
const adopt_spec * spec ;
39
39
40
40
for (spec = parser -> specs ; spec -> type ; ++ spec ) {
41
- if (spec -> type == ADOPT_LITERAL && namelen == 0 )
41
+ if (spec -> type == ADOPT_TYPE_LITERAL && namelen == 0 )
42
42
return spec ;
43
43
44
44
if (spec_is_named_type (spec ) &&
@@ -69,7 +69,7 @@ INLINE(const adopt_spec *) spec_nextarg(adopt_parser *parser)
69
69
size_t args = 0 ;
70
70
71
71
for (spec = parser -> specs ; spec -> type ; ++ spec ) {
72
- if (spec -> type == ADOPT_ARG ) {
72
+ if (spec -> type == ADOPT_TYPE_ARG ) {
73
73
if (args == parser -> arg_idx ) {
74
74
parser -> arg_idx ++ ;
75
75
return spec ;
@@ -78,7 +78,7 @@ INLINE(const adopt_spec *) spec_nextarg(adopt_parser *parser)
78
78
args ++ ;
79
79
}
80
80
81
- if (spec -> type == ADOPT_ARGS && args == parser -> arg_idx )
81
+ if (spec -> type == ADOPT_TYPE_ARGS && args == parser -> arg_idx )
82
82
return spec ;
83
83
}
84
84
@@ -105,7 +105,7 @@ INLINE(void) consume_choices(const adopt_spec *spec, adopt_parser *parser)
105
105
return ;
106
106
107
107
do {
108
- if (spec -> type == ADOPT_ARG )
108
+ if (spec -> type == ADOPT_TYPE_ARG )
109
109
parser -> arg_idx ++ ;
110
110
++ spec ;
111
111
} while (spec -> type && (spec -> usage & ADOPT_USAGE_CHOICE ));
@@ -130,17 +130,17 @@ static adopt_status_t parse_long(adopt_opt *opt, adopt_parser *parser)
130
130
opt -> spec = spec ;
131
131
132
132
/* Future options parsed as literal */
133
- if (spec -> type == ADOPT_LITERAL )
133
+ if (spec -> type == ADOPT_TYPE_LITERAL )
134
134
parser -> in_literal = 1 ;
135
135
136
- if (spec -> type == ADOPT_BOOL && spec -> value )
136
+ if (spec -> type == ADOPT_TYPE_BOOL && spec -> value )
137
137
* ((int * )spec -> value ) = 1 ;
138
138
139
- if (spec -> type == ADOPT_SWITCH && spec -> value )
139
+ if (spec -> type == ADOPT_TYPE_SWITCH && spec -> value )
140
140
* ((int * )spec -> value ) = spec -> switch_value ;
141
141
142
142
/* Parse values as "--foo=bar" or "--foo bar" */
143
- if (spec -> type == ADOPT_VALUE || spec -> type == ADOPT_VALUE_OPTIONAL ) {
143
+ if (spec -> type == ADOPT_TYPE_VALUE || spec -> type == ADOPT_TYPE_VALUE_OPTIONAL ) {
144
144
if (eql && * (eql + 1 ))
145
145
opt -> value = eql + 1 ;
146
146
else if ((parser -> idx + 1 ) <= parser -> args_len )
@@ -151,7 +151,7 @@ static adopt_status_t parse_long(adopt_opt *opt, adopt_parser *parser)
151
151
}
152
152
153
153
/* Required argument was not provided */
154
- if (spec -> type == ADOPT_VALUE && !opt -> value )
154
+ if (spec -> type == ADOPT_TYPE_VALUE && !opt -> value )
155
155
opt -> status = ADOPT_STATUS_MISSING_VALUE ;
156
156
else
157
157
opt -> status = ADOPT_STATUS_OK ;
@@ -177,14 +177,14 @@ static adopt_status_t parse_short(adopt_opt *opt, adopt_parser *parser)
177
177
178
178
opt -> spec = spec ;
179
179
180
- if (spec -> type == ADOPT_BOOL && spec -> value )
180
+ if (spec -> type == ADOPT_TYPE_BOOL && spec -> value )
181
181
* ((int * )spec -> value ) = 1 ;
182
182
183
- if (spec -> type == ADOPT_SWITCH && spec -> value )
183
+ if (spec -> type == ADOPT_TYPE_SWITCH && spec -> value )
184
184
* ((int * )spec -> value ) = spec -> switch_value ;
185
185
186
186
/* Parse values as "-ifoo" or "-i foo" */
187
- if (spec -> type == ADOPT_VALUE || spec -> type == ADOPT_VALUE_OPTIONAL ) {
187
+ if (spec -> type == ADOPT_TYPE_VALUE || spec -> type == ADOPT_TYPE_VALUE_OPTIONAL ) {
188
188
if (strlen (arg ) > 2 )
189
189
opt -> value = arg + 2 ;
190
190
else if ((parser -> idx + 1 ) <= parser -> args_len )
@@ -195,7 +195,7 @@ static adopt_status_t parse_short(adopt_opt *opt, adopt_parser *parser)
195
195
}
196
196
197
197
/* Required argument was not provided */
198
- if (spec -> type == ADOPT_VALUE && !opt -> value )
198
+ if (spec -> type == ADOPT_TYPE_VALUE && !opt -> value )
199
199
opt -> status = ADOPT_STATUS_MISSING_VALUE ;
200
200
else
201
201
opt -> status = ADOPT_STATUS_OK ;
@@ -216,7 +216,7 @@ static adopt_status_t parse_arg(adopt_opt *opt, adopt_parser *parser)
216
216
if (!spec ) {
217
217
parser -> idx ++ ;
218
218
opt -> status = ADOPT_STATUS_UNKNOWN_OPTION ;
219
- } else if (spec -> type == ADOPT_ARGS ) {
219
+ } else if (spec -> type == ADOPT_TYPE_ARGS ) {
220
220
if (spec -> value )
221
221
* ((char * * * )spec -> value ) = & parser -> args [parser -> idx ];
222
222
@@ -365,9 +365,9 @@ static int spec_name_fprint(FILE *file, const adopt_spec *spec)
365
365
{
366
366
int error ;
367
367
368
- if (spec -> type == ADOPT_ARG )
368
+ if (spec -> type == ADOPT_TYPE_ARG )
369
369
error = fprintf (file , "%s" , spec -> value_name );
370
- else if (spec -> type == ADOPT_ARGS )
370
+ else if (spec -> type == ADOPT_TYPE_ARGS )
371
371
error = fprintf (file , "%s" , spec -> value_name );
372
372
else if (spec -> alias && !(spec -> usage & ADOPT_USAGE_SHOW_LONG ))
373
373
error = fprintf (file , "-%c" , spec -> alias );
@@ -490,19 +490,19 @@ int adopt_usage_fprint(
490
490
if (error < 0 )
491
491
goto done ;
492
492
493
- if (spec -> type == ADOPT_VALUE && spec -> alias && !(spec -> usage & ADOPT_USAGE_SHOW_LONG ))
493
+ if (spec -> type == ADOPT_TYPE_VALUE && spec -> alias && !(spec -> usage & ADOPT_USAGE_SHOW_LONG ))
494
494
error = fprintf (file , "-%c <%s>" , spec -> alias , spec -> value_name );
495
- else if (spec -> type == ADOPT_VALUE )
495
+ else if (spec -> type == ADOPT_TYPE_VALUE )
496
496
error = fprintf (file , "--%s=<%s>" , spec -> name , spec -> value_name );
497
- else if (spec -> type == ADOPT_VALUE_OPTIONAL && spec -> alias )
497
+ else if (spec -> type == ADOPT_TYPE_VALUE_OPTIONAL && spec -> alias )
498
498
error = fprintf (file , "-%c [<%s>]" , spec -> alias , spec -> value_name );
499
- else if (spec -> type == ADOPT_VALUE_OPTIONAL )
499
+ else if (spec -> type == ADOPT_TYPE_VALUE_OPTIONAL )
500
500
error = fprintf (file , "--%s[=<%s>]" , spec -> name , spec -> value_name );
501
- else if (spec -> type == ADOPT_ARG )
501
+ else if (spec -> type == ADOPT_TYPE_ARG )
502
502
error = fprintf (file , "<%s>" , spec -> value_name );
503
- else if (spec -> type == ADOPT_ARGS )
503
+ else if (spec -> type == ADOPT_TYPE_ARGS )
504
504
error = fprintf (file , "<%s>..." , spec -> value_name );
505
- else if (spec -> type == ADOPT_LITERAL )
505
+ else if (spec -> type == ADOPT_TYPE_LITERAL )
506
506
error = fprintf (file , "--" );
507
507
else if (spec -> alias && !(spec -> usage & ADOPT_USAGE_SHOW_LONG ))
508
508
error = fprintf (file , "-%c" , spec -> alias );
0 commit comments