From cd634e074cd01d88341edba3e39279ca75856455 Mon Sep 17 00:00:00 2001 From: Benno Schulenberg Date: Mon, 14 Apr 2014 13:02:43 +0000 Subject: [PATCH] Initializing a variable to avoid a compiler warning, renaming it, adding and tweaking some comments, and removing an unneeded 'if'. git-svn-id: svn://svn.savannah.gnu.org/nano/trunk/nano@4771 35c25a1d-7b9e-4130-9fde-d3aeb78583b8 --- ChangeLog | 3 +++ src/text.c | 39 ++++++++++++++++++++------------------- 2 files changed, 23 insertions(+), 19 deletions(-) diff --git a/ChangeLog b/ChangeLog index e1fca29a..dd0eae79 100644 --- a/ChangeLog +++ b/ChangeLog @@ -5,6 +5,9 @@ and subsequently from parse_browser_input() and parse_help_input(). * src/*: Whitespace adjustments, plus a few comment tweaks. * src/winio.c (getfuncfromkey): Elide variable and condense comment. + * src/text.c (break_line): Initialize a variable to avoid a compiler + warning, rename it to be more apt, add a comment, tweak some others, + and remove an unneeded 'if'. 2014-04-13 Benno Schulenberg * proto.h, global.c, rcfile.c: Remove the unused parameter 'menu' diff --git a/src/text.c b/src/text.c index b24530ec..ac53b0a0 100644 --- a/src/text.c +++ b/src/text.c @@ -1350,7 +1350,7 @@ bool do_wrap(filestruct *line, bool undoing) * 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 newline is TRUE. */ + * blank, as does a '\n' if newln is TRUE. */ ssize_t break_line(const char *line, ssize_t goal #ifndef DISABLE_HELP , bool newln @@ -1364,12 +1364,13 @@ ssize_t break_line(const char *line, ssize_t goal /* Current index in line. */ size_t cur_pos = 0; /* Current column position in line. */ - int line_len; + int char_len = 0; + /* Length of current character, in bytes. */ assert(line != NULL); while (*line != '\0' && goal >= cur_pos) { - line_len = parse_mbchar(line, NULL, &cur_pos); + char_len = parse_mbchar(line, NULL, &cur_pos); if (is_blank_mbchar(line) #ifndef DISABLE_HELP @@ -1384,8 +1385,8 @@ ssize_t break_line(const char *line, ssize_t goal #endif } - line += line_len; - cur_loc += line_len; + line += char_len; + cur_loc += char_len; } if (goal >= cur_pos) @@ -1394,34 +1395,34 @@ ssize_t break_line(const char *line, ssize_t goal #ifndef DISABLE_HELP if (newln && blank_loc <= 0) { - /* If blank was not found or was found only first character, - * force line break. */ - cur_loc -= line_len; + /* 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 if (blank_loc == -1) { - /* No blank was found that was short enough. */ + /* 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') { - line_len = parse_mbchar(line, NULL, NULL); + char_len = parse_mbchar(line, NULL, NULL); if (is_blank_mbchar(line) #ifndef DISABLE_HELP || (newln && *line == '\n') #endif ) { - if (!found_blank) - found_blank = TRUE; + found_blank = TRUE; found_blank_loc = cur_loc; } else if (found_blank) return found_blank_loc; - line += line_len; - cur_loc += line_len; + line += char_len; + cur_loc += char_len; } return -1; @@ -1430,8 +1431,8 @@ ssize_t break_line(const char *line, ssize_t goal /* Move to the last blank after blank_loc, if there is one. */ line -= cur_loc; line += blank_loc; - line_len = parse_mbchar(line, NULL, NULL); - line += line_len; + char_len = parse_mbchar(line, NULL, NULL); + line += char_len; while (*line != '\0' && (is_blank_mbchar(line) #ifndef DISABLE_HELP @@ -1443,10 +1444,10 @@ ssize_t break_line(const char *line, ssize_t goal break; #endif - line_len = parse_mbchar(line, NULL, NULL); + char_len = parse_mbchar(line, NULL, NULL); - line += line_len; - blank_loc += line_len; + line += char_len; + blank_loc += char_len; } return blank_loc; -- 2.39.5