Blob Blame History Raw
From 493f1291993a352e47a79fa7471880289df2efc4 Mon Sep 17 00:00:00 2001
From: Kamil Dudka <kdudka@redhat.com>
Date: Fri, 3 Feb 2017 12:26:53 +0100
Subject: [PATCH] fold: preserve new-lines in mutlibyte text (#1418505)

---
 src/fold.c | 55 +++++++++++++++++++++++++++----------------------------
 1 file changed, 27 insertions(+), 28 deletions(-)

diff --git a/src/fold.c b/src/fold.c
index 51abea8..4106f24 100644
--- a/src/fold.c
+++ b/src/fold.c
@@ -342,39 +342,38 @@ fold_multibyte_text (FILE *istream, size_t width, int *saved_errno)
         }
 
 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;
       else if (operating_mode == character_mode)        /* character mode */
         increment = 1;
-      else                                                /* column mode */
+      else                                                 /* column mode */
         {
-          if (convfail)
-            increment = 1;
-          else
+          switch (wc)
             {
-              switch (wc)
-                {
-                case L'\n':
-                  fwrite (line_out, sizeof(char), offset_out, stdout);
-                  START_NEW_LINE;
-                  continue;
-                  
-                case L'\b':
-                  increment = (column > 0) ? -1 : 0;
-                  break;
-
-                case L'\r':
-                  increment = -1 * column;
-                  break;
-
-                case L'\t':
-                  increment = 8 - column % 8;
-                  break;
-
-                default:
-                  increment = wcwidth (wc);
-                  increment = (increment < 0) ? 0 : increment;
-                }
+            case L'\b':
+              increment = (column > 0) ? -1 : 0;
+              break;
+
+            case L'\r':
+              increment = -1 * column;
+              break;
+
+            case L'\t':
+              increment = 8 - column % 8;
+              break;
+
+            default:
+              increment = wcwidth (wc);
+              increment = (increment < 0) ? 0 : increment;
             }
         }
 
-- 
2.13.5