provide a layer of locality to FUNSUBs; get rid of a fork for each PS1 thus
This commit is contained in:
parent
1df0cb4093
commit
9bf0509829
@ -1,5 +1,5 @@
|
||||
# $Id$
|
||||
# $MirOS: src/bin/mksh/dot.mkshrc,v 1.75 2013/02/10 19:04:00 tg Exp $
|
||||
# $MirOS: src/bin/mksh/dot.mkshrc,v 1.76 2013/02/10 23:30:47 tg Exp $
|
||||
#-
|
||||
# Copyright (c) 2002, 2003, 2004, 2006, 2007, 2008, 2009, 2010,
|
||||
# 2011, 2012, 2013
|
||||
@ -33,10 +33,10 @@ function precmd {
|
||||
return $e
|
||||
}
|
||||
PS1=$'\001\r''${ precmd;}${USER:=$(ulimit -c 0; id -un 2>/dev/null || echo \?
|
||||
)}@${HOSTNAME%%.*}:$(local d=${PWD:-?} p=~; [[ $p = ?(*/) ]] || \
|
||||
)}@${HOSTNAME%%.*}:${ local e=$? d=${PWD:-?} p=~; [[ $p = ?(*/) ]] || \
|
||||
d=${d/#$p/~}; local m=${%d} n p=...; (( m > 0 )) || m=${#d}
|
||||
(( m > (n = (COLUMNS/3 < 7 ? 7 : COLUMNS/3)) )) && d=${d:(-n)} || \
|
||||
p=; print -nr -- "$p$d") '"$PS1 "
|
||||
p=; print -nr -- "$p$d"; return $e;} '"$PS1 "
|
||||
: ${MKSH:=$(whence -p mksh)}; export EDITOR HOSTNAME MKSH TERM USER
|
||||
alias ls=ls
|
||||
unalias ls
|
||||
|
42
eval.c
42
eval.c
@ -23,7 +23,7 @@
|
||||
|
||||
#include "sh.h"
|
||||
|
||||
__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.134 2013/02/10 21:42:15 tg Exp $");
|
||||
__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.135 2013/02/10 23:30:47 tg Exp $");
|
||||
|
||||
/*
|
||||
* string expansion
|
||||
@ -59,6 +59,7 @@ typedef struct Expand {
|
||||
|
||||
static int varsub(Expand *, const char *, const char *, int *, int *);
|
||||
static int comsub(Expand *, const char *, int);
|
||||
static int funsub(struct op *, struct shf *, int);
|
||||
static char *trimsub(char *, char *, int);
|
||||
static void glob(char *, XPtrV *, bool);
|
||||
static void globit(XString *, char **, char *, XPtrV *, int);
|
||||
@ -1318,7 +1319,7 @@ comsub(Expand *xp, const char *cp, int fn MKSH_A_UNUSED)
|
||||
if (shf == NULL)
|
||||
errorf("%s: %s %s", name, "can't open", "$() input");
|
||||
} else if (fn == FUNSUB) {
|
||||
int ofd1;
|
||||
int ofd1, i;
|
||||
struct temp *tf = NULL;
|
||||
|
||||
/* create a temporary file, open for writing */
|
||||
@ -1330,11 +1331,12 @@ comsub(Expand *xp, const char *cp, int fn MKSH_A_UNUSED)
|
||||
/* save stdout and make the temporary file it */
|
||||
ofd1 = savefd(1);
|
||||
ksh_dup2(shf_fileno(tf->shf), 1, false);
|
||||
/* run tree, with output thrown into the tempfile */
|
||||
execute(t, XXCOM | XERROK, NULL);
|
||||
/* close the tempfile and restore regular stdout */
|
||||
shf_close(tf->shf);
|
||||
restfd(1, ofd1);
|
||||
/*
|
||||
* run tree, with output thrown into the tempfile,
|
||||
* in new function block; close tempfile and end redir
|
||||
*/
|
||||
i = funsub(t, tf->shf, ofd1);
|
||||
subst_exstat = exstat & 0xFF;
|
||||
/* now open, unlink and free the tempfile for reading */
|
||||
shf = shf_open(tf->tffn, O_RDONLY, 0, SHF_MAPHI | SHF_CLEXEC);
|
||||
unlink(tf->tffn);
|
||||
@ -1794,3 +1796,29 @@ alt_expand(XPtrV *wp, char *start, char *exp_start, char *end, int fdo)
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
/* helper function due to setjmp/longjmp woes */
|
||||
int
|
||||
funsub(struct op *t, struct shf *shf, int ofd1)
|
||||
{
|
||||
volatile int i;
|
||||
|
||||
newblock();
|
||||
e->type = E_FUNC;
|
||||
if (!(i = kshsetjmp(e->jbuf))) {
|
||||
execute(t, XXCOM | XERROK, NULL);
|
||||
i = LRETURN;
|
||||
}
|
||||
/* close the tempfile and restore regular stdout */
|
||||
shf_close(shf);
|
||||
restfd(1, ofd1);
|
||||
/* function block error handling */
|
||||
if (i != LRETURN /* && i != LERROR */) {
|
||||
quitenv(NULL);
|
||||
unwind(i);
|
||||
internal_errorf("%s %d", "FUNSUB<", i);
|
||||
/* NOTREACHED */
|
||||
}
|
||||
popblock();
|
||||
return (i);
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user