<p>Corey Farrell has uploaded this change for <strong>review</strong>.</p><p><a href="https://gerrit.asterisk.org/7266">View Change</a></p><pre style="font-family: monospace,monospace; white-space: pre-wrap;">CLI: Refactor ast_cli_display_match_list.<br><br>* Stop estimating line count, just print until we run out of matches.<br>* Stop freeing entries, the caller does that anyways.<br>* Stop calculating / returning numoutput, it was ignored.<br><br>Change-Id: I7f92afa8bea92241a95227587367424c8c32a5cb<br>---<br>M main/asterisk.c<br>1 file changed, 15 insertions(+), 29 deletions(-)<br><br></pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">git pull ssh://gerrit.asterisk.org:29418/asterisk refs/changes/66/7266/1</pre><pre style="font-family: monospace,monospace; white-space: pre-wrap;">diff --git a/main/asterisk.c b/main/asterisk.c<br>index 77046f2..2908b46 100644<br>--- a/main/asterisk.c<br>+++ b/main/asterisk.c<br>@@ -3071,51 +3071,37 @@<br>        return strcasecmp(s1, s2);<br> }<br> <br>-static int ast_cli_display_match_list(char **matches, int len, int max)<br>+static void ast_cli_display_match_list(char **matches, int len, int max)<br> {<br>-   int i, idx, limit, count;<br>-    int screenwidth = 0;<br>- int numoutput = 0, numoutputline = 0;<br>-<br>-     screenwidth = ast_get_termcols(STDOUT_FILENO);<br>-<br>+    int idx = 1;<br>  /* find out how many entries can be put on one line, with two spaces between strings */<br>-      limit = screenwidth / (max + 2);<br>-     if (limit == 0)<br>+      int limit = ast_get_termcols(STDOUT_FILENO) / (max + 2);<br>+<br>+  if (limit == 0) {<br>             limit = 1;<br>-<br>-        /* how many lines of output */<br>-       count = len / limit;<br>- if (count * limit < len)<br>-          count++;<br>-<br>-  idx = 1;<br>+     }<br> <br>  qsort(&matches[0], (size_t)(len), sizeof(char *), ast_el_sort_compare);<br> <br>-       for (; count > 0; count--) {<br>-              numoutputline = 0;<br>-           for (i = 0; i < limit && matches[idx]; i++, idx++) {<br>+      for (;;) {<br>+           int numoutputline;<br> <br>+                for (numoutputline = 0; numoutputline < limit && matches[idx]; idx++) {<br>                    /* Don't print dupes */<br>                   if ( (matches[idx+1] != NULL && strcmp(matches[idx], matches[idx+1]) == 0 ) ) {<br>-                              i--;<br>-                         ast_free(matches[idx]);<br>-                              matches[idx] = NULL;<br>                          continue;<br>                     }<br> <br>-                 numoutput++;<br>                  numoutputline++;<br>                      fprintf(stdout, "%-*s  ", max, matches[idx]);<br>-                      ast_free(matches[idx]);<br>-                      matches[idx] = NULL;<br>          }<br>-            if (numoutputline > 0)<br>-                    fprintf(stdout, "\n");<br>-     }<br> <br>- return numoutput;<br>+            if (!numoutputline) {<br>+                        break;<br>+               }<br>+<br>+         fprintf(stdout, "\n");<br>+     }<br> }<br> <br> <br></pre><p>To view, visit <a href="https://gerrit.asterisk.org/7266">change 7266</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/7266"/><meta itemprop="name" content="View Change"/></div></div>

<div style="display:none"> Gerrit-Project: asterisk </div>
<div style="display:none"> Gerrit-Branch: master </div>
<div style="display:none"> Gerrit-MessageType: newchange </div>
<div style="display:none"> Gerrit-Change-Id: I7f92afa8bea92241a95227587367424c8c32a5cb </div>
<div style="display:none"> Gerrit-Change-Number: 7266 </div>
<div style="display:none"> Gerrit-PatchSet: 1 </div>
<div style="display:none"> Gerrit-Owner: Corey Farrell <git@cfware.com> </div>