| 1 | /* $Id: macucs.c,v 1.1 2002/11/19 02:13:46 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 | int is_dbcs_leadbyte(int codepage, char byte) |
| 25 | { |
| 26 | return 0; /* we don't do DBCS */ |
| 27 | } |
| 28 | |
| 29 | int mb_to_wc(int codepage, int flags, char *mbstr, int mblen, |
| 30 | wchar_t *wcstr, int wclen) |
| 31 | { |
| 32 | int ret = 0; |
| 33 | while (mblen > 0 && wclen > 0) { |
| 34 | *wcstr++ = (unsigned char) *mbstr++; |
| 35 | mblen--, wclen--, ret++; |
| 36 | } |
| 37 | return ret; /* FIXME: check error codes! */ |
| 38 | } |
| 39 | |
| 40 | int wc_to_mb(int codepage, int flags, wchar_t *wcstr, int wclen, |
| 41 | char *mbstr, int mblen, char *defchr, int *defused) |
| 42 | { |
| 43 | int ret = 0; |
| 44 | if (defused) |
| 45 | *defused = 0; |
| 46 | while (mblen > 0 && wclen > 0) { |
| 47 | if (*wcstr >= 0x100) { |
| 48 | if (defchr) |
| 49 | *mbstr++ = *defchr; |
| 50 | else |
| 51 | *mbstr++ = '.'; |
| 52 | if (defused) |
| 53 | *defused = 1; |
| 54 | } else |
| 55 | *mbstr++ = (unsigned char) *wcstr; |
| 56 | wcstr++; |
| 57 | mblen--, wclen--, ret++; |
| 58 | } |
| 59 | return ret; /* FIXME: check error codes! */ |
| 60 | } |
| 61 | |
| 62 | void init_ucs(void) |
| 63 | { |
| 64 | int i; |
| 65 | /* Find the line control characters. FIXME: this is not right. */ |
| 66 | for (i = 0; i < 256; i++) |
| 67 | if (i < ' ' || (i >= 0x7F && i < 0xA0)) |
| 68 | unitab_ctrl[i] = i; |
| 69 | else |
| 70 | unitab_ctrl[i] = 0xFF; |
| 71 | |
| 72 | for (i = 0; i < 256; i++) { |
| 73 | unitab_line[i] = unitab_scoacs[i] = i; |
| 74 | unitab_xterm[i] = (i >= 0x5F && i < 0x7F) ? ((i+1) & 0x1F) : i; |
| 75 | } |
| 76 | } |