~ubuntu-branches/ubuntu/natty/mutt/natty

« back to all changes in this revision

Viewing changes to charset.c

  • Committer: Package Import Robot
  • Author(s): أحمد المحمودي (Ahmed El-Mahmoudy)
  • Date: 2010-12-17 14:28:28 UTC
  • mfrom: (16.2.3 experimental)
  • Revision ID: package-import@ubuntu.com-20101217142828-ve8yy0xf1zomtnx9
Tags: 1.5.21-1ubuntu1
* Merge with Debian experimental (LP: #691512), remaining changes:
  + debian/control, debian/patches/debian-specific/build_doc_adjustments.diff:
    Use w3m (main) instead of elinks (universe) for generating documentation.
  + Drop libtokyocabinet-dev (universe) from Build-Depends, use always
    libgdbm-dev and also use gdbm for the header cache backend. (lp: #607448)

Show diffs side-by-side

added added

removed removed

Lines of Context:
239
239
 
240
240
#endif
241
241
 
 
242
/* this first ties off any charset extension such as //TRANSLIT,
 
243
   canonicalizes the charset and re-adds the extension */
242
244
void mutt_canonical_charset (char *dest, size_t dlen, const char *name)
243
245
{
244
246
  size_t i;
245
 
  char *p;
246
 
  char scratch[LONG_STRING];
247
 
 
248
 
  if (!ascii_strcasecmp (name, "utf-8") || !ascii_strcasecmp (name, "utf8"))
 
247
  char *p, *ext;
 
248
  char in[LONG_STRING], scratch[LONG_STRING];
 
249
 
 
250
  strfcpy (in, name, sizeof (in));
 
251
  if ((ext = strchr (in, '/')))
 
252
    *ext++ = 0;
 
253
 
 
254
  if (!ascii_strcasecmp (in, "utf-8") || !ascii_strcasecmp (in, "utf8"))
249
255
  {
250
256
    strfcpy (dest, "utf-8", dlen);
251
 
    return;
 
257
    goto out;
252
258
  }
253
259
 
254
260
  /* catch some common iso-8859-something misspellings */
255
 
  if (!ascii_strncasecmp (name, "8859", 4) && name[4] != '-')
256
 
    snprintf (scratch, sizeof (scratch), "iso-8859-%s", name +4);
257
 
  else if (!ascii_strncasecmp (name, "8859-", 5))
258
 
    snprintf (scratch, sizeof (scratch), "iso-8859-%s", name + 5);
259
 
  else if (!ascii_strncasecmp (name, "iso8859", 7) && name[7] != '-')
260
 
    snprintf (scratch, sizeof (scratch), "iso_8859-%s", name + 7);
261
 
  else if (!ascii_strncasecmp (name, "iso8859-", 8))
262
 
    snprintf (scratch, sizeof (scratch), "iso_8859-%s", name + 8);
 
261
  if (!ascii_strncasecmp (in, "8859", 4) && in[4] != '-')
 
262
    snprintf (scratch, sizeof (scratch), "iso-8859-%s", in +4);
 
263
  else if (!ascii_strncasecmp (in, "8859-", 5))
 
264
    snprintf (scratch, sizeof (scratch), "iso-8859-%s", in + 5);
 
265
  else if (!ascii_strncasecmp (in, "iso8859", 7) && in[7] != '-')
 
266
    snprintf (scratch, sizeof (scratch), "iso_8859-%s", in + 7);
 
267
  else if (!ascii_strncasecmp (in, "iso8859-", 8))
 
268
    snprintf (scratch, sizeof (scratch), "iso_8859-%s", in + 8);
263
269
  else
264
 
    strfcpy (scratch, NONULL(name), sizeof (scratch));
 
270
    strfcpy (scratch, in, sizeof (scratch));
265
271
 
266
272
  for (i = 0; PreferredMIMENames[i].key; i++)
267
273
    if (!ascii_strcasecmp (scratch, PreferredMIMENames[i].key) ||
268
274
        !mutt_strcasecmp (scratch, PreferredMIMENames[i].key))
269
275
    {
270
276
      strfcpy (dest, PreferredMIMENames[i].pref, dlen);
271
 
      return;
 
277
      goto out;
272
278
    }
273
279
 
274
280
  strfcpy (dest, scratch, dlen);
276
282
  /* for cosmetics' sake, transform to lowercase. */
277
283
  for (p = dest; *p; p++)
278
284
    *p = ascii_tolower (*p);
 
285
 
 
286
out:
 
287
  if (ext && *ext)
 
288
  {
 
289
    safe_strcat (dest, dlen, "/");
 
290
    safe_strcat (dest, dlen, ext);
 
291
  }
279
292
}
280
293
 
281
294
int mutt_chscmp (const char *s, const char *chs)
282
295
{
283
296
  char buffer[STRING];
 
297
  int a, b;
284
298
 
285
299
  if (!s) return 0;
286
300
 
 
301
  /* charsets may have extensions mutt_canonical_charset()
 
302
     leaves intact; we expect `chs' to originate from mutt
 
303
     code, not user input (i.e. `chs' does _not_ have any
 
304
     extension)
 
305
     we simply check if the shorter string is a prefix for
 
306
     the longer */
287
307
  mutt_canonical_charset (buffer, sizeof (buffer), s);
288
 
  return !ascii_strcasecmp (buffer, chs);
 
308
  a = mutt_strlen (buffer);
 
309
  b = mutt_strlen (chs);
 
310
  return !ascii_strncasecmp (a > b ? buffer : chs,
 
311
                             a > b ? chs : buffer, MIN(a,b));
289
312
}
290
313
 
291
314
char *mutt_get_default_charset ()