svn commit: r214208 - stable/7/bin/sh

David E. O'Brien obrien at FreeBSD.org
Fri Oct 22 17:49:11 UTC 2010


Author: obrien
Date: Fri Oct 22 17:49:11 2010
New Revision: 214208
URL: http://svn.freebsd.org/changeset/base/214208

Log:
  MFC
    r212243: improve comments in expand.c
    r214100: MFC r213815: only need to look as far as '..' to find 'test/'
    r214104:
      r213774: DEBUG_FLAGS should be used to enable extra debugging rather than
               frobbing CFLAGS directly.
      r213798: do not inline static functions if debugging

Modified:
  stable/7/bin/sh/Makefile
  stable/7/bin/sh/expand.c
Directory Properties:
  stable/7/bin/sh/   (props changed)

Modified: stable/7/bin/sh/Makefile
==============================================================================
--- stable/7/bin/sh/Makefile	Fri Oct 22 16:00:45 2010	(r214207)
+++ stable/7/bin/sh/Makefile	Fri Oct 22 17:49:11 2010	(r214208)
@@ -21,12 +21,12 @@ LDADD= -ll -ledit -ltermcap
 LFLAGS= -8	# 8-bit lex scanner for arithmetic
 CFLAGS+=-DSHELL -I. -I${.CURDIR}
 # for debug:
-# CFLAGS+= -g -DDEBUG=2
+# DEBUG_FLAGS+= -g -DDEBUG=2 -fno-inline
 WARNS?=	2
 WFORMAT=0
 
 .PATH:	${.CURDIR}/bltin \
-	${.CURDIR}/../../bin/test
+	${.CURDIR}/../test
 
 CLEANFILES+= mkinit mkinit.o mknodes mknodes.o \
 	mksyntax mksyntax.o

Modified: stable/7/bin/sh/expand.c
==============================================================================
--- stable/7/bin/sh/expand.c	Fri Oct 22 16:00:45 2010	(r214207)
+++ stable/7/bin/sh/expand.c	Fri Oct 22 17:49:11 2010	(r214208)
@@ -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)
 {
@@ -961,6 +972,12 @@ recordregion(int start, int end, int nul
  * 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)
@@ -1048,15 +1065,14 @@ 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.
- */
-
 STATIC char expdir[PATH_MAX];
 #define expdir_end (expdir + sizeof(expdir))
 
+/*
+ * 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 void
 expandmeta(struct strlist *str, int flag __unused)
 {
@@ -1456,7 +1472,7 @@ breakloop:
 
 
 /*
- * Remove any CTLESC characters from a string.
+ * Remove any CTLESC and CTLQUOTEMARK characters from a string.
  */
 
 void


More information about the svn-src-stable-7 mailing list