]> git.ozlabs.org Git - ccan/blob - ccan/opt/_info
e818b2ebdfb5813d7d23b302b691064c187a1979
[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.
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", opt_set_bool, &someflag,
23  *                      "Set someflag"),
24  *      OPT_WITH_ARG("--somefile=<filename>", opt_set_charp, opt_show_charp,
25  *                   &somestring, "Set somefile to <filename>"),
26  *      OPT_WITHOUT_ARG("--usage/--help/-h", 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, NULL);
37  *      // For fun, register an extra one.
38  *      opt_register_noarg("--no-someflag", 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  * License: 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                 printf("ccan/typesafe_cb\n");
62                 return 0;
63         }
64
65         return 1;
66 }