add quotation mark in add_header HSTS directive
[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\def\dummy@ext{.}\else\let\dummy@ext\empty\fi%
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\dummy@ext}%
71     \marginpar{\vspace*{-2\baselineskip}\protect\href{\@configurationbaseurl\configfilename}{%
72         \includegraphics[height=2\baselineskip]{img/ConfigIcns}}}
73   \else%
74     \@warning{\string\configfile outside a sectiontraced region}%
75   \fi%
76 }
77
78 %
79 % start tracing section commands to record (sub)section names
80 \newcommand*\startconfigfiles{%
81   \tracingsectionstrue%
82 }
83
84 %
85 % stop tracing section commands
86 \newcommand*\stopconfigfiles{%
87   \tracingsectionsfalse%
88   \renewcommand*\currentsectionname{%
89     \@warning{\string\currentsectionname outside sectiontraced region}}%
90   \renewcommand*\currentsubsectionname{%
91     \@warning{\string\currentsubsectionname outside sectiontraced region}}%
92 }%
93
94 % ok, we're done here
95 \makeatother
96
97 %%% Local Variables:
98 %%% mode: latex
99 %%% TeX-master: "../applied-crypto-hardening"
100 %%% End: