]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libsmartcols: revert the column flags API
authorOndrej Oprala <ooprala@redhat.com>
Mon, 24 Mar 2014 15:44:33 +0000 (16:44 +0100)
committerKarel Zak <kzak@redhat.com>
Thu, 3 Apr 2014 10:29:17 +0000 (12:29 +0200)
Signed-off-by: Ondrej Oprala <ooprala@redhat.com>
libsmartcols/src/column.c
libsmartcols/src/libsmartcols.h.in
libsmartcols/src/libsmartcols.sym
libsmartcols/src/smartcolsP.h
libsmartcols/src/table.c
libsmartcols/src/test.c

index 29eb636664253f00f3f13b010bdeaa745aacf627..8e9b11fdd2495bdb33189db8d33640ff85d79ab4 100644 (file)
@@ -66,12 +66,8 @@ struct libscols_column *scols_copy_column(const struct libscols_column *cl)
        ret->width_max  = cl->width_max;
        ret->width_avg  = cl->width_avg;
        ret->width_hint = cl->width_hint;
+       ret->flags      = cl->flags;
        ret->is_extreme = cl->is_extreme;
-       ret->trunc      = cl->trunc;
-       ret->tree       = cl->tree;
-       ret->right      = cl->right;
-       ret->strict_width       = cl->strict_width;
-       ret->no_extremes        = cl->no_extremes;
 
        return ret;
 err:
@@ -96,6 +92,23 @@ double scols_column_get_whint(struct libscols_column *cl)
        return cl ? cl->width_hint : -EINVAL;
 }
 
+int scols_column_set_flags(struct libscols_column *cl, int flags)
+{
+       assert(cl);
+
+       if (!cl)
+               return -EINVAL;
+
+       cl->flags = flags;
+       return 0;
+}
+
+int scols_column_get_flags(struct libscols_column *cl)
+{
+       assert(cl);
+       return cl ? cl->flags : -EINVAL;
+}
+
 struct libscols_cell *scols_column_get_header(struct libscols_column *cl)
 {
        assert(cl);
@@ -154,7 +167,7 @@ int scols_column_is_trunc(struct libscols_column *cl)
        assert(cl);
        if (!cl)
                return -EINVAL;
-       return cl->trunc;
+       return cl->flags & SCOLS_FL_TRUNC;
 }
 /**
  * scols_column_is_tree:
@@ -169,7 +182,7 @@ int scols_column_is_tree(struct libscols_column *cl)
        assert(cl);
        if (!cl)
                return -EINVAL;
-       return cl->tree;
+       return cl->flags & SCOLS_FL_TREE;
 }
 /**
  * scols_column_is_right:
@@ -184,7 +197,7 @@ int scols_column_is_right(struct libscols_column *cl)
        assert(cl);
        if (!cl)
                return -EINVAL;
-       return cl->right;
+       return cl->flags & SCOLS_FL_RIGHT;
 }
 /**
  * scols_column_is_strict_width:
@@ -199,7 +212,7 @@ int scols_column_is_strict_width(struct libscols_column *cl)
        assert(cl);
        if (!cl)
                return -EINVAL;
-       return cl->strict_width;
+       return cl->flags & SCOLS_FL_STRICTWIDTH;
 }
 /**
  * scols_column_is_no_extremes:
@@ -214,91 +227,5 @@ int scols_column_is_no_extremes(struct libscols_column *cl)
        assert(cl);
        if (!cl)
                return -EINVAL;
-       return cl->no_extremes;
-}
-
-/**
- * scols_column_set_trunc:
- * @cl: column
- * @enable: 1 or 0
- *
- * Enable/disable trunc
- *
- * Returns: 0 on success, negative number in case of an error.
- */
-int scols_column_set_trunc(struct libscols_column *cl, int enable)
-{
-       assert(cl);
-       if (!cl)
-               return -EINVAL;
-       cl->trunc = enable;
-       return 0;
-}
-/**
- * scols_column_set_tree:
- * @cl: column
- * @enable: 1 or 0
- *
- * Enable/disable tree
- *
- * Returns: 0 on success, negative number in case of an error.
- */
-int scols_column_set_tree(struct libscols_column *cl, int enable)
-{
-       assert(cl);
-       if (!cl)
-               return -EINVAL;
-       cl->tree = enable;
-       return 0;
-}
-/**
- * scols_column_set_right:
- * @cl: column
- * @enable: 1 or 0
- *
- * Enable/disable right
- *
- * Returns: 0 on success, negative number in case of an error.
- */
-int scols_column_set_right(struct libscols_column *cl, int enable)
-{
-       assert(cl);
-       if (!cl)
-               return -EINVAL;
-       cl->right = enable;
-       return 0;
-}
-/**
- * scols_column_set_strict_width:
- * @cl: column
- * @enable: 1 or 0
- *
- * Enable/disable strict_width
- *
- * Returns: 0 on success, negative number in case of an error.
- */
-int scols_column_set_strict_width(struct libscols_column *cl, int enable)
-{
-       assert(cl);
-       if (!cl)
-               return -EINVAL;
-       cl->strict_width = enable;
-       return 0;
-}
-/**
- * scols_column_set_no_extremes:
- * @cl: column
- * @enable: 1 or 0
- *
- * Enable/disable no_extremes
- *
- * Returns: 0 on success, negative number in case of an error.
- */
-int scols_column_set_no_extremes(struct libscols_column *cl, int enable)
-{
-       assert(cl);
-       if (!cl)
-               return -EINVAL;
-       cl->no_extremes = enable;
-       return 0;
+       return cl->flags & SCOLS_FL_NOEXTREMES;
 }
