%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++%
% This is file 'skeyval-view.sty', version 1.2, 2013/02/10.                %
%                                                                          %
% This package and accompanying files may be distributed and/or            %
% modified under the conditions of the LaTeX Project Public License,       %
% either version 1.3 of this license or any later version. The latest      %
% version of this license is in http://www.latex-project.org/lppl.txt      %
% and version 1.3 or later is part of all distributions of LaTeX           %
% version 2005/12/01 or later.                                             %
%                                                                          %
% The LPPL maintenance status of this software is 'author-maintained'.     %
%                                                                          %
% This software is provided 'as it is', without warranty of any kind,      %
% either expressed or implied, including, but not limited to, the          %
% implied warranties of merchantability and fitness for a particular       %
% purpose.                                                                 %
%                                                                          %
% The following files constitute the skeyval bundle and must be            %
% distributed as a whole:                                                  %
%                                                                          %
%  readme, skeyval.sty, skeyval-core.tex, skeyval-for.tex,                 %
%  skeyval-view.sty, skeyval-ltxpatch.sty, skeyval-ltxcmds.tex,            %
%  skeyval-pstkey.sty, skeyval-pstkey.tex, skeyval-testclass.cls,          %
%  and skeyval-testpkg.sty.                                                %
%                                                                          %
% Copyright (c) 2010-2013 Ahmed Musa (amusa22@gmail.com).                  %
%++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++%

\begingroup
\catcode035 06 % #
\catcode064 11 % @
\catcode123 01 % {
\catcode125 02 % }
\catcode044 12 % ,
\def\skv@prova{\endgroup
  \def\do##1,{%
    \ifx\do##1\else
      \catcode##1\string=\the\catcode##1\relax
      \expandafter\do
    \fi
  }%
  \edef\skv@view@restorecodes{\do35,64,123,125,61,59,13,\do,}%
}
\skv@prova

\edef\skv@view@restorecodes{%
  \unexpanded\expandafter{\skv@view@restorecodes}%
  \endlinechar\the\endlinechar\relax
}
\endlinechar13 %
\catcode035 06 % #
\catcode064 11 % @
\catcode123 01 % {
\catcode125 02 % }
\catcode061 12 % =
\catcode044 12 % ,
\def\do#1=#2,{%
  \ifx\do#1\else
    \edef\skv@view@restorecodes{%
      \unexpanded\expandafter{\skv@view@restorecodes}%
      \catcode#1=\the\catcode#1\relax
    }%
    \catcode#1=#2\relax
    \expandafter\do
  \fi
}
\do 032=10,033=12,036=03,038=04,040=12,041=12,042=12,043=12,%
  059=12,045=12,047=12,058=12,063=12,091=12,093=12,126=13,\do=,%

\NeedsTeXFormat{LaTeX2e}[2011/06/27]
\ProvidesPackage{skeyval-view}
  [2013/02/10 v1.2 Viewer utility for skeyval package (AM)]
\@ifpackageloaded{skeyval}{}{\RequirePackage{skeyval}}
\directkeys*{%
  .path=SKVV/skvview,
  .holder prefix=skvv@,
  .initialize keys after define,
  .every unknown option={
    \PackageWarning{skeyval-view}{Unknown option '\CurrentOption' ignored}%
  },
  .new options={
    % LaTeX's options processor will zap the option names. So these keys
    % can't have spaces between their parts.
    .ord/{xcolor-options,load-xcolor-with}//
      \edef\skvv@xcoloroptions{\unexpanded{#1}}
      \skvstripouterbraces{1}\skvv@xcoloroptions,
  },
  .copy class options and process options,
}
\AtEndOfPackage{%
  \skvdisablekeys[SKVV]{skvview}{%
    xcolor-options,load-xcolor-with
  }%
}

\@ifpackageloaded{longtable}{}{\RequirePackage{longtable}}
\@ifpackageloaded{xcolor}{}{\RequirePackage[\skvv@xcoloroptions]{xcolor}}
\skvnewbools[skvv@]{colii,coliii,coliv,colv}
\newwrite\skvv@out
\skvnewnumbers[skvv@]{depth,nra}

\directkeys*{
  .path=SKVV/skvview,
  .holder prefix=skvv@,
  .initialize after define=false,
  .define keys={
    .ord/{file,wcolsep,weol}/\@nil/
      \skvcsedef{skvv@\skvcurrentkey}{\unexpanded{#1}}
      \skvaftercsname{\skvstripouterbraces{1}}{skvv@\skvcurrentkey}
      \skvaftercsname\skvdespacecontent{skvv@\skvcurrentkey}
    ,
    .ord/{prefix,family,type,default,columns}/\@nil/
      \skvcsedef{skvv@\skvcurrentkey}{\unexpanded{#1}}
      \skvaftercsname{\skvstripouterbraces{1}}{skvv@\skvcurrentkey}
      \skvaftercsname\skvcsvnormalize{skvv@\skvcurrentkey}
    ,
    .bool/{view,vlabels,wlabels}/true,
    .ord/length of default/20/\def\skvv@lod{#1},
    .cmd/color/black,
  },
  .set keys={
    prefix,family,type,default,file,columns,wcolsep=&,weol=\\,
    view,vlabels=false,wlabels=false,color,length of default
  },
  .links={
    show/view,
    key type/type,
    {prefixes,only those with prefix,only those with prefixes}/prefix,
    {families,only those in family,only those in families}/family,
    {defaults,only those with default,only those with defaults}/default,
    view output/view,
    write to file/file,
    {view labels,show labels}/vlabels,
    {view wlabels,show wlabels}/wlabels,
    wend of line/weol,
    wcolumn separation/wcolsep,
    word length of default/length of default
  },
  .style={
    only those without default/default=[none],
  },
}

% Use \setupviewkeys to change viewing specifications without actually
% displaying (or writing to file) the key list:
%
\skvrobustdef*\setupviewkeys{\skvsetkeys[SKVV]{skvview}}

\let\skvv@db\@empty
\skvrobustdef*\skvv@tabulate#1#2#3{%
  \edef\skv@tempa{\detokenize{#3}}%
  \skv@getbasetoks\skvv@lod\skv@tempa\skv@ival
  \skvxaddtolist{,}\skvv@db{%
    #1=\ifx\skvcurrentprefix\@empty\else
    \skvcurrentprefix\fi=\skvcurrentfamily=#2=\skv@ival
  }%
}
\protected\def\skv@ordkey@a#1[#2]#3{%
  % Pointers have been stripped in \skv@ordkey.
  \skvifstrcmpTF{#2}{^skv^}{%
    \skvv@tabulate{#1}{ordinary}{[none]}%
  }{%
    \skv@definedefault{#1}{#2}%
    \skvv@tabulate{#1}{ordinary}{#2}%
  }%
  \skvcsedef{\skv@header#1.@cbk}{\unexpanded{#3}}%
}
\protected\def\skv@cmdkey#1#2[#3]#4{%
  \skv@strippointersfromkey{#2}%
  \skvifdefboolTF{skv@st}{%
    \skv@definedefault\skvcurrentkey{#3}%
    \skvv@tabulate\skvcurrentkey{command}{#3}%
  }{%
    \skvv@tabulate\skvcurrentkey{command}{[none]}%
  }%
  % This is to allow the key name to be expanded before possibly zapping
  % spaces in key name:
  \edef\skv@prova{#1\skvcurrentkey}%
  \edef\skv@prova{\expandafter\skv@zapornot\expandafter
    {\expandafter\skv@zapsw\expandafter}\expandafter{\skv@prova}}%
  \skvcslet{\skv@header\skvcurrentkey.@hp}\skv@prova
  \skvcsedef{\skv@header\skvcurrentkey.@cbk}{\unexpanded{#4}}%
}
\protected\def\skv@choicekey@g{%
  \skvcommaparse*\skv@currlist\skv@prova{%
    \skvexpbracenext\skv@strippointersfromkey\skv@prova
    \ifx\skv@default\skv@rej
      \skvv@tabulate\skvcurrentkey{choice}{[none]}%
    \else\skvafterfi
      \skvexpanded{%
        \noexpand\skvv@tabulate
          {\skvxonce\skvcurrentkey}{choice}{\skvxonce\skv@default}%
        \noexpand\skv@definedefault
          {\skvxonce\skvcurrentkey}{\skvxonce\skv@default}%
      }%
    \fi
    \skvcsedef{\skv@header\skvcurrentkey.@hp}{\skv@hp\skvcurrentkey}%
    \skvcsedef{\skv@header\skvcurrentkey.@cbk}{\the\skv@toksa}%
  }%
}
\protected\def\skv@boolkey@c#1#2#3#4{%
  % Pointers have been stripped in \skv@boolkey.
  \skvcsnewif{\skv@zapornot{\skv@zapsw}{#2}}%
  \edef\skvv@boolortog{\if\skv@typetogkey toggle\else bool\fi}%
  \skvifdefboolTF{skv@st}{%
    \skv@definedefault{#1}{#3}%
    \skvv@tabulate{#1}{\skvv@boolortog}{#3}%
  }{%
    \skvv@tabulate{#1}{\skvv@boolortog}{[none]}%
  }%
  \edef\skv@tempa##1##2{%
    \noexpand\skv@sttrue
    \ifskv@pl\noexpand\skv@pltrue\else\noexpand\skv@plfalse\fi
    \skv@checkchoice[\noexpand\skv@value]{##1}{true,false}##2%
  }%
  \skv@toksa\expandafter{\skv@tempa{##1}{#4}}%
  \skvcsedef{\skv@header#1.@cbk}{\the\skv@toksa}%
}
% #2: styles, #3: default, #4: callback
\protected\def\skv@appendstyles@a#1#2[#3]#4{%
  \skvcommaparse{#1}\skv@prova{%
    \skvexpbracenext\skv@strippointersfromkey\skv@prova
    \skvexpanded{%
      \skvifstrcmpTF{#3}{^skv^}{%
        \skvv@tabulate{\skvcurrentkey}{style}{[none]}%
      }{%
        \skv@definedefault{\skvcurrentkey}{\unexpanded{#3}}%
        \skvv@tabulate{\skvcurrentkey}{style}{\unexpanded{#3}}%
      }%
      \skv@appendstyles@b{\skvcurrentkey}\unexpanded{{#2}{#4}}%
    }%
  }%
}

\skvbuildmacrostack\skvv@state{%
  \do\skvv@prefix\do\skvv@family\do\skvv@type\do\skvv@default
  \do\skvv@file\do\skvv@columns\do\skvv@wcolsep\do\skvv@weol
  \do\skvv@color\do\ifskvv@view\do\ifskvv@vlabels\do\ifskvv@wlabels
}{2}

\skvrobustdef*\skvv@skvview@a#1{%
  \skvsetkeys[SKVV]{skvview}{#1}%
  \ifx\skvv@default\@nnil\else\@onelevel@sanitize\skvv@default\fi
  \ifx\skvv@columns\@nnil
    \skvsetnumber\skvv@nra5\relax
    \skvv@coliitrue\skvv@coliiitrue\skvv@colivtrue\skvv@colvtrue
  \else
    \skvsetnumber\skvv@nra\@ne
    \@expandtwoargs\skvtestifin{,prefix,}{,\skvv@columns,}%
    \ifin@\skvadvanceno\skvv@nra\@ne\skvv@coliitrue\else\skvv@coliifalse\fi
    \@expandtwoargs\skvtestifin{,family,}{,\skvv@columns,}%
    \ifin@\skvadvanceno\skvv@nra\@ne\skvv@coliiitrue\else\skvv@coliiifalse\fi
    \@expandtwoargs\skvtestifin{,type,}{,\skvv@columns,}%
    \ifin@
      \skvadvanceno\skvv@nra\@ne\skvv@colivtrue
    \else
      \@expandtwoargs\skvtestifin{,key type,}{,\skvv@columns,}%
      \ifin@\skvadvanceno\skvv@nra\@ne\skvv@colivtrue\else\skvv@colivfalse\fi
    \fi
    \@expandtwoargs\skvtestifin{,default,}{,\skvv@columns,}%
    \ifin@\skvadvanceno\skvv@nra\@ne\skvv@colvtrue\else\skvv@colvfalse\fi
  \fi
  \ifskvv@view
    \protected@edef\skv@prova{%
      \noexpand\begin{longtable}[l]{*\skvv@nra l}%
        \\\noexpand\hline
        \normalfont Key
        \ifskvv@colii&\normalfont Prefix\fi
        \ifskvv@coliii&\normalfont Family\fi
        \ifskvv@coliv&\normalfont Type\fi
        \ifskvv@colv&\normalfont Default\fi
        \\\noexpand\hline
      \noexpand\endfirsthead\noexpand\multicolumn{\skvv@nra}{l}{%
        \normalfont\emph{Continued from previous page}}%
      \\\noexpand\hline
      \normalfont Key
      \ifskvv@colii&\normalfont Prefix\fi
      \ifskvv@coliii&\normalfont Family\fi
      \ifskvv@coliv&\normalfont Type\fi
      \ifskvv@colv&\normalfont Default\fi
      \\\noexpand\hline\noexpand
      \endhead\noexpand\hline
      \noexpand\multicolumn{\skvv@nra}{r}{%
        \normalfont\emph{Continued on next page}}%
      \\\noexpand\endfoot\noexpand\hline
      \noexpand\endlastfoot
    }%
    \skv@toksa\expandafter{\skv@prova}%
  \fi
  \ifx\skvv@file\@nnil\else\immediate\openout\skvv@out\skvv@file\fi
  \skvcommaloop*\skvv@db\skv@prova{%
    \skv@swatrue
    \expandafter\skvv@skvview@b\skv@prova\skv@nil
  }%
  \ifskvv@view
    \addto@hook\skv@toksa{\end{longtable}}%
    \begingroup
    \color{\skvv@color}%
    \ttfamily\the\skv@toksa
    \endgroup
  \fi
  \ifx\skvv@file\@nnil\else\immediate\closeout\skvv@out\fi
}
\skvnewdef*\skvv@skvview@b#1=#2=#3=#4=#5\skv@nil{%
  \skvv@ifin{#2}\skvv@prefix
  \skvv@ifin{#3}\skvv@family
  \skvv@ifin{#4}\skvv@type
  \skvv@ifin{#5}\skvv@default
  \ifskv@swa
    \ifskvv@view
      \edef\skv@prova{%
        #1\ifskvv@colii&#2\fi\ifskvv@coliii&#3\fi
        \ifskvv@coliv&#4\fi\ifskvv@colv&#5\fi
        \ifskvv@vlabels\noexpand\label{#2/#3/#1}\fi
      }%
      \skv@toksa\expandafter{\the\expandafter\skv@toksa\skv@prova\\}%
    \fi
    \ifx\skvv@file\@nnil\else
      \immediate\write\skvv@out{%
        #1\ifskvv@colii\skvv@wcolsep#2\fi
        \ifskvv@coliii\skvv@wcolsep#3\fi
        \ifskvv@coliv\skvv@wcolsep#4\fi
        \ifskvv@colv\skvv@wcolsep#5\fi
        \ifskvv@wlabels\string\label{#2/#3/#1}\fi
        \skvexpandonce\skvv@weol
      }%
    \fi
  \fi
}
\skvrobustdef*\skvv@ifin#1#2{%
  \ifx#2\@nnil\else
    \skvxifinTF{,\detokenize{#1},}{,\skvoxdetok{#2},}{}\skv@swafalse
  \fi
}

\directkeys*{
  .path=SKVV/skvvshow,
  .holder prefix=skvvs@,
  .initialize keys after define,
  .new keys={
    .ord/{.show,.show table}//
      \skvifdefboolTF{skvindef}{}{
        \edef\skvvs@show{\unexpanded{#1}}
        \skvstripouterbraces{2}\skvvs@show
        \ifx\skvvs@show\@empty\else\skvafterfi
          \skvpushstate\skvv@state\skvv@depth
          \skvexpbracenext\skvv@skvview@a\skvvs@show
          \skvpopstate\skvv@state\skvv@depth
        \fi
      },
    .ord/.exec code/\@nil/
      \edef\skvvs@execcode{\unexpanded{#1}}
      \ifx\skvvs@execcode\@nnil\else
        \expandafter\skvvs@execcode
      \fi
  },
}

\skvrobustdef*\skvviewkeys{\skvsetkeys[SKVV]{skvvshow}}
\skvnewlet\skvshowkeys\skvviewkeys

\skv@view@restorecodes
\endinput

%% End of file 'skeyval-view.sty'.
