% \iffalse meta-comment
% $Id: svn-prov.dtx 1862 2010-04-24 14:19:07Z martin $
%
% Copyright (C) 2009-2010 by Martin Scharrer <martin@scharrer-online.de>
%
% This work may be distributed and/or modified under the
% conditions of the LaTeX Project Public License, either version 1.3c
% of this license or (at your option) any later version.
% The latest version of this license is in
%
%   http://www.latex-project.org/lppl.txt
%
% and version 1.3c or later is part of all distributions of LaTeX
% version 2008/05/04 or later.
%
% This work has the LPPL maintenance status `maintained'.
%
% The Current Maintainer of this work is Martin Scharrer.
%
% This work consists of the files svn-prov.dtx, svn-prov.ins
% and the derived file svn-prov.sty.
%
% \fi
%
% \iffalse
%<*driver>
\RequirePackage{svn-prov}
%</driver>
%<*driver|package>
\def\svnprov@version{v3.\rev}
%</driver|package>
%<*driver>
\ProvidesFileSVN{$Id: svn-prov.dtx 1862 2010-04-24 14:19:07Z martin $}
  [\svnprov@version\space DTX for \filebase.sty]
\DefineFileInfoSVN
\GetFileInfoSVN*
% Re-require package to check date
\RequirePackage{svn-prov}[\filedate]

\documentclass{article}
\usepackage{ydoc}
\usepackage[hyperfootnotes=false]{hyperref}
\usepackage{booktabs}

\makeatletter
%%% Examples %%%
\RequirePackage{fancyvrb}
\RequirePackage{listings}

\renewenvironment{example}
  {\begingroup\VerbatimOut[gobble=4]{\jobname.exa}}
  {\endVerbatimOut\endgroup\formatexample}

\usepackage{ifthen,calc}

\def\examplebeforetext{The following code:}
\def\exampleaftertext{is equivalent to:}

\def\formatexample{%
  \par\noindent\examplebeforetext
  \lstinputlisting{\jobname.exa}\medskip
  \exampleaftertext\\[\medskipamount]%
  {\catcode`\%=14%
  \input{\jobname.exa}}%
  \par\bigskip
}

\lstset{%
  %numbers=left,
  numberstyle=\scriptsize\sffamily,
  basicstyle=\ttfamily,
  stepnumber=1,
  language=[latex]tex,
}%


