From 30bdadd4d58ada8cb274ada03569f2bcf8b0a724 Mon Sep 17 00:00:00 2001
From: David Lawrence Ramsey <pooka109@gmail.com>
Date: Sat, 31 Dec 2005 21:08:10 +0000
Subject: [PATCH] revert previous erroneous change, and clarify comments

git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@3252 35c25a1d-7b9e-4130-9fde-d3aeb78583b8
---
 ChangeLog  |  3 ---
 src/text.c | 22 ++++++++++++++--------
 2 files changed, 14 insertions(+), 11 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index f2931991..3fa7ae0d 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -3,9 +3,6 @@ CVS code -
 	- Miscellaneous comment fixes. (DLR)
 	- Remove unnecessary #ifdef around termios.h #include in nano.c.
 	  (DLR)
-- text.c:
-  justify_format()
-	- Remove redundant character parsing. (DLR)
 
 GNU nano 1.3.10 - 2005.12.23
 - General:
diff --git a/src/text.c b/src/text.c
index f89262d3..fa62d5e1 100644
--- a/src/text.c
+++ b/src/text.c
@@ -744,11 +744,13 @@ void justify_format(filestruct *paragraph, size_t skip)
     new_end = new_paragraph_data + skip;
 
     while (*end != '\0') {
-	int end_len = parse_mbchar(end, NULL, NULL);
+	int end_len;
 
-	/* If this character is blank, make sure that it's a space with
-	 * no blanks after it. */
+	/* If this character is blank, change it to a space if
+	 * necessary, and skip over all blanks after it. */
 	if (is_blank_mbchar(end)) {
+	    end_len = parse_mbchar(end, NULL, NULL);
+
 	    *new_end = ' ';
 	    new_end++;
 	    end += end_len;
@@ -768,10 +770,12 @@ void justify_format(filestruct *paragraph, size_t skip)
 #endif
 	    }
 	/* If this character is punctuation optionally followed by a
-	 * bracket and then followed by blanks, make sure there are no
-	 * more than two blanks after it, and make sure that the blanks
-	 * are spaces. */
+	 * bracket and then followed by blanks, change no more than two
+	 * of the blanks to spaces if necessary, and skip over all
+	 * blanks after them. */
 	} else if (mbstrchr(punct, end) != NULL) {
+	    end_len = parse_mbchar(end, NULL, NULL);
+
 	    while (end_len > 0) {
 		*new_end = *end;
 		new_end++;
@@ -821,8 +825,10 @@ void justify_format(filestruct *paragraph, size_t skip)
 #endif
 	    }
 	/* If this character is neither blank nor punctuation, leave it
-	 * alone. */
+	 * unchanged. */
 	} else {
+	    end_len = parse_mbchar(end, NULL, NULL);
+
 	    while (end_len > 0) {
 		*new_end = *end;
 		new_end++;
@@ -836,7 +842,7 @@ void justify_format(filestruct *paragraph, size_t skip)
 
     *new_end = *end;
 
-    /* Make sure that there are no spaces at the end of the line. */
+    /* If there are spaces at the end of the line, remove them. */
     while (new_end > new_paragraph_data + skip &&
 	*(new_end - 1) == ' ') {
 	new_end--;
-- 
GitLab