]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
libsmartcols: clean up flags usage
authorKarel Zak <kzak@redhat.com>
Thu, 3 Apr 2014 14:09:57 +0000 (16:09 +0200)
committerKarel Zak <kzak@redhat.com>
Thu, 3 Apr 2014 14:09:57 +0000 (16:09 +0200)
 * rename flags functions to scols_table_enable_*
 * rename *_no_foo() functions to _nofoo()
 * output formats are mutually exclusive, so don't use flags there
 * don't assume symbols in scols_new_table(), use scols_table_set_symbols()

Signed-off-by: Karel Zak <kzak@redhat.com>
18 files changed:
disk-utils/cfdisk.c
disk-utils/partx.c
libfdisk/src/table.c
libsmartcols/docs/libsmartcols-sections.txt
libsmartcols/src/column.c
libsmartcols/src/libsmartcols.h.in
libsmartcols/src/libsmartcols.sym
libsmartcols/src/smartcolsP.h
libsmartcols/src/table.c
libsmartcols/src/table_print.c
misc-utils/findmnt.c
misc-utils/lsblk.c
misc-utils/lslocks.c
sys-utils/losetup.c
sys-utils/lscpu.c
sys-utils/prlimit.c
sys-utils/swapon.c
sys-utils/wdctl.c

index 624d7991d18e55b8cf27d30bccf8de834955440a..9d198e25ec14d870c5b6ac0b2253d7db1cff5da7 100644 (file)
@@ -219,11 +219,10 @@ static char *table_to_string(struct cfdisk *cf, struct fdisk_table *tb)
                }
        }
 
-       table = scols_new_table(NULL);
+       table = scols_new_table();
        if (!table)
                goto done;
