aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2020-02-20 10:06:20 +0100
committerDenys Vlasenko <vda.linux@googlemail.com>2020-02-20 10:37:30 +0100
commitecc85832f8b4d8278b0a17aa62b0c8a9f81461e4 (patch)
tree9ce4dce5d3cc149440408ada6e40c84ab4f26ac3
parente2dd2afc8e4dbcf1061818adc68d2e74a1fa64d3 (diff)
downloadbusybox-w32-ecc85832f8b4d8278b0a17aa62b0c8a9f81461e4.tar.gz
busybox-w32-ecc85832f8b4d8278b0a17aa62b0c8a9f81461e4.tar.bz2
busybox-w32-ecc85832f8b4d8278b0a17aa62b0c8a9f81461e4.zip
ash: expand: Merge syntax/quotes in memtodest with flags
Upstream commit: Date: Mon, 28 May 2018 00:17:39 +0800 expand: Merge syntax/quotes in memtodest with flags The function arguments syntax and quotes are both derived from the expansion flags. As syntax is only used by memtodest we do not need to maintain it outside of the function at all. The only place that uses something other than BASESYNTAX or DQSYNTAX is exptilde. However in that case DQSYNTAX has exactly the same effect as SQSYNTAX. This patch merges these two arguments into a single flags. The macro QUOTES_KEEPNUL has been renamed to EXP_KEEPNUL in order to keep the namespace separate. Signed-off-by: Herbert Xu <herbert@gondor.apana.org.au> Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-rw-r--r--shell/ash.c40
1 files changed, 19 insertions, 21 deletions
diff --git a/shell/ash.c b/shell/ash.c
index 81d2422d6..6087416ab 100644
--- a/shell/ash.c
+++ b/shell/ash.c
@@ -6030,6 +6030,8 @@ static int substr_atoi(const char *s)
6030#define EXP_VARTILDE2 0x20 /* expand tildes after colons only */ 6030#define EXP_VARTILDE2 0x20 /* expand tildes after colons only */
6031#define EXP_WORD 0x40 /* expand word in parameter expansion */ 6031#define EXP_WORD 0x40 /* expand word in parameter expansion */
6032#define EXP_QUOTED 0x100 /* expand word in double quotes */ 6032#define EXP_QUOTED 0x100 /* expand word in double quotes */
6033#define EXP_KEEPNUL 0x200 /* do not skip NUL characters */
6034
6033/* 6035/*
6034 * rmescape() flags 6036 * rmescape() flags
6035 */ 6037 */
@@ -6040,8 +6042,6 @@ static int substr_atoi(const char *s)
6040 6042
6041/* Add CTLESC when necessary. */ 6043/* Add CTLESC when necessary. */
6042#define QUOTES_ESC (EXP_FULL | EXP_CASE) 6044#define QUOTES_ESC (EXP_FULL | EXP_CASE)
6043/* Do not skip NUL characters. */
6044#define QUOTES_KEEPNUL EXP_TILDE
6045 6045
6046/* 6046/*
6047 * Structure specifying which parts of the string should be searched 6047 * Structure specifying which parts of the string should be searched
@@ -6348,27 +6348,28 @@ preglob(const char *pattern, int flag)
6348 * Put a string on the stack. 6348 * Put a string on the stack.
6349 */ 6349 */
6350static void 6350static void
6351memtodest(const char *p, size_t len, int syntax, int quotes) 6351memtodest(const char *p, size_t len, int flags)
6352{ 6352{
6353 int syntax = flags & EXP_QUOTED ? DQSYNTAX : BASESYNTAX;
6353 char *q; 6354 char *q;
6354 6355
6355 if (!len) 6356 if (!len)
6356 return; 6357 return;
6357 6358
6358 q = makestrspace((quotes & QUOTES_ESC) ? len * 2 : len, expdest); 6359 q = makestrspace(len * 2, expdest);
6359 6360
6360 do { 6361 do {
6361 unsigned char c = *p++; 6362 unsigned char c = *p++;
6362 if (c) { 6363 if (c) {
6363 if (quotes & QUOTES_ESC) { 6364 if (flags & QUOTES_ESC) {
6364 int n = SIT(c, syntax); 6365 int n = SIT(c, syntax);
6365 if (n == CCTL 6366 if (n == CCTL
6366 || (syntax != BASESYNTAX && n == CBACK) 6367 || ((flags & EXP_QUOTED) && n == CBACK)
6367 ) { 6368 ) {
6368 USTPUTC(CTLESC, q); 6369 USTPUTC(CTLESC, q);
6369 } 6370 }
6370 } 6371 }
6371 } else if (!(quotes & QUOTES_KEEPNUL)) 6372 } else if (!(flags & EXP_KEEPNUL))
6372 continue; 6373 continue;
6373 USTPUTC(c, q); 6374 USTPUTC(c, q);
6374 } while (--len); 6375 } while (--len);
@@ -6377,10 +6378,10 @@ memtodest(const char *p, size_t len, int syntax, int quotes)
6377} 6378}
6378 6379
6379static size_t 6380static size_t
6380strtodest(const char *p, int syntax, int quotes) 6381strtodest(const char *p, int flags)
6381{ 6382{
6382 size_t len = strlen(p); 6383 size_t len = strlen(p);
6383 memtodest(p, len, syntax, quotes); 6384 memtodest(p, len, flags);
6384 return len; 6385 return len;
6385} 6386}
6386 6387
@@ -6448,13 +6449,12 @@ removerecordregions(int endoff)
6448} 6449}
6449 6450
6450static char * 6451static char *
6451exptilde(char *startp, char *p, int flags) 6452exptilde(char *startp, char *p, int flag)
6452{ 6453{
6453 unsigned char c; 6454 unsigned char c;
6454 char *name; 6455 char *name;
6455 struct passwd *pw; 6456 struct passwd *pw;
6456 const char *home; 6457 const char *home;
6457 int quotes = flags & QUOTES_ESC;
6458 6458
6459 name = p + 1; 6459 name = p + 1;
6460 6460
@@ -6465,7 +6465,7 @@ exptilde(char *startp, char *p, int flags)
6465 case CTLQUOTEMARK: 6465 case CTLQUOTEMARK:
6466 return startp; 6466 return startp;
6467 case ':': 6467 case ':':
6468 if (flags & EXP_VARTILDE) 6468 if (flag & EXP_VARTILDE)
6469 goto done; 6469 goto done;
6470 break; 6470 break;
6471 case '/': 6471 case '/':
@@ -6486,7 +6486,7 @@ exptilde(char *startp, char *p, int flags)
6486 if (!home) 6486 if (!home)
6487 goto lose; 6487 goto lose;
6488 *p = c; 6488 *p = c;
6489 strtodest(home, SQSYNTAX, quotes); 6489 strtodest(home, flag | EXP_QUOTED);
6490 return p; 6490 return p;
6491 lose: 6491 lose:
6492 *p = c; 6492 *p = c;
@@ -6586,7 +6586,6 @@ expbackq(union node *cmd, int flag)
6586 char *p; 6586 char *p;
6587 char *dest; 6587 char *dest;
6588 int startloc; 6588 int startloc;
6589 int syntax = flag & EXP_QUOTED ? DQSYNTAX : BASESYNTAX;
6590 struct stackmark smark; 6589 struct stackmark smark;
6591 6590
6592 INT_OFF; 6591 INT_OFF;
@@ -6600,7 +6599,7 @@ expbackq(union node *cmd, int flag)
6600 if (i == 0) 6599 if (i == 0)
6601 goto read; 6600 goto read;
6602 for (;;) { 6601 for (;;) {
6603 memtodest(p, i, syntax, flag & QUOTES_ESC); 6602 memtodest(p, i, flag);
6604 read: 6603 read:
6605 if (in.fd < 0) 6604 if (in.fd < 0)
6606 break; 6605 break;
@@ -7309,11 +7308,10 @@ varvalue(char *name, int varflags, int flags, int quoted)
7309 int sep; 7308 int sep;
7310 int subtype = varflags & VSTYPE; 7309 int subtype = varflags & VSTYPE;
7311 int discard = subtype == VSPLUS || subtype == VSLENGTH; 7310 int discard = subtype == VSPLUS || subtype == VSLENGTH;
7312 int quotes = (discard ? 0 : (flags & QUOTES_ESC)) | QUOTES_KEEPNUL;
7313 int syntax;
7314 7311
7312 flags |= EXP_KEEPNUL;
7313 flags &= discard ? ~QUOTES_ESC : ~0;
7315 sep = (flags & EXP_FULL) << CHAR_BIT; 7314 sep = (flags & EXP_FULL) << CHAR_BIT;
7316 syntax = quoted ? DQSYNTAX : BASESYNTAX;
7317 7315
7318 switch (*name) { 7316 switch (*name) {
7319 case '$': 7317 case '$':
@@ -7379,11 +7377,11 @@ varvalue(char *name, int varflags, int flags, int quoted)
7379 if (!ap) 7377 if (!ap)
7380 return -1; 7378 return -1;
7381 while ((p = *ap++) != NULL) { 7379 while ((p = *ap++) != NULL) {
7382 len += strtodest(p, syntax, quotes); 7380 len += strtodest(p, flags);
7383 7381
7384 if (*ap && sep) { 7382 if (*ap && sep) {
7385 len++; 7383 len++;
7386 memtodest(&sepc, 1, syntax, quotes); 7384 memtodest(&sepc, 1, flags);
7387 } 7385 }
7388 } 7386 }
7389 break; 7387 break;
@@ -7410,7 +7408,7 @@ varvalue(char *name, int varflags, int flags, int quoted)
7410 if (!p) 7408 if (!p)
7411 return -1; 7409 return -1;
7412 7410
7413 len = strtodest(p, syntax, quotes); 7411 len = strtodest(p, flags);
7414#if ENABLE_UNICODE_SUPPORT 7412#if ENABLE_UNICODE_SUPPORT
7415 if (subtype == VSLENGTH && len > 0) { 7413 if (subtype == VSLENGTH && len > 0) {
7416 reinit_unicode_for_ash(); 7414 reinit_unicode_for_ash();