diff options
author | Karel Zak | 2019-07-23 16:04:51 +0200 |
---|---|---|
committer | Karel Zak | 2019-07-23 16:24:42 +0200 |
commit | 94dbb322737524027a55e6ed5646dc69c5ed9e5b (patch) | |
tree | d4b325c8890240f984805abce6ace03fc16a2043 /libsmartcols/samples/fromfile.c | |
parent | libfdisk: improve partition copy on resize (diff) | |
download | kernel-qcow2-util-linux-94dbb322737524027a55e6ed5646dc69c5ed9e5b.tar.gz kernel-qcow2-util-linux-94dbb322737524027a55e6ed5646dc69c5ed9e5b.tar.xz kernel-qcow2-util-linux-94dbb322737524027a55e6ed5646dc69c5ed9e5b.zip |
libsmartcols: cleanup and extend padding functionality
LIBSMARTCOLS_DEBUG_PADDING=on in the next examples forces libsmartcols
print '.' as a padding char. See line "ffff" in the exmaples.
* default output is to fill all except last cell
$ LIBSMARTCOLS_DEBUG_PADDING=on ./sample-scols-fromfile --nlines 10 --width 80 --column tests/ts/libsmartcols/files/col-name --column tests/ts/libsmartcols/files/col-number --column tests/ts/libsmartcols/files/col-string --column tests/ts/libsmartcols/files/col-string tests/ts/libsmartcols/files/data-string tests/ts/libsmartcols/files/data-number tests/ts/libsmartcols/files/data-string-empty tests/ts/libsmartcols/files/data-string-empty 2> /dev/null
NAME.. ......NUM STRINGS STRINGS
aaaa.. ........0 aaaa... aaaa
bbb... ......100 bbb.... bbb
ccccc. .......21 ccccc.. ccccc
dddddd ........3 dddddd. dddddd
ee.... ......411 ee..... ee
ffff.. .....5111 .......
gggggg 678993321 gggggg. gggggg
hhh... ..7666666 hhh.... hhh
* scols_table_enable_minout() minimizes output for tailing empty cells, example:
$ LIBSMARTCOLS_DEBUG_PADDING=on ./sample-scols-fromfile --nlines 10 --minout --width 80 --column tests/ts/libsmartcols/files/col-name --column tests/ts/libsmartcols/files/col-number --column tests/ts/libsmartcols/files/col-string --column tests/ts/libsmartcols/files/col-string tests/ts/libsmartcols/files/data-string tests/ts/libsmartcols/files/data-number tests/ts/libsmartcols/files/data-string-empty tests/ts/libsmartcols/files/data-string-empty 2> /dev/null
NAME.. ......NUM STRINGS STRINGS
aaaa.. ........0 aaaa... aaaa
bbb... ......100 bbb.... bbb
ccccc. .......21 ccccc.. ccccc
dddddd ........3 dddddd. dddddd
ee.... ......411 ee..... ee
ffff.. .....5111
gggggg 678993321 gggggg. gggggg
hhh... ..7666666 hhh.... hhh
* cleanup up scols_table_enable_maxout() use, example:
$ LIBSMARTCOLS_DEBUG_PADDING=on ./sample-scols-fromfile --nlines 10 --maxout --width 80 --column tests/ts/libsmartcols/files/col-name --column tests/ts/libsmartcols/files/col-number --column tests/ts/libsmartcols/files/col-string --column tests/ts/libsmartcols/files/col-string tests/ts/libsmartcols/files/data-string tests/ts/libsmartcols/files/data-number tests/ts/libsmartcols/files/data-string-empty tests/ts/libsmartcols/files/data-string-empty 2> /dev/null
NAME.............. ..................NUM STRINGS............ STRINGS............
aaaa.............. ....................0 aaaa............... aaaa...............
bbb............... ..................100 bbb................ bbb................
ccccc............. ...................21 ccccc.............. ccccc..............
dddddd............ ....................3 dddddd............. dddddd.............
ee................ ..................411 ee................. ee.................
ffff.............. .................5111 ................... ...................
gggggg............ ............678993321 gggggg............. gggggg.............
hhh............... ..............7666666 hhh................ hhh................
Note that we cannot make scols_table_enable_minout() default because
for example "column --table" is pretty commonly used with non-blank
columns separator and in this case all cells has to be filled.
$ echo -e "aa,b,ccc\na,,\naaa,bbb,ccc" | column --table --separator ',' --output-separator '|'
aa |b |ccc
a | |
aaa|bbb|ccc
Addresses: https://github.com/karelzak/util-linux/issues/826
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libsmartcols/samples/fromfile.c')
-rw-r--r-- | libsmartcols/samples/fromfile.c | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/libsmartcols/samples/fromfile.c b/libsmartcols/samples/fromfile.c index c1ab728fd..35d85489b 100644 --- a/libsmartcols/samples/fromfile.c +++ b/libsmartcols/samples/fromfile.c @@ -151,7 +151,8 @@ static int parse_column_data(FILE *f, struct libscols_table *tb, int col) if (!ln) break; - scols_line_set_data(ln, col, str); + if (str && *str) + scols_line_set_data(ln, col, str); } free(str); @@ -204,6 +205,7 @@ static void __attribute__((__noreturn__)) usage(void) "\n %s [options] <column-data-file> ...\n\n", program_invocation_short_name); fputs(" -m, --maxout fill all terminal width\n", out); + fputs(" -M, --minout minimize tailing padding\n", out); fputs(" -c, --column <file> column definition\n", out); fputs(" -n, --nlines <num> number of lines\n", out); fputs(" -J, --json JSON output format\n", out); @@ -227,6 +229,7 @@ int main(int argc, char *argv[]) static const struct option longopts[] = { { "maxout", 0, NULL, 'm' }, + { "minout", 0, NULL, 'M' }, { "column", 1, NULL, 'c' }, { "nlines", 1, NULL, 'n' }, { "width", 1, NULL, 'w' }, @@ -242,6 +245,7 @@ int main(int argc, char *argv[]) static const ul_excl_t excl[] = { /* rows and cols in ASCII order */ { 'E', 'J', 'r' }, + { 'M', 'm' }, { 0 } }; int excl_st[ARRAY_SIZE(excl)] = UL_EXCL_STATUS_INIT; @@ -253,7 +257,7 @@ int main(int argc, char *argv[]) if (!tb) err(EXIT_FAILURE, "failed to create output table"); - while((c = getopt_long(argc, argv, "hCc:Ei:Jmn:p:rw:", longopts, NULL)) != -1) { + while((c = getopt_long(argc, argv, "hCc:Ei:JMmn:p:rw:", longopts, NULL)) != -1) { err_exclusive_options(c, longopts, excl, excl_st); @@ -285,6 +289,9 @@ int main(int argc, char *argv[]) case 'm': scols_table_enable_maxout(tb, TRUE); break; + case 'M': + scols_table_enable_minout(tb, TRUE); + break; case 'r': scols_table_enable_raw(tb, TRUE); break; |