All of lore.kernel.org
 help / color / mirror / Atom feed
* [PATCH 2/4] column: Call mbs_to_wcs("") only once
@ 2020-09-20 13:08 Lennard Hofmann
  2020-09-20 13:08 ` [PATCH 3/4] column: Deprecate --table-empty-lines in favor of --keep-empty-lines Lennard Hofmann
  2020-09-20 13:08 ` [PATCH 4/4] tests: column --keep-empty-lines in cols mode Lennard Hofmann
  0 siblings, 2 replies; 4+ messages in thread
From: Lennard Hofmann @ 2020-09-20 13:08 UTC (permalink / raw)
  To: util-linux; +Cc: Lennard Hofmann

Signed-off-by: Lennard Hofmann <lennard.hofmann@web.de>
---
This is an optional patch to improve performance slightly while only
adding three lines of code.
 text-utils/column.c | 10 +++++++---
 1 file changed, 7 insertions(+), 3 deletions(-)

diff --git a/text-utils/column.c b/text-utils/column.c
index bc7851472..d83d8d6d7 100644
--- a/text-utils/column.c
+++ b/text-utils/column.c
@@ -496,14 +496,18 @@ static void add_entry(struct column_control *ctl, size_t *maxents, wchar_t *wcs)
 	ctl->ents[ctl->nents] = wcs;
 }

-static void add_empty_entry(struct column_control *ctl, size_t *maxents)
+static void add_empty_entry(struct column_control *ctl, size_t *maxents,
+                            wchar_t *empty)
 {
-	add_entry(ctl, maxents, mbs_to_wcs(""));
+	if (empty == NULL)
+		empty = mbs_to_wcs("");
+	add_entry(ctl, maxents, empty);
 	ctl->nents++;
 }

 static int read_input(struct column_control *ctl, FILE *fp)
 {
+	wchar_t *empty = NULL;
 	char *buf = NULL;
 	size_t bufsz = 0;
 	size_t maxents = 0;
@@ -531,7 +535,7 @@ static int read_input(struct column_control *ctl, FILE *fp)
 				if (ctl->mode == COLUMN_MODE_TABLE)
 					add_emptyline_to_table(ctl);
 				else
-					add_empty_entry(ctl, &maxents);
+					add_empty_entry(ctl, &maxents, empty);
 			}
 			continue;
 		}
--
2.28.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 3/4] column: Deprecate --table-empty-lines in favor of --keep-empty-lines
  2020-09-20 13:08 [PATCH 2/4] column: Call mbs_to_wcs("") only once Lennard Hofmann
