]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libsmartcols: add is_last_child(), move is_last_column()
authorKarel Zak <kzak@redhat.com>
Thu, 25 Oct 2018 12:12:16 +0000 (14:12 +0200)
committerKarel Zak <kzak@redhat.com>
Fri, 7 Dec 2018 11:33:34 +0000 (12:33 +0100)
Signed-off-by: Karel Zak <kzak@redhat.com>
libsmartcols/src/smartcolsP.h
libsmartcols/src/table_print.c

index f45ac3a242381b492dfe44026515b49263ecb199..aab3890c17e17f4ffb70afea392529f2dd14053c 100644 (file)
@@ -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 */
index a15bf90e341993aa5481277e273a2763042cfeed..2bdb5d90f31a22f1e0562c56dbb1632d7da9ee3f 100644 (file)
@@ -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));