summaryrefslogtreecommitdiffabout
authorSergey Poznyakoff <gray@gnu.org>2019-05-14 19:25:26 (GMT)
committer Sergey Poznyakoff <gray@gnu.org>2019-05-14 19:25:26 (GMT)
commit1658f5685bd396ce6bfd8e4822f4a9363eb4a4c9 (patch) (unidiff)
treeee5e39a9f040691da09b9a569b6f000d11e1ca6a
parent39beda10e855d265b5af74ea53a5d7a89a91296a (diff)
downloadgrecs-1658f5685bd396ce6bfd8e4822f4a9363eb4a4c9.tar.gz
grecs-1658f5685bd396ce6bfd8e4822f4a9363eb4a4c9.tar.bz2
Fix behaviour of $* and $@ in quoted context
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--include/wordsplit.h1
-rw-r--r--src/wordsplit.c30
-rw-r--r--tests/wordsplit.at34
3 files changed, 62 insertions, 3 deletions
diff --git a/include/wordsplit.h b/include/wordsplit.h
index d4975b3..2fac3c6 100644
--- a/include/wordsplit.h
+++ b/include/wordsplit.h
@@ -122,2 +122,3 @@ struct wordsplit
122 /* Doubly-linked list of parsed out nodes. */ 122 /* Doubly-linked list of parsed out nodes. */
123 char ws_sep[2]; /* Temporary storage used during splitting */
123 int ws_lvl; /* Invocation nesting level. */ 124 int ws_lvl; /* Invocation nesting level. */
diff --git a/src/wordsplit.c b/src/wordsplit.c
index f563725..4e633fa 100644
--- a/src/wordsplit.c
+++ b/src/wordsplit.c
@@ -258,2 +258,5 @@ wordsplit_init (struct wordsplit *wsp, const char *input, size_t len,
258 258
259 wsp->ws_sep[0] = wsp->ws_delim[0];
260 wsp->ws_sep[1] = 0;
261
259 if (!(wsp->ws_flags & WRDSF_COMMENT)) 262 if (!(wsp->ws_flags & WRDSF_COMMENT))
@@ -351,3 +354,3 @@ alloc_space (struct wordsplit *wsp, size_t count)
351#define _WSNF_DELIM 0x40 /* node is a delimiter */ 354#define _WSNF_DELIM 0x40 /* node is a delimiter */
352 355#define _WSNF_CONST 0x80 /* with _WSNF_WORD: v.word is constant */
353 #define _WSNF_EMPTYOK 0x0100/* special flag indicating that 356 #define _WSNF_EMPTYOK 0x0100/* special flag indicating that
@@ -443,3 +446,3 @@ wsnode_free (struct wordsplit_node *p)
443{ 446{
444 if (p->flags & _WSNF_WORD) 447 if ((p->flags & (_WSNF_WORD|_WSNF_CONST)) == _WSNF_WORD)
445 free (p->v.word); 448 free (p->v.word);
@@ -1252,2 +1255,3 @@ expand_paramv (struct wordsplit *wsp, struct wordsplit_node **ptail, int flg,
1252 size_t i; 1255 size_t i;
1256 struct wordsplit_node *tail = *ptail;
1253 1257
@@ -1290,2 +1294,24 @@ expand_paramv (struct wordsplit *wsp, struct wordsplit_node **ptail, int flg,
1290 wordsplit_free (&ws); 1294 wordsplit_free (&ws);
1295
1296 if (flg & _WSNF_QUOTE)
1297 {
1298 tail = tail->next;
1299 /* Insert delimiters, mark nodes as joinable */
1300 while (tail != *ptail)
1301 {
1302 struct wordsplit_node *next = tail->next;
1303 struct wordsplit_node *newnode;
1304
1305 tail->flags |= _WSNF_JOIN;
1306
1307 if (wsnode_new (wsp, &newnode))
1308 return 1;
1309 newnode->flags = _WSNF_WORD | _WSNF_CONST | _WSNF_NOEXPAND | _WSNF_JOIN;
1310 newnode->v.word = wsp->ws_sep;
1311
1312 wsnode_insert (wsp, newnode, tail, 0);
1313 tail = next;
1314 }
1315 }
1316
1291 return 0; 1317 return 0;
diff --git a/tests/wordsplit.at b/tests/wordsplit.at
index 0a9c4d6..0a7d7db 100644
--- a/tests/wordsplit.at
+++ b/tests/wordsplit.at
@@ -976,3 +976,5 @@ TESTWSP([$* and $@],[],['one two' three 'four five'],
976[$* 976[$*
977$@], 977$@
978"$*"
979"$@"],
978[NF: 5 980[NF: 5
@@ -989,2 +991,32 @@ NF: 3
989TOTAL: 3 991TOTAL: 3
992NF: 1
9930: "one two three four five"
994TOTAL: 1
995NF: 1
9960: "one two three four five"
997TOTAL: 1
998])
999
1000TESTWSP([$* and $@ in nosplit mode],[],
1001[-trimnl -nosplit 'one two' three 'four five'],
1002[$*
1003$@],
1004[NF: 1
10050: "one two three four five"
1006TOTAL: 1
1007NF: 1
10080: "one two three four five"
1009TOTAL: 1
1010])
1011
1012TESTWSP([$* and $@ in nosplit mode with delimiter],[],
1013[-trimnl -nosplit -delim : 'one two' three 'four five'],
1014[$*
1015$@],
1016[NF: 1
10170: "one two:three:four five"
1018TOTAL: 1
1019NF: 1
10200: "one two:three:four five"
1021TOTAL: 1
990]) 1022])

Return to:

Send suggestions and report system problems to the System administrator.