texlive[48799] Master/texmf-dist: bxwareki (1oct18) [recommit]

commits+karl at tug.org commits+karl at tug.org
Tue Oct 2 03:05:54 CEST 2018


Revision: 48799
          http://tug.org/svn/texlive?view=revision&revision=48799
Author:   karl
Date:     2018-10-02 03:05:54 +0200 (Tue, 02 Oct 2018)
Log Message:
-----------
bxwareki (1oct18) [recommit]

Modified Paths:
--------------
    trunk/Master/texmf-dist/doc/latex/bxwareki/README.md
    trunk/Master/texmf-dist/tex/latex/bxwareki/bxwareki-cd.def
    trunk/Master/texmf-dist/tex/latex/bxwareki/bxwareki.sty

Added Paths:
-----------
    trunk/Master/texmf-dist/doc/latex/bxwareki/bxwareki.pdf
    trunk/Master/texmf-dist/doc/latex/bxwareki/bxwareki.tex

Modified: trunk/Master/texmf-dist/doc/latex/bxwareki/README.md
===================================================================
--- trunk/Master/texmf-dist/doc/latex/bxwareki/README.md	2018-10-02 01:04:41 UTC (rev 48798)
+++ trunk/Master/texmf-dist/doc/latex/bxwareki/README.md	2018-10-02 01:05:54 UTC (rev 48799)
@@ -30,142 +30,15 @@
 The bxwareki Package ― main
 ----------------------------
 
-Note: The modern (post-1873) Japanese calendar (*wareki*; 和暦) can be
-regarded as a variant of Gregorian calendar where only the notation of
-years differs from the original. To avoid confusion, this document refers
-to the original Gregorian calendar as the *Western calendar*, which
-corresponds to the Japanese term *seireki* (西暦).
+See the manual `bxwareki.pdf` for detail.
 
-### Package Loading
 
