]> err.no Git - util-linux/commitdiff
col: getwchar() errors shouldn't be hidden
authorKarel Zak <kzak@redhat.com>
Tue, 30 Jan 2007 12:18:51 +0000 (13:18 +0100)
committerKarel Zak <kzak@redhat.com>
Tue, 30 Jan 2007 12:52:48 +0000 (13:52 +0100)
The col truncates output when multibyte errors is detected, but the problem is
not reported to stderr and return code is still same like for successful exit.
This stupid behaviour is fixed by this patch.

Signed-off-by: Karel Zak <kzak@redhat.com>
tests/commands.sh.in
tests/expected/ts-col-multibyte [new file with mode: 0644]
tests/functions.sh
tests/input/ts-col-multibyte [new file with mode: 0644]
tests/ts-col-multibyte [new file with mode: 0755]
text-utils/col.c

index 4345a28f5f59d960b54f36c2fa72ff2dbf2843e2..92deda21d6eaf624d0108f457e82f5b1a33eacc1 100644 (file)
@@ -11,3 +11,5 @@ TS_CMD_SWAPON=${TS_CMD_MOUNT:-"$TOPDIR/mount/swapon"}
 TS_CMD_SWAPOFF=${TS_CMD_MOUNT:-"$TOPDIR/mount/swapoff"}
 
 TS_CMD_IPCS=${TS_CMD_IPCS:-"$TOPDIR/sys-utils/ipcs"}
+
+TS_CMD_COL=${TS_CMD_COL:-"$TOPDIR/text-utils/col"}
diff --git a/tests/expected/ts-col-multibyte b/tests/expected/ts-col-multibyte
new file mode 100644 (file)
index 0000000..c6d36cc
--- /dev/null
@@ -0,0 +1 @@
+col: Invalid or incomplete multibyte or wide character
index 81168fc32c074cf4d7e1d4844e4b1a330ba996fb..8e8b34f74036a11f4555d706fa070bf84a9c75cb 100644 (file)
@@ -2,6 +2,7 @@
 TS_OUTDIR="$TS_TOPDIR/output"
 TS_DIFFDIR="$TS_TOPDIR/diff"
 TS_EXPECTEDDIR="$TS_TOPDIR/expected"
+TS_INPUTDIR="$TS_TOPDIR/input"
 
 function ts_skip {
        echo " IGNORE ($1)"
@@ -9,6 +10,7 @@ function ts_skip {
 }
 
 function ts_init {
+       export LANG="en_US.UTF-8":
        TS_NAME=$(basename $0)
        if [ ! -d $TS_OUTDIR ]; then
                mkdir -p $TS_OUTDIR
@@ -19,6 +21,7 @@ function ts_init {
        TS_OUTPUT="$TS_OUTDIR/$TS_NAME"
        TS_DIFF="$TS_DIFFDIR/$TS_NAME"
        TS_EXPECTED="$TS_EXPECTEDDIR/$TS_NAME"
+       TS_INPUT="$TS_INPUTDIR/$TS_NAME"
 
        rm -f $TS_OUTPUT
 
@@ -35,7 +38,7 @@ function ts_finalize {
                                res=1
                        fi
                else
-                       res=0
+                       res=1
                fi
        else
                echo " IGNORE (expected output undefined)"
diff --git a/tests/input/ts-col-multibyte b/tests/input/ts-col-multibyte
new file mode 100644 (file)
index 0000000..b203afd
--- /dev/null
@@ -0,0 +1 @@
+Dateiname der Versandhülle
diff --git a/tests/ts-col-multibyte b/tests/ts-col-multibyte
new file mode 100755 (executable)
index 0000000..125e396
--- /dev/null
@@ -0,0 +1,17 @@
+#!/bin/bash
+
+. commands.sh
+. functions.sh
+
+TS_COMPONENT="col"
+TS_DESC="multibyte"
+
+ts_init
+
+cat $TS_INPUT | $TS_CMD_COL > /dev/null  2> $TS_OUTPUT
+
+
+
+
+ts_finalize
+
index 052d91e7aba72326e6fe563285843d917a30287d..3b81a891ae9b010377286a19238e10126f11f070 100644 (file)
@@ -128,6 +128,7 @@ int main(int argc, char **argv)
        int this_line;                  /* line l points to */
        int nflushd_lines;              /* number of lines that were flushed */
        int adjust, opt, warned;
+       int ret = 0;
 
        setlocale(LC_ALL, "");
        bindtextdomain(PACKAGE, LOCALEDIR);
@@ -175,8 +176,16 @@ int main(int argc, char **argv)
        cur_line = max_line = nflushd_lines = this_line = 0;
        cur_set = last_set = CS_NORMAL;
        lines = l = alloc_line();
-
-       while ((ch = getwchar()) != WEOF) {
+       
+       while (feof(stdin)==0) {
+               errno = 0;
+               if ((ch = getwchar()) == WEOF) {
+                       if (errno==EILSEQ) {
+                               perror("col");
+                               ret = 1;
+                       }
+                       break;
+               }       
                if (!iswgraph(ch)) {
                        switch (ch) {
                        case BS:                /* can't go back further */
@@ -332,7 +341,7 @@ int main(int argc, char **argv)
        flush_blanks();
        if (ferror(stdout) || fclose(stdout))
                return 1;
-       return 0;
+       return ret;
 }
 
 void flush_lines(int nflush)