diff options
-rw-r--r-- | include/wordsplit.h | 1 | ||||
-rw-r--r-- | src/wordsplit.c | 30 | ||||
-rw-r--r-- | tests/wordsplit.at | 34 |
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 /* Doubly-linked list of parsed out nodes. */ + char ws_sep[2]; /* Temporary storage used during splitting */ 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, + wsp->ws_sep[0] = wsp->ws_delim[0]; + wsp->ws_sep[1] = 0; + if (!(wsp->ws_flags & WRDSF_COMMENT)) @@ -351,3 +354,3 @@ alloc_space (struct wordsplit *wsp, size_t count) #define _WSNF_DELIM 0x40 /* node is a delimiter */ - +#define _WSNF_CONST 0x80 /* with _WSNF_WORD: v.word is constant */ #define _WSNF_EMPTYOK 0x0100 /* special flag indicating that @@ -443,3 +446,3 @@ wsnode_free (struct wordsplit_node *p) { - if (p->flags & _WSNF_WORD) + if ((p->flags & (_WSNF_WORD|_WSNF_CONST)) == _WSNF_WORD) free (p->v.word); @@ -1252,2 +1255,3 @@ expand_paramv (struct wordsplit *wsp, struct wordsplit_node **ptail, int flg, size_t i; + struct wordsplit_node *tail = *ptail; @@ -1290,2 +1294,24 @@ expand_paramv (struct wordsplit *wsp, struct wordsplit_node **ptail, int flg, wordsplit_free (&ws); + + if (flg & _WSNF_QUOTE) + { + tail = tail->next; + /* Insert delimiters, mark nodes as joinable */ + while (tail != *ptail) + { + struct wordsplit_node *next = tail->next; + struct wordsplit_node *newnode; + + tail->flags |= _WSNF_JOIN; + + if (wsnode_new (wsp, &newnode)) + return 1; + newnode->flags = _WSNF_WORD | _WSNF_CONST | _WSNF_NOEXPAND | _WSNF_JOIN; + newnode->v.word = wsp->ws_sep; + + wsnode_insert (wsp, newnode, tail, 0); + tail = next; + } + } + 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'], [$* -$@], +$@ +"$*" +"$@"], [NF: 5 @@ -989,2 +991,32 @@ NF: 3 TOTAL: 3 +NF: 1 +0: "one two three four five" +TOTAL: 1 +NF: 1 +0: "one two three four five" +TOTAL: 1 +]) + +TESTWSP([$* and $@ in nosplit mode],[], +[-trimnl -nosplit 'one two' three 'four five'], +[$* +$@], +[NF: 1 +0: "one two three four five" +TOTAL: 1 +NF: 1 +0: "one two three four five" +TOTAL: 1 +]) + +TESTWSP([$* and $@ in nosplit mode with delimiter],[], +[-trimnl -nosplit -delim : 'one two' three 'four five'], +[$* +$@], +[NF: 1 +0: "one two:three:four five" +TOTAL: 1 +NF: 1 +0: "one two:three:four five" +TOTAL: 1 ]) |