Debian Codegraph @

texmf-dist/tex/generic/ctex/ctxdocstrip.tex

raw
1 %%
2 %% File ctxdocstrip.tex
3 %%
4 %% Copyright (C) 2016--2020
5 %% CTEX.ORG and any individual authors listed in the documentation.
6 %%---------------------------------------------------------------------
7 %%
8 %% This work may be distributed and/or modified under the
9 %% conditions of the LaTeX Project Public License, either
10 %% version 1.3c of this license or (at your option) any later
11 %% version. This version of this license is in
12 %% http://www.latex-project.org/lppl/lppl-1-3c.txt
13 %% and the latest version of this license is in
14 %% http://www.latex-project.org/lppl.txt
15 %% and version 1.3 or later is part of all distributions of
16 %% LaTeX version 2005/12/01 or later.
17 %%
18 %% This work has the LPPL maintenance status "maintained".
19 %%
20 %%---------------------------------------------------------------------
21 %%
22 \csname ctxDocstripLoaded\endcsname
23 \let\ctxDocstripLoaded\endinput
24 \input l3docstrip %
25 \edef\ctxResetCatcode{%
26 \catcode\number`\$=\the\catcode`\$\relax
27 \catcode\number`\@=\the\catcode`\@\relax
28 }
29 \makeOther\$
30 \catcode`\@=11\relax
31 \def\plusOption+#1>#2$#3$\endLine{%
32 \maybeMsg{<+#1 . >}%
33 \Evaluate{#1}%
34 \def\ctxCMD{#2}%
35 \def\ctxID{$#3$}%
36 \def\do##1##2##3{%
37 \if1\Expr{##2}%
38 \ctxReadIDFile
39 \StreamPut##1{\inLine}%
40 \fi
41 }%
42 \activefiles
43 }
44 \def\ctxReadIDFile{%
45 \openin\inputcheck=\jobname.id\relax
46 \ifeof\inputcheck\else
47 \read \inputcheck to \inLine
48 \closein\inputcheck
49 \ifx\inLine\empty\else
50 \let\ctxID\inLine
51 \fi
52 \fi
53 \maybeMsg{^^J\ctxID^^J}%
54 \def\inLine{\ctxCMD\ctxID}%
55 }
56 \keepsilent
57 \askforoverwritefalse
58 \declarepreamble\emptypreamble
59 \endpreamble
60 \declarepostamble\emptypostamble
61 \endpostamble
62 \begingroup\expandafter\expandafter\expandafter\endgroup
63 \expandafter\ifx\csname directlua\endcsname\relax
64 \expandafter\ctxResetCatcode\expandafter\endinput
65 \fi
66 \let\OriginalStreamClose\StreamClose
67 \def\ctxStreamClose#1{%
68 \OriginalStreamClose{#1}%
69 \ctxConvFile{#1}%
70 }
71 \def\ctxConvFile#1{%
72 \ifcsname zhconv@\csstring#1\endcsname
73 \ctxConv{\lastnamedcs}%
74 {\begincsname pth@\csstring#1\endcsname}%
75 \fi
76 }
77 \def\ctxLuaFunc{%
78 \directlua{
79 local zhconv = require("ctex-zhconv").conv
80 local scan_arg = token.scan_argument
81 local t = lua.get_functions_table()
82 local id = 233
83 while t[id] do id = id + 1 end
84 t[id] = function ()
85 local enc = scan_arg()
86 local file = scan_arg()
87 return zhconv(enc, file, file)
88 end
89 token.set_lua("ctxConv", id, "global", "protected")
90 }%
91 \global\let\ctxLuaFunc\relax
92 }
93 \def\convfile{%
94 \ifx\@file\file
95 \expandafter\ctxfile\else
96 \expandafter\setconvfile\fi
97 }
98 \def\setconvfile#1#2{%
99 \ctxLuaFunc
100 \Name\def{zhconv@#2}{#1}%
101 \let\StreamClose\ctxStreamClose
102 }
103 \def\ctxfile#1#2{%
104 \setconvfile{#1}{#2}%
105 \file{#2}%
106 }
107 \ctxResetCatcode
108 %%
109 %%
110 %% End of file ctxdocstrip.tex