% lltjlisting.sty: modified from jlisting.sty (by Thor) for
% LuaTeX-ja. 

\NeedsTeXFormat{LaTeX2e}
\def\filedate{2006/02/20}
\def\fileversion{0.2}
\ProvidesPackage{lltjlisting}[\filedate\space\fileversion\space(Thor)]
%
\newcount\lst@nextchar
\let\lst@@ProcessSpace\lst@ProcessSpace
\def\lst@ProcessSpace#1{%
   \lst@check@chartype{#1}%
      \lst@@ProcessSpace
      \lst@whitespacetrue}
\let\lst@@ProcessLetter\lst@ProcessLetter
\def\lst@ProcessLetter#1#2{%
   \lst@check@chartype{#2}%
      {\lst@@ProcessLetter{#1}}%
      \relax}
\let\lst@@ProcessDigit\lst@ProcessDigit
\def\lst@ProcessDigit#1#2{%
   \lst@check@chartype{#2}%
      {\lst@@ProcessDigit{#1}}%
      \relax}
\let\lst@@ProcessOther\lst@ProcessOther
\def\lst@ProcessOther#1#2{%
   \lst@check@chartype{#2}%
      {\lst@@ProcessOther{#1}}%
      \relax}
\let\lst@@ProcessTabulator\lst@ProcessTabulator
\def\lst@ProcessTabulator#1{%
   \lst@check@chartype{#1}%
      \lst@@ProcessTabulator
      \relax}
\def\lst@check@chartype#1#2#3{%
   \edef\@tempa{\lst@nextchar=`\string#1\relax}%
   \afterassignment\remove@to@nnil
   \@tempa\@nnil
   #2%
   \ifnum\lst@nextchar<\@cclvi
      #3%
   \else
      \lst@ifletter \else \lst@OutputOther \fi
      \lst@whitespacefalse
      \expandafter\lst@AppendJchar
   \fi
   #1}
\def\lst@AppendJchar#1#2{%
   \lst@check@chartype{#2}%
      {\advance\lst@length\@ne\lst@Append{#1}}%
      \relax}
\def\lst@check@chartype@BOL#1{%
   \edef\@tempa{\lst@nextchar=`\string#1\relax}%
   \afterassignment\remove@to@nnil
   \@tempa\@nnil
   \ifnum\lst@nextchar<\@cclvi\else
      \lst@whitespacefalse
      \expandafter\lst@AppendJchar
   \fi
   #1}
\def\lst@InputListing#1{%
   \begingroup
      \lsthk@PreSet \gdef\lst@intname{#1}%
      \expandafter\lstset\expandafter{\lst@set}%
      \lsthk@DisplayStyle
      \catcode\active=\active
      \lst@Init\relax \let\lst@gobble\z@
      \lst@SkipToFirst
      \lst@ifprint \def\lst@next{\lst@get@filecontents{#1}}%
      \else        \let\lst@next\@empty
      \fi
      \catcode"FFFFF=12%"
      \lst@next
      \lst@DeInit
   \endgroup}
\newread\lst@inputfile
\def\lst@get@filecontents#1{%
   \let\lst@filecontents\@empty
   \openin\lst@inputfile=#1\relax
   \let\@lst@get@filecontents@prevline\relax
   \lst@get@filecontents@loop
   \closein\lst@inputfile
   \lst@filecontents\empty}
\def\lst@get@filecontents@loop{%
   \read\lst@inputfile to\@lst@get@filecontents@currline
   \ifx\@lst@get@filecontents@prevline\relax\else
      \expandafter\expandafter\expandafter\def
      \expandafter\expandafter\expandafter\lst@filecontents
      \expandafter\expandafter\expandafter{%
         \expandafter\lst@filecontents\@lst@get@filecontents@prevline}%
   \fi
   \let\@lst@get@filecontents@prevline\@lst@get@filecontents@currline
   \ifeof\lst@inputfile\else
      \expandafter\lst@get@filecontents@loop
   \fi}
%%% [この処理も，相当強引です．]
\def\lst@BOLGobble{%
   \ifnum\lst@gobble>\z@
      \@tempcnta\lst@gobble\relax
      \expandafter\lst@BOLGobble@
   \else
      \expandafter\lst@check@chartype@BOL
   \fi}
\def\lst@BOLGobble@#1{%
   \let\lst@next#1%
   \ifx \lst@next\relax\else
   \ifx \lst@next\lst@MProcessListing\else
   \ifx \lst@next\lst@ProcessFormFeed\else
   \ifx \lst@next\lstenv@backslash
      \let\lst@next\lstenv@BOLGobble@@
   \else
      \let\lst@next\lst@BOLGobble@@
      \ifx #1\lst@ProcessTabulator
         \advance\@tempcnta-\lst@tabsize\relax
         \ifnum\@tempcnta<\z@
            \lst@length-\@tempcnta \lst@PreGotoTabStop
         \fi
      \else
         \edef\@tempa{\lst@nextchar=`\string#1\relax}%
         \@tempa
         \ifnum\lst@nextchar<\@cclvi\else
            \advance\@tempcnta\m@ne
         \fi
         \advance\@tempcnta\m@ne
      \fi
   \fi \fi \fi \fi
   \lst@next}
\def\lst@BOLGobble@@{%
   \ifnum\@tempcnta>\z@
      \expandafter\lst@BOLGobble@
   \else
      \expandafter\lst@check@chartype@BOL
   \fi
}

%
%    \begin{修正事項}{1.3}
% ちょっとした修正
\gdef\lst@breakProcessOther#1{\lst@ProcessOther#1}
% ソースコード目次における文字と番号の空き
\let \l@lstlisting = \l@figure
% キャプションとソースコード目次に対する日本語対応
\def\lstlistingname{ソースコード}
\def\lstlistlistingname{ソースコード目次}
%    \end{修正事項}


% Changes for LuaTeX-ja:
% 1. \char"FFFFF は通常行末用コメント文字として使われる．
%    だが，それはソースコードの組版には邪魔ものとなる．
%\lst@AddToHook{Init}{\catcode"FFFFF=9 }
%\lst@AddToHook{DeInit}{\catcode"FFFFF=14 }
%\lst@Def{1048575}{}

% 2. listing な環境の処理中に \DeclareFontShape の (s)sub が実行されると，なぜか
%        ! Use of set@size@funct@args@ doesn't match its definition.
%    のエラーが出る．
%    \ifnot@nil #1-> \def\reserved@a{#1}... の \reserved@a=\set@size@funct@args@
%    がなぜか実行される？
%    ad hoc な対策として事前に必要な (s)sub は実行しておくことにする．
\lst@AddToHook{Init}{\begingroup\itshape\bfseries\upshape\endgroup}
\endinput
