06567a99 |
1 | /* $Id: macucs.c,v 1.7 2003/04/05 22:12:44 ben Exp $ */ |
d082ac49 |
2 | |
3 | #include <stdio.h> |
4 | #include <stdlib.h> |
5 | #include <ctype.h> |
6 | |
7 | #include <time.h> |
8 | #include "putty.h" |
9 | #include "terminal.h" |
10 | #include "misc.h" |
2f9549c7 |
11 | #include "mac.h" |
d082ac49 |
12 | |
13 | /* |
14 | * Mac Unicode-handling routines. |
15 | * |
16 | * FIXME: currently trivial stub versions assuming all codepages |
17 | * are ISO8859-1. |
18 | * |
19 | * What we _should_ do is to use the Text Encoding Conversion Manager |
20 | * when it's available, and have our own routines for converting to |
21 | * standard Mac OS scripts when it's not. Support for ATSUI might be |
22 | * nice, too. |
23 | */ |
24 | |
e530c9fa |
25 | /* |
26 | * Determine whether a byte is the first byte of a double-byte |
27 | * character in a system character set. Only MI use is by clipme() |
28 | * when copying direct-to-font text to the clipboard. |
29 | */ |
d082ac49 |
30 | int is_dbcs_leadbyte(int codepage, char byte) |
31 | { |
32 | return 0; /* we don't do DBCS */ |
33 | } |
34 | |
e530c9fa |
35 | /* |
36 | * Convert from Unicode to a system character set. MI uses are: |
37 | * (1) by lpage_send(), whose only MI use is to convert the answerback |
38 | * string to Unicode, and |
39 | * (2) by clipme() when copying direct-to-font text to the clipboard. |
40 | */ |
d082ac49 |
41 | int mb_to_wc(int codepage, int flags, char *mbstr, int mblen, |
42 | wchar_t *wcstr, int wclen) |
43 | { |
44 | int ret = 0; |
45 | while (mblen > 0 && wclen > 0) { |
46 | *wcstr++ = (unsigned char) *mbstr++; |
47 | mblen--, wclen--, ret++; |
48 | } |
49 | return ret; /* FIXME: check error codes! */ |
50 | } |
51 | |
e530c9fa |
52 | /* |
53 | * Convert from a system character set to Unicode. Used by luni_send |
54 | * to convert Unicode into the line character set. |
55 | */ |
d082ac49 |
56 | int wc_to_mb(int codepage, int flags, wchar_t *wcstr, int wclen, |
c31f6c61 |
57 | char *mbstr, int mblen, char *defchr, int *defused, |
58 | struct unicode_data *ucsdata) |
d082ac49 |
59 | { |
60 | int ret = 0; |
61 | if (defused) |
62 | *defused = 0; |
63 | while (mblen > 0 && wclen > 0) { |
64 | if (*wcstr >= 0x100) { |
65 | if (defchr) |
66 | *mbstr++ = *defchr; |
67 | else |
68 | *mbstr++ = '.'; |
69 | if (defused) |
70 | *defused = 1; |
71 | } else |
72 | *mbstr++ = (unsigned char) *wcstr; |
73 | wcstr++; |
74 | mblen--, wclen--, ret++; |
75 | } |
76 | return ret; /* FIXME: check error codes! */ |
77 | } |
78 | |
bbe29f1f |
79 | /* Character conversion array, |
80 | * the xterm one has the four scanlines that have no unicode 2.0 |
81 | * equivalents mapped to their unicode 3.0 locations. |
82 | */ |
83 | static const wchar_t unitab_xterm_std[32] = { |
84 | 0x2666, 0x2592, 0x2409, 0x240c, 0x240d, 0x240a, 0x00b0, 0x00b1, |
85 | 0x2424, 0x240b, 0x2518, 0x2510, 0x250c, 0x2514, 0x253c, 0x23ba, |
86 | 0x23bb, 0x2500, 0x23bc, 0x23bd, 0x251c, 0x2524, 0x2534, 0x252c, |
87 | 0x2502, 0x2264, 0x2265, 0x03c0, 0x2260, 0x00a3, 0x00b7, 0x0020 |
88 | }; |
89 | |
c31f6c61 |
90 | void init_ucs(Session *s) |
d082ac49 |
91 | { |
92 | int i; |
c31f6c61 |
93 | |
d082ac49 |
94 | /* Find the line control characters. FIXME: this is not right. */ |
95 | for (i = 0; i < 256; i++) |
96 | if (i < ' ' || (i >= 0x7F && i < 0xA0)) |
c31f6c61 |
97 | s->ucsdata.unitab_ctrl[i] = i; |
d082ac49 |
98 | else |
c31f6c61 |
99 | s->ucsdata.unitab_ctrl[i] = 0xFF; |
d082ac49 |
100 | |
bbe29f1f |
101 | for (i = 0; i < 256; i++) |
c31f6c61 |
102 | s->ucsdata.unitab_line[i] = s->ucsdata.unitab_scoacs[i] = i; |
bbe29f1f |
103 | |
104 | /* VT100 graphics - NB: Broken for non-ascii CP's */ |
105 | memcpy(s->ucsdata.unitab_xterm, s->ucsdata.unitab_line, |
106 | sizeof(s->ucsdata.unitab_xterm)); |
107 | memcpy(s->ucsdata.unitab_xterm + '`', unitab_xterm_std, |
108 | sizeof(unitab_xterm_std)); |
109 | s->ucsdata.unitab_xterm['_'] = ' '; |
110 | |
d082ac49 |
111 | } |
8a7e67ec |
112 | |
113 | int decode_codepage(char *cp_name) |
114 | { |
115 | |
116 | return 0; |
117 | } |
118 | |
06567a99 |
119 | char const *cp_enumerate (int index) |
8a7e67ec |
120 | { |
121 | |
122 | if (index == 0) return "ISO/IEC 8859-1"; |
123 | return NULL; |
124 | } |
125 | |
06567a99 |
126 | char const *cp_name(int codepage) |
8a7e67ec |
127 | { |
128 | |
129 | return "ISO/IEC 8859-1"; |
130 | } |