summaryrefslogtreecommitdiff
path: root/Build/source/texk/ptexenc
diff options
context:
space:
mode:
authorPeter Breitenlohner <peb@mppmu.mpg.de>2012-09-18 17:23:59 +0000
committerPeter Breitenlohner <peb@mppmu.mpg.de>2012-09-18 17:23:59 +0000
commit070c6621f655b8434e1ed815441d68d8d0bff515 (patch)
treee5ab8943d4862ce9dd9aabbc0ff1e2d78cfc97a5 /Build/source/texk/ptexenc
parent86f3ba0eba41fad5fc4ffec0c58ba6d1cfe8cf61 (diff)
ptexenc: Define ptexenc_version_string as PTEXENCVERSION
Updates from W32TeX: Handle input files with Dos/Windows (CRLF) line endings Various sjisterminal related changes Update unicode variation[] table git-svn-id: svn://tug.org/texlive/trunk@27698 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build/source/texk/ptexenc')
-rw-r--r--Build/source/texk/ptexenc/ChangeLog16
-rw-r--r--Build/source/texk/ptexenc/ptexenc.c79
-rw-r--r--Build/source/texk/ptexenc/ptexenc/ptexenc.h2
-rw-r--r--Build/source/texk/ptexenc/unicode-jp.c20
4 files changed, 94 insertions, 23 deletions
diff --git a/Build/source/texk/ptexenc/ChangeLog b/Build/source/texk/ptexenc/ChangeLog
index e915539a5ae..9e209cb0bf1 100644
--- a/Build/source/texk/ptexenc/ChangeLog
+++ b/Build/source/texk/ptexenc/ChangeLog
@@ -1,3 +1,17 @@
+2012-09-04 Peter Breitenlohner <peb@mppmu.mpg.de>
+
+ * ptexenc.c: Define ptexenc_version_string as PTEXENCVERSION.
+
+2012-08-24 Peter Breitenlohner <peb@mppmu.mpg.de>
+
+ * ptexenc/ptexenc.h: Correct set_enc_string() return type.
+
+ Updates from W32TeX.
+ * ptexenc.c (input_line2): Handle input files with Dos/Windows
+ (CRLF) line endings.
+ Various sjisterminal related changes.
+ * unicode-jp.c: Update variation[] table.
+
2012-07-09 Peter Breitenlohner <peb@mppmu.mpg.de>
* version.ac: Update version number 1.3.0 => 1.3.1dev.
@@ -49,7 +63,7 @@
Use prototypes as in ptexenc/ from W32TeX.
* ptexenc.c: Handle default encoding with/without uptex.
- * configure.ac: Remove option '--with-ptexenc-enc' configure.
+ * configure.ac: Remove configure option '--with-ptexenc-enc'.
2011-08-18 Peter Breitenlohner <peb@mppmu.mpg.de>
diff --git a/Build/source/texk/ptexenc/ptexenc.c b/Build/source/texk/ptexenc/ptexenc.c
index 5bee9a9bdc8..ed178a77b53 100644
--- a/Build/source/texk/ptexenc/ptexenc.c
+++ b/Build/source/texk/ptexenc/ptexenc.c
@@ -23,7 +23,7 @@
#define ENC_UTF8 4
#define ENC_UPTEX 5
-static int default_kanji_enc = ENC_UTF8;
+static int default_kanji_enc;
static boolean UPTEX_enabled;
static boolean prior_file_enc = false;
@@ -36,7 +36,7 @@ static boolean prior_file_enc = false;
# define NOFILE OPEN_MAX
#endif
-const char *ptexenc_version_string = "ptexenc " PTEXENC_VERSION;
+const char *ptexenc_version_string = PTEXENCVERSION;
#if defined(WIN32)
int sjisterminal;
FILE *Poptr;
@@ -149,12 +149,17 @@ static int get_terminal_enc(void)
void enable_UPTEX (boolean enable)
{
UPTEX_enabled = enable;
- if (enable)
+ if (enable) {
default_kanji_enc = ENC_UPTEX;
- else {
+ internal_enc = ENC_UPTEX;
+ } else {
+#ifdef WIN32
+ default_kanji_enc = ENC_SJIS;
+ internal_enc = ENC_SJIS;
+#else
default_kanji_enc = ENC_UTF8;
- if (internal_enc == ENC_UPTEX)
- internal_enc = ENC_EUC;
+ internal_enc = ENC_EUC;
+#endif
}
}
@@ -408,12 +413,46 @@ static long toENC(long kcode, int enc)
}
}
-
-
#define KANJI_IN LONG(0, ESC, '$', 'B')
#define KANJI_OUT LONG(0, ESC, '(', 'B')
static int put_multibyte(long c, FILE *fp) {
+#ifdef WIN32
+ if (sjisterminal) {
+ const int fd = fileno(fp);
+
+ if ((fd == fileno(stdout) || fd == fileno(stderr)) && _isatty(fd)) {
+ HANDLE hStdout;
+ DWORD ret, wclen;
+ wchar_t buff[2];
+ char str[4];
+ int mblen;
+
+ if (fd == fileno(stdout))
+ hStdout = GetStdHandle(STD_OUTPUT_HANDLE);
+ else
+ hStdout = GetStdHandle(STD_ERROR_HANDLE);
+
+ mblen=0;
+ if (BYTE1(c) != 0) str[mblen++]=BYTE1(c);
+ if (BYTE2(c) != 0) str[mblen++]=BYTE2(c);
+ if (BYTE3(c) != 0) str[mblen++]=BYTE3(c);
+ /* always */ str[mblen++]=BYTE4(c);
+
+#define CP_932 932
+
+ if (MultiByteToWideChar(CP_932, 0, str, mblen, buff, 2) == 0)
+ return EOF;
+
+ wclen = mblen > 3 ? 2 : 1;
+ if (WriteConsoleW(hStdout, buff, wclen, &ret, NULL) == 0)
+ return EOF;
+
+ return BYTE4(c);
+ }
+ }
+#endif
+
if (BYTE1(c) != 0 && putc(BYTE1(c), fp) == EOF) return EOF;
if (BYTE2(c) != 0 && putc(BYTE2(c), fp) == EOF) return EOF;
if (BYTE3(c) != 0 && putc(BYTE3(c), fp) == EOF) return EOF;
@@ -443,9 +482,18 @@ int putc2(int c, FILE *fp)
const int fd = fileno(fp);
int ret = c, output_enc;
- if ((fp == stdout || fp == stderr) && !(prior_file_enc))
- output_enc = get_terminal_enc();
- else output_enc = get_file_enc();
+#ifdef WIN32
+ if ((fp == stdout || fp == stderr) && (_isatty(fd) || !prior_file_enc)) {
+ if (sjisterminal)
+ output_enc = ENC_SJIS;
+ else
+#else
+ if ((fp == stdout || fp == stderr) && !prior_file_enc) {
+#endif
+
+ output_enc = get_terminal_enc();
+ } else
+ output_enc = get_file_enc();
if (num[fd] > 0) { /* multi-byte char */
if (is_internalUPTEX() && iskanji1(c)) { /* error */
@@ -727,6 +775,15 @@ long input_line2(FILE *fp, unsigned char *buff, long pos,
buffer[last] = '\0';
if (i == EOF || i == '\n' || i == '\r') injis = false;
if (lastchar != NULL) *lastchar = i;
+
+ if (i == '\r' && !isatty(fd)) {
+ int ii;
+ while ((ii = getc4(fp)) == EOF && errno == EINTR)
+ ;
+ if (ii != '\n')
+ ungetc4(ii, fp);
+ }
+
return last;
}
diff --git a/Build/source/texk/ptexenc/ptexenc/ptexenc.h b/Build/source/texk/ptexenc/ptexenc/ptexenc.h
index 34e9092c6d1..a4cbeb327f9 100644
--- a/Build/source/texk/ptexenc/ptexenc/ptexenc.h
+++ b/Build/source/texk/ptexenc/ptexenc/ptexenc.h
@@ -36,7 +36,7 @@ extern PTENCDLL void set_prior_file_enc(void);
/* get/set Kanji encoding by string */
extern PTENCDLL const_string get_enc_string(void);
-extern PTENCDLL int set_enc_string(const_string file, const_string inter);
+extern PTENCDLL boolean set_enc_string(const_string file, const_string inter);
#define getencstring get_enc_string
#define setencstring set_enc_string
diff --git a/Build/source/texk/ptexenc/unicode-jp.c b/Build/source/texk/ptexenc/unicode-jp.c
index 856b2276c15..97d1fa0fb28 100644
--- a/Build/source/texk/ptexenc/unicode-jp.c
+++ b/Build/source/texk/ptexenc/unicode-jp.c
@@ -133,19 +133,19 @@ static int UCS2toJISnative(int ucs2)
*/
static unsigned short int variation[] = {
/* JIS X 0208, UCS-2(1), UCS-2(2), ..., 0(sentinel) */
- 0x2126 /* 1-6 */, 0x30FB, 0x2022, 0x2219, 0x22C5, 0,
- 0x2131 /* 1-17 */, 0xFFE3, 0x203E, 0,
- 0x213D /* 1-29 */, 0x2015, 0x2012, 0x2013, 0x2014, 0,
- 0x2141 /* 1-33 */, 0x301C, 0x223C, 0x223E, 0xFF5E, 0,
+ 0x2126 /* 1-6 */, 0x2022, 0x2219, 0x22C5, 0x30FB, 0,
+ 0x2131 /* 1-17 */, 0x203E, 0xFFE3, 0,
+ 0x213D /* 1-29 */, 0x2012, 0x2013, 0x2014, 0x2015, 0,
+ 0x2141 /* 1-33 */, 0x223C, 0x223E, 0x301C, 0xFF5E, 0,
0x2142 /* 1-34 */, 0x2016, 0x2225, 0,
- 0x2143 /* 1-35 */, 0xFF5C, 0x2223, 0,
+ 0x2143 /* 1-35 */, 0x2223, 0xFF5C, 0,
0x2144 /* 1-36 */, 0x2026, 0x22EF, 0,
0x215D /* 1-61 */, 0x2212, 0xFF0D, 0,
- 0x216F /* 1-79 */, 0xFFE5, 0x00A5, 0,
- 0x2171 /* 1-81 */, 0xFFE0, 0x00A2, 0,
- 0x2172 /* 1-82 */, 0xFFE1, 0x00A3, 0,
- 0x224C /* 2-44 */, 0xFFE2, 0x00AC, 0,
- 0x227E /* 2-94 */, 0x25EF, 0x20DD, 0,
+ 0x216f /* 1-79 */, 0x00A5, 0xFFE5, 0,
+ 0x2171 /* 1-81 */, 0x00A2, 0xFFE0, 0,
+ 0x2172 /* 1-82 */, 0x00A3, 0xFFE1, 0,
+ 0x224C /* 2-44 */, 0x00AC, 0xFFE2, 0,
+ 0x227E /* 2-94 */, 0x20DD, 0x25EF, 0,
0 /* end */
};
/*