]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libsmartcols: add SCOLS_FL_HIDDEN
authorKarel Zak <kzak@redhat.com>
Thu, 10 Dec 2015 12:02:03 +0000 (13:02 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 10 Dec 2015 12:02:03 +0000 (13:02 +0100)
Export "don't print this column" functionality by public API.

Signed-off-by: Karel Zak <kzak@redhat.com>
libsmartcols/docs/libsmartcols-sections.txt
libsmartcols/src/column.c
libsmartcols/src/libsmartcols.h.in
libsmartcols/src/smartcolsP.h
libsmartcols/src/table_print.c

index 071df3fff2ef8b92f8c394486412f64048be3ccc..30fb30225f8cb150c20ea4ce198f0c48fbd393b6 100644 (file)
@@ -20,6 +20,7 @@ scols_column_get_color
 scols_column_get_flags
 scols_column_get_header
 scols_column_get_whint
+scols_column_is_hidden
 scols_column_is_noextremes
 scols_column_is_right
 scols_column_is_strict_width
index c7af6347ce65cf0967a23d86b4ddbf8eb3a81392..269ceea0c8529d7bf2bb4d175d80e8f0f8bc58b0 100644 (file)
@@ -258,6 +258,21 @@ int scols_column_set_cmpfunc(struct libscols_column *cl,
        return 0;
 }
 
+/**
+ * scols_column_is_hidden:
+ * @cl: a pointer to a struct libscols_column instance
+ *
+ * Gets the value of @cl's flag hidden.
+ *
+ * Returns: hidden flag value, negative value in case of an error.
+ */
+int scols_column_is_hidden(struct libscols_column *cl)
+{
+       if (!cl)
+               return -EINVAL;
+       return cl->flags & SCOLS_FL_HIDDEN;
+}
+
 /**
  * scols_column_is_trunc:
  * @cl: a pointer to a struct libscols_column instance
index 2ac166b325c0ff337891c8b1062be3b787f26222..381a8eb9b6571e5e7f814d875b67edb00796eaab 100644 (file)
@@ -83,6 +83,7 @@ enum {
        SCOLS_FL_RIGHT       = (1 << 2),   /* align to the right */
        SCOLS_FL_STRICTWIDTH = (1 << 3),   /* don't reduce width if column is empty */
        SCOLS_FL_NOEXTREMES  = (1 << 4),   /* ignore extreme fields when count column width*/
+       SCOLS_FL_HIDDEN      = (1 << 5),   /* maintain data, but don't print */
 };
 
 extern struct libscols_iter *scols_new_iter(int direction);
@@ -126,6 +127,7 @@ extern int scols_column_is_tree(struct libscols_column *cl);
 extern int scols_column_is_trunc(struct libscols_column *cl);
 extern int scols_column_is_right(struct libscols_column *cl);
 extern int scols_column_is_strict_width(struct libscols_column *cl);
+extern int scols_column_is_hidden(struct libscols_column *cl);
 extern int scols_column_is_noextremes(struct libscols_column *cl);
 
 extern int scols_column_set_flags(struct libscols_column *cl, int flags);
index 8f371a7d583dcc47bf154582ea3bb06515fa9c50..163417707e54d59a2dcf33c1c4a3512f3e6fff90 100644 (file)
@@ -89,8 +89,6 @@ struct libscols_column {
 
        struct libscols_cell    header;
        struct list_head        cl_columns;
-
-       unsigned int ignore : 1;
 };
 
 /*
index d275ad640e328c8726bb8161cc43c1c3009e2061..caae98c1423f7fd85bd382ab52a3376d0963a116 100644 (file)
@@ -185,7 +185,7 @@ static int is_last_column(struct libscols_table *tb, struct libscols_column *cl)
                return 1;
 
        next = list_entry(cl->cl_columns.next, struct libscols_column, cl_columns);
-       if (next && next->ignore)
+       if (next && scols_column_is_hidden(next))
                return 1;
        return 0;
 }
@@ -532,7 +532,7 @@ static int print_line(struct libscols_table *tb,
 
        scols_reset_iter(&itr, SCOLS_ITER_FORWARD);
        while (rc == 0 && scols_table_next_column(tb, &itr, &cl) == 0) {
-               if (cl->ignore)
+               if (scols_column_is_hidden(cl))
                        continue;
                rc = cell_to_buffer(tb, ln, cl, buf);
                if (!rc)
@@ -563,7 +563,7 @@ static int print_header(struct libscols_table *tb, struct libscols_buffer *buf)
        /* set the width according to the size of the data */
        scols_reset_iter(&itr, SCOLS_ITER_FORWARD);
        while (rc == 0 && scols_table_next_column(tb, &itr, &cl) == 0) {
-               if (cl->ignore)
+               if (scols_column_is_hidden(cl))
                        continue;
                rc = buffer_set_data(buf, scols_cell_get_data(&cl->header));
                if (!rc)
@@ -660,7 +660,7 @@ static int print_tree(struct libscols_table *tb, struct libscols_buffer *buf)
 
 static void dbg_column(struct libscols_table *tb, struct libscols_column *cl)
 {
-       if (cl->ignore) {
+       if (scols_column_is_hidden(cl)) {
                DBG(COL, ul_debugobj(cl, "%s ignored", cl->header.data));
                return;
        }
@@ -949,7 +949,7 @@ static int recount_widths(struct libscols_table *tb, struct libscols_buffer *buf
                                cl->width -= r;
                                width -= r;
                        } else {
-                               cl->ignore = 1;
+                               cl->flags |= SCOLS_FL_HIDDEN;
                                width -= cl->width + 1;         /* +1 means separator between columns */
                        }
                }