summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--disk-utils/cfdisk.c5
-rw-r--r--disk-utils/partx.c8
-rw-r--r--libfdisk/src/table.c2
-rw-r--r--libsmartcols/docs/libsmartcols-sections.txt15
-rw-r--r--libsmartcols/src/column.c4
-rw-r--r--libsmartcols/src/libsmartcols.h.in23
-rw-r--r--libsmartcols/src/libsmartcols.sym17
-rw-r--r--libsmartcols/src/smartcolsP.h22
-rw-r--r--libsmartcols/src/table.c199
-rw-r--r--libsmartcols/src/table_print.c10
-rw-r--r--misc-utils/findmnt.c10
-rw-r--r--misc-utils/lsblk.c10
-rw-r--r--misc-utils/lslocks.c6
-rw-r--r--sys-utils/losetup.c6
-rw-r--r--sys-utils/lscpu.c2
-rw-r--r--sys-utils/prlimit.c6
-rw-r--r--sys-utils/swapon.c6
-rw-r--r--sys-utils/wdctl.c6
18 files changed, 172 insertions, 185 deletions
diff --git a/disk-utils/cfdisk.c b/disk-utils/cfdisk.c
index 624d7991d..9d198e25e 100644
--- a/disk-utils/cfdisk.c
+++ b/disk-utils/cfdisk.c
@@ -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++) {
diff --git a/disk-utils/partx.c b/disk-utils/partx.c
index 036e4cd3d..830af1f32 100644
--- a/disk-utils/partx.c
+++ b/disk-utils/partx.c
@@ -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);
diff --git a/libfdisk/src/table.c b/libfdisk/src/table.c
index 59f6ab430..add6bd983 100644
--- a/libfdisk/src/table.c
+++ b/libfdisk/src/table.c
@@ -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;
diff --git a/libsmartcols/docs/libsmartcols-sections.txt b/libsmartcols/docs/libsmartcols-sections.txt
index 85a9feb14..dc2203702 100644
--- a/libsmartcols/docs/libsmartcols-sections.txt
+++ b/libsmartcols/docs/libsmartcols-sections.txt
@@ -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>
diff --git a/libsmartcols/src/column.c b/libsmartcols/src/column.c
index b01119d28..91e3655cb 100644
--- a/libsmartcols/src/column.c
+++ b/libsmartcols/src/column.c
@@ -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)
diff --git a/libsmartcols/src/libsmartcols.h.in b/libsmartcols/src/libsmartcols.h.in
index b77b11e37..98d3e4c28 100644
--- a/libsmartcols/src/libsmartcols.h.in
+++ b/libsmartcols/src/libsmartcols.h.in
@@ -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);
diff --git a/libsmartcols/src/libsmartcols.sym b/libsmartcols/src/libsmartcols.sym
index 19c260198..40cc12c86 100644
--- a/libsmartcols/src/libsmartcols.sym
+++ b/libsmartcols/src/libsmartcols.sym
@@ -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;
diff --git a/libsmartcols/src/smartcolsP.h b/libsmartcols/src/smartcolsP.h
index 585b5e196..431b91b8b 100644
--- a/libsmartcols/src/smartcolsP.h
+++ b/libsmartcols/src/smartcolsP.h
@@ -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)
diff --git a/libsmartcols/src/table.c b/libsmartcols/src/table.c
index dd26410fe..7b08bc3d6 100644
--- a/libsmartcols/src/table.c
+++ b/libsmartcols/src/table.c
@@ -40,13 +40,10 @@
/**
* 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;
}
diff --git a/libsmartcols/src/table_print.c b/libsmartcols/src/table_print.c
index f3cdf70c7..6b846d49d 100644
--- a/libsmartcols/src/table_print.c
+++ b/libsmartcols/src/table_print.c
@@ -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;
diff --git a/misc-utils/findmnt.c b/misc-utils/findmnt.c
index 238907bdb..3386061cb 100644
--- a/misc-utils/findmnt.c
+++ b/misc-utils/findmnt.c
@@ -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);
diff --git a/misc-utils/lsblk.c b/misc-utils/lsblk.c
index bea04af0a..2efb2ecfb 100644
--- a/misc-utils/lsblk.c
+++ b/misc-utils/lsblk.c
@@ -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);
diff --git a/misc-utils/lslocks.c b/misc-utils/lslocks.c
index 12f08b549..1495bd4d6 100644
--- a/misc-utils/lslocks.c
+++ b/misc-utils/lslocks.c
@@ -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);
diff --git a/sys-utils/losetup.c b/sys-utils/losetup.c
index 58d3e08a4..85a15ac2f 100644
--- a/sys-utils/losetup.c
+++ b/sys-utils/losetup.c
@@ -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);
diff --git a/sys-utils/lscpu.c b/sys-utils/lscpu.c
index 564a705b0..ad1a6b352 100644
--- a/sys-utils/lscpu.c
+++ b/sys-utils/lscpu.c
@@ -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"));
diff --git a/sys-utils/prlimit.c b/sys-utils/prlimit.c
index 9b1b85f65..d37ec651e 100644
--- a/sys-utils/prlimit.c
+++ b/sys-utils/prlimit.c
@@ -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);
diff --git a/sys-utils/swapon.c b/sys-utils/swapon.c
index a3cfbabc8..3866ee70d 100644
--- a/sys-utils/swapon.c
+++ b/sys-utils/swapon.c
@@ -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);
diff --git a/sys-utils/wdctl.c b/sys-utils/wdctl.c
index 68ecf0d29..d63a110e3 100644
--- a/sys-utils/wdctl.c
+++ b/sys-utils/wdctl.c
@@ -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++) {