always set COLUMNS and LINES; make use of the fact in dot.mkshrc

This commit is contained in:
tg 2008-12-29 21:34:22 +00:00
parent de9fe12a4c
commit 177b1b4cf9
6 changed files with 70 additions and 41 deletions

View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/check.t,v 1.253 2008/12/17 19:39:21 tg Exp $
# $MirOS: src/bin/mksh/check.t,v 1.254 2008/12/29 21:34:18 tg Exp $
# $OpenBSD: bksl-nl.t,v 1.2 2001/01/28 23:04:56 niklas Exp $
# $OpenBSD: history.t,v 1.5 2001/01/28 23:04:56 niklas Exp $
# $OpenBSD: read.t,v 1.3 2003/03/10 03:48:16 david Exp $
@ -7,7 +7,7 @@
# http://www.research.att.com/~gsf/public/ifs.sh
expected-stdout:
@(#)MIRBSD KSH R36 2008/12/17
@(#)MIRBSD KSH R36 2008/12/29
description:
Check version of shell.
stdin:

View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/dot.mkshrc,v 1.39 2008/12/13 17:09:45 tg Rel $
# $MirOS: src/bin/mksh/dot.mkshrc,v 1.40 2008/12/29 21:34:19 tg Rel $
#-
# ~/.mkshrc: mksh initialisation file for interactive shells
@ -11,9 +11,9 @@ function precmd {
(( e )) && print -n "$e|"
}
PS1=' $(precmd)${USER:=$(ulimit -c 0;id -un 2>&-||print \?)}@${HOSTNAME%%.*}:$(
typeset p=~ d=${PWD:-?}; typeset -i n=${COLUMNS:-80}/3
[[ $p = ?(*/) ]] || d=${d/#$p/~}; (( n=n<7?7:n )); (( ${#d}>n )) && {
p=...; d=${d:(-n)}; } || p=; print -nr -- "$p$d") '"$PS1 "
typeset d=${PWD:-?} n p=~; [[ $p = ?(*/) ]] || d=${d/#$p/~}
(( ${#d} > (n = (COLUMNS/3 < 7 ? 7 : COLUMNS/3)) )) && {
d=${d:(-n)}; p=...; } || p=; print -nr -- "$p$d") '"$PS1 "
export EDITOR HOSTNAME LESSHISTFILE=- MKSH=$(whence -p mksh) PS1 TERM USER
alias ls=ls
unalias ls

8
main.c
View File

@ -13,7 +13,7 @@
#include <locale.h>
#endif
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.118 2008/12/29 20:52:09 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/main.c,v 1.119 2008/12/29 21:34:20 tg Exp $");
extern char **environ;
@ -32,8 +32,10 @@ static const char initsubs[] = "${PS2=> } ${PS3=#? } ${PS4=+ }";
static const char *initcoms[] = {
"typeset", "-r", initvsn, NULL,
"typeset", "-x", "SHELL", "PATH", "HOME", NULL,
"typeset", "-i10", "OPTIND=1", "PGRP", "PPID", "USER_ID", NULL,
"eval", "typeset -i10 RANDOM SECONDS=\"${SECONDS-0}\" TMOUT=\"${TMOUT-0}\"", NULL,
"typeset", "-i10", "COLUMNS=0", "LINES=0", "OPTIND=1", "PGRP", "PPID",
"RANDOM", "USER_ID", NULL,
"eval", "typeset -i10 SECONDS=\"${SECONDS-0}\" TMOUT=\"${TMOUT-0}\"",
NULL,
"alias", "integer=typeset -i", "local=typeset", NULL,
"alias",
"hash=alias -t", /* not "alias -t --": hash -r needs to work */

11
mksh.1
View File

@ -1,4 +1,4 @@
.\" $MirOS: src/bin/mksh/mksh.1,v 1.148 2008/12/17 19:39:22 tg Exp $
.\" $MirOS: src/bin/mksh/mksh.1,v 1.149 2008/12/29 21:34:20 tg Exp $
.\" $OpenBSD: ksh.1,v 1.122 2008/05/17 23:31:52 sobrado Exp $
.\"-
.\" Try to make GNU groff and AT&T nroff more compatible
@ -30,7 +30,7 @@
.el .xD \\$1 \\$2 \\$3 \\$4 \\$5 \\$6 \\$7 \\$8
..
.\"-
.Dd $Mdocdate: December 17 2008 $
.Dd $Mdocdate: December 29 2008 $
.Dt MKSH 1
.Os MirBSD
.Sh NAME
@ -1435,11 +1435,11 @@ built-in command will display the resulting directory when a match is found
in any search path other than the empty path.
.It Ev COLUMNS
Set to the number of columns on the terminal or window.
Currently set to the
.Dq cols
Always set, defaults to 80, unless the
value as reported by
.Xr stty 1
if that value is non-zero.
is non-zero and sane enough; similar for
.Ev LINES .
This parameter is used by the interactive line editing modes, and by the
.Ic select ,
.Ic set \-o ,
@ -1527,6 +1527,7 @@ The line number of the function or shell script that is currently being
executed.
.It Ev LINES
Set to the number of lines on the terminal or window.
Always set, defaults to 24.
.It Ev OLDPWD
The previous working directory.
Unset if

27
sh.h
View File

@ -103,9 +103,9 @@
#define __SCCSID(x) __IDSTRING(sccsid,x)
#ifdef EXTERN
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.271 2008/12/29 21:05:15 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/sh.h,v 1.272 2008/12/29 21:34:21 tg Exp $");
#endif
#define MKSH_VERSION "R36 2008/12/17"
#define MKSH_VERSION "R36 2008/12/29"
#ifndef MKSH_INCLUDES_ONLY
@ -906,17 +906,18 @@ extern const struct builtin mkshbuiltins[];
/* var spec values */
#define V_NONE 0
#define V_PATH 1
#define V_IFS 2
#define V_SECONDS 3
#define V_OPTIND 4
#define V_RANDOM 8
#define V_HISTSIZE 9
#define V_HISTFILE 10
#define V_COLUMNS 13
#define V_TMOUT 15
#define V_TMPDIR 16
#define V_LINENO 17
#define V_COLUMNS 1
#define V_HISTFILE 2
#define V_HISTSIZE 3
#define V_IFS 4
#define V_LINENO 5
#define V_LINES 6
#define V_OPTIND 7
#define V_PATH 8
#define V_RANDOM 9
#define V_SECONDS 10
#define V_TMOUT 11
#define V_TMPDIR 12
/* values for set_prompt() */
#define PS1 0 /* command */

53
var.c
View File

@ -2,7 +2,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.67 2008/12/29 21:05:15 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/var.c,v 1.68 2008/12/29 21:34:22 tg Exp $");
/*
* Variables
@ -87,24 +87,25 @@ initvar(void)
int v;
} names[] = {
{ "COLUMNS", V_COLUMNS },
{ "IFS", V_IFS },
{ "OPTIND", V_OPTIND },
{ "PATH", V_PATH },
{ "TMPDIR", V_TMPDIR },
#if HAVE_PERSISTENT_HISTORY
{ "HISTFILE", V_HISTFILE },
#endif
{ "HISTSIZE", V_HISTSIZE },
{ "IFS", V_IFS },
{ "LINENO", V_LINENO },
{ "LINES", V_LINES },
{ "OPTIND", V_OPTIND },
{ "PATH", V_PATH },
{ "RANDOM", V_RANDOM },
{ "SECONDS", V_SECONDS },
{ "TMOUT", V_TMOUT },
{ "LINENO", V_LINENO },
{ NULL, 0 }
{ "TMPDIR", V_TMPDIR },
{ NULL, 0 }
};
int i;
struct tbl *tp;
ktinit(&specials, APERM, 16); /* must be 2^n (currently 11 specials) */
ktinit(&specials, APERM, 16); /* must be 2^n (currently 12 specials) */
for (i = 0; names[i].name; i++) {
tp = ktenter(&specials, names[i].name, hash(names[i].name));
tp->flag = DEFINED|ISSET;
@ -1026,7 +1027,9 @@ static int user_lineno; /* what user set $LINENO to */
static void
getspec(struct tbl *vp)
{
switch (special(vp->name)) {
int i;
switch ((i = special(vp->name))) {
case V_SECONDS:
vp->flag &= ~SPECIAL;
/* On start up the value of SECONDS is used before seconds
@ -1048,17 +1051,30 @@ getspec(struct tbl *vp)
break;
case V_HISTSIZE:
vp->flag &= ~SPECIAL;
setint(vp, (long) histsize);
setint(vp, (long)histsize);
vp->flag |= SPECIAL;
break;
case V_OPTIND:
vp->flag &= ~SPECIAL;
setint(vp, (long) user_opt.uoptind);
setint(vp, (long)user_opt.uoptind);
vp->flag |= SPECIAL;
break;
case V_LINENO:
vp->flag &= ~SPECIAL;
setint(vp, (long) current_lineno + user_lineno);
setint(vp, (long)current_lineno + user_lineno);
vp->flag |= SPECIAL;
break;
case V_COLUMNS:
case V_LINES:
/* Do NOT export COLUMNS/LINES. Many applications
* check COLUMNS/LINES before checking ws.ws_col/row,
* so if the app is started with C/L in the environ
* and the window is then resized, the app won't
* see the change cause the environ doesn't change.
*/
vp->flag &= ~SPECIAL;
change_winsz();
setint(vp, i == V_COLUMNS ? x_cols : x_lins);
vp->flag |= SPECIAL;
break;
}
@ -1067,6 +1083,7 @@ getspec(struct tbl *vp)
static void
setspec(struct tbl *vp)
{
int i;
char *s;
switch (special(vp->name)) {
@ -1114,8 +1131,16 @@ setspec(struct tbl *vp)
break;
#endif
case V_COLUMNS:
if ((x_cols = intval(vp)) <= MIN_COLS)
x_cols = MIN_COLS;
vp->flag &= ~SPECIAL;
if ((i = intval(vp)) >= MIN_COLS)
x_cols = i;
vp->flag |= SPECIAL;
break;
case V_LINES:
vp->flag &= ~SPECIAL;
if ((i = intval(vp)) >= MIN_LINS)
x_lins = i;
vp->flag |= SPECIAL;
break;
case V_RANDOM:
vp->flag &= ~SPECIAL;