| 1 | /* $Id: macucs.c,v 1.3 2003/01/02 23:39:53 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 | #include "mac.h" |
| 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 | |
| 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 | */ |
| 30 | int is_dbcs_leadbyte(int codepage, char byte) |
| 31 | { |
| 32 | return 0; /* we don't do DBCS */ |
| 33 | } |
| 34 | |
| 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 | */ |
| 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 | |
| 52 | /* |
| 53 | * Convert from a system character set to Unicode. Used by luni_send |
| 54 | * to convert Unicode into the line character set. |
| 55 | */ |
| 56 | int wc_to_mb(int codepage, int flags, wchar_t *wcstr, int wclen, |
| 57 | char *mbstr, int mblen, char *defchr, int *defused) |
| 58 | { |
| 59 | int ret = 0; |
| 60 | if (defused) |
| 61 | *defused = 0; |
| 62 | while (mblen > 0 && wclen > 0) { |
| 63 | if (*wcstr >= 0x100) { |
| 64 | if (defchr) |
| 65 | *mbstr++ = *defchr; |
| 66 | else |
| 67 | *mbstr++ = '.'; |
| 68 | if (defused) |
| 69 | *defused = 1; |
| 70 | } else |
| 71 | *mbstr++ = (unsigned char) *wcstr; |
| 72 | wcstr++; |
| 73 | mblen--, wclen--, ret++; |
| 74 | } |
| 75 | return ret; /* FIXME: check error codes! */ |
| 76 | } |
| 77 | |
| 78 | void init_ucs(void) |
| 79 | { |
| 80 | int i; |
| 81 | /* Find the line control characters. FIXME: this is not right. */ |
| 82 | for (i = 0; i < 256; i++) |
| 83 | if (i < ' ' || (i >= 0x7F && i < 0xA0)) |
| 84 | unitab_ctrl[i] = i; |
| 85 | else |
| 86 | unitab_ctrl[i] = 0xFF; |
| 87 | |
| 88 | for (i = 0; i < 256; i++) { |
| 89 | unitab_line[i] = unitab_scoacs[i] = i; |
| 90 | unitab_xterm[i] = (i >= 0x5F && i < 0x7F) ? ((i+1) & 0x1F) : i; |
| 91 | } |
| 92 | } |