Add a "display usage on error" setting
[ctxopt.git] / ctxopt.h
blob48259611c5cc3f3645ae768f860ef44dd5e68ad2
1 /* ################################################################### */
2 /* This Source Code Form is subject to the terms of the Mozilla Public */
3 /* License, v. 2.0. If a copy of the MPL was not distributed with this */
4 /* file, You can obtain one at https://mozilla.org/MPL/2.0/. */
5 /* ################################################################### */
7 #ifndef CTXOPT_H
8 #define CTXOPT_H
10 typedef enum
12 parameters,
13 constraints,
14 actions,
15 incompatibilities,
16 requirements,
17 error_functions,
18 before,
19 after,
20 } settings;
22 typedef enum
24 entering,
25 exiting
26 } direction;
28 typedef enum
30 CTXOPTNOERR = 0,
31 CTXOPTMISPAR,
32 CTXOPTREQPAR,
33 CTXOPTMISARG,
34 CTXOPTDUPOPT,
35 CTXOPTUNKPAR,
36 CTXOPTINCOPT,
37 CTXOPTCTEOPT,
38 CTXOPTCTLOPT,
39 CTXOPTCTGOPT,
40 CTXOPTCTEARG,
41 CTXOPTCTLARG,
42 CTXOPTCTGARG,
43 CTXOPTUNXARG,
44 CTXOPTERRSIZ
45 } errors;
47 typedef enum
49 continue_after,
50 exit_after
51 } usage_behaviour;
53 typedef struct state_s
55 char * prog_name; /* base name of the program name. */
56 char * ctx_name; /* current context name. */
57 char * ctx_par_name; /* parameter which led to this context. */
58 char * opt_name; /* current option name. */
59 int opts_count; /* limit of the number of occurrences of *
60 | the current option. */
61 int opt_args_count; /* limit of the number of parameters of *
62 | the current option. */
63 char * pre_opt_par_name; /* parameter before the current one. */
64 char * cur_opt_par_name; /* current parameter. */
65 char * cur_opt_params; /* All the option's parameters. */
66 char * req_opt_par_needed; /* Option's params in the missing *
67 | required group of optrions. */
68 char * req_opt_par; /* Option's params of the option which *
69 | required one of the parameter in *
70 | req_opt_par_needed to also be present *
71 | in the current context. */
72 } state_t;
74 void
75 ctxopt_init(char * prog_name, char * flags);
77 void
78 ctxopt_analyze(int nb_words, char ** words, int * rem_count, char *** rem_args);
80 void
81 ctxopt_evaluate(void);
83 void
84 ctxopt_new_ctx(char * name, char * opts_specs);
86 void
87 ctxopt_ctx_disp_usage(char * ctx_name, usage_behaviour action);
89 void
90 ctxopt_disp_usage(usage_behaviour action);
92 void
93 ctxopt_add_global_settings(settings s, ...);
95 void
96 ctxopt_add_ctx_settings(settings s, ...);
98 void
99 ctxopt_add_opt_settings(settings s, ...);
102 ctxopt_format_constraint(int nb_args, char ** args, char * value, char * par);
105 ctxopt_re_constraint(int nb_args, char ** args, char * value, char * par);
108 ctxopt_range_constraint(int nb_args, char ** args, char * value, char * par);
110 void
111 ctxopt_free_memory(void);
113 #endif