Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
cs24-19fa
git_rec_nano
Commits
99ecd33c
Commit
99ecd33c
authored
8 years ago
by
Benno Schulenberg
Browse files
Options
Download
Email Patches
Plain Diff
tweaks: elide two variables, and condense some statements
Also, remove an assert and adjust some comments.
parent
6500f769
master
feature/match-parens
refactor/readbility
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/text.c
+12
-22
src/text.c
with
12 additions
and
22 deletions
+12
-22
src/text.c
View file @
99ecd33c
...
...
@@ -1622,17 +1622,15 @@ bool do_wrap(filestruct *line)
ssize_t
break_line
(
const
char
*
line
,
ssize_t
goal
,
bool
snap_at_nl
)
{
ssize_t
blank_loc
=
-
1
;
/* Current tentative return value. Index of the last blank we
* found with short enough display width. */
/* The index of the last blank we found. */
ssize_t
cur_loc
=
0
;
/* Current index in line. */
size_t
cur_pos
=
0
;
/*
Current
column position
in line
. */
/*
The
column position
that corresponds with cur_loc
. */
int
char_len
=
0
;
/* Length of current character, in bytes. */
assert
(
line
!=
NULL
);
/* Find the last blank that does not overshoot the target column. */
while
(
*
line
!=
'\0'
&&
goal
>=
cur_pos
)
{
char_len
=
parse_mbchar
(
line
,
NULL
,
&
cur_pos
);
...
...
@@ -1654,26 +1652,20 @@ ssize_t break_line(const char *line, ssize_t goal, bool snap_at_nl)
#ifndef DISABLE_HELP
/* If we're wrapping a help text and no blank was found, or was
* found only as the first character, force a line break. */
if
(
snap_at_nl
&&
blank_loc
<
1
)
{
cur_loc
-=
char_len
;
return
cur_loc
;
}
if
(
snap_at_nl
&&
blank_loc
<
1
)
return
(
cur_loc
-
char_len
);
#endif
/* If no blank was found within the goal width, try to find a
* blank beyond it. */
if
(
blank_loc
==
-
1
)
{
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
))
{
found_blank
=
TRUE
;
found_blank_loc
=
cur_loc
;
}
else
if
(
found_blank
)
return
found_blank_loc
;
if
(
is_blank_mbchar
(
line
))
blank_loc
=
cur_loc
;
else
if
(
blank_loc
>
0
)
return
blank_loc
;
line
+=
char_len
;
cur_loc
+=
char_len
;
...
...
@@ -1682,12 +1674,10 @@ ssize_t break_line(const char *line, ssize_t goal, bool snap_at_nl)
return
-
1
;
}
/* Move to the last blank after blank_loc, if there is one. */
line
-=
cur_loc
;
line
+=
blank_loc
;
char_len
=
parse_mbchar
(
line
,
NULL
,
NULL
);
line
+=
char_len
;
line
+=
blank_loc
-
cur_loc
;
line
+=
parse_mbchar
(
line
,
NULL
,
NULL
);
/* Move to the last consecutive blank after blank_loc. */
while
(
*
line
!=
'\0'
&&
is_blank_mbchar
(
line
))
{
char_len
=
parse_mbchar
(
line
,
NULL
,
NULL
);
...
...
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment
Menu
Projects
Groups
Snippets
Help