-#ifdef WINDOWS
-#include <windows.h>
-#endif
-
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
* the xterm one has the four scanlines that have no unicode 2.0
* equivalents mapped to their unicode 3.0 locations.
*/
-static char **uni_tbl;
-
static const WCHAR unitab_xterm_std[32] = {
0x2666, 0x2592, 0x2409, 0x240c, 0x240d, 0x240a, 0x00b0, 0x00b1,
0x2424, 0x240b, 0x2518, 0x2510, 0x250c, 0x2514, 0x253c, 0x23ba,
0x00F8, 0x00F9, 0x00FA, 0x00FB, 0x00FC, 0x00FF, 0xFFFD, 0xFFFD
};
+/* Mazovia (Polish) aka CP620
+ * from "Mazowia to Unicode table", 04/24/96, Mikolaj Jedrzejak */
+static const wchar_t mazovia[] = {
+ /* Code point 0x9B is "zloty" symbol (zŽ), which is not
+ * widely used and for which there is no Unicode equivalent.
+ * One reference shows 0xA8 as U+00A7 SECTION SIGN, but we're
+ * told that's incorrect. */
+ 0x00C7, 0x00FC, 0x00E9, 0x00E2, 0x00E4, 0x00E0, 0x0105, 0x00E7,
+ 0x00EA, 0x00EB, 0x00E8, 0x00EF, 0x00EE, 0x0107, 0x00C4, 0x0104,
+ 0x0118, 0x0119, 0x0142, 0x00F4, 0x00F6, 0x0106, 0x00FB, 0x00F9,
+ 0x015a, 0x00D6, 0x00DC, 0xFFFD, 0x0141, 0x00A5, 0x015b, 0x0192,
+ 0x0179, 0x017b, 0x00F3, 0x00d3, 0x0144, 0x0143, 0x017a, 0x017c,
+ 0x00BF, 0x2310, 0x00AC, 0x00BD, 0x00BC, 0x00A1, 0x00AB, 0x00BB,
+ 0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556,
+ 0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510,
+ 0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F,
+ 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567,
+ 0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B,
+ 0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580,
+ 0x03B1, 0x00DF, 0x0393, 0x03C0, 0x03A3, 0x03C3, 0x00B5, 0x03C4,
+ 0x03A6, 0x0398, 0x03A9, 0x03B4, 0x221E, 0x03C6, 0x03B5, 0x2229,
+ 0x2261, 0x00B1, 0x2265, 0x2264, 0x2320, 0x2321, 0x00F7, 0x2248,
+ 0x00B0, 0x2219, 0x00B7, 0x221A, 0x207F, 0x00B2, 0x25A0, 0x00A0
+};
+
struct cp_list_item {
char *name;
int codepage;
{"Win1258 (Vietnamese)", 1258},
{"CP437", 437},
+ {"CP620 (Mazovia)", 0, 128, mazovia},
{"CP819", 28591},
{"CP878", 20866},
static void link_font(WCHAR * line_tbl, WCHAR * font_tbl, WCHAR attr);
-void init_ucs(Config *cfg)
+void init_ucs(Config *cfg, struct unicode_data *ucsdata)
{
int i, j;
int used_dtf = 0;
tbuf[i] = i;
/* Decide on the Line and Font codepages */
- line_codepage = decode_codepage(cfg->line_codepage);
+ ucsdata->line_codepage = decode_codepage(cfg->line_codepage);
- if (font_codepage <= 0) {
- font_codepage=0;
- dbcs_screenfont=0;
+ if (ucsdata->font_codepage <= 0) {
+ ucsdata->font_codepage=0;
+ ucsdata->dbcs_screenfont=0;
}
if (cfg->vtmode == VT_OEMONLY) {
- font_codepage = 437;
- dbcs_screenfont = 0;
- if (line_codepage <= 0)
- line_codepage = GetACP();
- } else if (line_codepage <= 0)
- line_codepage = font_codepage;
+ ucsdata->font_codepage = 437;
+ ucsdata->dbcs_screenfont = 0;
+ if (ucsdata->line_codepage <= 0)
+ ucsdata->line_codepage = GetACP();
+ } else if (ucsdata->line_codepage <= 0)
+ ucsdata->line_codepage = ucsdata->font_codepage;
/* Collect screen font ucs table */
- if (dbcs_screenfont || font_codepage == 0) {
- get_unitab(font_codepage, unitab_font, 2);
+ if (ucsdata->dbcs_screenfont || ucsdata->font_codepage == 0) {
+ get_unitab(ucsdata->font_codepage, ucsdata->unitab_font, 2);
for (i = 128; i < 256; i++)
- unitab_font[i] = (WCHAR) (ATTR_ACP + i);
+ ucsdata->unitab_font[i] = (WCHAR) (CSET_ACP + i);
} else {
- get_unitab(font_codepage, unitab_font, 1);
+ get_unitab(ucsdata->font_codepage, ucsdata->unitab_font, 1);
/* CP437 fonts are often broken ... */
- if (font_codepage == 437)
- unitab_font[0] = unitab_font[255] = 0xFFFF;
+ if (ucsdata->font_codepage == 437)
+ ucsdata->unitab_font[0] = ucsdata->unitab_font[255] = 0xFFFF;
}
if (cfg->vtmode == VT_XWINDOWS)
- memcpy(unitab_font + 1, unitab_xterm_std,
+ memcpy(ucsdata->unitab_font + 1, unitab_xterm_std,
sizeof(unitab_xterm_std));
/* Collect OEMCP ucs table */
- get_unitab(CP_OEMCP, unitab_oemcp, 1);
+ get_unitab(CP_OEMCP, ucsdata->unitab_oemcp, 1);
/* Collect CP437 ucs table for SCO acs */
if (cfg->vtmode == VT_OEMANSI || cfg->vtmode == VT_XWINDOWS)
- memcpy(unitab_scoacs, unitab_oemcp, sizeof(unitab_scoacs));
+ memcpy(ucsdata->unitab_scoacs, ucsdata->unitab_oemcp,
+ sizeof(ucsdata->unitab_scoacs));
else
- get_unitab(437, unitab_scoacs, 1);
+ get_unitab(437, ucsdata->unitab_scoacs, 1);
/* Collect line set ucs table */
- if (line_codepage == font_codepage &&
- (dbcs_screenfont || cfg->vtmode == VT_POORMAN || font_codepage==0)) {
+ if (ucsdata->line_codepage == ucsdata->font_codepage &&
+ (ucsdata->dbcs_screenfont ||
+ cfg->vtmode == VT_POORMAN || ucsdata->font_codepage==0)) {
/* For DBCS and POOR fonts force direct to font */
used_dtf = 1;
for (i = 0; i < 32; i++)
- unitab_line[i] = (WCHAR) i;
+ ucsdata->unitab_line[i] = (WCHAR) i;
for (i = 32; i < 256; i++)
- unitab_line[i] = (WCHAR) (ATTR_ACP + i);
- unitab_line[127] = (WCHAR) 127;
+ ucsdata->unitab_line[i] = (WCHAR) (CSET_ACP + i);
+ ucsdata->unitab_line[127] = (WCHAR) 127;
} else {
- get_unitab(line_codepage, unitab_line, 0);
+ get_unitab(ucsdata->line_codepage, ucsdata->unitab_line, 0);
}
#if 0
debug(
- ("Line cp%d, Font cp%d%s\n", line_codepage, font_codepage,
- dbcs_screenfont ? " DBCS" : ""));
+ ("Line cp%d, Font cp%d%s\n", ucsdata->line_codepage,
+ ucsdata->font_codepage, ucsdata->dbcs_screenfont ? " DBCS" : ""));
for (i = 0; i < 256; i += 16) {
for (j = 0; j < 16; j++) {
- debug(("%04x%s", unitab_line[i + j], j == 15 ? "" : ","));
+ debug(("%04x%s", ucsdata->unitab_line[i + j], j == 15 ? "" : ","));
}
debug(("\n"));
}
#endif
/* VT100 graphics - NB: Broken for non-ascii CP's */
- memcpy(unitab_xterm, unitab_line, sizeof(unitab_xterm));
- memcpy(unitab_xterm + '`', unitab_xterm_std, sizeof(unitab_xterm_std));
- unitab_xterm['_'] = ' ';
+ memcpy(ucsdata->unitab_xterm, ucsdata->unitab_line,
+ sizeof(ucsdata->unitab_xterm));
+ memcpy(ucsdata->unitab_xterm + '`', unitab_xterm_std,
+ sizeof(unitab_xterm_std));
+ ucsdata->unitab_xterm['_'] = ' ';
/* Generate UCS ->line page table. */
- if (uni_tbl) {
+ if (ucsdata->uni_tbl) {
for (i = 0; i < 256; i++)
- if (uni_tbl[i])
- sfree(uni_tbl[i]);
- sfree(uni_tbl);
- uni_tbl = 0;
+ if (ucsdata->uni_tbl[i])
+ sfree(ucsdata->uni_tbl[i]);
+ sfree(ucsdata->uni_tbl);
+ ucsdata->uni_tbl = 0;
}
if (!used_dtf) {
for (i = 0; i < 256; i++) {
- if (DIRECT_CHAR(unitab_line[i]))
+ if (DIRECT_CHAR(ucsdata->unitab_line[i]))
continue;
- if (DIRECT_FONT(unitab_line[i]))
+ if (DIRECT_FONT(ucsdata->unitab_line[i]))
continue;
- if (!uni_tbl) {
- uni_tbl = smalloc(256 * sizeof(char *));
- memset(uni_tbl, 0, 256 * sizeof(char *));
+ if (!ucsdata->uni_tbl) {
+ ucsdata->uni_tbl = snewn(256, char *);
+ memset(ucsdata->uni_tbl, 0, 256 * sizeof(char *));
}
- j = ((unitab_line[i] >> 8) & 0xFF);
- if (!uni_tbl[j]) {
- uni_tbl[j] = smalloc(256 * sizeof(char));
- memset(uni_tbl[j], 0, 256 * sizeof(char));
+ j = ((ucsdata->unitab_line[i] >> 8) & 0xFF);
+ if (!ucsdata->uni_tbl[j]) {
+ ucsdata->uni_tbl[j] = snewn(256, char);
+ memset(ucsdata->uni_tbl[j], 0, 256 * sizeof(char));
}
- uni_tbl[j][unitab_line[i] & 0xFF] = i;
+ ucsdata->uni_tbl[j][ucsdata->unitab_line[i] & 0xFF] = i;
}
}
/* Find the line control characters. */
for (i = 0; i < 256; i++)
- if (unitab_line[i] < ' '
- || (unitab_line[i] >= 0x7F && unitab_line[i] < 0xA0))
- unitab_ctrl[i] = i;
+ if (ucsdata->unitab_line[i] < ' '
+ || (ucsdata->unitab_line[i] >= 0x7F &&
+ ucsdata->unitab_line[i] < 0xA0))
+ ucsdata->unitab_ctrl[i] = i;
else
- unitab_ctrl[i] = 0xFF;
+ ucsdata->unitab_ctrl[i] = 0xFF;
/* Generate line->screen direct conversion links. */
if (cfg->vtmode == VT_OEMANSI || cfg->vtmode == VT_XWINDOWS)
- link_font(unitab_scoacs, unitab_oemcp, ATTR_OEMCP);
+ link_font(ucsdata->unitab_scoacs, ucsdata->unitab_oemcp, CSET_OEMCP);
- link_font(unitab_line, unitab_font, ATTR_ACP);
- link_font(unitab_scoacs, unitab_font, ATTR_ACP);
- link_font(unitab_xterm, unitab_font, ATTR_ACP);
+ link_font(ucsdata->unitab_line, ucsdata->unitab_font, CSET_ACP);
+ link_font(ucsdata->unitab_scoacs, ucsdata->unitab_font, CSET_ACP);
+ link_font(ucsdata->unitab_xterm, ucsdata->unitab_font, CSET_ACP);
if (cfg->vtmode == VT_OEMANSI || cfg->vtmode == VT_XWINDOWS) {
- link_font(unitab_line, unitab_oemcp, ATTR_OEMCP);
- link_font(unitab_xterm, unitab_oemcp, ATTR_OEMCP);
+ link_font(ucsdata->unitab_line, ucsdata->unitab_oemcp, CSET_OEMCP);
+ link_font(ucsdata->unitab_xterm, ucsdata->unitab_oemcp, CSET_OEMCP);
}
- if (dbcs_screenfont && font_codepage != line_codepage) {
+ if (ucsdata->dbcs_screenfont &&
+ ucsdata->font_codepage != ucsdata->line_codepage) {
/* F***ing Microsoft fonts, Japanese and Korean codepage fonts
* have a currency symbol at 0x5C but their unicode value is
* still given as U+005C not the correct U+00A5. */
- unitab_line['\\'] = ATTR_OEMCP + '\\';
+ ucsdata->unitab_line['\\'] = CSET_OEMCP + '\\';
}
/* Last chance, if !unicode then try poorman links. */
if (cfg->vtmode != VT_UNICODE) {
- static char poorman_scoacs[] =
+ static const char poorman_scoacs[] =
"CueaaaaceeeiiiAAE**ooouuyOUc$YPsaiounNao?++**!<>###||||++||++++++--|-+||++--|-+----++++++++##||#aBTPEsyt******EN=+><++-=... n2* ";
- static char poorman_latin1[] =
+ static const char poorman_latin1[] =
" !cL.Y|S\"Ca<--R~o+23'u|.,1o>///?AAAAAAACEEEEIIIIDNOOOOOxOUUUUYPBaaaaaaaceeeeiiiionooooo/ouuuuypy";
- static char poorman_vt100[] = "*#****o~**+++++-----++++|****L.";
+ static const char poorman_vt100[] = "*#****o~**+++++-----++++|****L.";
for (i = 160; i < 256; i++)
- if (!DIRECT_FONT(unitab_line[i]) &&
- unitab_line[i] >= 160 && unitab_line[i] < 256)
- unitab_line[i] = (WCHAR) (ATTR_ACP
- + poorman_latin1[unitab_line[i] -
- 160]);
+ if (!DIRECT_FONT(ucsdata->unitab_line[i]) &&
+ ucsdata->unitab_line[i] >= 160 &&
+ ucsdata->unitab_line[i] < 256) {
+ ucsdata->unitab_line[i] =
+ (WCHAR) (CSET_ACP +
+ poorman_latin1[ucsdata->unitab_line[i] - 160]);
+ }
for (i = 96; i < 127; i++)
- if (!DIRECT_FONT(unitab_xterm[i]))
- unitab_xterm[i] =
- (WCHAR) (ATTR_ACP + poorman_vt100[i - 96]);
+ if (!DIRECT_FONT(ucsdata->unitab_xterm[i]))
+ ucsdata->unitab_xterm[i] =
+ (WCHAR) (CSET_ACP + poorman_vt100[i - 96]);
for(i=128;i<256;i++)
- if (!DIRECT_FONT(unitab_scoacs[i]))
- unitab_scoacs[i] =
- (WCHAR) (ATTR_ACP + poorman_scoacs[i - 128]);
+ if (!DIRECT_FONT(ucsdata->unitab_scoacs[i]))
+ ucsdata->unitab_scoacs[i] =
+ (WCHAR) (CSET_ACP + poorman_scoacs[i - 128]);
}
}
wchar_t xlat_uskbd2cyrllic(int ch)
{
- static wchar_t cyrtab[] = {
+ static const wchar_t cyrtab[] = {
0, 1, 2, 3, 4, 5, 6, 7,
8, 9, 10, 11, 12, 13, 14, 15,
16, 17, 18, 19, 20, 21, 22, 23,
return cyrtab[ch&0x7F];
}
-int check_compose(int first, int second)
+int check_compose_internal(int first, int second, int recurse)
{
- static struct {
+ static const struct {
char first, second;
wchar_t composed;
} composetbl[] = {
0, 0, 0}
}, *c;
- static int recurse = 0;
int nc = -1;
for (c = composetbl; c->first; c++) {
}
if (recurse == 0) {
- recurse = 1;
- nc = check_compose(second, first);
+ nc = check_compose_internal(second, first, 1);
if (nc == -1)
- nc = check_compose(toupper(first), toupper(second));
+ nc = check_compose_internal(toupper(first), toupper(second), 1);
if (nc == -1)
- nc = check_compose(toupper(second), toupper(first));
- recurse = 0;
+ nc = check_compose_internal(toupper(second), toupper(first), 1);
}
return nc;
}
+int check_compose(int first, int second)
+{
+ return check_compose_internal(first, second, 0);
+}
+
int decode_codepage(char *cp_name)
{
char *s, *d;
* 1254 -> ISO 8859-9
* 1255 -> ISO 8859-8
* 1256 -> ISO 8859-6
- * 1257 -> ISO 8859-4
+ * 1257 -> ISO 8859-13 (changed from 8859-4 on advice of a Lithuanian)
*
* and for anything else, choose direct-to-font.
*/
case 1254: cp_name = "ISO-8859-9"; break;
case 1255: cp_name = "ISO-8859-8"; break;
case 1256: cp_name = "ISO-8859-6"; break;
- case 1257: cp_name = "ISO-8859-4"; break;
+ case 1257: cp_name = "ISO-8859-13"; break;
/* default: leave it blank, which will select -1, direct->font */
}
}
return codepage;
}
-char *cp_name(int codepage)
+const char *cp_name(int codepage)
{
const struct cp_list_item *cpi, *cpno;
static char buf[32];
* Return the nth code page in the list, for use in the GUI
* configurer.
*/
-char *cp_enumerate(int index)
+const char *cp_enumerate(int index)
{
if (index < 0 || index >= lenof(cp_list))
return NULL;
}
int wc_to_mb(int codepage, int flags, wchar_t *wcstr, int wclen,
- char *mbstr, int mblen, char *defchr, int *defused)
+ char *mbstr, int mblen, char *defchr, int *defused,
+ struct unicode_data *ucsdata)
{
char *p;
int i;
- if (codepage == line_codepage && uni_tbl) {
+ if (ucsdata && codepage == ucsdata->line_codepage && ucsdata->uni_tbl) {
/* Do this by array lookup if we can. */
if (wclen < 0) {
for (wclen = 0; wcstr[wclen++] ;); /* will include the NUL */
wchar_t ch = wcstr[i];
int by;
char *p1;
- if (uni_tbl && (p1 = uni_tbl[(ch >> 8) & 0xFF])
+ if (ucsdata->uni_tbl && (p1 = ucsdata->uni_tbl[(ch >> 8) & 0xFF])
&& (by = p1[ch & 0xFF]))
*p++ = by;
else if (ch < 0x80)