summaryrefslogtreecommitdiffstats
path: root/bin
diff options
context:
space:
mode:
authorjilles <jilles@FreeBSD.org>2013-12-06 22:24:37 +0000
committerjilles <jilles@FreeBSD.org>2013-12-06 22:24:37 +0000
commitb5a84f73b8983991c384585ada139fe868193078 (patch)
treec3307d2c3585717721d799630f16c5e2b0175394 /bin
parent7d5f67faced17caa558c38a808c264c4242f3f28 (diff)
downloadFreeBSD-src-b5a84f73b8983991c384585ada139fe868193078.zip
FreeBSD-src-b5a84f73b8983991c384585ada139fe868193078.tar.gz
sh: Split set -x output into a separate function.
Diffstat (limited to 'bin')
-rw-r--r--bin/sh/eval.c75
1 files changed, 41 insertions, 34 deletions
diff --git a/bin/sh/eval.c b/bin/sh/eval.c
index b8f76d5..4f7559e 100644
--- a/bin/sh/eval.c
+++ b/bin/sh/eval.c
@@ -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) {
OpenPOWER on IntegriCloud