summaryrefslogtreecommitdiff
path: root/libmailutils/string
diff options
context:
space:
mode:
authorSergey Poznyakoff <gray@gnu.org.ua>2010-12-02 10:14:43 +0200
committerSergey Poznyakoff <gray@gnu.org.ua>2010-12-02 10:14:43 +0200
commit38d688c17f9545c032e22f117189b970e858697d (patch)
treed0ba9311b365c6b187205d43491c9c7eb2de834c /libmailutils/string
parent0fac46ab0e306070a46c5016cf2cf52c776c791c (diff)
downloadmailutils-38d688c17f9545c032e22f117189b970e858697d.tar.gz
mailutils-38d688c17f9545c032e22f117189b970e858697d.tar.bz2
Avoid using strtok(_r)
* TODO: Update. * gnulib.modules: Remove strtok_r * imap4d/auth_gsasl.c (auth_gsasl_capa_init): Use mu_wordsplit instead of strtok. * imap4d/imap4d.h (strtok_r): Remove declaration. * lib/mailcap.c (mime_context) <no_ask_str>: Remove. All uses updated. (mime_context_fill): Use mu_wordsplit instead of strtok. (mime_context_write_input): Tolerate ENOSYS return from mu_stream_seek. (display_stream_mailcap): Use mu_wordsplit instead of strtok. * libmailutils/diag/gdebug.c (mu_debug_level_from_string) (mu_global_debug_from_string): Use mu_wordsplit instead of strtok. * libmu_cfg/sieve.c (_add_path): Likewise. * libmu_sieve/extensions/list.c: Likewise. * mail/escape.c (quote0): Likewise. * mail/util.c (util_header_expand): Likewise. (util_rfc2047_decode): Use mu_parse_lc_all. * mh/mh_init.c (mh_charset): Use mu_parse_lc_all. * frm/common.c (get_charset): Use mu_parse_lc_all. * libmailutils/base/lcall.c: New file. * libmailutils/base/Makefile.am (libbase_la_SOURCES): Add lcall.c * libmailutils/string/strlst.c: New file. * libmailutils/string/Makefile.am (libstring_la_SOURCES): Add strlst.c. * include/mailutils/cstr.h: Include mailutils/types.h (mu_string_split): New proto. * include/mailutils/nls.h (MU_LC_LANG, MU_LC_TERR) (MU_LC_CSET,MU_LC_MOD): New flags. (mu_lc_all): New struct. (mu_parse_lc_all, mu_lc_all_free): New protos. (mu_charset_lookup): New proto (from util.h). * include/mailutils/util.h (mu_charset_lookup): Move to nls.h * libmailutils/base/tempfile.c (mu_tempname): Shut up compiler warning.
Diffstat (limited to 'libmailutils/string')
-rw-r--r--libmailutils/string/Makefile.am1
-rw-r--r--libmailutils/string/strlst.c72
2 files changed, 73 insertions, 0 deletions
diff --git a/libmailutils/string/Makefile.am b/libmailutils/string/Makefile.am
index 5cb6a2368..9c91e73cb 100644
--- a/libmailutils/string/Makefile.am
+++ b/libmailutils/string/Makefile.am
@@ -27,6 +27,7 @@ libstring_la_SOURCES = \
strltrim.c\
strskip.c\
stripws.c\
+ strlst.c\
strrtrim.c\
trueans.c\
unfold.c\
diff --git a/libmailutils/string/strlst.c b/libmailutils/string/strlst.c
new file mode 100644
index 000000000..e555e7378
--- /dev/null
+++ b/libmailutils/string/strlst.c
@@ -0,0 +1,72 @@
+/* GNU Mailutils -- a suite of utilities for electronic mail
+ Copyright (C) 1999, 2000, 2001, 2002, 2003, 2005, 2006, 2007, 2009,
+ 2010 Free Software Foundation, Inc.
+
+ This library is free software; you can redistribute it and/or
+ modify it under the terms of the GNU Lesser General Public
+ License as published by the Free Software Foundation; either
+ version 3 of the License, or (at your option) any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ Lesser General Public License for more details.
+
+ You should have received a copy of the GNU Lesser General
+ Public License along with this library. If not, see
+ <http://www.gnu.org/licenses/>. */
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <errno.h>
+#include <mailutils/errno.h>
+#include <mailutils/list.h>
+#include <mailutils/wordsplit.h>
+#include <mailutils/cstr.h>
+
+int
+mu_string_split (const char *string, char *delim, mu_list_t list)
+{
+ size_t i;
+ struct mu_wordsplit ws;
+ int rc = 0;
+
+ if (!string || !delim || !list)
+ return EINVAL;
+
+ /* Split the string */
+ ws.ws_delim = delim;
+ if (mu_wordsplit (string, &ws,
+ MU_WRDSF_DELIM|MU_WRDSF_SQUEEZE_DELIMS|
+ MU_WRDSF_NOVAR|MU_WRDSF_NOCMD))
+ return errno;
+
+ for (i = 0; i < ws.ws_wordc; i++)
+ {
+ rc = mu_list_append (list, ws.ws_wordv[i]);
+ if (rc)
+ break;
+ }
+
+ if (rc)
+ {
+ /* If failed, restore LIST to the state before entering this
+ function. */
+ size_t j;
+ mu_list_comparator_t cptr =
+ mu_list_set_comparator (list, NULL);
+ mu_list_destroy_item_t dptr =
+ mu_list_set_destroy_item (list, NULL);
+
+ for (j = 0; j < i; j++)
+ mu_list_remove (list, ws.ws_wordv[j]);
+ mu_list_set_destroy_item (list, dptr);
+ mu_list_set_comparator (list, cptr);
+ }
+ else
+ /* Make sure ws.ws_wordv[x] are not freed */
+ ws.ws_wordc = 0;
+ mu_wordsplit_free (&ws);
+ return rc;
+}

Return to:

Send suggestions and report system problems to the System administrator.