(I forgot to CC th emailint list so I resend this one)

On Sat, 2007-09-15 at 14:28 +0100, Denis Vlasenko wrote:
> On Thursday 13 September 2007 12:39, Natanael Copa wrote:
> > Hi,
> > 
> > Attatched is a patch that fixes the annoying bug in ash prmpt expansion.
> > 
> > Currently the default PS1='\w \$ ' will always show a '$' as prompt
> > while PS1='\w \\$ ' will show a '#' if effective user is root and '$'
> > otherwise.
> 
> This is strange, for me current svn seems to work:
> 
> sh-3.2# ./busybox ash
> /.1/usr/srcdevel/bbox/fix/busybox.t3 # PS1='\w \$ '
> /.1/usr/srcdevel/bbox/fix/busybox.t3 # PS1='\w \\$ '
> /.1/usr/srcdevel/bbox/fix/busybox.t3 \$ PS1='TEST>\$ '
> TEST># PS1='TEST>\\$ '
> TEST>\$
> 
> Is it already fixed? Or maybe it depends on .config.
> Mine is attached.

> CONFIG_ASH_RANDOM_SUPPORT=y
> # CONFIG_ASH_EXPAND_PRMT is not set
> CONFIG_HUSH=y 

Try enable CONFIG_ASH_EXPAND_PRMT

Maybe we should check if ASH_EXPAND_PRMT is enabled before trying to fix
the prompt expansion. See attatched patch.

> --
> vda
Index: shell/ash.c
===================================================================
--- shell/ash.c	(revision 19861)
+++ shell/ash.c	(working copy)
@@ -2494,6 +2494,7 @@
 #define DQSYNTAX   1    /* in double quotes */
 #define SQSYNTAX   2    /* in single quotes */
 #define ARISYNTAX  3    /* in arithmetic */
+#define PSSYNTAX   4    /* prompt */
 
 #if ENABLE_ASH_OPTIMIZE_FOR_SIZE
 #define USE_SIT_FUNCTION
@@ -9891,6 +9892,10 @@
 	int dqvarnest = 0;  /* levels of variables expansion within double quotes */
 	int oldstyle = 0;
 	int prevsyntax = 0; /* syntax before arithmetic */
+#if ENABLE_ASH_EXPAND_PRMT
+	int pssyntax = 0;   /* we are expanding a prompt string */
+#endif
+
 #if __GNUC__
 	/* Avoid longjmp clobbering */
 	(void) &out;
@@ -9907,6 +9912,12 @@
 
 	startlinno = plinno;
 	dblquote = 0;
+#if ENABLE_ASH_EXPAND_PRMT
+	if (syntax == PSSYNTAX) {
+		pssyntax = 1;
+		syntax = DQSYNTAX;
+	}
+#endif
 	if (syntax == DQSYNTAX)
 		dblquote = 1;
 	quotef = 0;
@@ -9949,6 +9960,12 @@
 					if (doprompt)
 						setprompt(2);
 				} else {
+#if ENABLE_ASH_EXPAND_PRMT
+					if (c == '$' && pssyntax) {
+						USTPUTC(CTLESC, out);
+						USTPUTC('\\', out);
+					}
+#endif
 					if (dblquote &&
 						c != '\\' && c != '`' &&
 						c != '$' && (
@@ -10784,7 +10801,7 @@
 
 	/* XXX Fix (char *) cast. */
 	setinputstring((char *)ps);
-	readtoken1(pgetc(), DQSYNTAX, nullstr, 0);
+	readtoken1(pgetc(), PSSYNTAX, nullstr, 0);
 	popfile();
 
 	n.narg.type = NARG;
_______________________________________________
busybox mailing list
[email protected]
http://busybox.net/cgi-bin/mailman/listinfo/busybox

Reply via email to