(FILECREATED "18-Dec-85 12:53:26" {QV}<NOTECARDS>1.3K>RHTPATCH017.;1 7505   

      changes to:  (VARS RHTPATCH017COMS))


(* Copyright (c) 1985 by Xerox Corporation. All rights reserved.)

(PRETTYCOMPRINT RHTPATCH017COMS)

(RPAQQ RHTPATCH017COMS ((* * Fixes to functions in NCCONVERTVERSION2TO3)
			  (FNS NC.ConvertNoteFileVersion2To3 NC.GetAndPutVersion2Card)))
(* * Fixes to functions in NCCONVERTVERSION2TO3)

(DEFINEQ

(NC.ConvertNoteFileVersion2To3
  (LAMBDA (StreamOrFileName)                                 (* rht: "18-Dec-85 12:49")

          (* * 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.)


    (LET ((OperationMsg "Converting file to version 3.")
	  CardTotal FileName FromStream FromNoteFile ToNoteFile Version2HashArray Version 
	  NextIndexNum IndexSizeInEntries NextLinkNum CheckptPtr)
         (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)
								IndexSizeInEntries OperationMsg T))
		    (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.")
			       FileName)
	   else (NC.ReportError "NC.ConvertNoteFileVersion2To3" (CONCAT "Filename " FileName 
									      " is version "
									      Version 
						       ".  Can only convert version 2 notefiles."))
		  NIL))))

(NC.GetAndPutVersion2Card
  (LAMBDA (Stream ID Version2HashArray FromNoteFile ToNoteFile)
                                                             (* rht: "18-Dec-85 12:24")

          (* * If ID has active status, then get its card parts off Stream and fill in the info into the corresponding card 
	  object. Find this object using Version2HashArray.)



          (* * rht 12/18/85: Now deactivates card after putting to file.)


    (LET ((Pointers (NC.ReadVersion2Ptrs ID Stream))
	  Card)
         (SELECTQ (fetch (POINTERLIST STATUS) of Pointers)
		    (ACTIVE                                  (* Recover card object from the hash array.)
			    (SETQ Card (GETHASH ID Version2HashArray))

          (* * Read main data and substance and fill in Card object.)


			    (SETFILEPTR Stream (fetch (POINTERLIST MAINPTR) of Pointers))
			    (NC.ReadVersion2MainCardData Stream ID Card Version2HashArray 
							   FromNoteFile ToNoteFile)

          (* * Read global links and fill in Card object.)


			    (SETFILEPTR Stream (fetch (POINTERLIST LINKSPTR) of Pointers))
			    (NC.ReadVersion2Links Stream ID Card)

          (* * Read title and fill in Card object.)


			    (SETFILEPTR Stream (fetch (POINTERLIST TITLEPTR) of Pointers))
			    (NC.ReadVersion2Title Stream ID Card)

          (* * Read prop list and fill in Card object.)


			    (SETFILEPTR Stream (fetch (POINTERLIST PROPSPTR) of Pointers))
			    (NC.ReadVersion2PropList Stream ID Card)

          (* * If card is a browser, then first convert to version 3 format.)


			    (if (NC.IsSubTypeOfP (NC.FetchType Card)
						     (QUOTE Browser))
				then (NC.ConvertVersion2BrowserCard Card Version2HashArray))

          (* * Write down the card parts to the ToNoteFile.)


			    (NC.PutMainCardData Card NIL T)
			    (NC.PutLinks Card T)
			    (NC.PutTitle Card T)
			    (NC.PutPropList Card T))
		    (SPECIAL                                 (* Deal specially with link labels.)
			     (SETQ Card (NC.Version3CardFromVersion2ID ID Version2HashArray))
                                                             (* Go get the link labels from version 2 stream and 
							     write down to version 3 notefile.)
			     (SETFILEPTR Stream (fetch (POINTERLIST MAINPTR) of Pointers))
			     (NC.StoreLinkLabels ToNoteFile (NC.ReadVersion2LinkLabels Stream ID 
											   Card)))
		    NIL)
         (AND (NC.CardP Card)
		(NC.DeactivateCard Card T))
     Card)))
)
(PUTPROPS RHTPATCH017 COPYRIGHT ("Xerox Corporation" 1985))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (430 7423 (NC.ConvertNoteFileVersion2To3 440 . 4737) (NC.GetAndPutVersion2Card 4739 . 
7421)))))
STOP