X-Git-Url: http://git.madism.org/?p=apps%2Fmadmutt.git;a=blobdiff_plain;f=charset.c;h=de6c5c9739e76bd5bf4390efbc0f5928e803afc7;hp=3fd46286b3541cffb5a07bd9e8b5b6f445bd29fd;hb=dba814e28104a395ffb52e16beccaecf09be8cde;hpb=df70e07e24add1869bcc9b7af2277d9d0c09a281 diff --git a/charset.c b/charset.c index 3fd4628..de6c5c9 100644 --- a/charset.c +++ b/charset.c @@ -1,22 +1,10 @@ /* + * Copyright notice from original mutt: * Copyright (C) 1999-2000 Thomas Roessler * - * This program is free software; you can redistribute it - * and/or modify it under the terms of the GNU General Public - * License as published by the Free Software Foundation; either - * version 2 of the License, or (at your option) any later - * version. - * - * This program 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 General Public License for more - * details. - * - * You should have received a copy of the GNU General Public - * License along with this program; if not, write to the Free - * Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111, USA. + * This file is part of mutt-ng, see http://www.muttng.org/. + * It's licensed under the GNU General Public License, + * please see the file GPL in the top level source directory. */ #if HAVE_CONFIG_H @@ -36,6 +24,11 @@ #include "mutt.h" #include "charset.h" +#include "ascii.h" + +#include "lib/mem.h" +#include "lib/intl.h" +#include "lib/str.h" #ifndef EILSEQ # define EILSEQ EINVAL @@ -203,15 +196,15 @@ void mutt_set_langinfo_charset (void) mutt_canonical_charset (buff2, sizeof (buff2), buff); /* finally, set $charset */ - if (!(Charset = safe_strdup (buff2))) - Charset = safe_strdup ("iso-8859-1"); + if (!(Charset = str_dup (buff2))) + Charset = str_dup ("iso-8859-1"); } #else void mutt_set_langinfo_charset (void) { - Charset = safe_strdup ("iso-8859-1"); + Charset = str_dup ("iso-8859-1"); } #endif @@ -236,7 +229,7 @@ void mutt_canonical_charset (char *dest, size_t dlen, const char *name) for (i = 0; PreferredMIMENames[i].key; i++) if (!ascii_strcasecmp (scratch, PreferredMIMENames[i].key) || - !mutt_strcasecmp (scratch, PreferredMIMENames[i].key)) { + !str_casecmp (scratch, PreferredMIMENames[i].key)) { strfcpy (dest, PreferredMIMENames[i].pref, dlen); return; } @@ -343,7 +336,7 @@ size_t mutt_iconv (iconv_t cd, ICONV_CONST char **inbuf, size_t * inbytesleft, for (t = inrepls; *t; t++) { ICONV_CONST char *ib1 = *t; - size_t ibl1 = strlen (*t); + size_t ibl1 = str_len (*t); char *ob1 = ob; size_t obl1 = obl; @@ -363,7 +356,7 @@ size_t mutt_iconv (iconv_t cd, ICONV_CONST char **inbuf, size_t * inbytesleft, outrepl = "?"; iconv (cd, 0, 0, &ob, &obl); if (obl) { - int n = strlen (outrepl); + int n = str_len (outrepl); if (n > obl) { outrepl = "?"; @@ -414,20 +407,20 @@ int mutt_convert_string (char **ps, const char *from, const char *to, else outrepl = "?"; - len = strlen (s); + len = str_len (s); ib = s, ibl = len + 1; obl = MB_LEN_MAX * ibl; - ob = buf = safe_malloc (obl + 1); + ob = buf = mem_malloc (obl + 1); mutt_iconv (cd, &ib, &ibl, &ob, &obl, inrepls, outrepl); iconv_close (cd); *ob = '\0'; - FREE (ps); + mem_free (ps); *ps = buf; - mutt_str_adjust (ps); + str_adjust (ps); return 0; } else @@ -468,14 +461,14 @@ FGETCONV *fgetconv_open (FILE * file, const char *from, const char *to, cd = mutt_iconv_open (to, from, flags); if (cd != (iconv_t) - 1) { - fc = safe_malloc (sizeof (struct fgetconv_s)); + fc = mem_malloc (sizeof (struct fgetconv_s)); fc->p = fc->ob = fc->bufo; fc->ib = fc->bufi; fc->ibl = 0; fc->inrepls = mutt_is_utf8 (to) ? repls : repls + 1; } else - fc = safe_malloc (sizeof (struct fgetconv_not)); + fc = mem_malloc (sizeof (struct fgetconv_not)); fc->file = file; fc->cd = cd; return (FGETCONV *) fc; @@ -560,7 +553,7 @@ void fgetconv_close (FGETCONV ** _fc) if (fc->cd != (iconv_t) - 1) iconv_close (fc->cd); - FREE (_fc); + mem_free (_fc); } char *mutt_get_first_charset (const char *charset) @@ -569,10 +562,10 @@ char *mutt_get_first_charset (const char *charset) const char *c, *c1; c = charset; - if (!mutt_strlen (c)) + if (!str_len (c)) return "us-ascii"; if (!(c1 = strchr (c, ':'))) - return charset; + return ((char*) charset); strfcpy (fcharset, c, c1 - c + 1); return fcharset; } @@ -590,11 +583,11 @@ static size_t convert_string (ICONV_CONST char *f, size_t flen, if (cd == (iconv_t) (-1)) return (size_t) (-1); obl = 4 * flen + 1; - ob = buf = safe_malloc (obl); + ob = buf = mem_malloc (obl); n = iconv (cd, &f, &flen, &ob, &obl); if (n == (size_t) (-1) || iconv (cd, 0, 0, &ob, &obl) == (size_t) (-1)) { e = errno; - FREE (&buf); + mem_free (&buf); iconv_close (cd); errno = e; return (size_t) (-1); @@ -603,7 +596,7 @@ static size_t convert_string (ICONV_CONST char *f, size_t flen, *tlen = ob - buf; - safe_realloc (&buf, ob - buf + 1); + mem_realloc (&buf, ob - buf + 1); *t = buf; iconv_close (cd); @@ -619,22 +612,22 @@ int mutt_convert_nonmime_string (char **ps) char *s; char *fromcode; size_t m, n; - size_t ulen = mutt_strlen (*ps); + size_t ulen = str_len (*ps); size_t slen; if (!u || !*u) return 0; c1 = strchr (c, ':'); - n = c1 ? c1 - c : mutt_strlen (c); + n = c1 ? c1 - c : str_len (c); if (!n) continue; - fromcode = safe_malloc (n + 1); + fromcode = mem_malloc (n + 1); strfcpy (fromcode, c, n + 1); m = convert_string (u, ulen, fromcode, Charset, &s, &slen); - FREE (&fromcode); + mem_free (&fromcode); if (m != (size_t) (-1)) { - FREE (ps); + mem_free (ps); *ps = s; return 0; }