diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2010-10-29 10:50:11 +0300 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2010-10-29 10:50:11 +0300 |
commit | f49d4057c49022a646c8dbe2d203e8c374bb7427 (patch) | |
tree | 42937fb3a2720fb7780747a62c060bbe3abffb19 /libmailutils/string | |
parent | 5dd9e9c13bafea91ccdc97a3afcbc13a8762aee1 (diff) | |
download | mailutils-f49d4057c49022a646c8dbe2d203e8c374bb7427.tar.gz mailutils-f49d4057c49022a646c8dbe2d203e8c374bb7427.tar.bz2 |
Fixes in wordsplit. Use wordsplit instead of vartab in movemail.
Eventually this will lead to vartab fading out until it is removed
in some point in the future. Wordsplit provides a much better
variable substitution mechanism.
* include/mailutils/wordsplit.h (mu_wordsplit) <ws_getvar>: Change
signature.
<ws_closure>: New member.
(MU_WRDSF_CLOSURE): New flag.
* libmailutils/string/wordsplit.c (mu_wordsplit_init): Initialize
ws_closure to NULL, unless MU_WRDSF_CLOSURE is set.
Do not modify ws_wordn if MU_WRDSF_DOOFFS is set.
(wsnode_remove): Clear _WSNF_JOIN on the previous node if the node
being deleted is the last one in chain.
(expvar): Pass ws_closure as 3rd argument to ws_getvar.
Insert a NULL node if the variable is not defined.
* movemail/movemail.c: Use wordsplit instead of vartab. Note a side
effect: the "source:*" and "dest:*" variables are now written as
"source_*" and "dest_*", correspondingly.
(movemail_getvar_closure): New structure.
(DCL_VTX): Remove macro and its uses.
(get_url_part, movemail_getvar): New functions.
(set_program_id): Rewrite using wordsplit.
Diffstat (limited to 'libmailutils/string')
-rw-r--r-- | libmailutils/string/wordsplit.c | 23 |
1 files changed, 18 insertions, 5 deletions
diff --git a/libmailutils/string/wordsplit.c b/libmailutils/string/wordsplit.c index 301ab005f..2121c7766 100644 --- a/libmailutils/string/wordsplit.c +++ b/libmailutils/string/wordsplit.c @@ -151,9 +151,10 @@ mu_wordsplit_init (struct mu_wordsplit *wsp, const char *input, size_t len, wsp->ws_wordc = 0; wsp->ws_wordn = 0; } - if (wsp->ws_flags & MU_WRDSF_DOOFFS) - wsp->ws_wordn += wsp->ws_offs; + if (!(wsp->ws_flags & MU_WRDSF_CLOSURE)) + wsp->ws_closure = NULL; + wsp->ws_endp = 0; wsp->ws_errno = 0; wsp->ws_head = wsp->ws_tail = NULL; @@ -311,7 +312,11 @@ wsnode_remove (struct mu_wordsplit *wsp, struct mu_wordsplit_node *node) p = node->prev; if (p) - p->next = node->next; + { + p->next = node->next; + if (!node->next) + p->flags &= ~_WSNF_JOIN; + } else wsp->ws_head = node->next; @@ -666,7 +671,7 @@ expvar (struct mu_wordsplit *wsp, const char *str, size_t len, { size_t i = 0; const char *defstr = NULL; - char *value; + const char *value; const char *vptr; struct mu_wordsplit_node *newnode; const char *start = str - 1; @@ -738,7 +743,7 @@ expvar (struct mu_wordsplit *wsp, const char *str, size_t len, return _wsplt_nomem (wsp); } else if (wsp->ws_flags & MU_WRDSF_GETVAR) - value = wsp->ws_getvar (str, i); + value = wsp->ws_getvar (str, i, wsp->ws_closure); else if (wsp->ws_flags & MU_WRDSF_UNDEF) { wsp->ws_errno = MU_WRDSE_UNDEF; @@ -822,6 +827,14 @@ expvar (struct mu_wordsplit *wsp, const char *str, size_t len, memcpy (newnode->v.word, start, size); newnode->v.word[size] = 0; } + else + { + if (wsnode_new (wsp, &newnode)) + return 1; + wsnode_insert (wsp, newnode, *ptail, 0); + *ptail = newnode; + newnode->flags = _WSNF_NULL; + } return 0; } |