@ 2020-09-20 13:08 ` Lennard Hofmann
  2020-09-21 13:08   ` Karel Zak
  2020-09-20 13:08 ` [PATCH 4/4] tests: column --keep-empty-lines in cols mode Lennard Hofmann
  1 sibling, 1 reply; 4+ messages in thread
From: Lennard Hofmann @ 2020-09-20 13:08 UTC (permalink / raw)
  To: util-linux; +Cc: Lennard Hofmann

`--table-empty-lines` gives the false impression that the option
only applies to table mode.

Signed-off-by: Lennard Hofmann <lennard.hofmann@web.de>
---
 text-utils/column.1 | 8 +++++---
 text-utils/column.c | 9 +++++----
 2 files changed, 10 insertions(+), 7 deletions(-)

diff --git a/text-utils/column.1 b/text-utils/column.1
index 86886f3bf..d10fc7efb 100644
--- a/text-utils/column.1
+++ b/text-utils/column.1
@@ -110,9 +110,11 @@ hide all unnamed columns (see \-\-table-columns).
 Specify columns order on output.
 .IP "\fB\-n, \-\-table-name\fP \fIname\fP"
 Specify the table name used for JSON output. The default is "table".
-.IP "\fB\-L, \-\-table\-empty\-lines\fP"
-Insert empty line to the table for each empty line on input. The default
-is ignore empty lines at all.
+.IP "\fB\-L, \-\-keep\-empty\-lines\fP"
+Preserve whitespace-only lines in the input. The default is ignore empty lines
+at all. This option’s original name was \-\-table-empty-lines but is now
+deprecated because it gives the false impression that the option only applies
+to table mode.
 .IP "\fB\-r, \-\-tree\fP \fIcolumn\fP"
 Specify column to use tree-like output. Note that the circular dependencies and
 other anomalies in child and parent relation are silently ignored.
diff --git a/text-utils/column.c b/text-utils/column.c
index d83d8d6d7..bc0c1fd11 100644
--- a/text-utils/column.c
+++ b/text-utils/column.c
@@ -96,7 +96,7 @@ struct column_control {
 	unsigned int greedy :1,
 		     json :1,
 		     header_repeat :1,
-		     tab_empty_lines :1,	/* --table-empty-lines */
+		     keep_empty_lines :1,	/* --keep-empty-lines */
 		     tab_noheadings :1;
 };

@@ -531,7 +531,7 @@ static int read_input(struct column_control *ctl, FILE *fp)
 				*p = '\0';
 		}
 		if (!str || !*str) {
-			if (ctl->tab_empty_lines) {
+			if (ctl->keep_empty_lines) {
 				if (ctl->mode == COLUMN_MODE_TABLE)
 					add_emptyline_to_table(ctl);
 				else
@@ -709,6 +709,7 @@ int main(int argc, char **argv)
 		{ "fillrows",            no_argument,       NULL, 'x' },
 		{ "help",                no_argument,       NULL, 'h' },
 		{ "json",                no_argument,       NULL, 'J' },
+		{ "keep-empty-lines",    no_argument,       NULL, 'L' },
 		{ "output-separator",    required_argument, NULL, 'o' },
 		{ "output-width",        required_argument, NULL, 'c' },
 		{ "separator",           required_argument, NULL, 's' },
@@ -723,7 +724,7 @@ int main(int argc, char **argv)
 		{ "table-right",         required_argument, NULL, 'R' },
 		{ "table-truncate",      required_argument, NULL, 'T' },
 		{ "table-wrap",          required_argument, NULL, 'W' },
-		{ "table-empty-lines",   no_argument,       NULL, 'L' },
+		{ "table-empty-lines",   no_argument,       NULL, 'L' }, /* deprecated */
 		{ "table-header-repeat", no_argument,       NULL, 'e' },
 		{ "tree",                required_argument, NULL, 'r' },
 		{ "tree-id",             required_argument, NULL, 'i' },
@@ -774,7 +775,7 @@ int main(int argc, char **argv)
 			ctl.mode = COLUMN_MODE_TABLE;
 			break;
 		case 'L':
-			ctl.tab_empty_lines = 1;
+			ctl.keep_empty_lines = 1;
 			break;
 		case 'l':
 			ctl.maxncols = strtou32_or_err(optarg, _("invalid columns limit argument"));
--
2.28.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [PATCH 4/4] tests: column --keep-empty-lines in cols mode
  2020-09-20 13:08 [PATCH 2/4] column: Call mbs_to_wcs("") only once Lennard Hofmann
  2020-09-20 13:08 ` [PATCH 3/4] column: Deprecate --table-empty-lines in favor of --keep-empty-lines Lennard Hofmann
