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