Blob Blame History Raw
From ff424639fe863cbd6963add1a79b97290c1606c6 Mon Sep 17 00:00:00 2001
From: rpm-build <rpm-build>
Date: Fri, 3 Feb 2017 12:26:53 +0100
Subject: [PATCH] fold.c: preserve new-lines in mutlibyte text

---
 src/fold.c | 49 ++++++++++++++++++++++++-------------------------
 1 file changed, 24 insertions(+), 25 deletions(-)

diff --git a/src/fold.c b/src/fold.c
index d23edd5..8c232a7 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'\b':
-                  increment = (column > 0) ? -1 : 0;
-                  break;
+            case L'\r':
+              increment = -1 * column;
+              break;
 
-                case L'\r':
-                  increment = -1 * column;
-                  break;
+            case L'\t':
+              increment = 8 - column % 8;
+              break;
 
-                case L'\t':
-                  increment = 8 - column % 8;
-                  break;
-
-                default:
-                  increment = wcwidth (wc);
-                  increment = (increment < 0) ? 0 : increment;
-                }
+            default:
+              increment = wcwidth (wc);
+              increment = (increment < 0) ? 0 : increment;
             }
         }
 
-- 
2.7.4