]> asedeno.scripts.mit.edu Git - PuTTY.git/blob - mac/macucs.c
05d10c10553ce4490797dd789397a05f51ffda23
[PuTTY.git] / mac / macucs.c
1 /* $Id: macucs.c,v 1.2 2002/12/04 19:44:57 ben Exp $ */
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"
11
12 /*
13  * Mac Unicode-handling routines.
14  * 
15  * FIXME: currently trivial stub versions assuming all codepages
16  * are ISO8859-1.
17  *
18  * What we _should_ do is to use the Text Encoding Conversion Manager
19  * when it's available, and have our own routines for converting to
20  * standard Mac OS scripts when it's not.  Support for ATSUI might be
21  * nice, too.
22  */
23
24 /*
25  * Determine whether a byte is the first byte of a double-byte
26  * character in a system character set.  Only MI use is by clipme()
27  * when copying direct-to-font text to the clipboard.
28  */
29 int is_dbcs_leadbyte(int codepage, char byte)
30 {
31     return 0;                          /* we don't do DBCS */
32 }
33
34 /*
35  * Convert from Unicode to a system character set.  MI uses are:
36  * (1) by lpage_send(), whose only MI use is to convert the answerback
37  * string to Unicode, and
38  * (2) by clipme() when copying direct-to-font text to the clipboard.
39  */
40 int mb_to_wc(int codepage, int flags, char *mbstr, int mblen,
41              wchar_t *wcstr, int wclen)
42 {
43     int ret = 0;
44     while (mblen > 0 && wclen > 0) {
45         *wcstr++ = (unsigned char) *mbstr++;
46         mblen--, wclen--, ret++;
47     }
48     return ret;                        /* FIXME: check error codes! */
49 }
50
51 /*
52  * Convert from a system character set to Unicode.  Used by luni_send
53  * to convert Unicode into the line character set.
54  */
55 int wc_to_mb(int codepage, int flags, wchar_t *wcstr, int wclen,
56              char *mbstr, int mblen, char *defchr, int *defused)
57 {
58     int ret = 0;
59     if (defused)
60         *defused = 0;
61     while (mblen > 0 && wclen > 0) {
62         if (*wcstr >= 0x100) {
63             if (defchr)
64                 *mbstr++ = *defchr;
65             else
66                 *mbstr++ = '.';
67             if (defused)
68                 *defused = 1;
69         } else
70             *mbstr++ = (unsigned char) *wcstr;
71         wcstr++;
72         mblen--, wclen--, ret++;
73     }
74     return ret;                        /* FIXME: check error codes! */
75 }
76
77 void init_ucs(void)
78 {
79     int i;
80     /* Find the line control characters. FIXME: this is not right. */
81     for (i = 0; i < 256; i++)
82         if (i < ' ' || (i >= 0x7F && i < 0xA0))
83             unitab_ctrl[i] = i;
84         else
85             unitab_ctrl[i] = 0xFF;
86
87     for (i = 0; i < 256; i++) {
88         unitab_line[i] = unitab_scoacs[i] = i;
89         unitab_xterm[i] = (i >= 0x5F && i < 0x7F) ? ((i+1) & 0x1F) : i;
90     }
91 }