From 40616c7bb389aaa1e23907cad897503212b8e51e Mon Sep 17 00:00:00 2001 From: stefanf Date: Thu, 15 Jun 2006 07:00:49 +0000 Subject: Implement the PS4 variable which is defined by the POSIX User Portability Utilities option. Its value is printed at the beginning of the line if tracing (-x) is active. PS4 defaults to the string "+ " which is compatible with the old behaviour to always print "+ ". We still need to expand variables in PS1, PS2 and PS4. PR: 46441 (part of) Submitted by: schweikh Obtained from: NetBSD --- bin/sh/eval.c | 11 ++++++++--- bin/sh/sh.1 | 13 ++++++++++--- bin/sh/var.c | 3 +++ bin/sh/var.h | 2 ++ 4 files changed, 23 insertions(+), 6 deletions(-) (limited to 'bin/sh') diff --git a/bin/sh/eval.c b/bin/sh/eval.c index fa2fe59..dc0236d 100644 --- a/bin/sh/eval.c +++ b/bin/sh/eval.c @@ -643,14 +643,19 @@ evalcommand(union node *cmd, int flags, struct backcmd *backcmd) /* Print the command if xflag is set. */ if (xflag) { - outc('+', &errout); + char sep = 0; + out2str(ps4val()); for (sp = varlist.list ; sp ; sp = sp->next) { - outc(' ', &errout); + if (sep != 0) + outc(' ', &errout); out2str(sp->text); + sep = ' '; } for (sp = arglist.list ; sp ; sp = sp->next) { - outc(' ', &errout); + if (sep != 0) + outc(' ', &errout); out2str(sp->text); + sep = ' '; } outc('\n', &errout); flushout(&errout); diff --git a/bin/sh/sh.1 b/bin/sh/sh.1 index 3c2fa9c..438fc24 100644 --- a/bin/sh/sh.1 +++ b/bin/sh/sh.1 @@ -32,7 +32,7 @@ .\" from: @(#)sh.1 8.6 (Berkeley) 5/4/95 .\" $FreeBSD$ .\" -.Dd December 8, 2005 +.Dd June 15, 2006 .Dt SH 1 .Os .Sh NAME @@ -305,8 +305,9 @@ as it is read. Useful for debugging. .It Fl x Li xtrace Write each command -(preceded by -.Dq Li "+ " ) +(preceded by the value of the +.Ev PS4 +variable) to standard error before it is executed. Useful for debugging. .El @@ -2197,6 +2198,12 @@ unless you are the superuser, in which case it defaults to .It Ev PS2 The secondary prompt string, which defaults to .Dq Li "> " . +.It Ev PS4 +The prefix for the trace output (if +.Fl x +is active). +The default is +.Dq Li "+ " . .It Ev TERM The default terminal setting for the shell. This is inherited by children of the shell, and is used in the history diff --git a/bin/sh/var.c b/bin/sh/var.c index 4dc54b0..54a0a84 100644 --- a/bin/sh/var.c +++ b/bin/sh/var.c @@ -88,6 +88,7 @@ struct var vpath; struct var vppid; struct var vps1; struct var vps2; +struct var vps4; struct var vvers; STATIC struct var voptind; @@ -111,6 +112,8 @@ STATIC const struct varinit varinit[] = { */ { &vps2, VSTRFIXED|VTEXTFIXED, "PS2=> ", NULL }, + { &vps4, VSTRFIXED|VTEXTFIXED, "PS4=+ ", + NULL }, { &voptind, VSTRFIXED|VTEXTFIXED, "OPTIND=1", getoptsreset }, { NULL, 0, NULL, diff --git a/bin/sh/var.h b/bin/sh/var.h index 4eb5dc1..c1f994b 100644 --- a/bin/sh/var.h +++ b/bin/sh/var.h @@ -74,6 +74,7 @@ extern struct var vpath; extern struct var vppid; extern struct var vps1; extern struct var vps2; +extern struct var vps4; #ifndef NO_HISTORY extern struct var vhistsize; #endif @@ -91,6 +92,7 @@ extern struct var vhistsize; #define pathval() (vpath.text + 5) #define ps1val() (vps1.text + 4) #define ps2val() (vps2.text + 4) +#define ps4val() (vps4.text + 4) #define optindval() (voptind.text + 7) #ifndef NO_HISTORY #define histsizeval() (vhistsize.text + 9) -- cgit v1.1