summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/bxwareki/bxwareki-cd.def
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2018-10-02 01:05:54 +0000
committerKarl Berry <karl@freefriends.org>2018-10-02 01:05:54 +0000
commitce46cfeac58868701de09c0e4a836a9bbbdcf049 (patch)
tree02f2a68c1c6171442ea3d5a7858c11176e2f98b6 /Master/texmf-dist/tex/latex/bxwareki/bxwareki-cd.def
parent60e8c3cc3a1065efdbecf837cd389599f261e588 (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/latex/bxwareki/bxwareki-cd.def')
-rw-r--r--Master/texmf-dist/tex/latex/bxwareki/bxwareki-cd.def285
1 files changed, 284 insertions, 1 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