diff options
author | Karl Berry <karl@freefriends.org> | 2018-10-02 01:05:54 +0000 |
---|---|---|
committer | Karl Berry <karl@freefriends.org> | 2018-10-02 01:05:54 +0000 |
commit | ce46cfeac58868701de09c0e4a836a9bbbdcf049 (patch) | |
tree | 02f2a68c1c6171442ea3d5a7858c11176e2f98b6 /Master/texmf-dist/tex | |
parent | 60e8c3cc3a1065efdbecf837cd389599f261e588 (diff) |
bxwareki (1oct18) [recommit]
git-svn-id: svn://tug.org/texlive/trunk@48799 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex')
-rw-r--r-- | Master/texmf-dist/tex/latex/bxwareki/bxwareki-cd.def | 285 | ||||
-rw-r--r-- | Master/texmf-dist/tex/latex/bxwareki/bxwareki.sty | 64 |
2 files changed, 345 insertions, 4 deletions
diff --git a/Master/texmf-dist/tex/latex/bxwareki/bxwareki-cd.def b/Master/texmf-dist/tex/latex/bxwareki/bxwareki-cd.def index ac08ea1e031..b82e1ce0d5d 100644 --- a/Master/texmf-dist/tex/latex/bxwareki/bxwareki-cd.def +++ b/Master/texmf-dist/tex/latex/bxwareki/bxwareki-cd.def @@ -12,12 +12,18 @@ %% file declaration \NeedsTeXFormat{LaTeX2e} -\ProvidesFile{bxwareki-cd.def}[2018/09/24 v0.3] +\ProvidesFile{bxwareki-cd.def}[2018/10/01 v0.4] \ifbxwy@epTeXinputencoding@ok \epTeXinputencoding utf8 \fi +%% branch for download mode +\ifbxwy@download + \long\def\bxwy@next#1\bxwy@download{} + \expandafter\bxwy@next +\fi + %--------------------------------------- helpers %% \bxwy@burst-`>... @@ -121,6 +127,283 @@ \def\bxwy@cdpo@@o#1#2#3{#1#2o} \def\bxwy@cdpo@@O#1#2#3{#1#2O} +%--------------------------------------- special procedure for LuaTeX +\ifx\bxwy@new@gengo\@empty \ifnum\bxwy@engine=5 + +% The process below tries to guess the name of the new gengo +% from the result of os,date(). +\begingroup + \catcode`\~=12 \let\0\relax \let\1\relax \let\2\relax + \directlua{ + if not bxwareki then bxwareki = {} end + local os = bxwareki.os or os + function bxwareki.get_new_gengo() + local lc_time = nil + local ok, ret = pcall(function() + assert(os.type == "unix") + lc_time = os.setlocale(nil, "time") + assert(os.setlocale("ja_JP.utf8", "time") or + os.setlocale("ja_JP.UTF-8", "time")) + local heisei = "\229\185\179\230\136\144" + local kanji = "[\228-\233][\128-\191][\128-\191]" + local gh = os.date("\037EC", 1500000000) + local gn = os.date("\037EC", 1600000000) + assert(gh == heisei and gn ~= heisei and + gn:match("^"..kanji..kanji.."$")) + return gn + end) + os.setlocale(lc_time, "time") + return ok and ret or "" + end} + \toks@{} + \directlua{pcall(function() + tex.toks[0] = bxwareki.get_new_gengo() + end)} + \xdef\bxwy@new@gengo{\the\toks@} +\endgroup + +\fi\fi %--------------------------------------- all done \endinput +%======================================= +\bxwy@download +\begingroup +\catcode`\^^A=14 \catcode`\^^\=0 \catcode`\^^[=1 \catcode`\^^]=2 +\endlinechar=10 \catcode10=12 \catcode96=7 \let\do\@makeother +\dospecials``\directlua``[``A +local ok, retcode = pcall(function() +---------------------------------------- shell availability check +local ok = false +if ((status and status.luatex_version) or 0) >= 68 then + ok = (os.execute() == 1) +end +if not ok then return 2 end +---------------------------------------- preparations +local url = 'https://raw.githubusercontent.com/zr-tex8r/BXwareki/master/bxwareki2019.def' +local fdef = 'bxwareki2019.def' +io.stderr:write("\n\n//////// START BXWAREKI DOWNLOAD PROCEDURE ////////\n") +local function log(s) + io.stderr:write("bxwareki: ", s, "\n") +end +local function info(f, ...) log(f:format(...)) end +local function finish(s, ...) info(...); return s end +---------------------------------------- 'zrget' module +zrget = (function(M) + -- parameters + M.max_trial = M.max_trial or 3 + M.interval = M.interval or 1 -- second + M.log = M.log or true + + -- helpers + local lfs = require 'lfs' + local socket = require 'socket' + local tempb = '__zrget' + local win = (lfs.attributes('C:\\NUL', 'mode') ~= nil) + local function upath(pth) + return (win) and pth:gsub('\\', '/') or pth + end + local function npath(pth) + return (win) and pth:gsub('/', '\\') or pth + end + local function mpath(...) + return table.concat({...}, (win) and '\\' or '/') + end + local function log_print(s) + io.stderr:write("zrget: ", s, "\n") + end + local function log(fmt, ...) + if not M.log then return end + local l = (type(M.log) == 'function') and M.log or log_print + l(tostring(fmt):format(...)) + end + local function file_ok(pth) + return ((lfs.attributes(pth, 'size') or 0) > 0) + end + local function execute(clfmt, ...) + local cl = clfmt:format(...) + if M.verbose then log("RUN: %s", cl) end + local ok = os.execute(cl) + return (ok == true) or (ok == 0) + end + local badbin = '*' + local function exefile(pth) + pth = npath(pth..(win and '.exe' or '')) + return (file_ok(pth) or nil) and pth + end + local function validate(vprc, pth) + if not file_ok(pth) then return false end + local h = io.open(pth, 'rb') + local d = h and h:read('*a') + if h then h:close() end + local r = d and (not vprc or vprc(d)) + if not r then log("Validation failure") end + return r + end + + -- TeXLive stuffs + local kpse + pcall(function() + kpse = require 'kpse' + kpse.set_program_name('luatex') + end) + local tlpkg = kpse and kpse.var_value('SELFAUTOPARENT') + tlpkg = tlpkg and tlpkg..'/tlpkg' + local tlwget = tlpkg and exefile(tlpkg..'/installer/wget/wget') + local tlperl = tlpkg and exefile(tlpkg..'/tlperl/bin/perl') + + -- methods + local fcout, fcerr, ftdst = + tempb..'-1.out', tempb..'-2.out', tempb..'-0.bin' + local method_list = { + { + name = 'wget'; + checker = 'wget --version'; check_tag = 'Wget'; + loader = function(src) + return execute('wget -q --no-check-certificate "%s" -O %s 2>%s', + src, ftdst, fcerr) + end + }, + { + name = 'curl'; + checker = 'curl --version'; check_tag = 'curl'; + loader = function(src) + return execute('curl -k -s "%s" -o %s 2>%s', + src, ftdst, fcerr) + end + }, + { + name = 'tl-wget'; + checker = tlwget and tlwget..' --version'; check_tag = 'Wget'; + loader = function(src) + return execute('%s -q --no-check-certificate "%s" -O %s 2>%s', + tlwget, src, ftdst, fcerr) + end + }, + { + name = 'powershell'; + checker = 'powershell -Help'; check_tag = 'PowerShell'; + loader = function(src) + return execute('powershell -Command Invoke-WebRequest '.. + '"%s" -OutFile %s 2>%s', + src, ftdst, fcerr) + end + }, +--[[ + { + name = 'tl-perl'; + checker = tlperl and tlperl..' --version'; check_tag = '?Perl'; + loader = function(src) + return false -- TODO: make it + end + }, +]] + } + + -- main procedure + function M.download(url, dst, vprc) + url = tostring(url):gsub('[\1-\31 \"\'<>\\`{|}]', + function(s) return ('%%%02X'):format(string.byte(s)) end) + if file_ok(dst) then + log("File '%s' already exists", dst) + return false + end + os.remove(dst) + -- + local done = false + for tc = 1, M.max_trial do + for _, mth in ipairs(method_list) do + repeat + if not mth.checker or mth.pass then break end + log("Try method '%s'...(%s)", mth.name, tc) + -- check + execute('%s 1>%s 2>%s', mth.checker, fcout, fcerr) + local hso = io.open(fcout, 'rb') + local p = (hso and hso:read('*a') or ''):find(mth.check_tag, 1, true) + hso:close() + if not p then + log("Method '%s' is not available", mth.name) + mth.pass = true + break + end + -- download + log("Try downloading...") + os.remove(ftdst) + if mth.loader(url) and validate(vprc, ftdst) then + done = true; break + end + socket.sleep(M.interval) + os.remove(ftdst) + until true + if done then break end + end + if done then break end + end + -- + if done then + os.rename(ftdst, dst) + log("File '%s' is successfully downloaded", dst) + else + log("File '%s' cannot be downloaded", dst) + end + -- + for _, f in ipairs {ftdst, fcerr, fcout} do + os.remove(f) + end + return done + end + + return M +end)({}) +---------------------------------------- make directory +if kpse.find_file(fdef, 'tex', true) then + return finish(0, "File '%s' already exists.", fdef) +end +local phome = kpse.var_value("TEXMFHOME") +if not (phome and lfs.isdir(phome)) then + return finish(1, "TEXMFHOME is invalid.") +end +local ppkg = assert(kpse.find_file('bxwareki.sty', 'tex', true)) +local pm = (ppkg:match('^.*(tex/latex.*)') or 'tex/latex/bxwareki/') + :gsub('/[^/]*$', '') +local pddir = phome +for t in pm:gmatch('[^/]+') do + pddir = pddir..'/'..t + lfs.mkdir(pddir) +end +if not lfs.isdir(pddir) then + return finish(1, "Cannot create directory '%s'", pddir) +end +---------------------------------------- download +zrget.log = log +info("Target file is '%s'.", fdef) +local ok = zrget.download(url, fdef, + function (d) return d:match('^%x%x%x%x%x%x:%x%x%x%x:') end) +if not ok then return 1 end +---------------------------------------- transfer +local pddef = pddir..'/'..fdef +local hddef = io.open(pddef, 'wb') +if not hddef then + return finish(1, 'Cannot open '%s' for output.', pddef) +end +local hsdef = assert(io.open(fdef, 'rb')) +assert(hddef:write(assert(hsdef:read('*a')))) +hsdef:close(); hddef:close() +os.remove(fdef) +info("Target file is copied to '%s'.", pddef) +---------------------------------------- last check +if not kpse.find_file(fdef, 'tex', true) then + return finish(1, "Target file is still not found.") +end +return finish(0, "Target file is installed at '%s'.", pddef) +---------------------------------------- done +end) +if not ok then + io.stderr:write("\n\nINTERNAL ERROR:\n"..tostring(retcode).."\n") + retcode = 1 +end +tex.setcount('global', 'count@', retcode) +``]``\endgroup% + +\chardef\bxwy@next=\count@ + %% EOF diff --git a/Master/texmf-dist/tex/latex/bxwareki/bxwareki.sty b/Master/texmf-dist/tex/latex/bxwareki/bxwareki.sty index 2509ccf7522..35349508622 100644 --- a/Master/texmf-dist/tex/latex/bxwareki/bxwareki.sty +++ b/Master/texmf-dist/tex/latex/bxwareki/bxwareki.sty @@ -12,7 +12,7 @@ %% package declaration \NeedsTeXFormat{LaTeX2e} -\ProvidesPackage{bxwareki}[2018/09/24 v0.3] +\ProvidesPackage{bxwareki}[2018/10/01 v0.4] %% preparation \def\bxwy@pkgname{bxwareki} @@ -87,6 +87,38 @@ \expandafter\mathchardef\csname c@#1\endcsname#2\relax} \fi +%--------------------------------------- options + +%% variables +\newif\ifbxwy@download + +%% 'download' +\DeclareOption{download2019}{% + \bxwy@downloadtrue} +% dispatch +\ProcessOptions\relax + +%--------------------------------------- download mode + +\ifbxwy@download + \chardef\bxwy@next=\tw@ + \ifnum\bxwy@engine=5 + \input{bxwareki-cd.def} + \fi + \ifcase\bxwy@next + \PackageInfo\bxwy@pkgname + {The installation of 'bxwareki2019.def' succeeded\@gobble} + \or + \PackageWarningNoLine\bxwy@pkgname + {The installation of 'bxwareki2019.def' failed} + \else + \PackageWarningNoLine\bxwy@pkgname + {Download mode is not available here and thus\MessageBreak + the option 'download2019' is ignored} + \fi +\fi +\bxwy@downloadfalse + %--------------------------------------- Japanese string maker % The "combo-code" represents a single Japanese character and has @@ -282,6 +314,10 @@ % The kanji string for the new gengo if available; otherwise empty. \let\bxwy@new@gengo\@empty +%% \bxwy@new@gengo@initial +% The initial Latin letter for the new gengo. +\let\bxwy@new@gengo@initial\@empty + %% read the file \endlinechar\m@ne \openin\@inputcheck=\bxwy@new@gengo@file\relax @@ -296,10 +332,19 @@ \else \edef\bxwy@next{\noexpand\bxwy@new@gengo{\bxwy@tmpa}} \expandafter\bxwy@add@jchar\bxwy@next + \read\@inputcheck to\bxwy@tmpa + \ifeof\@inputcheck + \global\let\bxwy@new@gengo\@empty + \else + \let\bxwy@new@gengo@initial\bxwy@tmpa + \fi \fi \fi \fi \endlinechar=13 % +\def\bxwy@next#1>#2#3#4\bxwy@end{% + \ifx#3\relax\else \let\bxwy@new@gengo@initial\@empty \fi} +\expandafter\bxwy@next\meaning\bxwy@new@gengo@initial\relax\relax\bxwy@end %--------------------------------------- calculate wareki year @@ -341,7 +386,7 @@ % Sets \bxwy@g@gengo and \bxwy@g@year. \def\bxwy@calc@wareki@year{% \@tempcnta=\the\year\two@digits\month\two@digits\day\relax - \let\bxwy@tmpb\@empty \@tempcntb\year + \let\bxwy@tmpa\@empty \let\bxwy@tmpb\@empty \@tempcntb\year \ifnum\@tempcnta<18730101 % ancient times (non-Gregorian) \else\ifnum\@tempcnta<19120730 % meiji era \let\bxwy@tmpb\bxwy@@meiji @@ -366,6 +411,16 @@ \xdef\bxwy@g@year{\the\@tempcntb}% \xdef\bxwy@g@date{{\the\year}{\the\month}{\the\day}}} +%% \bxwy@gengo@initial@of\CS +\def\bxwy@gengo@initial@of#1{% + \ifx#1\@empty \@empty + \else\ifx#1\bxwy@@meiji M% + \else\ifx#1\bxwy@@taisho T% + \else\ifx#1\bxwy@@showa S% + \else\ifx#1\bxwy@@heisei H% + \else\ifx#1\bxwy@new@gengo \bxwy@new@gengo@initial + \fi\fi\fi\fi\fi\fi} + %--------------------------------------- render wareki date %% \bxwy@render@for\CSIdate\CSIgengo\CSIyear @@ -424,7 +479,8 @@ %% \bxwy@render@date \def\bxwy@render@date{% \bxwy@render@for\bxwy@date\warekigengo\c@warekiyear - \warekiyear\warekidate\warekikanjidate\warekijkanjidate} + \warekiyear\warekidate\warekikanjidate\warekijkanjidate + \edef\warekigengoinitial{\bxwy@gengo@initial@of\warekigengo}} %% \bxwy@render@today \def\bxwy@render@today{% \bxwy@render@for\bxwy@today@date\bxwy@today@gengo\bxwy@today@year @@ -447,6 +503,8 @@ \bxwy@newcounter{warekiyear} %%<*> \warekigengo : kanji string of the current gengo \newcommand*\warekigengo{} +%%<*> \warekigengoinitial : initial Latin letter of the current gengo +\newcommand*\warekigengoinitial{} %%<*> \warekiyear : string of the wareki year \newcommand*\warekiyear{} %%<*> \warekidate : string of the wareki date |