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