(FILECREATED "16-Jul-86 18:38:10" {QV}<NOTECARDS>1.3K>RHTPATCH075.;3 80178  

      changes to:  (FNS NC.ScavengerPhase1 NC.FileBrowserInspect&Repair NC.ScavengerCleanup 
			NC.InspectAndRepairNoteFile NC.NoteFileOperations NC.DoNoteFileOp 
			NC.ScavengeDatabaseFile NC.BuildBadCardsList NC.CreateDatabaseFile 
			NC.ConvertNoteFileVersion2To3 NC.CheckpointDatabase NC.SetUpNoteFileInterface 
			NC.OpenDatabaseFile NC.CheckForNeededConversion)
		   (VARS RHTPATCH075COMS)

      previous date: "16-Jul-86 10:29:39" {QV}<NOTECARDS>1.3K>RHTPATCH075.;1)


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

(PRETTYCOMPRINT RHTPATCH075COMS)

(RPAQQ RHTPATCH075COMS ((* * Changes to add InterestedWindow args and other stuff.)
			  (* * Changes to NCDATABASE)
			  (FNS NC.OpenDatabaseFile NC.CheckForNeededConversion NC.CreateDatabaseFile 
			       NC.CheckpointDatabase)
			  (* * Changes to NCCONVERTVERSION2TO3)
			  (FNS NC.ConvertNoteFileVersion2To3)
			  (* * Changes to NCREPAIR)
			  (FNS NC.ScavengeDatabaseFile NC.ScavengerPhase1 NC.BuildBadCardsList 
			       NC.ScavengerCleanup NC.InspectAndRepairNoteFile)
			  (* * Changes to NCINTERFACE)
			  (FNS NC.NoteFileOperations NC.SetUpNoteFileInterface 
			       NC.FileBrowserInspect&Repair NC.DoNoteFileOp)))
(* * Changes to add InterestedWindow args and other stuff.)

(* * Changes to NCDATABASE)

