Commit graph

361 commits

Author SHA1 Message Date
Thomas Weißschuh
d36705f402 libsmartcols: (samples): fix format truncation warning
As this is only an example and the needed memory is not much just
hardcode a large enough number.
The previously computed value was wrong anyways.

libsmartcols/samples/continuous.c: In function 'main':
libsmartcols/samples/continuous.c:110:61: error: '%3d' directive output may be truncated writing between 3 and 11 bytes into a region of size between 0 and 7 [-Werror=format-truncation=]
  110 |                         snprintf(timecell, timecellsz, "%f [%3d%%]", diff,
      |                                                             ^~~
libsmartcols/samples/continuous.c:110:25: note: 'snprintf' output between 11 and 333 bytes into a destination of size 12
  110 |                         snprintf(timecell, timecellsz, "%f [%3d%%]", diff,
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  111 |                                 done ? 100 : (int)(diff / (TIME_PERIOD / 100.0)));
      |                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
libsmartcols/samples/continuous.c:110:61: error: '%3d' directive output may be truncated writing 3 bytes into a region of size between 0 and 7 [-Werror=format-truncation=]
  110 |                         snprintf(timecell, timecellsz, "%f [%3d%%]", diff,
      |                                                             ^~~
libsmartcols/samples/continuous.c:110:25: note: 'snprintf' output between 11 and 325 bytes into a destination of size 12
  110 |                         snprintf(timecell, timecellsz, "%f [%3d%%]", diff,
      |                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  111 |                                 done ? 100 : (int)(diff / (TIME_PERIOD / 100.0)));
      |                                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2023-05-19 17:50:01 +02:00
Karel Zak
e7a473b1e0 libmount: add missing symbols to docs
Signed-off-by: Karel Zak <kzak@redhat.com>
2023-03-02 13:39:12 +01:00
Karel Zak
b48ef54b43 libsmartcols: support simplified color sequences
Signed-off-by: Karel Zak <kzak@redhat.com>
2023-02-27 17:50:39 +01:00
Karel Zak
c64e6afbeb Merge branch '1' of https://github.com/neheb/util-linux
* '1' of https://github.com/neheb/util-linux:
  meson: remove some unused variables
  meson: fix array issue
2022-10-31 13:19:34 +01:00
Karel Zak
ffacfb2963 libsmartcols: fix divide by zero [coverity]
Signed-off-by: Karel Zak <kzak@redhat.com>
2022-10-31 09:33:24 +01:00
Rosen Penev
7da59534f8 meson: remove some unused variables
Found with muon's analyze.

Signed-off-by: Rosen Penev <rosenp@gmail.com>
2022-10-28 17:04:46 -07:00
Karel Zak
846ae2dcf4 libsmartcols: make columns reduction more backward compatible
The original version truncates only columns with extreme and truncate
flags.

Signed-off-by: Karel Zak <kzak@redhat.com>
2022-10-25 12:35:38 +02:00
Karel Zak
94feb5a20d libsmartcols: improve columns reduction
Signed-off-by: Karel Zak <kzak@redhat.com>
2022-10-25 11:11:06 +02:00
Karel Zak
3949a48dd1 libsmartcols: truncate by one char
Signed-off-by: Karel Zak <kzak@redhat.com>
2022-10-25 11:11:06 +02:00
Karel Zak
ee4cab98de libsmartcols: use local sqrt() implemenation
We do not need any powerful and precise sqrt implementation, so
let's use local code rather than depend on an external library.

Signed-off-by: Karel Zak <kzak@redhat.com>
2022-10-25 11:11:06 +02:00
Karel Zak
5470acc6a3 libsmartcols: use standard deviation to optimize columns width
The standard deviation together with mean (average) of the data width
can be used to detect "problematic" columns and to calculate optimal
width.

The idea is to sort column by avg+deviation and start columns width
reduction from the column with the most wide and variable width. The
width reduction is also optimized by 68–95–99 rule (aka empirical
rule, avg+n*deviation; where n={1,2,3}) to cover 95% or 68% data in
the column.

The disadvantage is we need to link libsmartcols with -lm (math) due
to sqrt() function.

Signed-off-by: Karel Zak <kzak@redhat.com>
2022-10-25 11:11:06 +02:00
Karel Zak
9522ff7796 libsmartcols: improve debug messages
* disable debug for tree-wall; it generates to many messages

* fix way how library prints column flags, 0x<hex> is more redable

Signed-off-by: Karel Zak <kzak@redhat.com>
2022-10-25 11:11:06 +02:00
Karel Zak
2aa5e70640 libsmartcols: (sample) remove hidden variable [CodeQL scan]
Signed-off-by: Karel Zak <kzak@redhat.com>
2022-09-21 09:42:12 +02:00
Karel Zak
c62b212080 lsblk: use strcoll() to sort
It's more user-friendly to follow locale.

Signed-off-by: Karel Zak <kzak@redhat.com>
2022-09-01 11:12:13 +02:00
Eli Schwartz
eefff5aac7
meson: fix typoed copy-paste error that override other dependencies to blkid 2022-04-14 19:47:56 -04:00
Eli Schwartz
a246498349
meson: export dependencies as declared dependencies
This allows util-linux to be built as a subproject in order to provide
an alternative to a system version of e.g. fdisk.pc, uuid.pc
2022-04-12 21:47:58 -04:00
Karel Zak
576f626b3a libsmartcols: add scols_column_set_properties()
This function can set all column properties from comma separated
string.

Signed-off-by: Karel Zak <kzak@redhat.com>
2022-03-30 11:14:31 +02:00
Karel Zak
dbdb18c1f6 docs: update copyright years
Signed-off-by: Karel Zak <kzak@redhat.com>
2022-03-15 13:20:47 +01:00
Karel Zak
3b5db50f73 libsmartcols: change "export" behavior, add "shellvar" flag
In version 2.37 the "export" output format automatically modifies
column names to be compatible with shell's requirements for variable
names. This change was backwardly incompatible for people who use for
example "lsblk -P" in non-shell environment.

It's painful to modify this behavior again in v2.38, but it seems
better to add a way how to control this behavior independently on
output format as it seems attractive feature for more use-cases.

This commit introduces scols_table_enable_shellvar() function to
enable/disable this feature.

It also introduces

	scols_column_set_name
	scols_column_get_name
	scols_column_get_name_as_shellvar
	scols_table_is_shellvar

to make it easy to work with column names.

Fixes: https://github.com/util-linux/util-linux/issues/1594
Signed-off-by: Karel Zak <kzak@redhat.com>
2022-02-11 12:06:41 +01:00
Karel Zak
22abf6df38 libsmartcols: fix lines groups for multi-line cells
Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=2031303
Signed-off-by: Karel Zak <kzak@redhat.com>
2022-01-05 11:15:36 +01:00
Karel Zak
dd69e525fd libsmartcols: add multi-line cells to samples
Signed-off-by: Karel Zak <kzak@redhat.com>
2022-01-05 11:04:05 +01:00
Thomas Weißschuh
3f7734ae6a meson: only install pkgconfig if library is built 2021-12-30 22:57:24 +01:00
Thomas Weißschuh
7a7982f94e meson: headers: Install headers
Fixes #1365

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2021-12-30 22:53:08 +01:00
Thomas Weißschuh
f02de6de85 meson: headers: use util-linux version of version defines
This matches what autotools is doing.

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2021-12-30 18:16:13 +01:00
Karel Zak
9c06edb074 libsmartcols: add scols_line_get_column_data()
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-10-06 11:01:54 +02:00
Alex Xu (Hello71)
231c2ffb9a meson: fix building libsmartcols 2021-09-07 18:58:32 -04:00
Karel Zak
28af0586b7 docs: fix info about LIBSMARTCOLS_DEBUG_PADDING
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-08-10 10:14:22 +02:00
Karel Zak
4be393a4ba libsmartcols: use lib/buffer, remove local implementation
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-08-06 12:13:56 +02:00
Karel Zak
2342efec20 libsmartcols: use snprintf() rather than sprintf() 2021-07-27 13:28:52 +02:00
Karel Zak
0d281926a3 libsmartcols: fix bare array on JSON output
The bare array ({[...]}) for top level list of entries is invalid. It
seems better to print empty string than nothing. This is workaround
for broken utils, better is to define a table name.

Addresses: https://github.com/karelzak/util-linux/issues/1339
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-06-07 10:32:20 +02:00
Karel Zak
79884c5dd1 Merge branch 'lscpu-json-types' of https://github.com/t-8ch/util-linux
* 'lscpu-json-types' of https://github.com/t-8ch/util-linux:
  lscpu: use optional json values
  libsmartcols: add support for optional boolean values
  lscpu: use json types
2021-06-02 13:06:10 +02:00
Karel Zak
d58121a22a docs: update copyright years
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-05-31 18:12:07 +02:00
Thomas Weißschuh
f48554d48b libsmartcols: add support for optional boolean values
These default to `null` instead of `false`.

Signed-off-by: Thomas Weißschuh <thomas@t-8ch.de>
2021-05-30 23:17:23 +02:00
Karel Zak
d124a78034 lib/jsonwrt: remove 'islast' from API
The code should be able to keep track about previous content and print
JSON objects separator automatically.

Signed-off-by: Karel Zak <kzak@redhat.com>
2021-05-06 15:58:02 +02:00
Karel Zak
aac716f503 libsmartcols: make buffers append function more robust
Fixes: https://github.com/karelzak/util-linux/issues/1279
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-04-14 16:25:30 +02:00
Karel Zak
529b51706e libsmartcols: introduce default sort column
* add default sort column, set by scols_sort_table()

* sort tree according to default sort column also in scols_sort_table_by_tree()

The function scols_sort_table() does not sort tree branches if tree
is not enabled. The function scols_sort_table_by_tree() does not care
if tree is enabled and it always follows parent->child relations. For
scols_sort_table_by_tree() we need to follow order in branches if
previously scols_sort_table() has been called.

For example lsblk calls

	scols_sort_table(tb, cl);
	scols_sort_table_by_tree(tb);

for list-like output (for example lsblk -P) and users assume the
same order as for tree (lsblk --tree).

Addresses: https://bugzilla.redhat.com/show_bug.cgi?id=1940607
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-03-24 12:43:17 +01:00
Karel Zak
c59d442809 libsmartcols: add sort sunction to the sample
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-03-24 12:42:58 +01:00
Karel Zak
308a097968 meson: update sources and dependencies
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-03-17 15:07:27 +01:00
Zbigniew Jędrzejewski-Szmek
69939195bd meson: implement building of static programs
The whole thing is complicated by the fact that we have two layers
of libraries: e.g. libmount also needs libblkid. If we just tell meson
to make libmount static, this is not enough, because we also need it
to link to a static libblkid. Hence in the case of libs that link to
other libs internally, we need to create a different object with a
a different set of link_with items.

To avoid building the libraries twice, libfdisk and libmount are first
built into an internal "convenience" library, which is then linked into
the static and shared versions as appropriate.
2021-03-17 15:07:27 +01:00
Zbigniew Jędrzejewski-Szmek
d4c880d5a4 meson: add second build system
To build: meson build && ninja -C build
To run tests: ninja -C build check
To install for packaging: DESTDIR=/var/tmp/inst ninja -C build install
To install for realz: sudo ninja -C build install

v2:
- Optional items are now based on the 'feature' feature in meson.
  Built libraries which are disabled turn into disabler() objects
  and also poison any executables which link to them.

What is there:
- building of the binaries and libs and the python module
- installation of binaries, libs, python module, localization files,
  man pages, pkgconfig files
- running of tests
- most options to configure build equivalently to the
  ./configure settings

Partially implemented:
- disabling of stuff when things missing. In the C code, the defines
  are all used, so that should be fine. In the build system, some
  files should be skipped, but that is probably not always done properly.
  Getting this right might require some testing of various build option
  combinations to get the details right.

Not implemented:
- static builds of fdisk and other binaries
- things marked with XXX or FIXME
- ???

Differences:
- .la files are not created. They are useless and everybody hates them.
- Requires.private in pkgconfig files are not present in the
  autogenerated .pc file. Not sure if they should be there or not. If
  necessary, they can be added by hand.
- man pages and systemd units are installed by the install target. Not
  sure why 'make install' doesn't do that.
- the split between / and /usr is probably wrong. But it's all pointless
  anyway, so maybe we could simplify things but not implementing it at
  all under meson?
2021-03-17 15:07:27 +01:00
Karel Zak
ef7e258b3d libsmratcols: print title color only when wanted
Reference: 676fb001d6.
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-03-15 16:19:23 +01:00
Karel Zak
676fb001d6 libsmartcols: fix colors use
* use color for all cell
* always switch back to line color

Signed-off-by: Karel Zak <kzak@redhat.com>
2021-03-12 16:15:16 +01:00
Karel Zak
c173ba11ec libsmartcols: add comments to private header file
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-03-10 11:30:53 +01:00
Karel Zak
f458782f14 libsmartcols: remove unnecessary code
Fixes: https://github.com/karelzak/util-linux/pull/1243
Signed-off-by: Karel Zak <kzak@redhat.com>
2021-02-08 14:47:38 +01:00
Karel Zak
3c7355dd63 libsmartcols: support arrays for JSON output
This patch add support to format multi-line cells (columns with
SCOLS_FL_WRAP) to arrays in JSON output.

For example mountpoints[] in lsblk output:

Normal output:
	 $ lsblk -oNAME,FSTYPE,TYPE,MOUNTPOINTS /dev/sdc1
	 NAME FSTYPE TYPE MOUNTPOINTS
	 sdc1 btrfs  part /mnt/A
			  /mnt/test
			  /mnt/B

JSON output:
	$ lsblk -J -oNAME,FSTYPE,TYPE,MOUNTPOINTS /dev/sdc1
	{
	   "blockdevices": [
	      {
		 "name": "sdc1",
		 "fstype": "btrfs",
		 "type": "part",
		 "mountpoints": [
		     "/mnt/A",
		     "/mnt/test",
		     "/mnt/B"
		 ]
	      }
	   ]
	}

Signed-off-by: Karel Zak <kzak@redhat.com>
2021-01-08 13:12:57 +01:00
Karel Zak
58b510e580 libsmartcols: sanitize variable names on export output
The shells are very restrictive about variable names, only [:alnum:]
chars are allowed (and alphabetic chars as the first char).  The
library will replace "bad" chars with "_". The char '%' at the end is
replaced by _PCT.

Addresses: https://github.com/karelzak/util-linux/issues/1201
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-12-03 12:14:10 +01:00
Karel Zak
618a6ccbfd libsmartcols: use lib/jsonwrt.c for JSON
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-11-12 11:21:50 +01:00
Karel Zak
f29a2cfbe1 libsmartcols: don't print empty output on empty table in JSON
old version:
 $ findmnt --json --type foo
 $

new version:
 $ findmnt --json --type foo
 {
    "filesystems": [
    ]
 }

Addresses: https://github.com/karelzak/util-linux/issues/1136
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-09-07 11:52:13 +02:00
Karel Zak
1ac70bf5a5 libsmartcols: (docs) fix reference
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-07-22 11:22:51 +02:00
Karel Zak
40a4845693 libsmartcols: (docs) add missing references
Signed-off-by: Karel Zak <kzak@redhat.com>
2020-07-22 10:34:14 +02:00