From:	CRDGW2::CRDGW2::MRGATE::"SMTP::CRVAX.SRI.COM::RELAY-INFO-VAX"  7-JUN-1989 07:58
To:	MRGATE::"ARISIA::EVERHART"
Subj:	Recursive directory comparison script

Received: From KL.SRI.COM by CRVAX.SRI.COM with TCP; Tue,  6 JUN 89 23:01:15 PDT
Received: from B.PSC.EDU (cpwscb.psc.edu) by KL.SRI.COM with TCP; Tue, 6 Jun 89 22:41:34 PDT
Date:    Wed, 7 Jun 1989 1:43:25 EDT
From: GENTZEL@B.PSC.EDU   (Dave Gentzel)
Message-Id: <890607014325.20403159@B.PSC.EDU>
Subject: Recursive directory comparison script
To: INFO-VAX@KL.SRI.COM
X-Vmsmail-To: SMTP%"INFO-VAX@KL.SRI.COM"

Here is a .COM file I wrote some time ago which people may find useful.  It
takes two directory specs and recursively compares all files in the two.
There is no documentation, but the only subtle thing is P3 which is a list of
extensions to ignore (I'm not even sure if this feature even works as I
haven't used it in a long time).

I find this incredibly valuable in comparing possibly divergent source
directories.

					David Gentzel
					Pittsburgh Supercomputing Center
					gentzel@cpwsca.psc.edu
					or gentzel@morgul.psc.edu
					or gentzel@cpwpsca.bitnet

$! DIFDIR.COM : Recursively compare two directory trees.
$! Usage: @DIFDIR dir1 dir2 [ignore] [recurse]
$!	ignore is a list of extensions to ignore
$!	recurse defaults to TRUE
$!
$! Author: David Gentzel
$!	Pittsburgh Supercomputing Center
$!	gentzel@cpwsca.psc.edu/gentzel@morgul.psc.edu/gentzel@cpwpsca.bitnet
$!
$ savver = 'f$verify(0)
$ set := set
$ set symbol/scope=(nolocal,noglobal)
$ d1 = p1
$ d2 = p2
$ ignore = p3
$ recurse = p4
$ if d1 .eqs. "" then read/error=quit/prompt="_Directory 1: " sys$command d1
$ if d2 .eqs. "" then read/error=quit/prompt="_Directory 2: " sys$command d2
$ if ignore .nes. "" then ignore = "," + ignore + ","
$ if recurse .eqs. "" then recurse = "TRUE"
$ d1 = f$parse(d1) - ".;"
$ d2 = f$parse(d2) - ".;"
$ call difdir "''d1'" "''d2'" "''ignore'" "''recurse'"
$quit:
$ exit 1+0*f$verify(savver)
$
$difdir: subroutine
$ d1 = p1
$ d2 = p2
$ ignore = p3
$ recurse = p4
$ ignorelen = f$length(ignore)
$ write sys$output "Comparing directories ''d1' and ''d2'..."
$ s1 = d1 + "*.*;"
$ s2 = d2 + "*.*;"
$ tmp = "SYS$SCRATCH:DD''f$getjpi("","PID")'.TMP"
$next:
$ f1 = f$search(s1,1)
$ n1 = f$parse(f1,,,"NAME") + f$parse(f1,,,"TYPE")
$ f2 = f$search(s2,2)
$ n2 = f$parse(f2,,,"NAME") + f$parse(f2,,,"TYPE")
$loop:
$ if f1 .eqs. "" then goto d2only
$ if f2 .eqs. "" then goto d1only
$ if n1 .lts. n2 then goto d1only
$ if n1 .gts. n2 then goto d2only
$ ext = f$parse(n1,,,"TYPE")
$ if ext .nes. ".DIR" then goto notdir
$ if .not. recurse then goto next
$ call name_as_dir "''f1'"
$ sav_dir = nad_res
$ call name_as_dir "''f2'"
$ call difdir "''sav_dir'" "''nad_res'" "''ignore'" "''recurse'"
$ goto next
$notdir:
$ if f$locate("," + ext + ",", ignore) .lt. ignorelen then goto next
$ diff 'f1' 'f2'/out='tmp'
$ if $severity .ne. 3 then goto nodif
$ write sys$output "diff ''f1' ''f2'"
$ write sys$output -
"----------------------------------------------------------------------"
$ type 'tmp'
$ write sys$output -
"----------------------------------------------------------------------"
$nodif:
$ delete/nolog 'tmp';
$ goto next
$
$d1only:
$ if f1 .eqs. "" then goto done
$ write sys$output "Only in ''d1' - ''n1'"
$ f1 = f$search(s1,1)
$ n1 = f$parse(f1,,,"NAME") + f$parse(f1,,,"TYPE")
$ if f2 .eqs. "" then goto d1only
$ goto loop
$
$d2only:
$ if f2 .eqs. "" then goto done
$ write sys$output "Only in ''d2' - ''n2'"
$ f2 = f$search(s2,2)
$ n2 = f$parse(f2,,,"NAME") + f$parse(f2,,,"TYPE")
$ if f1 .eqs. "" then goto d2only
$ goto loop
$
$done:
$ exit
$ endsubroutine
$
$name_as_dir: subroutine
$ name = p1
$ dir = f$parse(name,,,"NODE") + f$parse(name,,,"DEVICE") -
	+ f$parse(name,,,"DIRECTORY")
$ end = f$extract(f$length(dir) - 1,1,dir)
$ if end .nes. "]" .and. end .nes. "]" then goto hairy
$ nad_res == dir - end + "." + f$parse(name,,,"NAME") + end
$ exit
$hairy:
$ write sys$error "Directories of the form ''name' are not yet supported..."
$ exit 2
$ endsubroutine

