summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorKarel Zak2015-12-10 13:02:03 +0100
committerKarel Zak2015-12-10 13:02:03 +0100
commit6d6b6d185e7427e2b5590349edd76d019b0fe920 (patch)
treec939298915cfafd1da489166f3990213ddaccf40
parentlibmount: add comment, remove TODO item (diff)
downloadkernel-qcow2-util-linux-6d6b6d185e7427e2b5590349edd76d019b0fe920.tar.gz
kernel-qcow2-util-linux-6d6b6d185e7427e2b5590349edd76d019b0fe920.tar.xz
kernel-qcow2-util-linux-6d6b6d185e7427e2b5590349edd76d019b0fe920.zip
libsmartcols: add SCOLS_FL_HIDDEN
Export "don't print this column" functionality by public API. Signed-off-by: Karel Zak <kzak@redhat.com>
-rw-r--r--libsmartcols/docs/libsmartcols-sections.txt1
-rw-r--r--libsmartcols/src/column.c15
-rw-r--r--libsmartcols/src/libsmartcols.h.in2
-rw-r--r--libsmartcols/src/smartcolsP.h2
-rw-r--r--libsmartcols/src/table_print.c10
5 files changed, 23 insertions, 7 deletions
diff --git a/libsmartcols/docs/libsmartcols-sections.txt b/libsmartcols/docs/libsmartcols-sections.txt
index 071df3fff..30fb30225 100644
--- a/libsmartcols/docs/libsmartcols-sections.txt
+++ b/libsmartcols/docs/libsmartcols-sections.txt
@@ -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
diff --git a/libsmartcols/src/column.c b/libsmartcols/src/column.c
index c7af6347c..269ceea0c 100644
--- a/libsmartcols/src/column.c
+++ b/libsmartcols/src/column.c
@@ -259,6 +259,21 @@ int scols_column_set_cmpfunc(struct libscols_column *cl,
}
/**
+ * 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
*
diff --git a/libsmartcols/src/libsmartcols.h.in b/libsmartcols/src/libsmartcols.h.in
index 2ac166b32..381a8eb9b 100644
--- a/libsmartcols/src/libsmartcols.h.in
+++ b/libsmartcols/src/libsmartcols.h.in
@@ -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);
diff --git a/libsmartcols/src/smartcolsP.h b/libsmartcols/src/smartcolsP.h
index 8f371a7d5..163417707 100644
--- a/libsmartcols/src/smartcolsP.h
+++ b/libsmartcols/src/smartcolsP.h
@@ -89,8 +89,6 @@ struct libscols_column {
struct libscols_cell header;
struct list_head cl_columns;
-
- unsigned int ignore : 1;
};
/*
diff --git a/libsmartcols/src/table_print.c b/libsmartcols/src/table_print.c
index d275ad640..caae98c14 100644
--- a/libsmartcols/src/table_print.c
+++ b/libsmartcols/src/table_print.c
@@ -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 */
}
}