Skip to content

Commit e22e057

Browse files
committed
types are not ADOPT_TYPE_*
1 parent 57ac333 commit e22e057

File tree

5 files changed

+141
-141
lines changed

5 files changed

+141
-141
lines changed

adopt.c

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -27,18 +27,18 @@
2727
#endif
2828

2929
#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)
3434

3535
INLINE(const adopt_spec *) spec_byname(
3636
adopt_parser *parser, const char *name, size_t namelen)
3737
{
3838
const adopt_spec *spec;
3939

4040
for (spec = parser->specs; spec->type; ++spec) {
41-
if (spec->type == ADOPT_LITERAL && namelen == 0)
41+
if (spec->type == ADOPT_TYPE_LITERAL && namelen == 0)
4242
return spec;
4343

4444
if (spec_is_named_type(spec) &&
@@ -69,7 +69,7 @@ INLINE(const adopt_spec *) spec_nextarg(adopt_parser *parser)
6969
size_t args = 0;
7070

7171
for (spec = parser->specs; spec->type; ++spec) {
72-
if (spec->type == ADOPT_ARG) {
72+
if (spec->type == ADOPT_TYPE_ARG) {
7373
if (args == parser->arg_idx) {
7474
parser->arg_idx++;
7575
return spec;
@@ -78,7 +78,7 @@ INLINE(const adopt_spec *) spec_nextarg(adopt_parser *parser)
7878
args++;
7979
}
8080

81-
if (spec->type == ADOPT_ARGS && args == parser->arg_idx)
81+
if (spec->type == ADOPT_TYPE_ARGS && args == parser->arg_idx)
8282
return spec;
8383
}
8484

@@ -105,7 +105,7 @@ INLINE(void) consume_choices(const adopt_spec *spec, adopt_parser *parser)
105105
return;
106106

107107
do {
108-
if (spec->type == ADOPT_ARG)
108+
if (spec->type == ADOPT_TYPE_ARG)
109109
parser->arg_idx++;
110110
++spec;
111111
} while(spec->type && (spec->usage & ADOPT_USAGE_CHOICE));
@@ -130,17 +130,17 @@ static adopt_status_t parse_long(adopt_opt *opt, adopt_parser *parser)
130130
opt->spec = spec;
131131

132132
/* Future options parsed as literal */
133-
if (spec->type == ADOPT_LITERAL)
133+
if (spec->type == ADOPT_TYPE_LITERAL)
134134
parser->in_literal = 1;
135135

136-
if (spec->type == ADOPT_BOOL && spec->value)
136+
if (spec->type == ADOPT_TYPE_BOOL && spec->value)
137137
*((int *)spec->value) = 1;
138138

139-
if (spec->type == ADOPT_SWITCH && spec->value)
139+
if (spec->type == ADOPT_TYPE_SWITCH && spec->value)
140140
*((int *)spec->value) = spec->switch_value;
141141

142142
/* 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) {
144144
if (eql && *(eql+1))
145145
opt->value = eql + 1;
146146
else if ((parser->idx + 1) <= parser->args_len)
@@ -151,7 +151,7 @@ static adopt_status_t parse_long(adopt_opt *opt, adopt_parser *parser)
151151
}
152152

153153
/* Required argument was not provided */
154-
if (spec->type == ADOPT_VALUE && !opt->value)
154+
if (spec->type == ADOPT_TYPE_VALUE && !opt->value)
155155
opt->status = ADOPT_STATUS_MISSING_VALUE;
156156
else
157157
opt->status = ADOPT_STATUS_OK;
@@ -177,14 +177,14 @@ static adopt_status_t parse_short(adopt_opt *opt, adopt_parser *parser)
177177

178178
opt->spec = spec;
179179

180-
if (spec->type == ADOPT_BOOL && spec->value)
180+
if (spec->type == ADOPT_TYPE_BOOL && spec->value)
181181
*((int *)spec->value) = 1;
182182

183-
if (spec->type == ADOPT_SWITCH && spec->value)
183+
if (spec->type == ADOPT_TYPE_SWITCH && spec->value)
184184
*((int *)spec->value) = spec->switch_value;
185185

186186
/* 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) {
188188
if (strlen(arg) > 2)
189189
opt->value = arg + 2;
190190
else if ((parser->idx + 1) <= parser->args_len)
@@ -195,7 +195,7 @@ static adopt_status_t parse_short(adopt_opt *opt, adopt_parser *parser)
195195
}
196196

197197
/* Required argument was not provided */
198-
if (spec->type == ADOPT_VALUE && !opt->value)
198+
if (spec->type == ADOPT_TYPE_VALUE && !opt->value)
199199
opt->status = ADOPT_STATUS_MISSING_VALUE;
200200
else
201201
opt->status = ADOPT_STATUS_OK;
@@ -216,7 +216,7 @@ static adopt_status_t parse_arg(adopt_opt *opt, adopt_parser *parser)
216216
if (!spec) {
217217
parser->idx++;
218218
opt->status = ADOPT_STATUS_UNKNOWN_OPTION;
219-
} else if (spec->type == ADOPT_ARGS) {
219+
} else if (spec->type == ADOPT_TYPE_ARGS) {
220220
if (spec->value)
221221
*((char ***)spec->value) = &parser->args[parser->idx];
222222

@@ -365,9 +365,9 @@ static int spec_name_fprint(FILE *file, const adopt_spec *spec)
365365
{
366366
int error;
367367

368-
if (spec->type == ADOPT_ARG)
368+
if (spec->type == ADOPT_TYPE_ARG)
369369
error = fprintf(file, "%s", spec->value_name);
370-
else if (spec->type == ADOPT_ARGS)
370+
else if (spec->type == ADOPT_TYPE_ARGS)
371371
error = fprintf(file, "%s", spec->value_name);
372372
else if (spec->alias && !(spec->usage & ADOPT_USAGE_SHOW_LONG))
373373
error = fprintf(file, "-%c", spec->alias);
@@ -490,19 +490,19 @@ int adopt_usage_fprint(
490490
if (error < 0)
491491
goto done;
492492

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))
494494
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)
496496
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)
498498
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)
500500
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)
502502
error = fprintf(file, "<%s>", spec->value_name);
503-
else if (spec->type == ADOPT_ARGS)
503+
else if (spec->type == ADOPT_TYPE_ARGS)
504504
error = fprintf(file, "<%s>...", spec->value_name);
505-
else if (spec->type == ADOPT_LITERAL)
505+
else if (spec->type == ADOPT_TYPE_LITERAL)
506506
error = fprintf(file, "--");
507507
else if (spec->alias && !(spec->usage & ADOPT_USAGE_SHOW_LONG))
508508
error = fprintf(file, "-%c", spec->alias);

adopt.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,35 +16,35 @@
1616
* The type of argument to be parsed.
1717
*/
1818
typedef enum {
19-
ADOPT_NONE = 0,
19+
ADOPT_TYPE_NONE = 0,
2020

2121
/**
2222
* An argument that, when specified, sets a given value to true.
2323
* This is useful for arguments like "--debug". The `value` pointer
2424
* in the returned option will be set to `1` when this is set.
2525
*/
26-
ADOPT_BOOL,
26+
ADOPT_TYPE_BOOL,
2727

2828
/**
2929
* An argument that, when specified, sets the given `value_ptr`
3030
* to the given `value`.
3131
*/
32-
ADOPT_SWITCH,
32+
ADOPT_TYPE_SWITCH,
3333

3434
/** An argument that has a value ("-nvalue" or "--name value") */
35-
ADOPT_VALUE,
35+
ADOPT_TYPE_VALUE,
3636

3737
/** An argument that has an optional value ("-n" or "-n foo") */
38-
ADOPT_VALUE_OPTIONAL,
38+
ADOPT_TYPE_VALUE_OPTIONAL,
3939

4040
/** The literal arguments follow specifier, bare "--" */
41-
ADOPT_LITERAL,
41+
ADOPT_TYPE_LITERAL,
4242

4343
/** A single "free" argument ("path") */
44-
ADOPT_ARG,
44+
ADOPT_TYPE_ARG,
4545

4646
/** Unmatched arguments, a collection of "free" arguments ("paths...") */
47-
ADOPT_ARGS,
47+
ADOPT_TYPE_ARGS,
4848
} adopt_type_t;
4949

5050
/**

examples/loop.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,20 @@ static char *filename2 = NULL;
1818
static char **other = NULL;
1919

2020
adopt_spec opt_specs[] = {
21-
{ ADOPT_BOOL, "verbose", 'v', &verbose, 0,
22-
NULL, "Turn on verbose information", 0 },
23-
{ ADOPT_SWITCH, "quiet", 'q', &volume, 0,
21+
{ ADOPT_TYPE_BOOL, "verbose", 'v', &verbose, 0,
22+
NULL, "Turn on verbose information", 0 },
23+
{ ADOPT_TYPE_SWITCH, "quiet", 'q', &volume, 0,
2424
NULL, "Emit no output", ADOPT_USAGE_REQUIRED },
25-
{ ADOPT_SWITCH, "loud", 'l', &volume, 2,
25+
{ ADOPT_TYPE_SWITCH, "loud", 'l', &volume, 2,
2626
NULL, "Emit louder than usual output", ADOPT_USAGE_CHOICE },
27-
{ ADOPT_VALUE, "channel", 'c', &channel, 0,
27+
{ ADOPT_TYPE_VALUE, "channel", 'c', &channel, 0,
2828
"channel", "Set the channel", 0 },
29-
{ ADOPT_LITERAL },
30-
{ ADOPT_ARG, NULL, 0, &filename1, 0,
29+
{ ADOPT_TYPE_LITERAL },
30+
{ ADOPT_TYPE_ARG, NULL, 0, &filename1, 0,
3131
"file1", "The first filename", ADOPT_USAGE_REQUIRED },
32-
{ ADOPT_ARG, NULL, 0, &filename2, 0,
32+
{ ADOPT_TYPE_ARG, NULL, 0, &filename2, 0,
3333
"file2", "The second (optional) filename", 0 },
34-
{ ADOPT_ARGS, NULL, 0, &other, 0,
34+
{ ADOPT_TYPE_ARGS, NULL, 0, &other, 0,
3535
"other", "The other (optional) arguments", 0 },
3636
{ 0 }
3737
};

examples/parse.c

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -18,20 +18,20 @@ static char *filename2 = NULL;
1818
static char **other = NULL;
1919

2020
adopt_spec opt_specs[] = {
21-
{ ADOPT_BOOL, "verbose", 'v', &verbose, 0,
21+
{ ADOPT_TYPE_BOOL, "verbose", 'v', &verbose, 0,
2222
NULL, "Turn on verbose information", 0 },
23-
{ ADOPT_SWITCH, "quiet", 'q', &volume, 0,
23+
{ ADOPT_TYPE_SWITCH, "quiet", 'q', &volume, 0,
2424
NULL, "Emit no output", ADOPT_USAGE_REQUIRED },
25-
{ ADOPT_SWITCH, "loud", 'l', &volume, 2,
25+
{ ADOPT_TYPE_SWITCH, "loud", 'l', &volume, 2,
2626
NULL, "Emit louder than usual output", ADOPT_USAGE_CHOICE },
27-
{ ADOPT_VALUE, "channel", 'c', &channel, 0,
27+
{ ADOPT_TYPE_VALUE, "channel", 'c', &channel, 0,
2828
"channel", "Set the channel", 0 },
29-
{ ADOPT_LITERAL },
30-
{ ADOPT_ARG, NULL, 0, &filename1, 0,
29+
{ ADOPT_TYPE_LITERAL },
30+
{ ADOPT_TYPE_ARG, NULL, 0, &filename1, 0,
3131
"file1", "The first filename", ADOPT_USAGE_REQUIRED },
32-
{ ADOPT_ARG, NULL, 0, &filename2, 0,
32+
{ ADOPT_TYPE_ARG, NULL, 0, &filename2, 0,
3333
"file2", "The second (optional) filename", 0 },
34-
{ ADOPT_ARGS, NULL, 0, &other, 0,
34+
{ ADOPT_TYPE_ARGS, NULL, 0, &other, 0,
3535
"other", "The other (optional) arguments", 0 },
3636
{ 0 }
3737
};

0 commit comments

Comments
 (0)