diff options
Diffstat (limited to 'src/wordsplit.c')
-rw-r--r-- | src/wordsplit.c | 30 |
1 files changed, 28 insertions, 2 deletions
diff --git a/src/wordsplit.c b/src/wordsplit.c index f563725..4e633fa 100644 --- a/src/wordsplit.c +++ b/src/wordsplit.c @@ -257,4 +257,7 @@ wordsplit_init (struct wordsplit *wsp, const char *input, size_t len, wsp->ws_delim = " \t\n"; + wsp->ws_sep[0] = wsp->ws_delim[0]; + wsp->ws_sep[1] = 0; + if (!(wsp->ws_flags & WRDSF_COMMENT)) wsp->ws_comment = NULL; @@ -350,5 +353,5 @@ alloc_space (struct wordsplit *wsp, size_t count) #define _WSNF_SEXP 0x20 /* is a sed expression */ #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 wordsplit_add_segm must add the @@ -442,5 +445,5 @@ static void wsnode_free (struct wordsplit_node *p) { - if (p->flags & _WSNF_WORD) + if ((p->flags & (_WSNF_WORD|_WSNF_CONST)) == _WSNF_WORD) free (p->v.word); free (p); @@ -1251,4 +1254,5 @@ expand_paramv (struct wordsplit *wsp, struct wordsplit_node **ptail, int flg, | (q ? WRDSF_NOSPLIT : 0); size_t i; + struct wordsplit_node *tail = *ptail; for (i = 0; i < wsp->ws_paramc; i++) @@ -1289,4 +1293,26 @@ expand_paramv (struct wordsplit *wsp, struct wordsplit_node **ptail, int flg, if (wsflags & WRDSF_REUSE) 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; } |