[comp.text] Printing file modification date in *roff.

roger@gtisqr.uucp (Roger Droz) (05/30/90)

I am always forgetting to change the revision date when I modify a
document, so I wonder if there is a way to automatically date a file
with its modification date.

I don't think that nroff has access to the name of the file it is
processing, so I don't think that nroff has any information it can use
to ask the system for a modification date.  

Since most documents I want to date are maintained using rcs(1), it
should be possible to reformat the ouput of the rcs $Date$ macro to
something that looks nicer than:

	$Date: 90/05/29 12:07:53 $

I am thinking in terms of a few commands, or perhaps a macro, that can
be placed at the beginning of the file to translate the above string
into an nroff string that contains the date as month/day/year.

	.\" include my favorite macros
	.so format.n	
	.\" RCS expands $Date$ as above; 
	.\" macro translates it to mm/dd/yy in string dT.
	.mymacro $Date$

    	Last revised on \*(dT

Perhaps there is a wizzard on the net who has already done this.  I'm
enough of a novice at writing nroff macros that its quicker to ask the
net than to RTM and come up the learning curve.
____________
               Roger Droz       UUCP: uw-beaver!gtisqr!roger
()       ()    Maverick MICRoSystems / Global Technology International
 (_______)     Mukilteo, WA 
  (     )      
   |   |       Disclaimer: "We're all mavericks here: 
   |   |                    Each of us has our own opinions,
   (___)                    and the company has yet different ones!"

jeff@ism780c.isc.com (Jeff Copeland) (06/01/90)

In article <1990May30.163357.6070@gtisqr.uucp> roger@gtisqr.UUCP (Roger Droz) writes:
>I am always forgetting to change the revision date when I modify a
>document, so I wonder if there is a way to automatically date a file
>with its modification date.

There is actually a fairly general way to do this with the .sy troff
directive, and the ls command, but because you use RCS, the problem is a
lot simpler:

In simplest form, add a macro like:
	.de rD
	This document last revised on \\$2.
	..
and then include the text:
	.rD $Date$
in your document where you want the revision date to appear.

Alternately, if you want to rearrange the yy/mm/dd format RCS forces you to
use, try something like:
    .de DT\" get the date out of the RCS Header line
    .if !"\\$7"Locked" \{\
    .tr / 
    .de NR
    .br
    .nr yr \\\\$1
    .nr mo \\\\$2
    .nr dy \\\\$3
    \\..
    .di X
    \\!.NR \\$4
    .di
    .X
    .rm X NR
    .tr //
    .\}
    ..

This macro sets the troff number registers for the date.  It expects a
$Header$ line rather than a $Date$ line, so that if the file is locked, it
takes no action and today's date is used instead.  Defining a macro on the
fly and then diverting the macro breaks out the components of the date by
translating the / to a blank.  The macro is used like this:
    .\" setup the date
    .DT $Header: rr,v 1.4 90/03/23 16:43:47 jeff Exp $
    .ie \n(mo-11 \n(dy December 19\n(yr
    .el .ie \n(mo-10 \n(dy November 19\n(yr
    .el .ie \n(mo-9  \n(dy October 19\n(yr
    .el .ie \n(mo-8  \n(dy September 19\n(yr
    .el .ie \n(mo-7  \n(dy August 19\n(yr
    .el .ie \n(mo-6  \n(dy July 19\n(yr
    .el .ie \n(mo-5  \n(dy June 19\n(yr
    .el .ie \n(mo-4  \n(dy May 19\n(yr
    .el .ie \n(mo-3  \n(dy April 19\n(yr
    .el .ie \n(mo-2  \n(dy March 19\n(yr
    .el .ie \n(mo-1  \n(dy February 19\n(yr
    .el \n(dy January 19\n(yr

Enjoy.