-       scols_table_set_max(table, 1);
-       scols_table_set_tree(table, tree);
+       scols_table_enable_maxout(table, 1);
 
        /* headers */
        for (i = 0; i < cf->ncols; i++) {
index 036e4cd3dcfa67730d33d13f47660f843437aa18..830af1f321653d2671f78b9725238560503f3613 100644 (file)
@@ -626,14 +626,14 @@ static int show_parts(blkid_partlist ls, int scols_flags, int lower, int upper)
        if (!nparts)
                return 0;
 
-       table = scols_new_table(NULL);
+       table = scols_new_table();
        if (!table) {
                warn(_("failed to initialize output table"));
                return -1;
        }
-       scols_table_set_raw(table, !!(scols_flags & PARTX_RAW));
-       scols_table_set_export(table, !!(scols_flags & PARTX_EXPORT));
-       scols_table_set_no_headings(table, !!(scols_flags & PARTX_NOHEADINGS));
+       scols_table_enable_raw(table, !!(scols_flags & PARTX_RAW));
+       scols_table_enable_export(table, !!(scols_flags & PARTX_EXPORT));
+       scols_table_enable_noheadings(table, !!(scols_flags & PARTX_NOHEADINGS));
 
        for (i = 0; i < ncolumns; i++) {
                struct colinfo *col = get_column_info(i);
index 59f6ab430f4b08cabead41c05c2c0fc1373e30d5..add6bd983d601de0da899840cb27bac0c6246e15 100644 (file)
@@ -566,7 +566,7 @@ int fdisk_table_to_string(struct fdisk_table *tb,
                        return rc;
        }
 
-       table = scols_new_table(NULL);
+       table = scols_new_table();
        if (!table) {
                rc = -ENOMEM;
                goto done;
index 85a9feb1498c11d93991b33aa0f15aa9634b2f04..dc2203702b8f44675edf61721fc35e588685cd59 100644 (file)
@@ -17,7 +17,7 @@ scols_column_get_color
 scols_column_get_flags
 scols_column_get_header
 scols_column_get_whint
-scols_column_is_no_extremes
+scols_column_is_noextremes
 scols_column_is_right
 scols_column_is_strict_width
 scols_column_is_tree
@@ -86,6 +86,10 @@ scols_table_add_column
 scols_table_add_line
 scols_table_colors_wanted
 scols_table_enable_colors
+scols_table_enable_export
+scols_table_enable_maxout
+scols_table_enable_noheadings
+scols_table_enable_raw
 scols_table_get_column
 scols_table_get_line
 scols_table_get_ncols
@@ -94,8 +98,8 @@ scols_table_get_stream
 scols_table_is_ascii
 scols_table_is_empty
 scols_table_is_export
-scols_table_is_max
-scols_table_is_no_headings
+scols_table_is_maxout
+scols_table_is_noheadings
 scols_table_is_raw
 scols_table_is_tree
 scols_table_new_column
@@ -108,13 +112,8 @@ scols_table_remove_columns
 scols_table_remove_line
 scols_table_remove_lines
 scols_table_set_ascii
-scols_table_set_export
-scols_table_set_max
-scols_table_set_no_headings
-scols_table_set_raw
 scols_table_set_stream
 scols_table_set_symbols
-scols_table_set_tree
 scols_unref_table
 </SECTION>
 
index b01119d28655063478dcff6dba47ae33ae7dd077..91e3655cb92edf33a224b5414c2fa1ce1ebec8b5 100644 (file)
@@ -299,14 +299,14 @@ int scols_column_is_strict_width(struct libscols_column *cl)
        return cl->flags & SCOLS_FL_STRICTWIDTH;
 }
 /**
- * scols_column_is_no_extremes:
+ * scols_column_is_noextremes:
  * @cl: a pointer to a struct libscols_column instance
  *
  * Gets the value of @cl's flag no_extremes.
  *
  * Returns: no_extremes flag value, negative value in case of an error.
  */
-int scols_column_is_no_extremes(struct libscols_column *cl)
+int scols_column_is_noextremes(struct libscols_column *cl)
 {
        assert(cl);
        if (!cl)
index b77b11e37692c9b6c06c2097fa787beb88462f3b..98d3e4c28dc5f9a41c8a5181dd04c47292d1940d 100644 (file)
@@ -109,7 +109,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_no_extremes(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);
 extern int scols_column_get_flags(struct libscols_column *cl);
@@ -149,24 +149,23 @@ extern struct libscols_line *scols_copy_line(struct libscols_line *ln);
 extern int scols_table_colors_wanted(struct libscols_table *tb);
 extern int scols_table_is_raw(struct libscols_table *tb);
 extern int scols_table_is_ascii(struct libscols_table *tb);
-extern int scols_table_is_no_headings(struct libscols_table *tb);
+extern int scols_table_is_noheadings(struct libscols_table *tb);
 extern int scols_table_is_empty(struct libscols_table *tb);
 extern int scols_table_is_export(struct libscols_table *tb);
-extern int scols_table_is_max(struct libscols_table *tb);
+extern int scols_table_is_maxout(struct libscols_table *tb);
 extern int scols_table_is_tree(struct libscols_table *tb);
 
 extern int scols_table_enable_colors(struct libscols_table *tb, int enable);
-extern int scols_table_set_raw(struct libscols_table *tb, int enable);
-extern int scols_table_set_ascii(struct libscols_table *tb, int enable);
-extern int scols_table_set_no_headings(struct libscols_table *tb, int enable);
-extern int scols_table_set_export(struct libscols_table *tb, int enable);
-extern int scols_table_set_max(struct libscols_table *tb, int enable);
-extern int scols_table_set_tree(struct libscols_table *tb, int enable);
-
-extern struct libscols_table *scols_new_table(struct libscols_symbols *syms);
+extern int scols_table_enable_raw(struct libscols_table *tb, int enable);
+extern int scols_table_enable_ascii(struct libscols_table *tb, int enable);
+extern int scols_table_enable_noheadings(struct libscols_table *tb, int enable);
+extern int scols_table_enable_export(struct libscols_table *tb, int enable);
+extern int scols_table_enable_maxout(struct libscols_table *tb, int enable);
+
+extern struct libscols_table *scols_new_table(void);
 extern void scols_ref_table(struct libscols_table *tb);
 extern void scols_unref_table(struct libscols_table *tb);
-extern int scols_table_add_column(struct libscols_table *tb, struct libscols_column *cl, int flags);
+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, int flags);
index 19c260198e10423c6d527dca683a1f34144898be..40cc12c869cd4b54e8d530efe838b3d0bcd69a71 100644 (file)
@@ -13,7 +13,7 @@ global:
        scols_column_get_flags;
        scols_column_get_header;
        scols_column_get_whint;
-       scols_column_is_no_extremes;
+       scols_column_is_noextremes;
        scols_column_is_right;
        scols_column_is_strict_width;
        scols_column_is_tree;
@@ -61,7 +61,12 @@ global:
        scols_table_add_column;
        scols_table_add_line;
        scols_table_colors_wanted;
+       scols_table_enable_ascii;
        scols_table_enable_colors;
+       scols_table_enable_export;
+       scols_table_enable_maxout;
+       scols_table_enable_noheadings;
+       scols_table_enable_raw;
        scols_table_get_column;
        scols_table_get_line;
        scols_table_get_ncols;
@@ -70,8 +75,8 @@ global:
        scols_table_is_ascii;
        scols_table_is_empty;
        scols_table_is_export;
-       scols_table_is_max;
-       scols_table_is_no_headings;
+       scols_table_is_maxout;
+       scols_table_is_noheadings;
        scols_table_is_raw;
        scols_table_is_tree;
        scols_table_new_column;
@@ -83,14 +88,8 @@ global:
        scols_table_remove_columns;
        scols_table_remove_line;
        scols_table_remove_lines;
-       scols_table_set_ascii;
-       scols_table_set_export;
-       scols_table_set_max;
-       scols_table_set_no_headings;
-       scols_table_set_raw;
        scols_table_set_stream;
        scols_table_set_symbols;
-       scols_table_set_tree;
        scols_unref_column;
        scols_unref_line;
        scols_unref_symbols;
index 585b5e196f3c16fbd4fce6a8f9c862f731469d81..431b91b8b90080cd6d539de3c611c2b4cf383cd4 100644 (file)
@@ -93,30 +93,36 @@ struct libscols_line {
        struct libscols_line    *parent;
 };
 
+enum {
+       SCOLS_FMT_HUMAN = 0,            /* default, human readable */
+       SCOLS_FMT_RAW,                  /* space separated */
+       SCOLS_FMT_EXPORT                /* COLNAME="data" ... */
+};
+
 /*
  * The table
  */
 struct libscols_table {
        int     refcount;
        size_t  ncols;          /* number of columns */
+       size_t  ntreecols;      /* number of columns with SCOLS_FL_TREE */
        size_t  nlines;         /* number of lines */
        size_t  termwidth;      /* terminal width */
        size_t  termreduce;     /* extra blank space */
-       int     is_term;        /* is a tty? */
        FILE    *out;           /* output stream */
 
        struct list_head        tb_columns;
        struct list_head        tb_lines;
        struct libscols_symbols *symbols;
 
+       int     format;         /* SCOLS_FMT_* */
+
        /* flags */
-       unsigned int    colors_wanted   :1;
-       unsigned int    raw             :1;
-       unsigned int    ascii           :1;
-       unsigned int    no_headings     :1;
-       unsigned int    export          :1;
-       unsigned int    max             :1;
-       unsigned int    tree            :1;
+       unsigned int    ascii           :1,     /* don't use unicode */
+                       colors_wanted   :1,     /* enable colors */
+                       is_term         :1,     /* isatty() */
+                       maxout          :1,     /* maximalize output */
+                       no_headings     :1;     /* don't print header */
 };
 
 #define IS_ITER_FORWARD(_i)    ((_i)->direction == SCOLS_ITER_FORWARD)
index dd26410fe7b55033f595bc3b7c545edb9948dc25..7b08bc3d6fe02676b18bfb6d4bdd1569dd39475a 100644 (file)
 
 /**
  * scols_new_table:
- * @syms: tree symbols or NULL for default
- *
- * Note that this function add a new reference to @syms.
  *
  * Returns: A newly allocated table.
  */
-struct libscols_table *scols_new_table(struct libscols_symbols *syms)
+struct libscols_table *scols_new_table(void)
 {
        struct libscols_table *tb;
 
@@ -60,13 +57,7 @@ struct libscols_table *scols_new_table(struct libscols_symbols *syms)
        INIT_LIST_HEAD(&tb->tb_lines);
        INIT_LIST_HEAD(&tb->tb_columns);
 
-       if (syms && scols_table_set_symbols(tb, syms) != 0)
-               goto err;
-
        return tb;
-err:
-       scols_unref_table(tb);
-       return NULL;
 }
 
 /**
@@ -107,7 +98,7 @@ void scols_unref_table(struct libscols_table *tb)
  *
  * Returns: 0, a negative number in case of an error.
  */
-int scols_table_add_column(struct libscols_table *tb, struct libscols_column *cl, int flags)
+int scols_table_add_column(struct libscols_table *tb, struct libscols_column *cl)
 {
        assert(tb);
        assert(cl);
@@ -115,8 +106,8 @@ int scols_table_add_column(struct libscols_table *tb, struct libscols_column *cl
        if (!tb || !cl || !list_empty(&tb->tb_lines))
                return -EINVAL;
 
-       if (flags & SCOLS_FL_TREE)
-               scols_table_set_tree(tb, 1);
+       if (cl->flags & SCOLS_FL_TREE)
+               tb->ntreecols++;
 
        list_add_tail(&cl->cl_columns, &tb->tb_columns);
        cl->seqnum = tb->ncols++;
@@ -149,6 +140,9 @@ int scols_table_remove_column(struct libscols_table *tb,
        if (!tb || !cl || !list_empty(&tb->tb_lines))
                return -EINVAL;
 
+       if (cl->flags & SCOLS_FL_TREE)
+               tb->ntreecols--;
+
        list_del_init(&cl->cl_columns);
        tb->ncols--;
        scols_unref_column(cl);
@@ -238,7 +232,7 @@ struct libscols_column *scols_table_new_column(struct libscols_table *tb,
        scols_column_set_whint(cl, whint);
        scols_column_set_flags(cl, flags);
 
-       if (scols_table_add_column(tb, cl, flags))      /* this increments column ref-counter */
+       if (scols_table_add_column(tb, cl))     /* this increments column ref-counter */
                goto err;
 
        scols_unref_column(cl);
@@ -581,17 +575,20 @@ struct libscols_table *scols_copy_table(struct libscols_table *tb)
        assert(tb);
        if (!tb)
                return NULL;
-       ret = scols_new_table(tb->symbols);
+       ret = scols_new_table();
        if (!ret)
                return NULL;
 
+       if (tb->symbols)
+               scols_table_set_symbols(ret, tb->symbols);
+
        /* columns */
        scols_reset_iter(&itr, SCOLS_ITER_FORWARD);
        while (scols_table_next_column(tb, &itr, &cl) == 0) {
                cl = scols_copy_column(cl);
                if (!cl)
                        goto err;
-               if (scols_table_add_column(ret, cl, tb->tree ? SCOLS_FL_TREE : 0))
+               if (scols_table_add_column(ret, cl))
                        goto err;
                scols_unref_column(cl);
        }
@@ -622,7 +619,12 @@ err:
 /**
  * scols_table_set_symbols:
  * @tb: table
- * @sy: symbols
+ * @sy: symbols or NULL
+ *
+ * Add a reference to @sy from the table. The symbols are used by library to
+ * draw tree output. If no symbols are specified then library checks the
+ * current environment to select ASCII or UTF8 symbols. This default behavior
+ * could be controlled by scols_table_enable_ascii().
  *
  * Returns: 0, a negative value in case of an error.
  */
@@ -665,7 +667,7 @@ int scols_table_set_symbols(struct libscols_table *tb,
  * @tb: table
  * @enable: 1 or 0
  *
- * Enable/disable colors
+ * Enable/disable colors.
  *
  * Returns: 0 on success, negative number in case of an error.
  */
@@ -678,221 +680,204 @@ int scols_table_enable_colors(struct libscols_table *tb, int enable)
        return 0;
 }
 /**
- * scols_table_set_raw:
+ * scols_table_enable_raw:
  * @tb: table
  * @enable: 1 or 0
  *
- * Enable/disable raw
+ * Enable/disable raw output format. The parsable output formats
+ * (export and raw) are mutually exclusive.
  *
  * Returns: 0 on success, negative number in case of an error.
  */
-int scols_table_set_raw(struct libscols_table *tb, int enable)
+int scols_table_enable_raw(struct libscols_table *tb, int enable)
 {
        assert(tb);
        if (!tb)
                return -EINVAL;
-       tb->raw = enable;
+
+       if (enable)
+               tb->format = SCOLS_FMT_RAW;
+       else if (tb->format == SCOLS_FMT_RAW)
+               tb->format = 0;
        return 0;
 }
+
 /**
- * scols_table_set_ascii:
+ * scols_table_enable_export:
  * @tb: table
  * @enable: 1 or 0
  *
- * Enable/disable ascii
+ * Enable/disable export output format (COLUMNAME="value" ...).
+ * The parsable output formats (export and raw) are mutually exclusive.
  *
  * Returns: 0 on success, negative number in case of an error.
  */
-int scols_table_set_ascii(struct libscols_table *tb, int enable)
+int scols_table_enable_export(struct libscols_table *tb, int enable)
 {
        assert(tb);
        if (!tb)
                return -EINVAL;
-       tb->ascii = enable;
+       if (enable)
+               tb->format = SCOLS_FMT_EXPORT;
+       else if (tb->format == SCOLS_FMT_EXPORT)
+               tb->format = 0;
        return 0;
 }
+
 /**
- * scols_table_set_no_headings:
+ * scols_table_enable_ascii:
  * @tb: table
  * @enable: 1 or 0
  *
- * Enable/disable no_headings
+ * The ASCII-only output is relevant for tree-like outputs. The library
+ * checks if the current environment is UTF8 compatible by default. This
+ * function overrides this check and force the library to use ASCII chars
+ * for the tree.
  *
- * Returns: 0 on success, negative number in case of an error.
- */
-int scols_table_set_no_headings(struct libscols_table *tb, int enable)
-{
-       assert(tb);
-       if (!tb)
-               return -EINVAL;
-       tb->no_headings = enable;
-       return 0;
-}
-/**
- * scols_table_set_export:
- * @tb: table
- * @enable: 1 or 0
- *
- * Enable/disable export
+ * If a custom libcols_symbols are specified (see scols_table_set_symbols()
+ * then ASCII flag setting is ignored.
  *
  * Returns: 0 on success, negative number in case of an error.
  */
-int scols_table_set_export(struct libscols_table *tb, int enable)
+int scols_table_enable_ascii(struct libscols_table *tb, int enable)
 {
        assert(tb);
        if (!tb)
                return -EINVAL;
-       tb->export = enable;
+       tb->ascii = enable ? 1 : 0;
        return 0;
 }
+
 /**
- * scols_table_set_max:
+ * scols_table_enable_noheadings:
  * @tb: table
  * @enable: 1 or 0
  *
- * Enable/disable max
+ * Enable/disable header line.
  *
  * Returns: 0 on success, negative number in case of an error.
  */
-int scols_table_set_max(struct libscols_table *tb, int enable)
+int scols_table_enable_noheadings(struct libscols_table *tb, int enable)
 {
        assert(tb);
        if (!tb)
                return -EINVAL;
-       tb->max = enable;
+       tb->no_headings = enable ? 1 : 0;
        return 0;
 }
 
 /**
- * scols_table_set_tree:
+ * scols_table_enable_maxout:
  * @tb: table
  * @enable: 1 or 0
  *
- * Enable/disable tree
+ * The extra space after last column is ignored by default. The output
+ * maximization use the extra space for all columns.
  *
  * Returns: 0 on success, negative number in case of an error.
  */
-int scols_table_set_tree(struct libscols_table *tb, int enable)
+int scols_table_enable_maxout(struct libscols_table *tb, int enable)
 {
        assert(tb);
        if (!tb)
                return -EINVAL;
-       tb->tree = enable;
+       tb->maxout = enable ? 1 : 0;
        return 0;
 }
+
 /**
  * scols_table_colors_wanted:
  * @tb: table
  *
- * Gets the value of the colors_wanted flag.
- *
- * Returns: colors_wanted flag value, negative value in case of an error.
+ * Returns: 1 if colors are enabled.
  */
 int scols_table_colors_wanted(struct libscols_table *tb)
 {
        assert(tb);
-       if (!tb)
-               return -EINVAL;
-       return tb->colors_wanted;
+       return tb && tb->colors_wanted;
 }
 
 /**
  * scols_table_is_empty:
  * @tb: table
  *
- * Returns: 1 if empty, 0 if not (or in case of an error).
+ * Returns: 1  if the table is empty.
  */
 int scols_table_is_empty(struct libscols_table *tb)
 {
+       assert(tb);
        return !tb || !tb->nlines;
 }
+
 /**
- * scols_table_is_raw:
+ * scols_table_is_ascii:
  * @tb: table
  *
- * Gets the value of the raw flag.
- *
- * Returns: raw flag value, negative value in case of an error.
+ * Returns: 1 if ASCII tree is enabled.
  */
-int scols_table_is_raw(struct libscols_table *tb)
+int scols_table_is_ascii(struct libscols_table *tb)
 {
        assert(tb);
-       if (!tb)
-               return -EINVAL;
-       return tb->raw;
+       return tb && tb->ascii;
 }
+
 /**
- * scols_table_is_ascii:
+ * scols_table_is_noheadings:
  * @tb: table
  *
- * Gets the value of the ascii flag.
- *
- * Returns: ascii flag value, negative value in case of an error.
+ * Returns: 1 if header output is disabled.
  */
-int scols_table_is_ascii(struct libscols_table *tb)
+int scols_table_is_noheadings(struct libscols_table *tb)
 {
        assert(tb);
-       if (!tb)
-               return -EINVAL;
-       return tb->ascii;
+       return tb && tb->no_headings;
 }
+
 /**
- * scols_table_is_no_headings:
+ * scols_table_is_export:
  * @tb: table
  *
- * Gets the value of the no_headings flag.
- *
- * Returns: no_headings flag value, negative value in case of an error.
+ * Returns: 1 if export output format is enabled.
  */
-int scols_table_is_no_headings(struct libscols_table *tb)
+int scols_table_is_export(struct libscols_table *tb)
 {
        assert(tb);
-       if (!tb)
-               return -EINVAL;
-       return tb->no_headings;
+       return tb && tb->format == SCOLS_FMT_EXPORT;
 }
+
 /**
- * scols_table_is_export:
+ * scols_table_is_raw:
  * @tb: table
  *
- * Gets the value of the export flag.
- *
- * Returns: export flag value, negative value in case of an error.
+ * Returns: 1 if raw output format is enabled.
  */
-int scols_table_is_export(struct libscols_table *tb)
+int scols_table_is_raw(struct libscols_table *tb)
 {
        assert(tb);
-       if (!tb)
-               return -EINVAL;
-       return tb->export;
+       return tb && tb->format == SCOLS_FMT_RAW;
 }
+
+
 /**
- * scols_table_is_max:
+ * scols_table_is_maxout
  * @tb: table
  *
- * Gets the value of the max flag.
- *
- * Returns: max flag value, negative value in case of an error.
+ * Returns: 1 if output maximization is enabled, negative value in case of an error.
  */
-int scols_table_is_max(struct libscols_table *tb)
+int scols_table_is_maxout(struct libscols_table *tb)
 {
        assert(tb);
-       if (!tb)
-               return -EINVAL;
-       return tb->max;
+       return tb && tb->maxout;
 }
+
 /**
  * scols_table_is_tree:
  * @tb: table
  *
- * Gets the value of the tree flag.
- *
- * Returns: tree flag value, negative value in case of an error.
+ * Returns: returns 1 tree-like output is expected.
  */
 int scols_table_is_tree(struct libscols_table *tb)
 {
        assert(tb);
-       if (!tb)
-               return -EINVAL;
-       return tb->tree;
+       return tb && tb->ntreecols > 0;
 }
index f3cdf70c7c370b20704162ba9c9f72e02546fa93..6b846d49db6ebc74c2ff30ecb2e16da1546165a8 100644 (file)
@@ -77,7 +77,7 @@ static void print_data(struct libscols_table *tb,
        }
        width = cl->width;
 
-       if (is_last_column(tb, cl) && len < width && !scols_table_is_max(tb))
+       if (is_last_column(tb, cl) && len < width && !scols_table_is_maxout(tb))
                width = len;
 
        /* truncate data */
@@ -231,7 +231,7 @@ static void print_header(struct libscols_table *tb, char *buf, size_t bufsz)
 
        assert(tb);
 
-       if (scols_table_is_no_headings(tb) ||
+       if (scols_table_is_noheadings(tb) ||
            scols_table_is_export(tb) ||
            list_empty(&tb->tb_lines))
                return;
@@ -333,7 +333,7 @@ static void count_column_width(struct libscols_table *tb,
 
                if (cl->is_extreme && len > cl->width_avg * 2)
                        continue;
-               else if (scols_column_is_no_extremes(cl)) {
+               else if (scols_column_is_noextremes(cl)) {
                        sum += len;
                        count++;
                }
@@ -436,7 +436,7 @@ static void recount_widths(struct libscols_table *tb, char *buf, size_t bufsz)
                        }
                }
 
-               if (width < tb->termwidth && scols_table_is_max(tb)) {
+               if (width < tb->termwidth && scols_table_is_maxout(tb)) {
                        /* try enlarge all columns */
                        while (width < tb->termwidth) {
                                scols_reset_iter(&itr, SCOLS_ITER_FORWARD);
@@ -556,7 +556,7 @@ int scols_print_table(struct libscols_table *tb)
        if (!tb->symbols)
                scols_table_set_symbols(tb, NULL);      /* use default */
 
-       tb->is_term = isatty(STDOUT_FILENO);
+       tb->is_term = isatty(STDOUT_FILENO) ? 1 : 0;
        tb->termwidth = tb->is_term ? get_terminal_width() : 0;
        if (tb->termwidth <= 0)
                tb->termwidth = 80;
index 238907bdb24f05a70b6ff447c93dca2f8232746d..3386061cb6a5183ba257826c4c7bfda78815db03 100644 (file)
@@ -1464,15 +1464,15 @@ int main(int argc, char *argv[])
        /*
         * initialize output formatting (libsmartcols.h)
         */
-       table = scols_new_table(NULL);
+       table = scols_new_table();
        if (!table) {
                warn(_("failed to initialize output table"));
                goto leave;
        }
-       scols_table_set_raw(table,         !!(flags & FL_RAW));
-       scols_table_set_export(table,      !!(flags & FL_EXPORT));
-       scols_table_set_ascii(table,       !!(flags & FL_ASCII));
-       scols_table_set_no_headings(table, !!(flags & FL_NOHEADINGS));
+       scols_table_enable_raw(table,        !!(flags & FL_RAW));
+       scols_table_enable_export(table,     !!(flags & FL_EXPORT));
+       scols_table_enable_ascii(table,      !!(flags & FL_ASCII));
+       scols_table_enable_noheadings(table, !!(flags & FL_NOHEADINGS));
 
        for (i = 0; i < ncolumns; i++) {
                int fl = get_column_flags(i);
index bea04af0aaaee0eb47ee1e8c7ac3d4e08877d088..2efb2ecfb6d8356888cab361f73e75d6ea20bff8 100644 (file)
@@ -1558,12 +1558,12 @@ int main(int argc, char *argv[])
        /*
         * initialize output columns
         */
-       if (!(lsblk->table = scols_new_table(NULL)))
+       if (!(lsblk->table = scols_new_table()))
                errx(EXIT_FAILURE, _("failed to initialize output table"));
-       scols_table_set_raw(lsblk->table, !!(scols_flags & LSBLK_RAW));
-       scols_table_set_export(lsblk->table, !!(scols_flags & LSBLK_EXPORT));
-       scols_table_set_ascii(lsblk->table, !!(scols_flags & LSBLK_ASCII));
-       scols_table_set_no_headings(lsblk->table, !!(scols_flags & LSBLK_NOHEADINGS));
+       scols_table_enable_raw(lsblk->table, !!(scols_flags & LSBLK_RAW));
+       scols_table_enable_export(lsblk->table, !!(scols_flags & LSBLK_EXPORT));
+       scols_table_enable_ascii(lsblk->table, !!(scols_flags & LSBLK_ASCII));
+       scols_table_enable_noheadings(lsblk->table, !!(scols_flags & LSBLK_NOHEADINGS));
 
        for (i = 0; i < ncolumns; i++) {
                struct colinfo *ci = get_column_info(i);
index 12f08b549e0bbbcc9dd5d87ff53e5ec3807760cc..1495bd4d658d74f7ff939c7fcaa52f8cb68b28df 100644 (file)
@@ -455,13 +455,13 @@ static int show_locks(struct list_head *locks)
        struct list_head *p, *pnext;
        struct libscols_table *table;
 
-       table = scols_new_table(NULL);
+       table = scols_new_table();
        if (!table) {
                warn(_("failed to initialize output table"));
                return -1;
        }
-       scols_table_set_raw(table, raw);
-       scols_table_set_no_headings(table, no_headings);
+       scols_table_enable_raw(table, raw);
+       scols_table_enable_noheadings(table, no_headings);
 
        for (i = 0; i < ncolumns; i++) {
                struct colinfo *col = get_column_info(i);
index 58d3e08a4caa897d5dd57deaa77f969ef0b4b8d4..85a15ac2fb66a4c58b57616dec883db28f8269cf 100644 (file)
@@ -298,10 +298,10 @@ static int show_table(struct loopdev_cxt *lc,
        struct libscols_line *ln;
        int i, rc = 0;
 
-       if (!(tb = scols_new_table(NULL)))
+       if (!(tb = scols_new_table()))
                err(EXIT_FAILURE, _("failed to initialize output table"));
-       scols_table_set_raw(tb, raw);
-       scols_table_set_no_headings(tb, no_headings);
+       scols_table_enable_raw(tb, raw);
+       scols_table_enable_noheadings(tb, no_headings);
 
        for (i = 0; i < ncolumns; i++) {
                struct colinfo *ci = get_column_info(i);
index 564a705b033a621352cf3f076cd5ad939b901dad..ad1a6b35271975596c7f81f5632654c04b686f02 100644 (file)
@@ -1228,7 +1228,7 @@ print_readable(struct lscpu_desc *desc, int cols[], int ncols,
        int i;
        char buf[BUFSIZ];
        const char *data;
-       struct libscols_table *table = scols_new_table(NULL);
+       struct libscols_table *table = scols_new_table();
 
        if (!table)
                 err(EXIT_FAILURE, _("failed to initialize output table"));
index 9b1b85f65be5fbefc5dc4f5d3cc43c794a54b375..d37ec651e0d3d1a0423db53e388b520115d8114f 100644 (file)
@@ -288,12 +288,12 @@ static int show_limits(struct list_head *lims)
        struct list_head *p, *pnext;
        struct libscols_table *table;
 
-       table = scols_new_table(NULL);
+       table = scols_new_table();
        if (!table)
                err(EXIT_FAILURE, _("failed to initialize output table"));
 
-       scols_table_set_raw(table, raw);
-       scols_table_set_no_headings(table, no_headings);
+       scols_table_enable_raw(table, raw);
+       scols_table_enable_noheadings(table, no_headings);
 
        for (i = 0; i < ncolumns; i++) {
                struct colinfo *col = get_column_info(i);
index a3cfbabc8f48fad5c7aca39dfbdf3a21c4c997ab..3866ee70dab2b8714c06af994ef4312aea43f44c 100644 (file)
@@ -239,12 +239,12 @@ static int show_table(int bytes)
        if (!itr)
                err(EXIT_FAILURE, _("failed to initialize libmount iterator"));
 
-       table = scols_new_table(NULL);
+       table = scols_new_table();
        if (!table)
                err(EXIT_FAILURE, _("failed to initialize output table"));
 
-       scols_table_set_raw(table, raw);
-       scols_table_set_no_headings(table, no_headings);
+       scols_table_enable_raw(table, raw);
+       scols_table_enable_noheadings(table, no_headings);
 
        for (i = 0; i < ncolumns; i++) {
                struct colinfo *col = get_column_info(i);
index 68ecf0d29520e43446329bc2367a759ec4679f18..d63a110e384ccdd6a2ff384c21d068d2301abaea 100644 (file)
@@ -251,13 +251,13 @@ static int show_flags(struct wdinfo *wd, uint32_t wanted)
        uint32_t flags;
 
        /* create output table */
-       table = scols_new_table(NULL);
+       table = scols_new_table();
        if (!table) {
                warn(_("failed to initialize output table"));
                return -1;
        }
-       scols_table_set_raw(table, raw);
-       scols_table_set_no_headings(table, no_headings);
+       scols_table_enable_raw(table, raw);
+       scols_table_enable_noheadings(table, no_headings);
 
        /* define columns */
        for (i = 0; i < (size_t) ncolumns; i++) {