(FILECREATED "10-Jun-87 18:37:18" {QV}<NOTECARDS>1.3K>NEXT>RHTPATCH277.;5 29258  

      changes to:  (VARS RHTPATCH277COMS)
		   (FNS NC.ScavengeDatabaseFile NC.DelReferencesToCardFromBrowser 
			NC.GetBrowserHashArray NC.DeletedLinkGetFn)

      previous date: "10-Jun-87 17:53:31" {QV}<NOTECARDS>1.3K>NEXT>RHTPATCH277.;3)


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

(PRETTYCOMPRINT RHTPATCH277COMS)

(RPAQQ RHTPATCH277COMS ((DECLARE: FIRST (P (NC.LoadFileFromDirectories (QUOTE NCREPAIR))
					     (NC.LoadFileFromDirectories (QUOTE NCBROWSERCARD))))
			  (* * Fixes bug in inspector whereby bad links were being deleted but only 
			     in the cache; change wasn't being written to notefile. Also makes slight 
			     change to the way NC.DeleteLink checks for validity of source and 
			     destination cards. Also fixes NC.DeletedLinkGetFn to skip carriage 
			     return if any. This stems from a bug in the way imageobj's are read and 
			     written and was causing problems when deleted link icons lived in a 
			     browser. Changed browser to better handle deleted link icon graphnodes.)
			  (* * Change to NCLINKS)
			  (FNS NC.DelReferencesToCard NC.DeleteLink NC.DeletedLinkGetFn)
			  (* * Change to NCREPAIR)
			  (FNS NC.ScavengeDatabaseFile)
			  (* * Change to NCBROWSERCARD)
			  (FNS NC.DelReferencesToCardFromBrowser NC.GetHashArray)))
(DECLARE: FIRST 
(NC.LoadFileFromDirectories (QUOTE NCREPAIR))
(NC.LoadFileFromDirectories (QUOTE NCBROWSERCARD))
)
(* * Fixes bug in inspector whereby bad links were being deleted but only in the cache; change
 wasn't being written to notefile. Also makes slight change to the way NC.DeleteLink checks for
 validity of source and destination cards. Also fixes NC.DeletedLinkGetFn to skip carriage 
return if any. This stems from a bug in the way imageobj's are read and written and was causing
 problems when deleted link icons lived in a browser. Changed browser to better handle deleted 
link icon graphnodes.)

(* * Change to NCLINKS)

