%******************************************************************************
% File:     @(#)$OrigId: docversion-RCS.def,v 1.5 2016-11-05 14:16:06+01 martin Rel $
% Contents: Extension macros for the "docversion" package: support for the
%	    Revision Control System (RCS) and other version control systems
%	    with syntactically identical substitution strings
% Author:   Martin Lottermoser (Martin.Lottermoser at t-online.de)
%
%******************************************************************************
%
%	Copyright (C) Martin Lottermoser, 2009-2016
%	This file may be used under the same terms as any version of my
%	"docversion" package.
%
%******************************************************************************

% Version information
\ProvidesFile{docversion-RCS.def}[2016/11/05 Docversion extension for RCS]
\ifx\@undefined\sourceidentification\else\sourceidentification{\whatstring
  $OrigId: docversion-RCS.def,v 1.5 2016-11-05 14:16:06+01 martin Rel $}\fi

% Set CM-system-specific defaults
\setdefaultdocversionid{0.0}

% Helper macro to extract date and time information from an RCS "Date" value
\newcommand*{\rcs@parseDateAndTime}[2]{%
  % Date:
  \def\rcs@tempa##1/##2\rcs@end{\def\rcs@tempb{##2}}%
  \rcs@tempa#1/\rcs@end
  \ifx\rcs@tempb\@empty
    \def\rcs@tempa##1-##2-##3\rcs@end{##1##2##3}%
  \else
    \def\rcs@tempa##1/##2/##3\rcs@end{##1##2##3}%
  \fi
  \edef\rcs@versiondate{\rcs@tempa#1\rcs@end}%
  % Time:
  \def\rcs@tempa##1:##2:##3##4##5\rcs@end{%
    \edef\rcs@versiontime{##1##2##3##4}%
    \edef\rcs@versiontimezone{##5}%	empty, [-+]dd, or [-+]dd:dd
  }%
  \rcs@tempa#2\rcs@end
  % Convert RCS time zone specification to docversion format
  \ifx\@empty\rcs@versiontimezone \def\rcs@versiontimezone{+0000}\else
    \def\rcs@tempa##1:##2\rcs@end{\def\rcs@tempb{##2}}%
    \expandafter\rcs@tempa\rcs@versiontimezone:\rcs@end
    \ifx\@empty\rcs@tempb \edef\rcs@versiontimezone{\rcs@versiontimezone00}\else
      \def\rcs@tempa##1:##2\rcs@end{\edef\rcs@versiontimezone{##1##2}}%
      \expandafter\rcs@tempa\rcs@versiontimezone\rcs@end
    \fi
  \fi
}

% The macro |\setfileinfoRCS| expects an ordinary "Id" substitution string as
% its first argument (although the actual keyword is irrelevant), including
% the "$" delimiters. The value may either be the empty variant (i.e., without
% a colon) or it should be the full version (<RCS file> <revision> <date>
% <time> <user> <state> [<locker>]), except that it's also acceptable if the
% <state> field is missing as well (the "keyword" extension for Mercurial omits
% both, <state> and <locker>, in its default configuration).
\newcommand*{\setfileinfoRCS}[1]{%
  \def\rcs@file{}\def\rcs@beingedited{true}%
  \def\rcs@versionid{\dv@noversion}\def\rcs@versiondate{00000101}%
  \def\rcs@versiontime{000000}\edef\rcs@versiontimezone{\docversiontimezone}%
  \def\rcs@state{Exp}%	RCS default
  \def\rcs@tempa##1:##2\rcs@end{\def\rcs@tempb{##2}}%
  \rcs@tempa#1:\rcs@end
  \ifx\rcs@tempb\@empty\else
    \def\rcs@tempa$##1: ##2,v ##3 ##4 ##5 ##6 ##7$\rcs@end{%
      \def\rcs@file{##2}\def\rcs@versionid{##3}\rcs@parseDateAndTime{##4}{##5}%
      \def\rcs@tempb{##7}}%
    \rcs@tempa#1\rcs@end
    \ifx\rcs@tempb\@empty \def\rcs@beingedited{false}\else
      % Standard RCS notation with state and possibly locker; \rcs@temb will
      % always have a trailing space (a fact which we need here).
      \def\rcs@tempa##1 ##2\rcs@end{\def\rcs@state{##1}\def\rcs@tempb{##2}}%
      \expandafter\rcs@tempa\rcs@tempb\rcs@end
      \ifx\rcs@tempb\@empty \def\rcs@beingedited{false}\fi
    \fi
  \fi
  \setfileinfo{\rcs@file}{\rcs@beingedited}{\rcs@versionid}{false}%
    {\rcs@versiontimezone}{\rcs@versiondate}{\rcs@versiontime}}

% The following macro is intended to receive a substitution string with the
% "Name" keyword as its argument. It is a replacement for the \setdocversionid
% macro and should be called in the preamble. Note that, although RCS generates
% two spaces for an empty name, TeX will collapse them into a single space
% token.
\newcommand*{\setdocversionidfromRCSName}[1]{%
  \def\rcs@tempa##1:##2\rcs@end{\def\rcs@tempb{##2}}%
  \rcs@tempa#1:\rcs@end
  \def\rcs@docversionid{\dv@noversion}%
  \ifx\rcs@tempb\@empty\else
    \def\rcs@tempa$##1: ##2$\rcs@end{\def\rcs@tempb{##2}}%
    \rcs@tempa#1\rcs@end
    \ifx\@empty\rcs@tempb\else
      \def\rcs@tempa$##1: ##2 $\rcs@end{\def\rcs@tempb{##2}}%
      \rcs@tempa#1\rcs@end
      \def\rcs@docversionid{\rcs@tempb}\fi\fi
  \setdocversionid[false]{\rcs@docversionid}}

\endinput
% vim: set syntax=tex :
