Fix the licence again. (Despite the copyright holders being more
[sgt/putty] / unicode.c
index ad14b32..877aff6 100644 (file)
--- a/unicode.c
+++ b/unicode.c
@@ -16,7 +16,7 @@ static void get_unitab(int codepage, wchar_t * unitab, int ftype);
 
 /* Character conversion arrays; they are usually taken from windows,
  * the xterm one has the four scanlines that have no unicode 2.0
- * equlivents mapped into the private area.
+ * equivalents mapped to their unicode 3.0 locations.
  */
 static char **uni_tbl;
 
@@ -267,7 +267,7 @@ void init_ucs_tables(void)
     int i, j;
     int used_dtf = 0;
     char tbuf[256];
-    int old_codepage = line_codepage;
+
     for (i = 0; i < 256; i++)
        tbuf[i] = i;
 
@@ -393,6 +393,13 @@ void init_ucs_tables(void)
        link_font(unitab_xterm, unitab_oemcp, ATTR_OEMCP);
     }
 
+    if (dbcs_screenfont && font_codepage != line_codepage) {
+       /* F***ing Microsoft fonts, Japanese and Korean codepage fonts
+        * have a currency symbol at 0x5C but their unicode value is 
+        * still given as U+005C not the correct U+00A5. */
+       unitab_line['\\'] = ATTR_OEMCP + '\\';
+    }
+
     /* Last chance, if !unicode then try poorman links. */
     if (cfg.vtmode != VT_UNICODE) {
        static char poorman_scoacs[] = 
@@ -420,14 +427,14 @@ void init_ucs_tables(void)
 
 static void link_font(WCHAR * line_tbl, WCHAR * font_tbl, WCHAR attr)
 {
-    int i, j, k;
-    for (k = 0; k < 256; k++) {
-       i = ((k + 32) & 0xFF);
-       if (DIRECT_FONT(line_tbl[i]))
+    int font_index, line_index, i;
+    for (line_index = 0; line_index < 256; line_index++) {
+       if (DIRECT_FONT(line_tbl[line_index]))
            continue;
-       for (j = 0; j < 256; j++) {
-           if (line_tbl[i] == font_tbl[j]) {
-               line_tbl[i] = (WCHAR) (attr + j);
+       for(i = 0; i < 256; i++) {
+           font_index = ((32 + i) & 0xFF);
+           if (line_tbl[line_index] == font_tbl[font_index]) {
+               line_tbl[line_index] = (WCHAR) (attr + font_index);
                break;
            }
        }
@@ -474,6 +481,9 @@ void luni_send(wchar_t * widebuf, int len)
        /* UTF is a simple algorithm */
        for (p = linebuffer, i = 0; i < len; i++) {
            wchar_t ch = widebuf[i];
+           /* Windows wchar_t is UTF-16 */
+           if ((ch&0xF800) == 0xD800) ch = '.';
+
            if (ch < 0x80) {
                *p++ = (char) (ch);
            } else if (ch < 0x800) {
@@ -534,7 +544,7 @@ int check_compose(int first, int second)
        0x43, 0x2f, 0x00a2}, {
        0x43, 0x7c, 0x00a2}, {
        0x4c, 0x2d, 0x00a3}, {
-       0x4c, 0x3d, 0x00a3}, {
+       0x4c, 0x3d, 0x20a4}, {
        0x58, 0x4f, 0x00a4}, {
        0x58, 0x30, 0x00a4}, {
        0x59, 0x2d, 0x00a5}, {