[net.sources] SCCS to RCS convertor

phil@sequel.UUCP (08/30/83)

Shit, this must be the 10th copy of this article I have seen.
Would news administrators get their *..it* together!  This is
as bad as the pur-ee!davey stuff... GRRRR.........
-- 
.> Phil Hochstetler 	(503) 627-9811
.> Sequel Computer Systems, Inc
.> 14360 NW Science Park Drive
.> Portland, OR 97229
.> {unisoft,pur-ee,nsc,ogcvax,rocks34,cdi,vax135,verdix,shell}!sequel!phil

rich@cfib.UUCP (08/30/83)

#N:cfib:10100003:000:7555
cfib!rich    Aug 25 17:10:00 1983

For those of you contemplating switching from SCCS to RCS, this should
make your job somewhat easier.  RCS is a much nicer system, easier to
use, etc., etc.  If you do not have RCS but are interested, it should
be coming on the 4.2BSD tape.  Alternatively, contact:

    Walter F. Tichy
    Purdue University
    West Layfayette, IN 47907

    purdue!tichy

This will create a csh script and C program that converts sccs files
to rcs files, preserving all back versions, their numbers, their access
dates, and comments.  A line in the source file that matches the regular
expression
    /.*static char sid.*/
is replaced with the appropriate rcs string 'static char sid[]="$Header$";'.

If called with the -l flag, an rcs "$Log$" line is placed immediately
before the first line containing a closing C comment metastring in the
first column (i.e., "/^\*\/$/").

Requirements:
    SCCS system (including 'prs' command from System III)
    RCS system (version 3.0 or later)
    touch (need System III version to set dates on files) (OPTIONAL)
    LOTS of time - this runs very slowly.  Suggest you run it in
	background with stdout and stderr routed to a file so you can
	check it later for error messages.

CAUTION:
    No guarantee is granted as to the reliability of the conversion - I
    wrote this for the way we used sccs (formerly) and use rcs (now).
    We converted over 50 sccs files with no problems.

Example:
    If you have two sccs files called 's.foo.c' and 's.mumble.c',

	csh -f sccstorcs.csh s.foo.c s.mumble.c

    will create the files 'foo.c,v' and 'mumble.c,v' with access/modification
    times the same as their corresponding sccs files (so the next 'make' will
    not recompile the world).  It will also leave the original sccs files
    intact - these should be deleted after checking the rcs files.

The last file is a set of 'make' (S.III) rules for rcs.

Send flaming criticisms to /dev/null; constructive suggestions or
improvements to:

	Rich Baughman
	The Consumer Financial Institute
	...!ima!cfib!rich


RUN THE BOURNE SHELL AGAINST THE REST OF THIS FILE TO PRODUCE THE DESIRED
FILES; then compile ftime.c and you are ready to run.
	
***********************************************************************
# The rest of this file is a shell script which will extract:
# sccstorcs.csh ftime.c makefile.rcs
echo x - sccstorcs.csh
cat >sccstorcs.csh <<'!Funky!Stuff!'
# csh program to convert an sccs file to an rcs file with all revisions
# and comments kept intact

cat > awk.tmp <<EOF
\$0 ~ /^D [0-9][0-9]*\.[0-9][0-9]*/ {
    IDS = \$2 " " IDS
    }
END {
    print IDS
    }
EOF

cat > sed1.tmp <<EOF
1h
1d
/static char sid/g
EOF

