#!/bin/csh -f
# difflog -- runs rcsdiff on files in logfile created by 
#	changelog.  May specify RCS directory and Log file on command line,
#	overriding defaults and even environment settings.
#
#	same arguments -d and -f as for changelog.
	
    set usage = ($0 -d rcsdir -f logfile )

    if ($?RCSDIR) then
	echo using environment: $RCSDIR
	set RCSdir = $RCSDIR
    else
	no environment: $RCSDIR
	set RCSdir = ./RCS
    endif

    if ($?RCSLOCK) then
	set rcslock = $RCSLOCK
    else
	set rcslock = RCSLock
    endif

    if ($?RCSLOG) then
	set logfile = $RCSLOG
    else
	set logfile = Log
    endif

    set logmessage = ""
    set nolock = 0

    while ($#argv > 0)
	switch ($argv[1])
	case -d:
	    echo "-d flag found"
	    if ($#argv == 1) then
		echo RCS directory specifier missing
		echo usage: $usage
		exit (1)
	    endif
	    set RCSdir = $argv[2]
	    shift
	    breaksw
	case -f:
	    if ($#argv == 1) then
		echo logfile name missing
		echo usage: $usage
		exit (1)
	    endif
	    set logfile = $argv[2]
	    shift
	    breaksw
	case -m:
	    if ($#argv == 1) then
		echo message missing
		echo usage: $usage
		exit (1)
	    endif
	    set logmessage = "-m$argv[2]"
	    shift
	    breaksw
	case -l:
	    if ($#argv == 1) then
		echo lock file name missing
		echo usage: $usage
		exit (1)
	    endif
	    set rcslock = $argv[2]
	    if ($dbug) echo rcslock = $rcslock
	    shift
	    breaksw
	case -u:
	    set nolock = 1
	    breaksw
	default:
	    echo usage: $usage
	endsw
	shift
    end


    
    set fstr = $RCSdir/%s,v\\n
    set noglob
    set  astr = ({print \$1; printf \"$fstr\", \$1})
    set  bstr = ({print \$1})

    # alternatively, could loop, doing rcsdiff and ci
    #set fileargs = `tail +2 $logfile | egrep '(MISSING|CHANGED)' | awk "$astr"`
    set notmissing = `tail +2 $logfile | fgrep 'CHANGED' | awk "$bstr"`

    foreach nmfile ($notmissing)
	echo ======= $nmfile =====================================
	rcsdiff $RCSdir/$nmfile,v
    end

