diff options
author | pgen <p.gen.progs@gmail.com> | 2020-07-20 19:17:32 +0200 |
---|---|---|
committer | pgen <p.gen.progs@gmail.com> | 2020-07-20 19:24:26 +0200 |
commit | 8a390021cc4f1914a95afbe5ebdb9cdd1144cf89 (patch) | |
tree | a2c688f5a04018109c41a2d73a304a9a04113d2f /ctxopt.c | |
parent | f1d533a03bfda3eb8aef1d7549bb10cf47f0406c (diff) |
Sync with github's ctxopt commit a5447dc
Diffstat (limited to 'ctxopt.c')
-rw-r--r-- | ctxopt.c | 43 |
1 files changed, 43 insertions, 0 deletions
@@ -3191,6 +3191,10 @@ void ctxopt_analyze(int nb_words, char ** words, int * nb_rem_args, char *** rem_args) { + char * ctxopt_debug_env; /* Environment variable CTXOPT_DEBUG content. */ + int ctxopt_debug; /* 1 if ctxopt_debug_env is set and not empty. * + | 0 if ctxopt_debug_env is unset or empty. */ + ctx_t * ctx; opt_t * opt; par_t * par; @@ -3219,6 +3223,14 @@ ctxopt_analyze(int nb_words, char ** words, int * nb_rem_args, /* """""""""""""""""""""""""""""""""""""""""""""""""""""""""""""""" */ bst_walk(options_bst, bst_check_opt_cb); + /* CTXOPT debug setting */ + /* """""""""""""""""""" */ + ctxopt_debug_env = getenv("CTXOPT_DEBUG"); + if (ctxopt_debug_env != NULL && *ctxopt_debug_env != '\0') + ctxopt_debug = 1; + else + ctxopt_debug = 0; + /* Create the first ctx_inst record. */ /* """"""""""""""""""""""""""""""""" */ ctx = main_ctx; @@ -3265,6 +3277,12 @@ ctxopt_analyze(int nb_words, char ** words, int * nb_rem_args, /* """"""""""""""""""""" */ cur_state->ctx_name = ctx->name; cur_state->ctx_par_name = ctx_inst->par_name; + + if (ctxopt_debug) + fprintf(stderr, + "CTXOPT_DEBUG: Context forced backtrack, " + "new current context: %s.\n", + ctx->name); } else { @@ -3284,6 +3302,10 @@ ctxopt_analyze(int nb_words, char ** words, int * nb_rem_args, cur_state->ctx_name = ctx->name; cur_state->ctx_par_name = ctx_inst->par_name; + if (ctxopt_debug) + fprintf(stderr, "CTXOPT_DEBUG: Parameter: %s. Current context: %s.\n", + par_name, cur_state->ctx_name); + /* An expected parameter has been seen. */ /* """""""""""""""""""""""""""""""""""" */ if ((par = locate_par(par_name, ctx)) == NULL) @@ -3314,6 +3336,12 @@ ctxopt_analyze(int nb_words, char ** words, int * nb_rem_args, prefix = look_for_valid_prefix_in_word(par_name, ctx, &pos, &popt); if (prefix != NULL && pos != 0) { + if (ctxopt_debug) + fprintf(stderr, + "CTXOPT_DEBUG: Found a valid parameter " + "as a prefix of %s: %s.\n", + par_name, prefix); + cli_node->data = prefix; /* prefix contains le name of a valid * | parameter in this context. */ @@ -3387,6 +3415,12 @@ ctxopt_analyze(int nb_words, char ** words, int * nb_rem_args, ctx_inst = ctx_inst->prev_ctx_inst; ctx = ctx_inst->ctx; + if (ctxopt_debug) + fprintf(stderr, + "CTXOPT_DEBUG: Context backtrack, " + "new current context: %s.\n", + ctx->name); + /* Update current_state. */ /* """"""""""""""""""""" */ cur_state->ctx_name = ctx->name; @@ -3564,6 +3598,12 @@ ctxopt_analyze(int nb_words, char ** words, int * nb_rem_args, ctx_inst->par_name = xstrdup(par_name); ll_append(ctx_inst_list, ctx_inst); + + if (ctxopt_debug) + fprintf(stderr, + "CTXOPT_DEBUG: Context change, " + "new current context: %s.\n", + ctx->name); } /* Look is we must expect some arguments. */ @@ -3614,6 +3654,9 @@ ctxopt_analyze(int nb_words, char ** words, int * nb_rem_args, ll_node_t * cstr_node; constraint_t * cstr; + if (ctxopt_debug) + fprintf(stderr, "CTXOPT_DEBUG: Argument: %s.\n", par_name); + /* Check if the arguments of the option respects */ /* the attached constraints if any. */ /* """"""""""""""""""""""""""""""""""""""""""""" */ |