restructure so that the trailing separator is output separately from

the inner line separators
This commit is contained in:
tg 2016-11-11 20:22:52 +00:00
parent 5ba6be5837
commit 2f63478bc9

20
misc.c
View File

@ -30,7 +30,7 @@
#include <grp.h> #include <grp.h>
#endif #endif
__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.246 2016/11/11 20:14:18 tg Exp $"); __RCSID("$MirOS: src/bin/mksh/misc.c,v 1.247 2016/11/11 20:22:52 tg Exp $");
#define KSH_CHVT_FLAG #define KSH_CHVT_FLAG
#ifdef MKSH_SMALL #ifdef MKSH_SMALL
@ -1233,7 +1233,7 @@ print_columns(struct columnise_opts *opts, unsigned int n,
void (*func)(char *, size_t, unsigned int, const void *), void (*func)(char *, size_t, unsigned int, const void *),
const void *arg, size_t max_oct, size_t max_colz) const void *arg, size_t max_oct, size_t max_colz)
{ {
unsigned int i, r, c, rows, cols, nspace, max_col; unsigned int i, r = 0, c, rows, cols, nspace, max_col;
char *str; char *str;
if (!n) if (!n)
@ -1268,10 +1268,12 @@ print_columns(struct columnise_opts *opts, unsigned int n,
/* if we can only print one column anyway, skip the goo */ /* if we can only print one column anyway, skip the goo */
if (cols < 2) { if (cols < 2) {
for (i = 0; i < n; ++i) { goto prcols_easy;
(*func)(str, max_oct, i, arg); while (r < n) {
shf_puts(str, opts->shf);
shf_putc('\n', opts->shf); shf_putc('\n', opts->shf);
prcols_easy:
(*func)(str, max_oct, r++, arg);
shf_puts(str, opts->shf);
} }
goto out; goto out;
} }
@ -1286,7 +1288,10 @@ print_columns(struct columnise_opts *opts, unsigned int n,
if (nspace < 2) if (nspace < 2)
nspace = 2; nspace = 2;
max_col = -max_col; max_col = -max_col;
for (r = 0; r < rows; r++) { goto prcols_hard;
while (r < rows) {
shf_putchar('\n', opts->shf);
prcols_hard:
for (c = 0; c < cols; c++) { for (c = 0; c < cols; c++) {
if ((i = c * rows + r) >= n) if ((i = c * rows + r) >= n)
break; break;
@ -1297,9 +1302,10 @@ print_columns(struct columnise_opts *opts, unsigned int n,
shf_fprintf(opts->shf, "%*s%*s", shf_fprintf(opts->shf, "%*s%*s",
(int)max_col, str, (int)nspace, null); (int)max_col, str, (int)nspace, null);
} }
shf_putchar('\n', opts->shf); ++r;
} }
out: out:
shf_putchar('\n', opts->shf);
afree(str, ATEMP); afree(str, ATEMP);
} }