Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 6 Dec 2010 23:49:27 +0000 (UTC)
From:      Jilles Tjoelker <jilles@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org
Subject:   svn commit: r216246 - head/bin/sh
Message-ID:  <201012062349.oB6NnRfi048347@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jilles
Date: Mon Dec  6 23:49:27 2010
New Revision: 216246
URL: http://svn.freebsd.org/changeset/base/216246

Log:
  sh: Improve internal-representation-to-text code to avoid binary output.
  
  The code to translate the internal representation to text did not know about
  various additions to the internal representation since the original ash and
  therefore wrote binary stuff to the terminal.
  
  The code is used in the jobs command and similar output.
  
  Note that the output is far from complete and mostly serves for recognition
  purposes.

Modified:
  head/bin/sh/jobs.c

Modified: head/bin/sh/jobs.c
==============================================================================
--- head/bin/sh/jobs.c	Mon Dec  6 22:45:29 2010	(r216245)
+++ head/bin/sh/jobs.c	Mon Dec  6 23:49:27 2010	(r216246)
@@ -1314,13 +1314,46 @@ cmdputs(const char *s)
 			if (--cmdnleft > 0)
 				*q++ = '{';
 			subtype = *p++;
+			if ((subtype & VSTYPE) == VSLENGTH && --cmdnleft > 0)
+				*q++ = '#';
 		} else if (c == '=' && subtype != 0) {
-			*q++ = "}-+?="[(subtype & VSTYPE) - VSNORMAL];
+			*q = "}-+?=##%%\0X"[(subtype & VSTYPE) - VSNORMAL];
+			if (*q)
+				q++;
+			else
+				cmdnleft++;
+			if (((subtype & VSTYPE) == VSTRIMLEFTMAX ||
+			    (subtype & VSTYPE) == VSTRIMRIGHTMAX) &&
+			    --cmdnleft > 0)
+				*q = q[-1], q++;
 			subtype = 0;
 		} else if (c == CTLENDVAR) {
 			*q++ = '}';
-		} else if (c == CTLBACKQ || c == CTLBACKQ+CTLQUOTE)
-			cmdnleft++;		/* ignore it */
+		} else if (c == CTLBACKQ || c == CTLBACKQ+CTLQUOTE) {
+			cmdnleft -= 5;
+			if (cmdnleft > 0) {
+				*q++ = '$';
+				*q++ = '(';
+				*q++ = '.';
+				*q++ = '.';
+				*q++ = '.';
+				*q++ = ')';
+			}
+		} else if (c == CTLARI) {
+			cmdnleft -= 2;
+			if (cmdnleft > 0) {
+				*q++ = '$';
+				*q++ = '(';
+				*q++ = '(';
+			}
+			p++;
+		} else if (c == CTLENDARI) {
+			if (--cmdnleft > 0) {
+				*q++ = ')';
+				*q++ = ')';
+			}
+		} else if (c == CTLQUOTEMARK || c == CTLQUOTEEND)
+			cmdnleft++; /* ignore */
 		else
 			*q++ = c;
 		if (--cmdnleft <= 0) {



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?201012062349.oB6NnRfi048347>