index 412c8cd09c50d75c4278389da0ffbfe6ecc24611..54a623c43080d553ba83f10d04222429ff4320f1 100644 (file)
@@ -33,6 +33,17 @@ enum {
        SCOLS_ITER_BACKWARD
 };
 
+enum {
+       /*
+        * Column flags
+        */
+       SCOLS_FL_TRUNC       = (1 << 15),   /* truncate fields data if necessary */
+       SCOLS_FL_TREE        = (1 << 16),   /* use tree "ascii art" */
+       SCOLS_FL_RIGHT       = (1 << 17),   /* align to the right */
+       SCOLS_FL_STRICTWIDTH = (1 << 18),   /* don't reduce width if column is empty */
+       SCOLS_FL_NOEXTREMES  = (1 << 19),   /* ignore extreme fields when count column width*/
+};
+
 extern struct libscols_iter *scols_new_iter(int direction);
 extern void scols_free_iter(struct libscols_iter *itr);
 extern void scols_reset_iter(struct libscols_iter *itr, int direction);
@@ -59,16 +70,13 @@ extern const char *scols_cell_get_color(const struct libscols_cell *ce);
 
 /* column.c */
 extern int scols_column_is_tree(struct libscols_column *cl);
-extern int scols_column_set_tree(struct libscols_column *cl, int enable);
 extern int scols_column_is_trunc(struct libscols_column *cl);
-extern int scols_column_set_trunc(struct libscols_column *cl, int enable);
 extern int scols_column_is_right(struct libscols_column *cl);
-extern int scols_column_set_right(struct libscols_column *cl, int enable);
 extern int scols_column_is_strict_width(struct libscols_column *cl);
-extern int scols_column_set_strict_width(struct libscols_column *cl, int enable);
 extern int scols_column_is_no_extremes(struct libscols_column *cl);
-extern int scols_column_set_no_extremes(struct libscols_column *cl, int enable);
 
+extern int scols_column_set_flags(struct libscols_column *cl, int flags);
+extern int scols_column_get_flags(struct libscols_column *cl);
 extern struct libscols_column *scols_new_column(void);
 extern void scols_ref_column(struct libscols_column *cl);
 extern void scols_unref_column(struct libscols_column *cl);
@@ -124,7 +132,7 @@ extern void scols_unref_table(struct libscols_table *tb);
 extern int scols_table_add_column(struct libscols_table *tb, struct libscols_column *cl);
 extern int scols_table_remove_column(struct libscols_table *tb, struct libscols_column *cl);
 extern int scols_table_remove_columns(struct libscols_table *tb);
-extern struct libscols_column *scols_table_new_column(struct libscols_table *tb, const char *name, double whint);
+extern struct libscols_column *scols_table_new_column(struct libscols_table *tb, const char *name, double whint, int flags);
 extern int scols_table_next_column(struct libscols_table *tb, struct libscols_iter *itr, struct libscols_column **cl);
 extern int scols_table_get_ncols(struct libscols_table *tb);
 extern int scols_table_get_nlines(struct libscols_table *tb);
index b6538a5bc810b7fc31449f8bdbb37290148249c2..90ecd771c4713fc6377c92be4a93dcb90ecd73bf 100644 (file)
@@ -10,6 +10,7 @@ global:
        scols_cell_set_color;
        scols_cell_set_data;
        scols_column_get_color;
