ed: Use the variable LINES for z

Some shells keep a variable LINES with the number of lines of the terminal
updated in every SIGWINCH. Using that variable makes easier to get a
full listing.
This commit is contained in:
Roberto E. Vargas Caballero 2025-12-31 12:38:39 +01:00
parent 60d9f7a5a9
commit 4bc4a1d030
2 changed files with 12 additions and 4 deletions

7
ed.1
View File

@ -1,4 +1,4 @@
.Dd December 27, 2025
.Dd December 31, 2025
.Dt ED 1
.Os sbase
.Sh NAME
@ -233,7 +233,10 @@ lines starting at the addressed line.
If
.Ar n
is not specified then
it is defaulted to 24.
the value of $LINES - 1 is used.
If the value of
.Ar n
is 0 or negative then the default value of 23 is used.
.It ($)=
Print the line number of the addressed line.
The dot is unchanged.

9
ed.c
View File

@ -1270,6 +1270,7 @@ subst(int nth)
static void
docmd(void)
{
char *var;
int cmd, c, line3, num, trunc;
repeat:
@ -1406,10 +1407,14 @@ repeat:
case 'z':
if (nlines > 1)
goto bad_address;
num = 0;
if (isdigit(back(input())))
num = getnum();
else
num = 24;
else if ((var = getenv("LINES")) != NULL)
num = atoi(var) - 1;
if (num <= 0)
num = 23;
chkprint(1);
deflines(curln, curln);
scroll(num);