Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 21 Oct 2010 01:13:41 +0000 (UTC)
From:      "David E. O'Brien" <obrien@FreeBSD.org>
To:        src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-stable@freebsd.org, svn-src-stable-8@freebsd.org
Subject:   svn commit: r214123 - stable/8/bin/sh
Message-ID:  <201010210113.o9L1Df79074263@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: obrien
Date: Thu Oct 21 01:13:41 2010
New Revision: 214123
URL: http://svn.freebsd.org/changeset/base/214123

Log:
  MFC
    r211281: don't shadow sigset
    r212243: improve comments in expand.c
    r213925: use <stddef.h> rather than <sys/stddef.h>

Modified:
  stable/8/bin/sh/error.c
  stable/8/bin/sh/expand.c
Directory Properties:
  stable/8/bin/sh/   (props changed)

Modified: stable/8/bin/sh/error.c
==============================================================================
--- stable/8/bin/sh/error.c	Wed Oct 20 23:41:16 2010	(r214122)
+++ stable/8/bin/sh/error.c	Thu Oct 21 01:13:41 2010	(r214123)
@@ -98,7 +98,7 @@ exraise(int e)
 void
 onint(void)
 {
-	sigset_t sigset;
+	sigset_t sigs;
 
 	/*
 	 * The !in_dotrap here is safe.  The only way we can arrive here
@@ -111,8 +111,8 @@ onint(void)
 		return;
 	}
 	intpending = 0;
-	sigemptyset(&sigset);
-	sigprocmask(SIG_SETMASK, &sigset, NULL);
+	sigemptyset(&sigs);
+	sigprocmask(SIG_SETMASK, &sigs, NULL);
 
 	/*
 	 * This doesn't seem to be needed, since main() emits a newline.

Modified: stable/8/bin/sh/expand.c
==============================================================================
--- stable/8/bin/sh/expand.c	Wed Oct 20 23:41:16 2010	(r214122)
+++ stable/8/bin/sh/expand.c	Thu Oct 21 01:13:41 2010	(r214123)
@@ -139,12 +139,18 @@ expandhere(union node *arg, int fd)
 
 
 /*
- * Perform variable substitution and command substitution on an argument,
- * placing the resulting list of arguments in arglist.  If EXP_FULL is true,
- * perform splitting and file name expansion.  When arglist is NULL, perform
- * here document expansion.
+ * Perform expansions on an argument, placing the resulting list of arguments
+ * in arglist.  Parameter expansion, command substitution and arithmetic
+ * expansion are always performed; additional expansions can be requested
+ * via flag (EXP_*).
+ * The result is left in the stack string.
+ * When arglist is NULL, perform here document expansion.  A partial result
+ * may be written to herefd, which is then not included in the stack string.
+ *
+ * Caution: this function uses global state and is not reentrant.
+ * However, a new invocation after an interrupted invocation is safe
+ * and will reset the global state for the new call.
  */
-
 void
 expandarg(union node *arg, struct arglist *arglist, int flag)
 {
@@ -196,11 +202,14 @@ expandarg(union node *arg, struct arglis
 
 
 /*
- * Perform variable and command substitution.  If EXP_FULL is set, output CTLESC
- * characters to allow for further processing.  Otherwise treat
- * $@ like $* since no splitting will be performed.
+ * Perform parameter expansion, command substitution and arithmetic
+ * expansion, and tilde expansion if requested via EXP_TILDE/EXP_VARTILDE.
+ * Processing ends at a CTLENDVAR character as well as '\0'.
+ * This is used to expand word in ${var+word} etc.
+ * If EXP_FULL, EXP_CASE or EXP_REDIR are set, keep and/or generate CTLESC
+ * characters to allow for further processing.
+ * If EXP_FULL is set, also preserve CTLQUOTEMARK characters.
  */
-
 static void
 argstr(char *p, int flag)
 {
@@ -213,7 +222,7 @@ argstr(char *p, int flag)
 	for (;;) {
 		switch (c = *p++) {
 		case '\0':
-		case CTLENDVAR: /* ??? */
+		case CTLENDVAR:
 			goto breakloop;
 		case CTLQUOTEMARK:
 			/* "$@" syntax adherence hack */
@@ -263,6 +272,10 @@ argstr(char *p, int flag)
 breakloop:;
 }
 
+/*
+ * Perform tilde expansion, placing the result in the stack string and
+ * returning the next position in the input string to process.
+ */
 static char *
 exptilde(char *p, int flag)
 {
@@ -363,12 +376,11 @@ expari(int flag)
 	int quotes = flag & (EXP_FULL | EXP_CASE | EXP_REDIR);
 	int quoted;
 
-
 	/*
 	 * This routine is slightly over-complicated for
 	 * efficiency.  First we make sure there is
 	 * enough space for the result, which may be bigger
-	 * than the expression if we add exponentiation.  Next we
+	 * than the expression.  Next we
 	 * scan backwards looking for the start of arithmetic.  If the
 	 * next previous character is a CTLESC character, then we
 	 * have to rescan starting from the beginning since CTLESC
@@ -407,9 +419,8 @@ expari(int flag)
 
 
 /*
- * Expand stuff in backwards quotes.
+ * Perform command substitution.
  */
-
 static void
 expbackq(union node *cmd, int quoted, int flag)
 {
@@ -966,6 +977,12 @@ recordregion(int start, int end, int inq
  * Break the argument string into pieces based upon IFS and add the
  * strings to the argument list.  The regions of the string to be
  * searched for IFS characters have been stored by recordregion.
+ * CTLESC characters are preserved but have little effect in this pass
+ * other than escaping CTL* characters.  In particular, they do not escape
+ * IFS characters: that should be done with the ifsregion mechanism.
+ * CTLQUOTEMARK characters are used to preserve empty quoted strings.
+ * This pass treats them as a regular character, making the string non-empty.
+ * Later, they are removed along with the other CTL* characters.
  */
 static void
 ifsbreakup(char *string, struct arglist *arglist)
@@ -1067,10 +1084,10 @@ ifsbreakup(char *string, struct arglist 
 }
 
 
-
 /*
- * Expand shell metacharacters.  At this point, the only control characters
- * should be escapes.  The results are stored in the list exparg.
+ * Perform pathname generation and remove control characters.
+ * At this point, the only control characters should be CTLESC and CTLQUOTEMARK.
+ * The results are stored in the list exparg.
  */
 
 static char expdir[PATH_MAX];
@@ -1475,7 +1492,7 @@ breakloop:
 
 
 /*
- * Remove any CTLESC characters from a string.
+ * Remove any CTLESC and CTLQUOTEMARK characters from a string.
  */
 
 void



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