+       scols_column_get_flags;
        scols_column_get_header;
        scols_column_get_whint;
        scols_column_is_no_extremes;
@@ -18,11 +19,7 @@ global:
        scols_column_is_tree;
        scols_column_is_trunc;
        scols_column_set_color;
-       scols_column_set_no_extremes;
-       scols_column_set_right;
-       scols_column_set_strict_width;
-       scols_column_set_tree;
-       scols_column_set_trunc;
+       scols_column_set_flags;
        scols_column_set_whint;
        scols_copy_column;
        scols_copy_line;
index be2b0cfbfb0fa11c61f09de81c1c52055279dc58..18ca22a144d4249a1a41308cc81cd01135e758e2 100644 (file)
@@ -67,17 +67,12 @@ struct libscols_column {
        size_t  width_avg;      /* average width, used to detect extreme fields */
        double  width_hint;     /* hint (N < 1 is in percent of termwidth) */
 
+       int     flags;
        int     is_extreme;
        char    *color;         /* default column color */
 
        struct libscols_cell    header;
        struct list_head        cl_columns;
-
-       unsigned int    trunc           :1; /* truncate fields data if necessary */
-       unsigned int    tree            :1; /* use tree "ascii art" */
-       unsigned int    right           :1; /* align to the right */
-       unsigned int    strict_width    :1; /* don't reduce width if column is empty */
-       unsigned int    no_extremes     :1; /* ignore extreme fields when count column width*/
 };
 
 /*
index cb48ce4cb49a80898a0e3298bce28b7e742cbfdd..bbbd5a59def23225703c47e09250df67bee88cb3 100644 (file)
@@ -159,7 +159,8 @@ int scols_table_remove_columns(struct libscols_table *tb)
  */
 struct libscols_column *scols_table_new_column(struct libscols_table *tb,
                                               const char *name,
-                                              double whint)
+                                              double whint,
+                                              int flags)
 {
        struct libscols_column *cl;
        struct libscols_cell *hr;
@@ -179,6 +180,10 @@ struct libscols_column *scols_table_new_column(struct libscols_table *tb,
                goto err;
 
        scols_column_set_whint(cl, whint);
+       scols_column_set_flags(cl, flags);
+
+       if (flags & SCOLS_FL_TREE)
+               scols_table_set_tree(tb, 1);
 
        if (scols_table_add_column(tb, cl))     /* this increments column ref-counter */
                goto err;
index 0899cea3112c6b5701c78720fa1f944c73dc66de..aee4d8855b6cb46ceb9cd8dc747f1bdc4d58273d 100644 (file)
@@ -76,23 +76,21 @@ int main(int argc, char *argv[])
        bindtextdomain(PACKAGE, LOCALEDIR);
        textdomain(PACKAGE);
 
-       cl = scols_table_new_column(tb, "NAME", 0.3);
-       scols_table_set_tree(tb, !notree);
+       cl = scols_table_new_column(tb, "NAME", 0.3, notree ? 0 : SCOLS_FL_TREE);
        scols_table_enable_colors(tb, color);
 
        if (color)
                scols_column_set_color(cl, UL_COLOR_RED);
 
-       cl = scols_table_new_column(tb, "FOO", 0.3);
-       scols_column_set_trunc(cl, 1);
+       cl = scols_table_new_column(tb, "FOO", 0.3, SCOLS_FL_TRUNC);
        if (color) {
                struct libscols_cell *h = scols_column_get_header(cl);
 
                scols_column_set_color(cl, UL_COLOR_BOLD_GREEN);
                scols_cell_set_color(h, "green"); /* a human-readable string is also legal */
        }
-       scols_table_new_column(tb, "BAR", 0.3);
-       scols_table_new_column(tb, "PATH", 0.3);
+       scols_table_new_column(tb, "BAR", 0.3, 0);
+       scols_table_new_column(tb, "PATH", 0.3, 0);
 
        for (i = 0; i < 2; i++) {
                struct libscols_line *ln = scols_table_new_line(tb, NULL);
@@ -122,6 +120,7 @@ int main(int argc, char *argv[])
                scols_line_set_data(ln, MYCOL_FOO, "a.b-foo-foo");
                scols_line_set_data(ln, MYCOL_BAR, "barBar-A.B");
                scols_line_set_data(ln, MYCOL_PATH, "/mnt/AAA/B");
+
                if (color)
                        scols_cell_set_color(scols_line_get_cell(ln, MYCOL_FOO),
                                             UL_COLOR_MAGENTA);