Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 4 Mar 2014 22:30:38 +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: r262755 - head/bin/sh
Message-ID:  <201403042230.s24MUckS044898@svn.freebsd.org>

next in thread | raw e-mail | index | archive | help
Author: jilles
Date: Tue Mar  4 22:30:38 2014
New Revision: 262755
URL: http://svnweb.freebsd.org/changeset/base/262755

Log:
  sh: Make argstr() return where it stopped and simplify expari() using this.

Modified:
  head/bin/sh/expand.c

Modified: head/bin/sh/expand.c
==============================================================================
--- head/bin/sh/expand.c	Tue Mar  4 21:51:11 2014	(r262754)
+++ head/bin/sh/expand.c	Tue Mar  4 22:30:38 2014	(r262755)
@@ -98,7 +98,7 @@ static struct ifsregion ifsfirst;	/* fir
 static struct ifsregion *ifslastp;	/* last struct in list */
 static struct arglist exparg;		/* holds expanded arg list */
 
-static void argstr(char *, int);
+static char *argstr(char *, int);
 static char *exptilde(char *, int);
 static char *expari(char *);
 static void expbackq(union node *, int, int);
@@ -213,7 +213,7 @@ expandarg(union node *arg, struct arglis
  * characters to allow for further processing.
  * If EXP_FULL is set, also preserve CTLQUOTEMARK characters.
  */
-static void
+static char *
 argstr(char *p, int flag)
 {
 	char c;
@@ -231,9 +231,10 @@ argstr(char *p, int flag)
 		CHECKSTRSPACE(2, expdest);
 		switch (c = *p++) {
 		case '\0':
+			return (p - 1);
 		case CTLENDVAR:
 		case CTLENDARI:
-			goto breakloop;
+			return (p);
 		case CTLQUOTEMARK:
 			lit_quoted = 1;
 			/* "$@" syntax adherence hack */
@@ -290,7 +291,6 @@ argstr(char *p, int flag)
 				    expdest - stackblock(), 0);
 		}
 	}
-breakloop:;
 }
 
 /*
@@ -399,13 +399,11 @@ expari(char *p)
 	arith_t result;
 	int begoff;
 	int quoted;
-	int c;
-	int nesting;
 	int adj;
 
 	quoted = *p++ == '"';
 	begoff = expdest - stackblock();
-	argstr(p, 0);
+	p = argstr(p, 0);
 	removerecordregions(begoff);
 	STPUTC('\0', expdest);
 	start = stackblock() + begoff;
@@ -424,20 +422,6 @@ expari(char *p)
 	STADJUST(adj, expdest);
 	if (!quoted)
 		recordregion(begoff, expdest - stackblock(), 0);
-	nesting = 1;
-	while (nesting > 0) {
-		c = *p++;
-		if (c == CTLESC)
-			p++;
-		else if (c == CTLARI)
-			nesting++;
-		else if (c == CTLENDARI)
-			nesting--;
-		else if (c == CTLVAR)
-			p++; /* ignore variable substitution byte */
-		else if (c == '\0')
-			return p - 1;
-	}
 	return p;
 }
 



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