(FILECREATED "22-Aug-86 15:44:19" {PHYLUM}<LANNING>FILECACHE>MERGE-FILEGEN.;5 8345 changes to: (FNS FILES.IN.ORDER?) previous date: "30-Jul-86 18:48:11" {PHYLUM}<LANNING>FILECACHE>MERGE-FILEGEN.;2) (* Copyright (c) 1986 by Xerox Corporation. All rights reserved.) (PRETTYCOMPRINT MERGE-FILEGENCOMS) (RPAQQ MERGE-FILEGENCOMS ((* * Merging together two file generators) (FNS MERGE.FILEGENERATORS MERGED.FILEINFOFN MERGED.NEXTFILEFN \MERGED.NEXTFILEFN1 FILES.IN.ORDER?) (DECLARE: DONTCOPY (RECORDS MERGEDFILEGENSTATE)))) (* * Merging together two file generators) (DEFINEQ (MERGE.FILEGENERATORS [LAMBDA (gen1 gen2 sorted?) (* smL "28-Jun-85 15:49") (* * Merge the two file generators into one) (create FILEGENOBJ NEXTFILEFN ←(FUNCTION MERGED.NEXTFILEFN) FILEINFOFN ←(FUNCTION MERGED.FILEINFOFN) GENFILESTATE ←(create MERGEDFILEGENSTATE gen1 ← gen1 gen2 ← gen2 sorted? ← sorted?]) (MERGED.FILEINFOFN [LAMBDA (genState attribute) (* smL "28-Jun-85 15:42") (* * The FILEINFOFN for a merged filegenerator) (with MERGEDFILEGENSTATE genState (if lastUsedGen then (\GENERATEFILEINFO lastUsedGen attribute) else (ERROR "No files generated yet!"]) (MERGED.NEXTFILEFN [LAMBDA (genState nameOnly) (* smL " 4-Feb-86 18:12") (* * The NEXTFILEFN for a merged filegenerator) (with MERGEDFILEGENSTATE genState (PROG (nextFile) TRYNEXTFILE (SETQ nextFile (\MERGED.NEXTFILEFN1 genState nameOnly)) (if (NULL nextFile) then (* no more files) (RETURN NIL) elseif (MEMB (MKATOM (U-CASE nextFile)) genedFiles) then (* don't include the file twice) (GO TRYNEXTFILE) else (push genedFiles (MKATOM (U-CASE nextFile))) (RETURN nextFile]) (\MERGED.NEXTFILEFN1 [LAMBDA (genState nameOnly) (* smL " 4-Feb-86 18:06") (* * Almost the NEXTFILEFN for a merged filegenerator, but doesn't worry about replications) (with MERGEDFILEGENSTATE genState (LET (file gen1File gen2File) (if (NOT sorted?) then (* easy -- just use the first one till it is done, then switch to the second one) (if (NOT gen1Empty?) then (SETQ file (\GENERATENEXTFILE gen1 nameOnly)) (SETQ lastUsedGen gen1) (if (NULL file) then (SETQ gen1Empty? T) (\MERGED.NEXTFILEFN1 genState nameOnly) else file) else (SETQ file (\GENERATENEXTFILE gen2 nameOnly)) (SETQ lastUsedGen gen2) (if (NULL file) then (SETQ gen2Empty? T) file else file)) else (* sorted is more difficult --) [SETQ gen1File (OR gen1Info (AND (NOT gen1Empty?) (\GENERATENEXTFILE gen1 nameOnly] [SETQ gen2File (OR gen2Info (AND (NOT gen2Empty?) (\GENERATENEXTFILE gen2 nameOnly] (if (AND (NOT gen1File) (NOT gen2File) gen1Empty? gen2Empty?) then (* bad boy, you shouldnt be doing this) (ERROR "File generator exhausted!") ) (if (NOT gen1File) then (SETQ gen1Empty? T)) (if (NOT gen2File) then (SETQ gen2Empty? T)) (* if either gen1File or gen2File is NIL, things are easy) (if (NOT gen1File) then (SETQ gen2Info NIL) (SETQ lastUsedGen gen2) gen2File elseif (NOT gen2File) then (SETQ gen1Info NIL) (SETQ lastUsedGen gen1) gen1File else (* use the one that occurs first in order, but remember the unused one) (SELECTQ (FILES.IN.ORDER? gen1File gen2File) ((EQUAL LESSP) (SETQ gen1Info NIL) (SETQ gen2Info gen2File) (SETQ lastUsedGen gen1) gen1File) (GREATERP (SETQ gen1Info gen1File) (SETQ gen2Info NIL) (SETQ lastUsedGen gen2) gen2File) (SHOULDNT]) (FILES.IN.ORDER? [LAMBDA (file1 file2) (* smL "22-Aug-86 15:32") (* * Are the two files in correct order for a directory generation?) (* Used to be: (if (STRING-EQUAL file1 file2) then (QUOTE EQUAL) else (for field in (QUOTE (DIRECTORY NAME EXTENSION)) bind file1Field file2Field do (SETQ file1Field (UNPACKFILENAME.STRING file1 field)) (SETQ file2Field (UNPACKFILENAME.STRING file2 field)) (if (AND (NULL file1Field) (NULL file2Field)) then NIL elseif (NULL file1Field) then (RETURN (QUOTE LESSP)) elseif (NULL file2Field) then (RETURN (QUOTE GREATERP)) elseif (STRING-EQUAL file1Field file2Field) then NIL elseif (ALPHORDER file1Field file2Field) then (RETURN (QUOTE LESSP)) else (RETURN (QUOTE GREATERP))) finally (RETURN (LET ((version1 (FILENAMEFIELD file1 (QUOTE VERSION))) (version2 (FILENAMEFIELD file2 (QUOTE VERSION)))) (if (AND (NUMBERP version1) (NUMBERP version2)) then (if (LESSP version1 version2) then (QUOTE LESSP) else (QUOTE GREATERP)) elseif (ALPHORDER file1 file2 (UPPERCASEARRAY)) then (QUOTE LESSP) else (QUOTE GREATERP))))))) (if (STRING-EQUAL file1 file2) then (QUOTE EQUAL) else (LET ((rootFile1 (PACKFILENAME.STRING (QUOTE VERSION) NIL (QUOTE BODY) file1)) (rootFile2 (PACKFILENAME.STRING (QUOTE VERSION) NIL (QUOTE BODY) file2))) (* Strip off any null extension) (if (EQP (NTHCHARCODE rootFile1 -1) (CONSTANT (CHARCODE "."))) then (SETQ rootFile1 (SUBSTRING rootFile1 1 -2))) (if (EQP (NTHCHARCODE rootFile2 -1) (CONSTANT (CHARCODE "."))) then (SETQ rootFile2 (SUBSTRING rootFile2 1 -2))) (* Now compare them) (if (STRING-EQUAL rootFile1 rootFile2) then (LET [(version1 (FILENAMEFIELD file1 (QUOTE VERSION))) (version2 (FILENAMEFIELD file2 (QUOTE VERSION] (if (AND (NUMBERP version1) (NUMBERP version2)) then (if (LESSP version1 version2) then (QUOTE LESSP) else (QUOTE GREATERP)) elseif (ALPHORDER file1 file2 (UPPERCASEARRAY)) then (QUOTE LESSP) else (QUOTE GREATERP))) elseif (ALPHORDER rootFile1 rootFile2 (UPPERCASEARRAY)) then (QUOTE LESSP) else (QUOTE GREATERP]) ) (DECLARE: DONTCOPY [DECLARE: EVAL@COMPILE (RECORD MERGEDFILEGENSTATE (gen1 gen2 lastUsedGen gen1Info gen2Info gen1Empty? gen2Empty? sorted? genedFiles) (SYSTEM)) ] ) (PUTPROPS MERGE-FILEGEN COPYRIGHT ("Xerox Corporation" 1986)) (DECLARE: DONTCOPY (FILEMAP (NIL (619 8072 (MERGE.FILEGENERATORS 629 . 1064) (MERGED.FILEINFOFN 1066 . 1425) ( MERGED.NEXTFILEFN 1427 . 2301) (\MERGED.NEXTFILEFN1 2303 . 5267) (FILES.IN.ORDER? 5269 . 8070))))) STOP