Skip to content

Commit 443e2eb

Browse files
committed
sh_winsize(): minor rethink (re: f1c8ecc, 667034f, 1dd7e01)
If astwinsize cannot obtain the terminal window size, then it is` better not to set the LINES and COLUMNS variables at all, instead of setting default values. However, do guarantee that the internal sh.rows and sh.columns variables always have usable values, falling back to 24x80 if we have no alternative.
1 parent f15e2c4 commit 443e2eb

File tree

3 files changed

+11
-6
lines changed

3 files changed

+11
-6
lines changed

src/cmd/ksh93/sh/fault.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -202,18 +202,20 @@ void sh_winsize(void)
202202
int lines, columns;
203203
int32_t i;
204204
astwinsize(2,&lines,&columns);
205-
if (lines <= 0 || lines > USHRT_MAX || columns <= 0 || columns > USHRT_MAX)
206-
lines = 24, columns = 80;
205+
if (lines < 0 || lines > USHRT_MAX)
206+
lines = 0;
207+
if (columns < 0 || columns > USHRT_MAX)
208+
columns = 0;
207209
/*
208210
* Update LINES and COLUMNS only when the values changed; this makes
209211
* LINES.set and COLUMNS.set shell discipline functions more useful.
210212
*/
211-
if ((lines != sh.lines || nv_isnull(LINES)) && (i = lines))
213+
if (lines && (lines != sh.lines || nv_isnull(LINES)) && (i = lines))
212214
{
213215
nv_putval(LINES, (char*)&i, NV_INT32|NV_RDONLY);
214216
sh.lines = lines;
215217
}
216-
if ((columns != sh.columns || nv_isnull(COLUMNS)) && (i = columns))
218+
if (columns && (columns != sh.columns || nv_isnull(COLUMNS)) && (i = columns))
217219
{
218220
nv_putval(COLUMNS, (char*)&i, NV_INT32|NV_RDONLY);
219221
sh.columns = columns;

src/cmd/ksh93/sh/io.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2429,7 +2429,6 @@ static int subexcept(Sfio_t* sp,int mode, void *data, Sfdisc_t* handle)
24292429
return -1;
24302430
}
24312431

2432-
#define NROW 15 /* number of rows before going to multi-columns */
24332432
#define LBLSIZ 3 /* size of label field and interfield spacing */
24342433
/*
24352434
* print a list of arguments in columns
@@ -2440,7 +2439,7 @@ void sh_menu(Sfio_t *outfile,int argn,char *argv[])
24402439
char **arg;
24412440
int nrow, ncol=1, ndigits=1;
24422441
int fldsize, wsize = ed_window();
2443-
nrow = sh.lines ? (2 * (sh.lines / 3) + 1) : NROW;
2442+
nrow = 2 * (sh.lines / 3) + 1; /* number of rows before going to multi-columns */
24442443
for(i=argn;i >= 10;i /= 10)
24452444
ndigits++;
24462445
if(argn < nrow)

src/cmd/ksh93/sh/main.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,10 @@ int sh_main(int ac, char *av[], Shinit_f userinit)
316316
fixargs(sh.st.dolv,1);
317317
}
318318
sh_winsize();
319+
if(!sh.columns)
320+
sh.columns = 80;
321+
if(!sh.lines)
322+
sh.lines = 24;
319323
if(sh_isoption(SH_INTERACTIVE))
320324
{
321325
sh_onstate(SH_INTERACTIVE);

0 commit comments

Comments
 (0)