finally, all bugs fixed, adjust dot.mkshrc to use the subst code

This commit is contained in:
tg 2008-03-01 21:24:58 +00:00
parent 4912b5cf67
commit 947bc8e05b
3 changed files with 18 additions and 11 deletions

View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/check.t,v 1.155 2008/03/01 21:10:25 tg Exp $
# $MirOS: src/bin/mksh/check.t,v 1.156 2008/03/01 21:24:58 tg Rel $
# $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 $
@ -998,7 +998,9 @@ name: eglob-substrpl-1
description:
Check eglobbing works in substs... and they work at all
stdin:
[[ -n $BASH_VERSION ]] && shopt -s extglob
x=1222321_ab/cde_b/c_1221
y=xyz
echo 1: ${x/2}
echo 2: ${x//2}
echo 3: ${x/+(2)}
@ -1027,6 +1029,7 @@ stdin:
echo 26: ${x//\\%1/9}
echo 27: ${x//\a/9}
echo 28: ${x//\\a/9}
echo 29: ${x/2/$y}
expected-stdout:
1: 122321_ab/cde_b/c_1221
2: 131_ab/cde_b/c_11
@ -1056,6 +1059,7 @@ expected-stdout:
26: 1222321_ab/cde_b/c_1221
27: 1222321_9b/cde_b/c_1221
28: 1222321_9b/cde_b/c_1221
29: 1xyz22321_ab/cde_b/c_1221
---
name: eglob-substrpl-2
description:

View File

@ -1,4 +1,4 @@
# $MirOS: src/bin/mksh/dot.mkshrc,v 1.27 2008/03/01 16:35:30 tg Exp $
# $MirOS: src/bin/mksh/dot.mkshrc,v 1.28 2008/03/01 21:24:58 tg Rel $
#-
# Copyright (c) 2007, 2008
# Thorsten “mirabilos” Glaser <tg@mirbsd.de>
@ -36,7 +36,7 @@ function precmd {
PS1='$(precmd)${USER:=$(ulimit -c 0;id -un 2>&- || print \?)}@${HOSTNAME%%.*}:$(
typeset pfx=~ wd=${PWD:-?}
typeset -Ui n=${COLUMNS:-80}/3; (( n = n < 7 ? 7 : n ))
[[ ${wd#$pfx} = $wd || $pfx = ?(/) ]] || wd=\~${wd#$pfx}
wd=${wd/#$pfx/~}
pfx=; while (( (${#pfx} + ${#wd}) > n )); do
if [[ $wd = */* ]]; then
pfx=.../
@ -68,8 +68,7 @@ typeset -r DIRSTACKBASE
set -A DIRSTACK
function chpwd {
DIRSTACK[0]=$(readlink -nf . 2>&- || print -r -- "$PWD")
[[ ${DIRSTACK[0]#$DIRSTACKBASE} = ${DIRSTACK[0]} ]] || \
DIRSTACK[0]=\~${DIRSTACK[0]#$DIRSTACKBASE}
DIRSTACK[0]=${DIRSTACK[0]/#$DIRSTACKBASE/~}
:
}
chpwd .
@ -78,9 +77,8 @@ function cd {
chpwd "$@"
}
function cd_csh {
typeset d t=$1
typeset d t=${1/#~/$DIRSTACKBASE}
[[ $t = ~* ]] && t=$DIRSTACKBASE${t#~}
if ! d=$(builtin cd "$t" 2>&1); then
print -u2 "${1}: ${d##*$t - }."
return 1
@ -111,7 +109,7 @@ function dirs {
fv=0
while (( fv < ${#DIRSTACK[*]} )); do
d=${DIRSTACK[fv]}
[[ $fl$d = 1~* ]] && d=$DIRSTACKBASE${d#~}
(( fl )) && d=${d/#~/$DIRSTACKBASE}
print -r -- "$fv $d"
let fv++
done
@ -119,7 +117,7 @@ function dirs {
fv=0
while (( fv < ${#DIRSTACK[*]} )); do
d=${DIRSTACK[fv]}
[[ $fl$d = 1~* ]] && d=$DIRSTACKBASE${d#~}
(( fl )) && d=${d/#~/$DIRSTACKBASE}
if (( fn && (cpos+=${#d}+1) >= 79 && ${#d} < 80 )); then
print
(( cpos = ${#d} + 1 ))

9
eval.c
View File

@ -2,7 +2,7 @@
#include "sh.h"
__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.43 2008/03/01 21:10:25 tg Exp $");
__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.44 2008/03/01 21:24:58 tg Exp $");
#ifdef MKSH_SMALL
#define MKSH_NOPWNAM
@ -393,7 +393,12 @@ expand(const char *cp, /* input word */
sp += (d ? d : p) - s - 1;
tpat0 = wdstrip(s, true, true);
pat = substitute(tpat0, 0);
rrep = d ? wdstrip(p, true, false) : null;
if (d) {
d = wdstrip(p, true, false);
rrep = substitute(d, 0);
afree(d, ATEMP);
} else
rrep = null;
afree(s, ATEMP);
s = d = pat;
while (*s)