set ADDLOG = 0
while ($#argv > 0)
    set SFILE = ""
    switch ($argv[1])
    case -l:
	set ADDLOG = 1
	breaksw
    default:
	set SFILE = "$argv[1]"
	breaksw
    endsw
    shift
    if ("$SFILE" == "") continue

    set REVS=`prs $SFILE | awk -f awk.tmp`
    if ($status != 0) then
	echo "?$SFILE not an SCCS file - skipping"
	continue
    endif
    set TIME = `ftime $SFILE`
    echo "$#REVS revisions for $SFILE (TIME=$TIME)"
    foreach REL ($REVS)
	set RFILE=`expr $SFILE : "s\.\(.*\)"`
	prs -r$REL $SFILE -d":C:" > comments.tmp
	prs -r$REL $SFILE \
-d'static char sid[]="$Header: :PN:,v :I: :Dy:/:Dm:/:Dd: :T: :P: Exp $";\n:GB:' \
	    > sccs.tmp
	if (`grep -c "static char sid" sccs.tmp` > 1) then
	    sed -f sed1.tmp sccs.tmp > $RFILE
	else
	    mv sccs.tmp $RFILE
	endif
	if ($ADDLOG == 1 && "$REL" == "$REVS[$#REVS]") then
	    awk '$0 ~ /^\*\// && DONE == 0 {print "$Log$"; DONE = 1}; {print}' \
		$RFILE > sccs.tmp
	    mv sccs.tmp $RFILE
	endif
	ci -f -l -k$REL $RFILE < comments.tmp
    end
    rcs -u $RFILE
    rm -f $RFILE
    touch $TIME $RFILE,v
end

rm -f *.tmp
!Funky!Stuff!
echo x - ftime.c
cat >ftime.c <<'!Funky!Stuff!'
#include  <time.h>
#include  <sys/types.h>
#include  <sys/stat.h>

struct tm  *localtime();

static char  *Wdays[] = { "Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat" };
static char  *Months[] = {
    "Jan", "Feb", "Mar", "Apr", "May", "Jun",
    "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };

char  *dodate();

main (ac,av)
    int  ac;
    char  *av[];
{
    struct stat  sbuf;
    long  ftime;

    if (stat (*++av, &sbuf) == 0)
	ftime = (long)sbuf.st_mtime;
    else
	ftime = 0L;

    puts (dodate ((*++av == 0 ? "%m%d%H%M%y" : *av), ftime));

}  /* main */

char *dodate (pfmt, ldate)
    register char  *pfmt;	/* ptr to date fmt string - see S.III date(1) */
    long  ldate;		/* date to be formatted (like time() returns) */
{	/* format a date using a System III date(1) format string */
    register struct tm  *ptime;
    register char  c, *padate;
    register int  i;
    static char  adate[80];

    ptime = localtime(&ldate);
    padate = adate;
    while ((c = *pfmt++))
    {
	if (c != '%')
	{
	    *padate++ = c;
	    continue;
	}
	switch (c = *pfmt++)
	{
	  case '%':	/* "%%" - print a percent sign */
	    *padate++ = '%';
	    break;

	  case 'n':	/* "%n" - print a newline */
	    *padate++ = '\n';
	    break;

	  case 't':	/* "%t" - print a tab */
	    *padate++ = '\t';
	    break;

	  case 'm':	/* "%m" - print month of year (01 to 12) */
	    sprintf (padate, "%02d", ptime->tm_mon+1);
	    padate += 2;
	    break;

	  case 'd':	/* "%d" - print day of month (01 to 31) */
	    sprintf (padate, "%02d", ptime->tm_mday);
	    padate += 2;
	    break;

	  case 'y':	/* "%y" - print last 2 digits of year (00 to 99) */
	    sprintf (padate, "%02d", ptime->tm_year);
	    padate += 2;
	    break;

	  case 'D':	/* "%D" - print date as mm/dd/yy */
	    sprintf (padate, "%02d/%02d/%02d",
		ptime->tm_mon+1, ptime->tm_mday, ptime->tm_year);
	    padate += 8;
	    break;

	  case 'H':	/* "%H" - print hour (00 to 23) */
	    sprintf (padate, "%02d", ptime->tm_hour);
	    padate += 2;
	    break;

	  case 'M':	/* "%M" - print minute (00 to 59) */
	    sprintf (padate, "%02d", ptime->tm_min);
	    padate += 2;
	    break;

	  case 'S':	/* "%S" - print second (00 to 59) */
	    sprintf (padate, "%02d", ptime->tm_sec);
	    padate += 2;
	    break;

	  case 'T':	/* "%T" - print time as HH:MM:SS */
	    sprintf (padate, "%02d:%02d:%02d",
		ptime->tm_hour, ptime->tm_min, ptime->tm_sec);
	    padate += 8;
	    break;

	  case 'j':	/* "%j" - print julian date (001 to 366) */
	    sprintf (padate, "%03d", ptime->tm_yday+1);
	    padate += 3;
	    break;

	  case 'w':	/* "%w" - print day of week (0 to 6) (0=Sunday) */
	    sprintf (padate, "%1d", ptime->tm_wday);
	    padate += 1;
	    break;

	  case 'a':	/* "%a" - print abbreviated weekday (Sun to Sat) */
	    sprintf (padate, "%3.3s", Wdays[ptime->tm_wday]);
	    padate += 3;
	    break;

	  case 'h':	/* "%h" - print abbreviated month (Jan to Dec) */
	    sprintf (padate, "%3.3s", Months[ptime->tm_mon]);
	    padate += 3;
	    break;

	  case 'r':	/* "%r" - print time in AM/PM notation */
	    i = ptime->tm_hour;
	    if (i > 12)
		i -= 12;
	    sprintf (padate, "%02d:%02d:%02d %2.2s",
		i, ptime->tm_min, ptime->tm_sec,
		ptime->tm_hour >= 12 ? "PM" : "AM");
	    padate += 11;
	    break;

	  default:
	    *padate++ = '%';
	    *padate++ = c;
	    *padate++ = '?';
	    break;
	}
    }
    *padate = '\0';
    return (&adate[0]);

}  /* dodate */
!Funky!Stuff!
echo x - makefile.rcs
cat >makefile.rcs <<'!Funky!Stuff!'
.SUFFIXES:  .c,v

.c,v.o:
	co -q $*.c
	$(CC) $(CFLAGS) -c $*.c
	rm -f $*.c

.c,v.a:
	co -q $*.c
	$(CC) $(CFLAGS) -c $*.c
	ar rv $@ $*.o
	rm -f $*.c $*.o

.c,v:
	co -q $*.c
	$(CC) $(CFLAGS) $(LFLAGS) $*.c -o $@
	rm -f $*.c
!Funky!Stuff!

bill@utastro.UUCP (09/01/83)

This is about the 20th copy of this 297 line source file
to arrive at utastro.  What gives?

	Bill Jefferys
	Astronomy Dept, University of Texas, Austin TX 78712   (Snail)
	ihnp4!kpno!utastro!bill   (uucp)
	utastro!bill@utexas-11   (ARPA)