summaryrefslogtreecommitdiff
path: root/Build/source/texk/ptexenc/ptexenc.c
diff options
context:
space:
mode:
authorPeter Breitenlohner <peb@mppmu.mpg.de>2011-08-23 10:17:01 +0000
committerPeter Breitenlohner <peb@mppmu.mpg.de>2011-08-23 10:17:01 +0000
commit82e002633513b0b73099d293aba30fb14360fa9a (patch)
tree06d3e4ce4cde2988646b6967ca11598d22278cbe /Build/source/texk/ptexenc/ptexenc.c
parent16c57cd409df0f406fc2710bcadadbd790cab70b (diff)
more upTeX and e-upTeX
git-svn-id: svn://tug.org/texlive/trunk@23652 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk/ptexenc/ptexenc.c')
-rw-r--r--Build/source/texk/ptexenc/ptexenc.c145
1 files changed, 115 insertions, 30 deletions
diff --git a/Build/source/texk/ptexenc/ptexenc.c b/Build/source/texk/ptexenc/ptexenc.c
index c58863ff498..386c36cb477 100644
--- a/Build/source/texk/ptexenc/ptexenc.c
+++ b/Build/source/texk/ptexenc/ptexenc.c
@@ -21,6 +21,10 @@
#define ENC_EUC 2
#define ENC_SJIS 3
#define ENC_UTF8 4
+#define ENC_UPTEX 5
+
+static int default_kanji_enc = ENC_UTF8;
+static boolean UPTEX_enabled;
#define ESC '\033'
@@ -43,7 +47,6 @@ static int file_enc = ENC_UNKNOWN;
static int internal_enc = ENC_UNKNOWN;
static int terminal_enc = ENC_UNKNOWN;
-
static const_string enc_to_string(int enc)
{
switch (enc) {
@@ -51,6 +54,7 @@ static const_string enc_to_string(int enc)
case ENC_EUC: return "euc";
case ENC_SJIS: return "sjis";
case ENC_UTF8: return "utf8";
+ case ENC_UPTEX: if (UPTEX_enabled) return "uptex";
default: return "?";
}
}
@@ -58,11 +62,18 @@ static const_string enc_to_string(int enc)
static int string_to_enc(const_string str)
{
if (str == NULL) return ENC_UNKNOWN;
- if (strcasecmp(str, "default")== 0) return DEFAULT_KANJI_ENC;
+ if (strcasecmp(str, "default")== 0) return default_kanji_enc;
if (strcasecmp(str, "jis") == 0) return ENC_JIS;
if (strcasecmp(str, "euc") == 0) return ENC_EUC;
if (strcasecmp(str, "sjis") == 0) return ENC_SJIS;
if (strcasecmp(str, "utf8") == 0) return ENC_UTF8;
+ if (UPTEX_enabled && strcasecmp(str, "uptex") == 0) return ENC_UPTEX;
+
+ if (strcasecmp(str, "BINARY") == 0) return ENC_JIS;
+ if (strcasecmp(str, "ISO-2022-JP") == 0) return ENC_JIS;
+ if (strcasecmp(str, "EUC-JP") == 0) return ENC_EUC;
+ if (strcasecmp(str, "Shift_JIS") == 0) return ENC_SJIS;
+ if (strcasecmp(str, "UTF-8") == 0) return ENC_UTF8;
return -1; /* error */
}
@@ -79,17 +90,19 @@ static int get_default_enc(void)
} else if (enc != ENC_UNKNOWN) {
return enc;
}
- return DEFAULT_KANJI_ENC;
+ return default_kanji_enc;
}
static void set_file_enc(int enc)
{
- file_enc = enc;
+ if (enc == ENC_UPTEX) file_enc = ENC_UTF8;
+ else /* rest */ file_enc = enc;
}
static void set_internal_enc(int enc)
{
if (enc == ENC_SJIS) internal_enc = ENC_SJIS;
+ else if (UPTEX_enabled && enc == ENC_UPTEX) internal_enc = ENC_UPTEX;
else /* EUC, JIS, UTF8 */ internal_enc = ENC_EUC;
}
@@ -133,7 +146,14 @@ static int get_terminal_enc(void)
/* enable/disable UPTEX */
void enable_UPTEX (boolean enable)
{
- (void) enable;
+ UPTEX_enabled = enable;
+ if (enable)
+ default_kanji_enc = ENC_UPTEX;
+ else {
+ default_kanji_enc = ENC_UTF8;
+ if (internal_enc == ENC_UPTEX)
+ internal_enc = ENC_EUC;
+ }
}
const_string get_enc_string(void)
@@ -172,10 +192,43 @@ boolean is_internalSJIS(void)
return (internal_enc == ENC_SJIS);
}
+boolean is_internalEUC(void)
+{
+ return (internal_enc == ENC_EUC);
+}
+
+boolean is_internalUPTEX(void)
+{
+ return (internal_enc == ENC_UPTEX);
+}
+
+
+/* check char range */
+boolean ismultichr (int length, int nth, int c)
+{
+ if (is_internalUPTEX()) return isUTF8(length, nth, c);
+ if (length == 2) {
+ if (nth == 1) {
+ if (is_internalSJIS()) return isSJISkanji1(c);
+ /* EUC */ return isEUCkanji1(c);
+ } else if (nth == 2) {
+ if (is_internalSJIS()) return isSJISkanji2(c);
+ /* EUC */ return isEUCkanji2(c);
+ }
+ }
+ if ((length == 3 || length == 4) &&
+ (0 < nth && nth <= length)) return false;
+ fprintf(stderr, "ismultichr: unexpected param length=%d, nth=%d\n",
+ length, nth);
+ return false;
+}
/* check char range (kanji 1st) */
boolean iskanji1(int c)
{
+ if (is_internalUPTEX()) return (isUTF8(2,1,c) ||
+ isUTF8(3,1,c) ||
+ isUTF8(4,1,c));
if (is_internalSJIS()) return isSJISkanji1(c);
/* EUC */ return isEUCkanji1(c);
}
@@ -188,9 +241,14 @@ boolean iskanji2(int c)
}
/* multi-byte char length in s[pos] */
-int multistrlen(string s, int len, int pos)
+int multistrlen(unsigned char *s, int len, int pos)
{
s += pos; len -= pos;
+ if (is_internalUPTEX()) {
+ int ret = UTF8Slength(s, len);
+ if (ret < 0) return 1;
+ return ret;
+ }
if (len < 2) return 1;
if (is_internalSJIS()) {
if (isSJISkanji1(s[0]) && isSJISkanji2(s[1])) return 2;
@@ -200,10 +258,27 @@ int multistrlen(string s, int len, int pos)
return 1;
}
-/* buffer (EUC/SJIS/UTF-8) to internal (EUC/SJIS) code conversion */
-long fromBUFF(string s, int len, int pos)
+/* with not so strict range check */
+int multibytelen (int first_byte)
+{
+ if (is_internalUPTEX()) {
+ return UTF8length(first_byte);
+ } else if (is_internalSJIS()) {
+ if (isSJISkanji1(first_byte)) return 2;
+ } else { /* EUC */
+ if (isEUCkanji1(first_byte)) return 2;
+ }
+ return 1;
+}
+
+/* buffer (EUC/SJIS/UTF-8) to internal (EUC/SJIS/UPTEX) code conversion */
+long fromBUFF(unsigned char *s, int len, int pos)
{
s += pos; len -= pos;
+ if (is_internalUPTEX()) {
+ if (UTF8Slength(s, len) < 0) return s[0];
+ return UCStoUPTEX(UTF8StoUCS(s));
+ }
if (len < 2) return s[0];
if (is_internalSJIS()) {
if (isSJISkanji1(s[0]) && isSJISkanji2(s[1])) return HILO(s[0], s[1]);
@@ -213,85 +288,95 @@ long fromBUFF(string s, int len, int pos)
return s[0];
}
-/* internal (EUC/SJIS) to buffer (EUC/SJIS) code conversion */
+/* internal (EUC/SJIS/UPTEX) to buffer (EUC/SJIS/UTF-8) code conversion */
long toBUFF(long kcode)
{
+ if (is_internalUPTEX()) kcode = UCStoUTF8(UPTEXtoUCS(kcode));
return kcode;
}
-/* JIS to internal (EUC/SJIS) code conversion */
+/* JIS to internal (EUC/SJIS/UPTEX) code conversion */
long fromJIS(long kcode)
{
+ if (is_internalUPTEX()) return UCStoUPTEX(JIStoUCS2(kcode));
if (is_internalSJIS()) return JIStoSJIS(kcode);
/* EUC */ return JIStoEUC(kcode);
}
-/* internal (EUC/SJIS) to JIS code conversion */
+/* internal (EUC/SJIS/UPTEX) to JIS code conversion */
long toJIS(long kcode)
{
+ if (is_internalUPTEX()) return UCS2toJIS(UPTEXtoUCS(kcode));
if (is_internalSJIS()) return SJIStoJIS(kcode);
/* EUC */ return EUCtoJIS(kcode);
}
-/* EUC to internal (EUC/SJIS) code conversion */
+/* EUC to internal (EUC/SJIS/UPTEX) code conversion */
long fromEUC(long kcode)
{
- if (is_internalSJIS()) return fromJIS(EUCtoJIS(kcode));
- /* EUC */ return kcode;
+ if (!is_internalUPTEX() && !is_internalSJIS()) return kcode;
+ return fromJIS(EUCtoJIS(kcode));
}
-/* internal (EUC/SJIS) to EUC code conversion */
+/* internal (EUC/SJIS/UPTEX) to EUC code conversion */
static long toEUC(long kcode)
{
- if (is_internalSJIS()) return JIStoEUC(toJIS(kcode));
- /* EUC */ return kcode;
-
+ if (!is_internalUPTEX() && !is_internalSJIS()) return kcode;
+ return JIStoEUC(toJIS(kcode));
}
-/* SJIS to internal (EUC/SJIS) code conversion */
+/* SJIS to internal (EUC/SJIS/UPTEX) code conversion */
long fromSJIS(long kcode)
{
if (is_internalSJIS()) return kcode;
- /* EUC */ return fromJIS(SJIStoJIS(kcode));
+ return fromJIS(SJIStoJIS(kcode));
}
-/* internal (EUC/SJIS) to SJIS code conversion */
+/* internal (EUC/SJIS/UPTEX) to SJIS code conversion */
static long toSJIS(long kcode)
{
if (is_internalSJIS()) return kcode;
- /* EUC */ return JIStoSJIS(toJIS(kcode));
+ return JIStoSJIS(toJIS(kcode));
}
-/* KUTEN to internal (EUC/SJIS) code conversion */
+/* KUTEN to internal (EUC/SJIS/UPTEX) code conversion */
long fromKUTEN(long kcode)
{
return fromJIS(KUTENtoJIS(kcode));
}
-/* UCS to internal (EUC/SJIS) code conversion */
+/* UCS to internal (EUC/SJIS/UPTEX) code conversion */
long fromUCS(long kcode)
{
+ if (is_internalUPTEX()) return UCStoUPTEX(kcode);
kcode = UCS2toJIS(kcode);
if (kcode == 0) return 0;
return fromJIS(kcode);
}
-/* internal (EUC/SJIS) to UCS code conversion */
+/* internal (EUC/SJIS/UPTEX) to UCS code conversion */
long toUCS(long kcode)
{
+ if (is_internalUPTEX()) return UPTEXtoUCS(kcode);
return JIStoUCS2(toJIS(kcode));
}
-/* internal (EUC/SJIS) to 'enc' code conversion */
+/* internal (EUC/SJIS/UPTEX) to UTF-8 code conversion */
+static long toUTF8 (long kcode)
+{
+ return UCStoUTF8(toUCS(kcode));
+}
+
+/* internal (EUC/SJIS/UPTEX) to 'enc' code conversion */
static long toENC(long kcode, int enc)
{
switch (enc) {
- case ENC_UTF8: return UCStoUTF8(toUCS(kcode));
+ case ENC_UTF8: return toUTF8(kcode);
case ENC_JIS: return toJIS(kcode);
case ENC_EUC: return toEUC(kcode);
case ENC_SJIS: return toSJIS(kcode);
@@ -379,7 +464,7 @@ static int ungetc4(int c, FILE *fp)
}
-static string buffer;
+static unsigned char *buffer;
static long first, last;
static boolean combin_voiced_sound(boolean semi)
{
@@ -521,8 +606,8 @@ static int infile_enc[NOFILE]; /* ENC_UNKNOWN (=0): not determined
other: determined */
/* input line with encoding conversion */
-long input_line2(FILE *fp, string buff, long pos,
- const long buffsize, int *lastchar)
+long input_line2(FILE *fp, unsigned char *buff, long pos,
+ const long buffsize, int *lastchar)
{
long i;
static boolean injis = false;