OSDN Git Service

Merge branch 'master' into kitagawa_test
[luatex-ja/luatexja.git] / src / patches / lltjp-listings.sty
1 %
2 % lltjp-listings.sty
3 %
4 % Modified from jlisting.sty (by Thor) for LuaTeX-ja. 
5 %
6
7 \NeedsTeXFormat{LaTeX2e}
8 \def\filedate{2006/02/20}
9 \def\fileversion{0.2}
10 \ProvidesPackage{lltjp-listings}[\filedate\space\fileversion\space(Thor)]
11 \RequirePackage{listings}
12 \newcount\lst@nextchar
13 \let\lst@@ProcessSpace\lst@ProcessSpace
14 \def\lst@ProcessSpace#1{%
15    \lst@check@chartype{#1}%
16       \lst@@ProcessSpace
17       \lst@whitespacetrue}
18 \let\lst@@ProcessLetter\lst@ProcessLetter
19 \def\lst@ProcessLetter#1#2{%
20    \lst@check@chartype{#2}%
21       {\lst@@ProcessLetter{#1}}%
22       \relax}
23 \let\lst@@ProcessDigit\lst@ProcessDigit
24 \def\lst@ProcessDigit#1#2{%
25    \lst@check@chartype{#2}%
26       {\lst@@ProcessDigit{#1}}%
27       \relax}
28 \let\lst@@ProcessOther\lst@ProcessOther
29 \def\lst@ProcessOther#1#2{%
30    \lst@check@chartype{#2}%
31       {\lst@@ProcessOther{#1}}%
32       \relax}
33 \let\lst@@ProcessTabulator\lst@ProcessTabulator
34 \def\lst@ProcessTabulator#1{%
35    \lst@check@chartype{#1}%
36       \lst@@ProcessTabulator
37       \relax}
38 \def\lst@check@chartype#1#2#3{%
39    \edef\@tempa{\lst@nextchar=`\string#1\relax}%
40    \afterassignment\remove@to@nnil
41    \@tempa\@nnil
42    #2%
43    \ifnum\lst@nextchar<\@cclvi
44       #3%
45    \else
46       \lst@ifletter \else \lst@OutputOther \fi
47       \lst@whitespacefalse
48       \expandafter\lst@AppendJchar
49    \fi
50    #1}
51 \def\lst@AppendJchar#1#2{%
52    \lst@check@chartype{#2}%
53       {\advance\lst@length\@ne\lst@Append{#1}}%
54       \relax}
55 \def\lst@check@chartype@BOL#1{%
56    \edef\@tempa{\lst@nextchar=`\string#1\relax}%
57    \afterassignment\remove@to@nnil
58    \@tempa\@nnil
59    \ifnum\lst@nextchar<\@cclvi\else
60       \lst@whitespacefalse
61       \expandafter\lst@AppendJchar
62    \fi
63    #1}
64 \def\lst@InputListing#1{%
65    \begingroup
66       \lsthk@PreSet \gdef\lst@intname{#1}%
67       \expandafter\lstset\expandafter{\lst@set}%
68       \lsthk@DisplayStyle
69       \catcode\active=\active
70       \lst@Init\relax \let\lst@gobble\z@
71       \lst@SkipToFirst
72       \lst@ifprint \def\lst@next{\lst@get@filecontents{#1}}%
73       \else        \let\lst@next\@empty
74       \fi
75       \catcode"FFFFF=12%"
76       \lst@next
77       \lst@DeInit
78    \endgroup}
79 \newread\lst@inputfile
80 \def\lst@get@filecontents#1{%
81    \let\lst@filecontents\@empty
82    \openin\lst@inputfile=#1\relax
83    \let\@lst@get@filecontents@prevline\relax
84    \lst@get@filecontents@loop
85    \closein\lst@inputfile
86    \lst@filecontents\empty}
87 \def\lst@get@filecontents@loop{%
88    \read\lst@inputfile to\@lst@get@filecontents@currline
89    \ifx\@lst@get@filecontents@prevline\relax\else
90       \expandafter\expandafter\expandafter\def
91       \expandafter\expandafter\expandafter\lst@filecontents
92       \expandafter\expandafter\expandafter{%
93          \expandafter\lst@filecontents\@lst@get@filecontents@prevline}%
94    \fi
95    \let\@lst@get@filecontents@prevline\@lst@get@filecontents@currline
96    \ifeof\lst@inputfile\else
97       \expandafter\lst@get@filecontents@loop
98    \fi}
99 %%% [この処理も,相当強引です.]
100 \def\lst@BOLGobble{%
101    \ifnum\lst@gobble>\z@
102       \@tempcnta\lst@gobble\relax
103       \expandafter\lst@BOLGobble@
104    \else
105       \expandafter\lst@check@chartype@BOL
106    \fi}
107 \def\lst@BOLGobble@#1{%
108    \let\lst@next#1%
109    \ifx \lst@next\relax\else
110    \ifx \lst@next\lst@MProcessListing\else
111    \ifx \lst@next\lst@ProcessFormFeed\else
112    \ifx \lst@next\lstenv@backslash
113       \let\lst@next\lstenv@BOLGobble@@
114    \else
115       \let\lst@next\lst@BOLGobble@@
116       \ifx #1\lst@ProcessTabulator
117          \advance\@tempcnta-\lst@tabsize\relax
118          \ifnum\@tempcnta<\z@
119             \lst@length-\@tempcnta \lst@PreGotoTabStop
120          \fi
121       \else
122          \edef\@tempa{\lst@nextchar=`\string#1\relax}%
123          \@tempa
124          \ifnum\lst@nextchar<\@cclvi\else
125             \advance\@tempcnta\m@ne
126          \fi
127          \advance\@tempcnta\m@ne
128       \fi
129    \fi \fi \fi \fi
130    \lst@next}
131 \def\lst@BOLGobble@@{%
132    \ifnum\@tempcnta>\z@
133       \expandafter\lst@BOLGobble@
134    \else
135       \expandafter\lst@check@chartype@BOL
136    \fi
137 }
138
139 %
140 %    \begin{修正事項}{1.3}
141 % ちょっとした修正
142 \gdef\lst@breakProcessOther#1{\lst@ProcessOther#1}
143 % ソースコード目次における文字と番号の空き
144 \let \l@lstlisting = \l@figure
145 % キャプションとソースコード目次に対する日本語対応
146 \def\lstlistingname{ソースコード}
147 \def\lstlistlistingname{ソースコード目次}
148 %    \end{修正事項}
149
150
151 % Changes for LuaTeX-ja:
152 % 1. \char"FFFFF は通常行末用コメント文字として使われる.
153 %    だが,それはソースコードの組版には邪魔ものとなる.
154 %\lst@AddToHook{Init}{\catcode"FFFFF=9 }
155 %\lst@AddToHook{DeInit}{\catcode"FFFFF=14 }
156 %\lst@Def{1048575}{}
157
158 % 2. listing な環境の処理中に \DeclareFontShape の (s)sub が実行されると,なぜか
159 %        ! Use of set@size@funct@args@ doesn't match its definition.
160 %    のエラーが出る.
161 %    \ifnot@nil #1-> \def\reserved@a{#1}... の \reserved@a=\set@size@funct@args@
162 %    がなぜか実行される?
163 %    ad hoc な対策として事前に必要な (s)sub は実行しておくことにする.
164 \lst@AddToHook{Init}{\begingroup\itshape\bfseries\upshape\endgroup}
165 \endinput