@ 2020-09-20 13:08 ` Lennard Hofmann
  1 sibling, 0 replies; 4+ messages in thread
From: Lennard Hofmann @ 2020-09-20 13:08 UTC (permalink / raw)
  To: util-linux; +Cc: Lennard Hofmann

Add intentional whitespace to the test file `onecolumn` to test that
`column` ignores it. Add empty lines to the same test file to test that
`column--keep-empty-lines` preserves them.

Signed-off-by: Lennard Hofmann <lennard.hofmann@web.de>
---
 tests/expected/column/columnate-fill-cols-keep-empty | 7 +++++++
 tests/ts/column/columnate                            | 4 ++++
 tests/ts/column/files/onecolumn                      | 5 +++++
 3 files changed, 16 insertions(+)
 create mode 100644 tests/expected/column/columnate-fill-cols-keep-empty

diff --git a/tests/expected/column/columnate-fill-cols-keep-empty b/tests/expected/column/columnate-fill-cols-keep-empty
new file mode 100644
index 000000000..8cc1fdf1f
--- /dev/null
+++ b/tests/expected/column/columnate-fill-cols-keep-empty
@@ -0,0 +1,7 @@
+			FFFFFFFFFFFFFFFFFFF
+AAAAAAAAAAAAAAAAAAAA
+BBBBBBBBBBBBBBBBBBBBB
+CCCCCCCCCCCCCCCC	XXXXXXX
+			YYYYYYYYYYY
+DDDDDDDDDDDDDDDDD	ZZZZZZZZZZZ
+EEEEEEEEEEEEE
diff --git a/tests/ts/column/columnate b/tests/ts/column/columnate
index ebeb0c44f..e80f3b00d 100755
--- a/tests/ts/column/columnate
+++ b/tests/ts/column/columnate
@@ -49,4 +49,8 @@ ts_init_subtest "fill-rows-250"
 $TS_CMD_COLUMN --fillrows -c 250 $TS_SELF/files/onecolumn >> $TS_OUTPUT 2>> $TS_ERRLOG
 ts_finalize_subtest

+ts_init_subtest "fill-cols-keep-empty"
+$TS_CMD_COLUMN --keep-empty-lines -c 60 $TS_SELF/files/onecolumn >> $TS_OUTPUT 2>> $TS_ERRLOG
+ts_finalize_subtest
+
 ts_finalize
diff --git a/tests/ts/column/files/onecolumn b/tests/ts/column/files/onecolumn
index 69ec82f5d..3e579e1d4 100644
--- a/tests/ts/column/files/onecolumn
+++ b/tests/ts/column/files/onecolumn
@@ -1,9 +1,14 @@
+
 AAAAAAAAAAAAAAAAAAAA
 BBBBBBBBBBBBBBBBBBBBB
 CCCCCCCCCCCCCCCC
+
 DDDDDDDDDDDDDDDDD
 EEEEEEEEEEEEE
 FFFFFFFFFFFFFFFFFFF
+
+
 XXXXXXX
 YYYYYYYYYYY
 ZZZZZZZZZZZ
+
--
2.28.0


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [PATCH 3/4] column: Deprecate --table-empty-lines in favor of --keep-empty-lines
  2020-09-20 13:08 ` [PATCH 3/4] column: Deprecate --table-empty-lines in favor of --keep-empty-lines Lennard Hofmann
@ 2020-09-21 13:08   ` Karel Zak
  0 siblings, 0 replies; 4+ messages in thread
From: Karel Zak @ 2020-09-21 13:08 UTC (permalink / raw)
  To: Lennard Hofmann; +Cc: util-linux

On Sun, Sep 20, 2020 at 03:08:18PM +0200, Lennard Hofmann wrote:
> +.IP "\fB\-L, \-\-keep\-empty\-lines\fP"
> +Preserve whitespace-only lines in the input. The default is ignore empty lines
> +at all. This option’s original name was \-\-table-empty-lines but is now
> +deprecated because it gives the false impression that the option only applies
> +to table mode.

Please update also usage() (--help output) where we do not need --table-empty-lines
anymore.

 Karel


-- 
 Karel Zak  <kzak@redhat.com>
 http://karelzak.blogspot.com


^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2020-09-21 13:08 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-20 13:08 [PATCH 2/4] column: Call mbs_to_wcs("") only once Lennard Hofmann
2020-09-20 13:08 ` [PATCH 3/4] column: Deprecate --table-empty-lines in favor of --keep-empty-lines Lennard Hofmann
2020-09-21 13:08   ` Karel Zak
2020-09-20 13:08 ` [PATCH 4/4] tests: column --keep-empty-lines in cols mode Lennard Hofmann

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.