-    \usepackage{bxwareki}
-
-### Usage
-
-#### Conversion from the given date
-
-  * `\warekisetdate{<year>}{<month>}{<day>}`: Converts from the specified
-    Western date. The result will be rendered by the commands described
-    at the following items, where the result for the invocation
-    `\warekisetdate{2018}{8}{28}` will be shown as example.
-
-    Note: Although the Japanese calendar differs from the Western calendar
-    only in the notation of years, the value of months and days are still
-    required, since the notation of the year in which *kaigen* (改元;
-    change of gengo) occurs depends on months and days.
-
-  * `\warekisettoday`: Does `\warekisetdate` with the current date.
-
-  * Counter `warekiyear`: The year number (within the gengo); e.g. 30.
-
-    Note: Unlike ordinary counters, the assignment to `warekiyear` by
-    `\warekisetdate` is *local*. Moreover, manual assignment to this
-    counter is not supported.
-
-  * `\warekigengo`: The gengo in kanji, e.g. “平成”.
-
-  * `\warekiyear`: The full notation of the year (without ‘年’),
-    e.g. “平成30”.
-
-    Note: When the year number is one, the kanji ‘元’ is used instead
-    of the numeral ‘1’.
-
-  * `\warekidate`: The date string, e.g. “平成30年8月28日”.
-
-  * `\warekikanjidate`: The date string using kansuji (kanji numerals),
-    e.g. “平成三〇年八月二八日”.
-
-  * `\warekijkanjidate`: The date string using “kansuji-by-reading”
-    (that is, kanji rendering of numbers in the Japanese language),
-    e.g. “平成三十年八月二十八日”.
-
-  * `\warekicustomdate{<option>}`: The date string in the form specified
-    with the option. The option is a string of letters such as `wk` and
-    each letter means a specific setting. When the option is empty, the
-    date is rendered in the form “2018年8月28日” (using the Western
-    calendar). The available option letters are:
-
-      - `w`: uses Japanese calendar (2018年 → 平成30年)
-      - `k`: uses kansuji (28 → 二八)
-      - `j`: uses kansuji-by-reading (28 → 二十八)  
-        Note: Western years does not support kansuji-by-reading and thus
-        `k` will be applied instead (二〇一八, not 二千十八)
-      - `J`: variant of `j` where “ten’s multiple” kanji characters
-        (廿 and 卅) are employed (28 → 廿八)
-      - `o`: uses *imyo* (異名) for months (8月 → 葉月)  
-        (Don’t ask me if this form is ever used in LaTeX document!)
-
-    Note: This command is supported only on pdfLaTeX, XeLaTeX, LuaLaTeX,
-    upLaTeX, ApLaTeX and recent versions of pLaTeX. On other engines it
-    simply falls back to `\warekidate`.
-
-  * `\WarekiIfCustomDateAvailable{<true>}{<false>}`: Tests if the command
-    `\warekicustomdate` is supported on the engine in use.
-
-#### Current date
-
-These commands always represent the current date, and are not affected
-by `\warekisetdate` (or `\warekisettoday`).
-
-  * `\warekitoday`: The `\warekidate` form of the current date.
-  * `\warekikanjitoday`: The `\warekikanjidate` form.
-  * `\warekijkanjitoday`: The `\warekijkanjidate` form.
-
-#### Inter-alphabet-kanji glues
-
-In quality Japanese typesetting, a thin space (*shibuaki*; 四分空き)
-must be inserted between an alphabet letter and a kanji letter. This
-package by default inserts a command suitable for the most prevalent
-Japanese-typesetting environment for the engine in use.
-
-  * On pLaTeX, upLaTeX and ApLaTeX: Nothing is inserted, since the engine
-    can automatically insert shibuaki spaces.
-  * On LuaLaTeX and XeLaTeX: Nothing is inserted, on the assumption that
-    the package for Japanese typesetting (such as LuaTeXja and xeCJK)
-    will automatically insert shibuaki spaces.
-  * On LaTeX and pdfLaTeX: `~` is inserted, on the assumption that the
-    CJK package is employed and `\CJKtilde` is in effect.
-
-On the engines with e-TeX extension, the command for shibuaki can be
-changed with the following commands:
-
-  * `\WarekiUseCustomInterGlue{<text>}`: Uses `<text>` for making shibuaki
-    spaces.
-  * `\WarekiUseNormalInterGlue`: Reverts `\WarekiUseCustomInterGlue` and
-    uses the normal setting.
-
-### Support for the kaigen planned in 2019
-
-In Japan a kaigen (due to the abdication of the Emperor) is planned on
-2019/05/01, but the new gengo is not yet announced. Thus in the current
-version of the package, the date of the day or later is not supported
-(the Western year will be printed instead).
-.
-This package will be updated to support the new gengo and uploaded to
-CTAN, as soon as the new gengo is announced.
-
-### Notices for TeX programmers
-
-  * On the engines with support for native kanji/Unicode characters
-    (i.e. LuaLaTeX, XeLaTeX, pLaTeX, upLaTeX, and ApLaTeX), the content
-    (one-level expansion) of `\wareki…date` (except `\warekicustomdate`)
-    and `\wareki…today` is a simple string of character tokens, unless
-    `\WarekiUseCustomInterGlue` is in effect. The same holds for LaTeX
-    and pdfLaTeX, except that each kanji character is represented by the
-    sequence of activated byte tokens and `~` is inserted as shibuaki
-    spaces.
-  * On the engines with native kanji/Unicode support, `\warekicustomdate`
-    fully expands to a simple string of character tokens (again without
-    `\WarekiUseCustomInterGlue`), and the situation on LaTeX and pdfLaTeX
-    is parallel to that described at the item above.
-  * The use of `\WarekiUseCustomInterGlue` does not break the full
-    expandability of `\wareki…date` and `\wareki…today` on the engines
-    with native kanji/Unicode support.
-
-
 Revision History
 ----------------
 
