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