(FILECREATED " 2-May-86 02:42:06" {QV}<NOTECARDS>1.3K>FGHPATCH029.;3 7074 changes to: (VARS FGHPATCH029COMS) (FNS NC.CompactNoteFile) previous date: " 2-May-86 02:25:55" {QV}<NOTECARDS>1.3K>FGHPATCH029.;1) (* Copyright (c) 1986 by Xerox Corporation. All rights reserved.) (PRETTYCOMPRINT FGHPATCH029COMS) (RPAQQ FGHPATCH029COMS ((* * Fixes to the functions that call the compactor that the compactor works from the FB as well as the NF menu.) (* * From NCINTERFACE) (FNS NC.FileBrowserCompact) (* * From NCCOMPACT) (FNS NC.CompactNoteFile NC.CompactNoteFileToTarget))) (* * Fixes to the functions that call the compactor that the compactor works from the FB as well as the NF menu.) (* * From NCINTERFACE) (DEFINEQ (NC.FileBrowserCompact (LAMBDA (Browser Key Item Menu InPlaceFlg) (* fgh: " 2-May-86 01:56") (* * Function called from file browser menu for notefile compact.) (for FileObject in (FB.SELECTEDFILES Browser) do (NC.CompactNoteFile (MKATOM (FB.FETCHFILENAME FileObject)) NIL InPlaceFlg (fetch (FILEBROWSER PROMPTWINDOW) of Browser))))) ) (* * From NCCOMPACT) (DEFINEQ (NC.CompactNoteFile (LAMBDA (FromNoteFile ToFileName InPlaceFlg PromptWindow) (* fgh: " 2-May-86 02:39") (* * Compact a NoteFile. If InPlaceFlg is T calls NC.CompactNoteFileInPlace. Otherwise if ToFileName is NIL, asks for a new file name.) (* * fkr 11/8/85 Updated to handle new CardID scheme and NoteFile object.) (* * kirk 19Nov85: Created from NC.CompactDatabaseInPlace to handle new NoteFile format) (* * fgh 5/186 Totally rewritten to get rid of numerous bugs. Added new PromptWindow parameter.) (LET (WasOpen FromFileName ToNoteFile success) (* * Get the name of the file to be compacted) (SETQ FromFileName (COND ((NULL FromNoteFile) (PROG1 (NC.DatabaseFileName "Name of NoteFile to be compacted in place:" " -- " T NIL NIL PromptWindow) (NC.ClearMsg PromptWindow))) ((type? NoteFile FromNoteFile) (fetch (NoteFile FullFileName) of FromNoteFile)) (T FromNoteFile))) (* * If compact to target, get the name of the target file) (if (NULL InPlaceFlg) then (SETQ ToFileName (OR ToFileName (PROG1 (NC.DatabaseFileName "Name of target of compaction:" " -- " T NIL NIL PromptWindow) (NC.ClearMsg PromptWindow))))) (* * As long as you have file names, go ahead!) (if (AND FromFileName (OR InPlaceFlg ToFileName)) then (* * Make full names) (SETQ FromFileName (FULLNAME FromFileName (QUOTE OLD))) (SETQ ToFileName (FULLNAME ToFileName (QUOTE NEW))) (* * Close the file if its open) (if (AND (SETQ FromNoteFile (NC.NoteFileFromFileName FromFileName)) (SETQ WasOpen (OPENP FromFileName))) then (NC.CloseDatabaseFile FromNoteFile)) (* * Compact the file and reopen if successfull and was previously open) (if (SETQ ToNoteFile (if InPlaceFlg then (NC.CompactNoteFileInPlace FromNoteFile) else (* compact to target) (NC.CompactNoteFileToTarget FromNoteFile ToFileName))) then (if WasOpen then (NC.OpenDatabaseFile ToNoteFile) else (NC.PrintMsg NIL T "Done compacting " FromFileName)) else (NC.PrintMsg NIL T "Compact of " FromFileName " cancelled.")))))) (NC.CompactNoteFileToTarget (LAMBDA (FromNoteFile ToFileName) (* fgh: " 2-May-86 01:40") (* * In sorted order, copy card parts to lower addresses in the file.) (* * fgh 5/1/86 Now returns the ToNoteFile in order to be compatible with compact in place.) (LET (FromFileLength ToNoteFile TargetStream TargetFileLength success OriginalStream) (SETQ FromNoteFile (NC.OpenDatabaseFile FromNoteFile NIL T T T T NIL T T T)) (SETQ ToNoteFile (NC.OpenDatabaseFile (NC.CreateDatabaseFile ToFileName ( NC.ComputeNewDatabaseIndexSize FromNoteFile) NIL T NIL T) NIL T T T T T T T T)) (SETQ TargetStream (fetch (NoteFile Stream) of ToNoteFile)) (SETQ OriginalStream (fetch (NoteFile Stream) of FromNoteFile)) (replace (NoteFile NextIndexNum) of ToNoteFile with (fetch (NoteFile NextIndexNum) of FromNoteFile)) (SETFILEPTR (fetch (NoteFile Stream) of ToNoteFile) (NC.TotalIndexSize (fetch (NoteFile HashArraySize) of ToNoteFile))) (* truncate ToNoteFile after the index) (SETQ success (NC.CopySortedCardParts (NC.SortIndexEntries FromNoteFile) ToNoteFile)) (if success then (* all useable card parts got copied) (SETQ FromFileLength (GETEOFPTR OriginalStream)) (* * fool NC.PutHashArray into writing out the index for the new NoteFile) (replace (NoteFile Stream) of FromNoteFile with TargetStream) (NC.PutHashArray FromNoteFile T NIL T) (replace (NoteFile Stream) of FromNoteFile with OriginalStream) (* * Put out the new ChkptPtr to the file.) (replace (NoteFile CheckptPtr) of ToNoteFile with (SETQ TargetFileLength (GETEOFPTR TargetStream))) (* * Steal the UID from the original file so links will work. Write out the header.) (replace (NoteFile UID) of ToNoteFile with (fetch (NoteFile UID) of FromNoteFile)) (NC.PutNoteFileHeader ToNoteFile) (SETQ success (DIFFERENCE FromFileLength TargetFileLength)) (NC.PrintMsg NIL T (fetch (NoteFile FullFileName) of FromNoteFile) " compacted to " (fetch (NoteFile FullFileName) of ToNoteFile) (CHARACTER 13) "Recovered " success " bytes (" (FIX (TIMES 100 (FQUOTIENT success FromFileLength))) "%%)" (CHARACTER 13))) (NC.ForceDatabaseClose FromNoteFile T) (SETQ ToNoteFile (NC.ForceDatabaseClose ToNoteFile T)) ToNoteFile))) ) (PUTPROPS FGHPATCH029 COPYRIGHT ("Xerox Corporation" 1986)) (DECLARE: DONTCOPY (FILEMAP (NIL (785 1285 (NC.FileBrowserCompact 795 . 1283)) (1313 6992 (NC.CompactNoteFile 1323 . 3986 ) (NC.CompactNoteFileToTarget 3988 . 6990))))) STOP