|
|
f180de |
From 493f1291993a352e47a79fa7471880289df2efc4 Mon Sep 17 00:00:00 2001
|
|
|
f180de |
From: Kamil Dudka <kdudka@redhat.com>
|
|
|
f180de |
Date: Fri, 3 Feb 2017 12:26:53 +0100
|
|
|
f180de |
Subject: [PATCH] fold: preserve new-lines in mutlibyte text (#1418505)
|
|
|
f180de |
|
|
|
f180de |
---
|
|
|
f180de |
src/fold.c | 55 +++++++++++++++++++++++++++----------------------------
|
|
|
f180de |
1 file changed, 27 insertions(+), 28 deletions(-)
|
|
|
f180de |
|
|
|
f180de |
diff --git a/src/fold.c b/src/fold.c
|
|
|
f180de |
index 51abea8..4106f24 100644
|
|
|
f180de |
--- a/src/fold.c
|
|
|
f180de |
+++ b/src/fold.c
|
|
|
f180de |
@@ -342,39 +342,38 @@ fold_multibyte_text (FILE *istream, size_t width, int *saved_errno)
|
|
|
f180de |
}
|
|
|
f180de |
|
|
|
f180de |
rescan:
|
|
|
f180de |
- if (operating_mode == byte_mode) /* byte mode */
|
|
|
f180de |
+ if (convfail)
|
|
|
f180de |
+ increment = 1;
|
|
|
f180de |
+ else if (wc == L'\n')
|
|
|
f180de |
+ {
|
|
|
f180de |
+ /* preserve newline */
|
|
|
f180de |
+ fwrite (line_out, sizeof(char), offset_out, stdout);
|
|
|
f180de |
+ START_NEW_LINE;
|
|
|
f180de |
+ continue;
|
|
|
f180de |
+ }
|
|
|
f180de |
+ else if (operating_mode == byte_mode) /* byte mode */
|
|
|
f180de |
increment = mblength;
|
|
|
f180de |
else if (operating_mode == character_mode) /* character mode */
|
|
|
f180de |
increment = 1;
|
|
|
f180de |
- else /* column mode */
|
|
|
f180de |
+ else /* column mode */
|
|
|
f180de |
{
|
|
|
f180de |
- if (convfail)
|
|
|
f180de |
- increment = 1;
|
|
|
f180de |
- else
|
|
|
f180de |
+ switch (wc)
|
|
|
f180de |
{
|
|
|
f180de |
- switch (wc)
|
|
|
f180de |
- {
|
|
|
f180de |
- case L'\n':
|
|
|
f180de |
- fwrite (line_out, sizeof(char), offset_out, stdout);
|
|
|
f180de |
- START_NEW_LINE;
|
|
|
f180de |
- continue;
|
|
|
f180de |
-
|
|
|
f180de |
- case L'\b':
|
|
|
f180de |
- increment = (column > 0) ? -1 : 0;
|
|
|
f180de |
- break;
|
|
|
f180de |
-
|
|
|
f180de |
- case L'\r':
|
|
|
f180de |
- increment = -1 * column;
|
|
|
f180de |
- break;
|
|
|
f180de |
-
|
|
|
f180de |
- case L'\t':
|
|
|
f180de |
- increment = 8 - column % 8;
|
|
|
f180de |
- break;
|
|
|
f180de |
-
|
|
|
f180de |
- default:
|
|
|
f180de |
- increment = wcwidth (wc);
|
|
|
f180de |
- increment = (increment < 0) ? 0 : increment;
|
|
|
f180de |
- }
|
|
|
f180de |
+ case L'\b':
|
|
|
f180de |
+ increment = (column > 0) ? -1 : 0;
|
|
|
f180de |
+ break;
|
|
|
f180de |
+
|
|
|
f180de |
+ case L'\r':
|
|
|
f180de |
+ increment = -1 * column;
|
|
|
f180de |
+ break;
|
|
|
f180de |
+
|
|
|
f180de |
+ case L'\t':
|
|
|
f180de |
+ increment = 8 - column % 8;
|
|
|
f180de |
+ break;
|
|
|
f180de |
+
|
|
|
f180de |
+ default:
|
|
|
f180de |
+ increment = wcwidth (wc);
|
|
|
f180de |
+ increment = (increment < 0) ? 0 : increment;
|
|
|
f180de |
}
|
|
|
f180de |
}
|
|
|
f180de |
|
|
|
f180de |
--
|
|
|
f180de |
2.13.5
|
|
|
f180de |
|