[prev in list] [next in list] [prev in thread] [next in thread] 

List:       busybox
Subject:    Re: [PATCH] ash fancy prompt expansion
From:       Natanael Copa <natanael.copa () gmail ! com>
Date:       2007-09-24 14:03:45
Message-ID: 1190642625.2784.38.camel () nc ! nor ! wtbts ! org
[Download RAW message or body]

On Fri, 2007-09-21 at 23:36 +0100, Denys Vlasenko wrote:
> On Friday 21 September 2007 20:15, Natanael Copa wrote:
> > > Looks like it got worse, not better...
> > > I am attaching my .config too.
> > 
> > How does it look with your config and without the patch?
> 
> It works without the patch.

Your config (had to disable readahead and taskset), witout patch,
uclibc, r19987:

# env - ./busybox_unstripped ash
/busybox/svn $ set
IFS=' 
'
OPTIND='1'
PATH='/sbin:/usr/sbin:/bin:/usr/bin'
PPID='26186'
PS1='\w \$ '
PS2='> '
PS4='+ '
PWD='/busybox/svn'
/busybox/svn $ whoami
root
/busybox/svn $ 

With patch:

# env - ./busybox_unstripped ash
w # 

Humm...

the problem is in your modified patch:

@@ -9910,6 +9914,11 @@ readtoken1(int firstc, int syntax, char 
        dblquote = (syntax == DQSYNTAX);
        oldstyle = 0;
        prevsyntax = 0;
+#if ENABLE_ASH_EXPAND_PRMT
+       pssyntax = (syntax == PSSYNTAX);
+       if (pssyntax)
+               syntax = DQSYNTAX;
+#endif
        varnest = 0;
        arinest = 0;
        parenlevel = 0;

The

	dblquote = (syntax == DQSYNTAX);

line *must* come after the:

	if (pssyntax)
		syntax = DQSYNTAX;

I think this is a proof of how dirty the code really is.

I was thinking of:
#define DQSYNTAX   0x01    /* in double quotes */
#define SQSYNTAX   0x02    /* in single quotes */
#define ARISYNTAX  0x04    /* in arithmetic */
#define PSSYNTAX   0x08    /* prompt */

and use bit wise operations:
  if (syntax & PSSYNTAX) ...; 
  if (syntax & DQSYNTAX) ...;

But i have no idea what obscure consequences that might have in the
other end of the building. The patch tries to touch as little as
possible. 

Updated patch attatched.

Thanks!
> --
> vda

["busybox-svn-ash-prompt-expansion4.patch" (busybox-svn-ash-prompt-expansion4.patch)]

Index: shell/ash.c
===================================================================
--- shell/ash.c	(revision 19987)
+++ 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
@@ -9886,6 +9887,9 @@
 	smallint dblquote;
 	smallint oldstyle;
 	smallint prevsyntax; /* syntax before arithmetic */
+#if ENABLE_ASH_EXPAND_PRMT
+	smallint pssyntax;   /* we are expanding a prompt string */
+#endif
 	int varnest;         /* levels of variables expansion */
 	int arinest;         /* levels of arithmetic expansion */
 	int parenlevel;      /* levels of parens in arithmetic */
@@ -9907,9 +9911,14 @@
 	startlinno = plinno;
 	bqlist = NULL;
 	quotef = 0;
-	dblquote = (syntax == DQSYNTAX);
 	oldstyle = 0;
 	prevsyntax = 0;
+#if ENABLE_ASH_EXPAND_PRMT
+	pssyntax = (syntax == PSSYNTAX);
+	if (pssyntax)
+		syntax = DQSYNTAX;
+#endif
+	dblquote = (syntax == DQSYNTAX);
 	varnest = 0;
 	arinest = 0;
 	parenlevel = 0;
@@ -9948,6 +9957,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 != '$' && (
@@ -10780,7 +10795,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
busybox@busybox.net
http://busybox.net/cgi-bin/mailman/listinfo/busybox

[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic