tweaks: remove cluttering #ifdefs from break_line()
Also, rename a parameter to be less cryptic, and remove an entire condition because the relevant block will never be reached when getting called from the help routines: if blank_loc is negative, the function will have bailed out in the preceding if.master
parent
0378146add
commit
f95836a951
|
@ -613,11 +613,7 @@ void wrap_reset(void);
|
||||||
bool do_wrap(filestruct *line);
|
bool do_wrap(filestruct *line);
|
||||||
#endif
|
#endif
|
||||||
#if !defined(DISABLE_HELP) || !defined(DISABLE_WRAPJUSTIFY)
|
#if !defined(DISABLE_HELP) || !defined(DISABLE_WRAPJUSTIFY)
|
||||||
ssize_t break_line(const char *line, ssize_t goal
|
ssize_t break_line(const char *line, ssize_t goal, bool snap_at_nl);
|
||||||
#ifndef DISABLE_HELP
|
|
||||||
, bool newln
|
|
||||||
#endif
|
|
||||||
);
|
|
||||||
#endif
|
#endif
|
||||||
#if !defined(NANO_TINY) || !defined(DISABLE_JUSTIFY)
|
#if !defined(NANO_TINY) || !defined(DISABLE_JUSTIFY)
|
||||||
size_t indent_length(const char *line);
|
size_t indent_length(const char *line);
|
||||||
|
|
38
src/text.c
38
src/text.c
|
@ -1509,11 +1509,7 @@ bool do_wrap(filestruct *line)
|
||||||
line_len = strlen(line->data);
|
line_len = strlen(line->data);
|
||||||
|
|
||||||
/* Find the last blank where we can break the line. */
|
/* Find the last blank where we can break the line. */
|
||||||
wrap_loc = break_line(line->data, fill
|
wrap_loc = break_line(line->data, fill, FALSE);
|
||||||
#ifndef DISABLE_HELP
|
|
||||||
, FALSE
|
|
||||||
#endif
|
|
||||||
);
|
|
||||||
|
|
||||||
/* If we couldn't break the line, or we've reached the end of it, we
|
/* If we couldn't break the line, or we've reached the end of it, we
|
||||||
* don't wrap. */
|
* don't wrap. */
|
||||||
|
@ -1622,12 +1618,8 @@ bool do_wrap(filestruct *line)
|
||||||
* that the display length to there is at most (goal + 1). If there is
|
* 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
|
* 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 in that group of blanks. The terminating '\0' counts as a
|
||||||
* blank, as does a '\n' if newln is TRUE. */
|
* blank, as does a '\n' if snap_at_nl is TRUE. */
|
||||||
ssize_t break_line(const char *line, ssize_t goal
|
ssize_t break_line(const char *line, ssize_t goal, bool snap_at_nl)
|
||||||
#ifndef DISABLE_HELP
|
|
||||||
, bool newln
|
|
||||||
#endif
|
|
||||||
)
|
|
||||||
{
|
{
|
||||||
ssize_t blank_loc = -1;
|
ssize_t blank_loc = -1;
|
||||||
/* Current tentative return value. Index of the last blank we
|
/* Current tentative return value. Index of the last blank we
|
||||||
|
@ -1644,17 +1636,11 @@ ssize_t break_line(const char *line, ssize_t goal
|
||||||
while (*line != '\0' && goal >= cur_pos) {
|
while (*line != '\0' && goal >= cur_pos) {
|
||||||
char_len = parse_mbchar(line, NULL, &cur_pos);
|
char_len = parse_mbchar(line, NULL, &cur_pos);
|
||||||
|
|
||||||
if (is_blank_mbchar(line)
|
if (is_blank_mbchar(line) || (snap_at_nl && *line == '\n')) {
|
||||||
#ifndef DISABLE_HELP
|
|
||||||
|| (newln && *line == '\n')
|
|
||||||
#endif
|
|
||||||
) {
|
|
||||||
blank_loc = cur_loc;
|
blank_loc = cur_loc;
|
||||||
|
|
||||||
#ifndef DISABLE_HELP
|
if (*line == '\n')
|
||||||
if (newln && *line == '\n')
|
|
||||||
break;
|
break;
|
||||||
#endif
|
|
||||||
}
|
}
|
||||||
|
|
||||||
line += char_len;
|
line += char_len;
|
||||||
|
@ -1666,7 +1652,7 @@ ssize_t break_line(const char *line, ssize_t goal
|
||||||
return cur_loc;
|
return cur_loc;
|
||||||
|
|
||||||
#ifndef DISABLE_HELP
|
#ifndef DISABLE_HELP
|
||||||
if (newln && blank_loc <= 0) {
|
if (snap_at_nl && blank_loc < 1) {
|
||||||
/* If no blank was found, or was found only as the first
|
/* If no blank was found, or was found only as the first
|
||||||
* character, force a line break. */
|
* character, force a line break. */
|
||||||
cur_loc -= char_len;
|
cur_loc -= char_len;
|
||||||
|
@ -1683,11 +1669,7 @@ ssize_t break_line(const char *line, ssize_t goal
|
||||||
while (*line != '\0') {
|
while (*line != '\0') {
|
||||||
char_len = parse_mbchar(line, NULL, NULL);
|
char_len = parse_mbchar(line, NULL, NULL);
|
||||||
|
|
||||||
if (is_blank_mbchar(line)
|
if (is_blank_mbchar(line)) {
|
||||||
#ifndef DISABLE_HELP
|
|
||||||
|| (newln && *line == '\n')
|
|
||||||
#endif
|
|
||||||
) {
|
|
||||||
found_blank = TRUE;
|
found_blank = TRUE;
|
||||||
found_blank_loc = cur_loc;
|
found_blank_loc = cur_loc;
|
||||||
} else if (found_blank)
|
} else if (found_blank)
|
||||||
|
@ -2396,11 +2378,7 @@ void do_justify(bool full_justify)
|
||||||
/* If this line is too long, try to wrap it to the next line
|
/* If this line is too long, try to wrap it to the next line
|
||||||
* to make it short enough. */
|
* to make it short enough. */
|
||||||
break_pos = break_line(openfile->current->data + indent_len,
|
break_pos = break_line(openfile->current->data + indent_len,
|
||||||
fill - strnlenpt(openfile->current->data, indent_len)
|
fill - strnlenpt(openfile->current->data, indent_len), FALSE);
|
||||||
#ifndef DISABLE_HELP
|
|
||||||
, FALSE
|
|
||||||
#endif
|
|
||||||
);
|
|
||||||
|
|
||||||
/* We can't break the line, or don't need to, so get out. */
|
/* We can't break the line, or don't need to, so get out. */
|
||||||
if (break_pos == -1 || break_pos + indent_len == line_len)
|
if (break_pos == -1 || break_pos + indent_len == line_len)
|
||||||
|
|
Loading…
Reference in New Issue