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