(FILECREATED " 3-Jun-87 11:13:21" {QV}<NOTECARDS>1.3K>NEXT>PMIPATCH036.;30 167143 

      changes to:  (FNS NC.ProcessNoteFileNeedsTruncationError NC.CreateNoteFile 
			NC.ForceDatabaseClose NC.AskUserAboutTruncation NC.OpenNoteFile 
			NC.GetNoteFileMenu NC.SetNoteFileMenu)
		   (VARS PMIPATCH036COMS)

      previous date: "29-May-87 19:25:11" {QV}<NOTECARDS>1.3K>NEXT>PMIPATCH036.;27)


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

(PRETTYCOMPRINT PMIPATCH036COMS)

(RPAQQ PMIPATCH036COMS ((* * pmi 5/29/87: Changes to the interface to NoteFile operations and the 
			     menu of notefiles. Fixes bugs 370, 450, 454, 481, 482, and 592)
	(* * Move NC.ListOfNoteFilesMenu from NCINTERFACE to NCOBSOLETE)
	(* * Changed in NCCOMPACT)
	(FNS NC.CompactNoteFileToTarget NC.CompactNoteFileInPlace)
	(* * Changed in NCPROGINT)
	(FNS NCP.OpenNoteFile)
	(* * Changed in NCREPAIR)
	(FNS NC.ScavengeDatabaseFile NC.ScavengerPhase1)
	(* * Changed in NCCROSSFILELINKS)
	(FNS NC.OpenCrossFileLinkDestNoteFile)
	(* * Changed in NCLOCALDEVICE)
	(FNS NCLocalDevice.CompactNoteFile)
	(* * New for NCDATABASE)
	(FNS NC.RemoveNoteFileFromHashArray NC.RemoveNoteFileName NC.NoticeNoteFile 
	     NC.NoticeNoteFileName NC.NoticedNoteFileNamesMenu)
	(VARS (NC.NoticedNoteFileNames))
	(* * Changed in NCDATABASE)
	(FNS NC.CreateNoteFile NC.CreateDatabaseFile NC.ForceDatabaseClose NC.DeleteDatabaseFile 
	     NC.RenameNoteFile NC.CopyNoteFile NC.InspectAndRepairNoteFile NC.CompactNoteFile 
	     NC.OpenDatabaseFile NC.OpenNoteFile NC.ProcessTruncationRequest 
	     NC.ProcessInspectAndRepairRequest NC.ProcessNoteFileNeedsTruncationError 
	     NC.ProcessNoteFileNeedsConversionError NC.ProcessNoteFileNotFoundError 
	     NC.StoreNoteFileInHashArray NC.RemoveAccessToNoteFile NC.RemoveNoteFile 
	     NC.ListOfNoteFiles)
	(* * New for NCINTERFACE)
	(INITVARS (NC.FileNameFont (FONTCREATE (QUOTE HELVETICA)
					       10
					       (QUOTE BOLD)))
		  (NC.FullFileNameFont (FONTCREATE (QUOTE HELVETICA)
						   8
						   (QUOTE STANDARD)))
		  (NC.MaxFileNameChars 18))
	(FNS NC.CreateMenuBitmaps NC.GetNoteFileMenu NC.SetNoteFileMenu)
	(* * Changed in NCINTERFACE)
	(FNS NC.SetUpNoteFileInterface NC.NoteFileTitleLeftWhenSelectedFn NC.DoNoteFileOp 
	     NC.ListOfNoteFilesMenu NC.FileBrowserOpen)
	(* * In NCINTERFACE - Replace the content of the ADDVARs for NC.NoteFileOpsItems and 
	   NC.NoteFileIconOperationsMenuItems with the contents of these VARS - they should remain 
	   ADDVARs! (You may want to see me when you integrate this.))
	(VARS (NC.NoteFileIconCloseOperations (QUOTE (Open Compact Read-only% Open Inspect&Repair 
							   Read% Substances Copy Rename Delete 
							   Compact% To% New% File Compact% In% Place))
					      )
	      (NC.FileBrowserMenuItemsToAdd (QUOTE ((Open NC.FileBrowserOpen 
							  "Open selected Notefiles."
							  (SUBITEMS (Read-only% Open (
NC.FileBrowserOpen INPUT)
										     
							 "Open selected Notefiles for read-only.")))
						    (Checkpoint NC.FileBrowserCheckpoint 
					 "Checkpoint the selected Notefiles, saving dirty cards.")
						    (Close NC.FileBrowserClose 
							   "Close selected Notefiles.")
						    (Abort NC.FileBrowserAbort 
			       "Aborts the selected Notefiles losing work since last checkpoint.")
						    (Compact NC.FileBrowserCompact 
					      "Compacts selected Notefiles copying to new files."
							     (SUBITEMS (Compact% To% New% File 
									    NC.FileBrowserCompact 
					      "Compacts selected Notefiles copying to new files.")
								       (Compact% In% Place
									 (NC.FileBrowserCompact
									   (QUOTE InPlace))
									 
					   "Compacts selected Notefiles w/o copyig to new files.")))
						    (Inspect&Repair
						      NC.FileBrowserInspect&Repair 
					    "Inspects and optionally repairs selected Notefiles."
						      (SUBITEMS (Read% Substances
								  (NC.FileBrowserInspect&Repair
								    (QUOTE ReadSubstances))
								  
"Inspects and optionally repairs selected Notefiles, but reads every substance.  This slows things WAY down."
								  )))
						    (Copy FB.COPYCOMMAND 
					"Copies given notefile(s) to target file (or directory).")
						    (Rename FB.RENAMECOMMAND 
					 "Moves given notefile(s) to target file (or directory)."))))
	      (NC.NoteFileOpsItems (QUOTE ((% Open%  (NC.DoNoteFileOp (QUOTE Open% NoteFile))
						     "Opens a notefile."
						     (SUBITEMS (Read-only% Open (NC.DoNoteFileOp
										  (QUOTE 
										  Read-only% Open))
										
								 "Open a notefile for read-only.")))
					   (% Checkpoint%  (NC.DoNoteFileOp (QUOTE 
									     Checkpoint% NoteFile))
							   "Checkpoint a NoteFile"
							   (SUBITEMS (Checkpoint% All (
NC.CheckpointSession)
										      
							"Checkpoint all currently open NoteFiles")))
					   (% Close%  (NC.DoNoteFileOp (QUOTE Close% NoteFile))
						      "Close a notefile."
						      (SUBITEMS (Close% w/o% confirm
								  (NC.DoNoteFileOp (QUOTE 
									      Close% w/o% confirm))
								  
			"Close a notefile w/o asking for user confirm before closing open cards.")
								(Close% All (NC.CloseSession)
									    
							     "Close all currently open NoteFiles")
								(Close% All% w/o% confirm
								  (NC.CloseSession NIL T)
								  
		"Close all open notefiles w/o asking for user confirm before closing open cards.")))
					   (% Abort%  (NC.DoNoteFileOp (QUOTE Abort% NoteFile))
						      
					      "Close NF, deleting changes since last checkpoint."
						      (SUBITEMS (Abort% All (NC.CloseSession T)
									    
							     "Abort all currently open NoteFiles")))
					   (% Compact%  (NC.DoNoteFileOp (QUOTE Compact% NoteFile))
							"Compact a NoteFile."
							(SUBITEMS (Compact% To% New% File
								    (NC.DoNoteFileOp (QUOTE 
										Compact% NoteFile))
								    
						      "Compact a NoteFile copying to a new file.")
								  (Compact% In% Place
								    (NC.DoNoteFileOp (QUOTE 
									       Compact% In% Place))
								    
						  "Compact a NoteFile w/o copying to a new file.")))
					   (% Inspect&Repair%  (NC.DoNoteFileOp (QUOTE 
									 Inspect&Repair% NoteFile))
							       
							  "Do an Inspect & Repair on a NoteFile."
							       (SUBITEMS (Read% Substances
									   (NC.DoNoteFileOp
									     (QUOTE Read% Substances))
									   
"Inspects and optionally repairs a Notefile, but reads every substance.  This slows it WAY down.")))
					   (% Copy%  (NC.DoNoteFileOp (QUOTE Copy% NoteFile))
						     "Copy a NoteFile.")
					   (% Rename%  (NC.DoNoteFileOp (QUOTE Rename% NoteFile))
						       "Rename a NoteFile")
					   (% Delete%  (NC.DoNoteFileOp (QUOTE Delete% NoteFile))
						       "Delete a NoteFile")
					   (% Create%  (NC.DoNoteFileOp (QUOTE Create% NoteFile))
						       "Create a new NoteFile w/o opening it."
						       (SUBITEMS (% Create% and% Open% 
								   (NC.DoNoteFileOp (QUOTE 
										Create% and% Open))
								   
							     "Create a new NoteFile and open it.")
								 (% Create% and% Read-only% Open% 
								   (NC.DoNoteFileOp (QUOTE 
								     Create% and% Read-only% Open))
								   
					       "Create a new NoteFile and open it for read-only.")))
					   (% --------%  NIL "")
					   (% NC% FileBrowser%  (NC.FileBrowserMenu 
									   NC.NoteCardsIconWindow)
								"Bring up a NoteFile browser."))))
	      (NC.NoteFileIconOperationsMenuItems (QUOTE ((Open NIL "Opens this NoteFile."
								(SUBITEMS (Read-only% Open NIL 
							     "Opens this NoteFile for read-only.")))
							  (Checkpoint NIL 
						"Checkpoint this NoteFile, saving changed cards.")
							  (Close NIL "Closes this NoteFile."
								 (SUBITEMS (Close% w/o% confirm
									     NIL 
		     "Close this notefile w/o asking for user confirm before closing open cards.")))
							  (Abort NIL 
					      "Close NF, deleting changes since last checkpoint.")
							  (Compact NIL 
							  "Compacts this NoteFile to a new file."
								   (SUBITEMS (Compact% To% New% File
									       NIL 
						      "Compact a NoteFile copying to a new file.")
									     (Compact% In% Place
									       NIL 
						  "Compact a NoteFile w/o copying to a new file.")))
							  (Inspect&Repair NIL 
						 "Inspects and optionally repairs this NoteFile."
									  (SUBITEMS (Read% Substances
										      NIL 
"Inspects and optionally repairs a Notefile, but reads every substance.  This slows it WAY down.")))
							  (Copy NIL 
							 "Copies this notefile to a target file.")
							  (Rename NIL "Rename this NoteFile")
							  (Delete NIL "Deletes this NoteFile.")))))
	(* * This is only for the patch file - do not integrate)
	(VARS (NC.NoteFileOpsMenu))
	(P (NC.MakeNoteFileIconOperationsMenus))))
(* * pmi 5/29/87: Changes to the interface to NoteFile operations and the menu of notefiles. 
Fixes bugs 370, 450, 454, 481, 482, and 592)

(* * Move NC.ListOfNoteFilesMenu from NCINTERFACE to NCOBSOLETE)

(* * Changed in NCCOMPACT)

(DEFINEQ

(NC.CompactNoteFileToTarget
  (LAMBDA (FromNoteFile ToFileName InterestedWindow)         (* pmi: "27-May-87 15:51")

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



          (* * rht 11/3/86: Now opens FromNoteFile read-only. Also now takes InterestedWindow arg.)



          (* * rht 1/22/87: Slight change to computation of new index size.)



          (* * rht 3/17/87: Added RESETLST to make sure notefiles get closed in case of bombing out.)



          (* * rht 5/15/87: No longer calls NC.ComputeNewDatabaseIndexSize. Target notefile's index will be same size as 
	  source notefile's.)



          (* * pmi 5/27/87: Removed HashArray argument in calls to NC.OpenNoteFile. Added call to NC.NoticeNoteFile to notice
	  the original and target notefiles. Also stopped creation of a notefile interface for the target notefile before 
	  compaction -
	  it should be done at the end of compaction instead.)


    (LET (ToNoteFile OperationMsg)
         (if (SETQ FromNoteFile
		 (NC.OpenNoteFile FromNoteFile T T T NIL T T T InterestedWindow NIL NIL NIL T))
	     then (SETQ OperationMsg (CONCAT "Compacting " (fetch (NoteFile FullFileName)
								    of FromNoteFile)
						   (CHARACTER 13)))
		    (SETQ ToNoteFile (NC.OpenNoteFile (NC.CreateDatabaseFile
							    ToFileName
							    (fetch (NoteFile HashArraySize)
							       of FromNoteFile)
							    OperationMsg T NIL T InterestedWindow NIL 
							    NIL NIL NIL T)
							  T T T T T T T InterestedWindow))
		    (RESETLST (RESETSAVE NIL (BQUOTE (NC.ForceDatabaseClose , FromNoteFile)))
				(RESETSAVE NIL (BQUOTE (NC.ForceDatabaseClose , ToNoteFile)))
				(LET ((OriginalStream (fetch (NoteFile Stream) of FromNoteFile))
				      (TargetStream (fetch (NoteFile Stream) of ToNoteFile))
				      FromFileLength TargetFileLength BytesRecovered)
				     (replace (NoteFile NextIndexNum) of ToNoteFile
					with (fetch (NoteFile NextIndexNum) of FromNoteFile))
				     (SETFILEPTR TargetStream (NC.TotalIndexSize
						     (fetch (NoteFile HashArraySize) of 
										       ToNoteFile)))
                                                             (* truncate ToNoteFile after the index)
				     (if (NC.CopySortedCardParts (NC.SortIndexEntries 
										     FromNoteFile)
								     ToNoteFile NIL NIL NIL 
								     InterestedWindow OperationMsg)
					 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)
						(NCLocalDevice.PutHashArray FromNoteFile 
									      InterestedWindow T 
									      OperationMsg)
						(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 BytesRecovered (DIFFERENCE FromFileLength 
										 TargetFileLength))

          (* * Notice the original notefile and the new target notefile)


						(NC.NoticeNoteFile FromNoteFile)
						(NC.NoticeNoteFile ToNoteFile)
						(NC.PrintMsg NIL T (fetch (NoteFile FullFileName)
									of FromNoteFile)
							       " compacted to "
							       (fetch (NoteFile FullFileName)
								  of ToNoteFile)
							       (CHARACTER 13)
							       "Recovered " BytesRecovered " bytes ("
							       (FIX (TIMES 100 (FQUOTIENT
										 BytesRecovered 
										 FromFileLength)))
							       "%%)"
							       (CHARACTER 13))
						(NC.ClearMsg InterestedWindow T))
				 ToNoteFile))))))

(NC.CompactNoteFileInPlace
  (LAMBDA (NoteFile InterestedWindow)                        (* pmi: "20-May-87 18:20")

          (* * Compact the notefile in place. If index needs to be increased, then first make room for bigger index by 
	  copying. Compaction is done by sorting index pointers and moving each entry in the file to lower addresses.)



          (* * fkr 11/8/85 Updated to handle new CardID scheme and NoteFile object.)



          (* * kirk 19Nov85: Created from NC.CompactDatabaseInPlace)



          (* * rht 11/3/86: Added InterestedWindow arg.)



          (* * rht&pmi 12/9/86: Moved RESETLST to be after call to NC.OpenDatabaseFile.)



          (* * rht 1/22/87: Now bails out if NC.ExpandIndexInPlace was called but returned NIL. Also fixed message when size 
	  of notefile actually increases.)



          (* * rht 5/16/87: No longer calls NC.ExpandIndexInPlace.)



          (* * pmi 5/20/87: Removed HashArray argument in calls to NC.OpenNoteFile.)


    (if (AND NoteFile (SETQ NoteFile (NC.OpenNoteFile NoteFile T T NIL NIL T T T 
							      InterestedWindow)))
	then (RESETLST (RESETSAVE NIL (BQUOTE (NC.ForceDatabaseClose , NoteFile)))
			   (LET ((SourceStream (fetch (NoteFile Stream) of NoteFile))
				 (BufferStream (OPENSTREAM (QUOTE {NODIRCORE})
							     (QUOTE BOTH)
							     NIL
							     (QUOTE ((TYPE BINARY)))))
				 (FullFileName (fetch (NoteFile FullFileName) of NoteFile))
				 ToPtr OriginalLengthOfFile OperationMsg)

          (* * Expand index if needed.)


			        (SETQ OperationMsg (CONCAT "Compacting " FullFileName 
							       " in place."
							       (CHARACTER 13)))
			        (SETQ OriginalLengthOfFile (GETEOFPTR SourceStream))

          (* * In sorted order, copy entries to lower locations in the file. Expand index first if necessary.)


			        (if (SETQ ToPtr (NC.CopySortedCardParts
					  (NC.SortIndexEntries NoteFile)
					  NIL
					  (NC.TotalIndexSize (fetch (NoteFile HashArraySize)
								  of NoteFile))
					  BufferStream
					  (GETEOFPTR SourceStream)
					  InterestedWindow OperationMsg))
				    then                   (* all useable card parts got copied)
					   (NC.PutCheckptPtr NoteFile ToPtr) 
                                                             (* Put out the new ChkptPtr to the file.)

          (* * Truncate file at that point.)


					   (NC.PrintMsg InterestedWindow T "Truncating file " 
							  FullFileName " ...")
					   (NCLocalDevice.PutHashArray NoteFile InterestedWindow T 
									 OperationMsg)
					   (if (NOT (SETFILEINFO FullFileName (QUOTE LENGTH)
								       ToPtr))
					       then (NC.PrintMsg InterestedWindow NIL 
								     "Couldn't truncate "
								     FullFileName "." (CHARACTER
								       13))
					     else (NC.PrintMsg InterestedWindow T "Done."
								   (CHARACTER 13))
						    (NC.ClearMsg InterestedWindow T))
					   (LET ((NumBytesSaved (DIFFERENCE OriginalLengthOfFile 
									      ToPtr)))
					        (if (MINUSP NumBytesSaved)
						    then (NC.PrintMsg
							     NIL T FullFileName 
							     " compacted in place."
							     (CHARACTER 13)
							     "Increased by "
							     (MINUS NumBytesSaved)
							     " bytes ("
							     (FIX (TIMES 100 (FQUOTIENT
									       (MINUS NumBytesSaved)
									       OriginalLengthOfFile)))
							     "%%)"
							     (CHARACTER 13))
						  else (NC.PrintMsg NIL T FullFileName 
									" compacted in place."
									(CHARACTER 13)
									"Recovered " NumBytesSaved 
									" bytes ("
									(FIX (TIMES 100
											(FQUOTIENT
											  
										    NumBytesSaved 
									     OriginalLengthOfFile)))
									"%%)"
									(CHARACTER 13))))
					   (SETQ NC.DatabaseFileNameSuggestion (PACKFILENAME
					       (QUOTE VERSION)
					       NIL
					       (QUOTE BODY)
					       FullFileName))
				  else (FLASHW PROMPTWINDOW)
					 (NC.PrintMsg NIL T "Compact of " FullFileName 
							" cancelled.")))))))
)
(* * Changed in NCPROGINT)