\usepackage{xspace}
\let\pkg\relax
\newcommand*{\pkg}[1]{%
  \href{http://tug.ctan.org/pkg/#1}{\texttt{#1}}%
  % URL footnote (for print-out) on first appearance:
  \@ifundefined{seen@package@#1}{%
    \footnote{CTAN: \url{http://tug.ctan.org/pkg/#1}}%
    \@namedef{seen@package@#1}{1}%
  }{}%
  \xspace
}

\def\darg#1{\texttt{\frenchspacing\char`\{\$#1\$\char`\}}}

\makeatother

\EnableCrossrefs
\CodelineIndex
\RecordChanges

\let\manualnewpage\newpage
\listfiles
\begin{document}
  \DocInput{svn-prov.dtx}
  \PrintChanges
  \manualnewpage
  \PrintIndex
\end{document}
%</driver>
% \fi
%
% \CheckSum{423}
%
% \CharacterTable
%  {Upper-case    \A\B\C\D\E\F\G\H\I\J\K\L\M\N\O\P\Q\R\S\T\U\V\W\X\Y\Z
%   Lower-case    \a\b\c\d\e\f\g\h\i\j\k\l\m\n\o\p\q\r\s\t\u\v\w\x\y\z
%   Digits        \0\1\2\3\4\5\6\7\8\9
%   Exclamation   \!     Double quote  \"     Hash (number) \#
%   Dollar        \$     Percent       \%     Ampersand     \&
%   Acute accent  \'     Left paren    \(     Right paren   \)
%   Asterisk      \*     Plus          \+     Comma         \,
%   Minus         \-     Point         \.     Solidus       \/
%   Colon         \:     Semicolon     \;     Less than     \<
%   Equals        \=     Greater than  \>     Question mark \?
%   Commercial at \@     Left bracket  \[     Backslash     \\
%   Right bracket \]     Circumflex    \^     Underscore    \_
%   Grave accent  \`     Left brace    \{     Vertical bar  \|
%   Right brace   \}     Tilde         \~}
%
%
% \changes{v0.922}{2009/04/26}{Initial version}
% \changes{v1.}{2009/05/03}{Added \cs{DefineFileInfoSVN} macro.}
% \changes{v2.}{2010/03/25}{Fixed issues when used in font definition \texttt{*.fd} files due to changed catcodes.
% Also fixed error which occurred when Id line was not expanded.}
%
% ^^A \GetFileInfo{\jobname.dtx}
%
% \DoNotIndex{\newcommand,\newenvironment,\def,\edef,\gdef,\xdef,\let,\@tempa}
% \DoNotIndex{\g@tempa,\textbackslash,\ifx,\if,\ifnum,\else,\fi,\relax,\space}
% \DoNotIndex{\@ifnextchar,\@gobble,\@undefined,\begingroup,\endgroup,\empty}
% \DoNotIndex{\expandafter,\NeedsTeXFormat}
%
% \title{The \textsf{svn-prov} package\\\large Use SVN Id keywords for package, 
% class and file header}
% \author{Martin Scharrer \\ \url{martin@scharrer-online.de}}
% \GetFileInfoSVN{svnprov}
% \date{Version~\fileversion\ - \filetoday}
%
% \maketitle
%
% \section{Introduction}
% This package is directed to authors of \LaTeX\ packages and classes which use 
% the version control software 
% \href{http://subversion.tigris.org/}{Subversion}\footnote
% {WWW: \url{http://subversion.tigris.org/}} (SVN) for their source files. It 
% introduces three macros which are Subversion variants of the standard \LaTeX\ 
% header macros \cs{ProvidesPackage}, \cs{ProvidesClass} and \cs{ProvidesFile} 
% which are used to identify package, class and other files, respectively.  
% Instead of providing the package/class/file name and date manually they are 
% extracted from a Subversion Id keywords string which
% is updated automatically by every time the source file is committed to the 
% repository.
% 
% A similar package exists for RCS, the pre-predecessor of Subversion, in the 
% \pkg{pgf} bundle which is called \texttt{pgfrcs}.
% For further support for Subversion keywords see the author's other package 
% \pkg{svn-multi}.
%
% \section{Usage}
% ^^A\subsection{Subversion Id Keyword}
% The following macros need an Id keyword which can initially be written as 
% `|$||Id:$|' and will be expanded by Subversion into the following format at 
% the next commit:\par\smallskip
% \texttt{\frenchspacing\${}Id: \meta{filename} \meta{revision} \meta{date} 
% \meta{time} \meta{author} \$}
% \par\smallskip
% \noindent e.g. for the source file of this document:\par\smallskip
% |$Id: svn-prov.dtx 1862 2010-04-24 14:19:07Z martin $|
% \par\smallskip
% \noindent For this to work the Subversion \emph{property} \texttt{svn:keywords} must be 
% set to (at least) `|Id|' for the source file(s). e.g.\ using the command 
% line:\par\smallskip
% \texttt{svn propset 'svn:keyword' 'Id' \meta{filename(s)}}
% \par\smallskip\noindent
% \nopagebreak[3]\unskip
% More information about using Subversion in the \LaTeX\ workflow can be found in the 
% Prac\TeX{} Journal issue 2007-3\footnote
% {URL: 
% \ttfamily\url{http://www.tug.org/pracjourn/2007-3/}\char`\{\href
% {http://www.tug.org/pracjourn/2007-3/skiadas-svn}{skiadas-svn}\char`\|\href
% {http://www.tug.org/pracjourn/2007-3/ziegenhagen}{ziegenhagen}\char`\|\href
% {http://www.tug.org/pracjourn/2007-3/scharrer}{scharrer}\char`\}}.
%
% ^^A\subsection{Main Macros}
% \manualnewpage%%
% \DescribeMacro\ProvidesPackageSVN [<file name>] {\$Id:~\$} [<\small version and/or description>] [<\small description>]
% \DescribeMacro\ProvidesClassSVN   [<file name>] {\$Id:~\$} [<\small version and/or description>] [<\small description>]
% \DescribeMacro\ProvidesFileSVN    [<file name>] {\$Id:~\$} [<\small version and/or description>] [<\small description>]
%
% All of these macros await a valid Subversion Id keyword string as a mandatory 
% argument. The file name and date is extracted from this string. For cases when 
% the file source is not stored in the correct file but packed inside a 
% different one, like a |.dtx| file, the correct file name can be provided by an 
% optional argument. Because the file extension of package and class files is 
% predefined and therefore ignored this is not needed for them when they are 
% packed inside a corresponding |.dtx| file, i.e. one with the same base name.  
%
% As with the standard macros mentioned above additional information can be given optionally.
% Since v0.3 the SVN macro provide two optional arguments (before only one). 
% If only one optional argument is given it is taken as a description text which may start 
% with an potential version number. This version number must start with `|v|' and not include spaces
% and is extracted from the description. 
% Alternatively the version number and the description can be provided using two separate optional arguments.
% If no optional argument is given the default string \cs{revinfo} (see below) is used instead.
%
% All three optional arguments can include the following macros which are only valid
% inside them, but not afterwards\footnote{They can be set using \cs{GetFileInfoSVN}}:
% \begin{description}
%   \item[\cs{rev}] File revision.
%   \item[\cs{Rev}] File revision followed by a space.
%   \item[\cs{revinfo}] The default information used: 
%   ``\texttt{\frenchspacing(SVN Rev: \meta{revision})}''.
%   \item[\cs{filebase}] File base name (file name without extension).
%   \item[\cs{fileext}] File extension (without leading dot).
%   \item[\cs{filename}] File name.
%   \item[\cs{filedate}] File date (in the format YYYY/MM/DD).
%   \item[\cs{filerev}] File revision, like \cs{rev}.
% \end{description}
%
% ^^A\subsection{Other Macros}
% \par\medskip
% \DescribeMacro\GetFileInfoSVN{<name>}
% \DescribeMacro\GetFileInfoSVN*
% This macro\marginpar{\it\raggedright Non-star version added in v3. 2010/04/11}
% sets the macros \cs{filebase}, \cs{fileext}, \cs{filename}, \cs{filedate}, \cs{fileversion}, \cs{filerev},
% \cs{fileinfo} and \cs{filetoday} to the corresponding values of the file given by \meta{name}. The file must have been
% read/loaded before and use both a \cs{Provides\ldots SVN} macro and \cs{DefineFileInfoSVN}, otherwise the above macros
% will be set to |\relax|.  The \meta{name} can be either the real filename or the optional short name used with
% \cs{DefineFileInfoSVN}.
%
% The star version of this macro provides the file information of the last file which called one of the
% \cs{Provides\ldots SVN} macros.
%
% The macros \cs{fileversion} and \cs{fileinfo} hold the file version and description taken from optional argument of
% the \cs{Provide...SVN} macro.  The version is defined only if this argument starts with `|v|' and is otherwise empty.
% It includes all text up to the first space.
% The \cs{filetoday} macro generates a text representation of the \cs{filedate} using the \cs{today} macro. The format can be
% adjusted to a different language with the |\date|\meta{language} macro from the \pkg{babel} package.
% The other macros are described above.
%
%
% \par\medskip
% \DescribeMacro\DefineFileInfoSVN[<name>]
% Defined\marginpar{\it\raggedright New in v1. 2009/05/03}
% a set of macros which provide the information collected by a previous 
% \cs{Provides\ldots} macro. The macros have the form 
% |\|\meta{name}|@|\meta{data} where \meta{name} is by default the filename 
% either with the file extension (general files) or without (packages and 
% classes). This default can be overwritten by the optional argument.
% The \meta{data} stands for |version|, |rev| (revision), |date| and |info|
% (the information part without the version number)
% and, since v3,\marginpar{\it\raggedright Updated in v3. 2010/04/24}
% file name |base| and |ext|(ension) as well as |today|, which prints
% the |date| in the format of \cs{today}.
%
% \noindent
% \textit{Example:} Applied to the |.dtx| file of this very package the 
% following macros are defined:\par\medskip
% \begingroup
% \makeatletter\centering
% \begin{tabular}{ll}
%  \toprule
%  Macro  & Definition \\
%  \midrule
%  \cs{svn-prov.dtx@version} & \@nameuse{svn-prov.dtx@version} \\
%  \cs{svn-prov.dtx@rev}     & \@nameuse{svn-prov.dtx@rev}     \\
%  \cs{svn-prov.dtx@date}    & \@nameuse{svn-prov.dtx@date}    \\
%  \cs{svn-prov.dtx@info}    & \@nameuse{svn-prov.dtx@info}    \\
%  \cs{svn-prov.dtx@base}    & \@nameuse{svn-prov.dtx@base}    \\
%  \cs{svn-prov.dtx@ext}     & \@nameuse{svn-prov.dtx@ext}     \\
%  \cs{svn-prov.dtx@today}   & \@nameuse{svn-prov.dtx@today}   \\
%  \bottomrule
% \end{tabular}
% \par\bigskip
% The style file however would get macros like \cs{svn-prov@version}.
% Because `|-|' is not a letter the macros can only be accessed using |\csname|.  
% Therefore the optional argument |[svnprov]| is used to name the macros
% \cs{svnprov@version} etc..
% \endgroup
%
%
% \section{Examples}
% \begingroup
% \def\{{\texttt{\char`\{}}%
% \def\}{\texttt{\char`\}}}%
% \def\ProvidesPackage#1[#2]{\texttt{\cs{ProvidesPackage}\{#1\}[#2]}\\}%
% \def\ProvidesClass#1[#2]{\texttt{\cs{ProvidesClass}\{#1\}[#2]}\\}%
% \def\ProvidesFile#1[#2]{\texttt{\cs{ProvidesFile}\{#1\}[#2]}\\}%
%
% The following examples illustrate the usage of the provided macros and how 
% they call the equivalent standard macros internally. The example 
% \emph{results} are produced by expanding the corresponding example \emph{code} 
% while the standard provide macros are locally redefined to typeset their own 
% name and arguments in verbatim style. This does not only simplifies the 
% generation of this document but makes this examples also test cases which 
% allow the package author to test the result of the defined macros.
%
% While mostly the package macro is used here the usage is identical to the 
% class and file macros. Of course before this macros are used it must be made 
% sure that the \texttt{svn-prov} package is loaded which is done by using the 
% following code direct before them:\\[\smallskipamount]
% |\RequirePackage{svn-prov}|\\
%
% \frenchspacing
% \subsubsection*{Minimal usage}
% \begin{example}
%   \ProvidesPackageSVN
%     {$Id: svn-prov.dtx 1862 2010-04-24 14:19:07Z martin $}
% \end{example}
% \begin{example}
%   \ProvidesClassSVN
%     {$Id: svn-prov.dtx 1862 2010-04-24 14:19:07Z martin $}
% \end{example}
% \begin{example}
%   \ProvidesFileSVN
%     {$Id: svn-prov.dtx 1862 2010-04-24 14:19:07Z martin $}
% \end{example}
%
% \subsubsection*{Normal Usage}
% \begin{example}
%   \ProvidesPackageSVN
%     {$Id: svn-prov.dtx 1862 2010-04-24 14:19:07Z martin $}
%     [v1.0 Example Description]
% \end{example}
% \begin{example}
%   \ProvidesClassSVN
%     {$Id: svn-prov.dtx 1862 2010-04-24 14:19:07Z martin $}
%     [v1.0 Example Description]
% \end{example}
% \begin{example}
%   \ProvidesFileSVN
%     {$Id: svn-prov.dtx 1862 2010-04-24 14:19:07Z martin $}
%     [v1.0 Example Description]
% \end{example}
%
% \subsubsection*{Normal Usage with only Description}
% \begin{example}
%   \ProvidesFileSVN
%     {$Id: svn-prov.dtx 1862 2010-04-24 14:19:07Z martin $}
%     [Example Description]
% \end{example}
%
% \subsubsection*{Normal Usage with separate Version and Description}
% \begin{example}
%   \ProvidesFileSVN
%     {$Id: svn-prov.dtx 1862 2010-04-24 14:19:07Z martin $}
%     [v1.0][Example Description]
% \end{example}
%
% \subsubsection*{Overwriting Name}
% \begin{example}
%   \ProvidesPackageSVN[othername]
%     {$Id: svn-prov.dtx 1862 2010-04-24 14:19:07Z martin $}
%     [v1.0 Example Description]
% \end{example}
%
% \subsubsection*{Overwriting Name including unneeded Extension}
% \begin{example}
%   \ProvidesPackageSVN[othername.sty]
%     {$Id: svn-prov.dtx 1862 2010-04-24 14:19:07Z martin $}
%     [v1.0 Example Description]
% \end{example}
%
% \subsubsection*{Overwriting Name using Macros}
% \begin{example}
%   \ProvidesFileSVN[\filebase.cfg]
%     {$Id: svn-prov.dtx 1862 2010-04-24 14:19:07Z martin $}
%     [v1.0 Example Description]
% \end{example}
%
% \subsubsection*{Using Macros in File Information String}
% \begin{example}
%   \ProvidesPackageSVN
%     {$Id: svn-prov.dtx 1862 2010-04-24 14:19:07Z martin $}
%     [v1.\Rev Example Description]
% \end{example}
%
% \subsubsection*{Adding Text to Default Information}
% \begin{example}
%   \ProvidesPackageSVN
%     {$Id: svn-prov.dtx 1862 2010-04-24 14:19:07Z martin $}
%     [v1.\Rev Extra Text \revinfo]
% \end{example}
%
% \subsection*{Getting the File Information}
% \def\exampleaftertext{results in:}
% \def\ProvidesPackage#1[#2]{}%
%
% \begin{example}
%   \ProvidesPackageSVN
%     {$Id: svn-prov.dtx 1862 2010-04-24 14:19:07Z martin $}
%     [v1.\Rev Extra Text \revinfo]
%   \GetFileInfoSVN*
%   % ...
%   \begin{tabular}{l@{\ :\ \ }l}
%     File Name      & \filename    \\
%     File Base Name & \filebase    \\
%     File Extension & \fileext     \\
%     File Date      & \filedate    \\
%     File Revision  & \filerev     \\
%     File Version   & \fileversion \\
%     File Info      & \fileinfo    \\
%   \end{tabular}
% \end{example}
% \noindent
% The correct package file extension `|.sty|' for \cs{fileext} can be forced by 
% using |[\filebase.sty]| as a first optional argument.
%
% \endgroup
% \StopEventually{}
% \manualnewpage
% \section{Implementation}
%
% \iffalse
%<*package>
% \fi
%
%    \begin{macrocode}
\NeedsTeXFormat{LaTeX2e}[1999/12/01]
%    \end{macrocode}
%
% \begin{macro}{\ProvidesClassSVN}
% Calls the generic macro with the original LaTeX macro and the string to be 
% used as filename.
%    \begin{macrocode}
\def\ProvidesClassSVN{%
  \svnprov@generic\ProvidesClass{\svnprov@filebase@}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ProvidesFileSVN}
% Calls the generic macro with the original LaTeX macro and the string to be 
% used as filename.
%    \begin{macrocode}
\def\ProvidesFileSVN{%
  \svnprov@generic\ProvidesFile{\svnprov@filebase@.\svnprov@fileext@}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\ProvidesPackageSVN}
% Calls the generic macro with the original LaTeX macro and the string to be 
% used as filename.
%    \begin{macrocode}
\def\ProvidesPackageSVN{%
  \svnprov@generic\ProvidesPackage{\svnprov@filebase@}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\svnprov@generic}
% Stores the arguments (1: original macro, 2: file mask (full filename if only 
% base is used?)). Then tests if a explicit file name was given as optional 
% argument.  If not the file name from the SVN Id string is used.
%    \begin{macrocode}
\def\svnprov@generic#1#2{%
  \def\svnprov@ltxprov{#1}%
  \def\svnprov@filemask{#2}%
  \begingroup
  \svnprov@catcodes
  \@ifnextchar{[}%
    {\svnprov@getid}%
    {\svnprov@getid[\svnprov@svnfilename]}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\svnprov@catcodes}
% Sets the normal catcodes for all characters required by the |getid| macro.
%    \begin{macrocode}
\def\svnprov@catcodes{%
  \catcode`\ =10%
  \catcode`\$=3%
  \@makeother\:%
  \@makeother\-%
}
%    \end{macrocode}
% \end{macro}
%
% Enforce normal catcodes for the definition of the |Id| scanning macros.
% This makes sure that all scan patterns have the same catcodes during definition and execution.
%    \begin{macrocode}
\begingroup
\svnprov@catcodes
%    \end{macrocode}
%
% \begin{macro}{\svnprov@getid}
% Saves first argument as filename and calls the scan macro with the second.
% A fall-back string is provided to avoid \TeX\ parsing errors.
%    \begin{macrocode}
\gdef\svnprov@getid[#1]#2{%
  \endgroup
  \def\svnprov@filename{#1}%
  \svnprov@scanid #2\relax $%
    Id: unknown.xxx 0 0000-00-00 00:00:00Z user $\empty\svnprov@endmarker
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\svnprov@scanid}
% Parses the Id string and tests if it is correct (\#1=empty, \#8=\cs{relax}).
% If correct the values are stored in macros and the next macro is called.
% Otherwise a warning message is printed. In both cases any remaining text of 
% the parsing procedure is gobbled before the next step.
% \begin{macrocode}
\gdef\svnprov@scanid#1$%
  Id: #2 #3 #4-#5-#6 #7 $#8{%
  \def\next{%
    \begingroup
    \PackageWarning{svn-prov}{Invalid SVN Id line found! File name might be
    '#2' or '\expandafter\strip@prefix\meaning\@filef@und'. This occured}{}{}{}%
    \endgroup
    \svnprov@gobbleopt
  }%
  \ifx\relax#1\relax
    \ifx\relax#8\empty
      \def\svnprov@svnfilename{#2}%
      \svnprov@splitfilename{#2}%
      \def\svnprov@filerev@{#3}%
      \def\svnprov@filedate@{#4/#5/#6}%
      \def\svnprov@filetoday@{\svnprov@@today{#4}{#5}{#6}}%
      \def\next{\begingroup\svnprov@catcodes\svnprov@buildstring}%
    \fi
  \fi
  \expandafter\next\svnprov@gobblerest
}% $
%    \end{macrocode}
% \end{macro}
%
% End of area with enforced catcodes.
%    \begin{macrocode}
\endgroup
%    \end{macrocode}
%
% \begin{macro}{\svnprov@@today}
% Prints \cs{today} with the given date.
%    \begin{macrocode}
\def\svnprov@@today#1#2#3{%
  {\year#1\month#2\day#3\relax\today}%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\svnprov@splitfilename}
% Expands the argument and initialises the file base macro before it calls the 
% next macro with the expanded argument and a dot to protect for \TeX\ parsing 
% errors. The \cs{relax} is used as end marker.
%    \begin{macrocode}
\def\svnprov@splitfilename#1{%
  \edef\g@tempa{#1}%
  \let\svnprov@filebase@\@gobble
  \expandafter
  \svnprov@splitfilename@\g@tempa.\relax
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\svnprov@splitfilename@}
% The second argument is tested if it is empty (end of file name reached). If 
% not empty the first argument is concatenated to the file base macro and the 
% macro calls itself on the second argument. This ensures correct handling of 
% file name which contain multiple dots.
% 
% If the second argument was empty it is tested if the file base name is still 
% in its initialised state which means that there is no file extension. Then the 
% file base is defined to the first argument and the extension as empty.
% Otherwise the file extension is defined to the first argument and the file 
% base macro is unchanged because it is already correct.
% \begin{macrocode}
\def\svnprov@splitfilename@#1.#2\relax{%
  \if&#2&
    \ifx\svnprov@filebase@\@gobble
      \gdef\svnprov@filebase@{#1}%
      \gdef\svnprov@fileext@{}%
    \else
      \gdef\svnprov@fileext@{#1}%
    \fi
    \let\next\relax
  \else
    \xdef\svnprov@filebase@{\svnprov@filebase@.#1}%
    \def\next{\svnprov@splitfilename@#2\relax}%
  \fi
  \next
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\svnprov@gobblerest}
% Simply gobbles everything up to the next endmarker.
%    \begin{macrocode}
\def\svnprov@gobblerest#1\svnprov@endmarker{}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\svnprov@endmarker}
% This is the end marker which should never be expanded. However it gets defined 
% and set to an unique definition which will gobble itself if ever expanded.
%    \begin{macrocode} 
\def\svnprov@endmarker{\@gobble{svn-prov endmarker}}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\svnprov@gobbleopt}
% Gobbles an optional argument if present.
%    \begin{macrocode}
\newcommand*\svnprov@gobbleopt[1][]{}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\svnprov@defaultdesc}
% Default description text to be used. Does not include the file date which is 
% prepended later.
%    \begin{macrocode}
\def\svnprov@defaultdesc{%
  (SVN Rev:\space\svnprov@filerev@)%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\svnprov@buildstring}
% First aliases the internal macro to user-friendly names and then builds the 
% info string. Finally the stored original LaTeX macro is called with the 
% filename and information.
%    \begin{macrocode}
\newcommand*\svnprov@buildstring[1][\svnprov@defaultdesc]{%
  \@ifnextchar{[}%
    {\svnprov@buildstring@{#1}}%
    {\svnprov@buildstring@{#1}[\relax]}%
}
\def\svnprov@buildstring@#1[#2]{%
  \endgroup
  \begingroup
    \let\rev\svnprov@filerev@
    \let\filerev\svnprov@filerev@
    \def\Rev{\rev\space}%
    \let\revinfo\svnprov@defaultdesc
    \let\filebase\svnprov@filebase@
    \let\fileext\svnprov@fileext@
    \ifx\fileversion\@undefined
      \def\fileversion{v0.0}%
    \fi
    \edef\filename{\filebase.\fileext}%
    \xdef\svnprov@filename{\svnprov@filename}%
    \ifx\svnprov@filename\filename\else
      \svnprov@splitfilename{\svnprov@filename}%
    \fi
    \let\filename\svnprov@filename
    \ifx\relax#2\empty
      \xdef\svnprov@fileinfo@{#1}%
      \svnprov@getversion{#1}%
      \global\let\svnprov@filedesc@\svnprov@filedesc@
      \global\let\svnprov@fileinfo@\svnprov@fileinfo@
    \else
      \xdef\svnprov@fileversion@{#1}%
      \xdef\svnprov@filedesc@{#2}%
      \xdef\svnprov@fileinfo@{#1 #2}%
    \fi
  \endgroup
  \svnprov@ltxprov{\svnprov@filemask}%
    [\svnprov@filedate@
     \ifx\svnprov@fileinfo@\empty\else
      \space
      \svnprov@fileinfo@
     \fi
   ]%
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\GetFileInfoSVN}
% \changes{v3.}{2010/04/01}{Added non-star version.}
% The macro provides the file information of the given file, or (the star version) the last file which called one of the above \cs{Provides\ldots} macros.
% For this the internal macros are simply copied to user-friendly names.
%
% This macro is inspired by the macro \cs{GetFileInfo}\marg{file name} from the 
% \texttt{doc} package.
%    \begin{macrocode}
\def\GetFileInfoSVN#1{%
  \ifx*#1\relax
    \let\filebase\svnprov@filebase@
    \let\fileext\svnprov@fileext@
    \let\filename\svnprov@filename
    \let\filedate\svnprov@filedate@
    \let\filerev\svnprov@filerev@
    \let\fileversion\svnprov@fileversion@
    \let\fileinfo\svnprov@filedesc@
    \let\filetoday\svnprov@filetoday@
  \else
%    \end{macrocode}
% Given argument could be filename or short name.
% If a short name exists for the argument it was a filename is is defined as such,
% otherwise the filename is read from the |\|\meta{short name}|@long| macro.
%    \begin{macrocode}
    \expandafter\let\expandafter\@gtempa\csname#1@short\endcsname%
    \ifx\@gtempa\relax
      \def\@gtempa{#1}%
      \expandafter\let\expandafter\filename\csname#1@long\endcsname
    \else
      \edef\filename{#1}%
    \fi
    \expandafter\let\expandafter\filebase\csname\@gtempa @base\endcsname
    \expandafter\let\expandafter\fileext \csname\@gtempa @ext\endcsname
    \expandafter\let\expandafter\filedate\csname\@gtempa @date\endcsname
    \expandafter\let\expandafter\filerev \csname\@gtempa @rev\endcsname
    \expandafter\let\expandafter\fileversion\csname\@gtempa @version\endcsname
    \expandafter\let\expandafter\fileinfo\csname\@gtempa @info\endcsname
    \expandafter\let\expandafter\filetoday\csname\@gtempa @today\endcsname
  \fi
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\DefineFileInfoSVN}
% Defines macros in the form |\|\meta{filename}|@|\meta{xxx}, where \meta{xxx} is |date|, |version|, |rev|(ision), |info|, (file name)|base| and |ext|(ension).
% \changes{v3.}{2010/04/01}{Added file name `base' and 'ext'(ension).}
%    \begin{macrocode}
\newcommand*\DefineFileInfoSVN[1][\svnprov@filemask]{%
  \expandafter
  \edef\csname\svnprov@filemask @short\endcsname{#1}%
  \expandafter
  \edef\csname#1@long\endcsname{\svnprov@filemask}%
  \expandafter
  \let\csname#1@base\endcsname\svnprov@filebase@
  \expandafter
  \let\csname#1@ext\endcsname\svnprov@fileext@
  \expandafter
  \let\csname#1@date\endcsname\svnprov@filedate@
  \expandafter
  \let\csname#1@version\endcsname\svnprov@fileversion@
  \expandafter
  \let\csname#1@rev\endcsname\svnprov@filerev@
  \expandafter
  \let\csname#1@info\endcsname\svnprov@filedesc@
  \expandafter
  \let\csname#1@today\endcsname\svnprov@filetoday@
}
%    \end{macrocode}
% \end{macro}
%
% \begin{macro}{\svnprov@getversion}
% Checks if the argument (a file description) starts with `|v|'. If so
% everything until the first space is taken as version number. Otherwise
% the whole text is taken as description without version.
% Special care is taken to avoid a parser error if there is no space included.
% \changes{v3.}{2010/04/01}{Changed to look for leading `v' not just everything up to the first space.}
%    \begin{macrocode}
\def\svnprov@getversion#1{%
  \edef\@tempa{#1\space}%
  \expandafter\svnprov@@getversion\@tempa\svnprov@endmarker
}
\def\svnprov@@getversion{%
  \@ifnextchar{v}%
    {\svnprov@getversion@}%
    {\svnprov@getversion@@}%
}
\def\svnprov@getversion@#1 #2\svnprov@endmarker{%
  \gdef\svnprov@fileversion@{#1}%
  \ifx&#2&%
    \gdef\svnprov@filedesc@{}%
  \else
    \xdef\svnprov@filedesc@{\svnprov@zapspace#2\svnprov@endmarker}%
  \fi
}
\def\svnprov@getversion@@#1 \svnprov@endmarker{%
  \gdef\svnprov@fileversion@{}%
  \gdef\svnprov@filedesc@{#1}%
}
\def\svnprov@zapspace#1 \svnprov@endmarker{#1}
%    \end{macrocode}
% \end{macro}
%
% Finally, call the macros for this package itself.
%    \begin{macrocode}
\ProvidesPackageSVN{$Id: svn-prov.dtx 1862 2010-04-24 14:19:07Z martin $}%
  [\svnprov@version\space Package Date/Version from SVN Keywords]
\DefineFileInfoSVN[svnprov]
%    \end{macrocode}
%
% \iffalse
%</package>
% \fi
%
% \Finale

