This is now possible due to the previous changes
as default mode subtracts one column, and
-c subtracts one character, and every character counts as one,
so there is no need to track the last_character_width
(which is problematic anyway in the presence of
multiple backspaces).

* src/old.c (adjust_column): Just use the locally deterined width.
---
 src/fold.c | 25 ++++++-------------------
 1 file changed, 6 insertions(+), 19 deletions(-)

diff --git a/src/fold.c b/src/fold.c
index 154353d8c..1ce2700dc 100644
--- a/src/fold.c
+++ b/src/fold.c
@@ -50,9 +50,6 @@ static enum
 /* If nonzero, at least one of the files we read was standard input. */
 static bool have_read_stdin;
 
-/* Width of last read character.  */
-static int last_character_width = 0;
-
 static char const shortopts[] = "bcsw:0::1::2::3::4::5::6::7::8::9::";
 
 static struct option const longopts[] =
@@ -117,27 +114,17 @@ adjust_column (size_t column, mcel_t g)
   if (counting_mode != COUNT_BYTES)
     {
       if (g.ch == '\b')
-        column -= MIN (counting_mode == COUNT_CHARACTERS
-                       ? last_character_width : 1, column);
+        column -= !!column;
       else if (g.ch == '\r')
         column = 0;
       else if (g.ch == '\t')
-        {
-          /* A backspace after a tab moves back one column.  */
-          last_character_width = 1;
-          column += TAB_WIDTH - column % TAB_WIDTH;
-        }
+        column += TAB_WIDTH - column % TAB_WIDTH;
       else
         {
-          if (counting_mode == COUNT_CHARACTERS)
-            last_character_width = 1;
-          else
-            {
-              int width = c32width (g.ch);
-              /* Default to a width of 1 if there is an invalid character.  */
-              last_character_width = width < 0 ? 1 : width;
-            }
-          column += last_character_width;
+          int width = (counting_mode == COUNT_CHARACTERS
+                       ? 1 : c32width (g.ch));
+          /* Default to a width of 1 if there is an invalid character.  */
+          column += width < 0 ? 1 : width;
         }
     }
   else
-- 
2.55.0


Reply via email to