OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
argpar-help.c
Go to the documentation of this file.
1 
2 #include <argpar.h>
3 
4 
6 const char *argpar_program_name = "argpar-test";
7 static const char doc[] = "This is an argpar test.";
8 static const char args_doc[] = "[none]";
9 static const argpar_option options[] = {
10  { "ifile", 'f', "FILE", 0, "input file" },
11  { "ofile", 'o', "FILE", 0, "output file" },
12  { 0,0,0,0, "This is a header:", 2 },
13  { 0,0,0, OPTION_DOC, "This is some docs." },
14  { 0,0,0,0, "Header #1:", 1 },
15  { 0,0,0, OPTION_DOC, "This is some docs." },
16  { "efile", 'e', "FILE", 0, "error file", 2 },
17  { "long", 'l', 0, OPTION_INT, "long, not casted" },
18  { "int", 'i', 0, OPTION_INT, "casted as int", 1 },
19  { "dbl", 'd', 0, OPTION_DBL, "casted as dbl", 1 },
20  { "double", 0, 0, OPTION_ALIAS },
21  { "p", 'p', 0, 0, "load parfile via child", 1 },
22  { "bail", 'b', 0, 0, "if given, stop processing", 1 },
23  { "help", 'h', 0, 0, "if given, print usage summary", 1 },
24  { "enum", 'm', 0, 0, "this option has enum values", 1 },
25  { "val1", 0, 0, OPTION_ENUM, "description of val1", 1 },
26  { "val2", 0, 0, OPTION_ENUM, "description of val2", 1 },
27  { "default", 0, 0, OPTION_ATTR, "val1" },
28  {0}
29 };
30 
31 static int parse_options(int key, char *argv, argpar_state *state) {
32  return 0;
33 }
34 
35 argpar params = { options, parse_options, args_doc, doc };
36 
37 static const char doc_parent[] = "This is an argpar test.";
38 static const char args_doc_parent[] = "[none]";
39 static const argpar_option options_parent[] = {
40  { "dbl", 'd', 0, OPTION_DBL, "casted as dbl", 1 },
41  { "parg", 'p', 0, OPTION_INT, "new arg for parent", 1 },
42  {0}
43 };
44 
45 static int parse_options_parent(int key, char *argv, argpar_state *state) {
46  return 0;
47 }
48 
50 argpar params_parent = { options_parent, parse_options_parent, args_doc_parent, doc_parent, children };
51 
52 int main(int argc, char **argv){
53  int test1 = argpar_help_json(&params_parent, stdout, 0, "json-test");
54  printf("\n\n**************\n\n");
55  int test2 = argpar_help(&params_parent, stdout, 0, "help-test");
56  return (test1 | test2);
57 }
Master structure containing options, document strings, child parsers, and text filters....
Definition: argpar.h:398
FILE * argpar_ostream
Definition: argpar-help.c:5
int argpar_help_json(argpar *argpar, FILE *stream, unsigned flags, char *name)
Print the default usage summary with all available sections, in a format more suitable for automated ...
Definition: argpar-json.c:420
#define OPTION_INT
Cast this option as a long. The value and any error will be reflected in the argpar_state struct duri...
Definition: argpar.h:160
Child parser for nesting argpars.
Definition: argpar.h:377
#define OPTION_ATTR
This option serves to document additional attributes for an option. These are hidden from the normal ...
Definition: argpar.h:183
argpar params_parent
Definition: argpar-help.c:50
argpar params
Definition: argpar-help.c:35
int argpar_help(argpar *argpar, FILE *stream, unsigned flags, char *name)
Print the default usage summary with all available sections.
Definition: argpar-help.c:512
int state(double tjdTDB, JPLIntUtilType *util, double posvel[13][6], double *pnut)
#define OPTION_ENUM
This option serves to document a valid value for an option. This is not enforced by argpar.
Definition: argpar.h:179
int main(int argc, char **argv)
Definition: argpar-help.c:52
#define OPTION_ALIAS
Do not add an extra newline after this documentation string. Useful for lists and manual formatting.
Definition: argpar.h:175
#define OPTION_DOC
This option isn't actually an option, merely text for the usage summary.
Definition: argpar.h:152
State variable to be filled before each call to the parser callback.
Definition: argpar.h:196
const char * argpar_program_name
Definition: argpar-help.c:6
Library for reading command-line arguments in the form of key=value.
argpar_child children[]
Definition: argpar-help.c:49
Stores the configuration for a par argument.
Definition: argpar.h:87
#define OPTION_DBL
Cast this option as a double. The value and any error will be reflected in the argpar_state struct du...
Definition: argpar.h:156