summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLennart Poettering <lennart@poettering.net>2019-07-29 18:38:13 +0200
committerLennart Poettering <lennart@poettering.net>2019-07-29 18:48:28 +0200
commit728a22d3b13b3fb76ebbf4e9fb5bde74001bcac4 (patch)
tree446a40a71987dba35b79e5cca6734c7f0d54e1b7
parent4ea710eaf44132fbc10634dad3a4ac1e24432b6a (diff)
downloadsystemd-728a22d3b13b3fb76ebbf4e9fb5bde74001bcac4.tar.gz
format-table: add table_fill_empty() to fill in empty cells until the specified column is reached
-rw-r--r--src/shared/format-table.c21
-rw-r--r--src/shared/format-table.h2
2 files changed, 23 insertions, 0 deletions
diff --git a/src/shared/format-table.c b/src/shared/format-table.c
index d2764eebbd..39fc80571e 100644
--- a/src/shared/format-table.c
+++ b/src/shared/format-table.c
@@ -418,6 +418,27 @@ int table_add_cell_stringf(Table *t, TableCell **ret_cell, const char *format, .
return table_add_cell(t, ret_cell, TABLE_STRING, buffer);
}
+int table_fill_empty(Table *t, size_t until_column) {
+ int r;
+
+ assert(t);
+
+ /* Fill the rest of the current line with empty cells until we reach the specified column. Will add
+ * at least one cell. Pass 0 in order to fill a line to the end or insert an empty line. */
+
+ if (until_column >= t->n_columns)
+ return -EINVAL;
+
+ do {
+ r = table_add_cell(t, NULL, TABLE_EMPTY, NULL);
+ if (r < 0)
+ return r;
+
+ } while ((t->n_cells % t->n_columns) != until_column);
+
+ return 0;
+}
+
int table_dup_cell(Table *t, TableCell *cell) {
size_t i;
diff --git a/src/shared/format-table.h b/src/shared/format-table.h
index 8afb4257a8..0942fd7248 100644
--- a/src/shared/format-table.h
+++ b/src/shared/format-table.h
@@ -59,6 +59,8 @@ static inline int table_add_cell(Table *t, TableCell **ret_cell, TableDataType t
}
int table_add_cell_stringf(Table *t, TableCell **ret_cell, const char *format, ...) _printf_(3, 4);
+int table_fill_empty(Table *t, size_t until_column);
+
int table_dup_cell(Table *t, TableCell *cell);
int table_set_minimum_width(Table *t, TableCell *cell, size_t minimum_width);