From e8c5e48f98b3d80faa21f5bf0f1c60c220b3d9cf Mon Sep 17 00:00:00 2001 From: Takuji Tanaka Date: Sat, 9 Jun 2018 11:10:16 +0000 Subject: pTeX: Support UTF-8 file names on UTF-8 locale (Unix-like platform only) git-svn-id: svn://tug.org/texlive/trunk@47967 c570f23f-e606-0410-a88d-b1316a301751 --- Build/source/texk/ptexenc/ChangeLog | 8 ++ Build/source/texk/ptexenc/ptexenc.c | 134 ++++++++++++++++++++++++++++ Build/source/texk/ptexenc/ptexenc/ptexenc.h | 3 + 3 files changed, 145 insertions(+) (limited to 'Build/source/texk/ptexenc') diff --git a/Build/source/texk/ptexenc/ChangeLog b/Build/source/texk/ptexenc/ChangeLog index 26bb9d1fe52..cefcc2db516 100644 --- a/Build/source/texk/ptexenc/ChangeLog +++ b/Build/source/texk/ptexenc/ChangeLog @@ -1,3 +1,11 @@ +2018-06-09 TANAKA Takuji + + * ptexenc.c, ptexenc/ptexenc.h: Add new functions + ptenc_from_utf8_string_to_internal_enc(), + ptenc_from_internal_enc_string_to_utf8() and + ptenc_get_command_line_args() to support UTF-8 file names + on UTF-8 locale in pTeX (Unix-like platform only). + 2018-03-26 Akira Kakuto * ptexenc.c: Change default_kanji_enc from ENC_SJIS to ENC_UTF8 diff --git a/Build/source/texk/ptexenc/ptexenc.c b/Build/source/texk/ptexenc/ptexenc.c index 602b7f86698..aa5b9bbc867 100644 --- a/Build/source/texk/ptexenc/ptexenc.c +++ b/Build/source/texk/ptexenc/ptexenc.c @@ -935,4 +935,138 @@ int nkf_close(FILE *fp) { } return fclose(fp); } + + +unsigned char *ptenc_from_utf8_string_to_internal_enc(const unsigned char *is) +{ + int i; + long u = 0, j, len; + int i1 = EOF, i2 = EOF, i3 = EOF, i4 = EOF; + unsigned char *buf, *buf_bak; + long first_bak, last_bak; + + if (terminal_enc != ENC_UTF8 || is_internalUPTEX()) return NULL; + buf_bak = buffer; + first_bak = first; + last_bak = last; + + len = strlen(is)+1; + buffer = buf = xmalloc(len); + first = last = 0; + + for (i=0; i=len) buffer = xrealloc(buffer, len=last+64); + write_hex(i1); + if (i2 != '\0') write_hex(i2); + if (i3 != '\0') write_hex(i3); + if (i4 != '\0') write_hex(i4); + } else { + write_multibyte(j); + } + i2 = i3 = i4 = '\0'; + } + buffer[last] = '\0'; + end: + buffer = buf_bak; + first = first_bak; + last = last_bak; + return buf; +} + +unsigned char *ptenc_from_internal_enc_string_to_utf8(const unsigned char *is) +{ + int i; + long u = 0, len; + int i1 = EOF, i2 = EOF; + unsigned char *buf, *buf_bak; + long first_bak, last_bak; + + if (terminal_enc != ENC_UTF8 || is_internalUPTEX()) return NULL; + buf_bak = buffer; + first_bak = first; + last_bak = last; + + len = strlen(is)+1; + buffer = buf = xmalloc(len*1.5); + first = last = 0; + + for (i=0; i