<p>Joshua Colp <strong>merged</strong> this change.</p><p><a href="https://gerrit.asterisk.org/8589">View Change</a></p><div style="white-space:pre-wrap">Approvals:
George Joseph: Looks good to me, but someone else must approve
Richard Mudgett: Looks good to me, but someone else must approve
Joshua Colp: Looks good to me, approved; Approved for Submit
</div><pre style="font-family: monospace,monospace; white-space: pre-wrap;">aco: Use ast_cli_completion_add for 'config show help'.<br><br>In addition this removes:<br>* RAII_VAR usage<br>* Duplicate check of pos<br>* Unneeded arguments.<br><br>Change-Id: I2da8eac2670d1d8d6474c04037129804f55ebf39<br>---<br>M main/config_options.c<br>1 file changed, 37 insertions(+), 42 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/main/config_options.c b/main/config_options.c<br>index 3ac5590..c78f95d 100644<br>--- a/main/config_options.c<br>+++ b/main/config_options.c<br>@@ -960,88 +960,79 @@<br> /*! \internal<br> * \brief Complete the name of the module the user is looking for<br> */<br>-static char *complete_config_module(const char *word, int pos, int state)<br>+static char *complete_config_module(const char *word)<br> {<br>- char *c = NULL;<br> size_t wordlen = strlen(word);<br>- int which = 0;<br> struct ao2_iterator i;<br> struct ast_xml_doc_item *cur;<br> <br>- if (pos != 3) {<br>- return NULL;<br>- }<br>-<br> i = ao2_iterator_init(xmldocs, 0);<br> while ((cur = ao2_iterator_next(&i))) {<br>- if (!strncasecmp(word, cur->name, wordlen) && ++which > state) {<br>- c = ast_strdup(cur->name);<br>- ao2_ref(cur, -1);<br>- break;<br>+ if (!strncasecmp(word, cur->name, wordlen)) {<br>+ if (ast_cli_completion_add(ast_strdup(cur->name))) {<br>+ ao2_ref(cur, -1);<br>+ break;<br>+ }<br> }<br> ao2_ref(cur, -1);<br> }<br> ao2_iterator_destroy(&i);<br> <br>- return c;<br>+ return NULL;<br> }<br> <br> /*! \internal<br> * \brief Complete the name of the configuration type the user is looking for<br> */<br>-static char *complete_config_type(const char *module, const char *word, int pos, int state)<br>+static char *complete_config_type(const char *module, const char *word)<br> {<br>- char *c = NULL;<br> size_t wordlen = strlen(word);<br>- int which = 0;<br>- RAII_VAR(struct ast_xml_doc_item *, info, NULL, ao2_cleanup);<br>+ struct ast_xml_doc_item *info;<br> struct ast_xml_doc_item *cur;<br> <br>- if (pos != 4) {<br>- return NULL;<br>- }<br>-<br>- if (!(info = ao2_find(xmldocs, module, OBJ_KEY))) {<br>+ info = ao2_find(xmldocs, module, OBJ_KEY);<br>+ if (!info) {<br> return NULL;<br> }<br> <br> cur = info;<br> while ((cur = AST_LIST_NEXT(cur, next))) {<br>- if (!strcasecmp(cur->type, "configObject") && !strncasecmp(word, cur->name, wordlen) && ++which > state) {<br>- c = ast_strdup(cur->name);<br>- break;<br>+ if (!strcasecmp(cur->type, "configObject") && !strncasecmp(word, cur->name, wordlen)) {<br>+ if (ast_cli_completion_add(ast_strdup(cur->name))) {<br>+ break;<br>+ }<br> }<br> }<br>- return c;<br>+ ao2_ref(info, -1);<br>+<br>+ return NULL;<br> }<br> <br> /*! \internal<br> * \brief Complete the name of the configuration option the user is looking for<br> */<br>-static char *complete_config_option(const char *module, const char *option, const char *word, int pos, int state)<br>+static char *complete_config_option(const char *module, const char *option, const char *word)<br> {<br>- char *c = NULL;<br> size_t wordlen = strlen(word);<br>- int which = 0;<br>- RAII_VAR(struct ast_xml_doc_item *, info, NULL, ao2_cleanup);<br>+ struct ast_xml_doc_item *info;<br> struct ast_xml_doc_item *cur;<br> <br>- if (pos != 5) {<br>- return NULL;<br>- }<br>-<br>- if (!(info = ao2_find(xmldocs, module, OBJ_KEY))) {<br>+ info = ao2_find(xmldocs, module, OBJ_KEY);<br>+ if (!info) {<br> return NULL;<br> }<br> <br> cur = info;<br> while ((cur = AST_LIST_NEXT(cur, next))) {<br>- if (!strcasecmp(cur->type, "configOption") && !strcasecmp(cur->ref, option) && !strncasecmp(word, cur->name, wordlen) && ++which > state) {<br>- c = ast_strdup(cur->name);<br>- break;<br>+ if (!strcasecmp(cur->type, "configOption") && !strcasecmp(cur->ref, option) && !strncasecmp(word, cur->name, wordlen)) {<br>+ if (ast_cli_completion_add(ast_strdup(cur->name))) {<br>+ break;<br>+ }<br> }<br> }<br>- return c;<br>+ ao2_ref(info, -1);<br>+<br>+ return NULL;<br> }<br> <br> /* Define as 0 if we want to allow configurations to be registered without<br>@@ -1342,10 +1333,14 @@<br> return NULL;<br> case CLI_GENERATE:<br> switch(a->pos) {<br>- case 3: return complete_config_module(a->word, a->pos, a->n);<br>- case 4: return complete_config_type(a->argv[3], a->word, a->pos, a->n);<br>- case 5: return complete_config_option(a->argv[3], a->argv[4], a->word, a->pos, a->n);<br>- default: return NULL;<br>+ case 3:<br>+ return complete_config_module(a->word);<br>+ case 4:<br>+ return complete_config_type(a->argv[3], a->word);<br>+ case 5:<br>+ return complete_config_option(a->argv[3], a->argv[4], a->word);<br>+ default:<br>+ return NULL;<br> }<br> }<br> <br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/8589">change 8589</a>. To unsubscribe, visit <a href="https://gerrit.asterisk.org/settings">settings</a>.</p><div itemscope itemtype="http://schema.org/EmailMessage"><div itemscope itemprop="action" itemtype="http://schema.org/ViewAction"><link itemprop="url" href="https://gerrit.asterisk.org/8589"/><meta itemprop="name" content="View Change"/></div></div>
<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: 13 </div>
<div style="display:none"> Gerrit-MessageType: merged </div>
<div style="display:none"> Gerrit-Change-Id: I2da8eac2670d1d8d6474c04037129804f55ebf39 </div>
<div style="display:none"> Gerrit-Change-Number: 8589 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Corey Farrell <git@cfware.com> </div>
<div style="display:none"> Gerrit-Reviewer: George Joseph <gjoseph@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Jenkins2 </div>
<div style="display:none"> Gerrit-Reviewer: Joshua Colp <jcolp@digium.com> </div>
<div style="display:none"> Gerrit-Reviewer: Richard Mudgett <rmudgett@digium.com> </div>