Document did not compile under Windows because `\lstinputlisting` was not able to...
[ach-master.git] / src / common / configfiles.tex
1 %%%
2 %%% Applied Crypto Hardening
3 %%% bettercrypto.org
4 %%%
5 %%% configfiles.tex -- macros for automatically inserting config file parts
6 %%%
7 %%%
8
9 %%%
10 %%    I need dis
11 %%%
12 \RequirePackage{etoolbox}
13 \RequirePackage{ifplatform}
14
15 % for convenienc
16 \newwrite\configfileout
17 \immediate\openout\configfileout configfiles.txt
18
19 % do not trace everything
20 \newif\iftracingsections
21 \tracingsectionsfalse
22 \newcommand*\currentsectionname{}%
23 \newcommand*\currentsubsectionname{}%
24
25 \makeatletter
26 \def\@configurationdir{configuration}
27 \newcommand*\configurationdir[1]{%
28   \gdef\@configurationdir{#1}}
29 \def\@configurationbaseurl{}
30 \newcommand*\configurationbaseurl[1]{%
31   \gdef\@configurationbaseurl{#1}}
32
33 % patch the section command to record information for our config files
34
35 \pretocmd{\@sect}{%
36   \iftracingsections%
37     \def\sectn@me{section}%
38     \def\subsectn@me{subsection}%
39     \def\tempa{#1}%
40     \edef\tempn@me{#8}%
41     \ifx\tempa\sectn@me\relax%
42       \expandafter\xdef\expandafter\currentsectionname{\tempn@me}%
43     \else\relax\fi%
44     \ifx\tempa\subsectn@me\relax%
45       \expandafter\xdef\expandafter\currentsubsectionname%
46         {\tempn@me}\else\relax\fi%
47   \fi
48 }{}{}
49
50 %
51 %
52 %  \configfile[args]{filename}{range}
53 %  --> \lstinputlisting[linerange={range},args]{configurations/Section/Subsection/filename}
54 %
55 \newcommand*\configfile[4][]{%
56   \iftracingsections%
57     \edef\configfilen@me{\@configurationdir/\currentsectionname/\currentsubsectionname/#2}
58     \edef\configfilename{\expandafter\detokenize\expandafter{\configfilen@me}}
59     \def\configfilepres{\expandafter\protect\expandafter\path\expandafter{\configfilename}}
60     \immediate\write\configfileout{\configfilename}
61     \ifwindows%
62         \lstinputlisting[%
63           linerange={#3},%
64           %autounindent,%
65           frame=single,%
66           caption={[#4\\\configfilepres]%
67               #4\\\mbox{\protect\href{\@configurationbaseurl\configfilename}{%
68                   {\upshape [\configfilepres]}%
69             }}}
70           #1]{\configfilename.}%
71     \else%
72         \lstinputlisting[%
73           linerange={#3},%
74           %autounindent,%
75           frame=single,%
76           caption={[#4\\\configfilepres]%
77               #4\\\mbox{\protect\href{\@configurationbaseurl\configfilename}{%
78                   {\upshape [\configfilepres]}%
79             }}}
80           #1]{\configfilename}%
81     \fi%
82     \marginpar{\vspace*{-2\baselineskip}\protect\href{\@configurationbaseurl\configfilename}{%
83         \includegraphics[height=2\baselineskip]{img/ConfigIcns}}}
84   \else%
85     \@warning{\string\configfile outside a sectiontraced region}%
86   \fi%
87 }
88
89 %
90 % start tracing section commands to record (sub)section names
91 \newcommand*\startconfigfiles{%
92   \tracingsectionstrue%
93 }
94
95 %
96 % stop tracing section commands
97 \newcommand*\stopconfigfiles{%
98   \tracingsectionsfalse%
99   \renewcommand*\currentsectionname{%
100     \@warning{\string\currentsectionname outside sectiontraced region}}%
101   \renewcommand*\currentsubsectionname{%
102     \@warning{\string\currentsubsectionname outside sectiontraced region}}%
103 }%
104
105 % ok, we're done here
106 \makeatother
107
108 %%% Local Variables:
109 %%% mode: latex
110 %%% TeX-master: "../applied-crypto-hardening"
111 %%% End: