\usepackage{keyval}
\@primitives{listings}
%%%%%%%%%%% interface keyval
\def\lst@define@key#1#2{\define@key{lst}{#1}{\@funcall{#2}{##1}}}
\newenvironment{lst@protect}
  {\@clearstyle\def\%{\@print{\%}}%
   \def\#{\@print{\#}}%
   \def\${\@print{\$}}%
   \def\{{\@print{\{}}%
   \def\}{\@print{\}}}%
   \def\_{\@print{\_}}%
   \def\&{\@print{\&}}}
  {}
\def\lst@define@key@opt#1#2#3{\define@key{lst}{#1}[#3]
  {\@callopt{#2}{\begin{lst@protect}##1\end{lst@protect}}}}
%%%%%%%%%%%
% Helpers %
%%%%%%%%%%%
\def\lstinfo#1{\typeout{LST, #1}}
\def\lst@iter#1#2{\@iter#1,{#2}}
%For getting rid of two (optional) levels of braces
\def\lst@eat@again#1XXX#2{\@callsubst{#2}{#1\@empty\@empty\@empty\@empty\@empty}}
\def\lst@eat@key#1XXX#2{\@callsubst{\lst@eat@again}{#1XXX#2}}
%%%%%%%% Interface with keyval
\def\lstset#1{\@setkeys{lst}{#1}}
%%%%%%%% Def if not empty
\newcommand{\lst@defne}[2]{\ifx#1\@empty\def#1{#2}\fi}
%%%%%%%%%%%%
% Hooks    %
%%%%%%%%%%%%
\newcommand{\lst@Hook}[1]
  {\newtokens{\csname lsthk@#1\endcsname}}
\newcommand{\lst@ResetHook}[1]
  {\resettokens{\csname lsthk@#1\endcsname}}
\newcommand{\lst@UseHook}[1]
  {\csname lsthk@#1\endcsname}
\newcommand{\lst@AddToHook}[2]
  {\addtokens{\csname lsthk@#1\endcsname}{#2}}
\newcommand{\lst@AddToHookExe}[2]
  {\lst@AddToHook{#1}{#2}#2}
\lst@Hook{EOL}\lst@Hook{InitVarEOL}
\lst@Hook{InitVarBOL}\lst@Hook{EveryLine}
\lst@Hook{PreSet}
\lst@Hook{InitVar}
\lst@Hook{Init}
\lst@Hook{DeInit}
\lst@Hook{SelectCharTable}
\lst@Hook{SetLanguage}
\lst@Hook{AfterSetLanguage}
\lst@AddToHook{SetLanguage}{\lst@ResetHook{AfterSetLanguage}}
\lst@Hook{SetStyle}
\def\lststy@{\lsthk@EmptyStyle}
\lst@Hook{EmptyStyle}
\lst@Hook{EmptyLanguage}
\lst@Hook{InlineUnsave}
%%%%%%%%%%%%
% Keywords %
%%%%%%%%%%%%
\newcommand{\lst@allkeywords}{}
\def\lst@record@kwds#1{\lst@AddTo,{\lst@allkeywords}{\lst@normalize{#1}}}
\newcommand{\lst@allotherkeywords}{}
\def\lst@record@okwds#1{\lst@AddTo,{\lst@allotherkeywords}{\lst@normalize{#1}}}
\newcommand{\lst@alldirectives}{}
\def\lst@record@directives#1{\lst@AddTo,{\lst@alldirectives}{\lst@normalize{#1}}}
\lst@AddToHook{SetLanguage}
  {\@callprim{\lst@delete@kwds}{\{\lst@allkeywords\}}%
  \@callprim{\lst@delete@okwds}{\{\@rawchars{\lst@allotherkeywords}\}}%
  \@callprim{\lst@delete@directives}{\{\lst@alldirectives\}}}
\def\lst@install@kwd#1#2{\def\csname lstk@\lst@normalize{#2}\endcsname{#1}}
\def\lst@install@kwds
  #1#2{%
    \lst@record@kwds{#2}%
    \lst@iter{\lst@install@kwd{#1}}{#2}}
\def\lst@install@directive#1#2{\def\csname lstd@\lst@normalize{#2}\endcsname{#1}}
\def\lst@install@directives
  #1#2{%
    \lst@directivestrue%
    \lst@record@directives{#2}%
    \lst@iter{\lst@install@directive{#1}}{#2}}
\def\lst@install@okwds
  #1#2{%
    \lst@record@okwds{#2}%
    \lst@iter{\lst@install@kwd{#1}}{#2}}
\def\lst@delete@kwd
  #1{\def\csname lstk@\@rawchars{#1}\endcsname{\lst@identifier@style}}
\def\lst@delete@directive
  #1{\def\csname lstd@\@rawchars{#1}\endcsname{}}
\def\lst@delete@okwds#1{\lst@iter{\lst@delete@okwd}{#1}}
\def\lst@delete@kwds#1{\lst@iter{\lst@delete@kwd}{#1}}
\def\lst@delete@directives#1{\lst@iter{\lst@delete@directive}{#1}}
\def\lst@delete@okwd
  #1{\def\csname lstk@\@rawchars{#1}\endcsname{}}
\def\lst@delay@install#1#2{\lst@AddToHook{AfterSetLanguage}{\lst@install@kwds{#1}{#2}}}
\def\lst@delay@delete#1{\lst@AddToHook{AfterSetLanguage}{\lst@delete@kwds{#1}}}
\define@key{lst}{keywords}{\lst@delay@install\lst@kwd@style#1}
\define@key{lst}{morekeywords}{\lst@delay@install\lst@kwd@style#1}
\define@key{lst}{deletekeywords}{\lst@delay@delete#1}
\define@key{lst}{ndkeywords}{\lst@delay@install\lst@ndkwd@style#1}
\define@key{lst}{morendkeywords}{\lst@delay@install\lst@ndkwd@style#1}
\define@key{lst}{deletendkeywords}{\lst@delay@delete#1}
\define@key{lst}{rdkeywords}{\lst@delay@install\lst@rdkwd@style#1}
\define@key{lst}{morerdkeywords}{\lst@delay@install\lst@rdkwd@style#1}
\define@key{lst}{deleterdkeywords}{\lst@delay@delete#1}
%%%%%%%% Other keywords
\def\lst@delay@oinstall#1#2{\lst@AddToHook{AfterSetLanguage}{\lst@install@okwds{#1}{#2}}}
\def\lst@delay@odelete#1{\lst@AddToHook{AfterSetLanguage}{\lst@delete@okwds{#1}}}
\define@key{lst}{otherkeywords}{\lst@delay@oinstall\lst@okwd@style#1}
\define@key{lst}{morekeothersywords}{\lst@delay@oinstall\lst@okwd@style#1}
\define@key{lst}{deleteotherskeywords}{\lst@delay@odelete#1}
%%% Directives
\def\lst@delay@dinstall#1#2{\lst@AddToHook{AfterSetLanguage}{\lst@install@directives{#1}{#2}}}
\def\lst@delay@ddelete#1{\lst@AddToHook{AfterSetLanguage}{\lst@delete@directives{#1}}}
\define@key{lst}{directives}{\lst@delay@dinstall\lst@directive@style#1}
\define@key{lst}{moredirectives}{\lst@delay@dinstall\lst@directive@style#1}
%%%%%%% Styles applied to keywords, strings etc %%%%%%
\define@key{lst}{keywordstyle}{\def\lst@kwd@style##1{#1{##1}}}
\define@key{lst}{ndkeywordstyle}{\def\lst@ndkwd@style##1{#1{##1}}}
\define@key{lst}{rdkeywordstyle}{\def\lst@rdkwd@style##1{#1{##1}}}
\define@key{lst}{otherkeywordstyle}{\def\lst@okwd@style##1{#1{##1}}}
\define@key{lst}{directivestyle}{\def\lst@directive@style##1{#1{##1}}}
\define@key{lst}{identifierstyle}{\def\lst@identifier@style##1{#1{##1}}}
\define@key{lst}{Identifierstyle}{\def\lst@Identifier@style##1{#1{##1}}}
\define@key{lst}{nonkeywordstyle}{\def\lst@identifier@style##1{#1{##1}}}
\define@key{lst}{basicstyle}{\def\lst@basic@style{#1}}
\define@key{lst}{commentstyle}{\def\lst@comment@style{#1}}
\define@key{lst}{stringstyle}{\def\lst@string@style{#1}}
\lst@AddToHook{EmptyStyle}{\let\lst@string@style\@empty}
\lst@AddToHook{EmptyStyle}{\let\lst@comment@style\@empty}
\lst@AddToHook{EmptyStyle}{\let\lst@identifier@style\@empty}
\lst@AddToHook{EmptyStyle}{\let\lst@basic@style\@empty}
\lst@AddToHook{EmptyStyle}{\let\lst@kwd@style\bfseries}
\lst@AddToHook{EmptyStyle}{\def\lst@ndkwd@style{\lst@kwd@style}}
\lst@AddToHook{EmptyStyle}{\def\lst@rdkwd@style{\lst@kwd@style}}
\lst@AddToHook{EmptyStyle}{\def\lst@okwd@style{\lst@kwd@style}}
\lst@AddToHook{EmptyStyle}{\def\lst@directive@style{\lst@kwd@style}}
\lst@AddToHook{EmptyStyle}{\def\lst@directive@style{\lst@kwd@style}}
%%%%%% Emph identifiers
\def\lst@defall#1#2\@empty{\def\csname #1\endcsname{#2}}
\newcommand{\lst@emphstyle@key}[1][1]{\lst@defall{lst@emphstyle#1}}
\lst@AddToHook{EmptyStyle}{\let\csname lst@emphstyle1\endcsname\@empty}
\define@key{lst}{emphstyle}{\@callsubst{\lst@emphstyle@key}{#1\@empty}}
\def\lst@record@class#1#2{%
  \providecommand{\csname lst@allemph@#1\endcsname}{}%
  \lst@AddTo,{\csname lst@allemph@#1\endcsname}{\lst@normalize{#2}}}
\def\lst@delete@class#1{%
  \ifu\csname lst@allemph@#1\endcsname\else
  \@callprim{\lst@delete@kwds}{\{\csname lst@allemph@#1\endcsname\}}\fi}
\newcommand{\lst@moreemph@key}[2][1]
  {\lst@record@class{#1}{#2}%
  \lst@iter{\lst@install@kwd{\csname lst@emphstyle#1\endcsname}}{#2}}
\define@key{lst}{moreemph}{\@callsubst{\lst@moreemph@key}{#1}}
\newcommand{\lst@deleteemph@key}[2][1]
  {\lst@iter{\lst@delete@kwd}{#2}}
\define@key{lst}{deleteemph}{\@callsubst{\lst@deleteemph@key}{#1}}
\newcommand{\lst@emph@key}[2][1]
  {\lst@delete@class{#1}%  
  \lst@record@class{#1}{#2}%
  \lst@iter{\lst@install@kwd{\csname lst@emphstyle#1\endcsname}}{#2}}
\define@key{lst}{emph}{\@callsubst{\lst@emph@key}{#1}}
%%%%%% Style definitions
\define@key{lst}{style}[{}]{\lsthk@SetStyle\csname lst@sty#1\endcsname}
\newcommand{\lstdefinestyle}[2]
  {\def\csname lst@sty#1\endcsname{\lstset{#2}}}
%%%%%% Language definitions
\newcommand{\lst@define@dd}[2][]{\newcommand{\csname lstdd@#2\endcsname}{#1}}
\newcommand{\lst@mklang}[2][]
  {\ifthenelse{\equal{#1}{}}
    {lstlang@#2@\csname lstdd@#2\endcsname}
    {lstlang@#2@#1}}
\newcommand{\lst@language@key}[2][]
  {\lst@UseHook{SetLanguage}%
  \csname\lst@mklang[#1]{#2}\endcsname%
  \lst@UseHook{AfterSetLanguage}}
\lst@define@key@opt{language}{\lst@language@key}{}
\newcommand{\lst@checkdd}[2]
  {\@ifundefined{lstdd@#1}{\lst@define@dd[#2]{#1}}{}}
\newcommand{\lst@definelanguage@}[3]
  {\lst@checkdd{#1}{#2}\def\csname\lst@mklang[#2]{#1}\endcsname{\lstset{#3}}}
\newcommand{\lst@derivelanguage@}[5]
  {\lst@checkdd{#1}{#2}%
  \def\csname\lst@mklang[#2]{#1}\endcsname{\csname\lst@mklang[#4]{#3}\endcsname
    \lst@UseHook{AfterSetLanguage}\lst@ResetHook{AfterSetLanguage}%
    \lstset{#5}}}
\lst@define@key@opt{defaultdialect}{\lst@define@dd}{}
%%%%%%% Frames
\def\lst@bgcolor{}
\lst@AddToHook{InitVar}
  {\ifx\lst@bgcolor\@empty%
   \def\@open@lstbox{\begin{flushleft}\ttfamily}\def\@close@lstbox{\end{flushleft}}%
   \else
   \def\@open@lstbox
      {\begin{Tabular}[bgcolor=\lst@bgcolor]{l}\ttfamily}%
   \def\@close@lstbox{\end{Tabular}}%
   \fi
   \ifhtml\else
   \def\@open@lstbox{\begin{flushleft}\ttfamily}\def\@close@lstbox{\end{flushleft}}\fi}
\newcommand{\lst@define@bgcolor}[2][!*!]
  {\def\lst@tmp{#2}%
  \ifx\lst@tmp\@empty\let\lst@bgcolor\@empty
  \else\def\lst@bgcolor{\@getcolor[#1]{#2}}\fi}
\lst@define@key@opt{backgroundcolor}{\lst@define@bgcolor}{}
%%%%%%% Indentation
\define@key{lst}{indent}[1]{\def\lst@doindent{\hspace{#1}}}
\newcommand{\lst@doindent}{}
%%%%%%% Lines
\newcounter{lstlabel}
\lst@AddToHook{InitVar}{\let\@currentlabel\thelstlabel}
\newcommand{\lst@saved@lastline}
  {\@ifundefined{lst@intname}{}
    {\@ifundefined{thelst@saved@\lst@intname}
      {0}
      {\value{lst@saved@\lst@intname}}}}
\lst@AddToHook{PreSet}
  {\@ifundefined{lst@intname}{\def\lst@firstline{1}}
  {\@ifundefined{thelst@saved@\lst@intname}{\def\lst@firstline{1}}
  {\def\lst@firstline{\csname thelst@saved@\lst@intname\endcsname+1}}}}
\define@key{lst}{firstlabel}{\def\lst@firstline{#1}}
\define@key{lst}{advancelabel}{\def\lst@firstline{\lst@saved@lastline+#1+1}}
\lst@AddToHook{Init}{\setcounter{lstlabel}{\lst@firstline-1}}
\lst@AddToHook{DeInit}
  {\@ifundefined{lst@intname}{}
     {\@ifundefined{thelst@saved@\lst@intname}
       {\newcounter{lst@saved@\lst@intname}%
       \gdef\csname thelst@saved@\lst@intname\endcsname{\arabic{lst@saved@\lst@intname}}}
       {}%
     \setcounter{lst@saved@\lst@intname}{\value{lstlabel}}}}
\define@key{lst}{labelstyle}{\def\lst@label@style##1{{#1{##1}}}}
\newcommand{\lst@label@style}[1]{#1}
\define@key{lst}{labelstep}{\def\lst@labelstep{#1}}
\lst@AddToHook{InlineUnsave}{\def\lst@labelstep{0}}
\lst@AddToHookExe{EmptyStyle}{\def\lst@labelstep{0}}
\define@key{lst}{labelsep}{\def{\lst@labelsep}{\hspace{#1}}}
\newcommand{\lst@labelsep}{\hspace{1em}}
\newcommand{\lst@pad}[1]{\@pad{~}{4}{#1}}
\newcommand{\lst@linenumber@}[1]
  {\lst@label@style{\lst@pad{#1}}\lst@labelsep}
\newcommand{\lst@linenumber}
  {\ifthenelse{\lst@labelstep=0}
     {}
     {\ifthenelse
       {0=\value{lstlabel}-\(\value{lstlabel}/\lst@labelstep\)*\lst@labelstep}
       {\lst@linenumber@{\thelstlabel}}
       {\lst@linenumber@{}}}}
\lst@AddToHook{InitVarEOL}{\stepcounter{lstlabel}}
\newsavebox{\@prevlines}
\newsavebox{\@curline}
\newcommand{\lst@forget@lastline}
{\sbox{\@curline}{}\setcounter{lst@spaces}{0}\addtocounter{lstlabel}{-1}}
\newcommand{\@NewLine@}
{\usebox{\@prevlines}\usebox{\@curline}\lst@spaces%
\sbox{\@prevlines}{}\sbox{\@curline}{}\global\let\@NewLine\lst@spaces}
\lst@AddToHook{EveryLine}{\setcounter{lst@spaces}{0}%
\sbox{\@prevlines}{\usebox{\@prevlines}\usebox{\@curline}}%
\sbox{\@curline}{\@br\@rawchars{\lst@doindent}\lst@linenumber}%
\global\let\@NewLine\@NewLine@}
\lst@AddToHook{Init}{\sbox{\@prevlines}{}\sbox{\@curline}{}\global\let\@NewLine\lst@spaces}
%%%%%% TeX escapes
\define@key{lst}{texcl}[true]{\def\lst@texcl{#1}}
\setboolean{lst@texcl}{false}
\lst@AddToHook{Init}
  {\@ifundefined{lst@texcl}{}
     {\setboolean{lst@texcl}{\lst@boolean{\lst@texcl}}}}
\lst@AddToHook{DeInit}{\setboolean{lst@texcl}{false}}
\define@key{lst}{mathescape}[true]{\def\lst@mathescape{#1}}
\setboolean{lst@mathescape}{false}
\lst@AddToHook{Init}
  {\@ifundefined{lst@mathescape}{}
     {\setboolean{lst@mathescape}{\lst@boolean{\lst@mathescape}}}}
\lst@AddToHook{DeInit}{\setboolean{lst@mathescape}{false}}
\def\lst@BET{}\def\lst@EET{}
\newcommand{\lst@Esc@key}[2]
  {\def\lst@BET{\@rawchars{#1}}\def\lst@EET{\@rawchars{#2}}}
\define@key{lst}{escapeinside}{\@callsubst{\lst@Esc@key}{#1{}}}
\define@key{lst}{escapechar}[{}]{\lst@Esc@key#1#1}
\def\lst@escapebegin{}
\define@key{lst}{escapebegin}[]{\def\lst@escapebegin{#1}}
\def\lst@escapeend{}
\define@key{lst}{escapeend}[]{\def\lst@escapeend{#1}}
%%%%%% Ignore input
\newcommand{\lst@gobble}{0}
\define@key{lst}{gobble}{\def\lst@gobble{#1}}
\newcommand{\lst@first}{1}
\newcommand{\lst@last}{9999}
\define@key{lst}{first}{\def\lst@first{#1}}
\define@key{lst}{last}{\def\lst@last{#1}}
% print key
\define@key{lst}{print}[true]{\def\lst@print{#1}}
\setboolean{lst@print}{true}
\lst@AddToHook{Init}
  {\@ifundefined{lst@print}{}
     {\setboolean{lst@print}{\lst@boolean{\lst@print}}}}
\lst@AddToHook{DeInit}{\setboolean{lst@print}{true}}
% showlines
\define@key{lst}{showlines}[true]{\def\lst@showlines{#1}}
\setboolean{lst@showlines}{false}
\lst@AddToHook{Init}
  {\@ifundefined{lst@showlines}{}
     {\setboolean{lst@showlines}{\lst@boolean{\lst@showlines}}}}
\lst@AddToHook{DeInit}{\setboolean{lst@showlines}{false}}
%%%%%%% Strings
\lst@Hook{String}
\lst@AddToHook{Init}{\lst@UseHook{String}}
\lst@AddToHook{SetLanguage}{\lst@ResetHook{String}}
\newcommand{\lst@stringizer@key@add}[2][]
  {\lst@AddToHook{String}{\lst@def@stringizer{#1}{#2}}}
\newcommand{\lst@stringizer@key}[2][]
  {\lst@ResetHook{String}\lst@AddToHook{String}{\lst@def@stringizer{#1}{#2}}}
\newcommand{\lst@stringizer@key@delete}[2][]{\lst@ResetHook{String}}
\lst@define@key@opt{stringizer}{\lst@stringizer@key}{}
\lst@define@key@opt{string}{\lst@stringizer@key}{}
\lst@define@key@opt{morestring}{\lst@stringizer@key@add}{}
\lst@define@key@opt{deletestring}{\lst@stringizer@key@delete}{}
% stringspaces
\define@key{lst}{stringspaces}[true]{\def\lst@stringspaces{#1}}
\setboolean{lst@stringspaces}{false}
\lst@AddToHook{Init}
  {\@ifundefined{lst@stringspaces}{}
     {\setboolean{lst@stringspaces}{\lst@boolean{\lst@stringspaces}}}}
\lst@AddToHook{DeInit}{\setboolean{lst@stringspaces}{false}}
%%%%%% Comments
% Line comments
\newcommand{\lst@LC@key}[1]
  {\lst@lExtend\lst@DefineComments@LC
    {\lst@line@comment{\@rawchars{#1}}}}
\define@key{lst}{commentline}{\lst@LC@key{#1}}
\lst@AddToHookExe{SetLanguage}{\let\lst@DefineComments@LC\@empty}
\lst@AddToHook{SelectCharTable}{\lst@DefineComments@LC}
% Nested comments
\newcommand{\lst@NC@key}[2]
  {\lst@lExtend\lst@DefineComments@NC
     {\lst@nested@comment{\@rawchars{#1}}{\@rawchars{#2}}}}
\define@key[2]{lst}{nestedcomment}{\lst@NC@key{#1}{#2}}
\lst@AddToHookExe{SetLanguage}{\let\lst@DefineComments@NC\@empty}
\lst@AddToHook{SelectCharTable}{\lst@DefineComments@NC}
% Balanced comments
\newcommand{\lst@SC@key}[2]
   {\lst@lExtend\lst@DefineComments@SC
     {\lst@balanced@comment{\@rawchars{#1}}{\@rawchars{#2}}}}
\define@key[2]{lst}{singlecomment}{\lst@SC@key{#1}{#2}}
\lst@AddToHookExe{SetLanguage}{\let\lst@DefineComments@SC\@empty}
\lst@AddToHook{SelectCharTable}{\lst@DefineComments@SC}
\newcommand{\lst@DC@key}[4]
   {\lst@lExtend\lst@DefineComments@DC
      {\lst@balanced@comment{\@rawchars{#1}}{\@rawchars{#2}}}%
   \lst@lExtend\lst@DefineComments@DC
      {\lst@balanced@comment{\@rawchars{#3}}{\@rawchars{#4}}}}
\define@key[4]{lst}{doublecomment}{\lst@DC@key{#1}{#2}{#3}{#4}}
\lst@AddToHookExe{SetLanguage}{\let\lst@DefineComments@DC\@empty}
\lst@AddToHook{SelectCharTable}{\lst@DefineComments@DC}
%%%%%% New interface for comments grr...
\def\lst@morecomment@d#1#2#3#4{\lst@DC@key{#1}{#2}{#3}{#4}}
\def\lst@morecomment@s#1#2{\lst@SC@key{#1}{#2}}
\def\lst@morecomment@n#1#2{\lst@NC@key{#1}{#2}}
\def\lst@morecomment@l#1#2#3#4\@empty{\lst@LC@key{#1#2#3#4}}
\def\lst@deletecomment@d{\let\lst@DefineComments@DC\@empty}
\def\lst@deletecomment@s{\let\lst@DefineComments@SC\@empty}
\def\lst@deletecomment@n{\let\lst@DefineComments@NC\@empty}
\def\lst@deletecomment@l{\let\lst@DefineComments@LC\@empty}
\def\lst@till@empty#1\@empty{}
\newcommand{\lst@morecomment@key}[1][]
  {\ifu\csname lst@morecomment@#1\endcsname
    \warning{Unkown comment type ``#1''}%
    \let\lst@next\lst@till@empty\else
    \let\lst@next\csname lst@morecomment@#1\endcsname\fi
    \lst@next}
\newcommand{\lst@deletecomment@key}[1][]
  {\ifu\csname lst@deletecomment@#1\endcsname
   \warning{Unkown comment type ``#1''}\else
   \csname lst@deletecomment@#1\endcsname\fi
   \lst@till@empty}
\newcommand{\lst@comment@key}[1][]
  {\ifu\csname lst@morecomment@#1\endcsname
    \warning{Unkown comment type ``#1''}%
    \let\lst@next\lst@till@empty\else
    \csname lst@deletecomment@#1\endcsname
    \let\lst@next\csname lst@morecomment@#1\endcsname\fi
    \lst@next}
\define@key{lst}{deletecomment}{\@callsubst{\lst@deletecomment@key}{#1\@empty}}
\define@key{lst}{comment}{\@callsubst{\lst@comment@key}{#1\@empty\@empty\@empty}}
\define@key{lst}{morecomment}{\@callsubst{\lst@morecomment@key}{#1\@empty\@empty\@empty}}
%%%%%%% Extended chars
\def\lst@extendedchars{false}
\lst@AddToHook{DeInit}{\setboolean{lst@extendedchars}{false}}
\lst@AddToHookExe{SetLanguage}{\setboolean{lst@extendedchars}{false}}
\lst@AddToHook{SelectCharTable}
{\setboolean{lst@extendedchars}{\lst@boolean{\lst@extendedchars}}}
\define@key{lst}{extendedchars}[true]{\def\lst@extendedchars{#1}}
%%%%%%% Sensitive keywords
\lst@AddToHookExe{DeInit}{\setboolean{lst@sensitive}{true}}
\lst@AddToHook{SetLanguage}{\setboolean{lst@sensitive}{true}}
\define@key{lst}{sensitive}[true]{\setboolean{lst@sensitive}{\lst@boolean{#1}}}
%%%%%%% Output
% Treating spaces with a counter (and not with boxes) enables
% optimized style managment
\newcounter{lst@spaces}
\def\lst@output@space{\stepcounter{lst@spaces}}
\lst@AddToHook{Init}{\setcounter{lst@spaces}{0}}
\def\lst@normalize
  #1{\iflst@sensitive\@rawchars{#1}\else\@rawchars{\lowercase{#1}}\fi}
\def\lst@output#1#2{%
\@NewLine%\lstinfo{OUT: ``#1'' ``#2''}%
{\ifu\csname lstk@\lst@normalize{#1}\endcsname
  \lst@identifier@style{#2}\else
  \csname lstk@\lst@normalize{#1}\endcsname{#2}\fi}}
\def\lst@output@other#1#2{%
\@NewLine%\lstinfo{OTHER: ``#1'' ``#2''}%
\ifu\csname lstk@\lst@normalize{#1}\endcsname
  #2\else
  {\csname lstk@\lst@normalize{#1}\endcsname{#2}}\fi}
\newcounter{lst@save@spaces}
\def\save@spaces
  {\setcounter{lst@save@spaces}{\value{lst@spaces}}\setcounter{lst@spaces}{0}}
\def\restore@spaces
  {\setcounter{lst@spaces}{\value{lst@save@spaces}}}
\def\lst@output@directive#1#2{%
%\lstinfo{DIRECTIVE: ``#1'' ``#2'' ``\thelst@spaces''}%
\save@spaces\@NewLine\restore@spaces%
\ifu\csname lstd@\lst@normalize{#1}\endcsname
  {\lst@directive@style{\@print{#}}}%
  \lst@spaces\lst@output{#1}{#2}\else
  {\csname lstd@\lst@normalize{#1}\endcsname{\@print{#}\lst@spaces#2}}\fi}
%%%%%% Pre and post (already obsolete)
\let\lst@pre\@empty
\let\lst@post\@empty
\define@key{lst}{pre}{\def\lst@pre{#1}}
\define@key{lst}{post}{\def\lst@post{#1}}
%%%%%%% User interface
\newcommand{\lstinputlisting}[2][]
  {\@scaninput{\begin{lstlisting}[#1]{}
}{#2}{\end{lstlisting}}}
\let\lstdefinelanguage\lst@definelanguage
\newcommand{\lstloadlanguage}[1]{}
%%%%%% Driver files are loaded directly!
\lstset{defaultdialect=[95]Ada,
        defaultdialect=[68]Algol,
        defaultdialect=[ANSI]C,
        defaultdialect=[Objective]Caml,
        defaultdialect=[1985]Cobol,
        defaultdialect=[ANSI]C++,
        defaultdialect=[95]Fortran,
        defaultdialect=[3.0]Mathematica,
        defaultdialect=[Standard]Pascal,
        defaultdialect=[67]Simula,
        defaultdialect=[plain]TeX}
\input{lstlang1.hva}
\input{lstlang2.hva}
\input{lstlang3.hva}
%%%%%%%%%%% Inits
\lst@UseHook{SetStyle}\lst@UseHook{EmptyStyle}
\lst@UseHook{SetLanguage}\lst@UseHook{EmptyLanguage}