get rid of unneeded variables ⇒ error handling (that wasn’t there
previously) ⇒ code ⇒ simplify!
This commit is contained in:
parent
19cbb1ab78
commit
738f5f54fa
34
eval.c
34
eval.c
@ -23,7 +23,7 @@
|
|||||||
|
|
||||||
#include "sh.h"
|
#include "sh.h"
|
||||||
|
|
||||||
__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.135 2013/02/10 23:30:47 tg Exp $");
|
__RCSID("$MirOS: src/bin/mksh/eval.c,v 1.136 2013/02/10 23:43:59 tg Exp $");
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* string expansion
|
* string expansion
|
||||||
@ -59,7 +59,7 @@ typedef struct Expand {
|
|||||||
|
|
||||||
static int varsub(Expand *, const char *, const char *, int *, int *);
|
static int varsub(Expand *, const char *, const char *, int *, int *);
|
||||||
static int comsub(Expand *, const char *, int);
|
static int comsub(Expand *, const char *, int);
|
||||||
static int funsub(struct op *, struct shf *, int);
|
static void funsub(struct op *);
|
||||||
static char *trimsub(char *, char *, int);
|
static char *trimsub(char *, char *, int);
|
||||||
static void glob(char *, XPtrV *, bool);
|
static void glob(char *, XPtrV *, bool);
|
||||||
static void globit(XString *, char **, char *, XPtrV *, int);
|
static void globit(XString *, char **, char *, XPtrV *, int);
|
||||||
@ -1319,7 +1319,7 @@ comsub(Expand *xp, const char *cp, int fn MKSH_A_UNUSED)
|
|||||||
if (shf == NULL)
|
if (shf == NULL)
|
||||||
errorf("%s: %s %s", name, "can't open", "$() input");
|
errorf("%s: %s %s", name, "can't open", "$() input");
|
||||||
} else if (fn == FUNSUB) {
|
} else if (fn == FUNSUB) {
|
||||||
int ofd1, i;
|
int ofd1;
|
||||||
struct temp *tf = NULL;
|
struct temp *tf = NULL;
|
||||||
|
|
||||||
/* create a temporary file, open for writing */
|
/* create a temporary file, open for writing */
|
||||||
@ -1333,10 +1333,13 @@ comsub(Expand *xp, const char *cp, int fn MKSH_A_UNUSED)
|
|||||||
ksh_dup2(shf_fileno(tf->shf), 1, false);
|
ksh_dup2(shf_fileno(tf->shf), 1, false);
|
||||||
/*
|
/*
|
||||||
* run tree, with output thrown into the tempfile,
|
* run tree, with output thrown into the tempfile,
|
||||||
* in new function block; close tempfile and end redir
|
* in a new function block
|
||||||
*/
|
*/
|
||||||
i = funsub(t, tf->shf, ofd1);
|
funsub(t);
|
||||||
subst_exstat = exstat & 0xFF;
|
subst_exstat = exstat & 0xFF;
|
||||||
|
/* close the tempfile and restore regular stdout */
|
||||||
|
shf_close(tf->shf);
|
||||||
|
restfd(1, ofd1);
|
||||||
/* now open, unlink and free the tempfile for reading */
|
/* now open, unlink and free the tempfile for reading */
|
||||||
shf = shf_open(tf->tffn, O_RDONLY, 0, SHF_MAPHI | SHF_CLEXEC);
|
shf = shf_open(tf->tffn, O_RDONLY, 0, SHF_MAPHI | SHF_CLEXEC);
|
||||||
unlink(tf->tffn);
|
unlink(tf->tffn);
|
||||||
@ -1798,27 +1801,12 @@ alt_expand(XPtrV *wp, char *start, char *exp_start, char *end, int fdo)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* helper function due to setjmp/longjmp woes */
|
/* helper function due to setjmp/longjmp woes */
|
||||||
int
|
static void
|
||||||
funsub(struct op *t, struct shf *shf, int ofd1)
|
funsub(struct op *t)
|
||||||
{
|
{
|
||||||
volatile int i;
|
|
||||||
|
|
||||||
newblock();
|
newblock();
|
||||||
e->type = E_FUNC;
|
e->type = E_FUNC;
|
||||||
if (!(i = kshsetjmp(e->jbuf))) {
|
if (!kshsetjmp(e->jbuf))
|
||||||
execute(t, XXCOM | XERROK, NULL);
|
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();
|
popblock();
|
||||||
return (i);
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user