/
topt.c
56 lines (43 loc) · 1002 Bytes
/
topt.c
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
/* topt.c - test didomount/opt.c */
#if HAVE_CONFIG_H
#include "config.h"
#endif
#include <unistd.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <stdarg.h>
#include <assert.h>
#include "diod_log.h"
#include "opt.h"
int
main (int argc, char *argv[])
{
Opt o = opt_create ();
char *s;
int i;
diod_log_init (argv[0]);
opt_addf (o, "mickey=%d", 42);
opt_addf (o, "goofey=%s", "yes");
opt_addf (o, "donald");
opt_addf (o, "foo,bar,baz");
opt_addf (o, "lastone");
s = opt_csv (o);
msg ("opt string='%s'", s);
free (s);
assert (opt_find (o, "mickey"));
assert (opt_find (o, "bar"));
assert (!opt_find (o, "barn"));
assert (opt_scanf (o, "mickey=%d", &i));
assert (i == 42);
opt_addf (o, "mickey=string,foo=%d,bar=%d,baz", 12, 15);
s = opt_csv (o);
msg ("opt string='%s'", s);
free (s);
opt_destroy (o);
exit (0);
}
/*
* vi:tabstop=4 shiftwidth=4 expandtab
*/