1) sync with dash_0.5.2-7

2) but expand PS# as config option
3) correct kill error message again
4) remove show "line number" for interactive run (patch pending for dash)
This commit is contained in:
"Vladimir N. Oleynik" 2005-09-05 13:25:11 +00:00
parent 10a1fe6169
commit bef14d7a87
2 changed files with 103 additions and 59 deletions

View File

@ -143,6 +143,15 @@ config CONFIG_ASH_RANDOM_SUPPORT
After "unset RANDOM" then generator will switch off and this After "unset RANDOM" then generator will switch off and this
variable will no longer have special treatment. variable will no longer have special treatment.
config CONFIG_ASH_EXPAND_PRMT
bool " Support expand PS#"
default n
depends on CONFIG_ASH
help
"PS#" may be have commands. It option enable expand string
from prompt before each show.
config CONFIG_HUSH config CONFIG_HUSH
bool "hush" bool "hush"
default n default n

View File

@ -276,16 +276,6 @@ static void forceinton(void)
}) })
#endif /* CONFIG_ASH_OPTIMIZE_FOR_SIZE */ #endif /* CONFIG_ASH_OPTIMIZE_FOR_SIZE */
/*
* BSD setjmp saves the signal mask, which violates ANSI C and takes time,
* so we use _setjmp instead.
*/
#if defined(BSD) && !defined(__SVR4) && !defined(__GLIBC__)
#define setjmp(jmploc) _setjmp(jmploc)
#define longjmp(jmploc, val) _longjmp(jmploc, val)
#endif
/* $NetBSD: expand.h,v 1.13 2002/11/24 22:35:40 christos Exp $ */ /* $NetBSD: expand.h,v 1.13 2002/11/24 22:35:40 christos Exp $ */
struct strlist { struct strlist {
@ -1700,9 +1690,11 @@ init(void)
{ {
char **envp; char **envp;
char ppid[32]; char ppid[32];
const char *p;
struct stat st1, st2;
initvar(); initvar();
for (envp = environ ; *envp ; envp++) { for (envp = environ ; envp && *envp ; envp++) {
if (strchr(*envp, '=')) { if (strchr(*envp, '=')) {
setvareq(*envp, VEXPORT|VTEXTFIXED); setvareq(*envp, VEXPORT|VTEXTFIXED);
} }
@ -1710,7 +1702,13 @@ init(void)
snprintf(ppid, sizeof(ppid), "%d", (int) getppid()); snprintf(ppid, sizeof(ppid), "%d", (int) getppid());
setvar("PPID", ppid, 0); setvar("PPID", ppid, 0);
setpwd(0, 0);
p = lookupvar("PWD");
if (p)
if (*p != '/' || stat(p, &st1) || stat(".", &st2) ||
st1.st_dev != st2.st_dev || st1.st_ino != st2.st_ino)
p = 0;
setpwd(p, 0);
} }
} }
@ -2300,9 +2298,7 @@ cdcmd(int argc, char **argv)
dest = bltinlookup(homestr); dest = bltinlookup(homestr);
else if (dest[0] == '-' && dest[1] == '\0') { else if (dest[0] == '-' && dest[1] == '\0') {
dest = bltinlookup("OLDPWD"); dest = bltinlookup("OLDPWD");
if ( !dest ) goto out;
flags |= CD_PRINT; flags |= CD_PRINT;
goto step7;
} }
if (!dest) if (!dest)
dest = nullstr; dest = nullstr;
@ -2563,20 +2559,17 @@ onint(void) {
static void static void
exvwarning(const char *msg, va_list ap) exvwarning(const char *msg, va_list ap)
{ {
FILE *errs; FILE *errs;
const char *name;
const char *fmt;
errs = stderr; errs = stderr;
name = arg0; fprintf(errs, "%s: ", arg0);
fmt = "%s: "; if (commandname) {
if (commandname) { const char *fmt = (!iflag || parsefile->fd) ?
name = commandname; "%s: %d: " : "%s: ";
fmt = "%s: %d: "; fprintf(errs, fmt, commandname, startlinno);
} }
fprintf(errs, fmt, name, startlinno); vfprintf(errs, msg, ap);
vfprintf(errs, msg, ap); outcslow('\n', errs);
outcslow('\n', errs);
} }
/* /*
@ -3201,6 +3194,12 @@ isassignment(const char *p)
return *q == '='; return *q == '=';
} }
#ifdef CONFIG_ASH_EXPAND_PRMT
static const char *expandstr(const char *ps);
#else
#define expandstr(s) s
#endif
/* /*
* Execute a simple command. * Execute a simple command.
*/ */
@ -3296,7 +3295,7 @@ evalcommand(union node *cmd, int flags)
const char *p = " %s"; const char *p = " %s";
p++; p++;
dprintf(preverrout_fd, p, ps4val()); dprintf(preverrout_fd, p, expandstr(ps4val()));
sp = varlist.list; sp = varlist.list;
for(n = 0; n < 2; n++) { for(n = 0; n < 2; n++) {
@ -4595,11 +4594,12 @@ expandarg(union node *arg, struct arglist *arglist, int flag)
ifsfirst.next = NULL; ifsfirst.next = NULL;
ifslastp = NULL; ifslastp = NULL;
argstr(arg->narg.text, flag); argstr(arg->narg.text, flag);
p = _STPUTC('\0', expdest);
expdest = p - 1;
if (arglist == NULL) { if (arglist == NULL) {
return; /* here document expanded */ return; /* here document expanded */
} }
STPUTC('\0', expdest); p = grabstackstr(p);
p = grabstackstr(expdest);
exparg.lastp = &exparg.list; exparg.lastp = &exparg.list;
/* /*
* TODO - EXP_REDIR * TODO - EXP_REDIR
@ -5355,9 +5355,12 @@ param:
size_t partlen; size_t partlen;
partlen = strlen(p); partlen = strlen(p);
len += partlen; len += partlen;
if (len > partlen && sep) {
if (!(subtype == VSPLUS || subtype == VSLENGTH))
memtodest(p, partlen, syntax, quotes);
if (*ap && sep) {
char *q; char *q;
len++; len++;
@ -5370,9 +5373,6 @@ param:
STPUTC(sep, q); STPUTC(sep, q);
expdest = q; expdest = q;
} }
if (!(subtype == VSPLUS || subtype == VSLENGTH))
memtodest(p, partlen, syntax, quotes);
} }
return len; return len;
case '0': case '0':
@ -6603,10 +6603,12 @@ usage:
if (**argv == '%') { if (**argv == '%') {
jp = getjob(*argv, 0); jp = getjob(*argv, 0);
pid = -jp->ps[0].pid; pid = -jp->ps[0].pid;
} else } else {
pid = number(*argv); pid = **argv == '-' ?
-number(*argv + 1) : number(*argv);
}
if (kill(pid, signo) != 0) { if (kill(pid, signo) != 0) {
sh_warnx("kill %d: %s", pid, errmsg(errno, NULL)); sh_warnx("(%d) - %m", pid);
i = 1; i = 1;
} }
} while (*++argv); } while (*++argv);
@ -7621,11 +7623,10 @@ cmdputs(const char *s)
char *nextc; char *nextc;
int subtype = 0; int subtype = 0;
int quoted = 0; int quoted = 0;
static const char *const vstype[16] = { static const char vstype[VSTYPE + 1][4] = {
nullstr, "}", "-", "+", "?", "=", "", "}", "-", "+", "?", "=",
"%", "%%", "#", "##", nullstr "%", "%%", "#", "##"
}; };
nextc = makestrspace((strlen(s) + 1) * 8, cmdnextc); nextc = makestrspace((strlen(s) + 1) * 8, cmdnextc);
p = s; p = s;
while ((c = *p++) != 0) { while ((c = *p++) != 0) {
@ -7647,14 +7648,10 @@ cmdputs(const char *s)
goto dostr; goto dostr;
break; break;
case CTLENDVAR: case CTLENDVAR:
str = "\"}" + !(quoted & 1);
quoted >>= 1; quoted >>= 1;
subtype = 0; subtype = 0;
if (quoted & 1) { goto dostr;
str = "\"}";
goto dostr;
}
c = '}';
break;
case CTLBACKQ: case CTLBACKQ:
str = "$(...)"; str = "$(...)";
goto dostr; goto dostr;
@ -7676,13 +7673,13 @@ cmdputs(const char *s)
case '=': case '=':
if (subtype == 0) if (subtype == 0)
break; break;
if ((subtype & VSTYPE) != VSNORMAL)
quoted <<= 1;
str = vstype[subtype & VSTYPE]; str = vstype[subtype & VSTYPE];
if (subtype & VSNUL) if (subtype & VSNUL)
c = ':'; c = ':';
else else
c = *str++; goto checkstr;
if (c != '}')
quoted <<= 1;
break; break;
case '\'': case '\'':
case '\\': case '\\':
@ -7697,6 +7694,7 @@ cmdputs(const char *s)
break; break;
} }
USTPUTC(c, nextc); USTPUTC(c, nextc);
checkstr:
if (!str) if (!str)
continue; continue;
dostr: dostr:
@ -8138,7 +8136,7 @@ static int dotcmd(int argc, char **argv)
for (sp = cmdenviron; sp; sp = sp->next) for (sp = cmdenviron; sp; sp = sp->next)
setvareq(bb_xstrdup(sp->text), VSTRFIXED | VTEXTFIXED); setvareq(bb_xstrdup(sp->text), VSTRFIXED | VTEXTFIXED);
if (argc >= 2) { /* That's what SVR2 does */ if (argc >= 2) { /* That's what SVR2 does */
char *fullname; char *fullname;
struct stackmark smark; struct stackmark smark;
@ -9892,7 +9890,6 @@ parseheredoc(void)
while (here) { while (here) {
if (needprompt) { if (needprompt) {
setprompt(2); setprompt(2);
needprompt = 0;
} }
readtoken1(pgetc(), here->here->type == NHERE? SQSYNTAX : DQSYNTAX, readtoken1(pgetc(), here->here->type == NHERE? SQSYNTAX : DQSYNTAX,
here->eofmark, here->striptabs); here->eofmark, here->striptabs);
@ -10025,7 +10022,6 @@ static int xxreadtoken()
} }
if (needprompt) { if (needprompt) {
setprompt(2); setprompt(2);
needprompt = 0;
} }
startlinno = plinno; startlinno = plinno;
for (;;) { /* until token or start of word found */ for (;;) { /* until token or start of word found */
@ -10093,7 +10089,6 @@ xxreadtoken(void)
} }
if (needprompt) { if (needprompt) {
setprompt(2); setprompt(2);
needprompt = 0;
} }
startlinno = plinno; startlinno = plinno;
for (;;) { /* until token or start of word found */ for (;;) { /* until token or start of word found */
@ -10649,7 +10644,6 @@ parsebackq: {
for (;;) { for (;;) {
if (needprompt) { if (needprompt) {
setprompt(2); setprompt(2);
needprompt = 0;
} }
switch (pc = pgetc()) { switch (pc = pgetc()) {
case '`': case '`':
@ -10859,9 +10853,35 @@ synerror(const char *msg)
* should be added here. * should be added here.
*/ */
#ifdef CONFIG_ASH_EXPAND_PRMT
static const char *
expandstr(const char *ps)
{
union node n;
/* XXX Fix (char *) cast. */
setinputstring((char *)ps);
readtoken1(pgetc(), DQSYNTAX, nullstr, 0);
popfile();
n.narg.type = NARG;
n.narg.next = NULL;
n.narg.text = wordtext;
n.narg.backquote = backquotelist;
expandarg(&n, NULL, 0);
return stackblock();
}
#endif
static void setprompt(int whichprompt) static void setprompt(int whichprompt)
{ {
const char *prompt; const char *prompt;
#ifdef CONFIG_ASH_EXPAND_PRMT
struct stackmark smark;
#endif
needprompt = 0;
switch (whichprompt) { switch (whichprompt) {
case 1: case 1:
@ -10873,7 +10893,14 @@ static void setprompt(int whichprompt)
default: /* 0 */ default: /* 0 */
prompt = nullstr; prompt = nullstr;
} }
putprompt(prompt); #ifdef CONFIG_ASH_EXPAND_PRMT
setstackmark(&smark);
stalloc(stackblocksize());
#endif
putprompt(expandstr(prompt));
#ifdef CONFIG_ASH_EXPAND_PRMT
popstackmark(&smark);
#endif
} }
@ -13341,7 +13368,11 @@ arith_apply(operator op, v_n_t *numstack, v_n_t **numstackptr)
goto err; goto err;
} }
/* save to shell variable */ /* save to shell variable */
snprintf(buf, sizeof(buf), "%lld", (long long) rez); #ifdef CONFIG_ASH_MATH_SUPPORT_64
snprintf(buf, sizeof(buf), "%lld", rez);
#else
snprintf(buf, sizeof(buf), "%ld", rez);
#endif
setvar(numptr_m1->var, buf, 0); setvar(numptr_m1->var, buf, 0);
/* after saving, make previous value for v++ or v-- */ /* after saving, make previous value for v++ or v-- */
if(op == TOK_POST_INC) if(op == TOK_POST_INC)
@ -13479,7 +13510,11 @@ static arith_t arith (const char *expr, int *perrcode)
continue; continue;
} else if (is_digit(arithval)) { } else if (is_digit(arithval)) {
numstackptr->var = NULL; numstackptr->var = NULL;
#ifdef CONFIG_ASH_MATH_SUPPORT_64
numstackptr->val = strtoll(expr, (char **) &expr, 0); numstackptr->val = strtoll(expr, (char **) &expr, 0);
#else
numstackptr->val = strtol(expr, (char **) &expr, 0);
#endif
goto num; goto num;
} }
for(p = op_tokens; ; p++) { for(p = op_tokens; ; p++) {