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