(DEFINEQ

(NC.OpenDatabaseFile
  (LAMBDA (NoteFileOrFileName Access Don'tCacheTypesAndTitlesFlg QuietFlg Don'tCreateFlg 
			      Convertw/oConfirmFlg Don'tCreateArrayFlg Don'tTruncateFlg 
			      Don'tCreateInterfaceFlg Don'tGetSpecialCardsFlg InterestedWindow 
			      Don'tCheckOperationInProgressFlg MenuPosition)
                                                             (* rht: "16-Jul-86 10:29")

          (* * Open an already existing NoteFile and return a NoteFile object)



          (* * rht 8/7/84: For nonexistent files, asks user whether to create unless Don'tCreateFlg is non-nil.)



          (* * rht 1/9/85: Checks NC.UncachingNotCompleted global var. If non-nil, then previous notefile died unnaturally, 
	  so we first clear junk off the IDs.)



          (* * rht 8/6/85: Added Don'tTruncateFlg, which, if on, prevents the check for truncation.)



          (* * fgh 10/16/85 Updated to use new cacheing scheme.)



          (* * kirk 10/29/85: Now does cacheing of types and titles as background process.)



          (* * fkr 11/8/85: Converted from Streams to NoteFile object.)



          (* * kirk 30Nov85 Added a check for correct version number.)



          (* * rht 12/6/85: Moved Kirk's above patch to NC.CheckForNeededConversion and modified somewhat.
	  Added check for plausible header.)



          (* * rht 1/8/86: Now reuses old notefile object if there is one for this filename.)



          (* * fgh 1/13/86: Fixed bug with returning File Name with embedded call to CreateDatabaseFile.
	  Now just calls OpenDatabaseFile recursively using result of CreateDatabaseFile.)



          (* * fgh 1/16/86 Folded the cacheing of the special cards into BuildHashArray instead of making it a separate 
	  function after the hash array is already read in.)



          (* * kirk 20Jan86 Added NC.AskYesOrNo and InterestedWindow for prompt)



          (* * fgh 5/2/86 Implemented before and after opening hooks using NC.OpenNoteFileFns global variable.)



          (* * fgh 6/8/86 Added code to insure that two files with SameUIDP would never be open at once.)



          (* * fgh 6/25/86 Added contention locks -- NC.ProtectedNoteFileOperation, Don'tCheckOperationInProgressFlg etc.)



          (* * fgh 6/27/86 Added MenuPsotion arg to pass to SetUpNoteFileInterface)



          (* * rht 7/6/86: Added InterestedWindow arg to call to NC.CheckForNeededTruncation.)


    (PROG (NoteFile FileName Name Stream NewStream Card CardTotal)
	    (OR Access (SETQ Access (QUOTE BOTH)))
	    (SETQ FileName (COND
		((type? NoteFile NoteFileOrFileName)
		  (SETQ NoteFile NoteFileOrFileName)
		  (fetch (NoteFile FullFileName) of NoteFileOrFileName))
		(T NoteFileOrFileName)))
	    (if (NOT (OR FileName (SETQ FileName (NC.DatabaseFileName 
								      "Name of NoteFile to open:"
										" -- " T NIL NIL 
										InterestedWindow))))
		then (RETURN NIL))                       (* Use existing notefile object if there is one for 
							     this file name.)
	    (OR (type? NoteFile NoteFile)
		  (SETQ NoteFile (OR (NC.NoteFileFromFileName FileName)
					 (create NoteFile))))

          (* * If there is no interested window, see if the menu window can be used.)


	    (if (AND (NULL InterestedWindow)
			 (fetch (NoteFile Menu) of NoteFile))
		then (SETQ InterestedWindow (WFROMMENU (fetch (NoteFile Menu) of NoteFile)))
		  )

          (* * If this is an open NoteFIle, just bring up its menu.)


	    (if (NC.NoteFileOpenP NoteFile)
		then (NC.SetUpNoteFileInterface NoteFile MenuPosition)
		       (RETURN NIL))

          (* * Check to make sure the file is not already open.)


	    (if (OPENP FileName)
		then                                       (* need a better check here to bring up or create 
							     notefile icon if needed)
		       (NC.PrintMsg InterestedWindow T FileName " is an already open file."
				      (CHARACTER 13))
		       (RETURN NIL))

          (* * Check to see if this NoteFile is busy doing something else)


	    (if (AND (NULL Don'tCheckOperationInProgressFlg)
			 (PROCESSP (NC.NoteFileProp NoteFile (QUOTE ProcessInProgress))))
		then (NC.PrintOperationInProgressMsg InterestedWindow (QUOTE Open% NoteFile)
							 (NC.NoteFileProp NoteFile (QUOTE 
									      OperationInProgress)))
		       (RETURN NIL))

          (* * Run rest of function with contention lock.)


	    (RETURN (NC.ProtectedNoteFileOperation
			NoteFile Open% NoteFile
			(PROG NIL
			        (if (NOT (SETQ Name (INFILEP FileName)))
				    then (COND
					     (Don'tCreateFlg (NC.PrintMsg InterestedWindow T 
									"Couldn't find NoteFile "
									    FileName "."
									    (CHARACTER 13))
							     (RETURN NIL))
					     ((NC.AskYesOrNo (CONCAT "Unable to find NoteFile " 
									 FileName "." (CHARACTER
									   13)
									 
						   "Want to create a new NoteFile by that name? ")
							       " -- " "Yes" T InterestedWindow)
					       (SETQ NoteFile (NC.CreateDatabaseFile FileName NIL 
									       "Opening NoteFile"
											 T))
					       (if (NOT (type? NoteFile NoteFile))
						   then (NC.PrintMsg InterestedWindow T 
								     "Unable to create Notefile "
									 FileName "." (CHARACTER
									   13))
							  (RETURN NIL)
						 else (RETURN (NC.OpenDatabaseFile NoteFile 
											 Access 
								      Don'tCacheTypesAndTitlesFlg 
											 QuietFlg 
										   Don'tCreateFlg 
									     Convertw/oConfirmFlg 
									      Don'tCreateArrayFlg 
										 Don'tTruncateFlg 
									  Don'tCreateInterfaceFlg 
									  Don'tGetSpecialCardsFlg 
										 InterestedWindow T)))
					       )
					     (T (RETURN NIL))))

          (* * Run through OpenNoteFileFns with param of BEFORE. Exit if any returns DON'T)


			        (if (for Function in NC.OpenNoteFileFns
					 thereis (OR (EQ Function (QUOTE DON'T))
							 (EQ (QUOTE DON'T)
							       (APPLY* Function Name NoteFile
									 (QUOTE BEFORE)))))
				    then (RETURN NIL))

          (* * Open the file)


			        (OR QuietFlg (NC.PrintMsg InterestedWindow T "Opening NoteFile " 
							      Name " . . ." (CHARACTER 13)))
			        (if (NULL (SETQ Stream
						(CAR (ERSETQ (OPENSTREAM Name Access
									       (QUOTE OLD)
									       (QUOTE
										 ((TYPE BINARY))))))))
				    then (NC.PrintMsg InterestedWindow T "Couldn't open " 
							  FileName "." (CHARACTER 13))
					   (RETURN NIL))
			        (replace (NoteFile Stream) of NoteFile with Stream)
			        (replace (NoteFile FullFileName) of NoteFile with (FULLNAME
											  Stream))
			        (NC.SetMonitor NoteFile (CREATE.MONITORLOCK (MKATOM
										  (CONCAT Name 
											  ":LOCK"))))
			        (NC.GetNoteFileHeader NoteFile)

          (* * Make sure there is no other open NF with this UID.)


			        (LET (NF)
				     (if (AND (SETQ NF (GETHASH (fetch (NoteFile UID)
									   of NoteFile)
									NC.NoteFilesHashArray))
						  (NEQ (fetch (NoteFile FullFileName)
							    of NoteFile)
							 (fetch (NoteFile FullFileName)
							    of NF))
						  (NC.NoteFileOpenP NF))
					 then (FLASHW PROMPTWINDOW)
						(NC.PrintMsg InterestedWindow T "Couldn't open " 
							       FileName (CHARACTER 13)
							       "because "
							       (fetch (NoteFile FullFileName)
								  of NF)
							       " is already open "
							       (CHARACTER 13)
							       "and has the same UID.")
						(if (STREAMP (fetch (NoteFile Stream)
								    of NoteFile))
						    then (CLOSEF? (fetch (NoteFile Stream)
									 of NoteFile)))
						(replace (NoteFile Stream) of NoteFile
						   with NIL)
						(RETURN NIL)))

          (* * See if notefile is out of date. If so, convert to current version.)


			        (if (NOT (NC.CheckForNeededConversion NoteFile 
									    Convertw/oConfirmFlg 
									    InterestedWindow))
				    then (CLOSEF (fetch (NoteFile Stream) of NoteFile))
					   (NC.PrintMsg InterestedWindow T "Open cancelled.")
					   (RETURN NIL))   (* See if notefile header seems reasonable.
							     If not, bail out.)
			        (if (NOT (NC.PlausibleNoteFileHeaderP NoteFile))
				    then (NC.PrintMsg InterestedWindow NIL 
				       "Notefile has bad header.  Please see a NoteCards wizard."
							  (CHARACTER 13)
							  "Open cancelled.")
					   (RETURN NIL))
			        (COND
				  ((NULL Don'tTruncateFlg)
                                                             (* Can either bail out entirely or run inspector and 
							     then bail out.)
				    (SELECTQ (SETQ NewStream (NC.CheckForNeededTruncation
						   NoteFile Access InterestedWindow))
					       (ABORT (CLOSEF Stream)
						      (NC.PrintMsg InterestedWindow T 
								     "Open cancelled.")
						      (DISMISS 1500)
						      (NC.ClearMsg InterestedWindow T)
						      (RETURN NIL))
					       (ABORTANDINSPECT (CLOSEF Stream)
								(NC.ScavengerPhase1 Name)
								(RETURN NIL))
					       NIL)
				    (AND (STREAMP NewStream)
					   (replace (NoteFile Stream) of NoteFile with 
											NewStream))))

          (* * Stash the notefile in the global notefiles hash array.)


			        (NC.StoreNoteFile NoteFile)

          (* * Build the hash array and cache the special cards if necessary)


			        (OR Don'tCreateArrayFlg (NC.BuildHashArray NoteFile QuietFlg 
									  Don'tGetSpecialCardsFlg 
									       InterestedWindow
									       (CONCAT
										 "Opening NoteFile " 
										 Name (CHARACTER
										   13))))
			        (OR Don'tGetSpecialCardsFlg (NC.GetSpecialCards
					NoteFile QuietFlg InterestedWindow (CONCAT 
									      "Opening NoteFile "
										     Name
										     (CHARACTER
										       13))))

          (* * Make sure the NF can't be closed by CLOSEALL)


			        (WHENCLOSE (fetch (NoteFile Stream) of NoteFile)
					     (QUOTE CLOSEALL)
					     (QUOTE NO))
			        (COND
				  ((NULL Don'tCacheTypesAndTitlesFlg)
                                                             (* Cache all of the titles in this database)
				    (replace (NoteFile CachingProcess) of NoteFile
				       with (ADD.PROCESS (LIST (FUNCTION 
								       NC.CacheTypesAndTitles)
								     NoteFile)))))
			        (COND
				  ((NULL Don'tCreateInterfaceFlg)
                                                             (* Make an interface menu for this notefile.)
				    (NC.SetUpNoteFileInterface NoteFile MenuPosition)))
			        (AND (NULL QuietFlg)
				       (NC.PrintMsg InterestedWindow T "Opened " (FULLNAME Stream)
						      (CHARACTER 13))
				       (NC.ClearMsg InterestedWindow T))
			        (SETQ NC.LastNoteFileOpened NoteFile)

          (* * Run through OpenNoteFIleFns with param of AFTER. Stop if any returns DON'T)


			        (for Function in NC.OpenNoteFileFns
				   thereis (EQ (QUOTE DON'T)
						   (APPLY* Function Name NoteFile (QUOTE AFTER))))

          (* * return the opened NF)


			        (RETURN NoteFile)))))))

(NC.CheckForNeededConversion
  (LAMBDA (NoteFile Convertw/oConfirmFlg InterestedWindow)   (* rht: "16-Jul-86 10:29")

          (* * Check the version of NoteFile. If version 2, then convert if user confirms. If earlier than version 2, then 
	  bail out with informative message.)



          (* * kirk 23Jan86 Changed to use NC.AskYesOrNo)



          (* * rht 7/16/86: Added InterestedWindow arg.)


    (LET ((Stream (fetch (NoteFile Stream) of NoteFile))
	  (Version (fetch (NoteFile Version) of NoteFile))
	  (FullFileName (fetch (NoteFile FullFileName) of NoteFile))
	  NewFileName)
         (COND
	   ((EQ Version 3)
	     NoteFile)
	   ((GEQ Version 4)
	     (NC.ReportError "NC.CheckForNeededConversion" (CONCAT "Version number of notefile: " 
								       FullFileName 
								       " is greater than 3."))
	     NIL)
	   ((LEQ Version 1)
	     (NC.PrintMsg InterestedWindow T "Notefile " FullFileName " is  too old (version " 
			    Version 
").  It must first be converted to version 2 by opening in NoteCards release 1.2i. Then we convert to version 3."
			    (CHARACTER 13))
	     NIL)
	   ((AND Convertw/oConfirmFlg (NOT (NC.AskYesOrNo (CONCAT "Notefile: " FullFileName 
									  " is version 2."
									  (CHARACTER 13)
									  
								 "Want to convert to version 3? ")
								NIL
								(QUOTE Yes)
								T InterestedWindow T NIL)))
	     NIL)
	   ((SETQ NewFileName (NC.AutoloadApply* (FUNCTION NC.ConvertNoteFileVersion2To3)
						   Stream InterestedWindow))

          (* * Things are okay. File was version 2 and has been converted to version 3)


	     (if (SETQ Stream (CAR (ERSETQ (OPENSTREAM NewFileName Access (QUOTE OLD)
								 (QUOTE ((TYPE BINARY)))))))
		 then                                      (* Redo the work at the top of NC.OpenDatabaseFile.)
			(replace (NoteFile Stream) of NoteFile with Stream)
			(replace (NoteFile FullFileName) of NoteFile with (FULLNAME Stream))
			(NC.SetMonitor NoteFile (CREATE.MONITORLOCK (MKATOM (CONCAT 
										      NewFileName 
											  ":LOCK"))))
			(NC.GetNoteFileHeader NoteFile)
			NoteFile
	       else (NC.ReportError "NC.CheckForNeededConversion" (CONCAT "Couldn't open " 
										NewFileName 
						  " after running NC.ConvertNoteFileVersion2To3."
										(CHARACTER 13)))
		      NIL))
	   (T NIL)))))

(NC.CreateDatabaseFile
  (LAMBDA (FileName HashArraySize CallingOperationMsg OmitFinalNoteFlg StartingNextFreeIndex 
		    NoSpecialCardsFlg InterestedWindow QuietFlg)
                                                             (* rht: "16-Jul-86 16:22")

          (* * Create a NoteCards database on file FileName. Just creates an index HashArraySize entries long, then writes 
	  out the Root and Orphan cards)



          (* * rht 8/7/84: Added OmitFinalNoteFlg flag parameter to prevent the final message. Changed parameter name from 
	  NC.IndexSizeInEntries to HashArraySize since the fomer is a global.)



          (* * rht 1/30/85: Reserved 3 bytes of the remaining 8 to hold pointer to last checkpointed EOFPTR.)



          (* * rht 3/21/85: Added the StartingNextFreeIndex argument which if non-nil, gives a NextID Num to be filled in to 
	  the file before returning. This is useful when compacting.)



          (* * fkr 11/8/85: Added check that OPENSTREAM succeeded. Added call to NC.CreateNoteFileObject in which lots of 
	  work is now being done.)



          (* * fgh 11/17/85 Wrapped whole thing in ERSETQ to close file if somethinghappens during the create.)



          (* * kirk 26Dec85 Added NoSpecialCardsFlg flag for use by Compact to target file.)



          (* * rht 1/8/86: Now reuses old notefile object if there is one for this file name.)



          (* * rht 7/13/86: Added QuietFlg arg.)


    (LET (Stream NoteFile)
         (OR (CAR (ERSETQ (PROG NIL
				        (SETQ CallingOperationMsg (COND
					    (CallingOperationMsg (CONCAT CallingOperationMsg
									   (CHARACTER 13)))
					    (T "")))
				        (AND (NULL FileName)
					       (NULL (SETQ FileName
							 (NC.DatabaseFileName 
						"What is the name of the NoteFile to be created?"
										" -- " T T NIL 
										InterestedWindow)))
					       (RETURN (QUOTE CANCELLED)))
				        (OR (FIXP HashArraySize)
					      (SETQ HashArraySize NC.DefaultIndexSizeInEntries))
				        (COND
					  ((NULL (SETQ Stream
						     (CAR (ERSETQ (OPENSTREAM
									FileName
									(QUOTE BOTH)
									(QUOTE NEW)
									(QUOTE ((TYPE BINARY))))))))
					    (NC.PrintMsg InterestedWindow T "Can't open file: " 
							   FileName (CHARACTER 13)
							   "Create cancelled."
							   (CHARACTER 13))
					    (RETURN (QUOTE CANCELLED))))
				        (OR QuietFlg (NC.PrintMsg InterestedWindow T 
								      CallingOperationMsg 
								      "Creating NoteFile "
								      (FULLNAME Stream)
								      ".  Please wait...  "))
				        (SETQ NoteFile (OR (NC.NoteFileFromFileName FileName)
							       (create NoteFile)))
				        (create NoteFile
					   smashing NoteFile UID ←(NC.MakeUID)
						      Stream ← Stream FullFileName ←(FULLNAME
							Stream)
						      HashArray ←(HASHARRAY HashArraySize)
						      HashArraySize ← HashArraySize NextIndexNum ←(
							OR (FIXP StartingNextFreeIndex)
							     (CONSTANT (ADD1 (fetch
										   (NoteFileVersion
										     
									    NumberOfReservedCards)
										    of (
								     NC.FetchCurrentVersionObject)))
									 ))
						      Version ← NC.VersionNumber NextLinkNum ← 1 
						      CheckptPtr ←(NC.TotalIndexSize HashArraySize)
						      MonitorLock ←(CREATE.MONITORLOCK
							(QUOTE Creating)))
                                                             (* Write the header down to the file.)
				        (NC.PutNoteFileHeader NoteFile)
				        (for CTR from 1 to HashArraySize eachtime (BLOCK)
					   do (OR QuietFlg (AND (ZEROP (IREMAINDER CTR 1000)
									       )
								      (NC.PrintMsg InterestedWindow 
										     T 
									      CallingOperationMsg 
									     "Creating NoteFile."
										     (CHARACTER
										       13)
										     
									       "Processing item "
										     CTR " out of " 
										    HashArraySize "."
										     (CHARACTER
										       13))))
						(NC.WriteStatus Stream (QUOTE FREE))
						(SETFILEPTR
						  Stream
						  (PLUS (GETFILEPTR Stream)
							  (CONSTANT (SUB1 (fetch (
NoteFileVersion NoteFileIndexWidth) of (NC.FetchCurrentVersionObject)))))))
				        (OR QuietFlg (NC.PrintMsg InterestedWindow T 
								      CallingOperationMsg 
								      "Creating NoteFile "
								      (FULLNAME Stream)
								      ".  Please wait...  "))
                                                             (* Move NextIndexNum back to the beginning so that 
							     special cards will have the correct index nums.)
				        (replace (NoteFile NextIndexNum) of NoteFile
					   with 1)
				        (OR NoSpecialCardsFlg (NC.InitializeSpecialCards NoteFile)
					      )
				        (NC.CheckpointDatabase NoteFile T)
				        (NC.ForceDatabaseClose NoteFile)
				        (SETQ NC.DatabaseFileNameSuggestion (PACKFILENAME
					    (QUOTE VERSION)
					    NIL
					    (QUOTE BODY)
					    (FULLNAME FileName)))
				        (OR QuietFlg (COND
						(OmitFinalNoteFlg (NC.PrintMsg InterestedWindow NIL 
										 "  Done!"
										 (CHARACTER 13)))
						(T (NC.PrintMsg InterestedWindow NIL "  Done!"
								  (CHARACTER 13)
								  "Note that the NoteFile must still" 
								  " be opened before it is used."
								  (CHARACTER 13)))))
				        (RETURN NoteFile))))
	       (CLOSEF Stream (DELFILE (FULLNAME Stream)))
	       (QUOTE CANCELLED)))))

(NC.CheckpointDatabase
  (LAMBDA (NoteFile QuietFlg Don'tSaveDirtyCardsFlg Don'tCheckOperationInProgressFlg 
		    Don'tCheckCardOperationsInProgressFlg InterestedWindow OperationMsg)
                                                             (* rht: "16-Jul-86 17:44")

          (* * First save to the database any cards currently dirty. Copy the index array back into the file and set the 
	  LastChkptPtr to the end of the file.)



          (* * rht 11/12/85: Now calls NC.PutHashArray to do the hard work.)



          (* * fgh 6/4/86 Added Don'tSaveDirtyCardsFlg to prevent double passes through active cards at close time)



          (* * fgh 6/13/86 Changed printouts to NF menu. Added check for operations in progress.)



          (* * fgh 6/25/86 Put in contention lock and NC.ProtectedNoteFileOperation Added Don'tCheckOperationInProgressFlg 
	  Don'tCheckCardOperationsInProgressFlg & InterestedWindow args.)



          (* * rht 7/4/86: Added check for readonly notefile.)



          (* * rht 7/16/86: Now passes QuietFlg arg down to NC.SaveDirtyCards.)


    (OR InterestedWindow (SETQ InterestedWindow (WFROMMENU (fetch (NoteFile Menu)
								    of NoteFile))))
    (if (NC.CheckForNotReadOnly NoteFile InterestedWindow "Can't checkpoint ")
	then (LET ((Stream (fetch (NoteFile Stream) of NoteFile))
		     (FullFileName (fetch (NoteFile FullFileName) of NoteFile)))
		    (SETQ OperationMsg (OR OperationMsg (CONCAT "Checkpointing Notefile " 
								      FullFileName (CHARACTER
									13))))
		    (if (AND (NULL Don'tCheckOperationInProgressFlg)
				 (PROCESSP (NC.NoteFileProp NoteFile (QUOTE ProcessInProgress)))
				 )
			then 

          (* * Another operation is in progress on this NF.)


			       (NC.PrintOperationInProgressMsg InterestedWindow (QUOTE 
									     Checkpoint% NoteFile)
								 (NC.NoteFileProp NoteFile
										    (QUOTE 
									      OperationInProgress)))
		      elseif (NULL (NC.NoteFileOpenP NoteFile))
			then 

          (* * This NF is not open.)


			       (NC.PrintMsg InterestedWindow T FullFileName 
					      " is not an open NoteFile!!!"
					      (CHARACTER 13))
		      else 

          (* * Okay checkpoint under a contention lock.)


			     (NC.ProtectedNoteFileOperation
			       NoteFile Checkpoint% NoteFile
			       (OR QuietFlg (RESETSAVE NIL (BQUOTE (NC.ClearMsg , 
										 InterestedWindow T)))
				     )
			       (if (OR Don'tCheckCardOperationsInProgressFlg
					   (PROGN (OR QuietFlg (NC.PrintMsg InterestedWindow T 
										  OperationMsg 
						      "Checking for card operations in progress."
										  (CHARACTER 13)))
						    (NULL (SETQ OpsInProgress (
								NC.CardOperationsInProgress 
											 NoteFile))))
					   (NC.AskYesOrNo (CONCAT 
							 "There are card operations in progress."
								      (CHARACTER 13)
								      
								 "Do you want to terminate them?"
								      (CHARACTER 13))
							    "-->"
							    (QUOTE Yes)
							    T InterestedWindow))
				   then (OR QuietFlg (NC.PrintMsg InterestedWindow T 
									OperationMsg " ..."))
					  (if (NULL Don'tSaveDirtyCardsFlg)
					      then (NC.SaveDirtyCards NoteFile T InterestedWindow 
									  OperationMsg QuietFlg))
                                                             (* Put out the new ChkptPtr to the file.)
					  (NC.PutHashArray NoteFile QuietFlg OperationMsg NIL 
							     InterestedWindow)
					  (replace (NoteFile CheckptPtr) of NoteFile
					     with (GETEOFPTR Stream))
					  (NC.PutNoteFileHeader NoteFile)
					  (OR QuietFlg (PROGN (NC.PrintMsg InterestedWindow T 
										 OperationMsg "Done."
										 (CHARACTER 13))
								  (DISMISS 250)
								  (NC.ClearMsg InterestedWindow T)))
				     )))))))
)
(* * Changes to NCCONVERTVERSION2TO3)

(DEFINEQ

(NC.ConvertNoteFileVersion2To3
  (LAMBDA (StreamOrFileName InterestedWindow)                (* rht: "16-Jul-86 17:45")

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



          (* * rht 7/16/86: Added InterestedWindow arg.)


    (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 NIL NIL 
								InterestedWindow))
		    (SETQ ToFileName (fetch (NoteFile FullFileName) of ToNoteFile))
		    (if (AND (type? NoteFile ToNoteFile)
				 (NC.OpenDatabaseFile ToNoteFile NIL T T NIL NIL NIL NIL T NIL 
							InterestedWindow))
			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 InterestedWindow 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 InterestedWindow 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 InterestedWindow 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 ToNoteFile NIL NIL NIL InterestedWindow)
			       (NC.PrintMsg InterestedWindow T "Done.")
			       ToFileName)
	   else (NC.ReportError "NC.ConvertNoteFileVersion2To3" (CONCAT "Filename " FileName 
									      " is version "
									      Version 
						       ".  Can only convert version 2 notefiles."))
		  NIL))))
)
(* * Changes to NCREPAIR)

(DEFINEQ

(NC.ScavengeDatabaseFile
  (LAMBDA (NoteFileOrFileName BadLinkLabelsFlg ListOfBoxesToReconstruct 
			      ListOfCardsNeedingGlobalLinksReconstructed InterestedWindow)
                                                             (* rht: "16-Jul-86 17:13")

          (* Scavenge the database FileName. Essentially throw away all of the information about From and ToLinks and 
	  recreate them by retrieving the link information from the substance of each card and from the list of global links 
	  from the card.)



          (* * rht 8/9/84: Now calls NC.OpenDatabaseFile to do the file open.)



          (* * rht 7/17/85: Changed so can take a stream argument. Also handles link labels. If BadLinkLabelsFlg is non-nil, 
	  then don't try to read current link labels. Just rebuild them from what's out there. Otherwise, only rebuild if 
	  find new any new ones.)



          (* * fgh 22-Jul-85 Takes a list of bad file box cards and reconstructs the file boxes from the From pointer lists 
	  of all the cards in the NoteFile.)



          (* * fgh 30-Jul-85 Takes a list of cards with bad global links and reconstructs the global links list from the From
	  pointer lists of all the cards in the NoteFile.)



          (* * rht 11/23/85: Updated to handle new notefile and card object formats.)



          (* * rht 12/1/85: Now calls NC.GetMainCardData and NC.GetLinks instead of NC.GetNoteCard.)



          (* * rht 12/19/85: Massive overhaul for sake of speed. Should be wizzier now.)



          (* * fgh 2/4/86 Now works on open NFs. No need to error check since this function should always be called from 
	  earlier phases of the inspect & repaier.)



          (* * fgh 5/21/86 Fixed bug in handling of global links.)



          (* * rht 7/16/86: Added InterestedWindow arg.)


    (PROG (NoteFile FileName CardTotal NoteCardNumber OldLinkLabels DiscoveredLinkLabels 
		      ReconstructLinks ReconstructGlobalLinks ToBeFiledCards)

          (* * First, take care of checking stream's validity, etc.)


	    (SETQ FileName (if (type? NoteFile NoteFileOrFileName)
				 then (SETQ NoteFile NoteFileOrFileName)
					(fetch (NoteFile FullFileName) of NoteFileOrFileName)
			       else NoteFileOrFileName))   (* Try to open notefile.)
	    (if (NULL (OPENP FileName))
		then (if (NULL (SETQ NoteFile
				       (NC.OpenDatabaseFile FileName NIL T NIL NIL NIL NIL T T NIL 
							      InterestedWindow)))
			   then (NC.PrintMsg InterestedWindow NIL "Couldn't open " FileName "."
						 (CHARACTER 13)
						 "Repair aborted."
						 (CHARACTER 13))
				  (RETURN NIL)))

          (* * If link labels aren't screwed up, then read them in.)


	    (OR BadLinkLabelsFlg (SETQ OldLinkLabels (NC.RetrieveLinkLabels NoteFile T)))

          (* * Mark every card that needs its global links or substance reconstructed so we don't have to search the lists so
	  much.)


	    (for Card in ListOfCardsNeedingGlobalLinksReconstructed do (NC.SetUserDataProp
									       Card
									       (QUOTE 
								 NeedsGlobalLinksReconstructedFlg)
									       T))
	    (for Box in ListOfBoxesToReconstruct do (NC.SetUserDataProp Box (QUOTE 
									   NeedsReconstructingFlg)
										T))

          (* Read through all NoteCard substances to find actual pointers. Use this to create the To Links list.
	  The list collection function checks to make sure each link is valid.)


	    (SETQ CardTotal (SUB1 (fetch (NoteFile NextIndexNum)
					       NoteFile)))
	    (NC.PrintMsg InterestedWindow T "Rebuilding notefile links." (CHARACTER 13)
			   "Collecting Links for item " 1 " out of " CardTotal "." (CHARACTER
			     13))
	    (SETQ NoteCardNumber 0)
	    (NC.MapCards
	      NoteFile
	      (FUNCTION (LAMBDA (Card)
		  (SETQ NoteCardNumber (ADD1 NoteCardNumber))
		  (AND (ZEROP (REMAINDER NoteCardNumber 10))
			 (NC.PrintMsg InterestedWindow T "Rebuilding notefile links." (CHARACTER
					  13)
					"Collecting Links for item " NoteCardNumber " out of " 
					CardTotal "." (CHARACTER 13)))
		  (if (NC.FetchUserDataProp Card (QUOTE NeedsReconstructingFlg))
		      then                                 (* Card substance and links will be reconstructed so 
							     no need to try to read substance.)
			     (NC.GetLinks Card)
			     (if (NOT (NC.FetchUserDataProp Card (QUOTE 
								 NeedsGlobalLinksReconstructedFlg)))
				 then (NC.SetUserDataProp Card (QUOTE ScavengerToLinks)
							      (NC.FetchGlobalLinks Card))
					(NC.SetUserDataProp Card (QUOTE ScavengerGlobalLinks)
							      (NC.FetchGlobalLinks Card)))
			     (NC.DeactivateCard Card T)
		    else (NC.GetMainCardData Card)
			   (NC.GetLinks Card)
			   (NC.ActivateCard Card)
			   (if (EQ (NC.FetchStatus Card)
				       (QUOTE ACTIVE))
			       then                        (* Collect links having active destinations.
							     Delete the others.)
				      (NC.SetUserDataProp
					Card
					(QUOTE ScavengerToLinks)
					(NCONC (for Link in (CAR (NC.CollectReferences
									   Card))
						    eachtime (BLOCK)
						    when (if (EQ (NC.FetchStatus
									 (fetch (Link 
										  DestinationCard)
									    of Link))
								       (QUOTE ACTIVE))
							     else (NC.DelReferencesToCard Card 
											     Link)
								    NIL)
						    collect Link)
						 (if (NC.FetchUserDataProp Card (QUOTE 
								 NeedsGlobalLinksReconstructedFlg))
						   else (NC.SetUserDataProp Card (QUOTE 
									     ScavengerGlobalLinks)
										(NC.FetchGlobalLinks
										  Card))
							  (NC.FetchGlobalLinks Card))))
				      (if (NC.FetchUserDataProp Card (QUOTE 
								 NeedsGlobalLinksReconstructedFlg))
					else (NC.SetUserDataProp Card (QUOTE 
									     ScavengerGlobalLinks)
								     (NC.FetchGlobalLinks Card)))

          (* If there are file boxes to be reconstructed, then look thru the From links to see if this card was filed in one 
	  of the to-be-reconstructed boxes)


				      (AND ListOfBoxesToReconstruct
					     (for Link in (NC.FetchFromLinks Card)
						eachtime (BLOCK)
						when (AND (NC.ChildLinkP Link)
							      (NC.FetchUserDataProp
								(fetch (Link SourceCard)
								   of Link)
								(QUOTE NeedsReconstructingFlg)))
						do (push ReconstructLinks Link)))

          (* If there are global links to be reconstructed, then look thru the From links to see if this card had a global 
	  link from a card whose global links need reconstructing.)


				      (AND ListOfCardsNeedingGlobalLinksReconstructed
					     (for Link in (NC.FetchFromLinks Card)
						eachtime (BLOCK)
						when (AND (NC.GlobalLinkP Link)
							      (NC.FetchUserDataProp
								(fetch (Link SourceCard)
								   of Link)
								(QUOTE 
								 NeedsGlobalLinksReconstructedFlg)))
						do (push ReconstructGlobalLinks Link)))
				      (NC.DeactivateCard Card T))))))

          (* * Reconstruct any cards as requested)


	    (for BoxToReconstruct in ListOfBoxesToReconstruct eachtime (BLOCK)
	       do                                          (* Make a new file box using the given card.)
		    (NC.MakeNoteCard (QUOTE FileBox)
				       NoteFile "Untitled: Reconstructed during repair" T NIL 
				       BoxToReconstruct)

          (* File cards whose from links indicate that they used to be filed in this file box. Also add these new links to 
	  collected ToLinks.)


		    (NC.SetUserDataProp BoxToReconstruct (QUOTE ScavengerToLinks)
					  (APPEND (NC.FetchUserDataProp BoxToReconstruct
									    (QUOTE ScavengerToLinks)
									    )
						    (for Link in ReconstructLinks
						       eachtime (BLOCK)
						       when (NC.SameCardP BoxToReconstruct
									      (fetch (Link 
										       SourceCard)
										 of Link))
						       collect (NC.MakeChildLink
								   (fetch (Link DestinationCard)
								      of Link)
								   BoxToReconstruct NIL))))
                                                             (* Put the card away)
		    (NC.PutMainCardData BoxToReconstruct)
		    (NC.DeactivateCard BoxToReconstruct T))

          (* * Reconstruct any global link lists as required)


	    (for Link in ReconstructGlobalLinks bind ThisCardsToLinks ThisCardsGlobalLinks 
							   SourceCard
	       eachtime (BLOCK)
	       do (SETQ SourceCard (fetch (Link SourceCard) of Link)) 
                                                             (* Add it to the GlobalLinks list for its source card 
							     unless it's already there.)
		    (if (for GlobalLink in (SETQ ThisCardsGlobalLinks (NC.FetchUserDataProp
						     SourceCard
						     (QUOTE ScavengerGlobalLinks)))
			     eachtime (BLOCK) never (NC.SameLinkP Link GlobalLink))
			then (NC.SetUserDataProp SourceCard (QUOTE ScavengerGlobalLinks)
						     (CONS Link ThisCardsGlobalLinks)))
                                                             (* Add it to the source card's ToLinks list unless 
							     it's already there)
		    (if (for ToLink in (SETQ ThisCardsToLinks (NC.FetchUserDataProp
						 SourceCard
						 (QUOTE ScavengerToLinks)))
			     eachtime (BLOCK) never (NC.SameLinkP Link ToLink))
			then (NC.SetUserDataProp SourceCard (QUOTE ScavengerToLinks)
						     (CONS Link ThisCardsToLinks))))

          (* * Compute the From Links list by "inverting" the To Links list)


	    (NC.PrintMsg InterestedWindow T "Repairing NoteFile." (CHARACTER 13)
			   "Inverting links for item " 1 " out of " CardTotal "." (CHARACTER 13))
	    (SETQ NoteCardNumber 0)
	    (NC.MapCards NoteFile (FUNCTION (LAMBDA (Card)
			       (SETQ NoteCardNumber (ADD1 NoteCardNumber))
			       (AND (ZEROP (REMAINDER NoteCardNumber 100))
				      (NC.PrintMsg InterestedWindow T "Repairing NoteFile."
						     (CHARACTER 13)
						     "Inverting links for item " NoteCardNumber 
						     " out of "
						     CardTotal "." (CHARACTER 13)))
			       (if (EQ (NC.FetchStatus Card)
					   (QUOTE ACTIVE))
				   then (for Link in (NC.FetchUserDataProp Card (QUOTE
										     ScavengerToLinks)
										   )
					     bind DestinationCard LinkLabel eachtime (BLOCK)
					     do            (* Add this ToLink as a FromLink for the link's 
							     destination card.)
						  (NC.SetUserDataProp (SETQ DestinationCard
									  (fetch (Link 
										  DestinationCard)
									     of Link))
									(QUOTE ScavengerFromLinks)
									(CONS Link
										(
									     NC.FetchUserDataProp
										  DestinationCard
										  (QUOTE 
									       ScavengerFromLinks))))
                                                             (* Accumulate the link labels into a list.)
						  (if (NOT (FMEMB (SETQ LinkLabel
									  (fetch (Link Label)
									     of Link))
									DiscoveredLinkLabels))
						      then (push DiscoveredLinkLabels LinkLabel)))
				     ))))

          (* * Reset all of the To and From Links lists in the database)


	    (NC.PrintMsg InterestedWindow T "Repairing NoteFile." (CHARACTER 13)
			   "Rewriting links for item " 1 " out of " CardTotal "." (CHARACTER 13))
	    (SETQ NoteCardNumber 0)
	    (NC.MapCards NoteFile (FUNCTION (LAMBDA (Card)
			       (SETQ NoteCardNumber (ADD1 NoteCardNumber))
			       (AND (ZEROP (REMAINDER NoteCardNumber 10))
				      (NC.PrintMsg InterestedWindow T "Repairing NoteFile."
						     (CHARACTER 13)
						     "Rewriting links for item " NoteCardNumber 
						     " out of "
						     CardTotal "." (CHARACTER 13)))
			       (if (EQ (NC.FetchStatus Card)
					   (QUOTE ACTIVE))
				   then (NC.SetGlobalLinks Card (NC.FetchUserDataProp
								 Card
								 (QUOTE ScavengerGlobalLinks)))
					  (NC.SetToLinks Card (NC.FetchUserDataProp Card
											(QUOTE
											  
										 ScavengerToLinks)))
					  (NC.SetFromLinks Card (NC.FetchUserDataProp
							       Card
							       (QUOTE ScavengerFromLinks)))
                                                             (* Check whether this card isn't filed anywhere.)
					  (if (AND (NOT (NC.UndeletableCardP Card))
						       (for Link in (NC.FetchFromLinks Card)
							  eachtime (BLOCK) never (
										    NC.ChildLinkP
											 Link)))
					      then (push ToBeFiledCards Card))
					  (NC.PutLinks Card))
                                                             (* Clean any junk off the card.)
			       (NC.DeactivateCard Card T)
			       (NC.SetUserDataPropList Card NIL))))

          (* * File any unfiled cards in the ToBeFiled box.)


	    (if ToBeFiledCards
		then (NC.PrintMsg InterestedWindow T "Filing " (LENGTH ToBeFiledCards)
				      " cards in ToBeFiled box ..."
				      (CHARACTER 13))
		       (NCP.FileCards ToBeFiledCards (fetch (NoteFile ToBeFiledCard)
							  of NoteFile)))
                                                             (* Rewrite link labels if we've found any new ones.)
	    (if (LDIFFERENCE DiscoveredLinkLabels OldLinkLabels)
		then (NC.StoreLinkLabels NoteFile (UNION DiscoveredLinkLabels OldLinkLabels)))
                                                             (* Clean up and get out.)
	    (NC.CheckpointDatabase NoteFile T)
	    (NC.ForceDatabaseClose NoteFile)
	    (NC.PrintMsg InterestedWindow T "Repair Completed for " (FULLNAME FileName)
			   "."
			   (CHARACTER 13))
	    (if ToBeFiledCards
		then (NC.PrintMsg InterestedWindow NIL "Filed " (LENGTH ToBeFiledCards)
				      " cards in ToBeFiled box.")))))

(NC.ScavengerPhase1
  (LAMBDA (FileNameOrNoteFile ReadSubstancesFlg ScavengerInteractionWin RecheckBadCardsFlg 
			      InterestedWindow)              (* rht: "16-Jul-86 18:20")

          (* * This is the first phase of the scavenger. Runs over entire data portion of the notefile, accumulating pointers
	  to healthy parts of cards. Then runs over index array asking user what to do with bad or outdated pointers.
	  If ReadSubstancesFlg is non-nil then it'll do robust gets of the substances. This slows things down, but makes 
	  checking more comprehensive.)



          (* * rht 12/7/85: Updated to handle new notefile and card object formats.)



          (* * rht 3/22/86: No longer hangs bad cards off proplist of Reason atoms. Uses local var ReasonsHashArray instead.
	  NC.ScavengerPhase1 no longer hanging on completion of phase 3)



          (* * rht 7/7/86: Now passes non-nil Don'tCheckOperationInProgress flg to NC.OpenDatabaseFile.)



          (* * rht 7/16/86: Added InterestedWindow arg.)


    (PROG (FileName NoteFile UnknownCardTypesList ReasonsList ReasonsHashArray CardsToDelete Menu 
		      MenuItems LinkLabelsNews CardTotal BadNewsList BadBoxes ExtraBadNews 
		      FirstTimeFlg InspectorPendingEvent NoteFileMenu NoteFileOpsMenuItem 
		      CanDoPhase3Flg NoteFileStream)

          (* * First, take care of opening notefile if needed.)


	    (if (AND (type? NoteFile FileNameOrNoteFile)
			 (SETQ NoteFileStream (fetch (NoteFile Stream) of FileNameOrNoteFile))
			 (OPENP NoteFileStream))
		then                                       (* This notefile is already open For when we do 
							     recursive call.)
		       (SETQ NoteFile FileNameOrNoteFile)
	      else                                         (* Get file name and open the file if conditions are 
							     okay.)
		     (SETQ FileName FileNameOrNoteFile)
		     (AND (NULL FileName)
			    (NULL (SETQ FileName (NC.DatabaseFileName 
					   "What is the name of the NoteFile to Inspect&Repair? "
									    NIL T NIL NIL 
									    InterestedWindow)))
			    (RETURN NIL))
		     (AND (NULL (SETQ NoteFile
				      (NC.OpenDatabaseFile FileName NIL T NIL NIL NIL NIL T T NIL 
							     InterestedWindow T)))
			    (NC.PrintMsg InterestedWindow NIL "Couldn't open " FileName "."
					   (CHARACTER 13)
					   "Repair aborted."
					   (CHARACTER 13))
			    (RETURN NIL))
		     (NC.PrintMsg InterestedWindow NIL "Done."))
	    (SETQ CardTotal (SUB1 (fetch (NoteFile NextIndexNum) of NoteFile)))
                                                             (* Build a window for talking to the user if one 
							     wasn't passed in.)
	    (if (WINDOWP ScavengerInteractionWin)
		then (CLEARW ScavengerInteractionWin)
	      else (SETQ ScavengerInteractionWin (CREATEW NC.ScavengerInteractionWinRegion 
							      "Inspect&Repair Interaction Window"
								NIL T))
                                                             (* This flg indicates that we're in the first call to 
							     the scavenger.)
		     (SETQ FirstTimeFlg T)
		     (WINDOWADDPROP ScavengerInteractionWin (QUOTE CLOSEFN)
				      (FUNCTION NC.MessageWinCloseFn)
				      T))                    (* Get all relevant info about the data area of the 
							     notefile onto the cards' prop lists.)
	    (if (OR (NOT FirstTimeFlg)
			(EQ (NC.GetScavengerInfo NoteFile ReadSubstancesFlg 
						     ScavengerInteractionWin InterestedWindow)
			      (QUOTE SUCCESS)))
		then (WINDOWPROP ScavengerInteractionWin (QUOTE NOTEFILE)
				     NoteFile)
		       (WINDOWPROP ScavengerInteractionWin (QUOTE CARDTOTAL)
				     CardTotal)
	      else                                         (* Something's wrong. Couldn't get scavenger info.
							     Bail out.)
		     (NC.ScavengerCleanup ScavengerInteractionWin InterestedWindow)
		     (CLOSEW ScavengerInteractionWin)
		     (RETURN NIL))

          (* * Check the list of card types that are undefined to see if user has loaded a definition since the last time we 
	  checked. If he has, then go try to read the substance card parts for those newly defined card types.)


	    (NC.CheckUnknownCardTypes NoteFile ReadSubstancesFlg ScavengerInteractionWin)

          (* * Next step is to run down the in-core index and find those cards having pointers to bad items in the data area.
	  We also need to look for undefined card types and for pointers past the checkpoint pointer.
	  However, we can reuse old bad news list if nothing has changed.)


	    (if (OR FirstTimeFlg RecheckBadCardsFlg (WINDOWPROP ScavengerInteractionWin
								      (QUOTE NEEDCHECKPOINT)))
		then (WINDOWPROP ScavengerInteractionWin (QUOTE ORIGINALBADNEWSLIST)
				     (SETQ BadNewsList (NC.BuildBadCardsList NoteFile 
									  ScavengerInteractionWin 
										 FirstTimeFlg 
										 InterestedWindow)))
	      else (SETQ BadNewsList (WINDOWPROP ScavengerInteractionWin (QUOTE 
									      ORIGINALBADNEWSLIST))))

          (* * Okay, now all the troublesome IDs and the reasons for their troubles are recorded in BadNewsList.
	  We next need to get directives from the user as to what to do for each problem card.)


	    (NC.RepositionWindowIfNeeded ScavengerInteractionWin)
                                                             (* If there's bad news for link labels then take off 
							     list and store in a local var.)
	    (if (SETQ LinkLabelsNews (for BadCardEntry in BadNewsList
					    bind (LinkLabelsCard ←(fetch (NoteFile LinkLabelsCard)
								       of NoteFile))
					    eachtime (BLOCK) when (NC.SameCardP 
										   LinkLabelsCard
											(CAR 
										     BadCardEntry))
					    do (RETURN BadCardEntry)))
		then (SETQ BadNewsList (DREMOVE LinkLabelsNews BadNewsList)))
                                                             (* Accumulate general statistics on the problems.)
	    (SETQ ReasonsHashArray (HASHARRAY 100))
	    (for BadNews in BadNewsList bind Card Type eachtime (BLOCK)
	       unless (FMEMB (CADR BadNews)
				 (QUOTE (DELETED FREE)))
	       do (SETQ Card (CAR BadNews))
		    (for Reason in (CDDDR BadNews) eachtime (BLOCK)
		       do (PUTHASH Reason (CONS Card (GETHASH Reason ReasonsHashArray))
				       ReasonsHashArray)
			    (if (NOT (FMEMB Reason ReasonsList))
				then (SETQ ReasonsList (CONS Reason ReasonsList)))
			    (if (EQ Reason (QUOTE UNKNOWNCARDTYPE))
				then                       (* Accumulate the list of unknown card types for 
							     nondeleted cards.)
				       (if (NOT (FMEMB (SETQ Type (
								 NC.FetchTypeFromScavengerInfo
								 Card))
							     UnknownCardTypesList))
					   then (push UnknownCardTypesList Type)))))
                                                             (* Build the menu entries that we know will be present
							     regardless of which cards are bad.)
	    (SETQ MenuItems (QUOTE ((Abort (QUOTE Abort)
					       "Quit this Inspect&Repair operation.")
					 (Recheck% Bad% Cards (QUOTE Recheck% Bad% Cards)
							      
	    "Recompute bad cards list.  Useful if you've just loaded some card type definitions.")
					 (Inspect% Cards (QUOTE Inspect% Cards)
							 "Bring up the cards inspector menu."
							 (SUBITEMS (Include% Deleted% Cards
								     (QUOTE Include% Deleted% Cards)
								     
								"Throw in deleted cards as well.")))))
	      )                                              (* Print a message if news on link labels is worse 
							     than just past checkpoint.)
	    (if (AND LinkLabelsNews (NOT (EQUAL (CDDDR LinkLabelsNews)
							(QUOTE (MAINDATAPASTCHKPT)))))
		then (push ExtraBadNews LinkLabelsNews)
		       (NC.PrintMsg ScavengerInteractionWin NIL "The link types are bad."
				      (CHARACTER 13)
				      
"If you don't back them up to a previous version, then phase 3 of Inspect&Repair will rebuild them."
				      (CHARACTER 13))
		       (WINDOWPROP ScavengerInteractionWin (QUOTE NEEDLINKSCAVENGE)
				     T))                     (* Collect any fileboxes that have bad substances.)
	    (if (SETQ BadBoxes (LET (Boxes)
				        (SETQ BadNewsList
					  (for News in BadNewsList bind Box eachtime
										   (BLOCK)
					     unless (if (AND (EQ (
								    NC.FetchTypeFromScavengerInfo
									   (SETQ Box (CAR News)))
									 (QUOTE FileBox))
								   (FMEMB (QUOTE BADMAINDATA)
									    (CDDDR News)))
							  then (push Boxes Box) 
                                                             (* If nothing else is wrong with those boxes, then 
							     take off bad news list.)
								 (EQ (LENGTH (CDDDR News))
								       1)
							else NIL)
					     collect News))
				    Boxes))
		then (NC.PrintMsg ScavengerInteractionWin NIL "Fileboxes "
				      (for Box in BadBoxes collect (
								   NC.FetchTitleFromScavengerInfo
									   Box))
				      " have bad substance(s)."
				      (CHARACTER 13)
				      
"If you don't delete them or back up to a previous version, then phase 3 of Inspect&Repair will rebuild their contents."
				      (CHARACTER 13))
		       (WINDOWPROP ScavengerInteractionWin (QUOTE NEEDLINKSCAVENGE)
				     T))                     (* Print out totals of active and deleted cards.)
	    (LET ((ActivesTotal 0)
		  (DeletedsTotal 0))
	         (NC.MapCards NoteFile (FUNCTION (LAMBDA (Card)
				    (SELECTQ (NC.FetchStatus Card)
					       (ACTIVE (SETQ ActivesTotal (ADD1 ActivesTotal)))
					       (DELETED (SETQ DeletedsTotal (ADD1 DeletedsTotal)))
					       NIL))))
	         (NC.PrintMsg ScavengerInteractionWin NIL "Out of " CardTotal " cards:"
				(CHARACTER 13)
				"there are " ActivesTotal " active cards and " DeletedsTotal 
				" deleted cards."
				(CHARACTER 13)))
	    (if ReasonsList
		then                                       (* Print out messages for bad cards.)
		       (NC.PrintMsg ScavengerInteractionWin NIL "Of the non-deleted ones,"
				      (CHARACTER 13))
		       (for Reason in ReasonsList eachtime (BLOCK)
			  do (NC.PrintMsg ScavengerInteractionWin NIL (LENGTH (GETHASH Reason 
										 ReasonsHashArray))
					      " have "
					      (GETPROP Reason (QUOTE ReasonString))
					      (CHARACTER 13))
			       (if (EQ Reason (QUOTE UNKNOWNCARDTYPE))
				   then (NC.PrintMsg ScavengerInteractionWin NIL 
							 "The unknown types are: "
							 UnknownCardTypesList "." (CHARACTER 13))))
	      else (NC.PrintMsg ScavengerInteractionWin NIL "All non-deleted cards look okay."
				    (CHARACTER 13)))

          (* Only allow continuation to phase 3 of repair, links rebuilding, if there's no bad news that can't be fixed.
	  We can fix bad proplist, titles or links. We can also fix even bad substances if they're for fileboxes.)


	    (if (for News in BadNewsList eachtime (BLOCK)
		     unless (FMEMB (CADR News)
				       (QUOTE (DELETED FREE)))
		     unless (EQ (NC.FetchTypeFromScavengerInfo (CAR News))
				    (QUOTE FileBox))
		     never (INTERSECTION (CDDDR News)
					     (QUOTE (BADMAINDATA UNKNOWNCARDTYPE))))
		then                                       (* Add the appropriate menu items.)
		       (if (NOT (WINDOWPROP ScavengerInteractionWin (QUOTE NEEDLINKSCAVENGE)))
			   then (SETQ MenuItems (CONS (QUOTE (End% Inspect&Repair
								       (QUOTE End% Inspect&Repair)
								       
				      "This exits Inspect&Repair normally, closing the notefile."))
							    MenuItems)))
		       (SETQ CanDoPhase3Flg T)
		       (SETQ MenuItems (CONS (QUOTE (Continue% Repair (QUOTE Continue% Repair)
									    
					       "Complete Inspect&Repair by rebuilding the links."))
						 MenuItems)))
                                                             (* Make sure a checkpoint will happen before 
							     continuing to phase 3 if there are any card parts 
							     beyond the checkpt pointer.)
	    (if (INTERSECTION ReasonsList (QUOTE (MAINDATAPASTCHKPT LINKSPASTCHKPT 
									  TITLEPASTCHKPT 
									  PROPLISTPASTCHKPT)))
		then (AND CanDoPhase3Flg (NC.PrintMsg ScavengerInteractionWin NIL 
		  "'Continue Repair' will integrate any card part versions beyond chkpt pointer."
							    (CHARACTER 13)))
		       (WINDOWPROP ScavengerInteractionWin (QUOTE NEEDCHECKPOINT)
				     T))                     (* Ugliness! Have to cache all these vars on window so
							     that attached menu's whenselectedfn will be able to 
							     grab them.)
	    (WINDOWPROP ScavengerInteractionWin (QUOTE BADNEWSLIST)
			  BadNewsList)
	    (WINDOWPROP ScavengerInteractionWin (QUOTE EXTRABADNEWS)
			  ExtraBadNews)
	    (WINDOWPROP ScavengerInteractionWin (QUOTE LINKSLABELSNEWS)
			  LinkLabelsNews)
	    (WINDOWPROP ScavengerInteractionWin (QUOTE BADBOXES)
			  BadBoxes)
	    (ATTACHMENU (create MENU
				    ITEMS ← MenuItems
				    WHENSELECTEDFN ←(FUNCTION 
				      NC.MessageWinAttachedMenuWhenSelectedFn)
				    MENUFONT ← NC.ScavengerAttachedMenuFont)
			  ScavengerInteractionWin
			  (QUOTE RIGHT)
			  (QUOTE TOP)))))

(NC.BuildBadCardsList
  (LAMBDA (NoteFile MessageWin FirstTimeFlg InterestedWindow)
                                                             (* rht: "16-Jul-86 16:03")

          (* * Returns a list of all IDs with illegal index pointers, i.e. pointers not to valid data areas recorded in 
	  ScavengerArray. Also record those IDs with pointers beyond checkpoint ptr.)



          (* * rht 9/17/85: Now takes MessageWin argument so can extract the MaxIDNum off its props.)



          (* * rht 12/7/85: Modified to reflect new card and notefile object formats.)



          (* * fgh 2/4/86 Fixed minor bug where UNKNOWNCARDTYPE apeeared in a singleton list.)



          (* * rht 7/16/86: Added InterestedWindow arg.)


    (LET ((CardTotal (SUB1 (fetch (NoteFile NextIndexNum) of NoteFile)))
	  (CheckptPtr (fetch (NoteFile CheckptPtr) of NoteFile))
	  (Num 0)
	  Results)
         (NC.PrintMsg InterestedWindow T "Building bad cards list ..." (CHARACTER 13)
			"Processing item number " 1 " out of " CardTotal "." (CHARACTER 13))
         (NC.MapCards NoteFile
			(FUNCTION (LAMBDA (Card)
			    (LET (Problems)
			         (SETQ Num (ADD1 Num))
			         (if (ZEROP (IREMAINDER Num 100))
				     then (NC.PrintMsg InterestedWindow T 
							   "Building bad cards list ..."
							   (CHARACTER 13)
							   "Processing item number " Num " out of " 
							   CardTotal "." (CHARACTER 13)))
                                                             (* If card is not worthless, has reasonable status, 
							     and at least one problem, then make a bad card entry 
							     for it.)
			         (if (AND (NOT (NC.WorthlessCardP Card))
					      (FMEMB (NC.FetchStatus Card)
						       (QUOTE (ACTIVE DELETED SPECIAL BADPOINTER 
									NIL)))
					      (SETQ Problems
						(LET ((IndexLocsProblems (NC.CheckIndexLocs Card 
										       MessageWin 
										       CheckptPtr 
										     FirstTimeFlg))
						      (Type (NC.FetchTypeFromScavengerInfo Card)))
						     (if (AND Type (NOT (NCP.ValidCardType
										Type)))
							 then (CONS (QUOTE UNKNOWNCARDTYPE)
									IndexLocsProblems)
						       else IndexLocsProblems))))
				     then (push Results (BQUOTE (, Card , (NC.FetchStatus
									   Card)
									 ,
									 (NC.EncodeCardProblems
									   Problems)
									 ,@ Problems))))))))
         (NC.PrintMsg InterestedWindow T "Done.")
     Results)))

(NC.ScavengerCleanup
  (LAMBDA (MessageWin InterestedWindow)                      (* rht: "16-Jul-86 18:19")

          (* * Abort the scavenger by closing the notefile without checkpointing.)



          (* * rht 12/8/85: Updated to handle new notefile and card object formats.)



          (* * rht 3/22/86: Took out NOTIFY.EVENT stuff since NC.ScavengerPhase1 is no longer hanging on completion of phase 
	  3.0)



          (* * rht 7/16/86: Added InterestedWindow arg.)


    (LET ((NoteFile (WINDOWPROP MessageWin (QUOTE NOTEFILE))))
         (if (OPENP (fetch (NoteFile Stream) of NoteFile))
	     then (NC.ForceDatabaseClose NoteFile)
		    (NC.PrintMsg InterestedWindow T "Repair of " (fetch (NoteFile FullFileName)
								      of NoteFile)
				   " aborted.")))))

(NC.InspectAndRepairNoteFile
  (LAMBDA (NoteFile ReadSubstancesFlg InterestedWindow)      (* rht: "16-Jul-86 18:27")

          (* * Check to be sure file is closed before calling real inspect and repair.)



          (* * rht 7/16/86: Added InterestedWindow arg. Removed call to NC.OpenDatabaseFile.)


    (LET (WasOpen)
         (if (AND NoteFile (SETQ WasOpen (OPENP (fetch (NoteFile FullFileName)
							   of NoteFile))))
	     then (NC.CloseDatabaseFile NoteFile InterestedWindow) 
                                                             (* to get everything written out))
         (NC.ScavengerPhase1 NoteFile ReadSubstancesFlg InterestedWindow)
         (if WasOpen
	     then (NC.OpenDatabaseFile NoteFile)))))
)
(* * Changes to NCINTERFACE)

(DEFINEQ

(NC.NoteFileOperations
  (LAMBDA (NoteFile)                                         (* rht: "16-Jul-86 18:37")
                                                             (* Ask usere to choose which database operation.
							     Called from main menu whenselected fn.)

          (* * fgh 11/14/85 Updated to handle NoteFile object and per NoteFile menus.)



          (* * kirk 14Jan86 Added Close/Delete cards and changed the format)



          (* * fgh 6/13/86 Now sets BusyOperation of NF menu to something interesting.)



          (* * kirk 3Jul86 passed NoteFileMenuWindow to NC.CompactNoteFile)



          (* * fgh 7/5/86 Fixed above fix and put NoteFileMenuWindow is all calls.)



          (* * rht 7/5/86: Added read-only open to notefileops menu.)



          (* * kirk 7/14/86 Took comma out of FullFileName in NC.DeleteDatabaseFile call)


    (LET ((NoteFileMenu (fetch (NoteFile Menu) of NoteFile))
	  (Font NC.MenuFont)
	  (FullFileName (fetch (NoteFile FullFileName) of NoteFile))
	  NoteFileMenuWindow Menu)
         (SPAWN.MOUSE)
         (SETQ NoteFileMenuWindow (WFROMMENU NoteFileMenu))
         (OR (SETQ Menu (WINDOWPROP NoteFileMenuWindow (QUOTE DatabaseOperationsMenu)))
	       (WINDOWPROP NoteFileMenuWindow (QUOTE DatabaseOperationsMenu)
			     (SETQ Menu
			       (create MENU
					 ITEMS ←(BQUOTE ((Open (NC.OpenDatabaseFile , NoteFile 
											NIL NIL NIL 
											NIL NIL NIL 
											NIL NIL NIL , 
									       NoteFileMenuWindow)
								 "Opens this NoteFile."
								 (SUBITEMS
								   (Read-only% Open
								     (NC.OpenDatabaseFile
								       , NoteFile (QUOTE INPUT)
								       NIL NIL NIL NIL NIL NIL NIL 
								       NIL , NoteFileMenuWindow)
								     
							     "Opens this NoteFile for read-only.")))
							   (Checkpoint (NC.CheckpointDatabase
									 , NoteFile NIL NIL NIL NIL , 
									 NoteFileMenuWindow)
								       
						"Checkpoint this NoteFile, saving changed cards.")
							   (Close (NC.CloseDatabaseFile , NoteFile 
											  , 
									       NoteFileMenuWindow)
								  "Closes this NoteFile.")
							   (Abort (NC.AbortSession , NoteFile , 
									       NoteFileMenuWindow)
								  
					     "Close NF, deleteing changes since last checkpoint.")
							   (Compact (NC.CompactNoteFile , NoteFile 
											  NIL NIL , 
									       NoteFileMenuWindow)
								    
							  "Compacts a NoteFile to a target file."
								    (SUBITEMS (
Compact% To% Target% File (NC.CompactNoteFile , NoteFile NIL NIL , NoteFileMenuWindow)
			  "Compacts this NoteFile to a target file.")
									      (Compact% In% Place
										(NC.CompactNoteFile
										  , NoteFile NIL T , 
									       NoteFileMenuWindow)
										
							       "Compacts this NoteFile in place.")))
							   (Inspect&Repair
							     (NC.InspectAndRepairNoteFile , 
											 NoteFile NIL 
											    , 
									       NoteFileMenuWindow)
							     
						 "Inspects and optionally repairs this NoteFile."
							     (SUBITEMS (Read% Substances
									 (
								      NC.InspectAndRepairNoteFile
									   , NoteFile T , 
									   NoteFileMenuWindow)
									 
"Inspects and optionally repairs a Notefile, but reads every substance.  This slows it WAY down.")))
							   (Copy (NC.CopyNoteFile , NoteFile NIL , 
									       NoteFileMenuWindow)
								 
							 "Copies this notefile to a target file.")
							   (Rename (NC.RenameNoteFile , NoteFile)
								   "Rename this NoteFile")
							   (Delete (NC.DeleteDatabaseFile , 
											 NoteFile , 
									       NoteFileMenuWindow)
								   "Deletes this NoteFile.")))
					 CHANGEOFFSETFLG ←(QUOTE Y)
					 MENUOFFSET ←(CONS -1 0)
					 CENTERFLG ← NIL
					 TITLE ← "NoteFile Ops"
					 MENUTITLEFONT ← Font
					 MENUFONT ← Font
					 ITEMHEIGHT ←(IPLUS (FONTPROP Font (QUOTE HEIGHT))
							      1)
					 WHENSELECTEDFN ←(FUNCTION (LAMBDA (Item Menu Button)
					     (WINDOWPROP (WFROMMENU (fetch (NoteFile Menu)
									   of (GETMENUPROP
										  Menu
										  (QUOTE NoteFile)))
									)
							   (QUOTE BusyOperation)
							   (CAR Item))
					     (DEFAULTWHENSELECTEDFN Item Menu Button)))))))
         (PUTMENUPROP Menu (QUOTE NoteFile)
			NoteFile)
         (MENU Menu))))

(NC.SetUpNoteFileInterface
  (LAMBDA (NoteFile Position)                                (* rht: "16-Jul-86 18:05")

          (* * Create the NoteCards control menu for a NoteFile)



          (* * kirk 13Jan85 Decreased the size of the NoteFile Menu)



          (* * fgh 1/22/86 Fixed the ghost box size when position menu.)



          (* * rht 5/6/86: Now restores the menu's WhenSelectedFn and ungrays its items if already existed.)



          (* * fgh 6/27/86 Added position argument)



          (* * rht 7/5/86: Now shades NewCards if readonly notefile.)



          (* * fgh 7/6/86 Will now set up menu correctly even if NF is closed.)



          (* * rht 7/13/86: Was ignoring the Position arg. No longer.)


    (LET ((Font (FONTCREATE (QUOTE HELVETICA)
			      10
			      (QUOTE BOLD)))
	  (TitleFont (FONTCREATE (QUOTE HELVETICA)
				   12
				   (QUOTE BOLD)))
	  NoteFileMenuWindow NoteFileMenu FullFileName)      (* Main Menu)
         (SETQ FullFileName (fetch (NoteFile FullFileName) of NoteFile))
         (if (SETQ NoteFileMenu (fetch (NoteFile Menu) of NoteFile))
	     then (replace (MENU WHENSELECTEDFN) of NoteFileMenu
		       with (if (NC.NoteFileOpenP NoteFile)
				  then (FUNCTION NC.NoteFileMenuWhenSelectedFn)
				else (FUNCTION NC.ClosedNoteFileMenuWhenSelectedFn)))
		    (replace (MENU TITLE) of NoteFileMenu with (CONCAT (if (
									     NC.ReadOnlyNoteFileP
											 NoteFile)
										     then "RO: "
										   else "")
										 (FILENAMEFIELD
										   FullFileName
										   (QUOTE NAME))
										 ";"
										 (FILENAMEFIELD
										   FullFileName
										   (QUOTE VERSION)))
			       )
		    (replace (MENU IMAGE) of NoteFileMenu with NIL) 
                                                             (* KLUDGE. Fetching the image height forces the menu 
							     package to recompute the menu image.)
		    (fetch (MENU IMAGEHEIGHT) of NoteFileMenu)
		    (AND (WFROMMENU NoteFileMenu)
			   (REDISPLAYW (WFROMMENU NoteFileMenu)))
	   else (SETQ NoteFileMenu (create MENU
						 ITEMS ←(QUOTE ((NewCards NIL 
		       "Create a new Text card (left button) or other card type (middle button).")
								   (Show% Box NIL 
							"Bring up one of the standard FileBoxes.")))
						 WHENSELECTEDFN ←(if (NC.NoteFileOpenP NoteFile)
								     then (FUNCTION 
								    NC.NoteFileMenuWhenSelectedFn)
								   else (FUNCTION 
							      NC.ClosedNoteFileMenuWhenSelectedFn))
						 CENTERFLG ← T
						 MENUBORDERSIZE ← 1
						 MENUOUTLINESIZE ← 2
						 MENUCOLUMNS ← 2
						 MENUFONT ← Font
						 TITLE ←(CONCAT (if (NC.ReadOnlyNoteFileP
									  NoteFile)
								      then "RO: "
								    else "")
								  (FILENAMEFIELD FullFileName
										   (QUOTE NAME))
								  ";"
								  (FILENAMEFIELD FullFileName
										   (QUOTE VERSION)))
						 ITEMHEIGHT ←(IPLUS 6 (FONTPROP Font
										    (QUOTE HEIGHT)))
						 ITEMWIDTH ←(IPLUS (STRINGWIDTH (QUOTE NewCards)
										    Font)
								     10)
						 MENUTITLEFONT ← TitleFont)))
         (for Item in (fetch (MENU ITEMS) of NoteFileMenu)
	    do (SHADEITEM Item NoteFileMenu (if (NC.NoteFileOpenP NoteFile)
						    then WHITESHADE
						  else GRAYSHADE)))
                                                             (* Shade NewCards if readonly notefile.)
         (if (NC.ReadOnlyNoteFileP NoteFile)
	     then (for Item in (fetch (MENU ITEMS) of NoteFileMenu)
		       when (EQ (CAR Item)
				    (QUOTE NewCards))
		       do (SHADEITEM Item NoteFileMenu GRAYSHADE)))
         (if (WINDOWP (SETQ NoteFileMenuWindow (WFROMMENU NoteFileMenu)))
	     then (FLASHWINDOW NoteFileMenuWindow)
	   else (SETQ NoteFileMenuWindow (ADDMENU NoteFileMenu NIL
							(OR Position (GETMENUPROP NoteFileMenu
										      (QUOTE 
										      OldPosition))
							      (GETBOXPOSITION (fetch
										  (REGION WIDTH)
										   of (MENUREGION
											  
										     NoteFileMenu))
										(fetch
										  (REGION HEIGHT)
										   of (MENUREGION
											  
										     NoteFileMenu)))))
		    ))
         (WINDOWPROP NoteFileMenuWindow (QUOTE NoteFile)
		       NoteFile)
         (replace (NoteFile Menu) of NoteFile with NoteFileMenu)
         (WINDOWPROP NoteFileMenuWindow (QUOTE RESHAPEFN)
		       (QUOTE DON'T))
         (WINDOWPROP NoteFileMenuWindow (QUOTE BUTTONEVENTFN)
		       (FUNCTION NC.NoteFileIconButtonEventFn))
         (WINDOWPROP NoteFileMenuWindow (QUOTE SHRINKFN)
		       (QUOTE DON'T))
         (WINDOWADDPROP NoteFileMenuWindow (QUOTE CLOSEFN)
			  (FUNCTION (LAMBDA (Window)
			      (PUTMENUPROP (CAR (WINDOWPROP Window (QUOTE MENU)))
					     (QUOTE OldPosition)
					     (WINDOWPOSITION Window)))))
         (NC.MoveWindowOntoScreen NoteFileMenuWindow))))

(NC.FileBrowserInspect&Repair
  (LAMBDA (Browser Key Item Menu ReadSubstancesFlg)          (* rht: "16-Jul-86 18:17")

          (* * Function called from file browser menu for notefile inspect&repair.)



          (* * rht 7/1/86: Now passes InterestedWindow arg to NC.ScavengerPhase1.)


    (for FileObject in (FB.SELECTEDFILES Browser) do (NC.ScavengerPhase1
							       (MKATOM (FB.FETCHFILENAME 
										       FileObject))
							       ReadSubstancesFlg NIL NIL
							       (fetch (FILEBROWSER PROMPTWINDOW)
								  of Browser)))))

(NC.DoNoteFileOp
  (LAMBDA (Op)                                               (* rht: "16-Jul-86 18:36")

          (* * Do a NoteFile op chosen from NC icon menu)



          (* * rht 7/2/86: Now calls NC.AbortSession with NC.NoteCardsIconWindow arg.)



          (* * rht 7/5/86: Added Read-only% Open entry.)


    (SELECTQ Op
	       (Open% NoteFile (LET ((NoteFile (NC.ListOfNoteFilesMenu T NIL NC.NoteCardsIconWindow
									 (QUOTE Open% NoteFile))))
				    (if (NULL NoteFile)
					then NIL
				      else (if (EQ NoteFile (QUOTE NEW))
						 then (SETQ NoteFile NIL))
					     (NC.OpenDatabaseFile NoteFile NIL NIL NIL NIL NIL NIL 
								    NIL NIL NIL 
								    NC.NoteCardsIconWindow))))
	       (Read-only% Open (LET ((NoteFile (NC.ListOfNoteFilesMenu T NIL 
									  NC.NoteCardsIconWindow
									  (QUOTE Open% NoteFile))))
				     (if (NULL NoteFile)
					 then NIL
				       else (if (EQ NoteFile (QUOTE NEW))
						  then (SETQ NoteFile NIL))
					      (NC.OpenDatabaseFile NoteFile (QUOTE INPUT)
								     NIL NIL NIL NIL NIL NIL NIL NIL 
								     NC.NoteCardsIconWindow))))
	       (Checkpoint% NoteFile (LET ((NoteFile (NC.ListOfNoteFilesMenu NIL T 
									   NC.NoteCardsIconWindow
									       (QUOTE 
									     Checkpoint% NoteFile))))
				          (if NoteFile
					      then (NC.CheckpointDatabase NoteFile NIL NIL NIL 
									      NIL 
									   NC.NoteCardsIconWindow))))
	       (Close% NoteFile (LET ((NoteFile (NC.ListOfNoteFilesMenu NIL T 
									  NC.NoteCardsIconWindow
									  (QUOTE Close% NoteFile))))
				     (if NoteFile
					 then (NC.CloseDatabaseFile NoteFile 
									NC.NoteCardsIconWindow))))
	       (Abort% NoteFile (LET ((NoteFile (NC.ListOfNoteFilesMenu NIL T 
									  NC.NoteCardsIconWindow
									  (QUOTE Abort% NoteFile))))
				     (if NoteFile
					 then (NC.AbortSession NoteFile NC.NoteCardsIconWindow))))
	       (Compact% NoteFile (LET ((NoteFile (NC.ListOfNoteFilesMenu T NIL 
									   NC.NoteCardsIconWindow
									    (QUOTE 
										Compact% NoteFile))))
				       (if (NULL NoteFile)
					   then NIL
					 else (if (EQ NoteFile (QUOTE NEW))
						    then (SETQ NoteFile NIL))
						(NC.CompactNoteFile NoteFile NIL NIL 
								      NC.NoteCardsIconWindow))))
	       (Compact% In% Place (LET ((NoteFile (NC.ListOfNoteFilesMenu T NIL 
									   NC.NoteCardsIconWindow
									     (QUOTE 
										Compact% NoteFile))))
				        (if (NULL NoteFile)
					    then NIL
					  else (if (EQ NoteFile (QUOTE NEW))
						     then (SETQ NoteFile NIL))
						 (NC.CompactNoteFile NoteFile NIL T 
								       NC.NoteCardsIconWindow))))
	       (Inspect&Repair% NoteFile (LET ((NoteFile (NC.ListOfNoteFilesMenu T NIL 
									   NC.NoteCardsIconWindow
										   (QUOTE 
									 Inspect&Repair% NoteFile))))
					      (if (NULL NoteFile)
						  then NIL
						else (if (EQ NoteFile (QUOTE NEW))
							   then (SETQ NoteFile NIL))
						       (NC.ScavengerPhase1 NoteFile NIL NIL NIL 
									   NC.NoteCardsIconWindow))))
	       (Read% Substances (LET ((NoteFile (NC.ListOfNoteFilesMenu T NIL 
									   NC.NoteCardsIconWindow
									   (QUOTE 
									 Inspect&Repair% NoteFile))))
				      (if (NULL NoteFile)
					  then NIL
					else (if (EQ NoteFile (QUOTE NEW))
						   then (SETQ NoteFile NIL))
					       (NC.ScavengerPhase1 NoteFile T NIL NIL 
								     NC.NoteCardsIconWindow))))
	       (Copy% NoteFile (LET ((NoteFile (NC.ListOfNoteFilesMenu T (QUOTE CLOSED)
									 NC.NoteCardsIconWindow
									 (QUOTE Copy% NoteFile))))
				    (if (NULL NoteFile)
					then NIL
				      else (if (EQ NoteFile (QUOTE NEW))
						 then (SETQ NoteFile NIL))
					     (NC.CopyNoteFile NoteFile NIL NC.NoteCardsIconWindow)))
			       )
	       (Rename% NoteFile (LET ((NoteFile (NC.ListOfNoteFilesMenu T (QUOTE CLOSED)
									   (QUOTE Rename% NoteFile))
						 ))
				      (if (NULL NoteFile)
					  then NIL
					else (if (EQ NoteFile (QUOTE NEW))
						   then (SETQ NoteFile NIL))
					       (NC.RenameNoteFile NoteFile NIL 
								    NC.NoteCardsIconWindow))))
	       (Delete% NoteFile (LET ((NoteFile (NC.ListOfNoteFilesMenu T (QUOTE CLOSED)
									   (QUOTE Delete% NoteFile))
						 ))
				      (if (NULL NoteFile)
					  then NIL
					else (if (EQ NoteFile (QUOTE NEW))
						   then (SETQ NoteFile NIL))
					       (NC.DeleteDatabaseFile NoteFile 
									NC.NoteCardsIconWindow))))
	       (Create% NoteFile (NC.CreateDatabaseFile NIL NIL NIL NIL NIL NIL 
							  NC.NoteCardsIconWindow))
	       NIL)))
)
(PUTPROPS RHTPATCH075 COPYRIGHT ("Xerox Corporation" 1986))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (1397 26024 (NC.OpenDatabaseFile 1407 . 13479) (NC.CheckForNeededConversion 13481 . 
16014) (NC.CreateDatabaseFile 16016 . 21914) (NC.CheckpointDatabase 21916 . 26022)) (26069 30972 (
NC.ConvertNoteFileVersion2To3 26079 . 30970)) (31005 64379 (NC.ScavengeDatabaseFile 31015 . 45847) (
NC.ScavengerPhase1 45849 . 60093) (NC.BuildBadCardsList 60095 . 62729) (NC.ScavengerCleanup 62731 . 
63581) (NC.InspectAndRepairNoteFile 63583 . 64377)) (64415 80096 (NC.NoteFileOperations 64425 . 68963)
 (NC.SetUpNoteFileInterface 68965 . 74371) (NC.FileBrowserInspect&Repair 74373 . 74977) (
NC.DoNoteFileOp 74979 . 80094)))))
STOP