+  * Version 0.4  ‹2018/10/01›
+      - Add `\warekigengoinitial`.
+      - Add option `download2019`.
   * Version 0.3  ‹2018/09/24›
       - The total rewrite.
   * Version 0.2  ‹2018/04/08›

Added: trunk/Master/texmf-dist/doc/latex/bxwareki/bxwareki.pdf
===================================================================
(Binary files differ)

Index: trunk/Master/texmf-dist/doc/latex/bxwareki/bxwareki.pdf
===================================================================
--- trunk/Master/texmf-dist/doc/latex/bxwareki/bxwareki.pdf	2018-10-02 01:04:41 UTC (rev 48798)
+++ trunk/Master/texmf-dist/doc/latex/bxwareki/bxwareki.pdf	2018-10-02 01:05:54 UTC (rev 48799)

Property changes on: trunk/Master/texmf-dist/doc/latex/bxwareki/bxwareki.pdf
___________________________________________________________________
Added: svn:mime-type
## -0,0 +1 ##
+application/pdf
\ No newline at end of property
Added: trunk/Master/texmf-dist/doc/latex/bxwareki/bxwareki.tex
===================================================================
--- trunk/Master/texmf-dist/doc/latex/bxwareki/bxwareki.tex	                        (rev 0)
+++ trunk/Master/texmf-dist/doc/latex/bxwareki/bxwareki.tex	2018-10-02 01:05:54 UTC (rev 48799)
@@ -0,0 +1,286 @@
+% LuaLaTeX document; UTF-8
+\documentclass[a4paper]{article}
+\usepackage[scale=0.75]{geometry}
+\usepackage{shortvrb}
+\MakeShortVerb{\|}
+\newcommand{\PkgVersion}{0.4}
+\newcommand{\PkgDate}{2018/10/01}
+\newcommand{\Pkg}[1]{\textsf{#1}}
+\newcommand{\Meta}[1]{$\langle$\textit{#1}$\rangle$}
+\newcommand{\Note}{\par\noindent\emph{Note:}\quad}
+\newcommand{\Ie}{i.\,e.}
+\newcommand{\Eg}{e.\,g.}
+\newcommand{\Means}{~:\quad}
+\usepackage{bxtexlogo}
+\bxtexlogoimport{*,ApTeX,JTeX}
+% Japanese something
+\usepackage{fontspec}
+\newfontfamily{\fIpaex}{IPAexMincho}[Scale=0.95]
+\newcommand*{\Ja}[1]{{\fIpaex#1}}
+\newcommand*{\+}{\hspace{0.25em minus 0.25em}}
+%-----------------------------------------------------------
+\begin{document}
+\title{The \Pkg{bxwareki} package}
+\author{Takayuki YATO\quad (aka.~``ZR'')}
+\date{v\PkgVersion \quad[\PkgDate]}
+\maketitle
+
+%===========================================================
+\section{Overview}
+\label{sec:Overview}
+
+This package provides commands to convert from the Gregorian calendar
+(2018/8/28) to the Japanese rendering of the Japanese calendar
+(\Ja{平成\+30\+年\+8\+月\+28\+日}).
+You can choose whether the numbers are written
+in Western numerals (28) or kanji numerals (\Ja{二八}).
+
+Note that the package only deals with dates in the year 1873 or later,
+where the Japanese calendar is really a Gregorian calendar
+with the different notation of years.
+
+\paragraph{System requirement}
+
+\begin{itemize}
+\item \TeX{} format: \LaTeX.
+\item \TeX{} engine: {\pdfTeX}, {\LuaTeX}, {\XeTeX},
+  {\pTeX}, {\upTeX}, {\ApTeX} ({\pTeX}-ng), NTT-{\JTeX}.
+\end{itemize}
+
+\Note The modern (post-1873) Japanese calendar (\emph{wareki}; \Ja{和暦})
+can be regarded as a variant of Gregorian calendar
+where only the notation of years differs from the original.
+To avoid confusion, this document refers to the original Gregorian
+calendar as the \emph{Western calendar},
+which corresponds to the Japanese term \emph{seireki} (\Ja{西暦}).
+
+%===========================================================
+\section{Package Loading}
+\label{sec:Loading}
+
+No options are needed in normal use%
+\footnote{See Section~\ref{ssec:download2019}
+  for the \texttt{download2019} option.}.
+
+\begin{quote}\small\begin{verbatim}
+\usepackage{bxwareki}
+\end{verbatim}\end{quote}
+
+%===========================================================
+\section{Usage}
+\label{sec:Usage}
+
+%-------------------
+\subsection{Conversion from the given date}
+
+\begin{itemize}
+\item |\warekisetdate{|\Meta{year}|}{|\Meta{month}|}{|\Meta{day}|}|\Means
+  Converts from the specified Western date.
+  The result will be rendered by the commands described
+  at the following items, where the result for the invocation
+  |\warekisetdate{2018}{8}{28}|
+  will be shown as example.
+
+  \Note Although the Japanese calendar differs from the Western calendar
+  only in the notation of years,
+  the value of months and days are still required,
+  since the notation of the year in which
+  \emph{kaigen} (\Ja{改元}; change of gengo)
+  occurs depends on months and days.
+
+\item |\warekisettoday|\Means
+  Does |\warekisetdate| with the current date.
+
+\item Counter |warekiyear|\Means
+  The year number (within the gengo); \Eg~``\Ja{30}''.
+
+  \Note Unlike ordinary counters,
+  the assignment to |warekiyear| by |\warekisetdate| is \emph{local}.
+  Moreover, manual assignment to this counter is not supported.
+
+\item |\warekigengo|\Means
+  The gengo in kanji, \Eg~``\Ja{平成}''.
+
+\item |\warekigengoinitial|\Means
+  The initial Latin letter of the gengo, \Eg~``\Ja{H}''.
+
+\item |\warekiyear|\Means
+  The full notation of the year (without `\Ja{年}'),
+  \Eg~``\Ja{平成\+30}''.
+
+  \Note When the year number is one,
+  the kanji `\Ja{元}' is used instead of the numeral `\Ja{1}'.
+
+\item |\warekidate|\Means
+  The date string, \Eg~``\Ja{平成\+30\+年\+8\+月\+28\+日}''.
+
+\item |\warekikanjidate|\Means
+  The date string using kansuji (kanji numerals),
+  \Eg~``\Ja{平成三〇年八月二八日}''.
+
+\item |\warekijkanjidate|\Means
+  The date string using ``kansuji-by-reading''
+  (that is, kanji rendering of numbers in the Japanese language),
+  \Eg.``\Ja{平成三十年八月二十八日}''.
+
+\item |\warekicustomdate{|\Meta{option}|}|\Means
+  The date string in the form specified with the option.
+  The option is a string of letters such as |wk|
+  and each letter means a specific setting.
+  When the option is empty, the date is rendered in the form
+  ``\Ja{2018\+年\+8\+月\+28\+日}'' (using the Western calendar).
+  The available option letters are:
+  \begin{itemize}
+  \item |w|\Means
+    uses Japanese calendar (\Ja{2018\+年} $\to$ \Ja{平成\+30\+年});
+  \item |k|\Means
+    uses kansuji (\Ja{28} $\to$ \Ja{二八});
+  \item |j|\Means
+    uses kansuji-by-reading (\Ja{28} $\to$ \Ja{二十八});
+    \par\smallskip
+    \Note Western years does not support kansuji-by-reading
+    and thus |k| will be applied instead
+    (\Ja{二〇一八}, not \Ja{二千十八}).
+  \item |J|\Means
+    variant of |j| where ``ten's multiple'' kanji characters
+    (\Ja{廿} and \Ja{卅}) are employed (\Ja{28} $\to$ \Ja{廿八});
+  \item |o|\Means
+    uses \emph{imyo} (\Ja{異名}) for months%
+    \footnote{Don't ask me if this form is ever used in LaTeX document!}
+    (\Ja{8\+月} $\to$ \Ja{葉月}).
+  \end{itemize}
+
+  \Note This command is supported only on {\pdfLaTeX}, {\XeLaTeX},
+  {\LuaLaTeX}, {\upLaTeX}, {Ap\LaTeX} and recent versions of {\pLaTeX}.
+  On other engines it simply falls back to |\warekidate|.
+
+\item |\WarekiIfCustomDateAvailable{|\Meta{true}|}{|\Meta{false}|}|\Means
+  Tests if the command |\warekicustomdate| is
+  supported on the engine in use.
+\end{itemize}
+
+%-------------------
+\subsection{Current date}
+
+These commands always represent the current date,
+and are not affected by |\warekisetdate| (or |\warekisettoday|).
+
+\begin{itemize}
+\item |\warekitoday|\Means
+  The |\warekidate| form of the current date.
+\item |\warekikanjitoday|\Means
+  The |\warekikanjidate| form.
+\item |\warekijkanjitoday|\Means
+  The |\warekijkanjidate| form.
+\end{itemize}
+
+%-------------------
+\subsection{Inter-alphabet-kanji glues}
+
+In quality Japanese typesetting, a thin space
+(\emph{shibuaki}; \Ja{四分空き}) must be inserted
+between an alphabet letter and a kanji letter.
+This package by default inserts a command
+suitable for the most prevalent Japanese-typesetting environment
+for the engine in use.
+
+\begin{itemize}
+\item On {\pLaTeX}, {\upLaTeX} and {Ap\LaTeX}:
+  Nothing is inserted,
+  since the engine can automatically insert shibuaki spaces.
+\item On {\LuaLaTeX} and {\XeLaTeX}:
+  Nothing is inserted,
+  on the assumption that the package for Japanese typesetting
+  (such as \Pkg{\LuaTeX-ja} and \Pkg{xeCJK})
+  will automatically insert shibuaki spaces.
+\item On {\LaTeX} and {\pdfLaTeX}:
+  |~| is inserted,
+  on the assumption that the \Pkg{CJK} package is employed
+  and |\CJKtilde| is in effect.
+\end{itemize}
+
+On the engines with {\eTeX} extension,
+the command for shibuaki can be changed with the following commands:
+\begin{itemize}
+\item |\WarekiUseCustomInterGlue{|\Meta{text}|}|\Means
+  Uses \Meta{text} for making shibuaki spaces.
+\item |\WarekiUseNormalInterGlue|\Means
+  Reverts |\WarekiUseCustomInterGlue|
+  and uses the normal setting.
+\end{itemize}
+
+%===========================================================
+\section{Support for the kaigen planned in 2019}
+\label{sec:Kaigen}
+
+In Japan a kaigen (due to the abdication of the Emperor)
+is planned on 2019/05/01,
+but the new gengo is not yet announced.
+Thus in the current version of the package,
+the date of the day or later is not supported
+(the Western year will be printed instead).
+
+This package will be updated to support the new gengo
+and uploaded to CTAN,
+as soon as the new gengo is announced.
+
+%-------------------
+\subsection{The \texttt{download2019} option}
+\label{ssec:download2019}
+
+Instead of manually downloading the new version from CTAN,
+you can get the support for the new gengo
+with a single run of {\LaTeX}
+(of course after the annoucement of the gengo):
+when you compile a document which loads this package
+with |download2019| option using {\LuaLaTeX}
+with \emph{full shell escape} enabled%
+\footnote{In most system, full shell escape is enabled
+  by \texttt{-shell-escape} option.},
+then the run will download an additional file
+from the package's GitHub repository
+and install it into the user's TEXMF tree.
+
+In short: make the following dummy%
+\footnote{Using the dummy document with minimal content
+could reduce the risk of using full shell escape,
+but you need to trust me, of course.}
+document file (named |dummy.tex|)
+\begin{quote}\small\begin{verbatim}
+\documentclass{article}
+\usepackage[download2019]{bxwareki}
+\stop
+\end{verbatim}\end{quote}
+and run |lualatex -shell-escape dummy|.
+After that, the new gengo will be supported
+on any engine, without shell escape.
+
+%===========================================================
+\section{Notices for {\TeX} programmers}
+\label{sec:Allez}
+
+\begin{itemize}
+\item On the engines with native kanji/Unicode support
+  (\Ie~{\LuaLaTeX}, {\XeLaTeX}, {\pLaTeX}, {\upLaTeX}, and {Ap\LaTeX}),
+  the content (one-level expansion) of |\wareki...date|
+  (except |\warekicustomdate|) and |\wareki...today|
+  is a simple string of character tokens,
+  unless |\WarekiUseCustomInterGlue| is in effect.
+  The same holds for {\LaTeX} and {\pdfLaTeX},
+  except that each kanji character is
+  represented by the sequence of activated byte tokens
+  and |~| is inserted as shibuaki spaces.
+\item On the engines with native kanji/Unicode support,
+  |\warekicustomdate| fully expands to a simple string
+  of character tokens
+  (again without |\WarekiUseCustomInterGlue|),
+  and the situation on {\LaTeX} and {\pdfLaTeX}
+  is parallel to that described at the previous item.
+\item The use of |\WarekiUseCustomInterGlue|
+  does not break the full expandability
+  of |\wareki...date| and |\wareki...today|
+  on the engines with native kanji/Unicode support.
+\end{itemize}
+
+%===========================================================
+\end{document}


Property changes on: trunk/Master/texmf-dist/doc/latex/bxwareki/bxwareki.tex
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Modified: trunk/Master/texmf-dist/tex/latex/bxwareki/bxwareki-cd.def
===================================================================
--- trunk/Master/texmf-dist/tex/latex/bxwareki/bxwareki-cd.def	2018-10-02 01:04:41 UTC (rev 48798)
+++ trunk/Master/texmf-dist/tex/latex/bxwareki/bxwareki-cd.def	2018-10-02 01:05:54 UTC (rev 48799)
@@ -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 at epTeXinputencoding@ok
   \epTeXinputencoding utf8
 \fi
 
+%% branch for download mode
+\ifbxwy at download
+  \long\def\bxwy at next#1\bxwy at download{}
+  \expandafter\bxwy at next
+\fi
+
 %--------------------------------------- helpers
 
 %% \bxwy at burst-`>...
@@ -121,6 +127,283 @@
 \def\bxwy at cdpo@@o#1#2#3{#1#2o}
 \def\bxwy at cdpo@@O#1#2#3{#1#2O}
 
+%--------------------------------------- special procedure for LuaTeX
+\ifx\bxwy at new@gengo\@empty \ifnum\bxwy at 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 at new@gengo{\the\toks@}
+\endgroup
+
+\fi\fi
 %--------------------------------------- all done
 \endinput
+%=======================================
+\bxwy at 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 at next=\count@
+
 %% EOF

Modified: trunk/Master/texmf-dist/tex/latex/bxwareki/bxwareki.sty
===================================================================
--- trunk/Master/texmf-dist/tex/latex/bxwareki/bxwareki.sty	2018-10-02 01:04:41 UTC (rev 48798)
+++ trunk/Master/texmf-dist/tex/latex/bxwareki/bxwareki.sty	2018-10-02 01:05:54 UTC (rev 48799)
@@ -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 at pkgname{bxwareki}
@@ -87,6 +87,38 @@
     \expandafter\mathchardef\csname c@#1\endcsname#2\relax}
 \fi
 
+%--------------------------------------- options
+
+%% variables
+\newif\ifbxwy at download
+
+%% 'download'
+\DeclareOption{download2019}{%
+  \bxwy at downloadtrue}
+% dispatch
+\ProcessOptions\relax
+
+%--------------------------------------- download mode
+
+\ifbxwy at download
+  \chardef\bxwy at next=\tw@
+  \ifnum\bxwy at engine=5
+    \input{bxwareki-cd.def}
+  \fi
+  \ifcase\bxwy at next
+    \PackageInfo\bxwy at pkgname
+     {The installation of 'bxwareki2019.def' succeeded\@gobble}
+  \or
+    \PackageWarningNoLine\bxwy at pkgname
+     {The installation of 'bxwareki2019.def' failed}
+  \else
+    \PackageWarningNoLine\bxwy at pkgname
+     {Download mode is not available here and thus\MessageBreak
+      the option 'download2019' is ignored}
+  \fi
+\fi
+\bxwy at 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 at new@gengo\@empty
 
+%% \bxwy at new@gengo at initial
+% The initial Latin letter for the new gengo.
+\let\bxwy at new@gengo at initial\@empty
+
 %% read the file
 \endlinechar\m at ne
 \openin\@inputcheck=\bxwy at new@gengo at file\relax
@@ -296,10 +332,19 @@
     \else
       \edef\bxwy at next{\noexpand\bxwy at new@gengo{\bxwy at tmpa}}
       \expandafter\bxwy at add@jchar\bxwy at next
+      \read\@inputcheck to\bxwy at tmpa
+      \ifeof\@inputcheck
+        \global\let\bxwy at new@gengo\@empty
+      \else
+        \let\bxwy at new@gengo at initial\bxwy at tmpa
+      \fi
     \fi
   \fi
 \fi
 \endlinechar=13 %
+\def\bxwy at next#1>#2#3#4\bxwy at end{%
+  \ifx#3\relax\else \let\bxwy at new@gengo at initial\@empty \fi}
+\expandafter\bxwy at next\meaning\bxwy at new@gengo at initial\relax\relax\bxwy at end
 
 %--------------------------------------- calculate wareki year
 
@@ -341,7 +386,7 @@
 % Sets \bxwy at g@gengo and \bxwy at g@year.
 \def\bxwy at calc@wareki at year{%
   \@tempcnta=\the\year\two at digits\month\two at digits\day\relax
-  \let\bxwy at tmpb\@empty \@tempcntb\year
+  \let\bxwy at tmpa\@empty \let\bxwy at tmpb\@empty \@tempcntb\year
   \ifnum\@tempcnta<18730101 % ancient times (non-Gregorian)
   \else\ifnum\@tempcnta<19120730 % meiji era
     \let\bxwy at tmpb\bxwy@@meiji
@@ -366,6 +411,16 @@
   \xdef\bxwy at g@year{\the\@tempcntb}%
   \xdef\bxwy at g@date{{\the\year}{\the\month}{\the\day}}}
 
+%% \bxwy at gengo@initial at of\CS
+\def\bxwy at gengo@initial at 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 at new@gengo \bxwy at new@gengo at initial
+  \fi\fi\fi\fi\fi\fi}
+
 %--------------------------------------- render wareki date
 
 %% \bxwy at render@for\CSIdate\CSIgengo\CSIyear
@@ -424,7 +479,8 @@
 %% \bxwy at render@date
 \def\bxwy at render@date{%
   \bxwy at render@for\bxwy at date\warekigengo\c at warekiyear
-      \warekiyear\warekidate\warekikanjidate\warekijkanjidate}
+      \warekiyear\warekidate\warekikanjidate\warekijkanjidate
+  \edef\warekigengoinitial{\bxwy at gengo@initial at of\warekigengo}}
 %% \bxwy at render@today
 \def\bxwy at render@today{%
   \bxwy at render@for\bxwy at today@date\bxwy at today@gengo\bxwy at today@year
@@ -447,6 +503,8 @@
 \bxwy at 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



More information about the tex-live-commits mailing list