summaryrefslogtreecommitdiffstats
path: root/src/basic/macro.h
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2020-10-12 13:29:46 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2020-10-22 13:20:40 +0200
commitb0e3d799891c4633bd2b0d88e4ed2c741bbcd532 (patch)
tree5a75c03dbd7d29ba9a2e2a5c01739fe3a7dc5a87 /src/basic/macro.h
parentformat-table: reduce scope of iterator variables (diff)
downloadsystemd-b0e3d799891c4633bd2b0d88e4ed2c741bbcd532.tar.xz
systemd-b0e3d799891c4633bd2b0d88e4ed2c741bbcd532.zip
format-table: add TABLE_STRV_WRAPPED
The idea is that we have strvs like list of server names or addresses, where the majority of strings is rather short, but some are long and there can potentially be many strings. So formattting them either all on one line or all in separate lines leads to output that is either hard to read or uses way too many rows. We want to wrap them, but relying on the pager to do the wrapping is not nice. Normal text has a lot of redundancy, so when the pager wraps a line in the middle of a word the read can understand what is going on without any trouble. But for a high-density zero-redundancy text like an IP address it is much nicer to wrap between words. This also makes c&p easier. This adds a variant of TABLE_STRV which is wrapped on output (with line breaks inserted between different strv entries). The change table_print() is quite ugly. A second pass is added to re-calculate column widths. Since column size is now "soft", i.e. it can adjust based on available columns, we need to two passes: - first we figure out how much space we want - in the second pass we figure out what the actual wrapped columns widths will be. To avoid unnessary work, the second pass is only done when we actually have wrappable fields. A test is added in test-format-table.
Diffstat (limited to 'src/basic/macro.h')
-rw-r--r--src/basic/macro.h4
1 files changed, 3 insertions, 1 deletions
diff --git a/src/basic/macro.h b/src/basic/macro.h
index 954bb2de2a..f92e89a3a8 100644
--- a/src/basic/macro.h
+++ b/src/basic/macro.h
@@ -634,6 +634,8 @@ static inline int __coverity_check_and_return__(int condition) {
_copy; \
})
-#define SIZE_ADD(x, y) ((x) >= SIZE_MAX - (y) ? SIZE_MAX : (x) + (y))
+static inline size_t size_add(size_t x, size_t y) {
+ return y >= SIZE_MAX - x ? SIZE_MAX : x + y;
+}
#include "log.h"