diff options
author | pgen <p.gen.progs@gmail.com> | 2020-09-10 00:37:57 +0200 |
---|---|---|
committer | pgen <p.gen.progs@gmail.com> | 2020-09-13 12:12:21 +0200 |
commit | 683f32c8f52e2e89aa3cff60a9f9c2140a59e5bc (patch) | |
tree | c0565a9a15bc84aee36f9cc64b29df884191741f /ctxopt.c | |
parent | 613e0d13062fe4a74686f389ffb785a38224083b (diff) |
Sync with github's ctxopt commit 744a2f9
Diffstat (limited to 'ctxopt.c')
-rw-r--r-- | ctxopt.c | 60 |
1 files changed, 41 insertions, 19 deletions
@@ -211,6 +211,9 @@ static void incomp_bst_free(void * b); static void +req_free(void * r); + +static void seen_opt_free(void * seen_opt); static int @@ -1417,17 +1420,17 @@ struct opt_s /* """"""""""""""""""""""""""" */ struct ctx_inst_s { - ctx_t * ctx; /* the context whose this is an instance of */ - ctx_inst_t * prev_ctx_inst; /* ctx_inst of the opt_inst which led to the * - | creation of this ctx_inst structure. */ - opt_inst_t * gen_opt_inst; /* opt_inst which led to the creation of a * - | instance of this structure. */ - ll_t * incomp_bst_list; /* list of seen_opt_t BST. */ - void * seen_opt_bst; /* tree of seen_opt_t. */ - ll_t * opt_req_list; /* list of req_t. */ - ll_t * opt_inst_list; /* The list of option instances in this * - | context instance. */ - char * par_name; /* parameter which created this instance. */ + ctx_t * ctx; /* the context whose this is an instance of */ + ctx_inst_t * prev_ctx_inst; /* ctx_inst of the opt_inst which led to the * + | creation of this ctx_inst structure. */ + opt_inst_t * gen_opt_inst; /* opt_inst which led to the creation of a * + | instance of this structure. */ + ll_t * incomp_bst_list; /* list of seen_opt_t BST. */ + void * seen_opt_bst; /* tree of seen_opt_t. */ + ll_t * opt_req_list; /* list of req_t. */ + ll_t * opt_inst_list; /* The list of option instances in this * + | context instance. */ + char * par_name; /* parameter which created this instance. */ }; /* Option instance structure. */ @@ -1483,15 +1486,15 @@ struct constraint_s | it to be freed. */ }; -state_t * cur_state = NULL; /* Current analysis state. */ -static ll_t * cmdline_list; /* List of interpreted CLI words * +state_t * cur_state = NULL; /* Current analysis state. */ +static ll_t * cmdline_list; /* List of interpreted CLI words * | serves as the basis for the * | analysis of the parameters. */ static ctx_t * main_ctx = NULL; /* initial context. */ static ctx_inst_t * first_ctx_inst = NULL; /* Pointer to the fist context * | instance which holds the * | options instances. */ -static ll_t * ctx_inst_list = NULL; /* List of the context instances. */ +static ll_t * ctx_inst_list = NULL; /* List of the context instances. */ static flags_t flags = { 0, 1 }; @@ -1559,6 +1562,7 @@ ctx_free(void * c) ll_destroy(ctx->opt_list, NULL); ll_destroy(ctx->incomp_list, free); + ll_destroy(ctx->req_list, free); bst_destroy(ctx->par_bst, par_free); free(c); @@ -1576,13 +1580,14 @@ ctx_inst_free(void * ci) ll_destroy(ctx_inst->incomp_bst_list, incomp_bst_free); bst_destroy(ctx_inst->seen_opt_bst, seen_opt_free); ll_destroy(ctx_inst->opt_inst_list, opt_inst_free); + ll_destroy(ctx_inst->opt_req_list, req_free); free(ci); } -/* ============================= */ -/* Free a opt_inst_list element. */ -/* ============================= */ +/* ============================== */ +/* Free an opt_inst_list element. */ +/* ============================== */ static void opt_inst_free(void * oi) { @@ -1631,6 +1636,18 @@ incomp_bst_free(void * b) bst_destroy(bst, NULL); } +/* ============================= */ +/* Free an opt_req_list element. */ +/* ============================= */ +static void +req_free(void * r) +{ + req_t * req = r; + + ll_destroy(req->or_opt_list, NULL); + free(req); +} + /* ================================= */ /* Compare two options_bst elements. */ /* ================================= */ @@ -1656,6 +1673,7 @@ opt_free(void * o) ll_destroy(opt->ctx_list, NULL); ll_destroy(opt->constraints_list, constraint_free); + ll_destroy(opt->eval_before_list, NULL); free(o); } @@ -3126,6 +3144,8 @@ new_ctx_inst(ctx_t * ctx, ctx_inst_t * prev_ctx_inst) else fatal_internal("Unknown option %s.", opt_name); + free(str); + node = node->next; } return ctx_inst; @@ -3444,6 +3464,8 @@ ctxopt_analyze(int nb_words, char ** words, int * nb_rem_args, /* """""""""""""""""""""""""""""""""" */ cli_node = cmdline_list->head; expect_par = 1; + par_name = NULL; + while (cli_node != NULL) { if (strcmp(cli_node->data, "--") == 0) @@ -3453,7 +3475,7 @@ ctxopt_analyze(int nb_words, char ** words, int * nb_rem_args, /* Replace a leading -- by a single - */ /* """""""""""""""""""""""""""""""""" */ - if (strncmp(cli_node->data, "--", 2) == 0) + if (strncmp(par_name, "--", 2) == 0) par_name += 1; /* Ignore the first dash */ if (strcmp(par_name, "\x1d") == 0) @@ -3906,7 +3928,7 @@ ctxopt_analyze(int nb_words, char ** words, int * nb_rem_args, cli_node = cli_node->next; } - if (cmdline_list->len > 0 && *par_name == '-') + if (cmdline_list->len > 0 && par_name && *par_name == '-') { if (expect_arg && !opt->optional_args) fatal(CTXOPTMISARG, NULL); |