summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/tex/latex/webquiz/webquiz-ini.code.tex
diff options
context:
space:
mode:
authorKarl Berry <karl@freefriends.org>2019-03-16 22:43:33 +0000
committerKarl Berry <karl@freefriends.org>2019-03-16 22:43:33 +0000
commit7e80fa208736f4ab99b1d57dd1571da41f1e3744 (patch)
tree606bd82a5737d587ef239fd58a5a58c256666178 /Master/texmf-dist/tex/latex/webquiz/webquiz-ini.code.tex
parent9de7d0ea371387f647487812b48b51030c739bdf (diff)
webquiz
git-svn-id: svn://tug.org/texlive/trunk@50419 c570f23f-e606-0410-a88d-b1316a301751
Diffstat (limited to 'Master/texmf-dist/tex/latex/webquiz/webquiz-ini.code.tex')
-rw-r--r--Master/texmf-dist/tex/latex/webquiz/webquiz-ini.code.tex52
1 files changed, 52 insertions, 0 deletions
diff --git a/Master/texmf-dist/tex/latex/webquiz/webquiz-ini.code.tex b/Master/texmf-dist/tex/latex/webquiz/webquiz-ini.code.tex
new file mode 100644
index 00000000000..3fa2d454690
--- /dev/null
+++ b/Master/texmf-dist/tex/latex/webquiz/webquiz-ini.code.tex
@@ -0,0 +1,52 @@
+% -----------------------------------------------------------------------
+% webquiz-ini.sty | read the webquiz.ini file into pgfkeys
+% -----------------------------------------------------------------------
+%
+% Copyright (C) Andrew Mathas, University of Sydney
+%
+% Distributed under the terms of the GNU General Public License (GPL)
+% http://www.gnu.org/licenses/
+%
+% This file is part of the webquiz system.
+%
+% <Andrew.Mathas@sydney.edu.au>
+% ----------------------------------------------------------------------
+
+%% Read the webquiz.ini file into \pgfkeys for later use so that we
+%% don't need to hard-code version information. We allow unknown keys so
+%% that we can slurp in all of the information in the file into
+%% \pgfkeys{/webquiz}
+\RequirePackage{pgfkeys}
+\pgfkeys{/webquiz/.is family, /webquiz,
+ % allow arbitrary unknown keys and set with \pgfkeyssetvalue
+ .unknown/.code={\pgfkeyssetvalue{\pgfkeyscurrentpath/\pgfkeyscurrentname}{#1}},
+}
+\newcommand\webquiz[1]{\pgfkeysvalueof{/webquiz/#1}}
+
+% split input line into key-value pairs -- necessary as commas can appear in the value
+\RequirePackage{xparse}
+% \AddIniFileKeyValue{key=value} - take a single argument and split it on =
+\NewDocumentCommand{\AddIniFileKeyValue}{ >{\SplitList{=}} m }{%
+ \AddIniFileValue #1%
+}
+% put a key-value pair into \pgfkeys{/webquiz}
+% \AddIniFile{key}{value} - note that value may contain commas
+\newcommand\AddIniFileValue[2]{\expandafter\pgfkeys\expandafter{/webquiz,#1={#2}}}
+
+% read the webquiz.ini file into \pgfkeys{/webquiz}
+\newread\inifile% file handler
+\def\apar{\par}% \ifx\par won't work but \ifx\apar will
+\newcommand\AddEntry[1]{\expandafter\pgfkeys\expandafter{/webquiz, #1}}
+\openin\inifile=webquiz.ini% open file for reading
+\loop\unless\ifeof\inifile% loop until end of file
+ \read\inifile to \iniline% read line from file
+ \ifx\iniline\apar% test for, and ignore, \par
+ \else%
+ \ifx\iniline\empty\relax% skip over empty lines/comments
+ \else\expandafter\AddIniFileKeyValue\expandafter{\iniline}
+ \fi%
+ \fi%
+\repeat% end of file reading loop
+\closein\inifile% close input file
+
+\endinput