]> git.ozlabs.org Git - ccan/blob - ccan/opt/_info
opt: minor API tweaks.
[ccan] / ccan / opt / _info
1 #include <stdio.h>
2 #include <string.h>
3 #include "config.h"
4
5 /**
6  * opt - simple command line parsing
7  *
8  * Simple but powerful command line parsing, built on top of getopt_long.
9  *
10  * Example:
11  * #include <ccan/opt/opt.h>
12  * #include <stdio.h>
13  * #include <stdlib.h>
14  * 
15  * static bool someflag;
16  * static int verbose;
17  * static char *somestring;
18  * 
19  * static struct opt_table opts[] = {
20  *      { OPT_WITHOUT_ARG("verbose", 'v', opt_inc_intval, &verbose),
21  *        "Verbose mode (can be specified more than once)" },
22  *      { OPT_WITHOUT_ARG("someflag", 0, opt_set_bool, &someflag),
23  *        "Set someflag" },
24  *      { OPT_WITH_ARG("somestring", 0, opt_set_charp, &somestring),
25  *        "Set somestring to <arg>" },
26  *      { OPT_WITHOUT_ARG("usage", 0, opt_usage_and_exit,
27  *                        "args...\nA silly test program."),
28  *        "Print this message." },
29  *      OPT_ENDTABLE
30  * };
31  * 
32  * int main(int argc, char *argv[])
33  * {
34  *      int i;
35  * 
36  *      opt_register_table(opts);
37  *      // For fun, register an extra one.
38  *      opt_register_noarg("no-someflag", 0, opt_set_invbool, &someflag,
39  *                         "Unset someflag");
40  *      if (!opt_parse(&argc, argv, opt_log_stderr))
41  *              exit(1);
42  * 
43  *      printf("someflag = %i, verbose = %i, somestring = %s\n",
44  *             someflag, verbose, somestring);
45  *      printf("%u args left over:", argc - 1);
46  *      for (i = 1; i < argc; i++)
47  *              printf(" %s", argv[i]);
48  *      printf("\n");
49  *      return 0;
50  * }
51  *
52  * Licence: GPL (3 or any later version)
53  * Author: Rusty Russell <rusty@rustcorp.com.au>
54  */
55 int main(int argc, char *argv[])
56 {
57         if (argc != 2)
58                 return 1;
59
60         if (strcmp(argv[1], "depends") == 0) {
61                 return 0;
62         }
63
64         return 1;
65 }