summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/getargs/getargs.sty
blob: be28d6257b24b9054d92e4e1c50eca79f7382c97 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
\def\getargsversionnumber{v1.01}
\ProvidesPackage{getargs}
[2016/05/20 \getargsversionnumber\ 
 Macro to parse an argument list, using user-specified parsing character]
% CREATED BY Steven B. Segletes <steven.b.segletes.civ@mail.mil>
% THIS PACKAGE IS RELEASED IN ACCORDANCE WITH THE LaTeX PUBLIC PROJECT LICENSE
% LPPL v1.3c (http://ctan.org/license/lppl1.3) OR ITS SUCCESSORS

% V1.00-Initial release
\newcounter{getarg@ctr}
\let\getargs\relax
\newcommand\getargs{}

\newcommand\setparsechar[1]{%
  \def\getargparsechar{#1}%
  \renewcommand{\getargs}[1]{%
    \setcounter{getarg@ctr}{0}%
    \parse@args##1#1\relax\relax%
  }%
  \def\parse@args##1#1##2\relax{%
    \stepcounter{getarg@ctr}%
    \expandafter\gdef\csname\getarg@root\romannumeral\value{getarg@ctr}\endcsname{##1}%
    \ifx\relax##2\relax%
      \expandafter\xdef\csname n\getarg@root\endcsname{\thegetarg@ctr}\else%
        \parse@args##2\relax\fi%
  }%
}

\newcommand\setparserootname[1][arg]{\def\getarg@root{#1}}

\let\showargs\relax
\newcommand\showargs[1][t]{%
  \fboxrule=.7pt\relax\fboxsep=\dimexpr-.5pt-\fboxrule\relax%
  \csname n\getarg@root\endcsname{} \textbackslash\getarg@root\ldots{} items %
    \if x#1(expanded)\else (tokens)\fi%
  : \showargs@help{#1}{1}{\csname n\getarg@root\endcsname}\unskip\fbox{\strut}.%
}

\newcommand\showargs@help[3]{%
  \setcounter{getarg@ctr}{#2}%
  \if x#1%
    \fbox{\strut}\csname\getarg@root\romannumeral\value{getarg@ctr}\endcsname%
    \hskip0pt\relax%
  \else
    \fbox{\strut}%
      \expandafter\detokenize\expandafter\expandafter\expandafter{%
      \csname\getarg@root\romannumeral\value{getarg@ctr}\endcsname}\hskip0pt\relax%
  \fi
  \ifnum\value{getarg@ctr}<#3\relax\stepcounter{getarg@ctr}%
    \showargs@help{#1}{\thegetarg@ctr}{#3}%
  \fi%
}

\setparserootname
\setparsechar{,}
\endinput