SCO ACS part 2 (ESC[12m) apparently puts the top half of CP437 into
[u/mdw/putty] / unix / uxucs.c
CommitLineData
1709795f 1#include <stdio.h>
2#include <stdlib.h>
3#include <ctype.h>
4
5#include <time.h>
6#include "putty.h"
887035a5 7#include "terminal.h"
1709795f 8#include "misc.h"
9
10/*
11 * Unix Unicode-handling routines.
12 *
13 * FIXME: currently trivial stub versions assuming all codepages
14 * are ISO8859-1.
15 */
16
1709795f 17int is_dbcs_leadbyte(int codepage, char byte)
18{
19 return 0; /* we don't do DBCS */
20}
21
22int mb_to_wc(int codepage, int flags, char *mbstr, int mblen,
23 wchar_t *wcstr, int wclen)
24{
25 int ret = 0;
26 while (mblen > 0 && wclen > 0) {
27 *wcstr++ = (unsigned char) *mbstr++;
e6346999 28 mblen--, wclen--, ret++;
29 }
30 return ret; /* FIXME: check error codes! */
31}
32
33int wc_to_mb(int codepage, int flags, wchar_t *wcstr, int wclen,
34 char *mbstr, int mblen, char *defchr, int *defused)
35{
36 int ret = 0;
37 if (defused)
38 *defused = 0;
39 while (mblen > 0 && wclen > 0) {
40 if (*wcstr >= 0x100) {
41 if (defchr)
42 *mbstr++ = *defchr;
43 else
5def7522 44 *mbstr++ = '.';
e6346999 45 if (defused)
46 *defused = 1;
47 } else
48 *mbstr++ = (unsigned char) *wcstr;
49 wcstr++;
50 mblen--, wclen--, ret++;
1709795f 51 }
52 return ret; /* FIXME: check error codes! */
53}
54
55void init_ucs(void)
56{
57 int i;
58 /* Find the line control characters. FIXME: this is not right. */
59 for (i = 0; i < 256; i++)
60 if (i < ' ' || (i >= 0x7F && i < 0xA0))
61 unitab_ctrl[i] = i;
62 else
63 unitab_ctrl[i] = 0xFF;
64
65 for (i = 0; i < 256; i++) {
66 unitab_line[i] = unitab_scoacs[i] = i;
ec684ed4 67 unitab_xterm[i] = (i >= 0x5F && i < 0x7F) ? ((i+1) & 0x1F) : i;
1709795f 68 }
126ce234 69}