Show
Ignore:
Timestamp:
2000-09-07 14:56:00 (8 years ago)
Author:
Thomas Roessler <roessler@…>
Branch:
HEAD
Message:

Add a table of official character set names. Data taken from
www.iana.org.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • charset.c

    r1974 r2111  
    5050 */ 
    5151 
     52/*  
     53 * The following list has been created manually from the data under: 
     54 * http://www.isi.edu/in-notes/iana/assignments/character-sets 
     55 * Last update: 2000-09-07 
     56 * 
     57 * Note that it includes only the subset of character sets for which 
     58 * a preferred MIME name is given. 
     59 */ 
     60 
     61static struct  
     62{ 
     63  char *key; 
     64  char *pref; 
     65} 
     66PreferredMIMENames[] =  
     67{ 
     68  { "ansi_x3.4-1968",   "us-ascii"      }, 
     69  { "iso-ir-6",         "us-ascii"      }, 
     70  { "iso_646.irv:1991", "us-ascii"      }, 
     71  { "ascii",            "us-ascii"      }, 
     72  { "iso646-us",        "us-ascii"      }, 
     73  { "us",               "us-ascii"      }, 
     74  { "ibm367",           "us-ascii"      }, 
     75  { "cp367",            "us-ascii"      }, 
     76  { "csASCII",          "us-ascii"      }, 
     77   
     78  { "csISO2022KR",      "iso-2022-kr"   }, 
     79  { "csEUCKR",          "euc-kr"        }, 
     80  { "csISO2022JP",      "iso-2022-jp"   }, 
     81  { "csISO2022JP2",     "iso-2022-jp-2" }, 
     82 
     83  { "ISO_8859-1:1987",  "iso-8859-1"    }, 
     84  { "iso-ir-100",       "iso-8859-1"    }, 
     85  { "iso_8859-1",       "iso-8859-1"    }, 
     86  { "latin1",           "iso-8859-1"    }, 
     87  { "l1",               "iso-8859-1"    }, 
     88  { "IBM819",           "iso-8859-1"    }, 
     89  { "CP819",            "iso-8859-1"    }, 
     90  { "csISOLatin1",      "iso-8859-1"    }, 
     91   
     92  { "ISO_8859-2:1987",  "iso-8859-2"    }, 
     93  { "iso-ir-101",       "iso-8859-2"    }, 
     94  { "iso_8859-2",       "iso-8859-2"    }, 
     95  { "latin2",           "iso-8859-2"    }, 
     96  { "l2",               "iso-8859-2"    }, 
     97  { "csISOLatin2",      "iso-8859-2"    }, 
     98   
     99  { "ISO_8859-3:1988",  "iso-8859-3"    }, 
     100  { "iso-ir-109",       "iso-8859-3"    }, 
     101  { "ISO_8859-3",       "iso-8859-3"    }, 
     102  { "latin3",           "iso-8859-3"    }, 
     103  { "l3",               "iso-8859-3"    }, 
     104  { "csISOLatin3",      "iso-8859-3"    }, 
     105 
     106  { "ISO_8859-4:1988",  "iso-8859-4"    }, 
     107  { "iso-ir-110",       "iso-8859-4"    }, 
     108  { "ISO_8859-4",       "iso-8859-4"    }, 
     109  { "latin4",           "iso-8859-4"    }, 
     110  { "l4",               "iso-8859-4"    }, 
     111  { "csISOLatin4",      "iso-8859-4"    }, 
     112 
     113  { "ISO_8859-6:1987",  "iso-8859-6"    }, 
     114  { "iso-ir-127",       "iso-8859-6"    }, 
     115  { "iso_8859-6",       "iso-8859-6"    }, 
     116  { "ECMA-114",         "iso-8859-6"    }, 
     117  { "ASMO-708",         "iso-8859-6"    }, 
     118  { "arabic",           "iso-8859-6"    }, 
     119  { "csISOLatinArabic", "iso-8859-6"    }, 
     120   
     121  { "ISO_8859-7:1987",  "iso-8859-7"    }, 
     122  { "iso-ir-126",       "iso-8859-7"    }, 
     123  { "ISO_8859-7",       "iso-8859-7"    }, 
     124  { "ELOT_928",         "iso-8859-7"    }, 
     125  { "ECMA-118",         "iso-8859-7"    }, 
     126  { "greek",            "iso-8859-7"    }, 
     127  { "greek8",           "iso-8859-7"    }, 
     128  { "csISOLatinGreek",  "iso-8859-7"    }, 
     129   
     130  { "ISO_8859-8:1988",  "iso-8859-8"    }, 
     131  { "iso-ir-138",       "iso-8859-8"    }, 
     132  { "ISO_8859-8",       "iso-8859-8"    }, 
     133  { "hebrew",           "iso-8859-8"    }, 
     134  { "csISOLatinHebrew", "iso-8859-8"    }, 
     135 
     136  { "ISO_8859-5:1988",  "iso-8859-5"    }, 
     137  { "iso-ir-144",       "iso-8859-5"    }, 
     138  { "ISO_8859-5",       "iso-8859-5"    }, 
     139  { "cyrillic",         "iso-8859-5"    }, 
     140  { "csISOLatinCyrillic", "iso8859-5"   }, 
     141 
     142  { "ISO_8859-9:1989",  "iso-8859-9"    }, 
     143  { "iso-ir-148",       "iso-8859-9"    }, 
     144  { "ISO_8859-9",       "iso-8859-9"    }, 
     145  { "latin5",           "iso-8859-9"    }, /* this is not a bug */ 
     146  { "l5",               "iso-8859-9"    }, 
     147  { "csISOLatin5",      "iso-8859-9"    }, 
     148   
     149  { "ISO_8859-10:1992", "iso-8859-10"   }, 
     150  { "iso-ir-157",       "iso-8859-10"   }, 
     151  { "latin6",           "iso-8859-10"   }, /* this is not a bug */ 
     152  { "l6",               "iso-8859-10"   }, 
     153  { "csISOLatin6"       "iso-8859-10"   },  
     154   
     155  { "csKOI8r",          "koi8-r"        }, 
     156   
     157  { "MS_Kanji",         "Shift_JIS"     }, /* Note the underscore! */ 
     158  { "csShiftJis",       "Shift_JIS"     }, 
     159   
     160  { "Extended_UNIX_Code_Packed_Format_for_Japanese", 
     161                        "EUC-JP"        }, 
     162  { "csEUCPkdFmtJapanese", "EUC-JP"     }, 
     163   
     164  { "csGB2312",         "gb2312"        }, 
     165  { "csbig5",           "big5"          }, 
     166 
     167  /*  
     168   * End of official brain damage.  What follows has been taken 
     169   * from glibc's localedata files.  
     170   */ 
     171 
     172  { "iso_8859-13",      "iso-8859-13"   }, 
     173  { "iso-ir-179",       "iso-8859-13"   }, 
     174  { "latin7",           "iso-8859-13"   }, /* this is not a bug */ 
     175  { "l7",               "iso-8859-13"   }, 
     176   
     177  { "iso_8859-14",      "iso-8859-14"   }, 
     178  { "latin8",           "iso-8859-14"   }, /* this is not a bug */ 
     179  { "l8",               "iso-8859-14"   }, 
     180 
     181  { "iso_8859-15",      "iso-8859-15"   }, 
     182 
     183  /* 
     184   * If you happen to encounter system-specific brain-damage with 
     185   * respect to character set naming, please add it here, and 
     186   * submit a patch to <mutt-dev@mutt.org>.  
     187   */ 
     188 
     189  /* End of aliases.  Please keep this line last. */ 
     190   
     191  { NULL,               NULL            } 
     192}; 
     193 
    52194void mutt_set_langinfo_charset (void) 
    53195{ 
    54196  char buff[LONG_STRING]; 
    55197  char buff2[LONG_STRING]; 
    56   char *s, *d, *cp; 
    57198   
    58199  strfcpy (buff, nl_langinfo (CODESET), sizeof (buff)); 
    59   strfcpy (buff2, buff, sizeof (buff2)); 
    60    
    61   /* compactify the character set name returned */ 
    62   for (d = s = buff; *s; s++) 
    63   { 
    64     if (!strchr ("-_.", *s)) 
    65       *d++ = *s; 
    66   } 
    67   *d = '\0'; 
    68    
    69   /* look for common prefixes which may have been done wrong */ 
    70   if (!strncasecmp (buff, "iso8859", 7)) 
    71   { 
    72     snprintf (buff2, sizeof (buff2), "iso-8859-%s", buff + 7); 
    73     if ((cp = strchr (buff2, ':')))     /* strip :yyyy suffixes */ 
    74       *cp = '\0'; 
    75   } 
    76   else if (!strncasecmp (buff, "koi8", 4)) 
    77   { 
    78     snprintf (buff2, sizeof (buff2), "koi8-%s", buff + 4); 
    79   } 
    80   else if (!strncasecmp (buff, "windows", 7)) 
    81   { 
    82     snprintf (buff2, sizeof (buff2), "windows-%s", buff + 7); 
    83   } 
    84  
    85   /* fix the spelling */ 
    86   mutt_canonical_charset (buff, sizeof (buff), buff2); 
     200  mutt_canonical_charset (buff2, sizeof (buff2), buff); 
    87201   
    88202  /* finally, set $charset */ 
     
    95209{ 
    96210  size_t i; 
    97  
    98   if (!strncasecmp (name, "x-", 2)) 
    99     name = name + 2; 
    100  
    101   for (i = 0; name[i] && i < dlen - 1; i++) 
    102   { 
    103     if (strchr ("_/. ", name[i])) 
    104       dest[i] = '-'; 
    105     else if ('A' <= name[i] && name[i] <= 'Z') 
    106       dest[i] = name[i] - 'A' + 'a'; 
    107     else 
    108       dest[i] = name[i]; 
    109   } 
    110  
    111   dest[i] = '\0'; 
     211  char *p; 
     212  char scratch[LONG_STRING]; 
     213 
     214  /* catch some common iso-8859-something misspellings */ 
     215  if (!strncasecmp (name, "iso8859", 7) && name[7] != '-') 
     216    snprintf (scratch, sizeof (scratch), "iso_8859-%s", name + 8); 
     217  else 
     218    strfcpy (scratch, name, sizeof (scratch)); 
     219 
     220  for (i = 0; PreferredMIMENames[i].key; i++) 
     221    if (!strcasecmp (scratch, PreferredMIMENames[i].key)) 
     222    { 
     223      strfcpy (dest, PreferredMIMENames[i].pref, sizeof (dest)); 
     224      return; 
     225    } 
     226 
     227  strfcpy (dest, scratch, sizeof (dest)); 
     228 
     229  /* for cosmetics' sake, transform to lowercase. */ 
     230  for (p = dest; *p; p++) 
     231    if ('A' <= *p && *p <= 'Z') 
     232      *p += 'a' - 'A'; 
    112233} 
    113234