9fans / plan9port

Plan 9 from User Space
https://9fans.github.io/plan9port/
Other
1.62k stars 320 forks source link

Avoid page(1) to terminates when the end of the document is reached #534

Open LoupLobet opened 2 years ago

LoupLobet commented 2 years ago

First of all, this issue was noticed on the OpenBSD package of plan9port, I don't know if this remains an issue in the current plan9port version, or if the issue is related to OpenBSD as a system.

When you reach the end of a document, or viewing a simple image with page(1), if you try to go the next (non existant) page, the program terminates (that's not something that happen on a real plan9 install).

I kind of fixed the problem with these changes on view.c:

437,438c437,439
<               if(!doc->npage || page + 1 < doc->npage || doc->fwdonly)
<                   showpage(++page, &menu);
---
>               if(doc->npage && ++page >= doc->npage && !doc->fwdonly)
>                   wexits(0);
>               showpage(page, &menu);
520c521
<                       if(reverse) page++;
---
>                       if(reverse) return;
525c526
<                       page--;
---
>                       return;
536c537
<                       if(reverse) page++;
---
>                       if(reverse) return;
540,541c541,542
<                   if((page >= doc->npage) && !doc->fwdonly)
<                       page--;
---
>                   if((page >= doc->npage) && !doc->fwdonly && !reverse)
>                       return;