summaryrefslogtreecommitdiff
path: root/Master/texmf-dist/source/latex/datatool/datatool.dtx
diff options
context:
space:
mode:
Diffstat (limited to 'Master/texmf-dist/source/latex/datatool/datatool.dtx')
-rw-r--r--Master/texmf-dist/source/latex/datatool/datatool.dtx177
1 files changed, 151 insertions, 26 deletions
diff --git a/Master/texmf-dist/source/latex/datatool/datatool.dtx b/Master/texmf-dist/source/latex/datatool/datatool.dtx
index ac9fe123f73..9e9ddec7ae3 100644
--- a/Master/texmf-dist/source/latex/datatool/datatool.dtx
+++ b/Master/texmf-dist/source/latex/datatool/datatool.dtx
@@ -19,7 +19,7 @@
% -author "Nicola Talbot"
% -codetitle ""
% datatool
-% Created on 2014/1/17 12:07
+% Created on 2014/2/3 15:28
%\fi
%\iffalse
%<*package>
@@ -66,7 +66,7 @@ datatool.dtx
\doxitem{Counter}{counter}{counters}
\doxitem{Option}{option}{package options}
-\CheckSum{22929}
+\CheckSum{22983}
\RecordChanges
\PageIndex
@@ -79,11 +79,11 @@ datatool.dtx
%\fi
%\MakeShortVerb{"}
%
-%\title{Documented Code for datatool v2.19}
+%\title{Documented Code for datatool v2.20}
%\author{Nicola L. C. Talbot\\
%\url{http://www.dickimaw-books.com/}}
%
-%\date{2014-01-17}
+%\date{2014-02-03}
%\maketitle
%
%\pagenumbering{roman}
@@ -5708,7 +5708,7 @@ datatool.dtx
%\section{Package Declaration}
% \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}
-\ProvidesPackage{datatool}[2014/01/17 v2.19 (NLCT)]
+\ProvidesPackage{datatool}[2014/02/03 v2.20 (NLCT)]
% \end{macrocode}
% Load required packages:
% \begin{macrocode}
@@ -7160,13 +7160,79 @@ datatool.dtx
%\changes{2.10}{2012-07-18}{new}
% \begin{macrocode}
\newcommand*{\DTLassign}[3]{%
+ \DTLifdbexists{#1}
+ {%
% \end{macrocode}
% Grouped in the event that \cs{dtlcurrentrow} is already in use.
% (Assignments in \cs{@dtl@assign} are global.)
% \begin{macrocode}
- {%
- \dtlgetrow{#1}{#2}%
+ {%
+ \dtlgetrow{#1}{#2}%
\@dtl@assign{#3}{#1}%
+ }%
+ }%
+ {%
+ \PackageError{datatool}{Database `#1' doesn't exist}{}%
+ }%
+}
+% \end{macrocode}
+%\end{macro}
+%
+%\begin{macro}{\DTLassignfirstmatch}
+%\begin{definition}
+%\cs{DTLassignfirstmatch}\marg{db}\marg{col key}\marg{value}\marg{assign list}
+%\end{definition}
+% Applies the assignment list to the first row that has the given
+% value in the given column. (Value must be expanded.)
+%\changes{2.20}{2014-02-14}{new}
+% \begin{macrocode}
+\newcommand*{\DTLassignfirstmatch}[4]{%
+ \dtl@assignfirstmatch{#3}{#1}{#2}{#4}%
+}
+% \end{macrocode}
+%\end{macro}
+%\begin{macro}{\xDTLassignfirstmatch}
+%\begin{definition}
+%\cs{xDTLassignfirstmatch}\marg{db}\marg{col key}\marg{value}\marg{assign list}
+%\end{definition}
+% Applies the assignment list to the first row that has the given
+% value in the given column. (Performs \emph{one level} expansion on
+% \meta{value}.)
+%\changes{2.20}{2014-02-14}{new}
+% \begin{macrocode}
+\newcommand*{\xDTLassignfirstmatch}[4]{%
+ \protected@edef\@dtl@asg@value{\expandonce{#3}}%
+ \expandafter\dtl@assignfirstmatch\expandafter
+ {\@dtl@asg@value}{#1}{#2}{#4}%
+}
+% \end{macrocode}
+%\end{macro}
+%\begin{macro}{\dtl@assignfirstmatch}
+% Internal swaps the ordering around so the value is first. (This
+% just makes it easier for \cs{xDTLassignfirstmatch}
+% \begin{macrocode}
+\newcommand*{\dtl@assignfirstmatch}[4]{%
+ \DTLifdbexists{#2}%
+ {%
+% Grouped in the event that \cs{dtlcurrentrow} is already in use.
+% (Assignments in \cs{@dtl@assign} are global.)
+% \begin{macrocode}
+ {%
+% \end{macrocode}
+% Get row idx:
+% \begin{macrocode}
+ \dtlgetrowindex{\dtl@asg@rowidx}{#2}{\dtlcolumnindex{#2}{#3}}{#1}%
+ \ifx\dtl@asg@rowidx\dtlnovalue
+ \PackageError{datatool}{No match found for
+ \string\DTLassignfirstmatch{#2}{#3}{#1}{#4}}{}%
+ \else
+ \dtlgetrow{#2}{\dtl@asg@rowidx}%
+ \@dtl@assign{#4}{#2}%
+ \fi
+ }%
+ }%
+ {%
+ \PackageError{datatool}{Data base `#2' doesn't exist}{}%
}%
}
% \end{macrocode}
@@ -7180,9 +7246,13 @@ datatool.dtx
% The current row must be stored in \cs{dtlcurrentrow}.
%\changes{2.0}{2009 February 27}{updated to use new database
% structure}
+%\changes{2.20}{2014-02-14}{Added check for empty argument}%
% \begin{macrocode}
\newcommand*{\@dtl@assign}[2]{%
- \@dtl@assigncmd#1,\@nil\@@{#2}%
+ \ifstrempty{#1}{}%
+ {%
+ \@dtl@assigncmd#1,\@nil\@@{#2}%
+ }%
}
% \end{macrocode}
%\end{macro}
@@ -7196,6 +7266,12 @@ datatool.dtx
% \begin{macrocode}
\def\@dtl@assigncmd#1#2=#3,#4\@@#5{%
% \end{macrocode}
+% Store database label. (This may already have been done so \cs{edef}
+% is used to prevent infinite recursion.)
+%\changes{2.20}{2014-02-03}{Stored db label in \cs{@dtl@dbname}}
+% \begin{macrocode}
+ \edef\@dtl@dbname{#5}%
+% \end{macrocode}
% get entry for ID given by \#3 and store in \#2
% \begin{macrocode}
\@sDTLifhaskey{#5}{#3}%
@@ -7207,9 +7283,11 @@ datatool.dtx
% \end{macrocode}
% Set to null if required
% \begin{macrocode}
- \ifx#1\dtlnovalue
+ \ifdefequal{#1}{\dtlnovalue}%
+ {%
\@@dtl@setnull{#1}{#3}%
- \fi
+ }%
+ {}%
% \end{macrocode}
% Make it global
% \begin{macrocode}
@@ -7351,6 +7429,18 @@ datatool.dtx
% \end{macrocode}
%\end{macro}
%
+%\begin{macro}{\DTLifnullorempty}
+%\begin{definition}
+%\cs{DTLifnullorempty}\marg{command}\marg{true part}\marg{false part}
+%\end{definition}
+%\changes{2.20}{2014-02-14}{new}
+% \begin{macrocode}
+\newcommand*{\DTLifnullorempty}[3]{%
+ \ifdefempty{#1}{#2}{\DTLifnull{#1}{#2}{#3}}%
+}
+% \end{macrocode}
+%\end{macro}
+%
%\begin{macro}{\@dtlnovalue}
% \begin{macrocode}
\def\@dtlnovalue{Undefined Value}
@@ -8618,8 +8708,9 @@ datatool.dtx
\global\c@DTLrow=\c@DTLrow\relax
% \end{macrocode}
% Store database name
+%\changes{2.20}{2014-02-03}{change \cs{gdef} to \cs{xdef}}
% \begin{macrocode}
- \gdef\@dtl@dbname{#2}%
+ \xdef\@dtl@dbname{#2}%
% \end{macrocode}
% Increment level and check not exceeded 3
% \begin{macrocode}
@@ -8891,6 +8982,11 @@ datatool.dtx
% \begin{macrocode}
\global\c@DTLrow=\c@DTLrow
% \end{macrocode}
+% Store database name.
+%\changes{2.20}{2014-02-03}{Added missing \cs{@dtl@dbname} assignment}
+% \begin{macrocode}
+ \xdef\@dtl@dbname{#2}%
+% \end{macrocode}
% Increment level and check not exceeded 3
% \begin{macrocode}
\global\advance\dtlforeachlevel by 1\relax
@@ -10482,18 +10578,18 @@ datatool.dtx
% \end{macrocode}
% Iterate over all the listed data bases
% \begin{macrocode}
- \@for\@dtl@dbname:=#2\do{%
+ \@for\@dtl@db@name:=#2\do{%
% \end{macrocode}
% Iterate through this database (using read only version)
% \begin{macrocode}
- \@sDTLforeach{\@dtl@dbname}%
+ \@sDTLforeach{\@dtl@db@name}%
{#1}% assignment list
{%
% \end{macrocode}
% Iterate through key list.
% \begin{macrocode}
\@for\@dtl@key:=#3\do{%
- \@sdtl@getcolumnindex{\@dtl@col}{\@dtl@dbname}{\@dtl@key}%
+ \@sdtl@getcolumnindex{\@dtl@col}{\@dtl@db@name}{\@dtl@key}%
\dtlcurrentrow=\expandafter{\dtl@thisrow}%
\dtlgetentryfromrow{\DTLthisval}{\@dtl@col}{\dtlcurrentrow}%
\expandafter\ifthenelse\expandafter{\@dtl@cond}%
@@ -10585,18 +10681,18 @@ datatool.dtx
% \end{macrocode}
% Iterate over all the listed data bases
% \begin{macrocode}
- \@for\@dtl@dbname:=#2\do{%
+ \@for\@dtl@db@name:=#2\do{%
% \end{macrocode}
% Iterate through this database (using read only version)
% \begin{macrocode}
- \@sDTLforeach{\@dtl@dbname}%
+ \@sDTLforeach{\@dtl@db@name}%
{#1}% assignment list
{%
% \end{macrocode}
% Iterate through key list.
% \begin{macrocode}
\@for\@dtl@key:=#3\do{%
- \@sdtl@getcolumnindex{\@dtl@col}{\@dtl@dbname}{\@dtl@key}%
+ \@sdtl@getcolumnindex{\@dtl@col}{\@dtl@db@name}{\@dtl@key}%
\dtlcurrentrow=\expandafter{\dtl@thisrow}%
\dtlgetentryfromrow{\DTLthisval}{\@dtl@col}{\dtlcurrentrow}%
\expandafter\ifthenelse\expandafter{\@dtl@cond}%
@@ -10705,18 +10801,18 @@ datatool.dtx
% \end{macrocode}
% Iterate over all the listed data bases
% \begin{macrocode}
- \@for\@dtl@dbname:=#2\do{%
+ \@for\@dtl@db@name:=#2\do{%
% \end{macrocode}
% Iterate through this database (using read only version)
% \begin{macrocode}
- \@sDTLforeach{\@dtl@dbname}%
+ \@sDTLforeach{\@dtl@db@name}%
{#1}% assignment list
{%
% \end{macrocode}
% Iterate through key list.
% \begin{macrocode}
\@for\@dtl@key:=#3\do{%
- \@sdtl@getcolumnindex{\@dtl@col}{\@dtl@dbname}{\@dtl@key}%
+ \@sdtl@getcolumnindex{\@dtl@col}{\@dtl@db@name}{\@dtl@key}%
\dtlcurrentrow=\expandafter{\dtl@thisrow}%
\dtlgetentryfromrow{\DTLthisval}{\@dtl@col}{\dtlcurrentrow}%
\expandafter\ifthenelse\expandafter{\@dtl@cond}%
@@ -10881,18 +10977,18 @@ datatool.dtx
% \end{macrocode}
% Iterate over all the listed data bases
% \begin{macrocode}
- \@for\@dtl@dbname:=#2\do{%
+ \@for\@dtl@db@name:=#2\do{%
% \end{macrocode}
% Iterate through this database (using read only version)
% \begin{macrocode}
- \@sDTLforeach{\@dtl@dbname}%
+ \@sDTLforeach{\@dtl@db@name}%
{#1}% assignment list
{%
% \end{macrocode}
% Iterate through key list.
% \begin{macrocode}
\@for\@dtl@key:=#3\do{%
- \@sdtl@getcolumnindex{\@dtl@col}{\@dtl@dbname}{\@dtl@key}%
+ \@sdtl@getcolumnindex{\@dtl@col}{\@dtl@db@name}{\@dtl@key}%
\dtlcurrentrow=\expandafter{\dtl@thisrow}%
\dtlgetentryfromrow{\DTLthisval}{\@dtl@col}{\dtlcurrentrow}%
\expandafter\ifthenelse\expandafter{\@dtl@cond}%
@@ -10997,18 +11093,18 @@ datatool.dtx
% \end{macrocode}
% Iterate over all the listed data bases
% \begin{macrocode}
- \@for\@dtl@dbname:=#2\do{%
+ \@for\@dtl@db@name:=#2\do{%
% \end{macrocode}
% Iterate through this database (using read only version)
% \begin{macrocode}
- \@sDTLforeach{\@dtl@dbname}%
+ \@sDTLforeach{\@dtl@db@name}%
{#1}% assignment list
{%
% \end{macrocode}
% Iterate through key list.
% \begin{macrocode}
\@for\@dtl@key:=#3\do{%
- \@sdtl@getcolumnindex{\@dtl@col}{\@dtl@dbname}{\@dtl@key}%
+ \@sdtl@getcolumnindex{\@dtl@col}{\@dtl@db@name}{\@dtl@key}%
\dtlcurrentrow=\expandafter{\dtl@thisrow}%
\dtlgetentryfromrow{\DTLthisval}{\@dtl@col}{\dtlcurrentrow}%
\expandafter\ifthenelse\expandafter{\@dtl@cond}%
@@ -12381,6 +12477,35 @@ datatool.dtx
%
%\section{Loading a database from an external file}
%
+%\begin{macro}{\DTLloaddbtex}
+%\begin{definition}
+%\cs{DTLloaddbtex}\marg{cs}\marg{file}
+%\end{definition}
+% Load a \texttt{.dbtex} file and assign the database name to the
+% control sequence \meta{cs}. Checks the file name exists and the
+% control sequence doesn't exist.
+%\changes{2.20}{2014-02-14}{new}
+% \begin{macrocode}
+\newcommand*{\DTLloaddbtex}[2]{%
+ \IfFileExists{#2}%
+ {%
+ \input{#2}%
+ \ifdef#1%
+ {%
+ \PackageError{datatool}{Command \string#1\space is already defined}%
+ {}%
+ }%
+ {%
+ \let#1\dtllastloadeddb
+ }%
+ }%
+ {%
+ \PackageError{datatool}{File `#2' doesn't exist.}{}%
+ }%
+}
+% \end{macrocode}
+%\end{macro}
+%
%\begin{macro}{\@dtl@read}
% \begin{macrocode}
\newread\@dtl@read