From: Karel Zak Date: Wed, 22 Nov 2017 13:43:36 +0000 (+0100) Subject: column: use \x for invalid multibyte seq. X-Git-Tag: v2.32-rc1~185 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=dda229c7b2b16a31fae8e99079ab4f4ae5bc8eac;p=thirdparty%2Futil-linux.git column: use \x for invalid multibyte seq. Addresses: https://github.com/karelzak/util-linux/issues/542 Signed-off-by: Karel Zak --- diff --git a/text-utils/column.1 b/text-utils/column.1 index 2bc47edde2..b22468049d 100644 --- a/text-utils/column.1 +++ b/text-utils/column.1 @@ -54,7 +54,7 @@ mode is enabled by option \fB-t, \-\-table\fP and columns formatting is possible to modify by \fB\-\-table-*\fP options. Use this mode if not sure. .PP Input is taken from \fIfile\fR, or otherwise from standard input. Empty lines -are ignored. +are ignored and all invalid multibyte sequences are encoded by \\x convention. .PP .SH OPTIONS The argument \fIcolumns\fP for \fB\-\-table-*\fP options is comma separated diff --git a/text-utils/column.c b/text-utils/column.c index ad6c2b20e2..1484d783d5 100644 --- a/text-utils/column.c +++ b/text-utils/column.c @@ -52,6 +52,7 @@ #include "ttyutils.h" #include "strv.h" #include "optutils.h" +#include "mbsalign.h" #include "libsmartcols.h" @@ -485,8 +486,18 @@ static int read_input(struct column_control *ctl, FILE *fp) continue; wcs = mbs_to_wcs(str); - if (!wcs) - err(EXIT_FAILURE, _("read failed")); + if (!wcs) { + /* + * Convert broken sequences to \x and continue. + */ + size_t tmpsz = 0; + char *tmp = mbs_invalid_encode(str, &tmpsz); + + if (!tmp) + err(EXIT_FAILURE, _("read failed")); + wcs = mbs_to_wcs(tmp); + free(tmp); + } switch (ctl->mode) { case COLUMN_MODE_TABLE: @@ -618,6 +629,7 @@ static void __attribute__((__noreturn__)) usage(void) fputs(_(" -s, --separator possible table delimiters\n"), out); fputs(_(" -x, --fillrows fill rows before columns\n"), out); + fputs(USAGE_SEPARATOR, out); printf(USAGE_HELP_OPTIONS(34)); printf(USAGE_MAN_TAIL("column(1)"));