sh: Split set -x output into a separate function.

This commit is contained in:
Jilles Tjoelker 2013-12-06 22:24:37 +00:00
parent daab849b2c
commit d1670d4228
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=259047

View File

@ -750,6 +750,45 @@ isdeclarationcmd(struct narg *arg)
(have_command || !isfunc("local"))));
}
static void
xtracecommand(struct arglist *varlist, struct arglist *arglist)
{
struct strlist *sp;
char sep = 0;
const char *p, *ps4;
ps4 = expandstr(ps4val());
out2str(ps4 != NULL ? ps4 : ps4val());
for (sp = varlist->list ; sp ; sp = sp->next) {
if (sep != 0)
out2c(' ');
p = strchr(sp->text, '=');
if (p != NULL) {
p++;
outbin(sp->text, p - sp->text, out2);
out2qstr(p);
} else
out2qstr(sp->text);
sep = ' ';
}
for (sp = arglist->list ; sp ; sp = sp->next) {
if (sep != 0)
out2c(' ');
/* Disambiguate command looking like assignment. */
if (sp == arglist->list &&
strchr(sp->text, '=') != NULL &&
strchr(sp->text, '\'') == NULL) {
out2c('\'');
out2str(sp->text);
out2c('\'');
} else
out2qstr(sp->text);
sep = ' ';
}
out2c('\n');
flushout(&errout);
}
/*
* Check if a builtin can safely be executed in the same process,
* even though it should be in a subshell (command substitution).
@ -847,40 +886,8 @@ evalcommand(union node *cmd, int flags, struct backcmd *backcmd)
argv -= argc;
/* Print the command if xflag is set. */
if (xflag) {
char sep = 0;
const char *p, *ps4;
ps4 = expandstr(ps4val());
out2str(ps4 != NULL ? ps4 : ps4val());
for (sp = varlist.list ; sp ; sp = sp->next) {
if (sep != 0)
out2c(' ');
p = strchr(sp->text, '=');
if (p != NULL) {
p++;
outbin(sp->text, p - sp->text, out2);
out2qstr(p);
} else
out2qstr(sp->text);
sep = ' ';
}
for (sp = arglist.list ; sp ; sp = sp->next) {
if (sep != 0)
out2c(' ');
/* Disambiguate command looking like assignment. */
if (sp == arglist.list &&
strchr(sp->text, '=') != NULL &&
strchr(sp->text, '\'') == NULL) {
out2c('\'');
out2str(sp->text);
out2c('\'');
} else
out2qstr(sp->text);
sep = ' ';
}
out2c('\n');
flushout(&errout);
}
if (xflag)
xtracecommand(&varlist, &arglist);
/* Now locate the command. */
if (argc == 0) {