Intial commit
[profile/ivi/w3m.git] / entity.c
1 /* $Id: entity.c,v 1.7 2003/09/24 18:48:59 ukai Exp $ */
2 #ifdef DUMMY
3 #include "Str.h"
4 #define NBSP " "
5 #define UseAltEntity 1
6 #undef USE_M17N
7 #else                           /* DUMMY */
8 #include "fm.h"
9 #ifdef USE_M17N
10 #ifdef USE_UNICODE
11 #include "ucs.h"
12 #include "utf8.h"
13 #endif
14 #endif
15 #endif                          /* DUMMY */
16
17 /* *INDENT-OFF* */
18 static char *alt_latin1[ 96 ] = {
19     NBSP,  "!",   "-c-", "-L-", "CUR", "=Y=",  "|",  "S:",
20     "\"",  "(C)", "-a",  "<<",  "NOT", "-",   "(R)", "-",
21     "DEG", "+-",  "^2",  "^3",   "'",  "u",   "P:",  ".",
22     ",",   "^1",  "-o",  ">>",  "1/4", "1/2", "3/4", "?", 
23     "A`",  "A'",  "A^",  "A~",  "A:",  "AA",  "AE",  "C,",
24     "E`",  "E'",  "E^",  "E:",  "I`",  "I'",  "I^",  "I:",
25     "D-",  "N~",  "O`",  "O'",  "O^",  "O~",  "O:",  "x",
26     "O/",  "U`",  "U'",  "U^",  "U:",  "Y'",  "TH",  "ss",
27     "a`",  "a'",  "a^",  "a~",  "a:",  "aa",  "ae",  "c,", 
28     "e`",  "e'",  "e^",  "e:",  "i`",  "i'",  "i^",  "i:",
29     "d-",  "n~",  "o`",  "o'",  "o^",  "o~",  "o:",  "-:",
30     "o/",  "u`",  "u'",  "u^",  "u:",  "y'",  "th",  "y:"
31 };
32 /* *INDENT-ON* */
33
34 char *
35 conv_entity(unsigned int c)
36 {
37     char b = c & 0xff;
38
39     if (c < 0x20)               /* C0 */
40         return " ";
41     if (c < 0x7f)               /* ASCII */
42         return Strnew_charp_n(&b, 1)->ptr;
43     if (c < 0xa0)               /* DEL, C1 */
44         return " ";
45     if (c == 0xa0)
46         return NBSP;
47     if (c < 0x100) {            /* Latin1 (ISO 8859-1) */
48         if (UseAltEntity)
49             return alt_latin1[c - 0xa0];
50 #ifdef USE_M17N
51         return wc_conv_n(&b, 1, WC_CES_ISO_8859_1, InnerCharset)->ptr;
52 #else
53         return Strnew_charp_n(&b, 1)->ptr;
54 #endif
55     }
56 #ifdef USE_M17N
57 #ifdef USE_UNICODE
58     if (c <= WC_C_UCS4_END) {   /* Unicode */
59         wc_uchar utf8[7];
60         wc_ucs_to_utf8(c, utf8);
61         return wc_conv((char *)utf8, WC_CES_UTF_8, InnerCharset)->ptr;
62     }
63 #endif
64 #endif
65     return "?";
66 }