(FILECREATED " 7-May-86 12:48:52" {QV}<NOTECARDS>1.3K>RHTPATCH043.;2 8393 changes to: (VARS RHTPATCH043COMS) (FNS NC.ConvertNoteFileVersion2To3) previous date: " 7-May-86 12:00:46" {QV}<NOTECARDS>1.3K>RHTPATCH043.;1) (* Copyright (c) 1986 by Xerox Corporation. All rights reserved.) (PRETTYCOMPRINT RHTPATCH043COMS) (RPAQQ RHTPATCH043COMS ((* * Changes to NCCONVERTVERSION2TO3) (FNS NC.ConvertNoteFileVersion2To3 NC.ReadVersion2MainCardData))) (* * Changes to NCCONVERTVERSION2TO3) (DEFINEQ (NC.ConvertNoteFileVersion2To3 (LAMBDA (StreamOrFileName) (* rht: " 7-May-86 11:53") (* * Convert this notefile to version 3 outputting the version 3 notefile to new version with same filename.) (* * fgh 12/17/85 fixed call to CreateDatabaseFile to lop the version off of the file name.) (* * rht 12/18/85: Now clears Version2HashArray in case uncollectable garbage is left around.) (* * rht 5/7/86: No longer just passes IndexSizeInEntries on to NC.CreateDatabaseFile. Uses NextIndexNum and NC.DefaultIndexSizeInEntries to compute a reasonable hasharray size (hopefully smaller than 10240, the largest allowable.)) (LET ((OperationMsg "Converting file to version 3.") CardTotal FileName FromStream FromNoteFile ToNoteFile Version2HashArray Version NextIndexNum IndexSizeInEntries NextLinkNum CheckptPtr ToFileName) (if (STREAMP StreamOrFileName) then (SETQ FromStream StreamOrFileName) (SETQ FileName (FULLNAME StreamOrFileName)) else (SETQ FileName StreamOrFileName) (SETQ FromStream (OPENSTREAM FileName (QUOTE BOTH)))) (SETFILEPTR FromStream 7) (if (EQ (SETQ Version (NC.ReadPtr FromStream 1)) 2) then (* FromStream is indeed version 2.0) (* Get all the header info off the 1.2 stream.) (SETFILEPTR FromStream 0) (SETQ NextIndexNum (NC.ReadPtr FromStream 2)) (SETQ CardTotal (SUB1 NextIndexNum)) (SETQ IndexSizeInEntries (NC.ReadPtr FromStream 2)) (SETQ NextLinkNum (NC.ReadPtr FromStream 3)) (* Skip version number.) (NC.ReadPtr FromStream 1) (SETQ CheckptPtr (NC.ReadPtr FromStream 3)) (* * Create a dummy notefile object for the 1.2 source notefile.) (SETQ FromNoteFile (create NoteFile UID ←(NC.MakeUID) Stream ← FromStream FullFileName ←(FULLNAME FileName) NextIndexNum ← NextIndexNum Version ← Version NextLinkNum ← NextLinkNum CheckptPtr ← CheckptPtr)) (SETQ ToNoteFile (NC.CreateDatabaseFile (PACKFILENAME (QUOTE VERSION) NIL (QUOTE BODY) FileName) (MAX NC.DefaultIndexSizeInEntries (TIMES 2 NextIndexNum)) OperationMsg T)) (SETQ ToFileName (fetch (NoteFile FullFileName) of ToNoteFile)) (if (AND (type? NoteFile ToNoteFile) (NC.OpenDatabaseFile ToNoteFile NIL T T NIL NIL NIL NIL T)) then (* * Fill in NewNoteFile's hash array with new UIDs. Return a hash array mapping version 2 style ID atoms to version 3 style Cards.) (NC.PrintMsg NIL T "Reading index of version 2 notefile ...") (SETQ Version2HashArray (NC.BuildVersion2HashArray FromNoteFile ToNoteFile CardTotal)) (* * For each card in the old notefile, fill in a version 3 card object for it and put the filled in card down to NewNoteFile.) (NC.PrintMsg NIL T OperationMsg (CHARACTER 13) "Processing card ID 1 out of " CardTotal) (for IDNum from 1 to CardTotal eachtime (BLOCK) do (if (ZEROP (REMAINDER IDNum 10)) then (NC.PrintMsg NIL T OperationMsg (CHARACTER 13) "Processing card ID " IDNum " out of " CardTotal)) (NC.GetAndPutVersion2Card FromStream (NC.IDFromNumber IDNum) Version2HashArray FromNoteFile ToNoteFile)) (* Clear hash array to be sure uncollectable garbage isn't left around.) (CLRHASH Version2HashArray) (NC.CheckpointDatabase ToNoteFile T) (NC.ForceDatabaseClose ToNoteFile) (CLOSEF FromStream) (* Rebuild To and From links.) (NC.ScavengeDatabaseFile (fetch (NoteFile FullFileName) of ToNoteFile)) (NC.PrintMsg NIL T "Done.") ToFileName) else (NC.ReportError "NC.ConvertNoteFileVersion2To3" (CONCAT "Filename " FileName " is version " Version ". Can only convert version 2 notefiles.")) NIL)))) (NC.ReadVersion2MainCardData (LAMBDA (Stream ID Card Version2HashArray FromNoteFile ToNoteFile) (* rht: " 7-May-86 12:46") (* * Stream should be positioned at the main data card part of ID. Get the main data and fill in for Card.) (* * fgh 12/17/85 changed Apply of CollectReferencesFn to be done only if there is a CollectReferencesFn for the card type) (* * rht 5/7/86: Now only does the horrible kludge of smashing absolute pointers in the 1.2 file if the TEdit is judged to be formatted. We check that by looking for the TEdit password at the end of the substance.) (LET (CardType Region StartPtr EndPtr Length TEditBasedFlg StartFormatPtr CollectReferencesFn FormattedTEditP) (NC.SetItemDate Card (NC.ReadVersion2CardPartHeader Stream ID NC.Version2ItemIdentifier)) (* * Read card type and region) (NC.SetType Card (SETQ CardType (READ Stream))) (SETQ TEditBasedFlg (NC.TEditBasedP CardType)) (READC Stream) (NC.SetRegion Card (NC.ReadVersion2Region Stream)) (* * Read the substance pointers, compute the length, then call the substance get fn) (SETQ StartPtr (NC.ReadPtr Stream 3)) (SETQ EndPtr (NC.ReadPtr Stream 3)) (SETQ Length (DIFFERENCE EndPtr StartPtr)) (* * Figure out whether the substance is TEdit formatted. In that case we have to smush absolute pointers.) (SETQ FormattedTEditP (AND TEditBasedFlg (GREATERP Length 2) (SETFILEPTR Stream (DIFFERENCE EndPtr 2)) (EQ (QUOTIENT (NC.ReadPtr Stream 2) 100) NC.TEditPasswordDividedBy100))) (* * A horrible kludge: Change the infamous file absolute pointer in the text stream to be file relative for duration of the GetSubstance call.) (if FormattedTEditP then (SETFILEPTR Stream (DIFFERENCE EndPtr 8)) (SETQ StartFormatPtr (NC.ReadPtr Stream 4)) (SETFILEPTR Stream (DIFFERENCE EndPtr 8)) (NC.WritePtr Stream (DIFFERENCE StartFormatPtr StartPtr) 4)) (SETFILEPTR Stream StartPtr) (NC.SetSubstance Card (NC.ApplyFn GetFn Card Length Stream -1)) (* * Now put back the infamous file absolute pointer.) (if FormattedTEditP then (SETFILEPTR Stream (DIFFERENCE EndPtr 8)) (NC.WritePtr Stream StartFormatPtr 4) (SETFILEPTR Stream EndPtr)) (* * Now convert each link in the embedded link icons in the substance.) (if (fetch (Card CollectLinksFn) of Card) then (for LinkIcon in (CAR (NC.ApplyFn CollectLinksFn Card NIL T)) eachtime (BLOCK) do (NC.ConvertVersion2LinkIcon LinkIcon Card Version2HashArray)))))) ) (PUTPROPS RHTPATCH043 COPYRIGHT ("Xerox Corporation" 1986)) (DECLARE: DONTCOPY (FILEMAP (NIL (530 8311 (NC.ConvertNoteFileVersion2To3 540 . 5268) (NC.ReadVersion2MainCardData 5270 . 8309))))) STOP