From owner-svn-src-all@FreeBSD.ORG Sat Dec 11 22:13:29 2010 Return-Path: Delivered-To: svn-src-all@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 6A12E106566C; Sat, 11 Dec 2010 22:13:29 +0000 (UTC) (envelope-from jilles@FreeBSD.org) Received: from svn.freebsd.org (svn.freebsd.org [IPv6:2001:4f8:fff6::2c]) by mx1.freebsd.org (Postfix) with ESMTP id 4D4B38FC1C; Sat, 11 Dec 2010 22:13:29 +0000 (UTC) Received: from svn.freebsd.org (localhost [127.0.0.1]) by svn.freebsd.org (8.14.3/8.14.3) with ESMTP id oBBMDT8K019670; Sat, 11 Dec 2010 22:13:29 GMT (envelope-from jilles@svn.freebsd.org) Received: (from jilles@localhost) by svn.freebsd.org (8.14.3/8.14.3/Submit) id oBBMDTX0019668; Sat, 11 Dec 2010 22:13:29 GMT (envelope-from jilles@svn.freebsd.org) Message-Id: <201012112213.oBBMDTX0019668@svn.freebsd.org> From: Jilles Tjoelker Date: Sat, 11 Dec 2010 22:13:29 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org X-SVN-Group: head MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Cc: Subject: svn commit: r216384 - head/bin/sh X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 11 Dec 2010 22:13:29 -0000 Author: jilles Date: Sat Dec 11 22:13:29 2010 New Revision: 216384 URL: http://svn.freebsd.org/changeset/base/216384 Log: sh: Replace some macros and repeated code in expand.c with functions. No functional change is intended, but the binary is about 1K smaller on i386. Modified: head/bin/sh/expand.c Modified: head/bin/sh/expand.c ============================================================================== --- head/bin/sh/expand.c Sat Dec 11 20:29:52 2010 (r216383) +++ head/bin/sh/expand.c Sat Dec 11 22:13:29 2010 (r216384) @@ -137,6 +137,18 @@ expandhere(union node *arg, int fd) xwrite(fd, stackblock(), expdest - stackblock()); } +static char * +stputs_quotes(const char *data, const char *syntax, char *p) +{ + while (*data) { + CHECKSTRSPACE(2, p); + if (syntax[(int)*data] == CCTL) + USTPUTC(CTLESC, p); + USTPUTC(*data++, p); + } + return (p); +} +#define STPUTS_QUOTES(data, syntax, p) p = stputs_quotes((data), syntax, p) /* * Perform expansions on an argument, placing the resulting list of arguments @@ -334,11 +346,10 @@ done: if (*home == '\0') goto lose; *p = c; - while ((c = *home++) != '\0') { - if (quotes && SQSYNTAX[(int)c] == CCTL) - STPUTC(CTLESC, expdest); - STPUTC(c, expdest); - } + if (quotes) + STPUTS_QUOTES(home, SQSYNTAX, expdest); + else + STPUTS(home, expdest); return (p); lose: *p = c; @@ -723,12 +734,10 @@ again: /* jump here after setting a vari varlen++; } else { - while (*val) { - if (quotes && - syntax[(int)*val] == CCTL) - STPUTC(CTLESC, expdest); - STPUTC(*val++, expdest); - } + if (quotes) + STPUTS_QUOTES(val, syntax, expdest); + else + STPUTS(val, expdest); } } @@ -877,7 +886,14 @@ varisset(char *name, int nulok) return 1; } - +static void +strtodest(const char *p, int flag, int subtype, int quoted) +{ + if (flag & (EXP_FULL | EXP_CASE) && subtype != VSLENGTH) + STPUTS_QUOTES(p, quoted ? DQSYNTAX : BASESYNTAX, expdest); + else + STPUTS(p, expdest); +} /* * Add the value of a specialized variable to the stack string. @@ -891,21 +907,6 @@ varvalue(char *name, int quoted, int sub int i; char sep; char **ap; - char const *syntax; - -#define STRTODEST(p) \ - do {\ - if (flag & (EXP_FULL | EXP_CASE) && subtype != VSLENGTH) { \ - syntax = quoted? DQSYNTAX : BASESYNTAX; \ - while (*p) { \ - if (syntax[(int)*p] == CCTL) \ - STPUTC(CTLESC, expdest); \ - STPUTC(*p++, expdest); \ - } \ - } else \ - STPUTS(p, expdest); \ - } while (0) - switch (*name) { case '$': @@ -931,7 +932,7 @@ numvar: case '@': if (flag & EXP_FULL && quoted) { for (ap = shellparam.p ; (p = *ap++) != NULL ; ) { - STRTODEST(p); + strtodest(p, flag, subtype, quoted); if (*ap) STPUTC('\0', expdest); } @@ -944,21 +945,21 @@ numvar: else sep = ' '; for (ap = shellparam.p ; (p = *ap++) != NULL ; ) { - STRTODEST(p); + strtodest(p, flag, subtype, quoted); if (*ap && sep) STPUTC(sep, expdest); } break; case '0': p = arg0; - STRTODEST(p); + strtodest(p, flag, subtype, quoted); break; default: if (is_digit(*name)) { num = atoi(name); if (num > 0 && num <= shellparam.nparam) { p = shellparam.p[num - 1]; - STRTODEST(p); + strtodest(p, flag, subtype, quoted); } } break;