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 /* ################################################################### */ 6 7 #ifndef CTXOPT_H 8 #define CTXOPT_H 9 10 typedef enum 11 { 12 parameters, 13 constraints, 14 actions, 15 incompatibilities, 16 requirements, 17 error_functions, 18 before, 19 after, 20 } settings; 21 22 typedef enum 23 { 24 entering, 25 exiting 26 } direction; 27 28 typedef enum 29 { 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; 46 47 typedef enum 48 { 49 continue_after, 50 exit_after 51 } usage_behaviour; 52 53 typedef struct state_s 54 { 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; 73 74 void 75 ctxopt_init(char * prog_name, char * flags); 76 77 void 78 ctxopt_analyze(int nb_words, char ** words, int * rem_count, char *** rem_args); 79 80 void 81 ctxopt_evaluate(void); 82 83 void 84 ctxopt_new_ctx(char * name, char * opts_specs); 85 86 void 87 ctxopt_ctx_disp_usage(char * ctx_name, usage_behaviour action); 88 89 void 90 ctxopt_disp_usage(usage_behaviour action); 91 92 void 93 ctxopt_add_global_settings(settings s, ...); 94 95 void 96 ctxopt_add_ctx_settings(settings s, ...); 97 98 void 99 ctxopt_add_opt_settings(settings s, ...); 100 101 int 102 ctxopt_format_constraint(int nb_args, char ** args, char * value, char * par); 103 104 int 105 ctxopt_re_constraint(int nb_args, char ** args, char * value, char * par); 106 107 int 108 ctxopt_range_constraint(int nb_args, char ** args, char * value, char * par); 109 110 void 111 ctxopt_free_memory(void); 112 113 #endif 114