OB.DAAC Logo
NASA Logo
Ocean Color Science Software

ocssw V2022
argpar-params.c
Go to the documentation of this file.
1 
2 #include <argpar.h>
3 
4 #include <stdlib.h>
5 #include <string.h>
6 
7 
9 const char *argpar_program_name = "argpar-test";
10 static const char doc[] = "This is an argpar test.";
11 static const char args_doc[] = "[none]";
12 static const argpar_option options[] = {
13  { "ifile", 'f', "FILE", 0, "input file" },
14  { "ofile", 'o', "FILE", 0, "output file" },
15  { 0,0,0,0, "This is a header:", 2 },
16  { 0,0,0, OPTION_DOC, "This is some docs." },
17  { 0,0,0,0, "Header #1:", 1 },
18  { 0,0,0, OPTION_DOC, "This is some docs." },
19  { "efile", 'e', "FILE", 0, "error file", 2 },
20  { "long", 'l', 0, OPTION_INT, "long, not casted" },
21  { "int", 'i', 0, OPTION_INT, "casted as int", 1 },
22  { "dbl", 'd', 0, OPTION_DBL, "casted as dbl", 1 },
23  { "double", 0, 0, OPTION_ALIAS },
24  { "p", 'p', 0, 0, "load parfile via child", 1 },
25  { "enum", 'm', 0, 0, "this option has enum values", 1 },
26  { "val1", 0, 0, OPTION_ENUM, "description of val1", 1 },
27  { "val2", 0, 0, OPTION_ENUM, "description of val2", 1 },
28  { "default", 0, 0, OPTION_ATTR, "val1" },
29  {0}
30 };
31 
32 static int parse_options(int key, char *argv, argpar_state *state) {
33  return 0;
34 }
35 
36 argpar params = { options, parse_options, args_doc, doc };
37 
38 static const char doc_parent[] = "This is an argpar test.";
39 static const char args_doc_parent[] = "[none]";
40 static const argpar_option options_parent[] = {
41  { "dbl", 'd', 0, OPTION_DBL, "casted as dbl", 1 },
42  { "parg", 'p', 0, OPTION_INT, "new arg for parent", 1 },
43  {0}
44 };
45 
46 static int parse_options_parent(int key, char *argv, argpar_state *state) {
47  return 0;
48 }
49 
51 argpar params_parent = { options_parent, parse_options_parent, args_doc_parent, doc_parent, children };
52 
53 int main(){
54  int argc = 6;
55  const char *argv_const[] = {
56  argpar_program_name, "parfile=parfiles/initial.par", "ofile=keyarg_ofile1", "parfile=parfiles/final.par",
57  "ofile=keyarg_ofile2", "help=params"
58  };
59  char *argv[argc];
60  int i;
61  for (i=0;i<argc;i++){
62  argv[i] = strdup(argv_const[i]);
63  }
65 
66  for (i=0;i<argc;i++){
67  free(argv[i]);
68  }
69 
71  return ret;
72 }
int main()
Definition: argpar-params.c:53
Master structure containing options, document strings, child parsers, and text filters....
Definition: argpar.h:398
FILE * argpar_ostream
Definition: argpar-params.c:8
#define NULL
Definition: decode_rs.h:63
#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
int state(double tjdTDB, JPLIntUtilType *util, double posvel[13][6], double *pnut)
argpar params
Definition: argpar-params.c:36
#define OPTION_ENUM
This option serves to document a valid value for an option. This is not enforced by argpar.
Definition: argpar.h:179
#define ARGPAR_NO_EXIT
Passed to the argpar_parse_ functions, this tells argpar not to call exit after printing help/usage,...
Definition: argpar.h:132
int argpar_clean(argpar *p)
Free any space consumed by argpar for parfiles.
Definition: argpar.c:649
char * strdup(const char *)
argpar params_parent
Definition: argpar-params.c:51
const char * argpar_program_name
Definition: argpar-params.c:9
int argpar_parse_args(argpar *p, unsigned argc, char *argv[], unsigned flags, unsigned *end_index, void *input)
Parse an array of key=value pairs and/or key arguments.
Definition: argpar.c:679
#define ARGPAR_STORE_PARAMS
Passed to the argpar_parse_ functions, this tells argpar to create a special parser that stores all p...
Definition: argpar.h:141
#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
Library for reading command-line arguments in the form of key=value.
argpar_child children[]
Definition: argpar-params.c:50
int i
Definition: decode_rs.h:71
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