diff options
author | Jenkins2 <jenkins2@gerrit.asterisk.org> | 2017-11-27 13:23:28 -0600 |
---|---|---|
committer | Gerrit Code Review <gerrit2@gerrit.digium.api> | 2017-11-27 13:23:28 -0600 |
commit | d81761137405376b4edc75190fed1460ef42798a (patch) | |
tree | 095fadd4b906a6175ef33da3116ef5ea5a7104c7 /main | |
parent | d5eb530bdf73ce94a14c3fb7be48375e70e49368 (diff) | |
parent | 0ca507ba6715c9eee2b14fe438b19f2859e89087 (diff) |
Merge "CLI: Refactor ast_cli_display_match_list." into 15
Diffstat (limited to 'main')
-rw-r--r-- | main/asterisk.c | 44 |
1 files changed, 15 insertions, 29 deletions
diff --git a/main/asterisk.c b/main/asterisk.c index c4ed9093f..fbb2e77b8 100644 --- a/main/asterisk.c +++ b/main/asterisk.c @@ -3079,51 +3079,37 @@ static int ast_el_sort_compare(const void *i1, const void *i2) return strcasecmp(s1, s2); } -static int ast_cli_display_match_list(char **matches, int len, int max) +static void ast_cli_display_match_list(char **matches, int len, int max) { - int i, idx, limit, count; - int screenwidth = 0; - int numoutput = 0, numoutputline = 0; - - screenwidth = ast_get_termcols(STDOUT_FILENO); - + int idx = 1; /* find out how many entries can be put on one line, with two spaces between strings */ - limit = screenwidth / (max + 2); - if (limit == 0) - limit = 1; + int limit = ast_get_termcols(STDOUT_FILENO) / (max + 2); - /* how many lines of output */ - count = len / limit; - if (count * limit < len) - count++; - - idx = 1; + if (limit == 0) { + limit = 1; + } qsort(&matches[0], (size_t)(len), sizeof(char *), ast_el_sort_compare); - for (; count > 0; count--) { - numoutputline = 0; - for (i = 0; i < limit && matches[idx]; i++, idx++) { + for (;;) { + int numoutputline; + for (numoutputline = 0; numoutputline < limit && matches[idx]; idx++) { /* Don't print dupes */ if ( (matches[idx+1] != NULL && strcmp(matches[idx], matches[idx+1]) == 0 ) ) { - i--; - ast_free(matches[idx]); - matches[idx] = NULL; continue; } - numoutput++; numoutputline++; fprintf(stdout, "%-*s ", max, matches[idx]); - ast_free(matches[idx]); - matches[idx] = NULL; } - if (numoutputline > 0) - fprintf(stdout, "\n"); - } - return numoutput; + if (!numoutputline) { + break; + } + + fprintf(stdout, "\n"); + } } |