(FILECREATED "14-Jun-84 18:58:54" {ERIS}<LISPCORE>LIBRARY>COPYFILES.;8 3405   

      changes to:  (FNS COMPAREFILES)

      previous date: "12-Jun-84 13:41:33" {ERIS}<LISPCORE>LIBRARY>COPYFILES.;5)


(* Copyright (c) 1984 by John Sybalsky. All rights reserved.)

(PRETTYCOMPRINT COPYFILESCOMS)

(RPAQQ COPYFILESCOMS ((FNS COPYFILE? COPYFILES? COPYFILES COMPAREFILES)))
(DEFINEQ

(COPYFILE?
  [LAMBDA (FROMFILE TOFILE)                                  (* jds "16-May-84 16:02")

          (* Copy a file from one place to another, only if it has changed since the last copy, or if the file doesn't exist
	  in the target location. (Returns T if the copy took place, else NIL.))


    (COND
      ([AND (INFILEP FROMFILE)
	    (OR (NOT (INFILEP TOFILE))
		(IGREATERP (GETFILEINFO FROMFILE (QUOTE ICREATIONDATE))
			   (GETFILEINFO TOFILE (QUOTE ICREATIONDATE]

          (* Copy the file if (1) the SOURCE really exists, and (2) either the TARGET doesn't OR the source is newer than 
	  the target.)


	(COPYFILE FROMFILE TOFILE)                           (* Having copied the file, return T to tell the caller.)
	T])

(COPYFILES?
  [LAMBDA (FILES FROMLIB TOLIB VERBOSE?)                     (* jds "14-Mar-84 13:45")
                                                             (* Copy a group of files from one library to another, 
							     only if they have changed.)
    (for FILE in FILES WHEN (COPYFILE? (MKATOM (CONCAT FROMLIB FILE))
				       (MKATOM (CONCAT TOLIB FILE)))
       do (COND
	    (VERBOSE? (FRESHLINE VERBOSE?)
		      (PRINTOUT VERBOSE? "Copied " FILE " from " FROMLIB " to " TOLIB "."])

(COPYFILES
  [LAMBDA (FILES FROMLIB TOLIB VERBOSE?)                     (* jds "14-Mar-84 13:46")
                                                             (* Copy a list of files from one library to another)
    (for FILE in FILES WHEN (COPYFILE (MKATOM (CONCAT FROMLIB FILE))
				      (MKATOM (CONCAT TOLIB FILE)))
       do (COND
	    (VERBOSE? (FRESHLINE VERBOSE?)
		      (PRINTOUT VERBOSE? "Copied " FILE " from " FROMLIB " to " TOLIB "."])

(COMPAREFILES
  [LAMBDA (OLDFILE NEWFILE)                                  (* jds "14-Jun-84 18:57")
                                                             (* Compare two files to see if their contents are the 
							     same.)
    (PROG ([OSTREAM (OPENSTREAM OLDFILE (QUOTE INPUT)
				(QUOTE OLD)
				(QUOTE (SEQUENTIAL T]
	   [NSTREAM (OPENSTREAM NEWFILE (QUOTE INPUT)
				(QUOTE OLD)
				(QUOTE (SEQUENTIAL T]
	   OLEN NLEN)
          (SETQ OLEN (GETFILEINFO OSTREAM (QUOTE LENGTH)))
          (SETQ NLEN (GETFILEINFO NSTREAM (QUOTE LENGTH)))
          [COND
	    ((NOT (EQP OLEN NLEN))                           (* If they files are of different lengths, they aren't 
							     the same.)
	      (ERROR "File lengths differ:  " (CONCAT OLEN " vs " NLEN]
          [COND
	    (OLEN                                            (* FTP returns NIL for the length of an empty file!)
		  (for BYTEPOS from 0 to (SUB1 OLEN) do (COND
							  ((NEQ (\BIN OSTREAM)
								(\BIN NSTREAM))
							    (ERROR "Files differ at byte " BYTEPOS]
          (CLOSEF? OSTREAM)
          (CLOSEF? NSTREAM))
    T])
)
(PUTPROPS COPYFILES COPYRIGHT ("John Sybalsky" 1984))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (378 3329 (COPYFILE? 388 . 1152) (COPYFILES? 1154 . 1689) (COPYFILES 1691 . 2173) (
COMPAREFILES 2175 . 3327)))))
STOP