Commit Graph

300 Commits

Author SHA1 Message Date
Sami Kerola 218b1dd6f9
misc: fix typos [codespell]
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-09-12 19:41:46 +01:00
Karel Zak 94dbb32273 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>
2019-07-23 16:24:42 +02:00
Karel Zak ed16c910be libsmartcols: fix docs
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-06-13 13:45:46 +02:00
Karel Zak 36ad92c23e libsmartcols: (docs) add reference to v2.33 and v2.34
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-06-07 12:32:45 +02:00
Karel Zak e2a0f26341 libsmartcols: (groups) improve scols_table_group_lines() args check [coverity scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-15 17:46:31 +02:00
Karel Zak 47b6eccc97 libsmartcols: use scols_walk_* for calculations and printing
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-07 11:46:11 +02:00
Karel Zak 19c2e73116 libsmartcols: add generic function to walk on tree
Now we implement the same thing on more places. Let's add one set of
functions to walk the tree and use it everywhere.

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-07 11:44:24 +02:00
Karel Zak 281a2f3212 libsmartcols: cell width calulation cleanup
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-03 17:27:17 +02:00
Karel Zak ea7fb72eb2 libsmartcols: (groups) use print functions tp calculate grpset
Now we have extra code to calculate grpset. It seems better to use
only one way how we wall the tree.

Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-03 17:12:18 +02:00
Karel Zak b94932c063 libsmartcols: (groups) print group childrent after regualr tree
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-03 14:53:23 +02:00
Karel Zak 46634fc90d libsmartcols: (groups) improve debug messages
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-03 13:25:09 +02:00
Karel Zak 883246a104 libsmartcols: fix groups reset, add debugs
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-02 15:51:29 +02:00
Karel Zak 4525b6cf16 libsmartcols: (groups) remove hardcoded const numbers
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-05-02 13:44:12 +02:00
Karel Zak ebb6368990 libsmartcols: print tree also for empty cells
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-02-20 12:47:24 +01:00
Sami Kerola 110260830d docs: fix typos [codespell]
Reference: https://github.com/codespell-project/codespell
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-02-18 13:22:43 +01:00
Karel Zak ebc2397ec4 libsmartcols: use list_add_tail() in more robust way
Signed-off-by: Karel Zak <kzak@redhat.com>
2019-02-18 12:33:12 +01:00
Sami Kerola 5837f08a50 libsmartcols: remove extra ';' outside of a function [-Wextra-semi]
Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2019-01-02 14:40:30 +01:00
Sami Kerola 539e96b141
libsmartcols: fix variable shadowing
libsmartcols/src/grouping.c:115:26: warning: declaration of ‘ln’ shadows a
				    previous local [-Wshadow]
libsmartcols/src/grouping.c:108:24: note: shadowed declaration is here

Signed-off-by: Sami Kerola <kerolasa@iki.fi>
2018-12-10 20:31:48 +00:00
Karel Zak 4f4c2b3cdd libsmartcols: add grouping API docs
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:33:34 +01:00
Karel Zak 309c76e4ee libsmartcols: add grouping samples
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:33:34 +01:00
Karel Zak d52f5542b0 libsmartcols: add lines grouping support
For some use-case we need to describe M:N relation between output
lines. The nice examples are RAIDs or multi-path devices in lsblk
output.

    NAME                 MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINT
    loop0                  7:0    0 955.7M  0 loop
┌┈▶ ├─test-thin-metadata 253:0    0     2M  0 dm
└┬▶ └─test-thin-data     253:1    0 953.7M  0 dm
 └┈┈test-thin-pool       253:2    0 953.7M  0 dm

In this example two line (test-thin-metadata and test-thin-data) are
parents for another line (test-thin-pool). The new API uses term "group"
for parental line -- the number of group members is unlimited and every
group has at least one child.

It's possible that group's child is member of another group:

       NAME                 MAJ:MIN RM   SIZE RO TYPE  MOUNTPOINT
       loop0                  7:0    0 955.7M  0 loop
   ┌┈▶ ├─test-thin-metadata 253:0    0     2M  0 dm
   └┬▶ └─test-thin-data     253:1    0 953.7M  0 dm
┌┈▶ └┈┈test-thin-pool       253:2    0 953.7M  0 dm
┆      └─test-thin          253:3    0 190.8M  0 dm
└┬▶    loop1                  7:1    0 190.8M  0 loop
 └┈┈┈┈┈test-thin-extsnap    253:4    0 190.8M  0 dm

For now multi-group relation is unsupported and one line can be member
of one group only. The library API and printing code is ready to
support this feature, but not sure if we really need it. All what is
necessary is to create array of groups in the line struct.

Note that grouping is independent on standard parent->child relations
between lines and grouping can connect arbitrary lines. The
restriction is only that group child cannot be child of another line
or child of another group. These cross reference are (and probably
will be) impossible.

The patch is relative large, but easy to review. Changes:

* add new UTF symbols
* add scols_symbols_set_group_* public API to modify new symbols
* add struct libscols_group, used only internally

* add "grpset" array to table struct -- the array is used to keep
position of the group in the output. Every active group uses three
items in the grpset. If there is more overlapping groups than bigger
grpset is allocated.

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:33:34 +01:00
Karel Zak 3bb882be44 libsmartcols: split print.c into print.c, put.c and print-api.c
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:33:34 +01:00
Karel Zak 06a8decd72 libsmartcols: move width calculation to separate file
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:33:34 +01:00
Karel Zak ecd7cd253d libsmartcols: rename table_print.c to print.c
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:33:34 +01:00
Karel Zak ce6cb22f0d libsmartcols: move buffer stuff to buffer.c
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:33:34 +01:00
Karel Zak 6408e164e1 libsmartcols: add another UTF symbols
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:33:34 +01:00
Karel Zak 5d201da68f libsmartcols: add is_last_child(), move is_last_column()
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-12-07 12:33:34 +01:00
Karel Zak 369be41bcd libsmartcols: don't mark as extreme where average is zero
The columns with NOEXTREME flag are internally marked as extreme
(=contains extreme width) if maximal with is greater than 2 *
average_width. This detection has to sure that the average is non-zero
otherwise the column is always "extreme".

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-08-23 10:13:17 +02:00
Karel Zak c434b2782c libsmartcols: allow to add line to table without columns
The table allows to add columns on the fly when lines already exist.
So, it does not make sense to reject request to add line to table
without columns.

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-08-23 10:02:49 +02:00
Karel Zak 4189907e6c docs: use SPDX license names
Let's use standardized names for licenses. The names used by SPDX
makes things more obvious at first glance. For complete list see:
https://spdx.org/licenses/

Note, this commit does not change any license or so...

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-08-16 14:47:21 +02:00
Karel Zak a797704d5d libsmartcols: don't print empty column
The commit 0f9f927b6f forces
libsmartcols to use one byte as a minimal column width. This seems
like a bug if the column is empty and without header.

$ printf '🅰️b\n' | column -t -s ':' -o ':'
 🅰️b

Fixed version:
$ printf '🅰️b\n' | column -t -s ':' -o ':'
🅰️b

Reported-by: Sami Kerola <kerolasa@iki.fi>
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-06-04 15:20:28 +02:00
Karel Zak 3188ea9a92 build: Add missing -lintl linkage to lib{smartcols,uuid}
Addresses: https://github.com/karelzak/util-linux/pull/615
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-04-09 12:11:36 +02:00
Karel Zak de30626495 libsmartcols: make sure boolean is true/false only
.. and never "null".

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-04-05 12:12:25 +02:00
Karel Zak b2c871f978 libsmartcols: improve JSON support (add types)
This commit add SCOLS_JSON_{NUMBER,STRING,BOOLEAN} to specify column
type for JSON output formatting.

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-04-03 15:10:10 +02:00
Karel Zak ab0ede8619 libsmartcols: (docs) update year
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-03-20 18:55:36 +01:00
Karel Zak aef70f5514 libsmartcols: fix docs warnings
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-02-21 13:23:19 +01:00
Karel Zak 7595bed189 Merge branch 'maybe-for-v2.32' of https://github.com/rudimeier/util-linux
* 'maybe-for-v2.32' of https://github.com/rudimeier/util-linux:
  tests: use pgrep instead of ps --ppid ...
  misc: fix typos using codespell
  lsns: fix clang compiler warning
  tests: add udevadm settle to sfdisk/resize
  build-sys: disable bz2 tarball and fix some am warnings
2018-02-16 11:25:22 +01:00
Ruediger Meier 73afd3f8e8 misc: fix typos using codespell
Some more funny typos, please review carefully.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2018-02-16 11:12:52 +01:00
taiyu 0f9b4f2f3a libsmartcols: fixes issue with 0 width columns
[kzak@redhat.com: - it's possible that column has zero width when
 minimal width is reduced due to very small terminal. In this case
 make sure that we do not use such column at all.]

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-02-15 12:27:23 +01:00
Karel Zak 0f9f927b6f libsmartcols: set minimal column width to 1
The default is to use header width or relative width setting as the
minimal column width. The problem are columns where is no header or
relative width. Let's set minimal width to 1 in this case.

Addresses: https://github.com/karelzak/util-linux/pull/577
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-02-15 12:20:17 +01:00
Karel Zak 19b10b8978 libsmartcols: interpret zero width for pending data as error
The command

 $ column -t -W2 -c11 <<< "cat dog bird"

causes finite loop, because there is no minimal column width (missing
header). The print functions should be robust enough to return -EINVAL
when nonsense is requested.

Addresses: https://github.com/karelzak/util-linux/pull/577
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-02-15 11:58:41 +01:00
Karel Zak 63c9c05d35 misc: remove %p from debug messages
From libs where suid program may be executed by non-root user.

Signed-off-by: Karel Zak <kzak@redhat.com>
2018-02-01 13:18:57 +01:00
Ruediger Meier af1bc027db build-sys: remove redundant EXTRA_DIST files
The sources of AC_CONFIG_FILES (*.in) are automatically
distributed.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2018-01-22 11:16:49 +01:00
Ruediger Meier 4beacf105e build-sys: avoid using prog_DEPENDENCIES
Use EXTRA_prog_DEPENDENCIES to have the benefit
of automake's automatic prog_DEPENDENCIES.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2018-01-22 11:16:49 +01:00
Ruediger Meier 0da03d4490 build-sys: remove unneeded dependencies on bla.h.in
We have already automakes's automatic dependencies like
  bla.h.in -> bla.h -> foo.o -> bar.la

An explicit direct dependency bla.h.in -> bar.la
is redundant and useless anyways.

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2018-01-22 11:16:49 +01:00
Ruediger Meier a459f2ec33 build-sys: automake is able to find headers in builddir ...
Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2018-01-22 11:16:49 +01:00
Ruediger Meier 1d667d8849 build-sys: remove generated headers from dist tar ball
Headers should only be listed in either *_HEADERS or
*_SOURCES, especially when we want nodist_*_HEADERS.

Since all the generated headers are made by configure we
don't even need to use BUILT_SOURCES or other tricks.

Also see automake docs 9.4.1 Built Sources Example:
  case "Build bindir.h from configure"

Signed-off-by: Ruediger Meier <ruediger.meier@ga-group.nl>
2018-01-22 11:16:49 +01:00
Karel Zak a15dca2f6d include/debug: introduce __UL_INIT_DEBUG_FROM_STRING()
Let's make it possible to use debug.h without environment variables.

Suggested-by: J William Piggott <elseifthen@gmx.com>
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-01-17 13:58:29 +01:00
Karel Zak 6d00cfb233 include/debug: don't print pointer address for SUID programs
* introduce new flag __UL_DEBUG_FL_NOADDR to suppress pointer address printing

* use __UL_DEBUG_FL_NOADDR when SUID

* move ul_debugobj() to debugobj.h, and require UL_DEBUG_CURRENT_MASK
  to provide access to the current mask from ul_debugobj(). It's better
  than modify all ul_debugobj() calls and use the global mask as
  argument.

* remove never used UL_DEBUG_DEFINE_FLAG

Reported-by: halfdog <me@halfdog.net>
Signed-off-by: Karel Zak <kzak@redhat.com>
2018-01-12 11:01:26 +01:00
Karel Zak 3fa48b118a libsmartcols: don't add blank padding after left aligned title
Let's use the same semantic for the title as for the last column in
the table. If aligned on left, table is not "maxout" and title padding
symbol is undefined (or blank) then keep title as short as possible.

Addresses: https://github.com/karelzak/util-linux/issues/549
Signed-off-by: Karel Zak <kzak@redhat.com>
2017-12-12 13:19:36 +01:00