Commit 1c323496 authored by Simon Middleton's avatar Simon Middleton
Browse files

Fixed encoding table so that modules builds will work.

Made all tables be on linked list to avoid static copies of pointers.
Removed redundant 8bit files.

Version 0.03. Tagged as 'Unicode-0_03'
parent 72e1de26
/* (0.02) /* (0.03)
* *
* This file is automatically maintained by srccommit, do not edit manually. * This file is automatically maintained by srccommit, do not edit manually.
* *
*/ */
#define Module_MajorVersion_CMHG 0.02 #define Module_MajorVersion_CMHG 0.03
#define Module_MinorVersion_CMHG #define Module_MinorVersion_CMHG
#define Module_Date_CMHG 11 Nov 1997 #define Module_Date_CMHG 12 Nov 1997
#define Module_MajorVersion "0.02" #define Module_MajorVersion "0.03"
#define Module_MinorVersion "" #define Module_MinorVersion ""
#define Module_Date "11 Nov 1997" #define Module_Date "12 Nov 1997"
/* Copyright 1997 Acorn Computers Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "encpriv.h"
#include "koi8r.h"
#include "acorn.h"
/*
* Routines for encoding Macintosh (Mac Roman)
* Number: 5001
* Names: x-acorn-latin1
*/
static UCS2 *acorn_latin1_table;
static int acorn_latin1_reset(Encoding *e, int for_encoding)
{
EightBit_Encoding *ee = (EightBit_Encoding *) e;
if (!acorn_latin1_table)
acorn_latin1_table = encoding_load_map_file("Acorn.Latin1");
ee->table = acorn_latin1_table;
return ee->table != NULL;
}
EncodingPriv enc_acorn_latin1 =
{
eightbit_read,
acorn_latin1_reset,
sizeof(EightBit_Encoding) - sizeof(EncodingPriv),
eightbit_delete,
0,
eightbit_write
};
/* Copyright 1997 Acorn Computers Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "encpriv.h"
#include "koi8r.h"
#include "apple.h"
/*
* Routines for encoding Macintosh (Mac Roman)
* Number: 2027
* Names: macintosh
* csMacintosh
*/
static UCS2 *mac_roman_table;
static int mac_roman_reset(Encoding *e, int for_encoding)
{
EightBit_Encoding *ee = (EightBit_Encoding *) e;
if (!mac_roman_table)
mac_roman_table = encoding_load_map_file("Apple.MacRoman");
ee->table = mac_roman_table;
return ee->table != NULL;
}
EncodingPriv enc_mac_roman =
{
eightbit_read,
mac_roman_reset,
sizeof(EightBit_Encoding) - sizeof(EncodingPriv),
eightbit_delete,
0,
eightbit_write
};
...@@ -19,13 +19,11 @@ ...@@ -19,13 +19,11 @@
#include "iso2022.h" #include "iso2022.h"
#include "bigfive.h" #include "bigfive.h"
static UCS2 *bigfive_table;
typedef struct BigFive_Encoding typedef struct BigFive_Encoding
{ {
EncodingPriv e; EncodingPriv e;
char prev; char prev;
encoding_table table;
} BigFive_Encoding; } BigFive_Encoding;
/* /*
...@@ -35,7 +33,7 @@ typedef struct BigFive_Encoding ...@@ -35,7 +33,7 @@ typedef struct BigFive_Encoding
* CN-Big5 * CN-Big5
*/ */
static UCS4 bigfive_to_ucs(int c1, int c2) static UCS4 bigfive_to_ucs(const UCS2 *table, int c1, int c2)
{ {
/* /*
* Big Five encodes kanji using byte pairs: * Big Five encodes kanji using byte pairs:
...@@ -63,7 +61,7 @@ static UCS4 bigfive_to_ucs(int c1, int c2) ...@@ -63,7 +61,7 @@ static UCS4 bigfive_to_ucs(int c1, int c2)
else else
c2 -= 0x62; c2 -= 0x62;
u = bigfive_table[157 * c1 + c2]; u = table[157 * c1 + c2];
return u == NULL_UCS2 ? 0xFFFD : u; return u == NULL_UCS2 ? 0xFFFD : u;
} }
...@@ -72,12 +70,12 @@ static int bigfive_reset(Encoding *e, int for_encoding) ...@@ -72,12 +70,12 @@ static int bigfive_reset(Encoding *e, int for_encoding)
{ {
BigFive_Encoding *s5 = (BigFive_Encoding *) e; BigFive_Encoding *s5 = (BigFive_Encoding *) e;
if (!bigfive_table) if (!s5->table)
bigfive_table = encoding_load_map_file("BigFive"); s5->table = encoding_load_map_file("BigFive");
s5->prev = 0; s5->prev = 0;
return bigfive_table != NULL; return s5->table != NULL;
} }
static unsigned int bigfive_read(Encoding *e, static unsigned int bigfive_read(Encoding *e,
...@@ -87,6 +85,7 @@ static unsigned int bigfive_read(Encoding *e, ...@@ -87,6 +85,7 @@ static unsigned int bigfive_read(Encoding *e,
void *handle) void *handle)
{ {
BigFive_Encoding *s5 = (BigFive_Encoding *) e; BigFive_Encoding *s5 = (BigFive_Encoding *) e;
const UCS2 *table = encoding_table_ptr(s5->table);
unsigned int count; unsigned int count;
for (count = n; count; count--) for (count = n; count; count--)
...@@ -96,7 +95,7 @@ static unsigned int bigfive_read(Encoding *e, ...@@ -96,7 +95,7 @@ static unsigned int bigfive_read(Encoding *e,
if (s5->prev) if (s5->prev)
{ {
u = bigfive_to_ucs(s5->prev, c); u = bigfive_to_ucs(table, s5->prev, c);
s5->prev = 0; s5->prev = 0;
} }
else else
...@@ -133,7 +132,7 @@ static int bigfive_write(EncodingPriv *e, UCS4 u, char **bf, int *bufsize) ...@@ -133,7 +132,7 @@ static int bigfive_write(EncodingPriv *e, UCS4 u, char **bf, int *bufsize)
if (u < 0x0080) if (u < 0x0080)
c = u; c = u;
else if ((i = encoding_lookup_in_table(u, bigfive_table, encoding_n_table_entries(bigfive_table))) != -1) else if ((i = encoding_lookup_in_table(u, s5->table)) != -1)
{ {
/* first byte 0xA1-0xFE /* first byte 0xA1-0xFE
* second byte 0x40-0x7E, 0xA1-0xFE * second byte 0x40-0x7E, 0xA1-0xFE
...@@ -167,12 +166,19 @@ static int bigfive_write(EncodingPriv *e, UCS4 u, char **bf, int *bufsize) ...@@ -167,12 +166,19 @@ static int bigfive_write(EncodingPriv *e, UCS4 u, char **bf, int *bufsize)
s5 = s5; s5 = s5;
} }
static void bigfive_delete(EncodingPriv *e)
{
BigFive_Encoding *s5 = (BigFive_Encoding *) e;
if (s5->table)
encoding_discard_map_file(s5->table);
}
EncodingPriv enc_bigfive = EncodingPriv enc_bigfive =
{ {
bigfive_read, bigfive_read,
bigfive_reset, bigfive_reset,
sizeof(BigFive_Encoding) - sizeof(EncodingPriv), sizeof(BigFive_Encoding) - sizeof(EncodingPriv),
0, /* bigfive_delete */ bigfive_delete,
0, 0,
bigfive_write bigfive_write
}; };
...@@ -16,7 +16,13 @@ ...@@ -16,7 +16,13 @@
#include "encpriv.h" #include "encpriv.h"
#include "koi8r.h" #include "eightbit.h"
typedef struct EightBit_Encoding
{
EncodingPriv e;
encoding_table table; /* 128-entry table for codes 0x80-0xFF */
} EightBit_Encoding;
/* /*
* Routines for KOI-8R (Cyrillic) * Routines for KOI-8R (Cyrillic)
...@@ -25,21 +31,17 @@ ...@@ -25,21 +31,17 @@
* csKOI8R * csKOI8R
*/ */
static UCS2 *koi8r_table; static int eightbit_reset(Encoding *e, int for_encoding)
static int koi8r_reset(Encoding *e, int for_encoding)
{ {
EightBit_Encoding *ee = (EightBit_Encoding *) e; EightBit_Encoding *ee = (EightBit_Encoding *) e;
if (!koi8r_table) if (!ee->table)
koi8r_table = encoding_load_map_file("KOI8-R"); ee->table = encoding_load_map_file(e->list_entry->preload);
ee->table = koi8r_table;
return ee->table != NULL; return ee->table != NULL;
} }
unsigned int eightbit_read(EncodingPriv *e, static unsigned int eightbit_read(EncodingPriv *e,
encoding_read_callback_fn ucs_out, encoding_read_callback_fn ucs_out,
const char *s, const char *s,
unsigned int n, unsigned int n,
...@@ -47,11 +49,12 @@ unsigned int eightbit_read(EncodingPriv *e, ...@@ -47,11 +49,12 @@ unsigned int eightbit_read(EncodingPriv *e,
{ {
EightBit_Encoding *ee = (EightBit_Encoding *) e; EightBit_Encoding *ee = (EightBit_Encoding *) e;
unsigned int count; unsigned int count;
UCS2 *table = encoding_table_ptr(ee->table);
for (count = n; count; count--) for (count = n; count; count--)
{ {
char c = *s++; char c = *s++;
UCS4 u = c < 0x80 ? c : ee->table[c - 0x80]; UCS4 u = c < 0x80 ? c : table[c - 0x80];
if (u == NULL_UCS2) if (u == NULL_UCS2)
u = 0xFFFD; u = 0xFFFD;
...@@ -64,7 +67,7 @@ unsigned int eightbit_read(EncodingPriv *e, ...@@ -64,7 +67,7 @@ unsigned int eightbit_read(EncodingPriv *e,
return n - count; return n - count;
} }
int eightbit_write(EncodingPriv *e, UCS4 u, char **s, int *bufsize) static int eightbit_write(EncodingPriv *e, UCS4 u, char **s, int *bufsize)
{ {
EightBit_Encoding *ee = (EightBit_Encoding *) e; EightBit_Encoding *ee = (EightBit_Encoding *) e;
int i, c; int i, c;
...@@ -74,7 +77,7 @@ int eightbit_write(EncodingPriv *e, UCS4 u, char **s, int *bufsize) ...@@ -74,7 +77,7 @@ int eightbit_write(EncodingPriv *e, UCS4 u, char **s, int *bufsize)
if (u < 0x80) if (u < 0x80)
c = u; c = u;
else if ((i = encoding_lookup_in_table(u, ee->table, encoding_n_table_entries(ee->table))) != -1) else if ((i = encoding_lookup_in_table(u, ee->table)) != -1)
c = i + 0x80; c = i + 0x80;
else else
c = '?'; c = '?';
...@@ -84,10 +87,17 @@ int eightbit_write(EncodingPriv *e, UCS4 u, char **s, int *bufsize) ...@@ -84,10 +87,17 @@ int eightbit_write(EncodingPriv *e, UCS4 u, char **s, int *bufsize)
return 1; return 1;
} }
EncodingPriv enc_koi8r = static void eightbit_delete(EncodingPriv *e)
{
EightBit_Encoding *ee = (EightBit_Encoding *) e;
if (ee->table)
encoding_discard_map_file(ee->table);
}
EncodingPriv enc_eightbit =
{ {
eightbit_read, eightbit_read,
koi8r_reset, eightbit_reset,
sizeof(EightBit_Encoding) - sizeof(EncodingPriv), sizeof(EightBit_Encoding) - sizeof(EncodingPriv),
eightbit_delete, eightbit_delete,
0, 0,
......
...@@ -22,10 +22,7 @@ ...@@ -22,10 +22,7 @@
#include "iso2022.h" #include "iso2022.h"
#include "shiftjis.h" #include "shiftjis.h"
#include "bigfive.h" #include "bigfive.h"
#include "koi8r.h" #include "eightbit.h"
#include "microsoft.h"
#include "apple.h"
#include "acorn.h"
#include "enc_utf8.h" #include "enc_utf8.h"
#include "enc_utf16.h" #include "enc_utf16.h"
#include "enc_ucs4.h" #include "enc_ucs4.h"
...@@ -34,21 +31,38 @@ ...@@ -34,21 +31,38 @@
#include "VersionNum" #include "VersionNum"
/* ----------------------------------------------------------------------------- */
static char version[] = "Unicode library " Module_MajorVersion " " Module_Date " " Module_MinorVersion ; static char version[] = "Unicode library " Module_MajorVersion " " Module_Date " " Module_MinorVersion ;
/* ----------------------------------------------------------------------------- */
#define ENC_ascii 0
#define ENC_iso8859 1
#define ENC_shiftjis 2
#define ENC_eightbit 3
#define ENC_iso2022_escapes 4
#define ENC_iso2022_euc 5
#define ENC_iso2022 6
#define ENC_bigfive 7
#define ENC_utf8 8
#define ENC_utf16 9
#define ENC_ucs4 10
#define ENC_iso2022_shifts 11
static EncList enclist[] = static EncList enclist[] =
{ {
{ 3, "/US-ASCII/", &enc_ascii, NULL }, { 3, "/US-ASCII/", (EncodingPriv *)ENC_ascii, NULL },
{ 4, "/ISO-8859-1/ISO-IR-101/", &enc_iso8859, "\x1B\x2D\x41\x1B\x2F\x50" /* Select Latin-1 right half and G3 supplement */ }, { 4, "/ISO-8859-1/ISO-IR-101/", (EncodingPriv *)ENC_iso8859, "\x1B\x2D\x41\x1B\x2F\x50" /* Select Latin-1 right half and G3 supplement */ },
{ 5, "/ISO-8859-2/ISO-IR-102/", &enc_iso8859, "\x1B\x2D\x42\x1B\x2F\x50" }, /* Select Latin-2 right half */ { 5, "/ISO-8859-2/ISO-IR-102/", (EncodingPriv *)ENC_iso8859, "\x1B\x2D\x42\x1B\x2F\x50" }, /* Select Latin-2 right half */
{ 6, "/ISO-8859-3/", &enc_iso8859, "\x1B\x2D\x43\x1B\x2F\x50" }, /* Select Latin-3 right half */ { 6, "/ISO-8859-3/", (EncodingPriv *)ENC_iso8859, "\x1B\x2D\x43\x1B\x2F\x50" }, /* Select Latin-3 right half */
{ 7, "/ISO-8859-4/", &enc_iso8859, "\x1B\x2D\x44\x1B\x2F\x50" }, /* Select Latin-4 right half */ { 7, "/ISO-8859-4/", (EncodingPriv *)ENC_iso8859, "\x1B\x2D\x44\x1B\x2F\x50" }, /* Select Latin-4 right half */
{ 8, "/ISO-8859-5/", &enc_iso8859, "\x1B\x2D\x4C" }, /* Select Cyrillic right half */ { 8, "/ISO-8859-5/", (EncodingPriv *)ENC_iso8859, "\x1B\x2D\x4C" }, /* Select Cyrillic right half */
{ 10, "/ISO-8859-7/", &enc_iso8859, "\x1B\x2D\x46" }, /* Select Greek right half */ { 10, "/ISO-8859-7/", (EncodingPriv *)ENC_iso8859, "\x1B\x2D\x46" }, /* Select Greek right half */
{ 11, "/ISO-8859-8/", &enc_iso8859, "\x1B\x2D\x48" }, /* Select Hebrew right half */ { 11, "/ISO-8859-8/", (EncodingPriv *)ENC_iso8859, "\x1B\x2D\x48" }, /* Select Hebrew right half */
{ 12, "/ISO-8859-9/", &enc_iso8859, "\x1B\x2D\x4D\x1B\x2F\x50" }, /* Select Latin-5 right half */ { 12, "/ISO-8859-9/", (EncodingPriv *)ENC_iso8859, "\x1B\x2D\x4D\x1B\x2F\x50" }, /* Select Latin-5 right half */
{ 13, "/ISO-8859-10/", &enc_iso8859, "\x1B\x2D\x56\x1B\x2E\x58" }, /* Select Latin-6 right half, and Sami supplement as G2 */ { 13, "/ISO-8859-10/", (EncodingPriv *)ENC_iso8859, "\x1B\x2D\x56\x1B\x2E\x58" }, /* Select Latin-6 right half, and Sami supplement as G2 */
{ 17, "/SHIFT_JIS/X-SJIS/", &enc_shiftjis }, { 17, "/SHIFT_JIS/X-SJIS/", (EncodingPriv *)ENC_shiftjis },
/* /*
* Select G0 = JIS X 0201 Roman (ESC ( J) * Select G0 = JIS X 0201 Roman (ESC ( J)
...@@ -58,7 +72,7 @@ static EncList enclist[] = ...@@ -58,7 +72,7 @@ static EncList enclist[] =
* C1 = ISO 6429 (ESC " C) * C1 = ISO 6429 (ESC " C)
* Single shift range = GR (ESC SP \) * Single shift range = GR (ESC SP \)
*/ */
{ 18, "/EUC-JP/", &enc_iso2022_euc, { 18, "/EUC-JP/", (EncodingPriv *)ENC_iso2022_euc,
"\x1B\x28\x4A" "\x1B\x28\x4A"
"\x1B\x24\x29\x42" "\x1B\x24\x29\x42"
"\x1B\x2A\x49" "\x1B\x2A\x49"
...@@ -66,52 +80,109 @@ static EncList enclist[] = ...@@ -66,52 +80,109 @@ static EncList enclist[] =
"\x1B\x22\x43" "\x1B\x22\x43"
"\x1B\x20\x5C" }, "\x1B\x20\x5C" },
{ 37, "/ISO-2022-KR/", &enc_iso2022_shifts, NULL, { 37, "/ISO-2022-KR/", (EncodingPriv *)ENC_iso2022_shifts, NULL,
"\x1B\x24\x29\x43" }, "\x1B\x24\x29\x43" },
{ 38, "/EUC-KR/", &enc_iso2022_euc, { 38, "/EUC-KR/", (EncodingPriv *)ENC_iso2022_euc,
"\x1B\x24\x29\x43" }, /* Select G1 = KS C 5601 */ "\x1B\x24\x29\x43" }, /* Select G1 = KS C 5601 */
{ 39, "/ISO-2022-JP/JIS_Encoding/", &enc_iso2022_escapes, NULL, { 39, "/ISO-2022-JP/JIS_Encoding/", (EncodingPriv *)ENC_iso2022_escapes, NULL,
"\x1B\x28\x42" "\x1B\x28\x42"
"\x1B\x28\x4A" "\x1B\x28\x4A"
"\x1B\x24\x40" "\x1B\x24\x40"
"\x1B\x24\x42" }, "\x1B\x24\x42" },
{ 40, "/ISO-2022-JP-2/", &enc_iso2022_escapes, NULL, { 40, "/ISO-2022-JP-2/", (EncodingPriv *)ENC_iso2022_escapes, NULL,
"\x1B\x28\x42" "\x1B\x28\x42"
"\x1B\x28\x4A" "\x1B\x28\x4A"
"\x1B\x24\x40" "\x1B\x24\x40"
"\x1B\x24\x42" "\x1B\x24\x42"
"\x1B\x24\x28\x43" "\x1B\x24\x28\x43"
"\x1B\x24\x28\x44" }, "\x1B\x24\x28\x44" },
{ 104, "/ISO-2022-CN/", &enc_iso2022 { 104, "/ISO-2022-CN/", (EncodingPriv *)ENC_iso2022
}, },
{ 105, "/ISO-2022-CN-EXT/", &enc_iso2022 { 105, "/ISO-2022-CN-EXT/", (EncodingPriv *)ENC_iso2022
}, },
{ 106, "/UTF-8/UNICODE-1-1-UTF-8/UNICODE-2-0-UTF-8/", &enc_utf8 }, /* More general!!! */ { 106, "/UTF-8/UNICODE-1-1-UTF-8/UNICODE-2-0-UTF-8/", (EncodingPriv *)ENC_utf8 }, /* More general!!! */
{ 1001, "/ISO-10646-UCS-4/UCS-4/", &enc_ucs4 }, { 1001, "/ISO-10646-UCS-4/UCS-4/", (EncodingPriv *)ENC_ucs4 },
{ 1010, "/UCS-2/UTF-16/ISO-10646-UCS-2/UNICODE-1-1/UNICODE-2-0/", &enc_utf16 }, /* More general!!! */ { 1010, "/UCS-2/UTF-16/ISO-10646-UCS-2/UNICODE-1-1/UNICODE-2-0/", (EncodingPriv *)ENC_utf16 }, /* More general!!! */
{ 2022, "/ISO-2022/", &enc_iso2022 }, { 2022, "/ISO-2022/", (EncodingPriv *)ENC_iso2022 },
{ 2025, "/X-EUC_CN/GB2312/CN-GB/GB_2312-80", &enc_iso2022_euc, { 2025, "/X-EUC_CN/GB2312/CN-GB/GB_2312-80", (EncodingPriv *)ENC_iso2022_euc,
"\x1B\x24\x29\x41" }, /* Select G1 = GB 2312-80 */ "\x1B\x24\x29\x41" }, /* Select G1 = GB 2312-80 */
{ 2026, "/CN-BIG5/BIG5/", &enc_bigfive }, { 2026, "/CN-BIG5/BIG5/", (EncodingPriv *)ENC_bigfive },
{ 2027, "/MACINTOSH/", &enc_mac_roman }, { 2027, "/MACINTOSH/", (EncodingPriv *)ENC_eightbit, "Apple.MacRoman" },
{ 2084, "/KOI8-R/", &enc_koi8r }, { 2084, "/KOI8-R/", (EncodingPriv *)ENC_eightbit, "KOI8-R" },
{ 2250, "/WINDOWS-1250/", &enc_cp1250 }, { 2250, "/WINDOWS-1250/", (EncodingPriv *)ENC_eightbit, "Microsoft.CP1250" },
{ 2252, "/WINDOWS-1252/", &enc_cp1252 }, { 2252, "/WINDOWS-1252/", (EncodingPriv *)ENC_eightbit, "Microsoft.CP1252" },
{ csWelsh, "/ISO-IR-182/", &enc_iso8859, "\x1B\x2D\x5C" }, /* Select Welsh right half */ { csWelsh, "/ISO-IR-182/", (EncodingPriv *)ENC_iso8859, "\x1B\x2D\x5C" }, /* Select Welsh right half */
/* { 4001, "/ISO-IR-179/", &enc_baltic_rim }, */ /* { 4001, "/ISO-IR-179/", (EncodingPriv *)ENC_baltic_rim }, */
{ csSami, "/ISO-8859-15/ISO-IR-197/", &enc_iso8859, "\x1B\x2D\x5D" }, /* Select Sami right half */ { csSami, "/ISO-8859-15/ISO-IR-197/", (EncodingPriv *)ENC_iso8859, "\x1B\x2D\x5D" }, /* Select Sami right half */
{ csISOLatin13, "/ISO-8859-13/", &enc_iso8859, "\x1B\x2D\x59" }, /* Select Baltic Rim right half */ { csISOLatin13, "/ISO-8859-13/", (EncodingPriv *)ENC_iso8859, "\x1B\x2D\x59" }, /* Select Baltic Rim right half */
{ csAcornLatin1, "/X-ACORN-LATIN1/", &enc_acorn_latin1 }, { csAcornLatin1, "/X-ACORN-LATIN1/", (EncodingPriv *)ENC_eightbit, "Acorn.Latin1" },
{ 0, NULL, NULL } { 0, NULL, NULL }
}; };
/* ----------------------------------------------------------------------------- */ /* ----------------------------------------------------------------------------- */
static void fixup(void)
{
EncList *ep;
static int fixed = 0;
if (fixed)
return;
fixed = 1;
for (ep = enclist; ep->names ; ep++)
{
switch ((int)ep->encoding)
{
case ENC_ascii:
ep->encoding = &enc_ascii;
break;
case ENC_iso8859:
ep->encoding = &enc_iso8859;
break;
case ENC_shiftjis:
ep->encoding = &enc_shiftjis;
break;
case ENC_eightbit:
ep->encoding = &enc_eightbit;
break;
case ENC_iso2022_escapes:
ep->encoding = &enc_iso2022_escapes;
break;
case ENC_iso2022_euc:
ep->encoding = &enc_iso2022_euc;
break;
case ENC_iso2022:
ep->encoding = &enc_iso2022;
break;
case ENC_bigfive:
ep->encoding = &enc_bigfive;
break;
case ENC_utf8:
ep->encoding = &enc_utf8;
break;
case ENC_utf16:
ep->encoding = &enc_utf16;
break;
case ENC_ucs4:
ep->encoding = &enc_ucs4;
break;
case ENC_iso2022_shifts:
ep->encoding = &enc_iso2022_shifts;
break;
}
}
}
/* ----------------------------------------------------------------------------- */
Encoding *encoding_new(int n, int for_encoding) Encoding *encoding_new(int n, int for_encoding)
{ {
struct EncList *e = enclist; struct EncList *e = enclist;
EncodingPriv *enc; EncodingPriv *enc;
fixup();
for (e = enclist; e->identifier; e++) for (e = enclist; e->identifier; e++)
{ {
if (e->identifier == n) if (e->identifier == n)
...@@ -184,6 +255,83 @@ int encoding_write(Encoding *e, UCS4 c, char **buf, int *bufsize) ...@@ -184,6 +255,83 @@ int encoding_write(Encoding *e, UCS4 c, char **buf, int *bufsize)
/* ----------------------------------------------------------------------------- */ /* ----------------------------------------------------------------------------- */
#define DEPTH_CUTOFF 3
typedef struct table_info table_info;
struct table_info
{
table_info *next;
char *name;
UCS2 *table; /* pointer to the table */
int n_entries; /* number of main entries in table */
int alloc; /* does the pointer need freeing? */
int usage; /* number of current users */
};
static encoding_table enc_table_list = NULL;
UCS2 *encoding_table_ptr(encoding_table t)
{
return t->table;
}
int encoding_n_table_entries(encoding_table t)
{
return t->n_entries;
}
/* Table size is number of bytes including the length word
* Need to convert to number of 16bit entris
*/
int encoding_lookup_in_table(UCS4 u, encoding_table t)
{
const UCS2 *tt = t->table;
int n_entries = t->n_entries;
if (tt)
{
int i;
for (i = 0; i < n_entries; i++, tt++)
if ((UCS4)*tt == u)
return i;
}
return -1;
}
static encoding_table look_for_table(const char *name, encoding_table *pprev)
{
encoding_table t, prev;
int depth = 0;
for (prev = NULL, t = enc_table_list;
t;
prev = t, t = t->next)
{
if (strcmp(t->name, name) == 0)
break;
else
depth++;
}
if (pprev)
*pprev = depth > DEPTH_CUTOFF ? prev : NULL;
return t;
}
static void add_to_list(encoding_table t)
{
t->next = enc_table_list;
enc_table_list = t;
}
/* ----------------------------------------------------------------------------- */
static int mime_token_char(UCS4 c) static int mime_token_char(UCS4 c)
{ {
if (c < 0x21 || c > 0x7E) return 0; if (c < 0x21 || c > 0x7E) return 0;
...@@ -233,15 +381,40 @@ int encoding_number_from_name(const char *name) ...@@ -233,15 +381,40 @@ int encoding_number_from_name(const char *name)
/* To be supplied by the application */ /* To be supplied by the application */
/* extern void encoding_leaf_to_path(char *out, const char *leaf); */ /* extern void encoding_leaf_to_path(char *out, const char *leaf); */
void *encoding_load_map_file(const char *leaf) encoding_table encoding_load_map_file(const char *leaf)
{ {
int ftype = 0, flen, fh, filesys; int ftype = 0, flen, fh, filesys;
void *inthandle; void *inthandle;
char fname[256]; char fname[256];
_kernel_oserror *e; _kernel_oserror *e;
void *table; encoding_table t, prev;
fdebugf(stderr, "encoding_load_map_file: '%s'\n", leaf);
/* see if this is already in memory */
t = look_for_table(leaf, &prev);
if (t)
{
fdebugf(stderr, "encoding_load_map_file: found %p\n", t);
/* encoding_leaf_to_path(fname, leaf); */ t->usage++;
/* 'prev' is returned if 't' is further than a certain number
of levels down */
if (prev)
{
fdebugf(stderr, "encoding_load_map_file: move to top prev %p\n", prev);
/* take 't' out of list */
prev->next = t->next;
/* add 't' back in at head */
add_to_list(t);
}
return t;
}
/* otherwise load it */
strcpy(fname, "Unicode:Encodings."); strcpy(fname, "Unicode:Encodings.");
strncat(fname, leaf, sizeof(fname)); strncat(fname, leaf, sizeof(fname));
fname[sizeof(fname)-1] = 0; fname[sizeof(fname)-1] = 0;
...@@ -249,7 +422,9 @@ void *encoding_load_map_file(const char *leaf) ...@@ -249,7 +422,9 @@ void *encoding_load_map_file(const char *leaf)
/* Check it's a file, and get it's length */ /* Check it's a file, and get it's length */
_swix(OS_File, _INR(0,1)|_OUT(0)|_OUT(4), 23, fname, &ftype, &flen); _swix(OS_File, _INR(0,1)|_OUT(0)|_OUT(4), 23, fname, &ftype, &flen);
if (ftype != 1) fdebugf(stderr, "encoding_load_map_file: '%s' type %d len %d\n", fname, ftype, flen);
if ((ftype & 1) == 0)
return NULL; return NULL;
/* Open the file for input */ /* Open the file for input */
...@@ -259,31 +434,73 @@ void *encoding_load_map_file(const char *leaf) ...@@ -259,31 +434,73 @@ void *encoding_load_map_file(const char *leaf)
/* Obtain the filing system number and internal handle */ /* Obtain the filing system number and internal handle */
e = _swix(OS_FSControl, _INR(0,1)|_OUTR(1,2), 21, fh, &inthandle, &filesys); e = _swix(OS_FSControl, _INR(0,1)|_OUTR(1,2), 21, fh, &inthandle, &filesys);
if (e)
return NULL;
/* Close the file */ /* Close the file */
_swix(OS_Find, _INR(0,1), 0, fh); _swix(OS_Find, _INR(0,1), 0, fh);
/* return if an error after closing file */
if (e)
return NULL;
/* allocate space for description structure */
if ((t = encoding__alloc(sizeof(*t))) == NULL)
return NULL;
memset(t, 0, sizeof(*t));
/* take copy of name */
t->name = encoding__alloc(strlen(leaf)+1);
if (!t->name)
{
encoding__free(t);
return NULL;
}
strcpy(t->name, leaf);
/* If it's ResourceFS, return a direct pointer */ /* If it's ResourceFS, return a direct pointer */
if ((filesys & 0xFF) == 46) if ((filesys & 0xFF) == 46)
return inthandle; {
t->table = (UCS2 *)inthandle;
t->n_entries = (((const int *)t->table)[-1] - 4)/2;
}
else
{
/* Otherwise, load it */ /* Otherwise, load it */
table = encoding__alloc(flen+4); t->table = encoding__alloc(flen);
if (!table) t->alloc = 1;
return NULL; if (t->table)
{
t->n_entries = flen/2;
e = _swix(OS_File, _INR(0,3), 16, fname, (char *)table+4, 0); e = _swix(OS_File, _INR(0,3), 16, fname, t->table, 0);
if (e) if (e)
{ {
encoding__free(table); encoding__free(t->table);
return NULL; t->table = NULL;
}
}
} }
*(int *)table = flen+4; if (t->table)
{
t->usage++;
add_to_list(t);
}
else
{
encoding__free(t->name);
encoding__free(t);
t = NULL;
}
return t;
}
return (char *)table + 4; void encoding_discard_map_file(encoding_table t)
{
t->alloc--;
} }
encoding_alloc_fn encoding__alloc = malloc; encoding_alloc_fn encoding__alloc = malloc;
...@@ -295,29 +512,4 @@ void encoding_set_alloc_fns(encoding_alloc_fn alloc, encoding_free_fn free) ...@@ -295,29 +512,4 @@ void encoding_set_alloc_fns(encoding_alloc_fn alloc, encoding_free_fn free)
encoding__free = free; encoding__free = free;
} }
/* Table size is number of bytes including the length word
* Need to convert to number of 16bit entris
*/
int encoding_n_table_entries(const UCS2 *table)
{
return table ? (((const int *)table)[-1] - 4)/2 : 0;
}
int encoding_lookup_in_table(UCS4 u, const UCS2 *table, int n_entries)
{
const UCS2 *tt = table;
if (tt)
{
int i;
for (i = 0; i < n_entries; i++, tt++)
if ((UCS4)*tt == u)
return i;
}
return -1;
}
/* eof encoding.c */ /* eof encoding.c */
...@@ -30,7 +30,7 @@ typedef struct ISO2022_Encoding ISO2022_Encoding; ...@@ -30,7 +30,7 @@ typedef struct ISO2022_Encoding ISO2022_Encoding;
struct ISO2022_EncoderSet struct ISO2022_EncoderSet
{ {
UCS2 *table; encoding_table table;
const char *esc_seq; const char *esc_seq;
int esc_seq_len; int esc_seq_len;
...@@ -97,13 +97,13 @@ struct ISO2022_Set ...@@ -97,13 +97,13 @@ struct ISO2022_Set
typedef struct simple_set typedef struct simple_set
{ {
ISO2022_Set s; ISO2022_Set s;
UCS2 *table; encoding_table table;
} simple_set; } simple_set;
/* ---------------------------------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------------------------------------- */
static UCS2 *table94[0x3F], *table96[0x3F], *table128[0x3F], *table94x94[0x3F]; /* static UCS2 *table94[0x3F], *table96[0x3F], *table128[0x3F], *table94x94[0x3F]; */
static UCS2 *tableC0[0x3F], *tableC1[0x3F]; /* static UCS2 *tableC0[0x3F], *tableC1[0x3F]; */
/* ---------------------------------------------------------------------------------------------------- */ /* ---------------------------------------------------------------------------------------------------- */
...@@ -129,7 +129,7 @@ static UCS4 simple_double_next_code_94(ISO2022_Set *s, int c, int invoker, char ...@@ -129,7 +129,7 @@ static UCS4 simple_double_next_code_94(ISO2022_Set *s, int c, int invoker, char
} }
else else
{ {
UCS4 u = ss->table[94*(*sync-1) + c-1]; UCS4 u = encoding_table_ptr(ss->table)[94*(*sync-1) + c-1];
*sync = 0; *sync = 0;
return u; return u;
} }
...@@ -143,7 +143,7 @@ static UCS4 null_double_next_code(ISO2022_Set *s, int c, int invoker, char *sync ...@@ -143,7 +143,7 @@ static UCS4 null_double_next_code(ISO2022_Set *s, int c, int invoker, char *sync
static UCS4 simple_next_code_94(ISO2022_Set *s, int c, int invoker, char *sync) static UCS4 simple_next_code_94(ISO2022_Set *s, int c, int invoker, char *sync)
{ {
if (c > 0 && c < 0x5F) if (c > 0 && c < 0x5F)
return ((simple_set *)s)->table[c-1]; /* -1 for 94 byte tables */ return encoding_table_ptr(((simple_set *)s)->table)[c-1]; /* -1 for 94 byte tables */
if (invoker != _GL) if (invoker != _GL)
return 0xFFFD; return 0xFFFD;
...@@ -153,7 +153,7 @@ static UCS4 simple_next_code_94(ISO2022_Set *s, int c, int invoker, char *sync) ...@@ -153,7 +153,7 @@ static UCS4 simple_next_code_94(ISO2022_Set *s, int c, int invoker, char *sync)
static UCS4 simple_next_code_96(ISO2022_Set *s, int c, int invoker, char *sync) static UCS4 simple_next_code_96(ISO2022_Set *s, int c, int invoker, char *sync)
{ {
return ((simple_set *)s)->table[c]; return encoding_table_ptr(((simple_set *)s)->table)[c];
} }
static UCS4 null_next_code_94(ISO2022_Set *s, int c, int invoker, char *sync) static UCS4 null_next_code_94(ISO2022_Set *s, int c, int invoker, char *sync)
...@@ -200,50 +200,44 @@ static void iso2022_ss(ISO2022_Encoding *i, int n) ...@@ -200,50 +200,44 @@ static void iso2022_ss(ISO2022_Encoding *i, int n)
} }
} }
UCS2 *iso2022_find_table(int type, int id) encoding_table iso2022_find_table(int type, int id)
{ {
UCS2 **table;
const char *dir; const char *dir;
char fname[256]; char fname[256];
switch (type) switch (type)
{ {
case 32: case 32:
table = tableC0 + id - 0x40; /* table = tableC0 + id - 0x40; */
dir = "C0"; dir = "C0";
break; break;
case 32+1: case 32+1:
table = tableC1 + id - 0x40; /* table = tableC1 + id - 0x40; */
dir = "C1"; dir = "C1";
break; break;
case 94: case 94:
table = table94 + id - 0x40; /* table = table94 + id - 0x40; */
dir = "G94"; dir = "G94";
break; break;
case 96: case 96:
table = table96 + id - 0x40; /* table = table96 + id - 0x40; */
dir = "G96"; dir = "G96";
break; break;
case 94*94: case 94*94:
table = table94x94 + id - 0x40; /* table = table94x94 + id - 0x40; */
dir = "G94x94"; dir = "G94x94";
break; break;
default: default:
return NULL; return NULL;
} }
if (!*table)
{
sprintf(fname, "ISO2022.%s.%02X*", dir, id); sprintf(fname, "ISO2022.%s.%02X*", dir, id);
*table = encoding_load_map_file(fname); return encoding_load_map_file(fname);
}
return *table;
} }
static int iso2022_select_set(ISO2022_Encoding *i, int setno, int type, int id) static int iso2022_select_set(ISO2022_Encoding *i, int setno, int type, int id)
{ {
UCS2 *t; encoding_table t;
ISO2022_Set *set; ISO2022_Set *set;
/* This can return NULL if the table is not present in which case /* This can return NULL if the table is not present in which case
...@@ -596,14 +590,13 @@ static int iso2022_scan_tables(ISO2022_Encoding *enc, UCS4 u, int *index, int *t ...@@ -596,14 +590,13 @@ static int iso2022_scan_tables(ISO2022_Encoding *enc, UCS4 u, int *index, int *t
int i, tab; int i, tab;
for (tab = 0; tab < MAX_TABLES; tab++) for (tab = 0; tab < MAX_TABLES; tab++)
{ {
UCS2 *table = enc->table[tab].table; encoding_table table = enc->table[tab].table;
int n_entries = encoding_n_table_entries(table);
if ((i = encoding_lookup_in_table(u, table, n_entries)) != -1) if ((i = encoding_lookup_in_table(u, table)) != -1)
{ {
*index = i; *index = i;
*table_no = tab; *table_no = tab;
*size = n_entries; *size = encoding_n_table_entries(table);
return 1; return 1;
} }
} }
...@@ -705,15 +698,14 @@ static int iso2022_scan_sets(ISO2022_Encoding *enc, UCS4 u, int *index, int *tab ...@@ -705,15 +698,14 @@ static int iso2022_scan_sets(ISO2022_Encoding *enc, UCS4 u, int *index, int *tab
for (set = 0; set < 4; set++) for (set = 0; set < 4; set++)
{ {
simple_set *setptr = (simple_set *) enc->Set[set]; simple_set *setptr = (simple_set *) enc->Set[set];
int n_entries = encoding_n_table_entries(setptr->table);
/* fprintf(stderr, "scan_table: set %d table %p n %d\n", set, setptr->table, n_entries); */ /* fprintf(stderr, "scan_table: set %d table %p n %d\n", set, setptr->table, n_entries); */
if ((i = encoding_lookup_in_table(u, setptr->table, n_entries)) != -1) if ((i = encoding_lookup_in_table(u, setptr->table)) != -1)
{ {
*index = i; *index = i;
*table_no = set; *table_no = set;
*size = n_entries; *size = encoding_n_table_entries(setptr->table);
return 1; return 1;
} }
} }
......
/* Copyright 1997 Acorn Computers Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
#include "encpriv.h"
#include "koi8r.h"
#include "microsoft.h"
/*
* Routines for encoding Windows-1250 ("Latin-2")
* Number: 2250
* Names: Windows-1250
*/
static UCS2 *cp1250_table;
static int cp1250_reset(Encoding *e, int for_encoding)
{
EightBit_Encoding *ee = (EightBit_Encoding *) e;
if (!cp1250_table)
cp1250_table = encoding_load_map_file("Microsoft.CP1250");
ee->table = cp1250_table;
return ee->table != NULL;
}
EncodingPriv enc_cp1250 =
{
eightbit_read,
cp1250_reset,
sizeof(EightBit_Encoding) - sizeof(EncodingPriv),
eightbit_delete,
0,
eightbit_write
};
/*
* Routines for encoding Windows-1252 ("Latin-1")
* Number: 2252
* Names: Windows-1252
*/
static UCS2 *cp1252_table;
static int cp1252_reset(Encoding *e, int for_encoding)
{
EightBit_Encoding *ee = (EightBit_Encoding *) e;
if (!cp1252_table)
cp1252_table = encoding_load_map_file("Microsoft.CP1252");
ee->table = cp1252_table;
return ee->table != NULL;
}
EncodingPriv enc_cp1252 =
{
eightbit_read,
cp1252_reset,
sizeof(EightBit_Encoding) - sizeof(EncodingPriv),
eightbit_delete,
0,
eightbit_write
};
...@@ -20,12 +20,11 @@ ...@@ -20,12 +20,11 @@
#include "shiftjis.h" #include "shiftjis.h"
static UCS2 *roman, *katakana, *kanji;
typedef struct ShiftJIS_Encoding typedef struct ShiftJIS_Encoding
{ {
EncodingPriv e; EncodingPriv e;
char prev; char prev;
encoding_table roman, katakana, kanji;
} ShiftJIS_Encoding; } ShiftJIS_Encoding;
/* /*
...@@ -36,7 +35,7 @@ typedef struct ShiftJIS_Encoding ...@@ -36,7 +35,7 @@ typedef struct ShiftJIS_Encoding
* csShiftJIS * csShiftJIS
*/ */
static UCS4 kanji_to_ucs(int c1, int c2) static UCS4 kanji_to_ucs(const UCS2 *kanji, int c1, int c2)
{ {
UCS4 u; UCS4 u;
...@@ -83,18 +82,18 @@ static int shiftjis_reset(EncodingPriv *e, int for_encoding) ...@@ -83,18 +82,18 @@ static int shiftjis_reset(EncodingPriv *e, int for_encoding)
{ {
ShiftJIS_Encoding *sj = (ShiftJIS_Encoding *) e; ShiftJIS_Encoding *sj = (ShiftJIS_Encoding *) e;
if (!roman) if (!sj->roman)
roman = iso2022_find_table(94, 0x4A); sj->roman = iso2022_find_table(94, 0x4A);
if (!katakana) if (!sj->katakana)
katakana = iso2022_find_table(94, 0x49); sj->katakana = iso2022_find_table(94, 0x49);
if (!kanji) if (!sj->kanji)
kanji = iso2022_find_table(94*94, 0x42); sj->kanji = iso2022_find_table(94*94, 0x42);
sj->prev = 0; sj->prev = 0;
return roman && katakana && kanji; return sj->roman && sj->katakana && sj->kanji;
} }
static unsigned int shiftjis_read(Encoding *e, static unsigned int shiftjis_read(Encoding *e,
...@@ -105,6 +104,9 @@ static unsigned int shiftjis_read(Encoding *e, ...@@ -105,6 +104,9 @@ static unsigned int shiftjis_read(Encoding *e,
{ {
ShiftJIS_Encoding *sj = (ShiftJIS_Encoding *) e; ShiftJIS_Encoding *sj = (ShiftJIS_Encoding *) e;
unsigned int count; unsigned int count;
const UCS2 *roman = encoding_table_ptr(sj->roman);
const UCS2 *kanji = encoding_table_ptr(sj->kanji);
const UCS2 *katakana = encoding_table_ptr(sj->katakana);
for (count = n; count; count--) for (count = n; count; count--)
{ {
...@@ -113,7 +115,7 @@ static unsigned int shiftjis_read(Encoding *e, ...@@ -113,7 +115,7 @@ static unsigned int shiftjis_read(Encoding *e,
if (sj->prev) if (sj->prev)
{ {
u = kanji_to_ucs(sj->prev, c); u = kanji_to_ucs(kanji, sj->prev, c);
sj->prev = 0; sj->prev = 0;
} }
else else
...@@ -159,25 +161,25 @@ static unsigned int shiftjis_read(Encoding *e, ...@@ -159,25 +161,25 @@ static unsigned int shiftjis_read(Encoding *e,
return n - count; return n - count;
} }
static int lookup_table(UCS4 u, int *index, int *table_no) static int lookup_table(UCS4 u, ShiftJIS_Encoding *sj, int *index, int *table_no)
{ {
int i; int i;
if ((i = encoding_lookup_in_table(u, roman, encoding_n_table_entries(roman))) != -1) if ((i = encoding_lookup_in_table(u, sj->roman)) != -1)
{ {
*table_no = 0; *table_no = 0;
*index = i; *index = i;
return 1; return 1;
} }
if ((i = encoding_lookup_in_table(u, katakana, encoding_n_table_entries(katakana))) != -1) if ((i = encoding_lookup_in_table(u, sj->katakana)) != -1)
{ {
*table_no = 1; *table_no = 1;
*index = i; *index = i;
return 1; return 1;
} }
if ((i = encoding_lookup_in_table(u, kanji, encoding_n_table_entries(kanji))) != -1) if ((i = encoding_lookup_in_table(u, sj->kanji)) != -1)
{ {
*table_no = 2; *table_no = 2;
*index = i; *index = i;
...@@ -197,7 +199,7 @@ static int shiftjis_write(EncodingPriv *e, UCS4 u, char **sjis, int *bufsize) ...@@ -197,7 +199,7 @@ static int shiftjis_write(EncodingPriv *e, UCS4 u, char **sjis, int *bufsize)
if (u < 0x0021) if (u < 0x0021)
c = u; c = u;
else if (lookup_table(u, &index, &table)) else if (lookup_table(u, sj, &index, &table))
{ {
switch (table) switch (table)
{ {
...@@ -255,12 +257,23 @@ static int shiftjis_write(EncodingPriv *e, UCS4 u, char **sjis, int *bufsize) ...@@ -255,12 +257,23 @@ static int shiftjis_write(EncodingPriv *e, UCS4 u, char **sjis, int *bufsize)
sj = sj; sj = sj;
} }
static void shiftjis_delete(EncodingPriv *e)
{
ShiftJIS_Encoding *sj = (ShiftJIS_Encoding *) e;
if (sj->roman)
encoding_discard_map_file(sj->roman);
if (sj->katakana)
encoding_discard_map_file(sj->katakana);
if (sj->kanji)
encoding_discard_map_file(sj->kanji);
}
EncodingPriv enc_shiftjis = EncodingPriv enc_shiftjis =
{ {
shiftjis_read, shiftjis_read,
shiftjis_reset, shiftjis_reset,
sizeof(ShiftJIS_Encoding) - sizeof(EncodingPriv), sizeof(ShiftJIS_Encoding) - sizeof(EncodingPriv),
0, /* shiftjis_delete */ shiftjis_delete,
0, /* enable iso2022 */ 0, /* enable iso2022 */
shiftjis_write shiftjis_write
}; };
/* Copyright 1997 Acorn Computers Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
extern EncodingPriv enc_acorn_latin1;
...@@ -12,4 +12,4 @@ ...@@ -12,4 +12,4 @@
* See the License for the specific language governing permissions and * See the License for the specific language governing permissions and
* limitations under the License. * limitations under the License.
*/ */
extern EncodingPriv enc_mac_roman; extern EncodingPriv enc_eightbit;
...@@ -65,20 +65,31 @@ struct EncodingPriv ...@@ -65,20 +65,31 @@ struct EncodingPriv
int for_encoding; int for_encoding;
}; };
/*
* Load a named map file into a malloc block, or return a pointer to it if in
* ResourceFS.
*/
void *encoding_load_map_file(const char *fname);
/* Exported function pointers for the library internal use only */ /* Exported function pointers for the library internal use only */
extern encoding_alloc_fn encoding__alloc; extern encoding_alloc_fn encoding__alloc;
extern encoding_free_fn encoding__free; extern encoding_free_fn encoding__free;
extern int encoding_n_table_entries(const UCS2 *table); /* Encoding table functions */
typedef struct table_info *encoding_table;
extern UCS2 *encoding_table_ptr(encoding_table t);
extern int encoding_n_table_entries(encoding_table t);
extern int encoding_lookup_in_table(UCS4 u, encoding_table t);
extern int encoding_lookup_in_table(UCS4 u, const UCS2 *table, int n_entries); /*
* Load a named map file into a malloc block, or return a pointer to it if in
* ResourceFS.
*/
extern encoding_table encoding_load_map_file(const char *fname);
extern void encoding_discard_map_file(encoding_table t);
#if DEBUG
#define fdebugf fprintf
#else
#define fdebugf 1?0:fprintf
#endif
#endif #endif
...@@ -21,6 +21,6 @@ extern EncodingPriv enc_iso2022_escapes; ...@@ -21,6 +21,6 @@ extern EncodingPriv enc_iso2022_escapes;
#define enc_iso8859 enc_iso2022_euc /* 8859-X character sets can use same output as EUC */ #define enc_iso8859 enc_iso2022_euc /* 8859-X character sets can use same output as EUC */
#define enc_iso2022_shifts enc_iso2022 #define enc_iso2022_shifts enc_iso2022
extern UCS2 *iso2022_find_table(int type, int id); extern encoding_table iso2022_find_table(int type, int id);
#endif #endif
/* Copyright 1997 Acorn Computers Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
typedef struct EightBit_Encoding
{
EncodingPriv e;
UCS2 *table; /* 128-entry table for codes 0x80-0xFF */
} EightBit_Encoding;
extern EncodingPriv enc_koi8r;
extern unsigned int eightbit_read(EncodingPriv *e,
encoding_read_callback_fn ucs_out,
const char *s,
unsigned int n,
void *handle);
extern int eightbit_write(EncodingPriv *e, UCS4 u, char **s, int *bufsize);
#define eightbit_delete 0
/* Copyright 1997 Acorn Computers Ltd
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
extern EncodingPriv enc_cp1250;
extern EncodingPriv enc_cp1252;
...@@ -23,13 +23,11 @@ ASflags = -Stamp -quit ...@@ -23,13 +23,11 @@ ASflags = -Stamp -quit
.SUFFIXES: .c .s .o .oz .od .odz .SUFFIXES: .c .s .o .oz .od .odz
.c.o:; $(CC) -DROM=0 $(CCflags) -o $@ $< .c.o:; $(CC) -DROM=0 -DDEBUG=0 $(CCflags) -o $@ $<
.c.od:; $(CC) -DROM=0 -DDEBUG=1 -Fn $(CCflags) -o $@ $< .c.od:; $(CC) -DROM=0 -DDEBUG=1 -Fn $(CCflags) -o $@ $<
.c.oz:; $(CC) -zM -DROM=1 $(CCflags) -o $@ $< .c.oz:; $(CC) -zM -DROM=1 -DDEBUG=0 $(CCflags) -o $@ $<
.c.odz:;$(CC) -zM -DROM=1 -DDEBUG=1 -Fn $(CCflags) -o $@ $<
.s.o:; $(AS) $(ASflags) -from $< -to $@ .s.o:; $(AS) $(ASflags) -from $< -to $@
...@@ -37,10 +35,7 @@ Objects = autojp.o unictype.o \ ...@@ -37,10 +35,7 @@ Objects = autojp.o unictype.o \
utf8.o \ utf8.o \
encoding.o \ encoding.o \
iso2022.o \ iso2022.o \
koi8r.o \ eightbit.o \
microsoft.o \
acorn.o \
apple.o \
shiftjis.o \ shiftjis.o \
bigfive.o \ bigfive.o \
enc_utf8.o \ enc_utf8.o \
...@@ -52,10 +47,7 @@ ObjectsD = autojp.od unictype.od \ ...@@ -52,10 +47,7 @@ ObjectsD = autojp.od unictype.od \
utf8.od \ utf8.od \
encoding.od \ encoding.od \
iso2022.od \ iso2022.od \
koi8r.od \ eightbit.od \
microsoft.od \
acorn.od \
apple.od \
shiftjis.od \ shiftjis.od \
bigfive.od \ bigfive.od \
enc_utf8.od \ enc_utf8.od \
...@@ -63,6 +55,18 @@ ObjectsD = autojp.od unictype.od \ ...@@ -63,6 +55,18 @@ ObjectsD = autojp.od unictype.od \
enc_utf16.od \ enc_utf16.od \
enc_ucs4.od enc_ucs4.od
ObjectsZ = autojp.oz unictype.oz \
utf8.oz \
encoding.oz \
iso2022.oz \
eightbit.oz \
shiftjis.oz \
bigfive.oz \
enc_utf8.oz \
enc_ascii.oz \
enc_utf16.oz \
enc_ucs4.oz
all: ucodelib all: ucodelib
ucodelib: $(Objects) ucodelib: $(Objects)
...@@ -71,13 +75,10 @@ ucodelib: $(Objects) ...@@ -71,13 +75,10 @@ ucodelib: $(Objects)
ucodelibd: $(ObjectsD) ucodelibd: $(ObjectsD)
armlib -c -o ucodelibd $(ObjectsD) armlib -c -o ucodelibd $(ObjectsD)
ucodelibzm: $(ObjectsZM) ucodelibz: $(ObjectsZ)
armlib -c -o ucodelibzm $(ObjectsZM) armlib -c -o ucodelibz $(ObjectsZ)
ucodelibdzm: $(ObjectsDZM)
armlib -c -o ucodelibdzm $(ObjectsDZM)
riscos_libs: ucodelib ucodelibd riscos_libs: ucodelib ucodelibd ucodelibz
riscos_export: riscos_libs riscos_export: riscos_libs
@-mkdir $(RISCOS_BUILD_EXPORT) @-mkdir $(RISCOS_BUILD_EXPORT)
...@@ -86,7 +87,7 @@ riscos_export: riscos_libs ...@@ -86,7 +87,7 @@ riscos_export: riscos_libs
@echo Made export directories @echo Made export directories
@-cp -p ucodelib $(RISCOS_BUILD_EXPORT)/Lib/Unicode/ucodelib.o @-cp -p ucodelib $(RISCOS_BUILD_EXPORT)/Lib/Unicode/ucodelib.o
@-cp -p ucodelibd $(RISCOS_BUILD_EXPORT)/Lib/Unicode/ucodelibd.o @-cp -p ucodelibd $(RISCOS_BUILD_EXPORT)/Lib/Unicode/ucodelibd.o
@-cp -p ucodelibzm $(RISCOS_BUILD_EXPORT)/Lib/Unicode/ucodelibzm.o @-cp -p ucodelibz $(RISCOS_BUILD_EXPORT)/Lib/Unicode/ucodelibz.o
@cp -p autojp.h $(RISCOS_BUILD_EXPORT)/Lib/Unicode/ @cp -p autojp.h $(RISCOS_BUILD_EXPORT)/Lib/Unicode/
@cp -p charsets.h $(RISCOS_BUILD_EXPORT)/Lib/Unicode/ @cp -p charsets.h $(RISCOS_BUILD_EXPORT)/Lib/Unicode/
@cp -p unictype.h $(RISCOS_BUILD_EXPORT)/Lib/Unicode/ @cp -p unictype.h $(RISCOS_BUILD_EXPORT)/Lib/Unicode/
......
...@@ -22,14 +22,12 @@ wantlink ../h/unictype unictype.h ...@@ -22,14 +22,12 @@ wantlink ../h/unictype unictype.h
wantlink ../c/mkunictype mkunictype.c wantlink ../c/mkunictype mkunictype.c
wantlink ../h/charsets charsets.h wantlink ../h/charsets charsets.h
wantlink ../h/encpriv encpriv.h wantlink ../h/encpriv encpriv.h
wantlink ../h/iso10646 iso10646.h
wantlink ../c/utf8 utf8.c wantlink ../c/utf8 utf8.c
wantlink ../c/encoding encoding.c wantlink ../c/encoding encoding.c
wantlink ../c/iso2022 iso2022.c wantlink ../c/iso2022 iso2022.c
wantlink ../c/koi8r koi8r.c wantlink ../c/eightbit eightbit.c
wantlink ../c/microsoft microsoft.c
wantlink ../c/acorn acorn.c
wantlink ../c/apple apple.c
wantlink ../c/shiftjis shiftjis.c wantlink ../c/shiftjis shiftjis.c
wantlink ../c/bigfive bigfive.c wantlink ../c/bigfive bigfive.c
wantlink ../c/enc_utf8 enc_utf8.c wantlink ../c/enc_utf8 enc_utf8.c
...@@ -40,15 +38,11 @@ wantlink ../c/enc_ucs4 enc_ucs4.c ...@@ -40,15 +38,11 @@ wantlink ../c/enc_ucs4 enc_ucs4.c
wantlink ../h/utf8 utf8.h wantlink ../h/utf8 utf8.h
wantlink ../h/encoding encoding.h wantlink ../h/encoding encoding.h
wantlink ../h/iso2022 iso2022.h wantlink ../h/iso2022 iso2022.h
wantlink ../h/koi8r koi8r.h wantlink ../h/eightbit eightbit.h
wantlink ../h/microsoft microsoft.h
wantlink ../h/acorn acorn.h
wantlink ../h/apple apple.h
wantlink ../h/shiftjis shiftjis.h wantlink ../h/shiftjis shiftjis.h
wantlink ../h/bigfive bigfive.h wantlink ../h/bigfive bigfive.h
wantlink ../h/enc_utf8 enc_utf8.h wantlink ../h/enc_utf8 enc_utf8.h
wantlink ../h/enc_ascii enc_ascii.h wantlink ../h/enc_ascii enc_ascii.h
wantlink ../h/enc_utf16 enc_utf16.h wantlink ../h/enc_utf16 enc_utf16.h
wantlink ../h/enc_ucs4 enc_ucs4.h wantlink ../h/enc_ucs4 enc_ucs4.h
wantlink ../h/iso10646 iso10646.h
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment