fix fold -b with UTF-8 locale

Resolves: RHEL-60295
This commit is contained in:
Lukáš Zaoral 2024-09-27 11:08:53 +02:00
parent b45402ea96
commit a18e751ab9
No known key found for this signature in database
GPG Key ID: 39157506DD67752D
2 changed files with 36 additions and 34 deletions

View File

@ -1,4 +1,4 @@
From 94cf02dfcb1be23dedf8a39af295f28ee2de6013 Mon Sep 17 00:00:00 2001 From a54e632beb3a3f1f980103deea1cf9a8bdd164ac Mon Sep 17 00:00:00 2001
From: rpm-build <rpm-build> From: rpm-build <rpm-build>
Date: Wed, 30 Aug 2023 17:19:58 +0200 Date: Wed, 30 Aug 2023 17:19:58 +0200
Subject: [PATCH] coreutils-i18n.patch Subject: [PATCH] coreutils-i18n.patch
@ -17,7 +17,7 @@ Subject: [PATCH] coreutils-i18n.patch
src/expand-common.c | 114 ++++++ src/expand-common.c | 114 ++++++
src/expand-common.h | 12 + src/expand-common.h | 12 +
src/expand.c | 90 +++- src/expand.c | 90 +++-
src/fold.c | 312 ++++++++++++-- src/fold.c | 311 ++++++++++++--
src/local.mk | 4 +- src/local.mk | 4 +-
src/pr.c | 443 ++++++++++++++++++-- src/pr.c | 443 ++++++++++++++++++--
src/sort.c | 792 +++++++++++++++++++++++++++++++++--- src/sort.c | 792 +++++++++++++++++++++++++++++++++---
@ -34,7 +34,7 @@ Subject: [PATCH] coreutils-i18n.patch
tests/sort/sort-merge.pl | 42 ++ tests/sort/sort-merge.pl | 42 ++
tests/sort/sort.pl | 40 +- tests/sort/sort.pl | 40 +-
tests/unexpand/mb.sh | 172 ++++++++ tests/unexpand/mb.sh | 172 ++++++++
30 files changed, 3605 insertions(+), 196 deletions(-) 30 files changed, 3604 insertions(+), 196 deletions(-)
create mode 100644 lib/mbchar.c create mode 100644 lib/mbchar.c
create mode 100644 lib/mbchar.h create mode 100644 lib/mbchar.h
create mode 100644 lib/mbfile.c create mode 100644 lib/mbfile.c
@ -1820,7 +1820,7 @@ index a6176a9..60b1b8e 100644
} }
diff --git a/src/fold.c b/src/fold.c diff --git a/src/fold.c b/src/fold.c
index 941ad11..cf1e747 100644 index 941ad11..bdc466d 100644
--- a/src/fold.c --- a/src/fold.c
+++ b/src/fold.c +++ b/src/fold.c
@@ -23,10 +23,32 @@ @@ -23,10 +23,32 @@
@ -1968,7 +1968,7 @@ index 941ad11..cf1e747 100644
/* Look for the last blank. */ /* Look for the last blank. */
while (logical_end) while (logical_end)
{ {
@@ -214,13 +251,225 @@ fold_file (char const *filename, size_t width) @@ -214,13 +251,224 @@ fold_file (char const *filename, size_t width)
line_out[offset_out++] = c; line_out[offset_out++] = c;
} }
@ -2066,39 +2066,38 @@ index 941ad11..cf1e747 100644
+ } + }
+ +
+rescan: +rescan:
+ if (operating_mode == byte_mode) /* byte mode */ + if (convfail)
+ increment = 1;
+ else if (wc == L'\n')
+ {
+ /* preserve newline */
+ fwrite (line_out, sizeof(char), offset_out, stdout);
+ START_NEW_LINE;
+ continue;
+ }
+ else if (operating_mode == byte_mode) /* byte mode */
+ increment = mblength; + increment = mblength;
+ else if (operating_mode == character_mode) /* character mode */ + else if (operating_mode == character_mode) /* character mode */
+ increment = 1; + increment = 1;
+ else /* column mode */ + else /* column mode */
+ { + {
+ if (convfail) + switch (wc)
+ increment = 1;
+ else
+ { + {
+ switch (wc) + case L'\b':
+ { + increment = (column > 0) ? -1 : 0;
+ case L'\n': + break;
+ fwrite (line_out, sizeof(char), offset_out, stdout);
+ START_NEW_LINE;
+ continue;
+ +
+ case L'\b': + case L'\r':
+ increment = (column > 0) ? -1 : 0; + increment = -1 * column;
+ break; + break;
+ +
+ case L'\r': + case L'\t':
+ increment = -1 * column; + increment = 8 - column % 8;
+ break; + break;
+ +
+ case L'\t': + default:
+ increment = 8 - column % 8; + increment = wcwidth (wc);
+ break; + increment = (increment < 0) ? 0 : increment;
+
+ default:
+ increment = wcwidth (wc);
+ increment = (increment < 0) ? 0 : increment;
+ }
+ } + }
+ } + }
+ +
@ -2196,7 +2195,7 @@ index 941ad11..cf1e747 100644
if (STREQ (filename, "-")) if (STREQ (filename, "-"))
clearerr (istream); clearerr (istream);
else if (fclose (istream) != 0 && !saved_errno) else if (fclose (istream) != 0 && !saved_errno)
@@ -251,7 +500,8 @@ main (int argc, char **argv) @@ -251,7 +499,8 @@ main (int argc, char **argv)
atexit (close_stdout); atexit (close_stdout);
@ -2206,7 +2205,7 @@ index 941ad11..cf1e747 100644
while ((optc = getopt_long (argc, argv, shortopts, longopts, nullptr)) != -1) while ((optc = getopt_long (argc, argv, shortopts, longopts, nullptr)) != -1)
{ {
@@ -260,7 +510,15 @@ main (int argc, char **argv) @@ -260,7 +509,15 @@ main (int argc, char **argv)
switch (optc) switch (optc)
{ {
case 'b': /* Count bytes rather than columns. */ case 'b': /* Count bytes rather than columns. */
@ -5183,5 +5182,5 @@ index 0000000..8a82d74
+LC_ALL=C unexpand in in > out || fail=1 +LC_ALL=C unexpand in in > out || fail=1
+compare exp out > /dev/null 2>&1 || fail=1 +compare exp out > /dev/null 2>&1 || fail=1
-- --
2.44.0 2.46.1

View File

@ -1,7 +1,7 @@
Summary: A set of basic GNU tools commonly used in shell scripts Summary: A set of basic GNU tools commonly used in shell scripts
Name: coreutils Name: coreutils
Version: 9.5 Version: 9.5
Release: 2%{?dist} Release: 3%{?dist}
# some used parts of gnulib are under various variants of LGPL # some used parts of gnulib are under various variants of LGPL
License: GPL-3.0-or-later AND GFDL-1.3-no-invariants-or-later AND LGPL-2.1-or-later AND LGPL-3.0-or-later License: GPL-3.0-or-later AND GFDL-1.3-no-invariants-or-later AND LGPL-2.1-or-later AND LGPL-3.0-or-later
Url: https://www.gnu.org/software/coreutils/ Url: https://www.gnu.org/software/coreutils/
@ -264,6 +264,9 @@ rm -f $RPM_BUILD_ROOT%{_infodir}/dir
%license COPYING %license COPYING
%changelog %changelog
* Fri Sep 27 2024 Lukáš Zaoral <lzaoral@redhat.com> - 9.5-3
- fix fold -b with UTF-8 locale (RHEL-60295)
* Mon Jul 15 2024 Lukáš Zaoral <lzaoral@redhat.com> - 9.5-2 * Mon Jul 15 2024 Lukáš Zaoral <lzaoral@redhat.com> - 9.5-2
- fix fold exit code for non-existent files (RHEL-46722) - fix fold exit code for non-existent files (RHEL-46722)