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 | |||
@@ -256,6 +256,9 @@ wordsplit_init (struct wordsplit *wsp, const char *input, size_t len, | |||
256 | if (!(wsp->ws_flags & WRDSF_DELIM)) | 256 | if (!(wsp->ws_flags & WRDSF_DELIM)) |
257 | wsp->ws_delim = " \t\n"; | 257 | wsp->ws_delim = " \t\n"; |
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)) |
260 | wsp->ws_comment = NULL; | 263 | wsp->ws_comment = NULL; |
261 | 264 | ||
@@ -349,7 +352,7 @@ alloc_space (struct wordsplit *wsp, size_t count) | |||
349 | #define _WSNF_JOIN 0x10 /* node must be joined with the next node */ | 352 | #define _WSNF_JOIN 0x10 /* node must be joined with the next node */ |
350 | #define _WSNF_SEXP 0x20 /* is a sed expression */ | 353 | #define _WSNF_SEXP 0x20 /* is a sed expression */ |
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 |
354 | wordsplit_add_segm must add the | 357 | wordsplit_add_segm must add the |
355 | segment even if it is empty */ | 358 | segment even if it is empty */ |
@@ -441,7 +444,7 @@ wsnode_new (struct wordsplit *wsp, struct wordsplit_node **pnode) | |||
441 | static void | 444 | static void |
442 | wsnode_free (struct wordsplit_node *p) | 445 | 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); |
446 | free (p); | 449 | free (p); |
447 | } | 450 | } |
@@ -1250,6 +1253,7 @@ expand_paramv (struct wordsplit *wsp, struct wordsplit_node **ptail, int flg, | |||
1250 | | (WSP_RETURN_DELIMS (wsp) ? WRDSF_RETURN_DELIMS : 0) | 1253 | | (WSP_RETURN_DELIMS (wsp) ? WRDSF_RETURN_DELIMS : 0) |
1251 | | (q ? WRDSF_NOSPLIT : 0); | 1254 | | (q ? WRDSF_NOSPLIT : 0); |
1252 | size_t i; | 1255 | size_t i; |
1256 | struct wordsplit_node *tail = *ptail; | ||
1253 | 1257 | ||
1254 | for (i = 0; i < wsp->ws_paramc; i++) | 1258 | for (i = 0; i < wsp->ws_paramc; i++) |
1255 | { | 1259 | { |
@@ -1288,6 +1292,28 @@ expand_paramv (struct wordsplit *wsp, struct wordsplit_node **ptail, int flg, | |||
1288 | } | 1292 | } |
1289 | if (wsflags & WRDSF_REUSE) | 1293 | if (wsflags & WRDSF_REUSE) |
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; |
1292 | } | 1318 | } |
1293 | 1319 | ||