diff options
author | Sergey Poznyakoff <gray@gnu.org.ua> | 2010-12-02 10:14:43 +0200 |
---|---|---|
committer | Sergey Poznyakoff <gray@gnu.org.ua> | 2010-12-02 10:14:43 +0200 |
commit | 38d688c17f9545c032e22f117189b970e858697d (patch) | |
tree | d0ba9311b365c6b187205d43491c9c7eb2de834c /libmailutils/base | |
parent | 0fac46ab0e306070a46c5016cf2cf52c776c791c (diff) | |
download | mailutils-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/base')
-rw-r--r-- | libmailutils/base/Makefile.am | 1 | ||||
-rw-r--r-- | libmailutils/base/lcall.c | 131 | ||||
-rw-r--r-- | libmailutils/base/tempfile.c | 2 |
3 files changed, 133 insertions, 1 deletions
diff --git a/libmailutils/base/Makefile.am b/libmailutils/base/Makefile.am index 8160e04b3..ae9d2a972 100644 --- a/libmailutils/base/Makefile.am +++ b/libmailutils/base/Makefile.am @@ -36,6 +36,7 @@ libbase_la_SOURCES = \ hostname.c\ iterator.c\ kwd.c\ + lcall.c\ list.c\ listlist.c\ locale.c\ diff --git a/libmailutils/base/lcall.c b/libmailutils/base/lcall.c new file mode 100644 index 000000000..0485699a0 --- /dev/null +++ b/libmailutils/base/lcall.c @@ -0,0 +1,131 @@ +/* GNU Mailutils -- a suite of utilities for electronic mail + Copyright (C) 2003, 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/>. */ + +#ifdef HAVE_CONFIG_H +# include <config.h> +#endif + +#include <stdlib.h> +#include <string.h> +#include <errno.h> +#include <mailutils/nls.h> + +static int +_parse_lc_all (const char *arg, struct mu_lc_all *str, int flags) +{ + char *s; + size_t n; + + n = strcspn (arg, "_.@"); + if (flags & MU_LC_LANG) + { + s = malloc (n + 1); + if (!s) + return ENOMEM; + memcpy (s, arg, n); + s[n] = 0; + str->language = s; + str->flags |= MU_LC_LANG; + } + else + str->language = NULL; + arg += n; + + if (arg[0] == '_') + { + arg++; + + n = strcspn (arg, ".@"); + if (flags & MU_LC_TERR) + { + s = malloc (n + 1); + if (!s) + return ENOMEM; + memcpy (s, arg, n); + s[n] = 0; + str->territory = s; + str->flags |= MU_LC_TERR; + } + else + str->territory = NULL; + arg += n; + } + + if (arg[0] == '.') + { + arg++; + + n = strcspn (arg, "@"); + if (flags & MU_LC_CSET) + { + s = malloc (n + 1); + if (!s) + return ENOMEM; + memcpy (s, arg, n); + s[n] = 0; + str->charset = s; + str->flags |= MU_LC_CSET; + } + else + str->charset = NULL; + arg += n; + } + + if (arg[0]) + { + arg++; + if (flags & MU_LC_MOD) + { + str->modifier = strdup (arg); + if (!str->modifier) + return ENOMEM; + str->flags |= MU_LC_MOD; + } + } + return 0; +} + +void +mu_lc_all_free (struct mu_lc_all *str) +{ + free (str->language); + free (str->territory); + free (str->charset); + free (str->modifier); +} + +int +mu_parse_lc_all (const char *arg, struct mu_lc_all *str, int flags) +{ + int rc; + + memset (str, 0, sizeof (str[0])); + rc = _parse_lc_all (arg, str, flags); + if (rc == 0 && !str->charset) + { + const char *charset = mu_charset_lookup (str->language, str->territory); + if (charset) + { + str->charset = strdup (charset); + if (!str->charset) + rc = ENOMEM; + } + } + if (rc) + mu_lc_all_free (str); + return rc; +} diff --git a/libmailutils/base/tempfile.c b/libmailutils/base/tempfile.c index f494a3a9c..bc7da6fcc 100644 --- a/libmailutils/base/tempfile.c +++ b/libmailutils/base/tempfile.c @@ -220,7 +220,7 @@ mu_tempname (const char *tmpdir) struct mu_tempfile_hints hints; char *filename = NULL; int fd; - hints.tmpdir = tmpdir; + hints.tmpdir = (char*)tmpdir; if (mu_tempfile (&hints, MU_TEMPFILE_TMPDIR, &fd, &filename)) return NULL; close (fd); |