(DEFINEQ

(NC.DelReferencesToCard
  (LAMBDA (SourceCard LinkOrDestinationCard Don'tCreateDeletedImageObjFlg)
                                                             (* rht: " 9-Jun-87 18:16")
                                                             (* The card specified by DestinationID is being 
							     deleted. Remove all references to it from the card 
							     specified by SourceCard)

          (* * kirk: 13Nov85: deleted use of DatabaseStream)



          (* * fgh 2/5/86 Added call to NC.ApplyFn)



          (* * kef 7/31/86: Added wrapping of write lock grabbing so that deactivating the card preserves the nesting of 
	  write lock ownership.)



          (* * kef 8/5/86: Added putting of Main Card data in ActiveP case. This is so that if subsequent other people bring 
	  up the card, they will see the fact that link card was deleted.)



          (* * kef 8/7/86: Now requires that the card is being edited rather than just Active to thwart direct write through 
	  to NoteFile.)



          (* * rht 8/11/86 Added ShrunkenFlg so that SourceCard is reshrunk afterwards if necessary.)



          (* * fgh 8/30/86 Changed APPLY* to NC.ApplyFn. Appears there might be trouble here since we don't appear to wait if
	  we can't get all the write permission locks. I am assuming for now that this is being taken care of at a higher 
	  level.)



          (* * rht 9/19/86: It was testing NC.BeingEditedP to decide whether had to obtain write permission, etc. I think 
	  NC.ActiveCardP is enough. NC.BeingEditedP is bogus anyway as it doesn't work on card's whose editors don't have 
	  processes like graph cards.)



          (* * rht 11/4/86: Now takes Don'tCreateDeletedImageObjFlg arg.)



          (* * rht 3/19/87: Undo Ken's server-related fix of 8/5/86, i.e. ripped out call to NC.PutMainCardData when card is 
	  active.)



          (* * rht 6/9/87: Now marks card dirty after calling DeleteLinksFn.)


    (LET ((ShrunkenFlg (NC.GetShrunkenWin SourceCard))
	  NoteCardType Substance)
         (COND
	   ((NC.ActiveCardP SourceCard)
	     (SETQ NoteCardType (NC.RetrieveType SourceCard))
	     (SETQ Substance (NC.FetchSubstance SourceCard))
	     (NC.ApplyFn DeleteLinksFn SourceCard LinkOrDestinationCard Don'tCreateDeletedImageObjFlg)
	     (NC.MarkCardDirty SourceCard))
	   (T (WITH.MONITOR (NC.FetchMonitor (fetch (Card NoteFile) of SourceCard))
			    (if (NC.ValidCardP (NC.GetNoteCard SourceCard))
				then (RESETLST (RESETSAVE (for CardPart
								   in (QUOTE (SUBSTANCE TOLINKS 
										    GLOBALTOLINKS 
											 PROPLIST))
								   do (NC.ApplyFn 
									  ObtainWritePermissionFn 
										    SourceCard 
										    CardPart))
								(BQUOTE (NC.DeactivateCard , 
										       SourceCard)))
						   (SETQ NoteCardType (NC.RetrieveType SourceCard)
						     )
						   (SETQ Substance (NC.FetchSubstance SourceCard))
						   (NC.ApplyFn DeleteLinksFn SourceCard 
							       LinkOrDestinationCard 
							       Don'tCreateDeletedImageObjFlg)
						   (NC.PutMainCardData SourceCard))))))
         (NC.DelReferencesToCardFromGlobalList SourceCard LinkOrDestinationCard)
         (AND ShrunkenFlg (SHRINKW (NC.FetchWindow SourceCard))))))

(NC.DeleteLink
  (LAMBDA (Link NoOrphanHookFlg Don'tDelLinkIconFlg)         (* rht: " 9-Jun-87 18:27")

          (* * Delete a link with the option of not putting an orphan hook in case of last filing link.
	  Also option of not deleting link icon from the source card's substance.)



          (* * fgh 5/2/86 Included calls to NC.DelReferencesToCardFromShowLinks in order to clean up ShowLinks windows when 
	  links are deleted.)



          (* * kef 7/17/86: Added the requirement that the write permissions be obtained for the TOLINKS of the Source Card 
	  and the FROMLINKS of the Destination Card.)



          (* * kef 7/22/86: Puts the links for the Destination Card now right away while we are still holding onto the write 
	  lock for the FROMLINKS.)



          (* * kef 7/30/86: Modified to check for Client's concept of whether he owns the write lock or not, thus deciding 
	  whether or not to setup the release of the write lock afterwards.)



          (* * fgh 8/30/86 Adpated to use NC.IfCardPartNotBusy. Note use of ERROR!. Unfortunately, it appears that the only 
	  way to keep TEDIT from deleting the Link's Image Object is to bail out but good. The control structure here works 
	  because NC.IfCardPartNotBusy returns NIL if the CardPart is busy. The Ts at the end as the last SExpr in each call 
	  to NC.IfCardPartNotBusy insure that NC.IfCardPartNotBusy returns non-NIL otherwise.)



          (* * rht 9/29/86: Removed the call to NC.PutFromLinks. Looks to me like it'll get called anyway by NC.DelFromLink 
	  if necessary.)



          (* * rht 10/6/86: Delete crossfilelink cards when their links are deleted.)



          (* * rht 11/4/86: Now takes Don'tCreateDeletedImageObjFlg arg.)



          (* * rht 11/13/86: Undid my change of 11/4/86.)



          (* * rg 3/11/87 changed call of NC.DeleteNoteCard to NC.DeleteNoteCardInternal)



          (* * rht 3/13/87: Broke out code into the NC.DeleteFromLink and NC.DeleteToLink functions.)



          (* * rht 5/26/87: Changed to match reduced functionality of NC.ValidLinkP, now checks that DestinationCard and 
	  SourceCard are valid cards.)



          (* * rht 6/9/87: Slight modification of previous fix; moved check for valid source and destination card to be 
	  around the relevant calls to NC.DeleteFromLink and NC.DeleteToLink.)


    (AND (NC.ValidLinkP Link)
	   (LET ((SourceCard (fetch (Link SourceCard) of Link))
		 (DestinationCard (fetch (Link DestinationCard) of Link)))
	        (WITH.MONITOR (NC.FetchMonitor (fetch (Card NoteFile) of SourceCard))
			      (OR (NC.IfCardPartNotBusy DestinationCard (QUOTE FROMLINKS)
							  (OR (NC.IfCardPartNotBusy
								  DestinationCard
								  (QUOTE TOLINKS)
								  (AND (NC.ValidCardP 
										  DestinationCard)
									 (NC.DeleteFromLink Link 
										  NoOrphanHookFlg))
								  (AND (NC.ValidCardP SourceCard)
									 (NC.DeleteToLink Link 
									      Don'tDelLinkIconFlg))
								  (replace (Link UID) of Link
								     with -1)
								  T)
								(ERROR!))
							  T)
				    (ERROR!)))))))

(NC.DeletedLinkGetFn
  (LAMBDA (InputStream TextStream)                           (* rht: "10-Jun-87 14:56")

          (* * rht 6/10/87: Now skips carriage return if any.)


    (if (EQ (\PEEKBIN InputStream)
		13)
	then (BIN InputStream))
    (BIN InputStream)
    NC.DeletedLinkImageObject))
)
(* * Change to NCREPAIR)

(DEFINEQ

(NC.ScavengeDatabaseFile
  (LAMBDA (NoteFileOrFileName BadLinkLabelsFlg ListOfBoxesToReconstruct 
			      ListOfCardsNeedingGlobalLinksReconstructed InterestedWindow)
                                                             (* rht: " 9-Jun-87 18:19")

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



          (* * rht 6/9/87: Now calls NC.PutMainCardData if did a delete of bad link icons.)


    (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)))
                                                             (* If we deleted some bad link icons above, then need 
							     to write down substance.)
				       (if (NC.CardDirtyP Card)
					   then (NC.PutMainCardData Card))
				       (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)))))))
)
(* * Change to NCBROWSERCARD)

(DEFINEQ

(NC.DelReferencesToCardFromBrowser
  (LAMBDA (SourceCard LinkOrDestinationCard Don'tCreateDeletedImageObjFlg)
                                                             (* rht: "10-Jun-87 15:37")

          (* * Delete from the browser specified by SourceCard all link icon nodes whose DESTINATIONID is eq to 
	  DestinationID. This just checks the case of the SourceCard being a browser root and then passes off to GRAPHCARD's 
	  DelReferencesFn.)



          (* * rht 4/30/86: No longer passes control up to Super's DeleteLinksFn. Work is now done here.)



          (* * rht 9/2/86: Now sets dirtyflg of substance if change was made.)



          (* * rht 11/4/86: Now takes Don'tCreateDeletedImageObjFlg arg.)



          (* * rht 6/10/87: Now cleans up better in case when we're replacing node by deleted link icon.)


    (DECLARE (GLOBALVARS NC.UseDeletedLinkIconIndicatorsFlg NC.DeletedLinkImageObject))
    (LET ((LinkFlg (type? Link LinkOrDestinationCard))
	  (ImageBox (NC.DeletedLinkImageBoxFn NC.DeletedLinkImageObject))
	  LinkIcon Graph DestinationCard BrowserRoots RootCardToDelete UID)
         (if LinkFlg
	     then (OR (NC.CardP SourceCard)
			  (SETQ SourceCard (fetch (Link SourceCard) of LinkOrDestinationCard)))
		    (SETQ DestinationCard (fetch (Link DestinationCard) of 
									    LinkOrDestinationCard))
	   else (SETQ DestinationCard LinkOrDestinationCard))
         (if (SETQ RootCardToDelete (for RootCard in (SETQ BrowserRoots (
								 NC.FetchBrowserRoots SourceCard))
					   eachtime (BLOCK) do (if (NC.SameCardP 
										  DestinationCard 
											 RootCard)
									 then (RETURN RootCard))))
	     then (NC.SetBrowserRoots SourceCard (DREMOVE RootCardToDelete BrowserRoots)))
         (SETQ Graph (NC.FetchSubstance SourceCard))
         (for GraphNode in (fetch (GRAPH GRAPHNODES) of Graph)
	    when (AND (NC.LinkIconImageObjP (SETQ LinkIcon (fetch (GRAPHNODE NODELABEL)
								      of GraphNode)))
			  (if LinkFlg
			      then (NC.SameLinkP LinkOrDestinationCard (NC.FetchLinkFromLinkIcon
						       LinkIcon))
			    else (NC.SameCardP (fetch (Link DestinationCard)
						      of (NC.FetchLinkFromLinkIcon LinkIcon))
						   DestinationCard)))
	    do (if (AND NC.UseDeletedLinkIconIndicatorsFlg (NOT Don'tCreateDeletedImageObjFlg)
			      )
		     then (replace (GRAPHNODE NODELABEL) of GraphNode with 
									NC.DeletedLinkImageObject)
			    (replace (GRAPHNODE NODEWIDTH) of GraphNode
			       with (fetch (IMAGEBOX XSIZE) of ImageBox))
			    (replace (GRAPHNODE NODEHEIGHT) of GraphNode
			       with (fetch (IMAGEBOX YSIZE) of ImageBox))
			    (NC.RemoveBrowserNodeHashArrayEntry SourceCard DestinationCard)
			    (if (type? UID (SETQ UID (fetch (GRAPHNODE NODEID) of GraphNode)
					     ))
				then (NC.UIDSetPropList UID NIL))
			    (NC.SetSubstanceDirtyFlg SourceCard T)
		   else (NC.BrowserRemoveNode Graph (NC.FetchWindow SourceCard)
						  NIL GraphNode T)))
         (if (AND (NC.ActiveCardP SourceCard)
		      (NC.FetchWindow SourceCard))
	     then (REDISPLAYGRAPH (NC.FetchWindow SourceCard))))))

)
(PUTPROPS RHTPATCH277 COPYRIGHT ("Xerox Corporation" 1987))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (2052 9133 (NC.DelReferencesToCard 2062 . 5505) (NC.DeleteLink 5507 . 8799) (
NC.DeletedLinkGetFn 8801 . 9131)) (9165 25625 (NC.ScavengeDatabaseFile 9175 . 25623)) (25662 29176 (
NC.DelReferencesToCardFromBrowser 25672 . 29173)))))
STOP