From: Karel Zak Date: Mon, 10 May 2021 08:46:51 +0000 (+0200) Subject: column: add placeholder '0' to specify all columns X-Git-Tag: v2.37-rc2~7 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=21b16433a1cf771d40b4f4fc928594405b12e740;p=thirdparty%2Futil-linux.git column: add placeholder '0' to specify all columns Fixes: https://github.com/karelzak/util-linux/issues/1306 Signed-off-by: Karel Zak --- diff --git a/text-utils/column.1.adoc b/text-utils/column.1.adoc index aebcfb9496..10c8595419 100644 --- a/text-utils/column.1.adoc +++ b/text-utils/column.1.adoc @@ -65,7 +65,7 @@ Input is taken from _file_, or otherwise from standard input. Empty lines are ig == OPTIONS -The argument _columns_ for *--table-** options is a comma separated list of the column names as defined by *--table-columns* or it's column number in order as specified by input. It's possible to mix names and numbers. +The argument _columns_ for *--table-** options is a comma separated list of the column names as defined by *--table-columns* or it's column number in order as specified by input. It's possible to mix names and numbers. The special placeholder '0' (e.g. -R0) may be used to specify all columns. *-J, --json*:: Use JSON output format to print the table, the option *--table-columns* is required and the option *--table-name* is recommended. diff --git a/text-utils/column.c b/text-utils/column.c index 134b0b6ef6..1bc90e84e3 100644 --- a/text-utils/column.c +++ b/text-utils/column.c @@ -278,13 +278,28 @@ static int column_set_flag(struct libscols_column *cl, int fl) static void apply_columnflag_from_list(struct column_control *ctl, const char *list, int flag, const char *errmsg) { - char **all = split_or_error(list, errmsg); + char **all; char **one; int unnamed = 0; + struct libscols_column *cl; - STRV_FOREACH(one, all) { - struct libscols_column *cl; + /* apply to all */ + if (list && strcmp(list, "0") == 0) { + struct libscols_iter *itr; + + itr = scols_new_iter(SCOLS_ITER_FORWARD); + if (!itr) + err_oom(); + while (scols_table_next_column(ctl->tab, itr, &cl) == 0) + column_set_flag(cl, flag); + scols_free_iter(itr); + } + + all = split_or_error(list, errmsg); + + /* apply to columns specified by name */ + STRV_FOREACH(one, all) { if (flag == SCOLS_FL_HIDDEN && strcmp(*one, "-") == 0) { unnamed = 1; continue; @@ -298,7 +313,6 @@ static void apply_columnflag_from_list(struct column_control *ctl, const char *l /* apply flag to all columns without name */ if (unnamed) { struct libscols_iter *itr; - struct libscols_column *cl; itr = scols_new_iter(SCOLS_ITER_FORWARD); if (!itr)