From ea3e847ab9f78b2ec1e893347ea9521ed997e492 Mon Sep 17 00:00:00 2001
From: David Lawrence Ramsey <pooka109@gmail.com>
Date: Tue, 14 Feb 2017 13:53:25 -0600
Subject: [PATCH] tweaks: fix cluttering #ifdefs and comment formatting in
 break_line()

---
 src/proto.h |  6 +-----
 src/text.c  | 60 ++++++++++++++++++++++++------------------------------------
 2 files changed, 25 insertions(+), 41 deletions(-)

diff --git a/src/proto.h b/src/proto.h
index 3642ae3..140e9ac 100644
--- a/src/proto.h
+++ b/src/proto.h
@@ -611,11 +611,7 @@ void wrap_reset(void);
 bool do_wrap(filestruct *line);
 #endif
 #if !defined(DISABLE_HELP) || !defined(DISABLE_WRAPJUSTIFY)
-ssize_t break_line(const char *line, ssize_t goal
-#ifndef DISABLE_HELP
-	, bool newln
-#endif
-	);
+ssize_t break_line(const char *line, ssize_t goal, bool newln);
 #endif
 #if !defined(NANO_TINY) || !defined(DISABLE_JUSTIFY)
 size_t indent_length(const char *line);
diff --git a/src/text.c b/src/text.c
index ad6c4f6..a3f8f31 100644
--- a/src/text.c
+++ b/src/text.c
@@ -1509,11 +1509,7 @@ bool do_wrap(filestruct *line)
     line_len = strlen(line->data);
 
     /* Find the last blank where we can break the line. */
-    wrap_loc = break_line(line->data, fill
-#ifndef DISABLE_HELP
-	, FALSE
-#endif
-	);
+    wrap_loc = break_line(line->data, fill, FALSE);
 
     /* If we couldn't break the line, or we've reached the end of it, we
      * don't wrap. */
@@ -1618,76 +1614,72 @@ bool do_wrap(filestruct *line)
 #endif /* !DISABLE_WRAPPING */
 
 #if !defined(DISABLE_HELP) || !defined(DISABLE_WRAPJUSTIFY)
-/* We are trying to break a chunk off line.  We find the last blank such
- * that the display length to there is at most (goal + 1).  If there is
- * no such blank, then we find the first blank.  We then take the last
- * blank in that group of blanks.  The terminating '\0' counts as a
- * blank, as does a '\n' if newln is TRUE. */
-ssize_t break_line(const char *line, ssize_t goal
-#ifndef DISABLE_HELP
-	, bool newln
-#endif
-	)
+/* We are trying to break a chunk off line.  We find the last blank such that
+ * the display length to there is at most (goal + 1).  If there is no such
+ * blank, then we find the first blank.  We then take the last blank in that
+ * group of blanks.  The terminating '\0' counts as a blank, as does a '\n' if
+ * newln is TRUE. */
+ssize_t break_line(const char *line, ssize_t goal, bool newln)
 {
     ssize_t blank_loc = -1;
-	/* Current tentative return value.  Index of the last blank we
-	 * found with short enough display width. */
+	/* Current tentative return value.  Index of the last blank we found
+	 * with short enough display width. */
     ssize_t cur_loc = 0;
 	/* Current index in line. */
     size_t cur_pos = 0;
 	/* Current column position in line. */
     int char_len = 0;
 	/* Length of current character, in bytes. */
+    bool is_newline = FALSE;
+	/* Are we on a newline when newln is TRUE? */
 
     assert(line != NULL);
 
     while (*line != '\0' && goal >= cur_pos) {
 	char_len = parse_mbchar(line, NULL, &cur_pos);
 
-	if (is_blank_mbchar(line)
 #ifndef DISABLE_HELP
-		|| (newln && *line == '\n')
+	is_newline = (newln && *line == '\n');
 #endif
-		) {
+
+	if (is_blank_mbchar(line) || is_newline) {
 	    blank_loc = cur_loc;
 
-#ifndef DISABLE_HELP
-	    if (newln && *line == '\n')
+	    if (is_newline)
 		break;
-#endif
 	}
 
 	line += char_len;
 	cur_loc += char_len;
     }
 
+    /* If the whole line displays shorter than goal, get out. */
     if (goal >= cur_pos)
-	/* In fact, the whole line displays shorter than goal. */
 	return cur_loc;
 
 #ifndef DISABLE_HELP
+    /* If no blank was found, or was found only as the first character, force a
+     * line break. */
     if (newln && blank_loc <= 0) {
-	/* If no blank was found, or was found only as the first
-	 * character, force a line break. */
 	cur_loc -= char_len;
 	return cur_loc;
     }
 #endif
 
+    /* No blank was found within the goal width, so now try and find a blank
+     * beyond it. */
     if (blank_loc == -1) {
-	/* No blank was found within the goal width,
-	 * so now try and find a blank beyond it. */
 	bool found_blank = FALSE;
 	ssize_t found_blank_loc = 0;
 
 	while (*line != '\0') {
 	    char_len = parse_mbchar(line, NULL, NULL);
 
-	    if (is_blank_mbchar(line)
 #ifndef DISABLE_HELP
-		|| (newln && *line == '\n')
+	    is_newline = (newln && *line == '\n');
 #endif
-		) {
+
+	    if (is_blank_mbchar(line) || is_newline) {
 		found_blank = TRUE;
 		found_blank_loc = cur_loc;
 	    } else if (found_blank)
@@ -2396,11 +2388,7 @@ void do_justify(bool full_justify)
 	    /* If this line is too long, try to wrap it to the next line
 	     * to make it short enough. */
 	    break_pos = break_line(openfile->current->data + indent_len,
-		fill - strnlenpt(openfile->current->data, indent_len)
-#ifndef DISABLE_HELP
-		, FALSE
-#endif
-		);
+		fill - strnlenpt(openfile->current->data, indent_len), FALSE);
 
 	    /* We can't break the line, or don't need to, so get out. */
 	    if (break_pos == -1 || break_pos + indent_len == line_len)
-- 
2.9.0

