From 24e8a6996b593682f416220bb3ba86d12b32e001 Mon Sep 17 00:00:00 2001 From: tg Date: Fri, 23 Mar 2012 21:58:24 +0000 Subject: [PATCH] always keep x_cols and x_lins valid; check once at start including tty init if we find any, but not later; do not check on every read MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ⇒ allows changing COLUMNS and LINES (independent of each other, or both) for script shells by passing them in an environment setting, even if we get a tty; interactive shells still check before each line is read… reported by the PLD guys, thanks --- main.c | 8 +++++++- misc.c | 6 +----- sh.h | 4 ++-- var.c | 13 +------------ 4 files changed, 11 insertions(+), 20 deletions(-) diff --git a/main.c b/main.c index bacd550..8a5e157 100644 --- a/main.c +++ b/main.c @@ -34,7 +34,7 @@ #include #endif -__RCSID("$MirOS: src/bin/mksh/main.c,v 1.207 2012/03/23 19:38:12 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/main.c,v 1.208 2012/03/23 21:58:21 tg Exp $"); extern char **environ; @@ -258,6 +258,12 @@ main_init(int argc, const char *argv[], Source **sp, struct block **lp) init_histvec(); +#ifdef TIOCGWINSZ + /* try to initialise tty size before importing environment */ + tty_init(false, false); + change_winsz(); +#endif + #ifdef _PATH_DEFPATH def_path = _PATH_DEFPATH; #else diff --git a/misc.c b/misc.c index 92a00ca..4296fde 100644 --- a/misc.c +++ b/misc.c @@ -30,7 +30,7 @@ #include #endif -__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.183 2012/03/23 20:07:11 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/misc.c,v 1.184 2012/03/23 21:58:22 tg Exp $"); /* type bits for unsigned char */ unsigned char chtypes[UCHAR_MAX + 1]; @@ -1174,10 +1174,6 @@ print_columns(struct shf *shf, int n, ++max_oct; str = alloc(max_oct, ATEMP); - /* ensure x_cols is valid first */ - if (x_cols < MIN_COLS) - change_winsz(); - /* * We use (max_col + 1) to consider the space separator. * Note that no space is printed after the last column diff --git a/sh.h b/sh.h index c084146..72f227a 100644 --- a/sh.h +++ b/sh.h @@ -152,7 +152,7 @@ #endif #ifdef EXTERN -__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.524 2012/03/23 20:07:11 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.525 2012/03/23 21:58:22 tg Exp $"); #endif #define MKSH_VERSION "R40 2012/03/03" @@ -858,7 +858,7 @@ EXTERN char *current_wd; #define MIN_COLS (2 + MIN_EDIT_SPACE + 3) #define MIN_LINS 3 EXTERN mksh_ari_t x_cols E_INIT(80); /* tty columns */ -EXTERN mksh_ari_t x_lins E_INIT(-1); /* tty lines */ +EXTERN mksh_ari_t x_lins E_INIT(24); /* tty lines */ /* These to avoid bracket matching problems */ #define OPAREN '(' diff --git a/var.c b/var.c index be84347..099ea13 100644 --- a/var.c +++ b/var.c @@ -26,7 +26,7 @@ #include #endif -__RCSID("$MirOS: src/bin/mksh/var.c,v 1.141 2012/03/03 21:30:59 tg Exp $"); +__RCSID("$MirOS: src/bin/mksh/var.c,v 1.142 2012/03/23 21:58:24 tg Exp $"); /*- * Variables @@ -1132,7 +1132,6 @@ getspec(struct tbl *vp) * and the window is then resized, the app won't * see the change cause the environ doesn't change. */ - change_winsz(); i = st == V_COLUMNS ? x_cols : x_lins; break; default: @@ -1458,16 +1457,6 @@ set_array(const char *var, bool reset, const char **vals) void change_winsz(void) { - if (x_lins < 0) { - /* first time initialisation */ -#ifdef TIOCGWINSZ - if (tty_fd < 0) - /* non-FTALKING, try to get an fd anyway */ - tty_init(true, false); -#endif - x_cols = -1; - } - #ifdef TIOCGWINSZ /* check if window size has changed */ if (tty_fd >= 0) {