summaryrefslogtreecommitdiff
path: root/Build
diff options
context:
space:
mode:
authorTakuji Tanaka <ttk@t-lab.opal.ne.jp>2022-06-12 08:18:23 +0000
committerTakuji Tanaka <ttk@t-lab.opal.ne.jp>2022-06-12 08:18:23 +0000
commitc6f5af13c21701cf913804b954c734f20b2748ce (patch)
tree0c86b4de09354f4ef0cdc1a5f28150328dbf8790 /Build
parentab299733b38a3196a337723507b86a22a19589f3 (diff)
(e)(u)pTeX, (u)pBibTeX: support guessing input file encodings
git-svn-id: svn://tug.org/texlive/trunk@63557 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Build')
-rw-r--r--Build/source/texk/kpathsea/ChangeLog8
-rw-r--r--Build/source/texk/kpathsea/texmf.cnf11
-rw-r--r--Build/source/texk/web2c/ChangeLog10
-rw-r--r--Build/source/texk/web2c/Makefile.in78
-rw-r--r--Build/source/texk/web2c/help.h2
-rw-r--r--Build/source/texk/web2c/lib/ChangeLog6
-rw-r--r--Build/source/texk/web2c/lib/texmfmp.c2
-rw-r--r--Build/source/texk/web2c/ptexdir/ChangeLog8
-rw-r--r--Build/source/texk/web2c/ptexdir/am/ptex.am8
-rw-r--r--Build/source/texk/web2c/ptexdir/kanji.c2
-rw-r--r--Build/source/texk/web2c/ptexdir/kanji.h3
-rw-r--r--Build/source/texk/web2c/ptexdir/pbibtex.ch18
-rwxr-xr-xBuild/source/texk/web2c/ptexdir/pbibtex.test37
-rw-r--r--Build/source/texk/web2c/tests/enc-amb0.bib13
-rw-r--r--Build/source/texk/web2c/tests/enc-amb1.bib5
-rw-r--r--Build/source/texk/web2c/tests/enc-amb2.bib13
-rw-r--r--Build/source/texk/web2c/tests/enc-asc.bib1
-rw-r--r--Build/source/texk/web2c/tests/enc-e.aux3
-rw-r--r--Build/source/texk/web2c/tests/enc-ep.bbl53
-rw-r--r--Build/source/texk/web2c/tests/enc-eu.bbl54
-rw-r--r--Build/source/texk/web2c/tests/enc-euc.bib5
-rw-r--r--Build/source/texk/web2c/tests/enc-jis.bib5
-rw-r--r--Build/source/texk/web2c/tests/enc-p.bbl64
-rw-r--r--Build/source/texk/web2c/tests/enc-s.aux3
-rw-r--r--Build/source/texk/web2c/tests/enc-sjis.bib5
-rw-r--r--Build/source/texk/web2c/tests/enc-sp.bbl43
-rw-r--r--Build/source/texk/web2c/tests/enc-su.bblbin0 -> 931 bytes
-rw-r--r--Build/source/texk/web2c/tests/enc-u.bbl66
-rw-r--r--Build/source/texk/web2c/tests/enc-utf8.bib5
-rw-r--r--Build/source/texk/web2c/tests/enc-utf8a.bib6
-rw-r--r--Build/source/texk/web2c/tests/enc-utf8b.bib7
-rw-r--r--Build/source/texk/web2c/tests/enc.aux3
-rw-r--r--Build/source/texk/web2c/tests/testfield.bst38
-rw-r--r--Build/source/texk/web2c/texmfmp-help.h8
-rw-r--r--Build/source/texk/web2c/uptexdir/ChangeLog8
-rw-r--r--Build/source/texk/web2c/uptexdir/am/uptex.am4
-rw-r--r--Build/source/texk/web2c/uptexdir/kanji.c2
-rw-r--r--Build/source/texk/web2c/uptexdir/kanji.h3
-rw-r--r--Build/source/texk/web2c/uptexdir/upbibtex.ch4
-rwxr-xr-xBuild/source/texk/web2c/uptexdir/upbibtex.test37
40 files changed, 582 insertions, 69 deletions
diff --git a/Build/source/texk/kpathsea/ChangeLog b/Build/source/texk/kpathsea/ChangeLog
index 1f8d08a1b2d..5c6dccf80fc 100644
--- a/Build/source/texk/kpathsea/ChangeLog
+++ b/Build/source/texk/kpathsea/ChangeLog
@@ -1,3 +1,11 @@
+2022-06-12 TANAKA Takuji <ttk@t-lab.opal.ne.jp>
+
+ * texmf.cnf (guess_input_kanji_encoding):
+ Support guessing input file encodings for unix-like platforms.
+ (It has already been supported on Windows.)
+ Now we set default on for (e)p(la)tex, pbibtex & mendex.
+ https://github.com/texjporg/tex-jp-build/issues/142
+
2022-05-06 TANAKA Takuji <ttk@t-lab.opal.ne.jp>
* texmf.cnf (max_print_line):
diff --git a/Build/source/texk/kpathsea/texmf.cnf b/Build/source/texk/kpathsea/texmf.cnf
index 8ecda0a3101..8cc17505443 100644
--- a/Build/source/texk/kpathsea/texmf.cnf
+++ b/Build/source/texk/kpathsea/texmf.cnf
@@ -888,8 +888,14 @@ max_rows.gftype = 8191
max_cols.gftype = 8191
% Guess input encoding (SJIS vs. Unicode, etc.) in pTeX and friends?
-% Default is 1, to guess. Used on Windows only.
-guess_input_kanji_encoding = 1
+% Default is 1 for (e)p(la)tex, pbibtex & mendex, to guess.
+guess_input_kanji_encoding = 0
+guess_input_kanji_encoding.ptex = 1
+guess_input_kanji_encoding.eptex = 1
+guess_input_kanji_encoding.platex = 1
+guess_input_kanji_encoding.platex-dev = 1
+guess_input_kanji_encoding.pbibtex = 1
+guess_input_kanji_encoding.mendex = 1
% command_line_encoding
%
@@ -902,6 +908,7 @@ guess_input_kanji_encoding = 1
% ignored. If file names in sources and DVI or XDV files are ASCII
% only, the value of command_line_encoding is irrelevant.
% If command_line_encoding = utf8 or command_line_encoding = utf-8,
+% characters on a command line in cmd.exe are assumed to be Unicode and
% file names in sources and DVI or XDV files are assumed to be UTF-8.
% Default is utf-8, from 2019-07-24, to assume UTF-8 file names.
% In order to switch off the function, define an environment variable:
diff --git a/Build/source/texk/web2c/ChangeLog b/Build/source/texk/web2c/ChangeLog
index 70602c8d3db..1acaa12f589 100644
--- a/Build/source/texk/web2c/ChangeLog
+++ b/Build/source/texk/web2c/ChangeLog
@@ -1,3 +1,13 @@
+2022-06-12 TANAKA Takuji <ttk@t-lab.opal.ne.jp>
+
+ * texmfmp-help.h ((e)(u)pTeX), help.h ((u)pBibTeX):
+ Support guessing input file encodings.
+ https://github.com/texjporg/tex-jp-build/issues/142
+ * tests/enc-{asc,jis,sjis,euc,utf8{,a,b},amb[012]}.bib,
+ tests/enc{,-[es]}.aux, tests/testfield.bst,
+ tests/enc-{,[es]}[pu].bbl:
+ Add tests for guess encodings & (u)pBibTeX.
+
2022-06-05 Andreas Scherer <https://ascherer.github.io>
* ctangleboot.cin: CWEB 4.8 release.
diff --git a/Build/source/texk/web2c/Makefile.in b/Build/source/texk/web2c/Makefile.in
index 022bdbdccf2..c12e20dfbbf 100644
--- a/Build/source/texk/web2c/Makefile.in
+++ b/Build/source/texk/web2c/Makefile.in
@@ -3277,18 +3277,23 @@ EXTRA_DIST = PROJECTS cftests cpascal.h help.h w2c/config.h \
ptexdir/Changes.txt ptexdir/INSTALL.txt ptexdir/README.txt \
$(ptex_tests) $(pweb_tests) ptexdir/tests/nissya_bib.aux \
ptexdir/tests/nissya.bst ptexdir/tests/sample.bib \
- tests/memdata1.bst tests/memdata2.bst tests/memdata3.bst \
- ptexdir/tests/goth10.tfm ptexdir/tests/sample.dvi \
- ptexdir/tests/samplea.typ ptexdir/tests/min10.pl \
- ptexdir/tests/min10.tfm ptexdir/tests/tmin10.pl \
- ptexdir/tests/tmin10.tfm ptexdir/tests/skipjfmp.pl \
- ptexdir/tests/skipjfmp.tfm ptexdir/ptrip/ptrip.diffs \
- ptexdir/ptrip/texmf.cnf $(eptex_web_srcs) $(eptex_ch_srcs) \
- eptexdir/eptex.defines eptexdir/ChangeLog eptexdir/Changes.txt \
- eptexdir/README.txt $(eptex_tests) \
- eptexdir/eptrip/eptrip.diffs eptexdir/eptrip/eptrip.log \
- eptexdir/eptrip/eptrip.tex eptexdir/eptrip/texmf.cnf \
- eptexdir/pdfprimitive.test \
+ tests/testfield.bst tests/enc-asc.bib tests/enc-jis.bib \
+ tests/enc-sjis.bib tests/enc-euc.bib tests/enc-utf8.bib \
+ tests/enc-utf8a.bib tests/enc-utf8b.bib tests/enc-amb0.bib \
+ tests/enc-amb1.bib tests/enc-amb2.bib tests/enc.aux \
+ tests/enc-e.aux tests/enc-s.aux tests/enc-p.bbl \
+ tests/enc-ep.bbl tests/enc-sp.bbl tests/memdata1.bst \
+ tests/memdata2.bst tests/memdata3.bst ptexdir/tests/goth10.tfm \
+ ptexdir/tests/sample.dvi ptexdir/tests/samplea.typ \
+ ptexdir/tests/min10.pl ptexdir/tests/min10.tfm \
+ ptexdir/tests/tmin10.pl ptexdir/tests/tmin10.tfm \
+ ptexdir/tests/skipjfmp.pl ptexdir/tests/skipjfmp.tfm \
+ ptexdir/ptrip/ptrip.diffs ptexdir/ptrip/texmf.cnf \
+ $(eptex_web_srcs) $(eptex_ch_srcs) eptexdir/eptex.defines \
+ eptexdir/ChangeLog eptexdir/Changes.txt eptexdir/README.txt \
+ $(eptex_tests) eptexdir/eptrip/eptrip.diffs \
+ eptexdir/eptrip/eptrip.log eptexdir/eptrip/eptrip.tex \
+ eptexdir/eptrip/texmf.cnf eptexdir/pdfprimitive.test \
eptexdir/tests/pdfprimitive-test.tex \
eptexdir/tests/pdfprimitive-eptex.log $(uptex_web_srcs) \
$(uptex_ch_srcs) uptexdir/uptex.defines ptexdir/pbibtex.ch \
@@ -3296,6 +3301,7 @@ EXTRA_DIST = PROJECTS cftests cpascal.h help.h w2c/config.h \
ptexdir/ppltotf.ch uptexdir/uppltotf.ch ptexdir/ptftopl.ch \
uptexdir/uptftopl.ch uptexdir/COPYRIGHT uptexdir/COPYRIGHT.jis \
uptexdir/ChangeLog $(uptex_tests) $(upweb_tests) \
+ tests/enc-u.bbl tests/enc-eu.bbl tests/enc-su.bbl \
uptexdir/tests/umin10.pl uptexdir/tests/umin10.tfm \
uptexdir/tests/utmin10.pl uptexdir/tests/utmin10.tfm \
uptexdir/tests/testnewu.pl uptexdir/tests/testnewu.tfm \
@@ -3618,30 +3624,30 @@ DISTCLEANFILES = CXXLD.sh tangle.c tangle.h tangle.p tangle-web2c \
$(pweb_programs:=.h) $(pweb_programs:=.p) \
$(pweb_programs:=-web2c) $(pweb_programs:=.web) \
ptests/nissya_bib.* ptests/xexampl.aux ptests/xexampl.bbl \
- ptests/xexampl.blg ptests/memtest.bib ptests/memtest?.* \
- ptests/xstory.dvityp ptests/xpagenum.typ ptests/xcmr10.tfm \
- ptests/xcmr10.pl ptests/xsample.typ ptests/x*min10.* \
- ptests/xskipjfmp.* ptrip.diffs $(nodist_eptex_SOURCES) \
- eptex.web eptex.ch eptex-web2c eptex.p eptex.pool eptex-tangle \
- eptrip.diffs pdfprimitive-eptex.* $(nodist_uptex_SOURCES) \
- uptex.web uptex.ch uptex-web2c uptex.p uptex.pool uptex-tangle \
- $(upweb_programs:=.c) $(upweb_programs:=.h) \
- $(upweb_programs:=.p) $(upweb_programs:=-web2c) \
- $(upweb_programs:=.web) uptests/xexampl.aux \
- uptests/xexampl.bbl uptests/xexampl.blg uptests/xstory.dvityp \
- uptests/xpagenum.typ uptests/xcmr10.tfm uptests/xcmr10.pl \
- uptests/x*min10.* uptests/xtestnewu.* uptests/xuparse.* \
- uptests/yuparse.* uptests/ygkhuge*.* uptrip.diffs \
- $(nodist_euptex_SOURCES) euptex.web euptex.ch euptex-web2c \
- euptex.p euptex.pool euptex-tangle euptrip.diffs \
- pdfprimitive-euptex.* $(nodist_hitex_SOURCES) \
- $(nodist_hishrink_SOURCES) $(nodist_histretch_SOURCES) \
- hiformat-tangle hitex-tangle hello.log rule.log \
- $(nodist_pdftex_SOURCES) pdftex-final.ch pdftex-web2c pdftex.p \
- pdftex.pool pdftex-tangle pwprob.log pwprob.tex pdfimage.fmt \
- pdfimage.log pdfimage.pdf expanded.log cnfline.log \
- partoken-ok.log partoken-xfail.log postV3.afm postV7.afm \
- test-13.pdf test-13.xref test-15.pdf test-15.xref \
+ ptests/xexampl.blg ptests/xenc*.* ptests/memtest.bib \
+ ptests/memtest?.* ptests/xstory.dvityp ptests/xpagenum.typ \
+ ptests/xcmr10.tfm ptests/xcmr10.pl ptests/xsample.typ \
+ ptests/x*min10.* ptests/xskipjfmp.* ptrip.diffs \
+ $(nodist_eptex_SOURCES) eptex.web eptex.ch eptex-web2c eptex.p \
+ eptex.pool eptex-tangle eptrip.diffs pdfprimitive-eptex.* \
+ $(nodist_uptex_SOURCES) uptex.web uptex.ch uptex-web2c uptex.p \
+ uptex.pool uptex-tangle $(upweb_programs:=.c) \
+ $(upweb_programs:=.h) $(upweb_programs:=.p) \
+ $(upweb_programs:=-web2c) $(upweb_programs:=.web) \
+ uptests/xexampl.aux uptests/xexampl.bbl uptests/xexampl.blg \
+ uptests/xenc*.* uptests/xstory.dvityp uptests/xpagenum.typ \
+ uptests/xcmr10.tfm uptests/xcmr10.pl uptests/x*min10.* \
+ uptests/xtestnewu.* uptests/xuparse.* uptests/yuparse.* \
+ uptests/ygkhuge*.* uptrip.diffs $(nodist_euptex_SOURCES) \
+ euptex.web euptex.ch euptex-web2c euptex.p euptex.pool \
+ euptex-tangle euptrip.diffs pdfprimitive-euptex.* \
+ $(nodist_hitex_SOURCES) $(nodist_hishrink_SOURCES) \
+ $(nodist_histretch_SOURCES) hiformat-tangle hitex-tangle \
+ hello.log rule.log $(nodist_pdftex_SOURCES) pdftex-final.ch \
+ pdftex-web2c pdftex.p pdftex.pool pdftex-tangle pwprob.log \
+ pwprob.tex pdfimage.fmt pdfimage.log pdfimage.pdf expanded.log \
+ cnfline.log partoken-ok.log partoken-xfail.log postV3.afm \
+ postV7.afm test-13.pdf test-13.xref test-15.pdf test-15.xref \
$(nodist_libluatex_sources) luaimage.* luajitimage.* \
$(nodist_xetex_SOURCES) xetex.web xetex-final.ch xetex-web2c \
xetex.p xetex.pool xetex-tangle bug73.fmt bug73.log bug73.out \
diff --git a/Build/source/texk/web2c/help.h b/Build/source/texk/web2c/help.h
index ce384d77939..668d3f9f98c 100644
--- a/Build/source/texk/web2c/help.h
+++ b/Build/source/texk/web2c/help.h
@@ -373,6 +373,7 @@ const_string PBIBTEXHELP[] = {
" Write bibliography for entries in AUXFILE to AUXFILE.bbl,",
" along with a log file AUXFILE.blg."
"",
+ "[-no]-guess-input-enc disable/enable to guess input file encoding",
"-kanji=STRING set Japanese encoding (STRING=euc|jis|sjis|utf8)",
"-min-crossrefs=NUMBER include item after NUMBER cross-refs; default 2",
"-terse do not print progress reports",
@@ -533,6 +534,7 @@ const_string UPBIBTEXHELP[] = {
" Write bibliography for entries in AUXFILE to AUXFILE.bbl,",
" along with a log file AUXFILE.blg."
"",
+ "[-no]-guess-input-enc disable/enable to guess input file encoding",
"-kanji=STRING set Japanese encoding (STRING=euc|jis|sjis|utf8|uptex)",
"-kanji-internal=STRING set Japanese internal encoding (STRING=euc|uptex)",
"-min-crossrefs=NUMBER include item after NUMBER cross-refs; default 2",
diff --git a/Build/source/texk/web2c/lib/ChangeLog b/Build/source/texk/web2c/lib/ChangeLog
index 8fb448ca7c2..127c93436da 100644
--- a/Build/source/texk/web2c/lib/ChangeLog
+++ b/Build/source/texk/web2c/lib/ChangeLog
@@ -1,3 +1,9 @@
+2022-06-12 TANAKA Takuji <ttk@t-lab.opal.ne.jp>
+
+ * texmfmp.c:
+ Support guessing input file encodings for pTeX family.
+ https://github.com/texjporg/tex-jp-build/issues/142
+
2022-04-25 Karl Berry <karl@freefriends.org>
* texmfmp.c (find_input_file): doc fix.
diff --git a/Build/source/texk/web2c/lib/texmfmp.c b/Build/source/texk/web2c/lib/texmfmp.c
index 52f3028aeb2..d75ebcd7e15 100644
--- a/Build/source/texk/web2c/lib/texmfmp.c
+++ b/Build/source/texk/web2c/lib/texmfmp.c
@@ -1836,10 +1836,8 @@ static struct option long_options[]
{ "no-mktex", 1, 0, 0 },
#endif /* TeX or MF */
#if IS_pTeX
-#ifdef WIN32
{ "guess-input-enc", 0, &infile_enc_auto, 1 },
{ "no-guess-input-enc", 0, &infile_enc_auto, 0 },
-#endif
{ "kanji", 1, 0, 0 },
{ "kanji-internal", 1, 0, 0 },
#endif /* IS_pTeX */
diff --git a/Build/source/texk/web2c/ptexdir/ChangeLog b/Build/source/texk/web2c/ptexdir/ChangeLog
index 8d32404f757..0d94e1eb225 100644
--- a/Build/source/texk/web2c/ptexdir/ChangeLog
+++ b/Build/source/texk/web2c/ptexdir/ChangeLog
@@ -1,3 +1,11 @@
+2022-06-12 TANAKA Takuji <ttk@t-lab.opal.ne.jp>
+
+ * kanji.[ch], pbibtex.ch:
+ Support guessing input file encodings.
+ https://github.com/texjporg/tex-jp-build/issues/142
+ * tests/pbibtex.test, am/ptex.am:
+ Add tests for guess encodings & pBibTeX.
+
2022-05-15 TANAKA Takuji <ttk@t-lab.opal.ne.jp>
* pbibtex.ch, ptex.defines:
diff --git a/Build/source/texk/web2c/ptexdir/am/ptex.am b/Build/source/texk/web2c/ptexdir/am/ptex.am
index 4ab8c3bb486..a96e3dfa971 100644
--- a/Build/source/texk/web2c/ptexdir/am/ptex.am
+++ b/Build/source/texk/web2c/ptexdir/am/ptex.am
@@ -211,7 +211,13 @@ endif PWEB
EXTRA_DIST += ptexdir/tests/nissya_bib.aux ptexdir/tests/nissya.bst ptexdir/tests/sample.bib
DISTCLEANFILES += ptests/nissya_bib.*
## ptexdir/pbibtex.test
-DISTCLEANFILES += ptests/xexampl.aux ptests/xexampl.bbl ptests/xexampl.blg
+EXTRA_DIST += tests/testfield.bst tests/enc-asc.bib tests/enc-jis.bib tests/enc-sjis.bib \
+ tests/enc-euc.bib tests/enc-utf8.bib tests/enc-utf8a.bib tests/enc-utf8b.bib \
+ tests/enc-amb0.bib tests/enc-amb1.bib tests/enc-amb2.bib \
+ tests/enc.aux tests/enc-e.aux tests/enc-s.aux \
+ tests/enc-p.bbl tests/enc-ep.bbl tests/enc-sp.bbl
+DISTCLEANFILES += ptests/xexampl.aux ptests/xexampl.bbl ptests/xexampl.blg \
+ ptests/xenc*.*
## ptexdir/pbibtex-mem.test
EXTRA_DIST += tests/memdata1.bst tests/memdata2.bst tests/memdata3.bst
DISTCLEANFILES += ptests/memtest.bib ptests/memtest?.*
diff --git a/Build/source/texk/web2c/ptexdir/kanji.c b/Build/source/texk/web2c/ptexdir/kanji.c
index a3f56607612..0926f7b37ca 100644
--- a/Build/source/texk/web2c/ptexdir/kanji.c
+++ b/Build/source/texk/web2c/ptexdir/kanji.c
@@ -96,12 +96,10 @@ void init_default_kanji (const_string file_str, const_string internal_str)
fprintf (stderr, "Ignoring bad kanji encoding \"%s\".\n", p);
}
-#ifdef WIN32
p = kpse_var_value ("guess_input_kanji_encoding");
if (p) {
if (*p == '1' || *p == 'y' || *p == 't')
infile_enc_auto = 1;
free(p);
}
-#endif
}
diff --git a/Build/source/texk/web2c/ptexdir/kanji.h b/Build/source/texk/web2c/ptexdir/kanji.h
index e0edeb2ed70..91038154fd8 100644
--- a/Build/source/texk/web2c/ptexdir/kanji.h
+++ b/Build/source/texk/web2c/ptexdir/kanji.h
@@ -53,6 +53,9 @@ extern void init_default_kanji (const_string file_str, const_string internal_str
#endif
/* for pDVItype */
#define setpriorfileenc() set_prior_file_enc()
+/* for pBibTeX */
+#define enableguessfileenc() set_guess_file_enc(1)
+#define disableguessfileenc() set_guess_file_enc(0)
#ifndef PRESERVE_PUTC
#undef putc
diff --git a/Build/source/texk/web2c/ptexdir/pbibtex.ch b/Build/source/texk/web2c/ptexdir/pbibtex.ch
index 8b5f2077698..d1aa891a90a 100644
--- a/Build/source/texk/web2c/ptexdir/pbibtex.ch
+++ b/Build/source/texk/web2c/ptexdir/pbibtex.ch
@@ -625,7 +625,7 @@ while (sp_ptr < sp_end) do {shift the substring}
@x
const n_options = 4; {Pascal won't count array lengths for us.}
@y
-const n_options = 6; {Pascal won't count array lengths for us.}
+const n_options = 8; {Pascal won't count array lengths for us.}
@z
@x
@@ -641,6 +641,12 @@ const n_options = 6; {Pascal won't count array lengths for us.}
if (not set_enc_string(optarg, nil)) then
write_ln('Bad kanji encoding "', stringcast(optarg), '".');
+ end else if argument_is ('guess-input-enc') then begin
+ enable_guess_file_enc;
+
+ end else if argument_is ('no-guess-input-enc') then begin
+ disable_guess_file_enc;
+
end; {Else it was a flag; |getopt| has already done the assignment.}
@z
@@ -666,6 +672,16 @@ long_options[current_option].has_arg := 1;
long_options[current_option].flag := 0;
long_options[current_option].val := 0;
incr(current_option);
+long_options[current_option].name := 'guess-input-enc';
+long_options[current_option].has_arg := 0;
+long_options[current_option].flag := 0;
+long_options[current_option].val := 0;
+incr(current_option);
+long_options[current_option].name := 'no-guess-input-enc';
+long_options[current_option].has_arg := 0;
+long_options[current_option].flag := 0;
+long_options[current_option].val := 0;
+incr(current_option);
@z
@x
diff --git a/Build/source/texk/web2c/ptexdir/pbibtex.test b/Build/source/texk/web2c/ptexdir/pbibtex.test
index eaeff03454c..f7cb02845bb 100755
--- a/Build/source/texk/web2c/ptexdir/pbibtex.test
+++ b/Build/source/texk/web2c/ptexdir/pbibtex.test
@@ -5,13 +5,38 @@
# You may freely use, modify and/or distribute this file.
test -d ptests || mkdir -p ptests
-rm -f ptests/xexampl.*
+rm -f ptests/xexampl.* ptests/xenc*.*
+
+rc=0
+
+TEXMFCNF=$srcdir/../kpathsea
+BSTINPUTS=$srcdir/tests
+BIBINPUTS=$srcdir/tests
+export TEXMFCNF BSTINPUTS BIBINPUTS
cp $srcdir/tests/exampl.aux ptests/xexampl.aux
-TEXMFCNF=$srcdir/../kpathsea \
- BSTINPUTS=$srcdir/tests \
- BIBINPUTS=$srcdir/tests \
- ./pbibtex ptests/xexampl || exit 1
-diff $srcdir/tests/exampl.bbl ptests/xexampl.bbl || exit 2
+./pbibtex ptests/xexampl || rc=1
+diff $srcdir/tests/exampl.bbl ptests/xexampl.bbl || rc=2
+
+
+cp $srcdir/tests/enc.aux ptests/xenc.aux
+
+guess_input_kanji_encoding=1 ./pbibtex ptests/xenc || rc=3
+diff $srcdir/tests/enc-p.bbl ptests/xenc.bbl || rc=4
+
+
+cp $srcdir/tests/enc-e.aux ptests/xenc-e.aux
+
+guess_input_kanji_encoding=1 ./pbibtex -kanji=euc ptests/xenc-e || rc=5
+diff $srcdir/tests/enc-ep.bbl ptests/xenc-e.bbl || rc=6
+
+
+cp $srcdir/tests/enc-s.aux ptests/xenc-s.aux
+
+./pbibtex -guess-input-enc -kanji=sjis ptests/xenc-s || rc=7
+diff $srcdir/tests/enc-sp.bbl ptests/xenc-s.bbl || rc=8
+
+
+exit $rc
diff --git a/Build/source/texk/web2c/tests/enc-amb0.bib b/Build/source/texk/web2c/tests/enc-amb0.bib
new file mode 100644
index 00000000000..571d35b0ed3
--- /dev/null
+++ b/Build/source/texk/web2c/tests/enc-amb0.bib
@@ -0,0 +1,13 @@
+% ambiguous: UTF-8 or EUC-JP
+@Type{ambiguos-a001, field = {C2Ax: ¢£¥§¨¬}, }
+@Type{ambiguos-a002, field = {C2Bx: °±¶÷}, }
+@Type{ambiguos-a005, field = {CEAx: ΡΣΤΥΦΧΨΩ}, }
+@Type{ambiguos-a006, field = {CEBx: αβγδεζηθικλμνξο}, }
+@Type{ambiguos-a007, field = {D0Ax: СТУФХЦЧШЩЪЫЬЭЮЯ}, }
+@Type{ambiguos-a008, field = {D0Bx: абвгдежзийклмноп}, }
+@Type{ambiguos-a009, field = {佳人 大声 亡失 対価 幼女 帰任 信仰 伴侶 山岳 年俸 平常 延伸 鷲鷹}, }
+@Type{ambiguos-a011, field = {F0A3B3BE: 𣳾}, }
+@Type{ambiguos-a012, field = {F0A5B6A1: 𥶡}, }
+@Type{ambiguos-a013, field = {F0A1B6B7: 𡶷}, }
+@Type{ambiguos-a020, field = {ξΩ ΥΦ ®ã ŷЧ Сб άå º°}, }
+
diff --git a/Build/source/texk/web2c/tests/enc-amb1.bib b/Build/source/texk/web2c/tests/enc-amb1.bib
new file mode 100644
index 00000000000..07f09b456f3
--- /dev/null
+++ b/Build/source/texk/web2c/tests/enc-amb1.bib
@@ -0,0 +1,5 @@
+% ambiguous: UTF-8 or Shift_JIS
+@Type{ambiguos-a050, field = {係q体y}, }
+@Type{ambiguos-a051, field = {語①誚②}, }
+@Type{ambiguos-a052, field = {思想 打球 明文 垂直 怜悧}, }
+
diff --git a/Build/source/texk/web2c/tests/enc-amb2.bib b/Build/source/texk/web2c/tests/enc-amb2.bib
new file mode 100644
index 00000000000..b6b8e643fe0
--- /dev/null
+++ b/Build/source/texk/web2c/tests/enc-amb2.bib
@@ -0,0 +1,13 @@
+% ambiguous: EUC-JP or Shift_JIS
+@Type{ambiguos-a100, field = {E0Ax: }, }
+@Type{ambiguos-a101, field = {E2Ax: }, }
+@Type{ambiguos-a102, field = {E4Ax: }, }
+@Type{ambiguos-a103, field = {E6Ax: }, }
+@Type{ambiguos-a104, field = {E8Ax: }, }
+@Type{ambiguos-a105, field = {EAAx: }, }
+@Type{ambiguos-a106, field = {coffee: }, }
+@Type{ambiguos-a107, field = {amber: }, }
+@Type{ambiguos-a108, field = {dotage: }, }
+@Type{ambiguos-a109, field = {konjak: }, }
+@Type{ambiguos-a110, field = {rampant: }, }
+
diff --git a/Build/source/texk/web2c/tests/enc-asc.bib b/Build/source/texk/web2c/tests/enc-asc.bib
new file mode 100644
index 00000000000..1cc32d2a78f
--- /dev/null
+++ b/Build/source/texk/web2c/tests/enc-asc.bib
@@ -0,0 +1 @@
+@Type{ascii-a001, field = {ABC xyz}, }
diff --git a/Build/source/texk/web2c/tests/enc-e.aux b/Build/source/texk/web2c/tests/enc-e.aux
new file mode 100644
index 00000000000..1c79745a17d
--- /dev/null
+++ b/Build/source/texk/web2c/tests/enc-e.aux
@@ -0,0 +1,3 @@
+\citation{*}
+\bibstyle{testfield}
+\bibdata{enc-asc,enc-jis,enc-sjis,enc-euc,enc-utf8,enc-utf8b,enc-amb0,enc-amb2}
diff --git a/Build/source/texk/web2c/tests/enc-ep.bbl b/Build/source/texk/web2c/tests/enc-ep.bbl
new file mode 100644
index 00000000000..f297f089e2b
--- /dev/null
+++ b/Build/source/texk/web2c/tests/enc-ep.bbl
@@ -0,0 +1,53 @@
+\section*{Test result}
+\begin{itemize}
+\item ABC xyz
+\item ABC xyz
+\item ABC xyz
+\item ABC xyz
+\item ABC xyz
+\item ABC xyz
+\item C2Ax:
+\item C2Ax: ¢£¥§¨¬
+\item C2Bx: °±¶÷
+\item CEAx: ΡΣΤΥΦΧΨΩ
+\item CEBx: ¦æĦŦƦǦȦɦʦ˦̦ͦΦ
+\item CEBx: αβγδεζηθικλμνξο
+\item D0Ax: СТУФХЦЧШЩЪЫЬЭЮЯ
+\item D0Bx: ѧҧӧԧէ֧ا٧ڧۧܧݧާߧ
+\item D0Bx: абвгдежзийклмноп
+\item E0Ax:
+\item E2Ax:
+\item E4Ax:
+\item E6Ax:
+\item E8Ax:
+\item EAAx:
+\item F0A1B6B7: 𡶷
+\item F0A3B3BE: 𣳾
+\item F0A5B6A1: 𥶡
+\item amber:
+\item coffee:
+\item dotage:
+\item konjak:
+\item rampant:
+\item
+\item
+\item
+\item
+\item ֦צ
+\item ֦צ
+\item ֦צ
+\item ֦צ
+\item
+\item
+\item
+\item
+\item 󻰻͸
+\item 󻰻͸
+\item 󻰻͸
+\item 󻰻͸
+\item ¿ ˴ в Ľ Ǥ ȼη ǯ ʿ 俭
+\item ξΩ ΥΦ ®ã ŷЧ Сб άå º°
+\item
+ 佳人 大声 亡失 対価 幼女 帰任 信仰 伴侶 山岳 年俸 平常 延伸 鷲鷹
+\end{itemize}
+\endinput
diff --git a/Build/source/texk/web2c/tests/enc-eu.bbl b/Build/source/texk/web2c/tests/enc-eu.bbl
new file mode 100644
index 00000000000..68a89dd8ff9
--- /dev/null
+++ b/Build/source/texk/web2c/tests/enc-eu.bbl
@@ -0,0 +1,54 @@
+\section*{Test result}
+\begin{itemize}
+\item ABC xyz
+\item ABC xyz
+\item ABC xyz
+\item ABC xyz
+\item ABC xyz
+\item ABC xyz
+\item C2Ax:
+\item C2Ax: ¢£¥§¨¬
+\item C2Bx: °±¶÷
+\item CEAx: ΡΣΤΥΦΧΨΩ
+\item CEBx: ¦æĦŦƦǦȦɦʦ˦̦ͦΦ
+\item CEBx: αβγδεζηθικλμνξο
+\item D0Ax: СТУФХЦЧШЩЪЫЬЭЮЯ
+\item D0Bx: ѧҧӧԧէ֧ا٧ڧۧܧݧާߧ
+\item D0Bx: абвгдежзийклмноп
+\item E0Ax:
+\item E2Ax:
+\item E4Ax:
+\item E6Ax:
+\item E8Ax:
+\item EAAx:
+\item F0A1B6B7: 𡶷
+\item F0A3B3BE: 𣳾
+\item F0A5B6A1: 𥶡
+\item amber:
+\item coffee:
+\item dotage:
+\item konjak:
+\item rampant:
+\item ֦צ
+\item ֦צ
+\item ֦צ
+\item ֦צ
+\item
+\item
+\item
+\item
+\item
+\item
+\item
+\item
+\item 󻰻͸
+\item 󻰻͸
+\item 󻰻͸
+\item 󻰻͸
+\item ξΩ ΥΦ ®ã ŷЧ Сб άå º°
+\item
+ ¿ ˴ в Ľ Ǥ ȼη ǯ ʿ 俭
+\item
+ 佳人 大声 亡失 対価 幼女 帰任 信仰 伴侶 山岳 年俸 平常 延伸 鷲鷹
+\end{itemize}
+\endinput
diff --git a/Build/source/texk/web2c/tests/enc-euc.bib b/Build/source/texk/web2c/tests/enc-euc.bib
new file mode 100644
index 00000000000..e443b6f1c36
--- /dev/null
+++ b/Build/source/texk/web2c/tests/enc-euc.bib
@@ -0,0 +1,5 @@
+@Type{ascii-e001, field = {ABC xyz}, }
+@Type{greek-e001, field = { ֦צ}, }
+@Type{cyrillic-e001, field = { }, }
+@Type{kana-e001, field = {}, }
+@Type{hanzi-e001, field = {󻰻͸}, }
diff --git a/Build/source/texk/web2c/tests/enc-jis.bib b/Build/source/texk/web2c/tests/enc-jis.bib
new file mode 100644
index 00000000000..655bc894875
--- /dev/null
+++ b/Build/source/texk/web2c/tests/enc-jis.bib
@@ -0,0 +1,5 @@
+@Type{ascii-j001, field = {ABC xyz}, }
+@Type{greek-j001, field = {$B&!&"&#(B $B&V&W&X(B}, }
+@Type{cyrillic-j001, field = {$B'!'"'#(B $B'o'p'q(B}, }
+@Type{kana-j001, field = {$B$"$$$&$($*(B}, }
+@Type{hanzi-j001, field = {$B0lFs;0;M8^(B}, }
diff --git a/Build/source/texk/web2c/tests/enc-p.bbl b/Build/source/texk/web2c/tests/enc-p.bbl
new file mode 100644
index 00000000000..d8cec92c192
--- /dev/null
+++ b/Build/source/texk/web2c/tests/enc-p.bbl
@@ -0,0 +1,64 @@
+\section*{Test result}
+\begin{itemize}
+\item ABC xyz
+\item ABC xyz
+\item ABC xyz
+\item ABC xyz
+\item ABC xyz
+\item ABC xyz
+\item ABC xyz
+\item C2Ax: ¢£¥§¨¬
+\item C2Ax: ¢£¥§¨¬
+\item C2Bx: °±¶÷
+\item CEAx: ΡΣΤΥΦΧΨΩ
+\item CEBx: αβγδεζηθικλμνξο
+\item CEBx: αβγδεζηθικλμνξο
+\item D0Ax: СТУФХЦЧШЩЪЫЬЭЮЯ
+\item D0Bx: абвгдежзийклмноп
+\item D0Bx: абвгдежзийклмноп
+\item E0Ax:
+ ^^e0^^a1^^e0^^a2^^e0^^a3^^e0^^a4^^e0^^a5^^e0^^a6^^e0^^a7^^e0^^a8^^e0^^a9^^e0^^aa^^e0^^ab^^e0^^ac^^e0^^ad^^e0^^ae^^e0^^af
+\item E2Ax:
+ ^^e2^^a1^^e2^^a2^^e2^^a3^^e2^^a4^^e2^^a5^^e2^^a6^^e2^^a7^^e2^^a8^^e2^^a9^^e2^^aa^^e2^^ab^^e2^^ac^^e2^^ad^^e2^^ae^^e2^^af
+\item E4Ax:
+ ^^e4^^a1^^e4^^a2^^e4^^a3^^e4^^a4^^e4^^a5^^e4^^a6^^e4^^a7^^e4^^a8^^e4^^a9^^e4^^aa^^e4^^ab^^e4^^ac^^e4^^ad^^e4^^ae^^e4^^af
+\item E6Ax:
+ ^^e6^^a1^^e6^^a2^^e6^^a3^^e6^^a4^^e6^^a5^^e6^^a6^^e6^^a7^^e6^^a8^^e6^^a9^^e6^^aa^^e6^^ab^^e6^^ac^^e6^^ad^^e6^^ae^^e6^^af
+\item E8Ax:
+ ^^e8^^a1^^e8^^a2^^e8^^a3^^e8^^a4^^e8^^a5^^e8^^a6^^e8^^a7^^e8^^a8^^e8^^a9^^e8^^aa^^e8^^ab^^e8^^ac^^e8^^ad^^e8^^ae^^e8^^af
+\item EAAx: ^^ea^^a1^^ea^^a2^^ea^^a3^^ea^^a4
+\item F0A1B6B7: ^^f0^^a1^^b6^^b7
+\item F0A3B3BE: ^^f0^^a3^^b3^^be
+\item F0A5B6A1: ^^f0^^a5^^b6^^a1
+\item amber: ^^e0^^e8^^e0^^e1 ^^e0^^e6^^e0^^df
+\item coffee: ^^e0^^dd^^e0^^ea ^^e0^^db^^e0^^e8
+\item dotage: ^^e6^^ce^^e2^^f1 ^^e3^^cc^^e1^^ef
+\item konjak: ^^e8^^e7^^e8^^ea ^^e4^^e5^^e4^^e8
+\item rampant: ^^e0^^cb^^e0^^d5 ^^e0^^c9^^e0^^d3
+\item あいうえお
+\item あいうえお
+\item あいうえお
+\item あいうえお
+\item ΑΒΓ χψω
+\item ΑΒΓ χψω
+\item ΑΒΓ χψω
+\item ΑΒΓ χψω
+\item ξΩ ΥΦ ^^c2^^ae^^c3^^a3 ^^c5^^b7Ч Сб ^^ce^^ac^^c3^^a5 ^^c2^^ba°
+\item АБВ эюя
+\item АБВ эюя
+\item АБВ эюя
+\item АБВ эюя
+\item 一二三四五
+\item 一二三四五
+\item 一二三四五
+\item 一二三四五
+\item 佳人 大声 亡失 対価 幼女 帰任 信仰 伴侶 山岳 年俸 平常 延伸 鷲鷹
+\item 佳人 大声 亡失 対価 幼女 帰任 信仰 伴侶 山岳 年俸 平常 延伸 鷲鷹
+\item 係q体y
+\item 係q体y
+\item 語^^e2^^91^^a0誚^^e2^^91^^a1
+\item 語^^e2^^91^^a0誚^^e2^^91^^a1
+\item 思想 打球 明文 垂直 怜悧
+\item 思想 打球 明文 垂直 怜悧
+\end{itemize}
+\endinput
diff --git a/Build/source/texk/web2c/tests/enc-s.aux b/Build/source/texk/web2c/tests/enc-s.aux
new file mode 100644
index 00000000000..d14291f20f2
--- /dev/null
+++ b/Build/source/texk/web2c/tests/enc-s.aux
@@ -0,0 +1,3 @@
+\citation{*}
+\bibstyle{testfield}
+\bibdata{enc-asc,enc-jis,enc-sjis,enc-euc,enc-utf8,enc-utf8a,enc-amb1,enc-amb2}
diff --git a/Build/source/texk/web2c/tests/enc-sjis.bib b/Build/source/texk/web2c/tests/enc-sjis.bib
new file mode 100644
index 00000000000..88893cb2fa8
--- /dev/null
+++ b/Build/source/texk/web2c/tests/enc-sjis.bib
@@ -0,0 +1,5 @@
+@Type{ascii-s001, field = {ABC xyz}, }
+@Type{greek-s001, field = { ԃՃ}, }
+@Type{cyrillic-s001, field = {@AB }, }
+@Type{kana-s001, field = {}, }
+@Type{hanzi-s001, field = {Ol}, }
diff --git a/Build/source/texk/web2c/tests/enc-sp.bbl b/Build/source/texk/web2c/tests/enc-sp.bbl
new file mode 100644
index 00000000000..1512fe324a2
--- /dev/null
+++ b/Build/source/texk/web2c/tests/enc-sp.bbl
@@ -0,0 +1,43 @@
+\section*{Test result}
+\begin{itemize}
+\item ABC xyz
+\item ABC xyz
+\item ABC xyz
+\item ABC xyz
+\item ABC xyz
+\item ABC xyz
+\item E0Ax:
+\item E2Ax:
+\item E4Ax:
+\item E6Ax:
+\item E8Ax:
+\item EAAx:
+\item amber:
+\item coffee:
+\item dotage:
+\item konjak:
+\item rampant:
+\item
+\item
+\item
+\item
+\item ԃՃ
+\item ԃՃ
+\item ԃՃ
+\item ԃՃ
+\item @AB
+\item @AB
+\item @AB
+\item @AB
+\item Ol
+\item Ol
+\item Ol
+\item Ol
+\item Wqy
+\item ^^e2^^91^^a0v^^e2^^91^^a1
+\item vz ŋ 圤
+\item 係q体y
+\item 思想 打球 明文 垂直 怜悧
+\item 語①誚②
+\end{itemize}
+\endinput
diff --git a/Build/source/texk/web2c/tests/enc-su.bbl b/Build/source/texk/web2c/tests/enc-su.bbl
new file mode 100644
index 00000000000..a3cfb67084d
--- /dev/null
+++ b/Build/source/texk/web2c/tests/enc-su.bbl
Binary files differ
diff --git a/Build/source/texk/web2c/tests/enc-u.bbl b/Build/source/texk/web2c/tests/enc-u.bbl
new file mode 100644
index 00000000000..278cecf597d
--- /dev/null
+++ b/Build/source/texk/web2c/tests/enc-u.bbl
@@ -0,0 +1,66 @@
+\section*{Test result}
+\begin{itemize}
+\item ABC xyz
+\item ABC xyz
+\item ABC xyz
+\item ABC xyz
+\item ABC xyz
+\item ABC xyz
+\item ABC xyz
+\item C2Ax: ¢£¥§¨¬
+\item C2Ax: ¢£¥§¨¬
+\item C2Bx: °±¶÷
+\item CEAx: ΡΣΤΥΦΧΨΩ
+\item CEBx: αβγδεζηθικλμνξο
+\item CEBx: αβγδεζηθικλμνξο
+\item D0Ax: СТУФХЦЧШЩЪЫЬЭЮЯ
+\item D0Bx: абвгдежзийклмноп
+\item D0Bx: абвгдежзийклмноп
+\item E0Ax:
+ ^^e0^^a1^^e0^^a2^^e0^^a3^^e0^^a4^^e0^^a5^^e0^^a6^^e0^^a7^^e0^^a8^^e0^^a9^^e0^^aa^^e0^^ab^^e0^^ac^^e0^^ad^^e0^^ae^^e0^^af
+\item E2Ax:
+ ^^e2^^a1^^e2^^a2^^e2^^a3^^e2^^a4^^e2^^a5^^e2^^a6^^e2^^a7^^e2^^a8^^e2^^a9^^e2^^aa^^e2^^ab^^e2^^ac^^e2^^ad^^e2^^ae^^e2^^af
+\item E4Ax:
+ ^^e4^^a1^^e4^^a2^^e4^^a3^^e4^^a4^^e4^^a5^^e4^^a6^^e4^^a7^^e4^^a8^^e4^^a9^^e4^^aa^^e4^^ab^^e4^^ac^^e4^^ad^^e4^^ae^^e4^^af
+\item E6Ax:
+ ^^e6^^a1^^e6^^a2^^e6^^a3^^e6^^a4^^e6^^a5^^e6^^a6^^e6^^a7^^e6^^a8^^e6^^a9^^e6^^aa^^e6^^ab^^e6^^ac^^e6^^ad^^e6^^ae^^e6^^af
+\item E8Ax:
+ ^^e8^^a1^^e8^^a2^^e8^^a3^^e8^^a4^^e8^^a5^^e8^^a6^^e8^^a7^^e8^^a8^^e8^^a9^^e8^^aa^^e8^^ab^^e8^^ac^^e8^^ad^^e8^^ae^^e8^^af
+\item EAAx: ^^ea^^a1^^ea^^a2^^ea^^a3^^ea^^a4
+\item F0A1B6B7: 𡶷
+\item F0A3B3BE: 𣳾
+\item F0A5B6A1: 𥶡
+\item amber: ^^e0^^e8^^e0^^e1 ^^e0^^e6^^e0^^df
+\item coffee: ^^e0^^dd^^e0^^ea ^^e0^^db^^e0^^e8
+\item dotage: ^^e6^^ce^^e2^^f1 ^^e3^^cc^^e1^^ef
+\item konjak: ^^e8^^e7^^e8^^ea ^^e4^^e5^^e4^^e8
+\item rampant: ^^e0^^cb^^e0^^d5 ^^e0^^c9^^e0^^d3
+\item ΑΒΓ χψω
+\item ΑΒΓ χψω
+\item ΑΒΓ χψω
+\item ΑΒΓ χψω
+\item ξΩ ΥΦ ®ã ŷЧ Сб άå º°
+\item АБВ эюя
+\item АБВ эюя
+\item АБВ эюя
+\item АБВ эюя
+\item あいうえお
+\item あいうえお
+\item あいうえお
+\item あいうえお
+\item 一二三四五
+\item 一二三四五
+\item 一二三四五
+\item 一二三四五
+\item
+ 佳人 大声 亡失 対価 幼女 帰任 信仰 伴侶 山岳 年俸 平常 延伸 鷲鷹
+\item
+ 佳人 大声 亡失 対価 幼女 帰任 信仰 伴侶 山岳 年俸 平常 延伸 鷲鷹
+\item 係q体y
+\item 係q体y
+\item 思想 打球 明文 垂直 怜悧
+\item 思想 打球 明文 垂直 怜悧
+\item 語①誚②
+\item 語①誚②
+\end{itemize}
+\endinput
diff --git a/Build/source/texk/web2c/tests/enc-utf8.bib b/Build/source/texk/web2c/tests/enc-utf8.bib
new file mode 100644
index 00000000000..483754464cb
--- /dev/null
+++ b/Build/source/texk/web2c/tests/enc-utf8.bib
@@ -0,0 +1,5 @@
+@Type{ascii-u001, field = {ABC xyz}, }
+@Type{greek-u001, field = {ΑΒΓ χψω}, }
+@Type{cyrillic-u001, field = {АБВ эюя}, }
+@Type{kana-u001, field = {あいうえお}, }
+@Type{hanzi-u001, field = {一二三四五}, }
diff --git a/Build/source/texk/web2c/tests/enc-utf8a.bib b/Build/source/texk/web2c/tests/enc-utf8a.bib
new file mode 100644
index 00000000000..f51fb0b1d8e
--- /dev/null
+++ b/Build/source/texk/web2c/tests/enc-utf8a.bib
@@ -0,0 +1,6 @@
+% UTF-8 with BOM
+@Type{ascii-v001, field = {ABC xyz}, }
+@Type{ambiguos-v050, field = {係q体y}, }
+@Type{ambiguos-v051, field = {語①誚②}, }
+@Type{ambiguos-v052, field = {思想 打球 明文 垂直 怜悧}, }
+
diff --git a/Build/source/texk/web2c/tests/enc-utf8b.bib b/Build/source/texk/web2c/tests/enc-utf8b.bib
new file mode 100644
index 00000000000..d4dfddb0019
--- /dev/null
+++ b/Build/source/texk/web2c/tests/enc-utf8b.bib
@@ -0,0 +1,7 @@
+% UTF-8 with BOM
+@Type{ascii-v002, field = {ABC xyz}, }
+@Type{ambiguos-v003, field = {C2Ax: ¢£¥§¨¬}, }
+@Type{ambiguos-v006, field = {CEBx: αβγδεζηθικλμνξο}, }
+@Type{ambiguos-v008, field = {D0Bx: абвгдежзийклмноп}, }
+@Type{ambiguos-v009, field = {佳人 大声 亡失 対価 幼女 帰任 信仰 伴侶 山岳 年俸 平常 延伸 鷲鷹}, }
+
diff --git a/Build/source/texk/web2c/tests/enc.aux b/Build/source/texk/web2c/tests/enc.aux
new file mode 100644
index 00000000000..faf95546b76
--- /dev/null
+++ b/Build/source/texk/web2c/tests/enc.aux
@@ -0,0 +1,3 @@
+\citation{*}
+\bibstyle{testfield}
+\bibdata{enc-asc,enc-jis,enc-sjis,enc-euc,enc-utf8,enc-utf8a,enc-utf8b,enc-amb0,enc-amb1,enc-amb2}
diff --git a/Build/source/texk/web2c/tests/testfield.bst b/Build/source/texk/web2c/tests/testfield.bst
new file mode 100644
index 00000000000..862a4c59764
--- /dev/null
+++ b/Build/source/texk/web2c/tests/testfield.bst
@@ -0,0 +1,38 @@
+% BibTeX test style file
+% Copyright 2022 TANAKA Takuji <ttk@t-lab.opal.ne.jp>
+% You may freely use, modify and/or distribute this file.
+
+ENTRY {field}{}{}
+
+FUNCTION {output_entry} {
+ "\item " field * write$
+ newline$
+}
+
+FUNCTION {type} {output_entry}
+
+READ
+
+FUNCTION {set_sort_key} {
+ field 'sort.key$ :=
+}
+
+ITERATE {set_sort_key}
+
+SORT
+
+FUNCTION {output_bgn} {
+ "\section*{Test result}" write$ newline$
+ "\begin{itemize}" write$ newline$
+}
+
+FUNCTION {output_end} {
+ "\end{itemize}" write$ newline$
+ "\endinput" write$ newline$
+}
+
+EXECUTE {output_bgn}
+
+ITERATE {call.type$}
+
+EXECUTE {output_end}
diff --git a/Build/source/texk/web2c/texmfmp-help.h b/Build/source/texk/web2c/texmfmp-help.h
index 1e720340c42..068cbe2da6b 100644
--- a/Build/source/texk/web2c/texmfmp-help.h
+++ b/Build/source/texk/web2c/texmfmp-help.h
@@ -99,9 +99,7 @@ const_string EPTEXHELP[] = {
"-cnf-line=STRING parse STRING as a configuration file line",
"-etex enable e-TeX extensions",
"-fmt=NAME use NAME instead of program name or %&format.",
-#if defined(WIN32)
"[-no]-guess-input-enc disable/enable to guess input file encoding",
-#endif
"-halt-on-error stop processing at the first error",
"[-no]-file-line-error disable/enable file:line:error style messages",
"-ini be iniptex.",
@@ -228,9 +226,7 @@ const_string EUPTEXHELP[] = {
"-cnf-line=STRING parse STRING as a configuration file line",
"-etex enable e-TeX extensions",
"-fmt=NAME use NAME instead of program name or %&format.",
-#if defined(WIN32)
"[-no]-guess-input-enc disable/enable to guess input file encoding",
-#endif
"-halt-on-error stop processing at the first error",
"[-no]-file-line-error disable/enable file:line:error style messages",
"-ini be iniptex.",
@@ -497,9 +493,7 @@ const_string PTEXHELP[] = {
"",
"-cnf-line=STRING parse STRING as a configuration file line",
"-fmt=NAME use NAME instead of program name or %&format.",
-#if defined(WIN32)
"[-no]-guess-input-enc disable/enable to guess input file encoding",
-#endif
"-halt-on-error stop processing at the first error",
"[-no]-file-line-error disable/enable file:line:error style messages",
"-ini be iniptex.",
@@ -624,9 +618,7 @@ const_string UPTEXHELP[] = {
"",
"-cnf-line=STRING parse STRING as a configuration file line",
"-fmt=NAME use NAME instead of program name or %&format.",
-#if defined(WIN32)
"[-no]-guess-input-enc disable/enable to guess input file encoding",
-#endif
"-halt-on-error stop processing at the first error",
"[-no]-file-line-error disable/enable file:line:error style messages",
"-ini be iniptex.",
diff --git a/Build/source/texk/web2c/uptexdir/ChangeLog b/Build/source/texk/web2c/uptexdir/ChangeLog
index e6e481b8bfb..a9d282a43d2 100644
--- a/Build/source/texk/web2c/uptexdir/ChangeLog
+++ b/Build/source/texk/web2c/uptexdir/ChangeLog
@@ -1,3 +1,11 @@
+2022-06-12 TANAKA Takuji <ttk@t-lab.opal.ne.jp>
+
+ * kanji.[ch], upbibtex.ch:
+ Support guessing input file encodings.
+ https://github.com/texjporg/tex-jp-build/issues/142
+ * tests/upbibtex.test, am/uptex.am:
+ Add tests for guess encodings & upBibTeX.
+
2022-05-15 TANAKA Takuji <ttk@t-lab.opal.ne.jp>
* upbibtex.ch:
diff --git a/Build/source/texk/web2c/uptexdir/am/uptex.am b/Build/source/texk/web2c/uptexdir/am/uptex.am
index 13c5ecb37ff..6ad2b69c5ef 100644
--- a/Build/source/texk/web2c/uptexdir/am/uptex.am
+++ b/Build/source/texk/web2c/uptexdir/am/uptex.am
@@ -199,7 +199,9 @@ endif UPWEB
## Test data and results
##
## uptexdir/upbibtex.test
-DISTCLEANFILES += uptests/xexampl.aux uptests/xexampl.bbl uptests/xexampl.blg
+EXTRA_DIST += tests/enc-u.bbl tests/enc-eu.bbl tests/enc-su.bbl
+DISTCLEANFILES += uptests/xexampl.aux uptests/xexampl.bbl uptests/xexampl.blg \
+ uptests/xenc*.*
## uptexdir/updvitype.test
DISTCLEANFILES += uptests/xstory.dvityp uptests/xpagenum.typ
## uptexdir/uppltotf.test
diff --git a/Build/source/texk/web2c/uptexdir/kanji.c b/Build/source/texk/web2c/uptexdir/kanji.c
index a73ebf1f3cc..4cc5b38aace 100644
--- a/Build/source/texk/web2c/uptexdir/kanji.c
+++ b/Build/source/texk/web2c/uptexdir/kanji.c
@@ -513,14 +513,12 @@ void init_default_kanji (const_string file_str, const_string internal_str)
fprintf (stderr, "Ignoring bad kanji encoding \"%s\".\n", p);
}
-#ifdef WIN32
p = kpse_var_value ("guess_input_kanji_encoding");
if (p) {
if (*p == '1' || *p == 'y' || *p == 't')
infile_enc_auto = 1;
free(p);
}
-#endif
}
void init_default_kanji_select(void)
diff --git a/Build/source/texk/web2c/uptexdir/kanji.h b/Build/source/texk/web2c/uptexdir/kanji.h
index 7a23e31a0b9..cbdd47f2453 100644
--- a/Build/source/texk/web2c/uptexdir/kanji.h
+++ b/Build/source/texk/web2c/uptexdir/kanji.h
@@ -44,6 +44,9 @@ extern void init_default_kanji_select (void);
#define initkanji() init_default_kanji_select()
/* for upDVItype */
#define setpriorfileenc() set_prior_file_enc()
+/* for upBibTeX */
+#define enableguessfileenc() set_guess_file_enc(1)
+#define disableguessfileenc() set_guess_file_enc(0)
/* number of rest of multi-char for kcode_pos */
#define nrestmultichr(x) ( (x)!=0 ? ((x) / 8) + 2 - ((x) % 8) : -1 )
diff --git a/Build/source/texk/web2c/uptexdir/upbibtex.ch b/Build/source/texk/web2c/uptexdir/upbibtex.ch
index 4493d9f32c7..da97034c925 100644
--- a/Build/source/texk/web2c/uptexdir/upbibtex.ch
+++ b/Build/source/texk/web2c/uptexdir/upbibtex.ch
@@ -462,9 +462,9 @@ sp_end := tpe;
@z
@x
-const n_options = 6; {Pascal won't count array lengths for us.}
+const n_options = 8; {Pascal won't count array lengths for us.}
@y
-const n_options = 7; {Pascal won't count array lengths for us.}
+const n_options = 9; {Pascal won't count array lengths for us.}
@z
@x
diff --git a/Build/source/texk/web2c/uptexdir/upbibtex.test b/Build/source/texk/web2c/uptexdir/upbibtex.test
index 9a12a72cb04..e8acc12d5dd 100755
--- a/Build/source/texk/web2c/uptexdir/upbibtex.test
+++ b/Build/source/texk/web2c/uptexdir/upbibtex.test
@@ -5,13 +5,38 @@
# You may freely use, modify and/or distribute this file.
test -d uptests || mkdir -p uptests
-rm -f uptests/xexampl.*
+rm -f uptests/xexampl.* uptests/xenc*.*
+
+rc=0
+
+TEXMFCNF=$srcdir/../kpathsea
+BSTINPUTS=$srcdir/tests
+BIBINPUTS=$srcdir/tests
+export TEXMFCNF BSTINPUTS BIBINPUTS
cp $srcdir/tests/exampl.aux uptests/xexampl.aux
-TEXMFCNF=$srcdir/../kpathsea \
- BSTINPUTS=$srcdir/tests \
- BIBINPUTS=$srcdir/tests \
- ./upbibtex uptests/xexampl || exit 1
-diff $srcdir/tests/exampl.bbl uptests/xexampl.bbl || exit 2
+./upbibtex uptests/xexampl || rc=1
+diff $srcdir/tests/exampl.bbl uptests/xexampl.bbl || rc=2
+
+
+cp $srcdir/tests/enc.aux uptests/xenc.aux
+
+guess_input_kanji_encoding=1 ./upbibtex uptests/xenc || rc=3
+diff $srcdir/tests/enc-u.bbl uptests/xenc.bbl || rc=4
+
+
+cp $srcdir/tests/enc-e.aux uptests/xenc-e.aux
+
+guess_input_kanji_encoding=1 ./upbibtex -kanji=euc uptests/xenc-e || rc=5
+diff $srcdir/tests/enc-eu.bbl uptests/xenc-e.bbl || rc=6
+
+
+cp $srcdir/tests/enc-s.aux uptests/xenc-s.aux
+
+./upbibtex -guess-input-enc -kanji=sjis uptests/xenc-s || rc=7
+diff $srcdir/tests/enc-su.bbl uptests/xenc-s.bbl || rc=8
+
+
+exit $rc