Beruflich Dokumente
Kultur Dokumente
\documentclass{progltx}
\usepackage{rcs-doc}
\usepackage{path}
\usepackage{alltt}
\usepackage{fullpage}
\RCS $StyleDate: 2003/02/02 20:42:38 $
\begin{document}
\title{The \texttt{rcs} Package\\
{\large (Implementation)}%
}
\author{%
% LaTeX does not discard unnecessary glue...
Joachim Schrod%
\thanks{%
\protect\raggedright
R\"odermark, Germany.
Email: \texttt{jschrod@acm.org}%
}%
}
\date{%
Revision \RCSStyleRevision\\
(as of \RCSStyleDate)%
}
\maketitle
% -----------------------------------------------------------%
% subdocument: The user interface of rcs.sty
%
\input{rcs-user}
%
% -----------------------------------------------------------%
% subdocument: The internal interface
%
\input{rcs-conf}
%
% ------------------------------------------------------------
\chap Implementation.
This module reserves the namespace |rcs|.
\beginprog
\ifx \rcs@loaded\undefined
\def\rcs@loaded{$StyleRevision: 2.10 $}
\else
\PackageWarningNoLine{rcs}%
{Some other package already uses namespace `rcs'}
\fi
\endprog
\sect Let's identify this package.
Now I'm caught in a catch-22 situation. The code below---part of my
standard templates for \LaTeX{} packages---uses principles that are
explained later in this document. In particular, the explanation how
the information from the following RCS fields are gathered starts at
chunk~\ref{chunk:value-split}.
There you'll find also the explanation for the funny strings behind
the RCS fields. Actually, I would not need them any more, they make
the initial document (before the first check-in) work. But they won't
be discarded in this package source, as they'll demonstrate another
utilization of RCS at work.
\beginprog
\begingroup
\def\RCSPackage#1#2 $#3: #4 #5\endRCS $#6: #7 #8\endRCS{%
\def\date{#4}\def\id{v#7}%
\ProvidesPackage{#1}[\date\space\id\space #2]%
}
\RCSPackage{rcs}{typeset info from RCS fields}
$StyleDate: 2003/02/02 20:42:38 $: 9999/00/00 \endRCS
$StyleRevision: 2.10 $: 0.0 \endRCS
\endgroup
\endprog
\sect This module is supported. Send bug reports, comments, and
repairs.
The reference version may be retrieved via anonymous ftp from CTAN,
directory \path|/tex-archive/macros/latex/contrib/supported/rcs|.
\sect This is freely distributable software; you can redistribute it
and/or modify it under the terms of the GNU General Public License
(version~2) as published by the Free Software Foundation.
This software is distributed in the hope that it will be useful, but
\textbf{without any warranty}; without even the implied warranty of
\textbf{merchantability} or \textbf{fitness for a particular purpose}.
See the GNU General Public License for more details.
You should have received a copy of the GNU General Public License in
the file |License| along with this package; if not, write to the Free
Software Foundation, Inc., 675~Mass Ave, Cambridge, MA~02139,~USA.
\sect Before we start we declare some shorthands for category codes.
By declaring the underscore~`(|_|)' as letter we can use it in our
macros. (I agree with {\sc D.~Knuth} that
|\identifier_several_words_long| is more readable than
|\IdentifierSeveralWordsLong| and in every case better than
|\p@@@s|.) As this is a \LaTeX{} style option the at sign is a letter
anyhow; so we can use the ``private'' Plain and \LaTeX{} macros; and
with the underscore we can make our own macros more readable. But as
we have to restore this category code at the end of this macro file
we store its former value in the control sequence |\CatUsCode|. This
method is better than to use a group because not all macros have to
be defined global this way.
\beginprog
\ifx \CatEscape\undefined
\chardef\CatEscape=0
\chardef\CatOpen=1
\chardef\CatClose=2
\chardef\CatIgnore=9
\chardef\CatLetter=11
\chardef\CatOther=12
\chardef\CatActive=13
\chardef\CatUsCode=\catcode`\_
\fi
\catcode`\_=\CatLetter
\endprog
|\RCS $|Keyword\/|$|\\
|\RCS $|Keyword\/\verb*|: |value\/\verb*| $|
\end{quote}
%
where \textit{Keyword} and \textit{value} may be arbitrary strings. In
fact, we assume that \textit{Keyword} is a sequence of letters---only
then the creation of a cseq |\RCS|\textit{Keyword} is sensible. Our
implementation will not produce an error with an obscure keyword, but
the result will not be of use for the author.
We must not depend on a fixed set of keywords, this style shall be
usable with a configurable RCS version. In such a version one can
bind arbitrary keywords to the information available in RCS\@. This
means we will parse all RCS fields with the same macro,
|\rcs_split_field|. This macro will place its results in two macros:
|\RCS_keyword| and |\RCS_value|. Afterwards we can bind the expansion
of |\RCS_value| to the target cseq.
\sect |\RCS_value| will be set to the expansion of |\RcsEmptyValue|
if there was no RCS value available, i.e., if the field was not
processed by RCS yet. This way the values of non-expanded RCS fields
can be configured. The default value is the empty token list.
\beginprog
\def\RcsEmptyValue{}
\endprog
\sect For those fields where a special handling is demanded, a cseq
|\RcsHandle|\textit{Keyword} must exist. This cseq must handle the
parsing of the value. Usually this means that it will create a macro
named |\RCS|\textit{Keyword} with a transformed (or filtered) value.
If you happen to write a handler you might want to look at the
definition of |\RcsHandleDate| starting at section~\ref{sec:date}
If a special handler for a field exists, the original value is
placed automatically in the macro |\RCSRaw|\textit{Keyword}. This is done
before the handler is called.
\sect \label{chunk:value-split} The macro
|\rcs_split_field| will split the field into |\RCS_keyword| and
|\RCS_value|. This split is done by the argument parsing capability
of \TeX{}: We can separate parameters by token lists and \TeX{} will
use a shortest pattern match to determine the arguments.
Let's look what kind of pattern we can use. As an example we use the
RCS field `\verb*|$Revision: 2.11 $|', i.e., the unexpanded field is
`|$Revision: 2.11 $|'. The macro |\RCS| will use dollars to delimit its
argument, we don't need to worry for them. Eventually we'll have to
discard the space of the expanded field's value---after all,
|\RCSRevision| shall expand to `1.1', not to `1.1~'.
First, we can see that the token list $\it (colon, space)$ may be used
as the seperator of keyword and value:
%
\begin{quote}
\macroCall{\\rcs_split_field \[Revision\(: \)1.1 \]\\end_value}
\end{quote}
%
($d_i$ is the separating token list between parameter $i$ and~$i+1$.
%
($p_3$, the third parameter will be empty in this case.)
\medskip
\noindent As explained above: if the value does not exist, a default
value is supplied.
\beginprog
\def\rcs_split_field #1: #2 :#3\end_value{%
\def\RCS_keyword{#1}%
\def\RCS_value{#2}%
\ifx \RCS_value\empty
\let\RCS_value\RcsEmptyValue
\fi
}
\endprog
\sect |\RCS| triggers the split. After it has occured, we can bind the
expansion of |\RCS_value| to a new name. This name is constructed from
the prefix |RCS|, the string |Raw| iff a handle for this field exists,
and the keyword itself.
Afterwards we call the handle, on non-existance this will be a no-op.
Gathering the field is a bit more complicated, as we need to pay
attention to underscores in file names.
\beginprog
\def\RCS{%
\bgroup
\catcode`\_ \CatActive
\RCS_get_argument
}
\def\RCS_get_argument $#1${%
\gdef\RCS_argument{#1}%
\egroup
\RCS_process
}
\def\RCS_process{%
\expandafter\rcs_split_field \RCS_argument: {} :\end_value
\expandafter\let \csname RCS\rcs_raw_if_handle\RCS_keyword\endcsname
\RCS_value
\csname RcsHandle\RCS_keyword\endcsname
}
\def\rcs_raw_if_handle{%
\@ifundefined{RcsHandle\RCS_keyword}{}{Raw}%
}
\endprog
Certain RCS versions (one of them created at our site) allow the
configuration of the used keywords. I.e., there might be another
keyword used for this field, but we still want to use the
functionality provided here.
For example, let's assume the keyword of the \Date{} field is
|StyleDate|. Then the assignment
%
\begin{quote}
|\let\RcsHandleStyleDate=\RcsHandleDate|
\end{quote}
%
is all that's needed to turn on the `date special handling' for this
field. (In fact, that's done in this style file you're reading.)
\sect The special handler for \Date{} fields sets up
|\RCS|\textit{Keyword} (|\RCSDate| usually) to produce a textual
representation of the date part of the \Date{} value in a
|\today|-like format. Thus the constructed tag can be used in many
circumstances, e.g., as the argument of the |\date| tag on the
titlepage.
In addition, |\RCSTime| is defined; it expands to the checkin time.
If the value is empty, i.e., if there's no \Date{} value from RCS
available, we use the current date. Later we might supply the current
time, too---currently |\RCSTime| expands to an empty token list in
such a case.
Of course, this whole special handling is only done if |\today| is
defined in some way; otherwise we just handle the \Date{} field like
every other RCS field: The value is stored unfiltered in
|\RCS|\textit{Keyword}.
\beginprog
\def\RcsHandleDate{%
\ifx \today\undefined
\expandafter\let \csname RCS\RCS_keyword\endcsname \RCS_value
\else
\ifx \RCS_value\RcsEmptyValue
\@namedef{RCS\RCS_keyword}{\today}%
\let\RCSTime\empty
\else
\expandafter\rcs_set_date \RCS_value\end_date
\fi
\fi
}
\endprog
\sect If the value is not empty we split it using the argument parsing
mechanism of \TeX{}. Then we'll define the value using the current
definition of |\today|. This way language-specific styles (e.g., from
the \textsf{babel} system) may supply their own way to present a date.
\beginprog
\def\rcs_set_date #1/#2/#3 #4\end_date{%
\begingroup
\day #3
% <-- space!
\month #2
% <-- space!
\year #1
% <-- space!
\beginprog
\def\rcsAuthor#1#2{\@namedef{rcs_author:#1}{#2}}
\def\RCS_get_author#1{%
\@ifundefined{rcs_author:#1}{#1}{\@nameuse{rcs_author:#1}}%
}
\endprog
\sect Since this style option shall be usable with many styles, we
must provide means to configure its behaviour. In particular, it must
be possible to configure the layout. What remains fixed, is the layout
of the log like a |description| list. I might add this flexibility if
there is enough interest (or if somebody sends me tested changes).
The first thing to parametrize is the overall layout and the header.
This is set up by |\RcsLogStyle|. This cseq \emph{must} define
|\RcsLogHeading|, which is the macro to set the header. E.g., here
one could insert a |\newpage| to start a new page for the revision log.
In addition, we reduce the base size of the log. That's the reason why
these two configurations are combined in one macro---if you change
one, you also have to consider to change the other.
\beginprog
\def\RcsLogStyle{%
\def\RcsLogHeading{\subsubsection*}%
\footnotesize
}
\endprog
\sect The header itself is created by |\rcs_log_hdr|, which is called
with the expanded \Log{} value as its argument, terminated by
|\end_value|. We use \TeX{}'s parameter parsing mechanism to chop off
the tail of the value---if the value exists, it always ends in~`|,v|'.
Since only an existing value ends in~`|,v|', we have to supply a
fitting empty value. We will use |\rcs_empty_log_value| for that.
The empty log value gets a bit more complicated: If we have an empty
\Log{} value, we will not have any revision entries. (Well, except in
pathological cases. Then we will produce spurious text.) Missing
revision entries are missing items; since \LaTeX{} will complain
about a missing |\item|, we must provide one to stop it from doing
so. But here is no place for such tokens, the list environment hasn't
started yet. We will set the flag |@rcs_empty_log@| and check this
flag after we invoked the list.
\beginprog
\def\rcs_log_hdr#1,v\end_value{%
\@rcs_empty_log@false
\RcsLogHeading{\RcsLogHeadingName #1}%
\the\rcsLogIntro
}
\def\rcs_empty_log_value{%
\global\@rcs_empty_log@true
% that's most probably in a group!
\RcsUnknownFile
% text for unknown file name
,v%
% assert calling env
}
\newif\if@rcs_empty_log@
\endprog
\sect The user might want to adapt the text output. He can do so by
redefining |\RcsLogHeadingName|, |\RcsUnknownFile|, and |\RcsEmptyLog|.
\beginprog
\def\RcsLogHeadingName{Revision Log for \ttfamily} % file name in monospace
\def\RcsUnknownFile{\rmfamily\mdseries $\langle\,$Unknown file name$\,\rangle$}
\def\RcsEmptyLog{{\itshape No log entries available.}}
\endprog
\sect OK, we have fixed the header, let's address the entries. Each
entry is typeset by |\RcsLogRevision| which is called with four
arguments: (1)~the revision number, (2)~the checkin date, (3)~the
checkin time, and (4)~the uid of the author.
Such an entry is inserted as an item in the list. The uid is
transformed to an author name, if the respective information is
available. The checkin timestamp is mapped to a neater appearance by
|\RcsLogDate| and |\RcsLogTime|.
\beginprog
\def\RcsLogRevision#1#2#3#4{%
\item [Revision #1]%
(created at \RcsLogDate #2\endDate\space \RcsLogTime{#3} % <-- space!
by \RCS_get_author{#4})\\\relax
}
\endprog
\sect |\RcsLogDate| sets the date. We can use \TeX{}'s parameter parsing
mechanism to separate the date value (passed as the argument) in its
sub-values. The code is very similar to |\rcs_set_date|.
|\RcsLogTime| sets the time. As explained in the user manual, the time
is ignored usually. (I don't think that this info is relevant in a
printout.) Here we assume something about the context it's expanded
in: Spaces will be before and after the tag. One of them must be
discarded. The user option |\settime| is implemented here as a
private macro, too.
\beginprog
\def\RcsLogDate #1/#2/#3\endDate{%
\begingroup
\day #3
% <-- space!
\month #2
% <-- space!
\year #1
% <-- space!
\today
\endgroup
}
\def\RcsLogTime#1{\ignorespaces}
\def\rcs_settime{%
\def\RcsLogTime##1{[##1]}%
}
\endprog
\sect Well, that are all possibilities to configure the revision log.
Let's put together the pieces. Within the |rcslog| environment the
tags |\Revision| and |\settime| are used, they are implemented in
the |rcs| namespace.
At the start, we use the optional argument of the environment to
configure it. |\settime| might be placed here, or font switches, etc.
The next entity shall be the \Log{} field. In fact, it shall be on
the next line. If an optional environment argument was there, the
newline is still in the input and must be discarded before we can use
|\RCS| to parse the field.
\beginprog
\def\rcslog{%
\@ifnextchar[%
\rcslog_configure
{\rcslog_configure[]}%
}
\def\rcslog_configure[#1]{%
\let\Revision\rcslog_revision
\let\settime\rcs_settime
\RcsLogStyle
#1%
\afterassignment\rcslog_skipcr
\let\next
}
\endprog
% ] (Emacs)
\begingroup
\obeylines
\rcslog_gobble_line
}
\begingroup
\obeylines
\gdef\rcslog_gobble_line #1^^M{%
\endgroup%
\afterassignment\rcslog_skipcr%
\let\next%
}
\endgroup
\endprog
\sect Yep, we've reached a dollar; let's hope that it's our \Log{}
field. It must be on one line, this line is fetched first and then
analyzed.
\beginprog
\def\rcslog_field{%
\begingroup
\obeylines
\catcode`\_ \CatActive
\rcslog_get_field
}
\begingroup
\obeylines
\gdef\rcslog_get_field $#1$^^M{%
\gdef\RCS_argument{#1}%
\endgroup%
\rcslog_set_field%
}
\endgroup
\endprog
\sect When we analyze the \Log{} field, we must supply the default
value. Within the log list there will be no other RCS fields,
therefore we can redefine |\RcsEmptyValue| in this environment.
The header gets passed the expanded \Log{} value, as explained above.
We use |\RCS_value| instead of |\RCSLog| since we don't know which
RCS keyword is used.
At last, we start the list and check the |@rcs_empty_log@| flag,
perhaps we have to supply a dummy |\item|.
\beginprog
\def\rcslog_set_field{%
\let\RcsEmptyValue\rcs_empty_log_value
\RCS_process
\expandafter\rcs_log_hdr \RCS_value\end_value
\list{}\RcsLogListStyle
% empty label, layout configurable
\if@rcs_empty_log@
\item []\RcsEmptyLog
% supply missing item
\fi
}
\endprog
\sect The setup of the log list is done by a macro from the protected
interface, the user shall be able to change it. In the default
supplied, there is no skip between paragraphs, but a quad indentation.
|rcslog| is here no list environment in the sense like |itemize| or
|enumerate|, therefore a usage of these environments within an entry
shall result in top-level item markers.
\textbf{Caveat}:\quad Since we globally set |\@listdepth| at the start
of the environment, we must not execute |\endlist| that decrements it.
Instead we use |\endtrivlist| for the termination of the |rcslog|
environment. It might be, that this must be changed if
|\RcsLogListStyle| is changed.
\beginprog
\def\RcsLogListStyle{%
\global\@listdepth\z@
\labelwidth\z@
\itemindent -\leftmargin
\advance\itemindent \labelsep
\def\makelabel##1{\bf ##1}%
\parsep\z@skip
\listparindent 1em
}%
%
%
%
%
%
%
\let\endrcslog\endtrivlist
\endprog
\sect The arguments of |\Revision| are separated by spaces and
terminated by the end of the line. We have to fetch them, then we can
pass them to |\RcsLogRevision| which does the real work.
\beginprog
\def\rcslog_revision{%
\begingroup
\obeylines
\rcslog_get_revinfo
}
\begingroup
\obeylines
\gdef\rcslog_get_revinfo #1 #2 #3 #4^^M{%
\endgroup%
\RcsLogRevision{#1}{#2}{#3}{#4}%
}
\endgroup
\endprog
\def\RCSdate $#1${%
\RCS $#1$%
\expandafter\date \expandafter{\csname RCS\RCS_keyword\endcsname}%
}
\endprog
\sect |\RCSID| parses the RCS field and redefines the footline. This
tag is from Nelson's |rcs| style. In his style he defines that the RCS
field is passed as an argument to the macro. To be upward compatible,
we have to support this as well: We look at the next token, if it is
an opening brace we fetch the param and trigger the `real' invocation
by |\rcs_id|. If no brace follows, we call |\rcs_id| immediately.
\beginprog
\def\RCSID{%
\@ifnextchar\bgroup
\rcsid_get_field
\rcs_id
}
\def\rcsid_get_field#1{\rcs_id #1}
\endprog
\sect As a side effect, we'll produce the normal value tags. When we
define the footline, we must assert that |\RCS_keyword| and
|\RCS_value| are expanded. (They will get new bindings at the next
invocation of |\RCS|.) All other macros must not be expanded, they
shall be used in the context of the footline, not in our definition
context. We utilize |\protect| for that, |\framebox| is the only macro
that must be protected.
\beginprog
\def\rcs_id $#1${%
\RCS $#1$%
\begingroup
\let\protect\noexpand
\xdef\@oddfoot{%
\reset@font
\protect\framebox[\textwidth]{\RCS_keyword: \RCS_value}%
}%
\endgroup
\global\let\@evenfoot\@oddfoot
}
\endprog
\sect |\RCSdef| just outputs its parameter before it's passed to
|\RCS|. This tag is from Tom Verhoeff's |rcs| style. In fact, we're
not fully compatible: Tom did output `RCS keyword string'. I
substitute this by `RCS field', this is consistent with the rest of
this style's description.
\beginprog
\def\RCSdef $#1${%
\typeout{RCS field: $#1$}%
\RCS $#1$%
}
\endprog
\vskip \PltxPreSectSkip
\rcsLogIntro{Of course, we shouldn't stop without the RCS log of this
style file.}
\begin{rcslog}
$StyleLog: rcs.doc,v $
\Revision 2.10 2003/02/02 20:42:38 schrod
Support underscores in file names in RCS field values. E.g., in
\rcsField{Id} or \Log{}.
Update my contact information.
\Revision 2.9 1995/08/02 12:09:07 schrod
Transformed this style option into a \LaTeXe{} package.
Updated to \LaTeXe{}.
\end{document}
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
Local Variables:
mode: LaTeX
TeX-brace-indent-level: 4
indent-tabs-mode: t
TeX-auto-untabify: nil
TeX-auto-regexp-list: LaTeX-auto-regexp-list
End: