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>
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>
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>
* 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>
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>
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>
* '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
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>
* 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>
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.
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?
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>
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>