summaryrefslogtreecommitdiffstats
path: root/libsmartcols
diff options
context:
space:
mode:
authorKarel Zak2018-10-25 14:12:16 +0200
committerKarel Zak2018-12-07 12:33:34 +0100
commit5d201da68f9efab64f9983ab2be1d44e3c09b36d (patch)
tree1eeb3f6ec38b0d53d8f4192a18df6efa294219b9 /libsmartcols
parentlsblk: make devtree dependences more generic (diff)
downloadkernel-qcow2-util-linux-5d201da68f9efab64f9983ab2be1d44e3c09b36d.tar.gz
kernel-qcow2-util-linux-5d201da68f9efab64f9983ab2be1d44e3c09b36d.tar.xz
kernel-qcow2-util-linux-5d201da68f9efab64f9983ab2be1d44e3c09b36d.zip
libsmartcols: add is_last_child(), move is_last_column()
Signed-off-by: Karel Zak <kzak@redhat.com>
Diffstat (limited to 'libsmartcols')
-rw-r--r--libsmartcols/src/smartcolsP.h22
-rw-r--r--libsmartcols/src/table_print.c19
2 files changed, 24 insertions, 17 deletions
diff --git a/libsmartcols/src/smartcolsP.h b/libsmartcols/src/smartcolsP.h
index f45ac3a24..aab3890c1 100644
--- a/libsmartcols/src/smartcolsP.h
+++ b/libsmartcols/src/smartcolsP.h
@@ -213,4 +213,26 @@ static inline int scols_iter_is_last(const struct libscols_iter *itr)
return itr->p == itr->head;
}
+static inline int is_last_child(struct libscols_line *ln)
+{
+ if (!ln || !ln->parent)
+ return 1;
+
+ return list_entry_is_last(&ln->ln_children, &ln->parent->ln_branch);
+}
+
+
+static inline int is_last_column(struct libscols_column *cl)
+{
+ struct libscols_column *next;
+
+ if (list_entry_is_last(&cl->cl_columns, &cl->table->tb_columns))
+ return 1;
+
+ next = list_entry(cl->cl_columns.next, struct libscols_column, cl_columns);
+ if (next && scols_column_is_hidden(next) && is_last_column(next))
+ return 1;
+ return 0;
+}
+
#endif /* _LIBSMARTCOLS_PRIVATE_H */
diff --git a/libsmartcols/src/table_print.c b/libsmartcols/src/table_print.c
index a15bf90e3..2bdb5d90f 100644
--- a/libsmartcols/src/table_print.c
+++ b/libsmartcols/src/table_print.c
@@ -196,7 +196,7 @@ static int line_ascii_art_to_buffer(struct libscols_table *tb,
if (rc)
return rc;
- if (list_entry_is_last(&ln->ln_children, &ln->parent->ln_branch))
+ if (is_last_child(ln))
art = " ";
else
art = vertical_symbol(tb);
@@ -204,21 +204,6 @@ static int line_ascii_art_to_buffer(struct libscols_table *tb,
return buffer_append_data(buf, art);
}
-static int is_last_column(struct libscols_column *cl)
-{
- int rc = list_entry_is_last(&cl->cl_columns, &cl->table->tb_columns);
- struct libscols_column *next;
-
- if (rc)
- return 1;
-
- next = list_entry(cl->cl_columns.next, struct libscols_column, cl_columns);
- if (next && scols_column_is_hidden(next) && is_last_column(next))
- return 1;
- return 0;
-}
-
-
static int has_pending_data(struct libscols_table *tb)
{
struct libscols_column *cl;
@@ -613,7 +598,7 @@ static int cell_to_buffer(struct libscols_table *tb,
if (ln->parent && !scols_table_is_json(tb)) {
rc = line_ascii_art_to_buffer(tb, ln->parent, buf);
- if (!rc && list_entry_is_last(&ln->ln_children, &ln->parent->ln_branch))
+ if (!rc && is_last_child(ln))
rc = buffer_append_data(buf, right_symbol(tb));
else if (!rc)
rc = buffer_append_data(buf, branch_symbol(tb));