Skip to content

Commit

Permalink
(mcview_bol): refactor, fix coding style.
Browse files Browse the repository at this point in the history
Signed-off-by: Andrew Borodin <[email protected]>
  • Loading branch information
aborodin committed Dec 15, 2024
1 parent 053108a commit b5610b2
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions src/viewer/lib.c
Original file line number Diff line number Diff line change
Expand Up @@ -314,29 +314,35 @@ off_t
mcview_bol (WView *view, off_t current, off_t limit)
{
int c;
off_t filesize;
filesize = mcview_get_filesize (view);

if (current <= 0)
return 0;

const off_t filesize = mcview_get_filesize (view);

if (current > filesize)
return filesize;

if (!mcview_get_byte (view, current, &c))
return current;

if (c == '\n')
{
if (!mcview_get_byte (view, current - 1, &c))
return current;

if (c == '\r')
current--;
}
while (current > 0 && current > limit)

for (; current > 0 && current > limit; current--)
{
if (!mcview_get_byte (view, current - 1, &c))
break;
if (c == '\r' || c == '\n')
break;
current--;
}

return current;
}

Expand Down

0 comments on commit b5610b2

Please sign in to comment.