diff options
| author | David Lamparter <equinox@opensourcerouting.org> | 2017-07-14 13:15:55 +0200 |
|---|---|---|
| committer | David Lamparter <equinox@opensourcerouting.org> | 2017-07-14 13:15:55 +0200 |
| commit | 84a98309def99b23c86de42ea8228d9191b65772 (patch) | |
| tree | d473c3ae0dd06c865fbb318aef71e19ae96931c6 /lib/command.c | |
| parent | 50790e72fb676f6f5d6a775552770aba8b2e59cc (diff) | |
| parent | 444d4d3b9355dbf7814ae41ddd78bfb7a2da7766 (diff) | |
Merge remote-tracking branch 'frr/master' into newline-redux
Signed-off-by: David Lamparter <equinox@opensourcerouting.org>
Diffstat (limited to 'lib/command.c')
| -rw-r--r-- | lib/command.c | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/lib/command.c b/lib/command.c index 99e6b6e004..454f0957c5 100644 --- a/lib/command.c +++ b/lib/command.c @@ -715,6 +715,41 @@ cmd_variable_complete (struct cmd_token *token, const char *arg, vector comps) vector_free(tmpcomps); } +#define AUTOCOMP_INDENT 5 + +char * +cmd_variable_comp2str(vector comps, unsigned short cols, const char nl[]) +{ + size_t bsz = 16; + char *buf = XCALLOC(MTYPE_TMP, bsz); + int lc = AUTOCOMP_INDENT; + size_t cs = AUTOCOMP_INDENT; + size_t nllen = strlen(nl); + size_t itemlen; + snprintf(buf, bsz, "%*s", AUTOCOMP_INDENT, ""); + for (size_t j = 0; j < vector_active (comps); j++) + { + char *item = vector_slot (comps, j); + itemlen = strlen(item); + + if (cs + itemlen + nllen + AUTOCOMP_INDENT + 2 >= bsz) + buf = XREALLOC(MTYPE_TMP, buf, (bsz *= 2)); + + if (lc + itemlen + 1 >= cols) + { + cs += snprintf(&buf[cs], bsz - cs, "%s%*s", nl, AUTOCOMP_INDENT, ""); + lc = AUTOCOMP_INDENT; + } + + size_t written = snprintf(&buf[cs], bsz - cs, "%s ", item); + lc += written; + cs += written; + XFREE (MTYPE_COMPLETION, item); + vector_set_index (comps, j, NULL); + } + return buf; +} + void cmd_variable_handler_register (const struct cmd_variable_handler *cvh) { |