(DEFINEQ

(NCP.OpenNoteFile
  (LAMBDA (NoteFileOrFileName Don'tCreateFlg Convertw/oConfirmFlg QuietFlg MenuPosition ReadOnlyFlg 
			      Don'tCreateInterfaceFlg)       (* pmi: "20-May-87 18:35")

          (* * Prog's intface version of opening a notefile.)



          (* * rht 7/7/86: Now takes QuietFlg and MenuPosition arg. Takes either NoteFile object or file name.)



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



          (* * rht 7/26/86: Added Don'tCreateInterfaceFlg)



          (* * Fix to bug #391: Now calls NC.OpenNoteFile instead of NC.OpenDatabaseFile.)



          (* * pmi 5/20/87: Removed HashArray argument in calls to NC.OpenNoteFile.)


    (if (type? NoteFile NoteFileOrFileName)
	then (NC.OpenNoteFile NoteFileOrFileName NIL NIL Don'tCreateFlg Convertw/oConfirmFlg NIL 
				  NIL Don'tCreateInterfaceFlg NIL NIL NIL MenuPosition QuietFlg
				  (AND ReadOnlyFlg (QUOTE INPUT))
				  NIL)
      else (LET ((FileNameWithExt (NC.DatabaseFileName "Name of NoteFile to open:" " -- " T NIL 
							   NoteFileOrFileName)))
	          (AND FileNameWithExt
			 (NC.OpenNoteFile FileNameWithExt NIL Don'tCreateFlg Convertw/oConfirmFlg 
					    NIL NIL Don'tCreateInterfaceFlg NIL NIL NIL MenuPosition 
					    QuietFlg (AND ReadOnlyFlg (QUOTE INPUT))
					    NIL))))))
)
(* * Changed in NCREPAIR)

(DEFINEQ

(NC.ScavengeDatabaseFile
  (LAMBDA (NoteFileOrFileName BadLinkLabelsFlg ListOfBoxesToReconstruct 
			      ListOfCardsNeedingGlobalLinksReconstructed InterestedWindow)
                                                             (* pmi: "20-May-87 18:35")

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



          (* * rht 7/16/86: Now calls NC.PutLinks passing UseOldDatesFlg.)



          (* * rht 9/5/86: Now checks that link is valid before passing it to NC.DelReferencesToCard.)



          (* * rht 10/29/86: Now closes prompt win at end if no filing info to tell.)



          (* * rht 12/10/86: No longer calls NC.GetLinks for cards appearing on the 
	  ListOfCardsNeedingGlobalLinksReconstructed list.)



          (* * rht 1/19/87: Now uses NC.CardNeedsFilingP to check for unfiled cards at the end.)



          (* * rht 1/22/87: Added yet another BLOCK call.)



          (* * rht 2/18/87: Added SPAWN.MOUSE call.)



          (* * rht 3/17/87: Changed call to OPENP to NC.OpenDatabaseFile to recover lost change from KIRKPATCH033.
	  Added RESETLST to close notefile in case we bomb out.)



          (* * rht 4/3/87: Call to NC.OpenNoteFile had extra NIL in it.)



          (* * pmi 5/20/87: Removed HashArray argument in calls to NC.OpenNoteFile.)


    (PROG (NoteFile FileName)
	    (SPAWN.MOUSE)

          (* * 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 (NC.NoteFileOpenP FileName))
		then (if (NULL (SETQ NoteFile
				       (NC.OpenNoteFile FileName T NIL NIL NIL NIL T T 
							  InterestedWindow)))
			   then (NC.PrintMsg InterestedWindow NIL "Couldn't open " FileName "."
						 (CHARACTER 13)
						 "Repair aborted.")
				  (RETURN NIL)))
	    (RESETLST
	      (RESETSAVE NIL (BQUOTE (NC.ForceDatabaseClose , NoteFile)))
	      (LET (CardTotal NoteCardNumber OldLinkLabels DiscoveredLinkLabels ReconstructLinks 
			      ReconstructGlobalLinks ToBeFiledCards)

          (* * 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 ".")
	           (SETQ NoteCardNumber 0)
	           (NC.MapCards
		     NoteFile
		     (FUNCTION (LAMBDA (Card)
			 (BLOCK)
			 (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 "."))
                                                             (* Get global links unless links are unreadable.)
			 (if (NOT (NC.FetchUserDataProp Card (QUOTE 
								 NeedsGlobalLinksReconstructedFlg)))
			     then (NC.GetLinks Card))
			 (if (NC.FetchUserDataProp Card (QUOTE NeedsReconstructingFlg))
			     then                          (* Card substance and links will be reconstructed so 
							     no need to try to read substance.)
				    (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.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 (AND (type? Link Link)
									    (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 ".")
	           (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 "."))
				    (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 ".")
	           (SETQ NoteCardNumber 0)
	           (NC.MapCards NoteFile (FUNCTION (LAMBDA (Card)
				    (BLOCK)
				    (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 "."))
				    (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 (NC.CardNeedsFilingP Card)
						   then (push ToBeFiledCards Card))
					       (NC.PutLinks Card T))
                                                             (* 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 ...")
			      (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.PrintMsg InterestedWindow T "Repair Completed for " (FULLNAME FileName)
				  ".")
	           (if ToBeFiledCards
		       then (NC.PrintMsg InterestedWindow NIL "Filed " (LENGTH ToBeFiledCards)
					     " cards in ToBeFiled box.")
		     else (NC.ClearMsg InterestedWindow T)))))))

(NC.ScavengerPhase1
  (LAMBDA (FileNameOrNoteFile ReadSubstancesFlg ScavengerInteractionWin RecheckBadCardsFlg 
			      InterestedWindow)              (* pmi: "20-May-87 18:33")

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



          (* * rht 9/16/86: Changed call to NC.OpenDatabaseFile so that it won't try to get special cards.)



          (* * rht 10/31/86: Changed call from NC.OpenDatabaseFile to NC.OpenNoteFile. Now returns non-nil if successful.)



          (* * rht 11/13/86: Now passes non-nil Don'tCreateFlg to NC.OpenNoteFile.)



          (* * rht 2/18/87: Added SPAWN.MOUSE call.)



          (* * rht 3/14/87: Now calls new function NC.TotalCardsInNoteFile to compute the total number of cards.)



          (* * pmi 5/20/87: Removed HashArray argument in calls to NC.OpenNoteFile.)


    (DECLARE (GLOBALVARS NC.ScavengerAttachedMenuFont NC.ScavengerInteractionWinRegion))
    (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.)


	    (SPAWN.MOUSE)
	    (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.OpenNoteFile FileName T T NIL NIL NIL T T 
							 InterestedWindow NIL NIL NIL NIL T)))
			    (NC.PrintMsg InterestedWindow NIL "Couldn't open " FileName "."
					   (CHARACTER 13)
					   "Repair aborted.")
			    (RETURN NIL))
		     (NC.ClearMsg InterestedWindow T))
	    (SETQ CardTotal (NC.TotalCardsInNoteFile 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))                    (* Stash InterestedWindow for calls to phase 3 under 
							     menu whenselected fn.)
	    (OR (WINDOWPROP ScavengerInteractionWin (QUOTE INTERESTEDWINDOW))
		  (WINDOWPROP ScavengerInteractionWin (QUOTE INTERESTEDWINDOW)
				InterestedWindow))           (* 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))
	    (RETURN NoteFile))))
)
(* * Changed in NCCROSSFILELINKS)

(DEFINEQ

(NC.OpenCrossFileLinkDestNoteFile
  (LAMBDA (DestNoteFile DestFileName InterestedWindow)       (* pmi: "20-May-87 18:26")

          (* * If DestNoteFile is an open notefile, then fine. Otherwise get file names from user and keep trying to open 
	  until she gives up.)



          (* * pmi 5/20/87: Removed HashArray argument in calls to NC.OpenNoteFile.)


    (LET ((Menu (create MENU
			  ITEMS ←(QUOTE (Open% Read/Write Open% Read-Only Cancel))
			  MENUFONT ←(FONTCREATE (QUOTE HELVETICA)
						  12
						  (QUOTE BOLD))
			  MENUROWS ← 1
			  MENUBORDERSIZE ← 1
			  ITEMHEIGHT ← 20
			  MENUTITLEFONT ←(FONTCREATE (QUOTE HELVETICA)
						       12
						       (QUOTE BOLD))))
	  ReadOnlyOpenFlg)
         (if (NCP.OpenNoteFileP DestNoteFile)
	     then DestNoteFile
	   else (for while (OR DestFileName (SETQ DestFileName
					 (NC.AskUser "File name to try opening: " NIL NIL T 
						       InterestedWindow)))
		     do (replace (MENU TITLE) of Menu with (CONCAT "OPEN " DestFileName 
									       "?"))
			  (if (AND (SELECTQ (MENU Menu)
						  (Open% Read/Write (SETQ ReadOnlyOpenFlg NIL)
								    T)
						  (Open% Read-Only (SETQ ReadOnlyOpenFlg T))
						  (Cancel (RETURN NIL))
						  (RETURN NIL))
				       (NCP.OpenNoteFileP (SETQ DestNoteFile
							      (NC.OpenNoteFile (OR DestNoteFile 
										     DestFileName)
										 NIL NIL NIL NIL NIL 
										 NIL NIL 
										 InterestedWindow NIL 
										 NIL NIL 
										 ReadOnlyOpenFlg))))
			      then (RETURN DestNoteFile)
			    else (NC.PrintMsg InterestedWindow T "Couldn't open " DestFileName 
						  "."
						  (CHARACTER 13))
				   (SETQ DestFileName (SETQ DestNoteFile NIL))
				   (if (NOT (NC.AskYesOrNo 
						     "Want to try opening a different notefile? "
								 NIL "Yes" NIL InterestedWindow))
				       then (RETURN NIL))))))))
)
(* * Changed in NCLOCALDEVICE)

(DEFINEQ

(NCLocalDevice.CompactNoteFile
  (LAMBDA (FromNoteFile ToFileName InPlaceFlg PromptWindow)
                                                             (* pmi: "27-May-87 13:54")

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



          (* * rht 7/2/86: Fixed bug in call to NC.CompactToTarget and NC.CompactInPlace. They were being called with 
	  FromNoteFile instead of (OR FromNoteFile FromFileName).)



          (* * kirk 3Jul86 Added SETQ NC.DatabaseFileNameSuggestion)



          (* * rht 10/16/86: Now autoloads NCREPAIR.)



          (* * rht 11/3/86: No longer reopens if was originally open. Also now passes PromptWindow along to called 
	  functions.)



          (* * pmi 5/27/87: Now returns the target notefile.)


    (DECLARE (GLOBALVARS NC.DatabaseFileNameSuggestion))
    (LET (FromFileName ToNoteFile)

          (* * Get the name of the file to be compacted)


         (SETQ FromFileName (COND
	     ((NULL FromNoteFile)
	       (PROG1 (NC.DatabaseFileName "Name of NoteFile to be compacted:" " -- " 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 NC.DatabaseFileNameSuggestion (PACKFILENAME (QUOTE VERSION)
									  NIL
									  (QUOTE BODY)
									  (FULLNAME FromFileName)))
		    (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))
				 (OPENP FromFileName))
			then (NC.CloseDatabaseFile FromNoteFile))

          (* * Compact the file and reopen if successfull and was previously open)


		    (NC.PrintMsg PromptWindow T "Compacting " FromFileName " ...")
		    (if (SETQ ToNoteFile (if InPlaceFlg
						 then (NC.AutoloadApply* (FUNCTION 
									NC.CompactNoteFileInPlace)
									   (OR FromNoteFile 
										 FromFileName)
									   PromptWindow)
					       else        (* compact to target)
						      (NC.AutoloadApply* (FUNCTION 
								       NC.CompactNoteFileToTarget)
									 (OR FromNoteFile 
									       FromFileName)
									 ToFileName PromptWindow)))
			then (NC.ClearMsg PromptWindow T)))
     ToNoteFile)))
)
(* * New for NCDATABASE)

(DEFINEQ

(NC.RemoveNoteFileFromHashArray
  (LAMBDA (NoteFile)                                         (* pmi: "21-May-87 11:16")

          (* * Remove this notefile from the global hash array.)



          (* * pmi 5/21/87: Service function called by NC.RemoveNoteFile.)


    (DECLARE (GLOBALVARS NC.NoteFilesHashArray))
    (LET ((NoteFileUID (fetch (NoteFile UID) of NoteFile)))
         (if (AND NoteFile NoteFileUID)
	     then (PUTHASH NoteFileUID NIL NC.NoteFilesHashArray)))))

(NC.RemoveNoteFileName
  (LAMBDA (NoteFileOrFileName)                               (* pmi: "19-May-87 11:32")

          (* * pmi 5/19/87: Created to keep track of noticed NoteFiles)


    (DECLARE (GLOBALVARS NC.NoticedNoteFileNames))
    (LET (FullFileName)
         (if (type? NoteFile NoteFileOrFileName)
	     then (SETQ FullFileName (fetch (NoteFile FullFileName) of NoteFileOrFileName))
	   else (SETQ FullFileName (OR (FULLNAME NoteFileOrFileName)
					     NoteFileOrFileName)))

          (* * If the filename is a valid or invalid file, remove it from the list of noticed files. If the resulting list is
	  empty, set it to NIL (DREMOVE can't set a list to NIL))


         (if (DREMOVE FullFileName NC.NoticedNoteFileNames)
	   else (SETQ NC.NoticedNoteFileNames NIL)))))

(NC.NoticeNoteFile
  (LAMBDA (NoteFileOrFileName)                               (* pmi: "27-May-87 16:11")

          (* * store NoteFile in HashArray, a NoteFiles hash array.)



          (* * fgh 5/23/86 First created.)



          (* * pmi 5/27/87: Broke into two functions: one to add the filename to list of noticed files, and one to put the 
	  notefile in the notefile hash array.)


    (NC.NoticeNoteFileName NoteFileOrFileName)
    (NC.StoreNoteFileInHashArray NoteFileOrFileName)))

(NC.NoticeNoteFileName
  (LAMBDA (NoteFileOrFileName)                               (* pmi: "21-May-87 20:57")

          (* * pmi 5/14/87: Created to keep track of noticed NoteFiles)



          (* * pmi 5/21/87: Now creates a menu item bitmap for this notefile.)


    (DECLARE (GLOBALVARS NC.NoticedNoteFileNames))
    (LET ((FullFileName (if (type? NoteFile NoteFileOrFileName)
			    then (fetch (NoteFile FullFileName) of NoteFileOrFileName)
			  else (FULLNAME NoteFileOrFileName))))

          (* * If the filename is a valid file, add it to the list of noticed files. If the filename is not a valid file, 
	  remove it from the list of noticed files. If the resulting list is empty, set it to NIL (DREMOVE can't set a list 
	  to NIL))


         (if FullFileName
	     then (if NC.NoticedNoteFileNames
			then (MERGEINSERT FullFileName NC.NoticedNoteFileNames T)
		      else (SETQ NC.NoticedNoteFileNames (MERGEINSERT FullFileName 
									  NC.NoticedNoteFileNames T)))

          (* * Constuct a menu item bitmap for this notefile, if it does not already have one.)


		    (if (GETPROP FullFileName (QUOTE MenuBitmap))
		      else (NC.CreateMenuBitmaps FullFileName))
	   else (if (DREMOVE NoteFileOrFileName NC.NoticedNoteFileNames)
		    else (SETQ NC.NoticedNoteFileNames NIL))))))

(NC.NoticedNoteFileNamesMenu
  (LAMBDA (IncludeNewNoteFileFlg ShowOnlyOpenNFsFlg InterestedWindow Operation)
                                                             (* pmi: "21-May-87 21:16")

          (* * Bring up a menu of all notefiles found in the notefiles hash array. Also allow user to open a new notefile.)



          (* * kirk 23Jan86 Added AskYesOrNo and InterestedWindow parameter)



          (* * fgh 6/8/86 Added check to make sure NoteFile is open if it has a menu on the screen. Needed to handle case of 
	  liongering NF menus.)



          (* * fgh 6/24/86 Changed to be a general function rather than one specific for opening. Now just returns the chosen
	  name. Also, added IncludeNewNoteFileFlg and ShowOnlyOpenNFsFlg. Removed InterestedWindow arg.)



          (* * fgh 6/27/86 Added InterestedWindow & Operation args and call to NC.DatabaseFileName.)



          (* * pmi 12/4/86: Added version numbers to rootnames on list of known files. Also cleaned up help string for menu 
	  items. It was giving a bogus message about opening the selected file, even though this function is used for many 
	  operations and not just for Open.)



          (* * pmi 2/18/87: Added GLOBALVARS declaration for NC.MenuFont)



          (* * pmi 5/15/87: Used to be NC.ListOfNoteFilesMenu. Changed symbol for open notefile to o.
	  Now uses NC.NoticedNoteFileNames instead of hash array to build menu. Returns a NoteFile name instead of a NoteFile
	  object.)



          (* * pmi 5/21/87: Replaced each NoteFile menu item with a bitmap of its name in a large font and its full filename 
	  in a small font.)


    (DECLARE (GLOBALVARS NC.FileNameFont NC.NoticedNoteFileNames))
    (LET (Menu Items Result)
         (SETQ Items (BQUOTE (,@(for NoteFileName in NC.NoticedNoteFileNames
				       bind NoteFile Stream RootName
				       when (PROGN (SETQ NoteFile (NC.NoteFileFromFileName
							   NoteFileName))
						       (OR (AND (EQ ShowOnlyOpenNFsFlg
									  (QUOTE CLOSED))
								    (NULL (NC.NoteFileOpenP
									      NoteFile)))
							     (NULL ShowOnlyOpenNFsFlg)
							     (NC.NoteFileOpenP NoteFile)))
				       collect (LIST (if (NC.NoteFileOpenP NoteFile)
							     then 
                                                             (* (if (WINDOWP (WFROMMENU 
							     (fetch (NoteFile Menu) of NoteFile))) then "* " else 
							     "$ "))
								    (GETPROP NoteFileName
									       (QUOTE 
										   OpenMenuBitmap))
							   else (GETPROP NoteFileName
									     (QUOTE MenuBitmap)))
							 (BQUOTE (QUOTE , NoteFileName))
							 (CONCAT "Selects NoteFile " NoteFileName)))
				   ,@(if IncludeNewNoteFileFlg
					 then (LIST (QUOTE ("-- Other NoteFile --"
								   (QUOTE NEW)
								   
				  "Select some other notefile - you'll be prompted for the name.")))
				       else NIL))))
         (SETQ Result (if (NULL Items)
			    then (if ShowOnlyOpenNFsFlg
				       then (NC.PrintMsg InterestedWindow NIL 
							     "No open NoteFiles."
							     (CHARACTER 13))
				     else (NC.PrintMsg InterestedWindow NIL "No NoteFiles."
							   (CHARACTER 13)))
				   NIL
			  elseif (AND (EQ (LENGTH Items)
						1)
					  (EQUAL (CADAR Items)
						   (QUOTE (QUOTE NEW))))
			    then (QUOTE NEW)
			  else (MENU (create MENU
						   ITEMS ← Items
						   TITLE ←(OR Operation "NoteFiles")
						   MENUFONT ← NC.FileNameFont
						   ITEMHEIGHT ←(IPLUS (BITMAPHEIGHT (CAAR
											  Items))
									1)))))
         (if (EQ Result (QUOTE NEW))
	     then (SETQ Result (NC.DatabaseFileName (CONCAT "Name of NoteFile to "
								    (SUBSTRING Operation 1 -9)
								    (CHARACTER 13))
							  " -- " T T NIL InterestedWindow)))
     Result)))
)

(RPAQQ NC.NoticedNoteFileNames NIL)
(* * Changed in NCDATABASE)

(DEFINEQ

(NC.CreateNoteFile
  (LAMBDA (NoteFileOrFileName SizeInCards Don'tCreateSpecialCards InterestedWindow OperationMsg 
			      QuietFlg PublicOrPrivate OpenFlg ReadOnlyFlg Don'tCreateInterfaceFlg 
			      MenuPosition)                  (* pmi: "20-May-87 13:38")

          (* * Create a NoteFile. Most of the work should be done by the device specific create notefile fn.)



          (* * fgh 9/1/86 First created.)



          (* * fgh&rht 9/5/86: Now creates small temporary hash array.)



          (* * pmi 5/20/87: Added call to NC.SetUpNoteFileInterface to create a closed NoteFile Icon after creating the 
	  NoteFile. Now asks if next version should be created if file already exists.)


    (DECLARE (GLOBALVARS NC.MsgDelay))
    (PROG (NoteFile NoteFileName NoteFileFullName ReturnValue)

          (* * Get the name from the user if necessary.)


	    (SETQ NoteFileName (if (type? NoteFile NoteFileOrFileName)
				     then (fetch (NoteFile FullFileName) of NoteFileOrFileName)
				   else (OR NoteFileOrFileName
						(NC.DatabaseFileName 
						    "What is the name of the file to be created?"
								       " -- " T T NIL 
								       InterestedWindow))))
	    (if (NULL NoteFileName)
		then (RETURN (QUOTE CreateCancelled)))

          (* * Check to see if a file by this name already exists.)


	    (if (SETQ NoteFileFullName (FULLNAME NoteFileName (QUOTE OLD)))
		then 

          (* * Notify user)


		       (NC.PrintMsg InterestedWindow T "NoteFile " NoteFileFullName 
				      " already exists."
				      (CHARACTER 13))

          (* * If the user wants to create the file, then create the next version of it.)


		       (SETQ NoteFileFullName (FULLNAME (PACKFILENAME (QUOTE VERSION)
									    NIL
									    (QUOTE BODY)
									    NoteFileFullName)
							    (QUOTE NEW)))
		       (if (NC.AskYesOrNo (CONCAT "Do you want to create " NoteFileFullName 
							" (next available version)?")
					      " -- " "N" NIL InterestedWindow T NIL)
			 else (NC.PrintMsg InterestedWindow NIL "Create cancelled." (CHARACTER
						 13))
				(DISMISS NC.MsgDelay)
				(NC.ClearMsg InterestedWindow T)
				(RETURN (QUOTE CreateCancelled)))
	      else (SETQ NoteFileFullName (FULLNAME NoteFileName (QUOTE NEW))))

          (* * Create a NoteFile object with a UID, etc.)


	    (SETQ NoteFile (if (type? NoteFile NoteFileOrFileName)
				 then NoteFileOrFileName
			       else (OR (NC.NoteFileFromFileName NoteFileFullName)
					    (create NoteFile))))
	    (replace (NoteFile UID) of NoteFile with (NC.MakeUID))
	    (replace (NoteFile MonitorLock) of NoteFile with (CREATE.MONITORLOCK
								     (QUOTE Creating% NoteFile)))
	    (replace (NoteFile FullFileName) of NoteFile with NoteFileFullName)
	    (replace (NoteFile ReadOnlyFlg) of NoteFile with NIL)

          (* * only a small hash array for creating a file.)


	    (replace (NoteFile HashArray) of NoteFile
	       with (NC.CreateUIDHashArray (CONSTANT (LENGTH (RECORDFIELDNAMES
								       (QUOTE NoteFileCriticalUIDs))
								     ))))

          (* * Install the appropriate device vector)


	    (NC.InstallDeviceVectorInNoteFile NoteFile PublicOrPrivate)

          (* * Say something to the user.)


	    (OR QuietFlg (NC.PrintMsg InterestedWindow T (OR OperationMsg "")
					  "Creating NoteFile " NoteFileFullName ".  Please wait...  ")
		  )

          (* * Call the device specific create notefile fn.)


	    (if (type? NoteFile (SETQ ReturnValue (CAR (ERSETQ (APPLY*
									   (fetch (NoteFile 
										 CreateNoteFileFn)
									      of NoteFile)
									   NoteFile SizeInCards 
									   InterestedWindow 
									   OperationMsg QuietFlg)))))
		then 

          (* * Device specific Create NoteFile fn returned okay. Go an an create the special cards.)


		       (if Don'tCreateSpecialCards
			 else (replace (NoteFile NextIndexNum) of NoteFile with 1)
				(NC.InitializeSpecialCards NoteFile))

          (* * Checkpoint the NF, then close it and return the NF objet.)


		       (NC.CheckpointNoteFile NoteFile QuietFlg T InterestedWindow OperationMsg)
		       (if (type? NoteFile (SETQ ReturnValue
					(CAR (ERSETQ (APPLY* (fetch (NoteFile CloseNoteFileFn)
								      of NoteFile)
								   NoteFile SizeInCards 
								   InterestedWindow OperationMsg 
								   QuietFlg)))))
			   then                            (* Close went okay.)
				  (if (NULL QuietFlg)
				      then (NC.PrintMsg InterestedWindow NIL "Done!"
							    (CHARACTER 13))
					     (NC.ClearMsg InterestedWindow T))
                                                             (* Clean out the NF object and "notice it".)
				  (create NoteFile smashing NoteFile UID ←(fetch (NoteFile
											 UID)
										 of NoteFile)
								FullFileName ←(fetch (NoteFile
											 FullFileName)
										 of NoteFile)
								Menu ←(fetch (NoteFile Menu)
									 of NoteFile)
								NoteFileDevice ←(fetch
								  (NoteFile NoteFileDevice)
										   of NoteFile))

          (* * If needed, create a closed NoteFile interface.)


				  (if (AND (NULL Don'tCreateInterfaceFlg)
					       (NULL OpenFlg))
				      then (NC.SetUpNoteFileInterface NoteFile MenuPosition 
									  InterestedWindow))

          (* * Notice the notefile)


				  (NC.NoticeNoteFile NoteFile) 

          (* * Open the notefile, if requested)


				  (if OpenFlg
				      then (NC.OpenNoteFile NoteFile NIL T NIL NIL NIL 
								Don'tCreateInterfaceFlg NIL 
								InterestedWindow PublicOrPrivate 
								MenuPosition QuietFlg ReadOnlyFlg NIL)
					)                    (* Set the DatabaseFileNameSuggestion)
				  (SETQ NC.DatabaseFileNameSuggestion (PACKFILENAME
				      (QUOTE VERSION)
				      NIL
				      (QUOTE BODY)
				      (fetch (NoteFile FullFileName) of NoteFile)))
                                                             (* Return the NoteFile.)
				  (RETURN NoteFile)
			 else                              (* Problems with closing the NoteFile -- error)
				(NC.ReportError "NC.CreateNoteFile" (CONCAT 
					"Could not close notefile after it was created because: "
										ReturnValue))
				(RETURN ReturnValue))
	      else 

          (* * There was an error in the device specific create notefile fn.)


		     (NC.ReportError "NC.CreateNoteFile" (CONCAT 
							      "Could not create NoteFile due to "
								     ReturnValue " error."))
		     (RETURN ReturnValue)))))

(NC.CreateDatabaseFile
  (LAMBDA (FileName HashArraySize CallingOperationMsg OmitFinalNoteFlg StartingNextFreeIndex 
		    NoSpecialCardsFlg InterestedWindow QuietFlg PublicOrPrivate OpenFlg ReadOnlyFlg 
		    Don'tCreateInterfaceFlg MenuPosition)    (* pmi: "15-May-87 19:03")

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



          (* * fgh 9/1/86 Now just a wrapper for NC.CreateNoteFile to maintain compatibility with callers.
	  Result of device vector implementation.)



          (* * pmi 5/15/87: Added PublicOrPrivate, OpenFlg, ReadOnlyFlg, Don'tCreateInterfaceFlg, and MenuPosition arguments 
	  to correspond to changes in NC.CreateNoteFile.)


    (NC.CreateNoteFile FileName HashArraySize NoSpecialCardsFlg InterestedWindow 
			 CallingOperationMsg QuietFlg PublicOrPrivate OpenFlg ReadOnlyFlg 
			 Don'tCreateInterfaceFlg MenuPosition)))

(NC.ForceDatabaseClose
  (LAMBDA (NoteFile Don'tMenuFlg)                            (* pmi: "19-May-87 10:46")

          (* * Really close the database, i.e.. bypass the ADVISE on CLOSEF that prevents closing of the database.)



          (* * rht 1/10/85: Note new kludgey call to \UPDATEOF recommended by Tayloe to avoid truncation problems.)



          (* * rht 2/5/85: Added resetting of NC.UncachingNotCompleted here so it will happen after compact, repair, etc.)



          (* * rht 7/9/85: Added resetting of NC.LinkLabelsDate.)



          (* * rht 11/10/85: Updated to incorporate new NoteFile scheme.)



          (* * kirk 31Dec85: added Don'tMenuFlg)



          (* * rht 1/8/86: Now smashes old notefile object to remove cycles. Don't you love interlisp gc'er?)



          (* * rht 5/1/86: Save Menu on notefile object when smashing.)



          (* * rht 7/6/86: Only closes notefile's stream if there is an open one.)



          (* * fgh 9/1/86 Now saves the Device vector when cleaning up the NoteFile object.)



          (* * pmi 5/19/87: Replaced call to NC.RemoveNoteFileFromHashArray with NC.RemoveNoteFile as part of general 
	  cleanup.)


    (CLOSEF? (fetch (NoteFile Stream) of NoteFile))    (* Smash the cardcache and userdata fields of all card
							     objects for this notefile to remove circular links.)
    (ADD.PROCESS (LIST (FUNCTION NC.CleanupCardObjects)
			   (fetch (NoteFile HashArray) of NoteFile)))
    (replace (NoteFile Stream) of NoteFile with NIL)   (* Smash the notefile object so we don't have cycles -
							     card -> notefile -> card.)
    (create NoteFile smashing NoteFile UID ←(fetch (NoteFile UID) of NoteFile)
				  FullFileName ←(fetch (NoteFile FullFileName) of NoteFile)
				  Menu ←(fetch (NoteFile Menu) of NoteFile)
				  NoteFileDevice ←(fetch (NoteFile NoteFileDevice) of NoteFile))
                                                             (* Usually we leave shell in notefiles hash array so 
							     there's a record.)
    (if Don'tMenuFlg
	then (NC.RemoveNoteFile NoteFile))
    NoteFile))

(NC.DeleteDatabaseFile
  (LAMBDA (FileNameOrNoteFile InterestedWindow Don'tConfirmFlg QuietFlg)
                                                             (* pmi: "29-May-87 18:24")
                                                             (* Delete file FileName)

          (* * rht 8/7/84: If delete happens, clear NC.DatabaseFileNameSuggestion.)



          (* * rht 3/17/85: Fixed for case when user specifies version number of file to delete.)



          (* * fkr 11/8/85: Ripped out PSA.Database check. Added check for file open.)



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



          (* * fgh 6/24/86 Added ability to pass down NoteFile object as well as file name. Added code to remove NF from NFs 
	  hash array and remove the menu on the screen.)



          (* * rht 7/2/86: No longer prints completed message with DISMISS. Now returns non-nil if successful.
	  Accepts Don'tConfirmFlg arg.)



          (* * fgh 7/5/86 Added call to RemoveAccessToNoteFile.)



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



          (* * kef 8/8/86: Factored out into device specific vectors.)



          (* * pmi 12/3/86 Added check for open file)



          (* * pmi 12/19/86 Changed to call NC.NoteFileOpenP instead of OPENP to check whether the file is open.
	  Added NC.DeviceVectorsHashArray. to GLOBALVARS)



          (* * pmi 5/29/87: Fixed search for full filename to work for non-DSK files. Added error message if delete fails.
	  Added test for existence of file to be deleted.)


    (DECLARE (GLOBALVARS NC.MsgDelay NC.DeviceVectorsHashArray))
    (PROG ((FileName (if (type? NoteFile FileNameOrNoteFile)
			   then (fetch (NoteFile FullFileName) of FileNameOrNoteFile)
			 else FileNameOrNoteFile))
	     (MsgWindow (OR InterestedWindow (NC.CoerceToInterestedWindow FileNameOrNoteFile)))
	     FullFileName)                                   (* Make sure no open databases)
                                                             (* Get file name)
	    (AND (NULL FileName)
		   (NULL (SETQ FileName (NC.DatabaseFileName "Name of Notefile to be deleted:" 
								   " -- "
								   T NIL NIL MsgWindow)))
		   (RETURN NIL))                           (* make sure to-be-deleted file exists and that we get
							     the earliest version, if version is not specified.)
	    (SETQ FullFileName (if (FILENAMEFIELD FileName (QUOTE VERSION))
				     then (FULLNAME FileName)
				   else (CAR (FILDIR-EARLIEST FileName))))

          (* * Can't delete a non-existent file.)


	    (if (NULL FullFileName)
		then (NC.RemoveAccessToNoteFile FileName)
		       (SETQ MsgWindow (NC.CoerceToInterestedWindow MsgWindow))
		       (NC.PrintMsg (NC.AttachPromptWindow MsgWindow)
				      T FileName " does not exist." (CHARACTER 13)
				      "Delete cancelled."
				      (CHARACTER 13))
		       (DISMISS NC.MsgDelay)
		       (NC.ClearMsg MsgWindow T)
		       (RETURN))

          (* * Don't try to delete if the NoteFile is open)


	    (if (NC.NoteFileOpenP FullFileName)
		then (NC.PrintMsg MsgWindow T "Can't delete an open notefile." (CHARACTER
					13))
		       (DISMISS NC.MsgDelay)
		       (NC.ClearMsg MsgWindow T)
		       (RETURN NIL))

          (* * Ask user to confirm twice.)


	    (OR Don'tConfirmFlg (if (NOT (NC.AskYesOrNo (CONCAT 
							       "Are you sure you want to delete "
									  (CHARACTER 13)
									  FullFileName "?"
									  (CHARACTER 13))
								" -- " "No" T (NC.AttachPromptWindow
								  MsgWindow)
								(NOT MsgWindow)))
				      then (if QuietFlg
					       else (NC.PrintMsg (NC.AttachPromptWindow 
											MsgWindow)
								     T FullFileName " not deleted."
								     (CHARACTER 13))
						      (DISMISS NC.MsgDelay)
						      (NC.ClearMsg MsgWindow T))
					     (RETURN)))
	    (OR QuietFlg (NC.PrintMsg (NC.AttachPromptWindow MsgWindow)
					  T "Deleting" FullFileName (CHARACTER 13)))
	    (DISMISS 1000)
	    (OR Don'tConfirmFlg (if (NOT (NC.AskYesOrNo (CONCAT 
							 "Are you still sure you want to delete "
									  (CHARACTER 13)
									  FullFileName "?"
									  (CHARACTER 13))
								" -- " "No" T (NC.AttachPromptWindow
								  MsgWindow)
								(NOT MsgWindow)))
				      then (OR QuietFlg (NC.PrintMsg (NC.AttachPromptWindow
									     MsgWindow)
									   T FullFileName 
									   " not deleted."
									   (CHARACTER 13)))
					     (RETURN)))

          (* * Delete the file)


	    (SETQ FullFileName (APPLY* (fetch (NoteFileDevice DeleteNoteFileFn)
					      of (GETHASH (COND
								((NC.RemoteHostP FullFileName)
								  (QUOTE REMOTEMULTIUSER))
								(T (QUOTE LOCALSINGLEUSER)))
							      NC.DeviceVectorsHashArray))
					   FullFileName))
	    (if (NULL FullFileName)
		then (NC.PrintMsg (NC.AttachPromptWindow MsgWindow)
				      T FileName " could not be deleted." (CHARACTER 13)
				      "Delete cancelled."
				      (CHARACTER 13))
		       (DISMISS NC.MsgDelay)
		       (NC.ClearMsg MsgWindow T)
		       (RETURN))
	    (NC.RemoveAccessToNoteFile FullFileName)
	    (SETQ NC.DatabaseFileNameSuggestion NIL)
	    (NC.ClearMsg MsgWindow T)
	    (RETURN FullFileName))))

(NC.RenameNoteFile
  (LAMBDA (FromNoteFileOrName ToFileName InterestedWindow)   (* pmi: "29-May-87 18:46")

          (* * Rename a notefile. Ask user for names of FromNoteFileOrName and ToFileName.)



          (* * fgh 7/5/86 First created on basis of CopyNoteFile.)



          (* * rht 11/1/86: Added missing var binding.)



          (* * pmi 12/19/86 Changed to call NC.NoteFileOpenP instead of OPENP to check whether the file is open.
	  Made consistent with other NoteFile operations in the way it checks for valid NoteFile, gets msg window, etc.)



          (* * pmi 5/29/87: Added calls to notice the new file name and to forget the old file name. Cleaned up case where 
	  notefilename is valid, but a notefile object does not exist.)


    (DECLARE (GLOBALVARS NC.MsgDelay NC.DatabaseFileNameSuggestion))
    (PROG ((MsgWindow InterestedWindow)
	     Result NoteFile FromFileName FullFromFileName)

          (* * Get the name of the file to be compacted)


	    (if (type? NoteFile FromNoteFileOrName)
		then (SETQ NoteFile FromNoteFileOrName)
		       (SETQ FromFileName (fetch (NoteFile FullFileName) of NoteFile))
	      elseif (SETQ FromFileName (OR FromNoteFileOrName
						  (NC.DatabaseFileName 
								"Name of NoteFile to be renamed:"
									 " -- " T NIL NIL MsgWindow)))
	      else (RETURN NIL))

          (* * Check for existence of file to be renamed.)


	    (if (SETQ FullFromFileName (FULLNAME FromFileName))
		then (if (OR NoteFile (SETQ NoteFile (NC.NoteFileFromFileName 
										 FullFromFileName)))
			   then (SETQ MsgWindow (OR MsgWindow (NC.CoerceToInterestedWindow
							    NoteFile))))
	      else (NC.RemoveAccessToNoteFile FromFileName)
		     (SETQ MsgWindow (NC.CoerceToInterestedWindow MsgWindow))
		     (NC.PrintMsg MsgWindow T FromFileName " does not exist." (CHARACTER 13)
				    "Rename cancelled."
				    (CHARACTER 13))
		     (DISMISS NC.MsgDelay)
		     (NC.ClearMsg MsgWindow T)
		     (RETURN NIL))

          (* * Check to see if the notefile is open, abort if it is.)


	    (if (NC.NoteFileOpenP NoteFile)
		then (NC.PrintMsg MsgWindow T "Can't rename an open notefile." (CHARACTER
					13)
				      "Rename cancelled."
				      (CHARACTER 13))
		       (DISMISS NC.MsgDelay)
		       (NC.ClearMsg MsgWindow T)
		       (RETURN NIL))
	    (OR ToFileName (SETQ ToFileName (NC.DatabaseFileName "New name for the NoteFile:" 
								       " -- "
								       T NIL NIL MsgWindow))
		  (RETURN))
	    (if (AND FullFromFileName ToFileName)
		then (NC.PrintMsg MsgWindow T "Renaming " FullFromFileName " to " ToFileName 
				      " ...")
		       (if (SETQ Result (RENAMEFILE FullFromFileName ToFileName))
			   then (NC.PrintMsg MsgWindow T FullFromFileName " renamed to " Result 
						 "."
						 (CHARACTER 13))

          (* * Fix up the NoteFile with the new name.)


				  (AND NoteFile (replace (NoteFile FullFileName) of NoteFile
						     with Result)
					 (AND (fetch (NoteFile Menu) of NoteFile)
						(WFROMMENU (fetch (NoteFile Menu) of NoteFile))
						(NC.SetUpNoteFileInterface NoteFile)))

          (* * Forget the old file name)


				  (NC.RemoveNoteFileName FullFromFileName) 

          (* * Register the new file name as noticed.)


				  (NC.NoticeNoteFileName Result)
				  (SETQ NC.DatabaseFileNameSuggestion (PACKFILENAME (QUOTE
											  VERSION)
											NIL
											(QUOTE
											  BODY)
											Result))
				  (DISMISS NC.MsgDelay)
				  (NC.ClearMsg MsgWindow T))
	      elseif (NULL FullFromFileName)
		then (NC.PrintMsg MsgWindow T "Can't open file for rename: " FromNoteFileOrName
				      (CHARACTER 13)
				      "Rename cancelled."
				      (CHARACTER 13))
		       (DISMISS NC.MsgDelay)
		       (NC.ClearMsg MsgWindow T)))))

(NC.CopyNoteFile
  (LAMBDA (FromNoteFileOrName ToFileName InterestedWindow)   (* pmi: "29-May-87 19:01")

          (* * Copy a notefile. Ask user for names of FromNoteFileOrName and ToFileName.)



          (* * fkr 11/8/85: Ripped out PSA.Database check. Now takes FromNoteFileOrName and ToFileName args.)



          (* * kirk 19May86 Fixed to work from NoteFile menu)



          (* * fgh 6/24/86 Fixed bug where would not work if NULL FromNoteFileOrName)



          (* * fgh 7/5/86 Closes prompt window when done.)



          (* * rht 11/1/86: Added missing var binding.)



          (* * pmi 12/19/86 Changed to call NC.NoteFileOpenP instead of OPENP to check whether the file is open.)



          (* * pmi 5/29/87: Added call to NC.NoticeNoteFile to make sure From NoteFile is noticed. Added call to 
	  NC.NoticeNoteFileName for the To file name. Cleaned up case where notefilename is valid, but a notefile object does
	  not exist.)


    (DECLARE (GLOBALVARS NC.MsgDelay NC.DatabaseFileNameSuggestion))
    (PROG ((MsgWindow InterestedWindow)
	     Result FromFileName FullFromFileName FromNoteFile)

          (* * Get the name of the file to be copied.)


	    (if (type? NoteFile FromNoteFileOrName)
		then (SETQ FromNoteFile FromNoteFileOrName)
		       (SETQ FromFileName (fetch (NoteFile FullFileName) of FromNoteFile))
	      elseif (SETQ FromFileName (OR FromNoteFileOrName
						  (NC.DatabaseFileName 
								 "Name of NoteFile to be copied:"
									 " -- " T NIL NIL MsgWindow)))
	      else (RETURN NIL))

          (* * Check for existence of file to be copied.)


	    (if (SETQ FullFromFileName (FULLNAME FromFileName))
		then (if (OR FromNoteFile (SETQ FromNoteFile (NC.NoteFileFromFileName
				       FullFromFileName)))
			   then (SETQ MsgWindow (OR MsgWindow (NC.CoerceToInterestedWindow
							    FromNoteFile))))
	      else (NC.RemoveAccessToNoteFile FromFileName)
		     (SETQ MsgWindow (NC.CoerceToInterestedWindow MsgWindow))
		     (NC.PrintMsg MsgWindow T FromFileName " does not exist." (CHARACTER 13)
				    "Copy cancelled."
				    (CHARACTER 13))
		     (DISMISS NC.MsgDelay)
		     (NC.ClearMsg MsgWindow T)
		     (RETURN NIL))

          (* * Check to see if the notefile is open, abort if it is.)


	    (if (NC.NoteFileOpenP FromNoteFile)
		then (NC.PrintMsg MsgWindow T "Can't copy an open notefile." (CHARACTER 13)
				      "Copy cancelled."
				      (CHARACTER 13))
		       (DISMISS NC.MsgDelay)
		       (NC.ClearMsg MsgWindow T)
		       (RETURN NIL))

          (* * Add the From notefile to the Hash Array and the list of noticed notefiles, in case it isn't already there.)


	    (NC.NoticeNoteFile FullFromFileName)
	    (OR ToFileName (SETQ ToFileName (NC.DatabaseFileName "Name of target of copy:" 
								       " -- "
								       T NIL NIL MsgWindow))
		  (RETURN))
	    (if (AND FullFromFileName ToFileName)
		then (NC.PrintMsg MsgWindow T "Copying " FullFromFileName " to " ToFileName 
				      " ...")
		       (COND
			 ((SETQ Result (COPYFILE FullFromFileName ToFileName))
			   (NC.PrintMsg MsgWindow T FullFromFileName " copied to " Result "."
					  (CHARACTER 13))

          (* * Notice the To NoteFile name)


			   (NC.NoticeNoteFileName Result)
			   (SETQ NC.DatabaseFileNameSuggestion (PACKFILENAME (QUOTE VERSION)
										 NIL
										 (QUOTE BODY)
										 Result))
			   (DISMISS NC.MsgDelay)
			   (NC.ClearMsg MsgWindow T)))
	      elseif (NULL FullFromFileName)
		then (NC.PrintMsg MsgWindow T "Can't open file for copy: " FromNoteFileOrName
				      (CHARACTER 13)
				      "Copy cancelled."
				      (CHARACTER 13))
		       (DISMISS NC.MsgDelay)
		       (NC.ClearMsg MsgWindow T)))))

(NC.InspectAndRepairNoteFile
  (LAMBDA (NoteFileOrFileName ReadSubstancesFlg InterestedWindow)
                                                             (* pmi: "29-May-87 18:53")

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



          (* * rht 7/17/86: Now works with file name args as well as notefile args. Took out reopen'ing of notefile, because 
	  you don't know how it was originally opened.)



          (* * fgh 9/1/86 Now just a wrapper for the device specific inspect & repair fn. Old functionality is in 
	  NCLocalDevice.InspectAndRepairNoteFile.)



          (* * pmi 12/19/86 Added test for open notefile so we can abort if it is open. Made consistent with other NoteFile 
	  operations in the way it checks for valid NoteFile, gets msg window, etc.)



          (* * pmi 5/29/87: Added call to NC.NoticeNoteFile to make sure this NoteFile is noticed. Cleaned up case where 
	  notefilename is valid, but a notefile object does not exist.)


    (DECLARE (GLOBALVARS NC.MsgDelay))
    (PROG ((MsgWindow InterestedWindow)
	     NoteFile FileName FullFileName)

          (* * Get the name of the file to be inspected.)


	    (if (type? NoteFile NoteFileOrFileName)
		then (SETQ NoteFile NoteFileOrFileName)
		       (SETQ FileName (fetch (NoteFile FullFileName) of NoteFile))
	      elseif (SETQ FileName (OR NoteFileOrFileName
					      (NC.DatabaseFileName 
						 "Name of NoteFile to be inspected and repaired:"
								     " -- " T NIL NIL MsgWindow)))
	      else (RETURN NIL))

          (* * Check for existence of file to be inspect and repaired.)


	    (if (SETQ FullFileName (FULLNAME FileName))
		then (if (OR NoteFile (SETQ NoteFile (NC.NoteFileFromFileName FullFileName))
				   )
			   then (SETQ MsgWindow (OR MsgWindow (NC.CoerceToInterestedWindow
							    NoteFile))))
	      else (NC.RemoveAccessToNoteFile FileName)
		     (SETQ MsgWindow (NC.CoerceToInterestedWindow MsgWindow))
		     (NC.PrintMsg MsgWindow T FileName " does not exist." (CHARACTER 13)
				    "Inspect & Repair cancelled."
				    (CHARACTER 13))
		     (DISMISS NC.MsgDelay)
		     (NC.ClearMsg MsgWindow T)
		     (RETURN NIL))

          (* * Check to see if the notefile is open, abort if it is.)


	    (if (NC.NoteFileOpenP FullFileName)
		then (NC.PrintMsg MsgWindow T "Can't inspect and repair an open notefile."
				      (CHARACTER 13)
				      "Inspect & Repair cancelled."
				      (CHARACTER 13))
		       (DISMISS NC.MsgDelay)
		       (NC.ClearMsg MsgWindow T)
		       (RETURN NIL))

          (* * Add the From notefile to the Hash Array and the list of noticed notefiles, in case it isn't already there.)


	    (NC.NoticeNoteFile FullFileName)

          (* * Apply the device specific repair notefile fn for the file's host.)


	    (RETURN (APPLY* (fetch (NoteFileDevice RepairNoteFileFn)
				   of (NC.DeviceVectorForHost (FILENAMEFIELD FullFileName
										   (QUOTE HOST))
								  (QUOTE PRIVATE)))
				NoteFile ReadSubstancesFlg MsgWindow)))))

(NC.CompactNoteFile
  (LAMBDA (FromNoteFileOrName ToFileName InPlaceFlg InterestedWindow)
                                                             (* pmi: "29-May-87 18:52")

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



          (* * rht 7/2/86: Fixed bug in call to NC.CompactToTarget and NC.CompactInPlace. They were being called with 
	  FromNoteFile instead of (OR FromNoteFile FromFileName).)



          (* * kirk 3Jul86 Added SETQ NC.DatabaseFileNameSuggestion)



          (* * fgh 9/1/86 Now just a wrapper that calls the device specific compact fn. Old CompactNoteFile is now 
	  NCLocalDevice.CompactNoteFile.)



          (* * pmi 12/19/86 Added test for open notefile so we can abort if it is open. Made consistent with other NoteFile 
	  operations in the way it checks for valid NoteFile, gets msg window, etc.)



          (* * pmi 5/29/87: Added call to NC.NoticeNoteFile to make sure this NoteFile is noticed. Cleaned up case where 
	  notefilename is valid, but a notefile object does not exist. Now creates an interface menu for the target of 
	  compaction if NC.NoteFileMenuLingerFlg is T. This menu for the new notefile is positioned slightly offset from the 
	  original notefile's menu.)


    (DECLARE (GLOBALVARS NC.MsgDelay NC.NoteFileMenuLingerFlg NC.NoteCardsIconWindow))
    (PROG ((MsgWindow InterestedWindow)
	     FromNoteFile FromFileName FullFromFileName ReturnValue Menu MenuWindowRegion NewMenu)

          (* * Get the name of the file to be compacted)


	    (if (type? NoteFile FromNoteFileOrName)
		then (SETQ FromNoteFile FromNoteFileOrName)
		       (SETQ FromFileName (fetch (NoteFile FullFileName) of FromNoteFile))
	      elseif (SETQ FromFileName (OR FromNoteFileOrName
						  (NC.DatabaseFileName 
							      "Name of NoteFile to be compacted:"
									 " -- " T NIL NIL MsgWindow)))
	      else (RETURN NIL))

          (* * Check for existence of file to be compacted.)


	    (if (SETQ FullFromFileName (FULLNAME FromFileName))
		then (if (OR FromNoteFile (SETQ FromNoteFile (NC.NoteFileFromFileName
				       FullFromFileName)))
			   then (SETQ MsgWindow (OR MsgWindow (NC.CoerceToInterestedWindow
							    FromNoteFile))))
	      else (NC.RemoveAccessToNoteFile FromFileName)
		     (SETQ MsgWindow (NC.CoerceToInterestedWindow MsgWindow))
		     (NC.PrintMsg MsgWindow T FromFileName " does not exist." (CHARACTER 13)
				    "Compact cancelled."
				    (CHARACTER 13))
		     (DISMISS NC.MsgDelay)
		     (NC.ClearMsg MsgWindow T)
		     (RETURN NIL))

          (* * Check to see if the notefile is open, abort if it is.)


	    (if (NC.NoteFileOpenP FromNoteFile)
		then (NC.PrintMsg MsgWindow T "Can't compact an open notefile." (CHARACTER
					13)
				      "Compact cancelled."
				      (CHARACTER 13))
		       (DISMISS NC.MsgDelay)
		       (NC.ClearMsg MsgWindow T)
		       (RETURN NIL))

          (* * Add the From notefile to the Hash Array and the list of noticed notefiles, in case it isn't already there.)


	    (NC.NoticeNoteFile FullFromFileName)

          (* * Apply the device specific comnpact notefile fn for the file's host.)


	    (if (SETQ ReturnValue (APPLY* (fetch (NoteFileDevice CompactNoteFileFn)
						   of (NC.DeviceVectorForHost
							  (FILENAMEFIELD FullFromFileName
									   (QUOTE HOST))
							  (QUOTE PRIVATE)))
						FullFromFileName ToFileName InPlaceFlg MsgWindow))
		then (if (AND (NULL InPlaceFlg)
				    NC.NoteFileMenuLingerFlg)
			   then (if (SETQ Menu (OR (AND (type? NoteFile FromNoteFile)
								  (fetch (NoteFile Menu)
								     of FromNoteFile))
							   (GETPROP FullFromFileName (QUOTE
									Menu))))
				      then (SETQ MenuWindowRegion (WINDOWPROP (WFROMMENU
										      Menu)
										    (QUOTE REGION)))
					     (SETQ NewMenu (NC.SetUpNoteFileInterface
						 ReturnValue
						 (create POSITION
							   XCOORD ←(fetch (REGION LEFT)
								      of MenuWindowRegion)
							   YCOORD ←(fetch (REGION BOTTOM)
								      of MenuWindowRegion))
						 MsgWindow))
					     (RELMOVEW
					       NewMenu
					       (create POSITION
							 XCOORD ← 6
							 YCOORD ←(MINUS
							   (PLUS (FONTHEIGHT (fetch
										   (MENU 
										    MENUTITLEFONT)
										    of Menu))
								   6))))))
	      else (NC.PrintMsg MsgWindow T "Compact cancelled." (CHARACTER 13))
		     (DISMISS NC.MsgDelay)
		     (NC.ClearMsg MsgWindow T))
	    (RETURN ReturnValue))))

(NC.OpenDatabaseFile
  (LAMBDA (NoteFileOrFileName Access Don'tCacheTypesAndTitlesFlg QuietFlg Don'tCreateFlg 
			      Convertw/oConfirmFlg Don'tCreateArrayFlg Don'tTruncateFlg 
			      Don'tCreateInterfaceFlg Don'tGetSpecialCardsFlg InterestedWindow)
                                                             (* pmi: "14-May-87 15:33")

          (* * Removed Hash Array argument to NC.OpenNoteFile %.)


    (NC.OpenNoteFile NoteFileOrFileName Don'tCacheTypesAndTitlesFlg Don'tCreateFlg 
		       Convertw/oConfirmFlg Don'tCreateArrayFlg Don'tTruncateFlg 
		       Don'tCreateInterfaceFlg Don'tGetSpecialCardsFlg InterestedWindow NIL NIL 
		       QuietFlg (if (EQ Access (QUOTE INPUT))
				    then T
				  else NIL))))

(NC.OpenNoteFile
  (LAMBDA (NoteFileOrFileName Don'tCacheTypesAndTitlesFlg Don'tCreateFlg ConvertNoConfirmFlg 
			      Don'tCreateArrayFlg Can'tTruncateFlg Don'tCreateInterfaceFlg 
			      Don'tGetSpecialCardsFlg InterestedWindow PublicOrPrivate MenuPosition 
			      QuietFlg ReadOnlyFlg Don'tCheckForTruncationFlg)
                                                             (* pmi: "29-May-87 19:01")

          (* * fgh 5/23/86 Renamed to NC.OpenNoteFile from NC.OpenDatabaseFile. Total revamp to implement device vector.)



          (* * kef 7/18/86: Inserted a call to stuff the UID into the NoteFile because BuildHashArray needed it.)



          (* * kef 7/21/86: Moved up the install of the NoteFile into the NoteFileHashArray to before the building of the 
	  NoteFile's hash array. The reason is that the remote multi client build hash array function needs to get a list of 
	  UIDs, and in order to do this, it needs to grab a Courier stream for the NoteFile given only the UID.
	  It can only do this if the UID is registered in the NoteFilesHashArray.)



          (* * fgh 8/31/86 Updated to account for changes made to system since 5/23/86 revamp. Changes reimplemented include:
	  (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) (kirk 15Jul86 Added call to 
	  NC.SetUpNoteFileInterface if already open))



          (* * fgh 9/1/86 Reimplemented ReadOnly NoteFile open.)



          (* * fgh 9/4/86 Put in default for NoteFilesHashArray which is NC.NoteFilesHashArray)



          (* * kirk/rht 8/29/86: Now resets Name after conversion from version 2 to version3.)



          (* * rht 10/29/86: Changed "aborted" to "canceled" in message.)



          (* * rht 10/31/86: Added Don'tCheckForTruncationFlg arg.)



          (* * rht&pmi 11/21/86: Took away the protection from around the AFTER call to open events fns.)



          (* * pmi 12/12/86: Added InterestedWindow argument to NC.SetUpNoteFileInterface so that it can print a prompt to 
	  the user about placing the NoteFile menu.)



          (* * rg 3/4/87 Added NC.ProtectedSessionOperation wrapper, removed Don'tCheckOperationsInProgressFlg)



          (* * rht 3/25/87: Now calls NC.CoerceToInterestedWindow.)



          (* * pmi 3/31/87: Moved line of code which sets the ReadOnlyFlg to just after the test for an open notefile.
	  Otherwise, a notefile opened read-only could be changed to one opened normally.)



          (* * rht 4/2/87: Now passes InterestedWindow to opennotefilefns.)



          (* * rg 4/2/87 enlarged scope of NC.ProtectedNoteFileOperation)



          (* * RG 4/3/87 replaced missing InterestedWindow arg to OpenNoteFileFn)



          (* * pmi 5/19/87: Removed NoteFilesHashArray argument. Replaced call to NC.StoreNoteFileInHashArray with 
	  NC.NoticeNoteFile in general cleanup.)



          (* * pmi 5/20/87: Moved the open test up to almost the beginning of the function.)



          (* * pmi 5/29/87: Deleted extra InterestedWindow argument to NC.ProtectedNoteFileOperation.
	  Added call to NC.RemoveAccessToNoteFile to "unnotice" this notefile if the file does not exist, and remove its 
	  icon, if it has one. If InterestedWindow is the window for this NoteFile's interface, then change it to 
	  NC.NoteCardsIconWindow.)


    (DECLARE (GLOBALVARS NC.OpenNoteFileFns NC.LastNoteFileOpened))

          (* * NOTE: Session lock turns into NoteFile lock after NoteFile is created)


    (PROG (NoteFile FileName NewerFileName OldVersion NewVersion NoteFileMenu ReturnValue 
		      CriticalUIDs)

          (* * Figure out the name of the file containing the NoteFile)


	    (if (NULL (SETQ FileName (if (type? NoteFile NoteFileOrFileName)
					       then (fetch (NoteFile FullFileName) of 
									       NoteFileOrFileName)
					     elseif NoteFileOrFileName
					     else (NC.DatabaseFileName 
								      "Name of NoteFile to open:"
									   " -- " T NIL NIL 
									   InterestedWindow))))
		then (RETURN))

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


	    (if (NC.NoteFileOpenP FileName)
		then (OR Don'tCreateInterfaceFlg (NC.SetUpNoteFileInterface (
									  NC.NoteFileFromFileName
										    FileName)
										  MenuPosition 
										 InterestedWindow))
		       (NC.ClearMsg InterestedWindow T)    (* bring up or create notefile icon if needed)
		       (RETURN NIL))

          (* * Check for higher version of same notefile)


	    (if (AND (SETQ OldVersion (FILENAMEFIELD FileName (QUOTE VERSION)))
			 (SETQ NewVersion (FILENAMEFIELD (SETQ NewerFileName
							       (FULLNAME (PACKFILENAME
									     (QUOTE VERSION)
									     NIL
									     (QUOTE BODY)
									     FileName)))
							     (QUOTE VERSION)))
			 (LESSP OldVersion NewVersion))
		then 

          (* * Notify user)


		       (NC.PrintMsg InterestedWindow T "A higher version of " FileName " exists."
				      (CHARACTER 13))

          (* * Open the version the user requests.)


		       (if (NC.AskYesOrNo (CONCAT "Open " NewerFileName " instead?")
					      " -- " "N" NIL InterestedWindow T NIL)
			   then (SETQ FileName NewerFileName)
				  (SETQ NoteFileOrFileName (NC.NoteFileFromFileName FileName))
				  (if (SETQ NoteFileMenu (GETPROP FileName (QUOTE Menu)))
				      then (replace (NoteFile Menu) of NoteFileOrFileName
						with NoteFileMenu))))

          (* * Create a NoteFile object or use existing notefile object if there is one for this file name.)


	    (SETQ NoteFile (if (type? NoteFile NoteFileOrFileName)
				 then NoteFileOrFileName
			       else (OR (NC.NoteFileFromFileName FileName)
					    (create NoteFile))))
	    (replace (NoteFile FullFileName) of NoteFile with FileName)
	    (RETURN
	      (NC.ProtectedNoteFileOperation
		NoteFile "Open NoteFile" (OR (OPENWP InterestedWindow)
					       (SETQ InterestedWindow (NC.CoerceToInterestedWindow
						   NoteFile)))
		(PROG NIL

          (* * Figure out the appropriate device vector from the file name.)


		        (NC.InstallDeviceVectorInNoteFile NoteFile PublicOrPrivate)

          (* * Moved this replace to after test for open notefile. Otherwise, if notefile is open read-only, it well be 
	  changed to regular open.)


		        (replace (NoteFile ReadOnlyFlg) of NoteFile with ReadOnlyFlg)

          (* * Notify user.)


		        (OR QuietFlg (NC.PrintMsg InterestedWindow T "Opening NoteFile: " 
						      FileName " ..." (CHARACTER 13)))
		        (SETQ ReturnValue
			  (PROG 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 FileName NoteFile
									   (QUOTE BEFORE)
									   InterestedWindow))))
				      then (if (WINDOWP InterestedWindow)
						 then (NC.PrintMsg InterestedWindow NIL 
								    "Open canceled for NoteFile "
								       FileName "." (CHARACTER
									 13))
							(DISMISS NC.MsgDelay)
							(NC.ClearMsg InterestedWindow T))
					     (RETURN))

          (* * Call the device specific OpenNoteFileFn, which returns a list of special UIDs)


			          (if (NULL (ERSETQ (SETQ ReturnValue
							    (APPLY* (fetch (NoteFile 
										   OpenNoteFileFn)
									 of NoteFile)
								      NoteFile InterestedWindow 
								      Don'tCheckForTruncationFlg))))
				      then (SETQ ReturnValue (QUOTE NoteFileOpenFailed)))

          (* * Process error returns from the OpenNoteFileFn)


			          (if (NOT (LITATOM ReturnValue))
				      then 

          (* * OpenNoteFileFn returned correctly)


					     (SETQ CriticalUIDs ReturnValue)
				    else

          (* * Error, process it.)


				     (SETQ ReturnValue
				       (OR (SELECTQ
					       ReturnValue
					       (NoteFileNotFound (NC.RemoveAccessToNoteFile 
											 NoteFile)
								 (SETQ InterestedWindow
								   (NC.CoerceToInterestedWindow
								     InterestedWindow))
								 (NC.ProcessNoteFileNotFoundError
								   NoteFile 
								   Don'tCacheTypesAndTitlesFlg 
								   Don'tCreateFlg ConvertNoConfirmFlg 
								   Don'tCreateArrayFlg 
								   Can'tTruncateFlg 
								   Don'tCreateInterfaceFlg 
								   Don'tGetSpecialCardsFlg 
								   InterestedWindow PublicOrPrivate 
								   MenuPosition QuietFlg ReadOnlyFlg 
								   Don'tCheckForTruncationFlg))
					       (NoteFileNeedsConversion (
							   NC.ProcessNoteFileNeedsConversionError
									  NoteFile 
								      Don'tCacheTypesAndTitlesFlg 
									  Don'tCreateFlg 
									  ConvertNoConfirmFlg 
									  Don'tCreateArrayFlg 
									  Can'tTruncateFlg 
									  Don'tCreateInterfaceFlg 
									  Don'tGetSpecialCardsFlg 
									  InterestedWindow 
									  PublicOrPrivate 
									  MenuPosition QuietFlg 
									  ReadOnlyFlg 
								       Don'tCheckForTruncationFlg))
					       (NoteFileNeedsTruncation (
							   NC.ProcessNoteFileNeedsTruncationError
									  NoteFile 
								      Don'tCacheTypesAndTitlesFlg 
									  Don'tCreateFlg 
									  ConvertNoConfirmFlg 
									  Don'tCreateArrayFlg 
									  Can'tTruncateFlg 
									  Don'tCreateInterfaceFlg 
									  Don'tGetSpecialCardsFlg 
									  InterestedWindow 
									  PublicOrPrivate 
									  MenuPosition QuietFlg 
									  ReadOnlyFlg 
								       Don'tCheckForTruncationFlg))
					       (NoteFileAlreadyOpen
						 (ERSETQ (NC.ReportError
							     NIL
							     (CONCAT (fetch (NoteFile 
										     FullFileName)
									  of NoteFile)
								       
					    " is already open for exclusive access. Open failed."))))
					       (NoteFileOpenFailed
						 (ERSETQ (NC.ReportError
							     NIL
							     (CONCAT "Open of "
								       (fetch (NoteFile 
										     FullFileName)
									  of NoteFile)
								       " failed for unknown reason."))
							   ))
					       (NoteFileHeaderBad
						 (ERSETQ (NC.ReportError
							     NIL
							     (CONCAT "Header of NoteFile "
								       (fetch (NoteFile 
										     FullFileName)
									  of NoteFile)
								       
							  " is bad.  Contact a NoteCards wizard."))))
					       (PROGN (ERSETQ (NC.ReportError NIL
										    (CONCAT 
									   "Unknown error code ("
											      
										      ReturnValue 
						     ") returned by OpenNoteFileFn for NoteFile "
											      
											 FileName)))))
					     ReturnValue))

          (* * notify the user. if there's been a problem)


				     (if (AND (NOT (type? NoteFile ReturnValue))
						  (WINDOWP InterestedWindow))
					 then (NC.PrintMsg InterestedWindow NIL 
							       "Open canceled for NoteFile "
							       FileName "." (CHARACTER 13))
						(DISMISS NC.MsgDelay)
						(NC.ClearMsg InterestedWindow T))

          (* * return whatever the error processing returned.)


				     (RETURN ReturnValue))
			          (SETQ ReturnValue)

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


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

          (* * If needed, build a hash array by calling the device specific BuilHashArrayFn.)


			          (replace (NoteFile UID) of NoteFile with (fetch
										   (
NoteFileCriticalUIDs NoteFile) of CriticalUIDs))

          (* * Store this NoteFile object in the appropriate NoteFile hash array)


			          (NC.NoticeNoteFile NoteFile)
			          (if (NOT Don'tCreateArrayFlg)
				      then
				       (OR QuietFlg (NC.PrintMsg InterestedWindow T 
								     "Opening NoteFile: "
								     FileName
								     (CHARACTER 13)
								     "Building index array ..."
								     (CHARACTER 13)))
				       (if
					 (OR (NULL (ERSETQ (SETQ ReturnValue
								   (APPLY*
								     (fetch (NoteFile 
										 BuildHashArrayFn)
									of NoteFile)
								     NoteFile QuietFlg 
								     InterestedWindow
								     (CONCAT "Opening NoteFile "
									       (fetch (NoteFile
											  
										     FullFileName)
										  of NoteFile)
									       (CHARACTER 13))))))
					       (NOT (type? NoteFile ReturnValue)))
					   then 

          (* * Error during building of hash array)


						  (ERSETQ (NC.ReportError
							      NIL
							      (CONCAT 
							  "Build Hash Array failed for NoteFile "
									(fetch (NoteFile 
										     FullFileName)
									   of NoteFile)
									" because " ReturnValue)))
						  (RETURN)))

          (* * Set up critical UIDs in NoteFile object using the values returned from OpenNoteFileFn.)


			          (NC.InstallCriticalUIDsInNoteFile NoteFile CriticalUIDs)

          (* * if needed, cache the special cards)


			          (if (NOT Don'tGetSpecialCardsFlg)
				      then (NC.GetSpecialCards NoteFile QuietFlg InterestedWindow
								   (CONCAT "Opening NoteFile: "
									     (fetch (NoteFile
											FullFileName)
										of NoteFile)
									     (CHARACTER 13))))

          (* * If needed, start the titles and types caching process)


			          (if (NOT Don'tCacheTypesAndTitlesFlg)
				      then (replace (NoteFile CachingProcess) of NoteFile
						with (ADD.PROCESS (LIST (FUNCTION 
									   NC.CacheTypesAndTitles)
									      NoteFile))))

          (* * If needed, open up a NoteFile interface.)


			          (if (NOT Don'tCreateInterfaceFlg)
				      then (NC.SetUpNoteFileInterface NoteFile MenuPosition 
									  InterestedWindow))

          (* * Record this as the last NF opened.)


			          (SETQ NC.LastNoteFileOpened NoteFile)
			          (RETURN NoteFile)))
		        (if (type? NoteFile ReturnValue)
			    then 

          (* * 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 FileName NoteFile
								(QUOTE AFTER)
								InterestedWindow)))

          (* * Go home, returning NoteFile)


				   (if (NULL QuietFlg)
				       then (NC.PrintMsg InterestedWindow T "Opening NoteFile: " 
							     FileName (CHARACTER 13)
							     "Done."
							     (CHARACTER 13))
					      (NC.ClearMsg InterestedWindow T))
				   (RETURN NoteFile)
			  else 

          (* * Bail out if open was unsuccessful.)


				 (RETURN NIL))))))))

(NC.ProcessTruncationRequest
  (LAMBDA (NoteFile Don'tCacheTypesAndTitlesFlg Don'tCreateFlg Convertw/oConfirmFlg 
		    Don'tCreateArrayFlg Don'tTruncateFlg Don'tCreateInterfaceFlg 
		    Don'tGetSpecialCardsFlg PromptWindow PublicOrPrivate MenuPosition QuietFlg 
		    ReadOnlyFlg)                             (* pmi: "14-May-87 11:42")

          (* * Do the actual truncation of a NoteFile that has stuf past the checkpoint pointer.)



          (* * fgh 5/25/86 First created.)



          (* * fgh 9/1/86 Updated args to match NC.OpenNoteFile.)



          (* * rht 2/19/87: Now passes PromptWindow arg to TruncationFn.)



          (* * pmi 5/14/87: Removed NoteFilesHashArray argument.)


    (LET (ReturnValue (TruncationFn (fetch (NoteFile TruncateNoteFileFn) of NoteFile)))

          (* * Do the truncation.)


         (if (type? NoteFile (CAR (ERSETQ (SETQ ReturnValue (APPLY* TruncationFn NoteFile 
										PromptWindow)))))
	     then 

          (* * Truncation successful, Open the note file.)


		    (NC.OpenNoteFile NoteFile Don'tCacheTypesAndTitlesFlg Don'tCreateFlg 
				       Convertw/oConfirmFlg Don'tCreateArrayFlg Don'tTruncateFlg 
				       Don'tCreateInterfaceFlg Don'tGetSpecialCardsFlg PromptWindow 
				       PublicOrPrivate MenuPosition QuietFlg ReadOnlyFlg)
	   else 

          (* * Error during truncation fn. report and get out of here.)


		  (SELECTQ ReturnValue
			     (NoteFileTruncationAborted (QUOTE NoteFileTruncationAborted))
			     (PROGN (ERSETQ (NC.ReportError NIL (CONCAT 
						       "NoteFile truncation failed for NoteFile "
										(fetch
										  (NoteFile 
										     FullFileName)
										   of NoteFile)
										" because " 
										ReturnValue ".")))
				      (QUOTE NoteFileTruncationFailed)))))))

(NC.ProcessInspectAndRepairRequest
  (LAMBDA (NoteFile Don'tCacheTypesAndTitlesFlg Don'tCreateFlg Convertw/oConfirmFlg 
		    Don'tCreateArrayFlg Can'tTruncateFlg Don'tCreateInterfaceFlg 
		    Don'tGetSpecialCardsFlg PromptWindow PublicOrPrivate 
		    Don'tCheckOperationsInProgressFlg MenuPosition QuietFlg ReadOnlyFlg 
		    Don'tCheckForTruncationFlg)              (* pmi: "14-May-87 11:41")

          (* * Do an an InspectAndRepair on a file then try to reopen. Used when checkpoint pinter out of sorts during an 
	  Open.)



          (* * fgh 5/25/86 First created.)



          (* * fgh 9/1/86 Updated args to match NC.OpenNoteFile.)



          (* * rht 10/31/86: Changed outdated call to NC.RepairNoteFile to NC.InspectAndRepairNoteFile.
	  Added Don'tCheckForTruncationFlg arg. No longer tries to open after NC.InspectAndRepairNoteFile returns.)



          (* * pmi 5/14/87: Removed NoteFilesHashArray argument.)


    (if (CAR (ERSETQ (NC.InspectAndRepairNoteFile NoteFile NIL PromptWindow)))
	then 

          (* * For now, can't open after NC.InspectAndRepairNoteFile returns because returns before repair has completed.)



          (* * (* * Repair NoteFile succeeded, try to Open the NF now.) (NC.OpenNoteFile NoteFile NoteFilesHashArray 
	  Don'tCacheTypesAndTitlesFlg Don'tCreateFlg Convertw/oConfirmFlg Don'tCreateArrayFlg Can'tTruncateFlg 
	  Don'tCreateInterfaceFlg Don'tGetSpecialCardsFlg PromptWindow PublicOrPrivate T MenuPosition QuietFlg ReadOnlyFlg 
	  Don'tCheckForTruncationFlg))


	       NIL
      else 

          (* * REapir NoteFile failed for some reason. Report and return.)


	     (ERSETQ (NC.ReportError NIL (CONCAT "NoteFile Inspect&RepairFailed for NoteFile "
						       (fetch (NoteFile FullFileName) of NoteFile)
						       )))
	     (QUOTE InspectAndRepairFailed))))

(NC.ProcessNoteFileNeedsTruncationError
  (LAMBDA (NoteFile Don'tCacheTypesAndTitlesFlg Don'tCreateFlg Convertw/oConfirmFlg 
		    Don'tCreateArrayFlg Can'tTruncateFlg Don'tCreateInterfaceFlg 
		    Don'tGetSpecialCardsFlg PromptWindow PublicOrPrivate MenuPosition QuietFlg 
		    ReadOnlyFlg Don'tCheckForTruncationFlg)
                                                             (* pmi: " 2-Jun-87 14:27")

          (* * Discovered NoteFile needs version truncation when attempted to open it. Process that error.)



          (* * fgh 5/23/86 First created.)



          (* * fgh 9/1/86 Updated args to match NC.OpenNoteFile.)



          (* * rht 10/29/86: Changed name from Abort to Cancel.)



          (* * rht 10/31/86: Added Don'tCheckForTruncationFlg arg.)



          (* * pmi 5/14/87: Removed NoteFilesHashArray argument.)



          (* * pmi 6/2/87: Reinstates fix made by Randy T. which I must have clobbered with the above patch file of my own: 
	  (* * rht 4/30/87: No longer breaks when user selects outside of menu.))


    (PROG (TruncationFn)

          (* * If appropriate, notify the user.)


	    (if (WINDOWP PromptWindow)
		then (NC.PrintMsg PromptWindow T "NoteFile " (fetch (NoteFile FullFileName)
								    of NoteFile)
				      
			    " has information written since last successful close or checkpoint."
				      (CHARACTER 13)))

          (* * If the device has a TruncationFn then apply it and try to Open the NoteFile.)


	    (if (AND (NULL Can'tTruncateFlg)
			 (SETQ TruncationFn (fetch (NoteFile TruncateNoteFileFn) of NoteFile)))
		then 

          (* * ASk the user if they want to truncate, or abort, or repair the notefile.)


		       (SELECTQ (NC.AskUserAboutTruncation NoteFile PromptWindow)
				  (Cancel (RETURN (QUOTE CancelOpen)))
				  (Inspect% &% Repair (RETURN (NC.ProcessInspectAndRepairRequest
								  NoteFile 
								  Don'tCacheTypesAndTitlesFlg 
								  Don'tCreateFlg Convertw/oConfirmFlg 
								  Don'tCreateArrayFlg 
								  Can'tTruncateFlg 
								  Don'tCreateInterfaceFlg 
								  Don'tGetSpecialCardsFlg 
								  PromptWindow PublicOrPrivate 
								  MenuPosition QuietFlg ReadOnlyFlg 
								  Don'tCheckForTruncationFlg)))
				  (Truncate% File (RETURN (NC.ProcessTruncationRequest NoteFile 
								      Don'tCacheTypesAndTitlesFlg 
										   Don'tCreateFlg 
									     Convertw/oConfirmFlg 
									      Don'tCreateArrayFlg 
										 Can'tTruncateFlg 
									  Don'tCreateInterfaceFlg 
									  Don'tGetSpecialCardsFlg 
										     PromptWindow 
										  PublicOrPrivate 
										     MenuPosition 
											 QuietFlg 
										      ReadOnlyFlg 
								       Don'tCheckForTruncationFlg)))
				  (RETURN (QUOTE CancelOpen)))
	      else 

          (* * No TruncationFn. Tell the user if appropriate and return an error msg.)


		     (if (WINDOWP PromptWindow)
			 then (NC.PrintMsg PromptWindow NIL 
					       "No file truncation possible for this NoteFile."
					       (CHARACTER 13)
					       "See a NoteCards wizard."
					       (CHARACTER 13)))
		     (RETURN (QUOTE NoteFileNeedsTruncation))))))

(NC.ProcessNoteFileNeedsConversionError
  (LAMBDA (NoteFile Don'tCacheTypesAndTitlesFlg Don'tCreateFlg Convertw/oConfirmFlg 
		    Don'tCreateArrayFlg Can'tTruncateFlg Don'tCreateInterfaceFlg 
		    Don'tGetSpecialCardsFlg PromptWindow PublicOrPrivate MenuPosition QuietFlg 
		    ReadOnlyFlg Don'tCheckForTruncationFlg)
                                                             (* pmi: "14-May-87 11:38")

          (* * Discovered NoteFile needs version conversion when attempted to open it. Process that error.)



          (* * fgh 5/23/86 First created.)



          (* * fgh 9/1/86 Updated args to match NC.OpenNoteFile.)



          (* * rht 10/31/86: Added Don'tCheckForTruncationFlg arg.)



          (* * 11/6/86: Now passes PromptWindow down to conversion fn.)



          (* * pmi 5/14/87: Removed NoteFilesHashArray argument.)


    (LET (ConversionFn ReturnValue)

          (* * If appropriate, notify the user.)


         (if (WINDOWP PromptWindow)
	     then (NC.PrintMsg PromptWindow T "NoteFile " (fetch (NoteFile FullFileName)
								 of NoteFile)
				   "is an old format file."
				   (CHARACTER 13)))

          (* * If the device has a ConversionFn, then apply it and try to Open the NoteFile.)


         (if (SETQ ConversionFn (fetch (NoteFile ConvertNoteFileFormatFn) of NoteFile))
	     then 

          (* * ask the user if conversion should be done. If so, do it, else return an error msg,)


		    (if (OR Convertw/oConfirmFlg (NC.AskYesOrNo 
						  "Do you want to convert it to the new format? "
								      " -- " "Y" NIL PromptWindow))
			then 

          (* * go ahead and convert.)


			       (if (type? NoteFile (CAR (ERSETQ (SETQ ReturnValue
									  (APPLY* ConversionFn 
										    NoteFile 
										    PromptWindow)))))
				   then 

          (* * Conversion successful, Open the note file.)


					  (NC.OpenNoteFile NoteFile Don'tCacheTypesAndTitlesFlg 
							     Don'tCreateFlg Convertw/oConfirmFlg 
							     Don'tCreateArrayFlg Can'tTruncateFlg 
							     Don'tCreateInterfaceFlg 
							     Don'tGetSpecialCardsFlg PromptWindow 
							     PublicOrPrivate MenuPosition QuietFlg 
							     ReadOnlyFlg Don'tCheckForTruncationFlg)
				 else 

          (* * Error during conversion fn. report and get out of here.)


					(SELECTQ ReturnValue
						   (PROGN (ERSETQ
							      (NC.ReportError
								NIL
								(CONCAT 
						"NoteFile format conversion failed for NoteFile "
									  (fetch (NoteFile 
										     FullFileName)
									     of NoteFile))))
							    (QUOTE NoteFileConversionFailed))))
		      else 

          (* * User said don't convert. Just return)


			     (QUOTE NoteFileNeedsConversion))
	   else 

          (* * No conversion fn. Tell the user if appropriate and return an error msg.)


		  (if (WINDOWP PromptWindow)
		      then (NC.PrintMsg PromptWindow NIL "No format conversion possible."
					    (CHARACTER 13)
					    "See a NoteCards wizard."
					    (CHARACTER 13)))
		  (QUOTE NoteFileNeedsConversion)))))

(NC.ProcessNoteFileNotFoundError
  (LAMBDA (NoteFile Don'tCacheTypesAndTitlesFlg Don'tCreateFlg Convertw/oConfirmFlg 
		    Don'tCreateArrayFlg Can'tTruncateFlg Don'tCreateInterfaceFlg 
		    Don'tGetSpecialCardsFlg InterestedWindow PublicOrPrivate MenuPosition QuietFlg 
		    ReadOnlyFlg Don'tCheckForTruncationFlg)
                                                             (* pmi: "28-May-87 17:40")

          (* * NoteFile couldnot be found when an attempt was made to open it. Find out if the user wants to create it.)



          (* * fgh 5/23/86 First created.)



          (* * fgh 9/1/86 Updated args to match NC.OpenNoteFIle.)



          (* * rht 10/31/86: Added Don'tCheckForTruncationFlg arg.)



          (* * pmi 5/28/87: Removed NoteFilesHashArray argument.)


    (if QuietFlg
	then 

          (* * If QuietFlg is set, then we'll just have to send back a error notification.)


	       (QUOTE NoteFileNotFound)
      else 

          (* * Otherwise, we can interact with the user.)


	     (LET (NewFileName)

          (* * Notify user of the error)


	          (NC.PrintMsg InterestedWindow T "Could not find NoteFile " (fetch (NoteFile
											  
										     FullFileName)
										  of NoteFile)
				 (CHARACTER 13))

          (* * If the user wants to create the file, then create it and try the open again.)


	          (if (AND (NULL Don'tCreateFlg)
			       (NC.AskYesOrNo (CONCAT "Do you want to create "
							  (fetch (NoteFile FullFileName)
							     of NoteFile))
						" -- " "Y" NIL InterestedWindow T NIL))
		      then (if (CAR (ERSETQ (SETQ NewFileName (NC.CreateNoteFile
							NoteFile NIL NIL InterestedWindow
							(CONCAT "Opening NoteFile" (CHARACTER
								    13))))))
				 then (NC.OpenNoteFile NoteFile Don'tCacheTypesAndTitlesFlg 
							   Don'tCreateFlg Convertw/oConfirmFlg 
							   Don'tCreateArrayFlg Can'tTruncateFlg 
							   Don'tCreateInterfaceFlg 
							   Don'tGetSpecialCardsFlg InterestedWindow 
							   PublicOrPrivate MenuPosition QuietFlg 
							   ReadOnlyFlg Don'tCheckForTruncationFlg))
		    else (QUOTE NoteFileNotFound))))))

(NC.StoreNoteFileInHashArray
  (LAMBDA (NoteFileOrFileName)                               (* pmi: "20-May-87 11:59")

          (* * store NoteFile in HashArray, a NoteFiles hash array.)



          (* * fgh 5/23/86 First created.)



          (* * Are there any other NoteFiles of the same fullfilename here? If so, something got messed up.
	  Remove these items.)



          (* * pmi 5/19/87: Removed HashArray argument -
	  this function only applies to NC.NoteFilesHashArray.)


    (DECLARE (GLOBALVARS NC.NoteFilesHashArray))
    (LET ((NoteFile (if (type? NoteFile NoteFileOrFileName)
			then NoteFileOrFileName
		      else (NC.NoteFileFromFileName NoteFileOrFileName))))
         (if NoteFile
	     then (MAPHASH NC.NoteFilesHashArray (FUNCTION (LAMBDA (NF UID)
				   (if (EQ (fetch (NoteFile FullFileName) of NoteFile)
					       (fetch (NoteFile FullFileName) of NF))
				       then (PUTHASH UID NIL NC.NoteFilesHashArray)))))

          (* * Okay, now put in the new entry)


		    (PUTHASH (fetch (NoteFile UID) of NoteFile)
			       NoteFile NC.NoteFilesHashArray)))))

(NC.RemoveAccessToNoteFile
  (LAMBDA (NoteFileOrFileNameOrUID)                          (* pmi: "21-May-87 11:49")

          (* * Remove a NoteFile from the NoteFiles hash array and close its menu if its on the screen.)



          (* * pmi 5/21/87: Cleaned up to call NC.RemoveNoteFile for the hash array stuff.)


    (LET ((NoteFileObject (NC.RemoveNoteFile NoteFileOrFileNameOrUID))
	  NoteFileName Menu)
         (SETQ Menu (if NoteFileObject
			  then (SETQ NoteFileName (fetch (NoteFile FullFileName)
							       NoteFileObject))
				 (OR (fetch (NoteFile Menu) of NoteFileObject)
				       (GETPROP NoteFileName (QUOTE Menu)))
			else (GETPROP (SETQ NoteFileName NoteFileOrFileNameOrUID)
					  (QUOTE Menu))))
         (if Menu
	     then (CLOSEW (WFROMMENU Menu))
		    (SETQ Menu)))))

(NC.RemoveNoteFile
  (LAMBDA (NoteFileOrFileNameOrUID)                          (* pmi: "28-May-87 11:54")

          (* * Remove this notefile from the global hash array and the list of noticed notefiles.)



          (* * pmi 5/28/87: Checks more thoroughly for type of object passed in. Also calls NC.RemoveNoteFileName to remove 
	  NoteFile name form list of Noticed NoteFiles. Returns NoteFile object removed.)


    (DECLARE (GLOBALVARS NC.NoteFilesHashArray))
    (LET (NoteFile NoteFileName)
         (if (type? NoteFile NoteFileOrFileNameOrUID)
	     then (SETQ NoteFile NoteFileOrFileNameOrUID)
		    (SETQ NoteFileName (fetch (NoteFile FullFileName) of NoteFile))
	   elseif (type? UID NoteFileOrFileNameOrUID)
	     then (SETQ NoteFile (GETHASH NoteFileOrFileNameOrUID NC.NoteFilesHashArray))
		    (SETQ NoteFileName (fetch (NoteFile FullFileName) of NoteFile))
	   else (SETQ NoteFile (NC.NoteFileFromFileName NoteFileOrFileNameOrUID))
		  (SETQ NoteFileName NoteFileOrFileNameOrUID))
         (if NoteFile
	     then (NC.RemoveNoteFileFromHashArray NoteFile))
         (if NoteFileName
	     then (NC.RemoveNoteFileName NoteFileName))
     NoteFile)))

(NC.ListOfNoteFiles
  (LAMBDA NIL                                                (* pmi: "22-May-87 11:31")

          (* * Create a list of all NoteFiles found in the notefiles hash array.)



          (* * pmi 5/22/87: Added Globalvars.)


    (DECLARE (GLOBALVARS NC.NoteFilesHashArray))
    (LET (NoteFiles)
         (MAPHASH NC.NoteFilesHashArray (FUNCTION (LAMBDA (Value Key)
			(AND (type? NoteFile Value)
			       (push NoteFiles Value)))))
     NoteFiles)))
)
(* * New for NCINTERFACE)


(RPAQ? NC.FileNameFont (FONTCREATE (QUOTE HELVETICA)
				     10
				     (QUOTE BOLD)))

(RPAQ? NC.FullFileNameFont (FONTCREATE (QUOTE HELVETICA)
					 8
					 (QUOTE STANDARD)))

(RPAQ? NC.MaxFileNameChars 18)
(DEFINEQ

(NC.CreateMenuBitmaps
  (LAMBDA (NoteFileOrFileName)                               (* pmi: "26-May-87 17:09")

          (* * pmi 5/21/87: creates a menu item bitmap for this notefile.)


    (DECLARE (GLOBALVARS NC.FileNameFont NC.FullFileNameFont NC.MaxFileNameChars))
    (PROG (FullFileName FileNameString FullFileNameString NameWidth MaxNameWidth SpaceWidth oWidth 
			  FullNameWidth FullNameMargin FontDescent OpenMenuBitmap MenuBitmap 
			  DisplayStream OpenDisplayStream)
	    (SETQ FullFileName (if (type? NoteFile NoteFileOrFileName)
				     then (fetch (NoteFile FullFileName)
						     NoteFileOrFileName)
				   else (FULLNAME NoteFileOrFileName)))
	    (if (NULL FullFileName)
		then (RETURN))
	    (SETQ FileNameString (MKSTRING (PACKFILENAME (QUOTE HOST)
							       NIL
							       (QUOTE DIRECTORY)
							       NIL
							       (QUOTE EXTENSION)
							       NIL
							       (QUOTE BODY)
							       FullFileName)))
	    (SETQ FullFileNameString (MKSTRING (L-CASE FullFileName)))
	    (SETQ NameWidth (STRINGWIDTH FileNameString NC.FileNameFont))
	    (SETQ FullNameWidth (STRINGWIDTH FullFileNameString NC.FullFileNameFont))
	    (SETQ MaxNameWidth (STRINGWIDTH (ALLOCSTRING NC.MaxFileNameChars "X")
						NC.FileNameFont))
	    (SETQ SpaceWidth (STRINGWIDTH " " NC.FullFileNameFont))
	    (SETQ oWidth (STRINGWIDTH "o" NC.FullFileNameFont))
	    (if (GREATERP NameWidth MaxNameWidth)
		then (SETQ FullNameMargin (PLUS SpaceWidth oWidth SpaceWidth NameWidth 
						      SpaceWidth))
	      else (SETQ FullNameMargin (PLUS SpaceWidth oWidth SpaceWidth MaxNameWidth 
						    SpaceWidth)))
	    (SETQ FontDescent (FONTDESCENT NC.FileNameFont))

          (* * Create the bitmap for the open notefile.)


	    (SETQ OpenMenuBitmap (BITMAPCREATE (PLUS FullNameMargin FullNameWidth SpaceWidth)
						   (FONTHEIGHT NC.FileNameFont)))
	    (SETQ OpenDisplayStream (DSPCREATE OpenMenuBitmap))
	    (MOVETO SpaceWidth FontDescent OpenDisplayStream)
	    (DSPFONT NC.FullFileNameFont OpenDisplayStream)
	    (PRIN1 "o" OpenDisplayStream)
	    (RELMOVETO SpaceWidth 0 OpenDisplayStream)
	    (DSPFONT NC.FileNameFont OpenDisplayStream)
	    (PRIN1 FileNameString OpenDisplayStream)
	    (MOVETO FullNameMargin FontDescent OpenDisplayStream)
	    (DSPFONT NC.FullFileNameFont OpenDisplayStream)
	    (PRIN1 FullFileNameString OpenDisplayStream)
	    (PUTPROP FullFileName (QUOTE OpenMenuBitmap)
		       OpenMenuBitmap)

          (* * Create bitmap for the closed notefile.)


	    (SETQ MenuBitmap (BITMAPCREATE (PLUS FullNameMargin FullNameWidth SpaceWidth)
					       (FONTHEIGHT NC.FileNameFont)))
	    (SETQ DisplayStream (DSPCREATE MenuBitmap))
	    (MOVETO (PLUS SpaceWidth oWidth SpaceWidth)
		      FontDescent DisplayStream)
	    (DSPFONT NC.FileNameFont DisplayStream)
	    (PRIN1 FileNameString DisplayStream)
	    (MOVETO FullNameMargin FontDescent DisplayStream)
	    (DSPFONT NC.FullFileNameFont DisplayStream)
	    (PRIN1 FullFileNameString DisplayStream)
	    (PUTPROP FullFileName (QUOTE MenuBitmap)
		       MenuBitmap)
	    (RETURN FullFileName))))

(NC.GetNoteFileMenu
  (LAMBDA (NoteFileOrFileName)                               (* pmi: " 2-Jun-87 12:47")

          (* * pmi 6/2/87: Created to get the NoteFile icon menu for a NoteFile.)


    (LET (FullFileName NoteFile)
         (if (type? NoteFile NoteFileOrFileName)
	     then (OR (fetch (NoteFile Menu) of NoteFileOrFileName)
			  (GETPROP (fetch (NoteFile FullFileName)
					      NoteFileOrFileName)
				     (QUOTE Menu)))
	   elseif (SETQ FullFileName (FULLNAME NoteFileOrFileName))
	     then (OR (GETPROP FullFileName (QUOTE Menu))
			  (if (type? NoteFile (SETQ NoteFile (NC.NoteFileFromFileName 
										     FullFileName)))
			      then (fetch (NoteFile Menu) of NoteFile)))))))

(NC.SetNoteFileMenu
  (LAMBDA (NoteFileOrFileName Menu)                          (* pmi: " 2-Jun-87 12:47")

          (* * pmi 6/2/87: Created to set the NoteFile icon menu for a NoteFile.)


    (LET (FullFileName NoteFile)
         (if NoteFileOrFileName
	     then (if (type? NoteFile NoteFileOrFileName)
			then (replace (NoteFile Menu) of NoteFileOrFileName with Menu)
			       (PUTPROP (fetch (NoteFile FullFileName)
						   NoteFileOrFileName)
					  (QUOTE Menu)
					  Menu)
		      elseif (SETQ FullFileName (FULLNAME NoteFileOrFileName))
			then (PUTPROP FullFileName (QUOTE Menu))
			       (if (type? NoteFile (SETQ NoteFile (NC.NoteFileFromFileName
						  FullFileName)))
				   then (replace (NoteFile Menu) of NoteFile with Menu)))))))
)
(* * Changed in NCINTERFACE)

(DEFINEQ

(NC.SetUpNoteFileInterface
  (LAMBDA (NoteFile Position InterestedWindow)               (* pmi: "29-May-87 19:22")

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



          (* * rht 11/20/86: Changed name from ShowBox to ShowCards.)



          (* * pmi 12/12/86: Added InterestedWindow argument so that we can print a prompt to the user about placing a newly 
	  created NoteFile menu.)



          (* * pmi 3/20/87: Removed WhenSelectedFn when overhauling to have NewCards and ShowCards middlebutton menus appear 
	  when buttoned DOWN, instead of after the button comes back up. Everything is now done in the ButtonEventFn.)



          (* * pmi 5/6/87: Moved prompt for position of icon to better place. Also added MENUOFFSET to NoteFile menu for 
	  Lyric.)



          (* * pmi 5/19/87: Now stores the menu as a property of the fullfilename of the notefile. We might lose our pointer 
	  to the notefile object if another one gets created with the same UID, but we would like to keep a pointer to the 
	  menu.)



          (* * pmi 5/28/87: Now returns the NoteFile Interface window.)


    (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 (OR (NC.GetNoteFileMenu NoteFile)
					  (NC.GetNoteFileMenu FullFileName)))
	     then 

          (* * No longer need WHENSELECTEDFN)



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

          (* * Removed this menu field from following menu: (WHENSELECTEDFN ← (if (NC.NoteFileOpenP NoteFile) then 
	  (FUNCTION NC.NoteFileMenuWhenSelectedFn) else (FUNCTION NC.ClosedNoteFileMenuWhenSelectedFn))))


		  (SETQ NoteFileMenu (create MENU
						 ITEMS ←(QUOTE ((NewCards NIL 
		       "Create a new Text card (left button) or other card type (middle button).")
								   (ShowCards NIL 
							     "Bring up one of the special cards.")))
						 WHENSELECTEDFN ←(FUNCTION NILL)
						 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
						 MENUOFFSET ←(CONS 0 0))))
         (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
							(if Position
							  elseif (GETMENUPROP NoteFileMenu
										  (QUOTE 
										      OldPosition))
							  else 
                                                             (* Prompt the user to place the new notefile menu)
								 (NC.PrintMsg InterestedWindow T 
							    "Please place the menu for notefile "
										FullFileName)
								 (SETQ Position
								   (GETBOXPOSITION
								     (fetch (REGION WIDTH)
									of (MENUREGION 
										     NoteFileMenu))
								     (fetch (REGION HEIGHT)
									of (MENUREGION 
										     NoteFileMenu))))
								 (NC.ClearMsg InterestedWindow T)
								 Position))))
         (WINDOWPROP NoteFileMenuWindow (QUOTE NoteFile)
		       NoteFile)
         (replace (NoteFile Menu) of NoteFile with NoteFileMenu)
         (PUTPROP FullFileName (QUOTE Menu)
		    NoteFileMenu)
         (WINDOWPROP NoteFileMenuWindow (QUOTE RESHAPEFN)
		       (QUOTE DON'T))
         (WINDOWPROP NoteFileMenuWindow (QUOTE BUTTONEVENTFN)
		       (FUNCTION NC.NoteFileIconButtonEventFn))
         (WINDOWPROP NoteFileMenuWindow (QUOTE SHRINKFN)
		       (QUOTE DON'T))
         (WINDOWPROP NoteFileMenuWindow (QUOTE SCROLLFN)
		       NIL)
         (WINDOWPROP NoteFileMenuWindow (QUOTE NOSCROLLBARS)
		       T)

          (* * Make sure default menu WhenSelectedFn is not called)


         (WINDOWPROP NoteFileMenuWindow (QUOTE CURSORINFN)
		       NIL)
         (WINDOWPROP NoteFileMenuWindow (QUOTE CURSOROUTFN)
		       NIL)
         (WINDOWPROP NoteFileMenuWindow (QUOTE CURSORMOVEDFN)
		       NIL)

          (* *)


         (WINDOWADDPROP NoteFileMenuWindow (QUOTE CLOSEFN)
			  (FUNCTION (LAMBDA (Window)
			      (PUTMENUPROP (CAR (WINDOWPROP Window (QUOTE MENU)))
					     (QUOTE OldPosition)
					     (WINDOWPOSITION Window)))))
         (NC.MoveWindowOntoScreen NoteFileMenuWindow)
     NoteFileMenuWindow)))

(NC.NoteFileTitleLeftWhenSelectedFn
  (LAMBDA (Item Menu Button)                                 (* pmi: "27-May-87 12:07")

          (* * WhenSelectedFn for the menus NC.OpenedNoteFileMenu and NC.ClosedNoteFileMenu. These operations used to be 
	  performed by NC.NoteFileOperations. Provides faster Left-button title bar menu on NoteFile icons.)



          (* * rht 2/11/87: Now handles possibly extra unanticipated menu items.)



          (* * rht 2/11/87: Removed useless call to DEFAULTWHENSELECTEDFN.)



          (* * rht 2/16/87: Added Close% cards% w/o% confirm case.)



          (* * pmi 5/14/87: Removed HashArray argument to NC.OpenNoteFile.)



          (* * pmi 5/27/87: Changed "Compact to Target File" to "Compact to New File.")


    (DECLARE (GLOBALVARS NC.NoteFileIconCloseOperations NC.NoteFileIconOpenOperations NC.MsgDelay)
	       )
    (LET ((NoteFile (GETMENUPROP Menu (QUOTE NoteFile)))
	  (Operation (CAR Item))
	  NoteFileMenuWindow)
         (SETQ NoteFileMenuWindow (WFROMMENU (fetch (NoteFile Menu) of NoteFile)))
         (WINDOWPROP NoteFileMenuWindow (QUOTE BusyOperation)
		       Operation)
         (COND
	   ((AND (NC.NoteFileOpenP NoteFile)
		   (NOT (FMEMB Operation NC.NoteFileIconOpenOperations)))
	     (NC.PrintMsg NoteFileMenuWindow T "Can't " Operation " an open notefile."
			    (CHARACTER 13))
	     (DISMISS NC.MsgDelay)
	     (NC.ClearMsg NoteFileMenuWindow T))
	   ((AND (NOT (NC.NoteFileOpenP NoteFile))
		   (NOT (FMEMB (CAR Item)
				   NC.NoteFileIconCloseOperations)))
	     (NC.PrintMsg NoteFileMenuWindow T "Can't " Operation " a closed notefile."
			    (CHARACTER 13))
	     (DISMISS NC.MsgDelay)
	     (NC.ClearMsg NoteFileMenuWindow T))
	   (T (SELECTQ Operation
			 (Open (NC.OpenNoteFile NoteFile NIL NIL NIL NIL NIL NIL NIL 
						  NoteFileMenuWindow))
			 (Read-only% Open (NC.OpenNoteFile NoteFile NIL NIL NIL NIL NIL NIL NIL 
							     NoteFileMenuWindow NIL NIL NIL T))
			 (Checkpoint (NC.CheckpointNoteFile NoteFile NIL NIL NoteFileMenuWindow))
			 (Close (NC.CloseNoteFile NoteFile NoteFileMenuWindow))
			 (Close% w/o% confirm (NC.CloseNoteFile NoteFile NoteFileMenuWindow T))
			 (Abort (NC.AbortSession NoteFile NoteFileMenuWindow))
			 (Compact (NC.CompactNoteFile NoteFile NIL NIL NoteFileMenuWindow))
			 (Compact% To% New% File (NC.CompactNoteFile NoteFile NIL NIL 
								       NoteFileMenuWindow))
			 (Compact% In% Place (NC.CompactNoteFile NoteFile NIL T NoteFileMenuWindow))
			 (Inspect&Repair (NC.InspectAndRepairNoteFile NoteFile NIL 
									NoteFileMenuWindow))
			 (Read% Substances (NC.InspectAndRepairNoteFile NoteFile T 
									  NoteFileMenuWindow))
			 (Copy (NC.CopyNoteFile NoteFile NIL NoteFileMenuWindow))
			 (Rename (NC.RenameNoteFile NoteFile))
			 (Delete (NC.DeleteDatabaseFile NoteFile NoteFileMenuWindow))
			 (APPLY* (CADR Item)
				   NoteFile NoteFileMenuWindow)))))))

(NC.DoNoteFileOp
  (LAMBDA (Op)                                               (* pmi: "28-May-87 12:08")

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



          (* * rht 7/17/86: Now calls NC.InspectAndRepairNoteFile instead of NC.ScavengerPhase1.)



          (* * pmi 12/4/86: Added NC.NoteCardsIconWindow argument to calls to NC.ListOfNoteFilesMenu for "Delete" and 
"Rename" operations)



          (* * rht 2/11/87: Now handles case when Op has unexpected value.)



          (* * rht 2/16/87: Added Close% w/o% confirm case.)



          (* * pmi 5/15/87: overhauled to use NC.NoticedNoteFileNamesMenu instead of NC.ListOfNoteFilesMenu.
	  Added "Create and Open" and "Create and Read-only Open" options.)


    (DECLARE (GLOBALVARS NC.NoteCardsIconWindow NC.MsgDelay))
    (SELECTQ Op
	       (Open% NoteFile (LET ((NoteFileName (NC.NoticedNoteFileNamesMenu T NIL 
									   NC.NoteCardsIconWindow
										  (QUOTE 
										   Open% NoteFile))))
				    (if (NULL NoteFileName)
					then NIL
				      else (if (EQ NoteFileName (QUOTE NEW))
						 then (SETQ NoteFileName NIL))
					     (NC.OpenDatabaseFile NoteFileName NIL NIL NIL NIL NIL 
								    NIL NIL NIL NIL 
								    NC.NoteCardsIconWindow))))
	       (Read-only% Open (LET ((NoteFileName (NC.NoticedNoteFileNamesMenu T NIL 
									   NC.NoteCardsIconWindow
										   (QUOTE 
										   Open% NoteFile))))
				     (if (NULL NoteFileName)
					 then NIL
				       else (if (EQ NoteFileName (QUOTE NEW))
						  then (SETQ NoteFileName NIL))
					      (NC.OpenDatabaseFile NoteFileName (QUOTE INPUT)
								     NIL NIL NIL NIL NIL NIL NIL NIL 
								     NC.NoteCardsIconWindow))))
	       (Checkpoint% NoteFile (LET ((NoteFileName (NC.NoticedNoteFileNamesMenu NIL T 
									   NC.NoteCardsIconWindow
											(QUOTE
											  
									     Checkpoint% NoteFile))))
				          (if NoteFileName
					      then (NC.CheckpointDatabase (
									  NC.NoteFileFromFileName
										NoteFileName)
									      NIL NIL 
									   NC.NoteCardsIconWindow)
					    else (NC.PrintMsg NC.NoteCardsIconWindow NIL 
								  "Checkpoint cancelled."
								  (CHARACTER 13))
						   (DISMISS NC.MsgDelay)
						   (NC.ClearMsg NC.NoteCardsIconWindow T))))
	       (Close% NoteFile (LET ((NoteFileName (NC.NoticedNoteFileNamesMenu NIL T 
									   NC.NoteCardsIconWindow
										   (QUOTE 
										  Close% NoteFile))))
				     (if NoteFileName
					 then (NC.CloseNoteFile (NC.NoteFileFromFileName 
										     NoteFileName)
								    NC.NoteCardsIconWindow)
				       else (NC.PrintMsg NC.NoteCardsIconWindow NIL 
							     "Close cancelled."
							     (CHARACTER 13))
					      (DISMISS NC.MsgDelay)
					      (NC.ClearMsg NC.NoteCardsIconWindow T))))
	       (Close% w/o% confirm (LET ((NoteFileName (NC.NoticedNoteFileNamesMenu NIL T 
									   NC.NoteCardsIconWindow
										       (QUOTE
											 
										  Close% NoteFile))))
				         (if NoteFileName
					     then (NC.CloseNoteFile (NC.NoteFileFromFileName
									  NoteFileName)
									NC.NoteCardsIconWindow NIL T)
					   else (NC.PrintMsg NC.NoteCardsIconWindow NIL 
								 "Close w/o confirm cancelled."
								 (CHARACTER 13))
						  (DISMISS NC.MsgDelay)
						  (NC.ClearMsg NC.NoteCardsIconWindow T))))
	       (Abort% NoteFile (LET ((NoteFileName (NC.NoticedNoteFileNamesMenu NIL T 
									   NC.NoteCardsIconWindow
										   (QUOTE 
										  Abort% NoteFile))))
				     (if NoteFileName
					 then (NC.AbortSession (NC.NoteFileFromFileName 
										     NoteFileName)
								   NC.NoteCardsIconWindow)
				       else (NC.PrintMsg NC.NoteCardsIconWindow NIL 
							     "Abort cancelled."
							     (CHARACTER 13))
					      (DISMISS NC.MsgDelay)
					      (NC.ClearMsg NC.NoteCardsIconWindow T))))
	       (Compact% NoteFile (LET ((NoteFileName (NC.NoticedNoteFileNamesMenu T NIL 
									   NC.NoteCardsIconWindow
										     (QUOTE 
										Compact% NoteFile))))
				       (if (NULL NoteFileName)
					   then NIL
					 else (if (EQ NoteFileName (QUOTE NEW))
						    then (SETQ NoteFileName NIL))
						(NC.CompactNoteFile NoteFileName NIL NIL NIL))))
	       (Compact% In% Place (LET ((NoteFileName (NC.NoticedNoteFileNamesMenu T NIL 
									   NC.NoteCardsIconWindow
										      (QUOTE 
										Compact% NoteFile))))
				        (if (NULL NoteFileName)
					    then NIL
					  else (if (EQ NoteFileName (QUOTE NEW))
						     then (SETQ NoteFileName NIL))
						 (NC.CompactNoteFile NoteFileName NIL T NIL))))
	       (Inspect&Repair% NoteFile (LET ((NoteFileName (NC.NoticedNoteFileNamesMenu
							       T NIL NC.NoteCardsIconWindow
							       (QUOTE Inspect&Repair% NoteFile))))
					      (if (NULL NoteFileName)
						  then NIL
						else (if (EQ NoteFileName (QUOTE NEW))
							   then (SETQ NoteFileName NIL))
						       (NC.InspectAndRepairNoteFile NoteFileName 
										      NIL 
									   NC.NoteCardsIconWindow))))
	       (Read% Substances (LET ((NoteFileName (NC.NoticedNoteFileNamesMenu T NIL 
									   NC.NoteCardsIconWindow
										    (QUOTE 
									 Inspect&Repair% NoteFile))))
				      (if (NULL NoteFileName)
					  then NIL
					else (if (EQ NoteFileName (QUOTE NEW))
						   then (SETQ NoteFileName NIL))
					       (NC.InspectAndRepairNoteFile NoteFileName T 
									   NC.NoteCardsIconWindow))))
	       (Copy% NoteFile (LET ((NoteFileName (NC.NoticedNoteFileNamesMenu T (QUOTE CLOSED)
										  
									   NC.NoteCardsIconWindow
										  (QUOTE 
										   Copy% NoteFile))))
				    (if (NULL NoteFileName)
					then NIL
				      else (if (EQ NoteFileName (QUOTE NEW))
						 then (SETQ NoteFileName NIL))
					     (NC.CopyNoteFile NoteFileName NIL 
								NC.NoteCardsIconWindow))))
	       (Rename% NoteFile (LET ((NoteFileName (NC.NoticedNoteFileNamesMenu T (QUOTE CLOSED)
										    
									   NC.NoteCardsIconWindow
										    (QUOTE 
										 Rename% NoteFile))))
				      (if (NULL NoteFileName)
					  then NIL
					else (if (EQ NoteFileName (QUOTE NEW))
						   then (SETQ NoteFileName NIL))
					       (NC.RenameNoteFile NoteFileName NIL 
								    NC.NoteCardsIconWindow))))
	       (Delete% NoteFile (LET ((NoteFileName (NC.NoticedNoteFileNamesMenu T (QUOTE CLOSED)
										    
									   NC.NoteCardsIconWindow
										    (QUOTE 
										 Delete% NoteFile))))
				      (if (NULL NoteFileName)
					  then NIL
					else (if (EQ NoteFileName (QUOTE NEW))
						   then (SETQ NoteFileName NIL))
					       (NC.DeleteDatabaseFile NoteFileName 
									NC.NoteCardsIconWindow))))
	       (Create% NoteFile (NC.CreateDatabaseFile NIL NIL NIL NIL NIL NIL 
							  NC.NoteCardsIconWindow NIL NIL NIL NIL NIL 
							  NIL))
	       (Create% and% Open (NC.CreateDatabaseFile NIL NIL NIL NIL NIL NIL 
							   NC.NoteCardsIconWindow NIL NIL T NIL NIL 
							   NIL))
	       (Create% and% Read-only% Open (NC.CreateDatabaseFile NIL NIL NIL NIL NIL NIL 
								      NC.NoteCardsIconWindow NIL NIL 
								      T T NIL NIL))
	       (LET ((NoteFileName (NC.NoticedNoteFileNamesMenu NIL T NC.NoteCardsIconWindow)))
		    (if NoteFileName
			then (APPLY* Op (NC.NoteFileFromFileName NoteFileName)
					 NC.NoteCardsIconWindow))))))

(NC.ListOfNoteFilesMenu
  (LAMBDA (IncludeNewNoteFileFlg ShowOnlyOpenNFsFlg InterestedWindow Operation)
                                                             (* pmi: "14-May-87 12:49")

          (* * Bring up a menu of all notefiles found in the notefiles hash array. Also allow user to open a new notefile.)



          (* * kirk 23Jan86 Added AskYesOrNo and InterestedWindow parameter)



          (* * fgh 6/8/86 Added check to make sure NoteFile is open if it has a menu on the screen. Needed to handle case of 
	  liongering NF menus.)



          (* * fgh 6/24/86 Changed to be a general function rather than one specific for opening. Now just returns the chosen
	  name. Also, added IncludeNewNoteFileFlg and ShowOnlyOpenNFsFlg. Removed InterestedWindow arg.)



          (* * fgh 6/27/86 Added InterestedWindow & Operation args and call to NC.DatabaseFileName.)



          (* * pmi 12/4/86: Added version numbers to rootnames on list of known files. Also cleaned up help string for menu 
	  items. It was giving a bogus message about opening the selected file, even though this function is used for many 
	  operations and not just for Open.)



          (* * pmi 2/18/87: Added GLOBALVARS declaration for NC.MenuFont)



          (* * pmi 5/14/87: Changed symbol for open notefile to o. Now uses NC.NoticedNoteFileNames instead of hash array to 
	  build menu. Returns a NoteFile name instead of a NoteFile object.)


    (DECLARE (GLOBALVARS NC.MenuFont NC.NoticedNoteFileNames))
    (LET (Menu Items Result)
         (SETQ Items (BQUOTE (,@(for NoteFileName in NC.NoticedNoteFileNames
				       bind NoteFile Stream RootName
				       when (PROGN (SETQ NoteFile (NC.NoteFileFromFileName
							   NoteFileName))
						       (OR (AND (EQ ShowOnlyOpenNFsFlg
									  (QUOTE CLOSED))
								    (NULL (NC.NoteFileOpenP
									      NoteFile)))
							     (NULL ShowOnlyOpenNFsFlg)
							     (NC.NoteFileOpenP NoteFile)))
				       collect (LIST (CONCAT
							   (if (NC.NoteFileOpenP NoteFile)
							       then 
                                                             (* (if (WINDOWP (WFROMMENU 
							     (fetch (NoteFile Menu) of NoteFile))) then "* " else 
							     "$ "))
								      "o "
							     else "  ")
							   (SUBSTRING (SETQ RootName
									  (PACKFILENAME
									    (QUOTE NAME)
									    (FILENAMEFIELD
									      NoteFileName
									      (QUOTE NAME))
									    (QUOTE VERSION)
									    (FILENAMEFIELD
									      NoteFileName
									      (QUOTE VERSION))))
									1
									(MIN 20 (NCHARS RootName))
									))
							 NoteFileName
							 (CONCAT "Selects NoteFile " NoteFileName)))
				   ,@(if IncludeNewNoteFileFlg
					 then (LIST (QUOTE ("-- Other NoteFile --"
								   (QUOTE NEW)
								   
				  "Select some other notefile - you'll be prompted for the name.")))
				       else NIL))))
         (SETQ Result (if (NULL Items)
			    then NIL
			  elseif (AND (EQ (LENGTH Items)
						1)
					  (EQUAL (CADAR Items)
						   (QUOTE (QUOTE NEW))))
			    then (QUOTE NEW)
			  else (MENU (create MENU
						   ITEMS ← Items
						   TITLE ←(OR Operation "NoteFiles")
						   MENUFONT ← NC.MenuFont
						   ITEMHEIGHT ←(IPLUS (FONTPROP NC.MenuFont
										    (QUOTE HEIGHT))
									1)))))
         (if (EQ Result (QUOTE NEW))
	     then (SETQ Result (NC.DatabaseFileName (CONCAT "Name of NoteFile to "
								    (SUBSTRING Operation 1 -9)
								    (CHARACTER 13))
							  " -- " T T NIL InterestedWindow)))
     Result)))

(NC.FileBrowserOpen
  (LAMBDA (Browser Key Item Menu Access)                     (* pmi: "20-May-87 18:22")

          (* * Function called from file browser menu for notefile open.)



          (* * rht 7/4/86: Added Access arg.)



          (* * rht 3/14/87: Changed to call NC.OpenNoteFile.)



          (* * pmi 5/20/87: Removed HashArray argument in calls to NC.OpenNoteFile.)


    (for FileObject in (FB.SELECTEDFILES Browser) bind FileName
       do (NC.OpenNoteFile (SETQ FileName (U-CASE (MKATOM (FB.FETCHFILENAME FileObject))))
			       NIL NIL NIL NIL NIL NIL NIL (if (NOT (NC.NoteFileFromFileName
									  FileName))
							       then (fetch (FILEBROWSER 
										     PROMPTWINDOW)
									 of Browser))
			       NIL NIL NIL Access))))
)
(* * In NCINTERFACE - Replace the content of the ADDVARs for NC.NoteFileOpsItems and 
NC.NoteFileIconOperationsMenuItems with the contents of these VARS - they should remain 
ADDVARs! (You may want to see me when you integrate this.))


(RPAQQ NC.NoteFileIconCloseOperations (Open Compact Read-only% Open Inspect&Repair Read% Substances 
					      Copy Rename Delete Compact% To% New% File 
					      Compact% In% Place))

(RPAQQ NC.FileBrowserMenuItemsToAdd ((Open NC.FileBrowserOpen "Open selected Notefiles."
					     (SUBITEMS (Read-only% Open (NC.FileBrowserOpen INPUT)
									
							 "Open selected Notefiles for read-only.")))
				       (Checkpoint NC.FileBrowserCheckpoint 
					 "Checkpoint the selected Notefiles, saving dirty cards.")
				       (Close NC.FileBrowserClose "Close selected Notefiles.")
				       (Abort NC.FileBrowserAbort 
			       "Aborts the selected Notefiles losing work since last checkpoint.")
				       (Compact NC.FileBrowserCompact 
					      "Compacts selected Notefiles copying to new files."
						(SUBITEMS (Compact% To% New% File 
									    NC.FileBrowserCompact 
					      "Compacts selected Notefiles copying to new files.")
							  (Compact% In% Place (NC.FileBrowserCompact
										(QUOTE InPlace))
									      
					   "Compacts selected Notefiles w/o copyig to new files.")))
				       (Inspect&Repair NC.FileBrowserInspect&Repair 
					    "Inspects and optionally repairs selected Notefiles."
						       (SUBITEMS (Read% Substances
								   (NC.FileBrowserInspect&Repair
								     (QUOTE ReadSubstances))
								   
"Inspects and optionally repairs selected Notefiles, but reads every substance.  This slows things WAY down."
								   )))
				       (Copy FB.COPYCOMMAND 
					"Copies given notefile(s) to target file (or directory).")
				       (Rename FB.RENAMECOMMAND 
					 "Moves given notefile(s) to target file (or directory).")))

(RPAQQ NC.NoteFileOpsItems ((% Open%  (NC.DoNoteFileOp (QUOTE Open% NoteFile))
					"Opens a notefile."
					(SUBITEMS (Read-only% Open (NC.DoNoteFileOp (QUOTE 
										  Read-only% Open))
								   "Open a notefile for read-only.")))
			      (% Checkpoint%  (NC.DoNoteFileOp (QUOTE Checkpoint% NoteFile))
					      "Checkpoint a NoteFile"
					      (SUBITEMS (Checkpoint% All (NC.CheckpointSession)
									 
							"Checkpoint all currently open NoteFiles")))
			      (% Close%  (NC.DoNoteFileOp (QUOTE Close% NoteFile))
					 "Close a notefile."
					 (SUBITEMS (Close% w/o% confirm (NC.DoNoteFileOp
									  (QUOTE Close% w/o% confirm))
									
			"Close a notefile w/o asking for user confirm before closing open cards.")
						   (Close% All (NC.CloseSession)
							       "Close all currently open NoteFiles")
						   (Close% All% w/o% confirm (NC.CloseSession NIL T)
									     
		"Close all open notefiles w/o asking for user confirm before closing open cards.")))
			      (% Abort%  (NC.DoNoteFileOp (QUOTE Abort% NoteFile))
					 "Close NF, deleting changes since last checkpoint."
					 (SUBITEMS (Abort% All (NC.CloseSession T)
							       "Abort all currently open NoteFiles")))
			      (% Compact%  (NC.DoNoteFileOp (QUOTE Compact% NoteFile))
					   "Compact a NoteFile."
					   (SUBITEMS (Compact% To% New% File (NC.DoNoteFileOp
									       (QUOTE 
										Compact% NoteFile))
									     
						      "Compact a NoteFile copying to a new file.")
						     (Compact% In% Place (NC.DoNoteFileOp
									   (QUOTE Compact% In% Place))
									 
						  "Compact a NoteFile w/o copying to a new file.")))
			      (% Inspect&Repair%  (NC.DoNoteFileOp (QUOTE Inspect&Repair% NoteFile))
						  "Do an Inspect & Repair on a NoteFile."
						  (SUBITEMS (Read% Substances (NC.DoNoteFileOp
										(QUOTE 
										 Read% Substances))
									      
"Inspects and optionally repairs a Notefile, but reads every substance.  This slows it WAY down.")))
			      (% Copy%  (NC.DoNoteFileOp (QUOTE Copy% NoteFile))
					"Copy a NoteFile.")
			      (% Rename%  (NC.DoNoteFileOp (QUOTE Rename% NoteFile))
					  "Rename a NoteFile")
			      (% Delete%  (NC.DoNoteFileOp (QUOTE Delete% NoteFile))
					  "Delete a NoteFile")
			      (% Create%  (NC.DoNoteFileOp (QUOTE Create% NoteFile))
					  "Create a new NoteFile w/o opening it."
					  (SUBITEMS (% Create% and% Open%  (NC.DoNoteFileOp
									     (QUOTE Create% and% Open)
									     )
									   
							     "Create a new NoteFile and open it.")
						    (% Create% and% Read-only% Open% 
						      (NC.DoNoteFileOp (QUOTE 
								     Create% and% Read-only% Open))
						      
					       "Create a new NoteFile and open it for read-only.")))
			      (% --------%  NIL "")
			      (% NC% FileBrowser%  (NC.FileBrowserMenu NC.NoteCardsIconWindow)
						   "Bring up a NoteFile browser.")))

(RPAQQ NC.NoteFileIconOperationsMenuItems ((Open NIL "Opens this NoteFile."
						   (SUBITEMS (Read-only% Open NIL 
							     "Opens this NoteFile for read-only.")))
					     (Checkpoint NIL 
						"Checkpoint this NoteFile, saving changed cards.")
					     (Close NIL "Closes this NoteFile."
						    (SUBITEMS (Close% w/o% confirm NIL 
		     "Close this notefile w/o asking for user confirm before closing open cards.")))
					     (Abort NIL 
					      "Close NF, deleting changes since last checkpoint.")
					     (Compact NIL "Compacts this NoteFile to a new file."
						      (SUBITEMS (Compact% To% New% File NIL 
						      "Compact a NoteFile copying to a new file.")
								(Compact% In% Place NIL 
						  "Compact a NoteFile w/o copying to a new file.")))
					     (Inspect&Repair NIL 
						 "Inspects and optionally repairs this NoteFile."
							     (SUBITEMS (Read% Substances NIL 
"Inspects and optionally repairs a Notefile, but reads every substance.  This slows it WAY down.")))
					     (Copy NIL "Copies this notefile to a target file.")
					     (Rename NIL "Rename this NoteFile")
					     (Delete NIL "Deletes this NoteFile.")))
(* * This is only for the patch file - do not integrate)


(RPAQQ NC.NoteFileOpsMenu NIL)
(NC.MakeNoteFileIconOperationsMenus)
(PUTPROPS PMIPATCH036 COPYRIGHT ("Xerox Corporation" 1987))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (9066 17875 (NC.CompactNoteFileToTarget 9076 . 13530) (NC.CompactNoteFileInPlace 13532
 . 17873)) (17909 19292 (NCP.OpenNoteFile 17919 . 19290)) (19325 50645 (NC.ScavengeDatabaseFile 19335
 . 35430) (NC.ScavengerPhase1 35432 . 50643)) (50686 52758 (NC.OpenCrossFileLinkDestNoteFile 50696 . 
52756)) (52796 56321 (NCLocalDevice.CompactNoteFile 52806 . 56319)) (56353 63855 (
NC.RemoveNoteFileFromHashArray 56363 . 56888) (NC.RemoveNoteFileName 56890 . 57758) (NC.NoticeNoteFile
 57760 . 58286) (NC.NoticeNoteFileName 58288 . 59729) (NC.NoticedNoteFileNamesMenu 59731 . 63853)) (
63931 131973 (NC.CreateNoteFile 63941 . 71040) (NC.CreateDatabaseFile 71042 . 73109) (
NC.ForceDatabaseClose 73111 . 75371) (NC.DeleteDatabaseFile 75373 . 81072) (NC.RenameNoteFile 81074 . 
85243) (NC.CopyNoteFile 85245 . 89318) (NC.InspectAndRepairNoteFile 89320 . 92746) (NC.CompactNoteFile
 92748 . 98070) (NC.OpenDatabaseFile 98072 . 98835) (NC.OpenNoteFile 98837 . 115322) (
NC.ProcessTruncationRequest 115324 . 117227) (NC.ProcessInspectAndRepairRequest 117229 . 119160) (
NC.ProcessNoteFileNeedsTruncationError 119162 . 122491) (NC.ProcessNoteFileNeedsConversionError 122493
 . 125767) (NC.ProcessNoteFileNotFoundError 125769 . 128045) (NC.StoreNoteFileInHashArray 128047 . 
129261) (NC.RemoveAccessToNoteFile 129263 . 130159) (NC.RemoveNoteFile 130161 . 131457) (
NC.ListOfNoteFiles 131459 . 131971)) (132231 137346 (NC.CreateMenuBitmaps 132241 . 135669) (
NC.GetNoteFileMenu 135671 . 136475) (NC.SetNoteFileMenu 136477 . 137344)) (137382 160904 (
NC.SetUpNoteFileInterface 137392 . 144841) (NC.NoteFileTitleLeftWhenSelectedFn 144843 . 147962) (
NC.DoNoteFileOp 147964 . 156129) (NC.ListOfNoteFilesMenu 156131 . 160048) (NC.FileBrowserOpen 160050
 . 160902)))))
STOP