summaryrefslogtreecommitdiffstats
path: root/ctxopt.h
blob: 9aa1f8ef46ae7160a630e15ef2d38f8785d5a49d (plain)
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
/* ########################################################### */
/* This Software is licensed under the GPL licensed Version 2, */
/* please read http://www.gnu.org/copyleft/gpl.html            */
/* ########################################################### */

#ifndef CTXOPT_H
#define CTXOPT_H

typedef enum
{
  parameters,
  constraints,
  actions,
  incompatibilities,
  error_functions
} settings;

typedef enum
{
  entering,
  exiting
} direction;

typedef enum
{
  CTXOPTNOERR = 0,
  CTXOPTMISPAR,
  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.                    */
} 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