(FILECREATED " 8-Jun-87 16:43:11" {QV}<NOTECARDS>1.3K>NEXT>NCOBSOLETE.;2 59072  

      changes to:  (VARS NCOBSOLETECOMS)

      previous date: "10-Dec-86 14:05:42" {QV}<NOTECARDS>1.3K>NEXT>NCOBSOLETE.;1)


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

(PRETTYCOMPRINT NCOBSOLETECOMS)

(RPAQQ NCOBSOLETECOMS ((FNS DRAWBOX NC.AddLinkToTextCard NC.AddLinksToTextCard 
			      NC.AskMoveOrCopyNoteCards NC.AssignSources NC.BitMapFromImageObject 
			      NC.BrowserDeleteCard NC.CachedInsertLinkInOrdering 
			      NC.CardTypeFieldInheritedP NC.CheckForNeededTruncation 
			      NC.CheckLinkRecordFormat NC.CleanupIndexEntries NC.CloseCards 
			      NC.CollectAndCheckLinks NC.CollectCards NC.ComputeMenuPosition 
			      NC.CopyCrossFileLinkCard NC.DeleteCards NC.DeleteNoteFile 
			      NC.DeleteSource NC.DetermineFileBoxes NC.EditFileBox NC.FileNoteCard 
			      NC.FlattenLinkFields NC.FloppyArchive NC.GetNoteFileHeader 
			      NC.GetNoteFileVersion NC.GetTypeIcon NC.GetUIDFromIndexNum 
			      NC.GraphEdgesInconsistentP NC.GrapherBasedP NC.InsertLinkInOrdering 
			      NC.InsertLinksInText NC.ListDatabaseFiles NC.MapRegistry 
			      NC.MarkIndexEntryFree NC.MoveTTYWindow NC.NotBrowserHookP 
			      NC.NoteCardsGraphP NC.NoteFileTitleMiddleButtonFn NC.NumberFromID 
			      NC.OwnWriteLockP NC.PushCopyLinkIcon NC.PutIndexEntry 
			      NC.PutNoteFileVersion NC.ReadIndexEntry NC.ReorderVirtualGraphNodes 
			      NC.SameCardIDP NC.SetIndexLoc NC.SetInitialPropList 
			      NC.SetLinkInLinkIcon NC.SetWriteLock NC.SketchBasedP NC.SkipWhiteSpace 
			      NC.StoreNoteFile NC.UnSetWriteLock NC.WriteMainCardData NC.\TEDIT.LOOKS 
			      NC.\TEDIT.QUIT NCP.AddTitleBarMenuItems QUEUE.CREATE QUEUE.DEQUEUE 
			      QUEUE.ENQUEUE NC.InspectorTitleCommandFn)))
(DEFINEQ

(DRAWBOX
  [LAMBDA (LEFT BOTTOM WIDTH HEIGHT LINEWIDTH STREAM)        (* fgh: "24-Oct-84 12:57")
    (DRAWLINE LEFT BOTTOM (IPLUS LEFT WIDTH)
		BOTTOM LINEWIDTH NIL STREAM)
    (DRAWLINE (IPLUS LEFT WIDTH)
		BOTTOM
		(IPLUS LEFT WIDTH)
		(IPLUS BOTTOM HEIGHT)
		LINEWIDTH NIL STREAM)
    (DRAWLINE (IPLUS LEFT WIDTH)
		(IPLUS BOTTOM HEIGHT)
		LEFT
		(IPLUS BOTTOM HEIGHT)
		LINEWIDTH NIL STREAM)
    (DRAWLINE LEFT (IPLUS BOTTOM HEIGHT)
		LEFT BOTTOM LINEWIDTH NIL STREAM])

(NC.AddLinkToTextCard
  [LAMBDA (TextStream)                                       (* fgh: "28-Sep-84 18:54")
                                                             (* Called from a TEXT TEdit window to add a new link 
							     to the text.)
    (PROG ((Label (NC.AskLinkLabel (WINDOW.FROM.TEDIT.THING TextStream)
				       NIL NIL T T)))
	    (AND Label (RETURN (NC.InsertLinkInText TextStream Label NIL NIL NIL])

(NC.AddLinksToTextCard
  [LAMBDA (TextStream)                                       (* rht: "21-Nov-84 15:20")

          (* * Called from a TEXT TEdit window to add multiple links to the text.)


    (PROG ((Label (NC.AskLinkLabel (WINDOW.FROM.TEDIT.THING TextStream)
				       NIL NIL T T)))
	    (AND Label (RETURN (NC.InsertLinksInText TextStream Label])

(NC.AskMoveOrCopyNoteCards
  [LAMBDA (Msg Prompt FirstTry ClearFirstFlg MainWindow DontCloseAtEndFlg DontClearAtEndFlg)
                                                             (* Randy.Gobbel "18-Nov-86 15:32")

          (* * Get a Copy Move or Cancel response from the user via keyboard or mouse. Return NIL for Cancel)



          (* * rg 11/18/86: Added declaration for Answer)


    (LET (Menu MenuWindow PromptWin Answer)

          (* * Determine and open the prompt window if necessary)


         (COND
	   ((NOT (WINDOWP MainWindow))
	     (SETQ PromptWin PROMPTWINDOW))
	   ((NC.CoerceToCard MainWindow)
	     (SETQ PromptWin (GETPROMPTWINDOW MainWindow 5 (FONTCREATE (QUOTE HELVETICA)
									     10)))
	     (NC.MoveWindowOntoScreen MainWindow))
	   (T (SETQ PromptWin MainWindow)))

          (* * Attach a move/copy/cancel menu to the prompt window)


         (SETQ MenuWindow (ATTACHMENU (SETQ Menu (create
					      MENU
					      ITEMS ← (QUOTE (Cancel Move Copy))
					      WHENSELECTEDFN ← [FUNCTION (LAMBDA (Item Menu Button)
						  (TTY.PROCESS (WINDOWPROP (MAINWINDOW
										 (WFROMMENU Menu))
									       (QUOTE PROCESS)))
						  (BKSYSBUF (CONCAT Item (CHARACTER 13]
					      MENUFONT ← (FONTCREATE (QUOTE HELVETICA)
								       14
								       (QUOTE BOLD))
					      MENUBORDERSIZE ← 1
					      ITEMHEIGHT ← 20
					      ITEMWIDTH ← 65))
					  PromptWin
					  (COND
					    ((EQ PromptWin PROMPTWINDOW)
					      (QUOTE BOTTOM))
					    (T (QUOTE TOP)))
					  (QUOTE LEFT)))

          (* * print msg in prompt window and wait for user repsonse)


         (SETQ Answer (MKATOM (NC.AskUser Msg Prompt FirstTry ClearFirstFlg MainWindow T 
						DontClearAtEndFlg T)))
         (DELETEMENU Menu T)
         (DETACHWINDOW MenuWindow)
         (if (OR DontCloseAtEndFlg (EQ PromptWin PROMPTWINDOW))
	   else (CLOSEW PromptWin))
         (COND
	   ((FMEMB Answer (QUOTE (c C Copy copy COPY)))
	     (QUOTE Copy))
	   ((FMEMB Answer (QUOTE (m M Move move MOVE)))
	     (QUOTE Move))
	   (T NIL])

(NC.AssignSources
  [LAMBDA (WindowOrTextStream)                               (* Randy.Gobbel " 7-Nov-86 16:47")
                                                             (* Called from title bar menus.
							     Assign a new source link to this card.
							     Destination to be specified by the user.)

          (* * fgh 11/11/85: Updated to handle Card object. Also made NoSource be a card property.)


    (LET (Card Sources (Window (WINDOW.FROM.TEDIT.THING WindowOrTextStream)))
         (SETQ Card (NC.CoerceToCard Window))
         (SETQ Sources (NC.DetermineSources Card NIL))
         (COND
	   ((LISTP Sources)
	     (for Source in Sources do (NC.AddSourceLink Card Source))
	     (NC.SetLinksDirtyFlg Card T))
	   ((EQ Sources (QUOTE NoSource))
	     (NCP.CardAddProp Card (QUOTE NoSource)
				T)))
         (NC.ClearMsg Window T)
     NIL])

(NC.BitMapFromImageObject
  [LAMBDA (ImageObject)                                      (* fgh: " 9-Apr-84 22:40")
    (PROG (DisplayStream ImageBox BitMap)
	    (SETQ DisplayStream (DSPCREATE (BITMAPCREATE 1 1 1)))
	    (SETQ ImageBox (APPLY* (IMAGEOBJPROP ImageObject (QUOTE IMAGEBOXFN))
				       ImageObject DisplayStream))
	    [SETQ BitMap (BITMAPCREATE (fetch (IMAGEBOX XSIZE) of ImageBox)
					   (IPLUS (fetch (IMAGEBOX YSIZE) of ImageBox)
						    (fetch (IMAGEBOX YDESC) of ImageBox]
	    (DSPDESTINATION BitMap DisplayStream)
	    (DSPYPOSITION (fetch (IMAGEBOX YDESC) of ImageBox)
			    DisplayStream)
	    (APPLY* (IMAGEOBJPROP ImageObject (QUOTE DISPLAYFN))
		      ImageObject DisplayStream)
	    (RETURN BitMap])

(NC.BrowserDeleteCard
  [LAMBDA (Node Graph Window)                                (* rht: " 6-Jul-86 17:28")

          (* * Called by grapher when user deletes a node. Will try to delete the card behind the node as well.)



          (* * rht 11/17/85: updated to handle card and notefile object styles.)



          (* * rht 2/7/86: Changed to use NC.SetBrowserRoots instead of NC.PutProp.)


    (PROG ((GraphCard (NC.CoerceToCard Window))
	     Card GraphNodeID RootCards)
	    (SETQ Card (NC.CardFromBrowserNodeID (fetch (GRAPHNODE NODEID) of Node)))
	    (NC.MarkCardDirty GraphCard)                   (* Delete all record of links to and from this node on
							     prop lists.)
	    (NC.SmashGraphNodeIDProps (SETQ GraphNodeID (NC.CoerceToGraphNodeID Node)))
	    (for OtherNode in (fetch (GRAPH GRAPHNODES) of Graph) do (NC.GraphNodeIDRemProp
										 (
NC.CoerceToGraphNodeID OtherNode)
										 GraphNodeID))
                                                             (* Does user really want to delete the card behind 
							     this node?)
	    (COND
	      [(AND (NC.ValidCardP Card)
		      (NC.AskYesOrNo (CONCAT "Want to delete the " (NC.RetrieveTitle Card)
						 " card? ")
				       "--"
				       (QUOTE Yes)
				       T Window NIL NIL))
		(NC.DeleteNoteCards Card T)                (* Redisplay so that the deletedLinkIcon goes away.)
		(DISPLAYNODE Node (CONSTANT (create POSITION
							  XCOORD ← 0
							  YCOORD ← 0))
			       Window Graph)                 (* Remove from the root ids list.)
		(SETQ RootCards (NC.FetchBrowserRoots GraphCard))
		(if (for RootCard in RootCards eachtime (BLOCK) thereis (NC.SameCardP
										      Card RootCard))
		    then (NC.SetBrowserRoots GraphCard (for RootCard in RootCards
							    eachtime (BLOCK)
							    unless (NC.SameCardP Card RootCard)
							    collect RootCard]
	      (T (NC.PrintMsg Window NIL "Card not deleted."])

(NC.CachedInsertLinkInOrdering
  [LAMBDA (SourceCard DestinationCard LinkLabel DisplayMode NoSpacerFlg OrderingFn)
                                                             (* kirk: "15-Nov-85 11:56")
                                                             (* Insert a link to DestinationCard in SourceID.
							     Place to insert is dertermined alphabetically.)

          (* * rht 6/14/85: Fixed the CHLIM uses according to Intermezzo changes. Also took out some SEL setting that was 
	  useless. And changed TEDIT.SETSEL calls. Now uses OrderingFn arg so can do any sorts of orderings user wants.)



          (* * kirk: 14Nov85: abstracted from NC.InsertLinkInOrdering)


    (LET (Objects TextStream TextObject SEL InsertCharPtr (Spacer (CONCAT (CHARACTER 13)))
		  Link)
         (SETQ TextStream (NC.FetchSubstance SourceCard))
         (SETQ TextObject (TEXTOBJ TextStream))
         [COND
	   ((SETQ Objects (TEDIT.LIST.OF.OBJECTS TextObject (FUNCTION NC.LinkIconImageObjP)))
	     (for ObjectPair in Objects when [APPLY* OrderingFn DestinationCard
							     (fetch (Link DestinationCard)
								of (NC.FetchLinkFromLinkIcon
								       (CAR ObjectPair]
		do (TEDIT.SETSEL TextStream (CADR ObjectPair)
				     0
				     (QUOTE LEFT))
		     (RETURN NIL)
		finally (TEDIT.SETSEL TextStream (GETEOFPTR TextStream)
					  0
					  (QUOTE RIGHT]
         (SETQ SEL (fetch (TEXTOBJ SEL) of TextObject))
         (SETQ Link (NC.InsertLinkInText TextStream LinkLabel DestinationCard SourceCard 
					     DisplayMode))
         (COND
	   ((NULL NoSpacerFlg)
	     (TEDIT.INSERT TextStream Spacer)))
     Link])

(NC.CardTypeFieldInheritedP
  [LAMBDA (FieldName CardTypeRecord)                         (* kirk: "12-Jul-86 19:12")

          (* * kirk 12/6/86 returns T if the CardTypeRecord inherits FieldName)



          (* * kirk 12/6/86 first created)


    (RECORDACCESS (MKATOM (CONCAT FieldName (QUOTE InheritedFlg)))
		    CardTypeRecord])

(NC.CheckForNeededTruncation
  [LAMBDA (NoteFile Access InterestedWindow)                 (* rht: " 6-Jul-86 18:48")

          (* * See if there was a crash or aborted close last time. That is, has the notefile got junk beyond the last 
	  checkpoint EOFPTR? If so, ask if user wants to save the extra junk in a file. In any case, truncate at the old 
	  point. If the version number is less than 2, change to a version 2 file and write the the new checkpoint pointer.)



          (* * rht 9/20/85: Now allows user to enter inspector rather than truncating -
	  uses a pop up menu.)



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



          (* * rht 7/6/86: Now cancels out of open if user clicks outside of menu.)


    [OR InterestedWindow (SETQ InterestedWindow (WFROMMENU (fetch (NoteFile Menu)
								    of NoteFile]
    (WITH.MONITOR (NC.FetchMonitor NoteFile)
		  (PROG ((Stream (fetch (NoteFile Stream) of NoteFile))
			   (FullFileName (fetch (NoteFile FullFileName) of NoteFile))
			   (Version (fetch (NoteFile Version) of NoteFile))
			   LastChkptPtr EndPtr SaveFile SaveStream Ptr Menu InterestedWindowPos)
		          (COND
			    ((LESSP Version 2)             (* Pronounce this a version 2 file and write the new 
							     lastchkptr value.)
			      (NC.PutNoteFileVersion NoteFile 2)
			      (NC.PutCheckptPtr NoteFile (GETEOFPTR Stream))
			      (RETURN NIL)))
		          (SETQ LastChkptPtr (fetch (NoteFile CheckptPtr) of NoteFile))
		          (SETQ EndPtr (GETEOFPTR Stream))
		          (COND
			    ((LESSP LastChkptPtr EndPtr)
			      (NC.PrintMsg InterestedWindow T "Last " (IDIFFERENCE EndPtr 
										     LastChkptPtr)
					     " bytes of " FullFileName (CHARACTER 13)
					     
				       " were written since last checkpoint or successful close."
					     (CHARACTER 13))
			      [SETQ Menu (create MENU
						     ITEMS ← (QUOTE ((Cancel (QUOTE Abort)
									       
							   "Cancel this open notefile operation.")
									(Inspect% &% Repair
									  (QUOTE Inspect% &% Repair)
									  
		      "Run the Inspect&Repair facility to integrate extra work since checkpoint.")
									(Truncate% File (QUOTE
											  
										   Truncate% File)
											
	       "Truncate the file, either throwing away or saving changes since last checkpoint.")))
						     MENUOUTLINESIZE ← 2
						     MENUFONT ← (FONTCREATE (QUOTE HELVETICA)
									      12
									      (QUOTE BOLD]
			      (SELECTQ [MENU Menu (create POSITION
								XCOORD ← (fetch (POSITION XCOORD)
									    of (SETQ 
									      InterestedWindowPos
										   (WINDOWPOSITION
										     InterestedWindow)
										   ))
								YCOORD ← (DIFFERENCE
								  (fetch (POSITION YCOORD)
								     of InterestedWindowPos)
								  (fetch (MENU IMAGEHEIGHT)
								     of Menu]
					 (Cancel (RETURN (QUOTE ABORT)))
					 (Inspect% &% Repair (RETURN (QUOTE ABORTANDINSPECT)))
					 (NIL (RETURN (QUOTE ABORT)))
					 NIL)
			      [COND
				((NC.AskYesOrNo "Want to save info beyond checkpoint to a file? " 
						  "--"
						  "Yes" NIL InterestedWindow NIL T)
				  (COND
				    ([AND (SETQ SaveFile (NC.AskUser (CONCAT (CHARACTER
										       13)
										     
									 "File to save info in: ")
									   NIL NIL NIL 
									   InterestedWindow T))
					    (SETQ SaveStream (OPENSTREAM SaveFile (QUOTE OUTPUT)
									     NIL
									     (QUOTE ((TYPE BINARY]
				      (NC.PrintMsg InterestedWindow T "Saving extra info to " 
						     SaveFile " ...")
				      (COPYBYTES Stream SaveStream LastChkptPtr EndPtr)
				      (CLOSEF SaveStream)
				      (NC.PrintMsg InterestedWindow NIL "Done." (CHARACTER 13)))
				    (T (NC.PrintMsg InterestedWindow T "Can't open " SaveFile "."
						      (CHARACTER 13)
						      "Open aborted."
						      (CHARACTER 13))
				       (RETURN (QUOTE ABORT]
			      (COND
				[(NC.AskYesOrNo (CONCAT "Are you sure you want to truncate "
							    (CHARACTER 13)
							    FullFileName "? ")
						  "--" "No" T InterestedWindow NIL T)
				  (NC.PrintMsg InterestedWindow T "Truncating file " FullFileName 
						 " ...")
				  (CLOSEF Stream)
				  [COND
				    ((NOT (SETFILEINFO FullFileName (QUOTE LENGTH)
							   LastChkptPtr))
				      (NC.PrintMsg InterestedWindow NIL "Couldn't truncate " 
						     FullFileName "." (CHARACTER 13)
						     "Open aborted."
						     (CHARACTER 13))
				      (RETURN (QUOTE ABORT]
				  (NC.PrintMsg InterestedWindow T "Done." (CHARACTER 13))
				  (RETURN (OPENSTREAM FullFileName Access NIL
							  (QUOTE ((TYPE BINARY]
				(T (NC.PrintMsg InterestedWindow NIL (CHARACTER 13)
						  "Open aborted."
						  (CHARACTER 13))
				   (RETURN (QUOTE ABORT])

(NC.CheckLinkRecordFormat
  [LAMBDA (Links)                                            (* rht: "18-Jul-85 16:18")

          (* * Makes sure links are typedrecords and inserts NOTECARDLINK in car if not. Does it in place to save space)


    [for RestOfLinks on Links when (NEQ (CAAR RestOfLinks)
						(QUOTE NOTECARDLINK))
       do (RPLACA RestOfLinks (CONS (QUOTE NOTECARDLINK)
					  (CAR RestOfLinks]
    Links])

(NC.CleanupIndexEntries
  [LAMBDA (NoteFile)                                         (* rht: "14-Nov-85 12:34")

          (* * Take a pass through index, replacing any entries not ACTIVE, SPECIAL, or FREE, by FREE entries.
	  This uses the array to save time, so it better be up to date with the file.)



          (* * rht 11/12/85: Now uses new notefile and Card formats.)


    (NC.MapCards NoteFile (FUNCTION (LAMBDA (Card)
		     (if [NOT (FMEMB (NC.FetchStatus Card)
					   (QUOTE (ACTIVE SPECIAL FREE]
			 then (NC.MarkIndexEntryFree Card)
				(NC.PutIndexEntry Card])

(NC.CloseCards
  [LAMBDA (CardIds NoCheckFlg DontClearFlg InterestedWindow)
                                                             (* kirk: "24-Apr-86 12:32")
    (NC.CloseNoteCards CardIds NoCheckFlg DontClearFlg InterestedWindow])

(NC.CollectAndCheckLinks
  [LAMBDA (Card NoteFile ListOfValidCards)                   (* kirk: "17-Feb-86 23:46")

          (* Return the list of all of the NoteCardLinks in the substance of NoteCard ID. Check each link to make sure it is 
	  legal. If not legal delete it from the substance.)



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



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

                                                             (* Assumes that the Card is already an active 
							     NoteCard)
    (PROG (Links DirtyFlg ActualLink GlobalLinks LinkIcon LinksDirtyFlg)
                                                             (* Collect the links. Check the validity of each link 
							     and delete it if it is not a valid link.)
	    [COND
	      ((SETQ Links (NC.ApplyFn CollectLinksFn Card T))
		(SETQ DirtyFlg (CDR Links))
		(SETQ Links (CAR Links]

          (* * Process the GlobalLinks as well .... same for all substance types)


	    (SETQ Links (NCONC Links (for Link
					    in
					     (SETQ GlobalLinks
					       (for GlobalLink in (NC.FetchGlobalLinks Card)
						  eachtime (BLOCK)
						  when (COND
							   [(AND (LISTP ListOfValidCards)
								   (for ValidCard in 
										 ListOfValidCards
								      thereis
								       (NC.SameCardP
									 (fetch (Link 
										  DestinationCard)
									    of GlobalLink)
									 ValidCard]
							   ((NC.ValidLinkP GlobalLink))
							   (T (SETQ LinksDirtyFlg T)
							      NIL))
						  collect GlobalLink))
					    eachtime (BLOCK) collect Link)))
	    (NC.SetGlobalLinks Card GlobalLinks)

          (* * Update list of valid cards with good links returned from Collect references)


	    [AND (LISTP ListOfValidCards)
		   (NCONC ListOfValidCards (for Link in Links eachtime (BLOCK)
						collect (fetch (Link DestinationCard)
							     of Link]

          (* * Write out the card or links if it has been modified)


	    (AND DirtyFlg (NC.PutMainCardData Card))
	    (AND LinksDirtyFlg (NC.PutLinks Card))
	    (RETURN Links])

(NC.CollectCards
  [LAMBDA (RootCards TraversalSpec)                          (* kirk: "31-Jul-86 10:57")

          (* * converts from a simple traversal spec to FSM path to enumerate cards.)



          (* * kirk changed to use NCP.TransitiveClosure until path stuff is ready)



          (* * kirk 7/29/86 added backlinks)



          (* * (LET (node FSM) (SETQ node (create NCPathFSMNode Predicate ← (NC.MakePredFromTraversalSpec TraversalSpec))) 
	  (replace (NCPathFSMNode NextNodes) of node with (LIST NIL node)) (SETQ FSM (create NCPathFSM InitialState ← node 
	  CurrentState ← node)) (NCPath.GetCardPathListsFromPathCollection (NCPath.FSM.PathCollect FSM FromCard))))


    (NCP.ComputeTransitiveClosure RootCards (fetch (TRAVERSALSPECS LinkTypes) of TraversalSpec)
				    (fetch (TRAVERSALSPECS Depth) of TraversalSpec])

(NC.ComputeMenuPosition
  [LAMBDA (Menu Win)                                         (* rht: "14-Jul-85 22:52")

          (* * Compute the position to put Menu so it sits along upper right edge of Win.)


    (LET ((WinRegion (WINDOWREGION Win)))
         (create POSITION
		   XCOORD ← (PLUS (fetch (REGION LEFT) of WinRegion)
				    (fetch (REGION WIDTH) of WinRegion))
		   YCOORD ← (PLUS (fetch (REGION BOTTOM) of WinRegion)
				    (fetch (REGION HEIGHT) of WinRegion)
				    (MINUS (fetch (MENU IMAGEHEIGHT) of Menu])

(NC.CopyCrossFileLinkCard
  [LAMBDA (CrossFileLinkCard)                                (* rht: " 9-Nov-86 21:46")

          (* * Make a new crossfilelink card, just a copy of the given one.)


    (OR (NC.ActiveCardP CrossFileLinkCard)
	  (NC.GetNoteCard CrossFileLinkCard))
    (NC.MakeNoteCard (QUOTE CrossFileLink)
		       (fetch (Card NoteFile) of CrossFileLinkCard)
		       (NC.FetchTitle CrossFileLinkCard)
		       T
		       (create CrossFileLinkSubstance copying (NC.FetchSubstance 
										CrossFileLinkCard)
								  CrossFileLinkTwoWayFlg ← NIL])

(NC.DeleteCards
  [LAMBDA (CardIdentifiers NoCheckFlg DontClearFlg InterestedWindow)
                                                             (* kirk: "24-Apr-86 12:13")
    (NC.DeleteNoteCards CardIdentifiers T DontClearFlg InterestedWindow])

(NC.DeleteNoteFile
  [LAMBDA (NoteFile InterestedWindow Don'tConfirmFlg QuietFlg)
                                                             (* rht: "13-Jul-86 16:22")

          (* * rht 7/13/86: Added Don'tConfirmFlg and QuietFlg args.)


    (NC.DeleteDatabaseFile NoteFile InterestedWindow Don'tConfirmFlg QuietFlg])

(NC.DeleteSource
  [LAMBDA (WindowOrTextStream)                               (* pmi: " 5-Dec-86 11:26")
                                                             (* Called from title bar menus.
							     Deletes source/s/ for the card specified by 
							     WindowOrTextStream)

          (* * fgh 11/12/85: Updated to handle Card objects.)



          (* * pmi 12/5/86: Modified message to NC.SelectNoteCards to mention SHIFT-selection. Also added NC.SourceLinkLabel 
	  to GLOBALVARS statement.)


    (DECLARE (GLOBALVARS NC.DeleteSelectingMenu NC.SourceLinkLabel))
    (LET ((Window (WINDOW.FROM.TEDIT.THING WindowOrTextStream))
	  Card Sources EditWindow)
         (SETQ Card (NC.CoerceToCard Window))
         (SETQ Sources (for Link in (NC.FetchGlobalLinks Card)
			    when (EQUAL NC.SourceLinkLabel (fetch (Link Label) of Link))
			    collect Link))
         (COND
	   ((NULL Sources)
	     (NC.PrintMsg Window T "This card has no sources." (CHARACTER 13))
	     (SPAWN.MOUSE)
	     (DISMISS 2000)
	     (NC.ClearMsg Window T))
	   (T (SETQ EditWindow (NC.OpenPropListEditor Window (LIST (QUOTE Source% TO)
									 Sources)
							  "Sources" T T))
	      (until (WINDOWPROP EditWindow (QUOTE TEXTOBJ)) do (BLOCK))
	      (SETQ Sources (NC.SelectNoteCards NIL NIL NC.DeleteSelectingMenu Card NIL 
						    "Shift-select source(s) to be deleted."))
	      (NC.ClearMsg Window T)
	      (NC.ClosePropListEditor EditWindow (QUOTE NoSave))
	      (for ToBeDeletedLink in (NC.FetchGlobalLinks Card)
		 when (AND (EQ NC.SourceLinkLabel (fetch (Link Label) of ToBeDeletedLink))
			       (for SourceCard in Sources thereis (NC.SameCardP
									  (fetch (Link 
										  DestinationCard)
									     of ToBeDeletedLink)
									  SourceCard)))
		 do (NC.DelToLink ToBeDeletedLink)
		      (NC.DelFromLink ToBeDeletedLink)
		      (NC.SetGlobalLinks Card (for Link in (NC.FetchGlobalLinks Card)
						   when (for SourceCard in Sources
							     never (NC.SameCardP
								       (fetch (Link DestinationCard)
									  of ToBeDeletedLink)
								       SourceCard))
						   collect Link])

(NC.DetermineFileBoxes
  [LAMBDA (Card OptionalFilingFlg)                           (* pmi: " 5-Dec-86 11:25")

          (* Returns a list of contents cards for filing a card. The rule used for the choice is: First ask the user.
	  If the user returns NIL, then use the Orphan Note Card)



          (* * rht 8/1/84: Changed so that user can't file a card twice in the same box.)



          (* * fgh 11/13/85 Updated to handle Card object. Got rid of DatabaseStream.)



          (* * pmi 12/5/86: Modified message to NC.SelectNoteCards to mention SHIFT-selection. Also added GLOBALVARS 
	  statement.)


    (DECLARE (GLOBALVARS NC.FiledCardLinkLabel))
    (LET (NewParents (ParentCards (for Link in (NC.FetchFromLinks Card)
				     when (EQ (fetch (Link Label) of Link)
						  NC.FiledCardLinkLabel)
				     collect (fetch (Link SourceCard) of Link)))
		     (Window (NC.FetchWindow Card)))
         (COND
	   ((PROGN [SETQ NewParents (NC.SelectNoteCards NIL NIL (COND
								(ParentCards NC.SelectingParentsMenu)
								(T NC.SelectingContentsMenu))
							      Card NIL
							      (CONCAT 
					    "Please shift-select the Boxes to file this card in."
									(COND
									  (ParentCards "")
									  (T (CONCAT (CHARACTER
											 13)
										       
							   "NoBox files it in the ToBeFiled box."]
		     (for NewParentCard in NewParents unless (AND (FMEMB NewParentCard 
										   ParentCards)
									  (NC.PrintMsg
									    Window T (
									      NC.RetrieveTitle
									      Card)
									    " already filed in "
									    (NC.RetrieveTitle
									      NewParentCard)
									    (CHARACTER 13)))
			collect NewParentCard)))
	   ((AND (NOT OptionalFilingFlg)
		   (NOT ParentCards))
	     (NC.PrintMsg Window T "No Box has been specified." (CHARACTER 13)
			    "Filing this card in the ToBeFiled Box."
			    (CHARACTER 13))
	     (LIST (NC.ToBeFiledBox (fetch (Card NoteFile) of Card])

(NC.EditFileBox
  [LAMBDA (Card TextStream Region/Position)                  (* fgh: " 7-Jun-86 02:35")

          (* * Edit a file box. Just call super editfn with proper TEdit props props flg)


    (NC.ApplySupersFn EditFn Card TextStream Region/Position T])

(NC.FileNoteCard
  [LAMBDA (WindowOrTextStream)                               (* fgh: "13-Nov-85 20:03")
                                                             (* Called from title bar menus -
							     adds card containing TextStream to a Contents Card or 
							     Cards)

          (* * fgh 11/11/85: Updated to handle new Card object. Also changed NC.MakeContentsHooks to NC.MakeFilingLinks)


    (LET ((Card (NC.CoerceToCard WindowOrTextStream)))
         (NC.CheckTitle Card)
         (NC.MakeFilingLinks Card])

(NC.FlattenLinkFields
  [LAMBDA (Link)                                             (* fgh: "16-Nov-85 19:11")

          (* * Unbundle the datatypes for SOURCEID and DESTINATIONID in the NOTECARDLINK record.)


    (LET ((SourceCard (fetch (Link SourceCard) of Link))
	  (DestinationCard (fetch (Link DestinationCard) of Link)))
         (LIST (fetch (Link UID) of Link)
		 (fetch (Card UID) of SourceCard)
		 (fetch (NoteFile UID) of (fetch (Card NoteFile) of SourceCard))
		 (fetch (Card UID) of DestinationCard)
		 (fetch (NoteFile UID) of (fetch (Card NoteFile) of DestinationCard))
		 (fetch (Link AnchorMode) of Link)
		 (fetch (Link Label) of Link)
		 (fetch (Link DisplayMode) of Link])

(NC.FloppyArchive
  [LAMBDA (FileName FromFloppyFlg)                           (* fgh: "17-Nov-85 16:54")
                                                             (* Copy a database from a file to or from a floppy 
							     file for backup.)

          (* * rht 8/7/84: If restoring, don't give a suggested name for NC.DatabaseFileName and set 
	  NC.DatabaseFileNameSuggestion to the new file name before leaving)



          (* * fgh 11/17/85 Update to handle Multiple open NoteFiles.)


    (PROG (FromFile ToFile)
	    (AND (NULL (SETQ FileName (NC.DatabaseFileName (CONCAT 
								 "Name of NoteFile to be copied "
									     (COND
									       (FromFloppyFlg "from")
									       (T "to"))
									     " floppy:")
								   " -- " T FromFloppyFlg FileName)))
		   (RETURN NIL))
	    [COND
	      (FromFloppyFlg (SETQ FromFile (INFILEP (PACKFILENAME (QUOTE HOST)
									 (QUOTE {FLOPPY})
									 (QUOTE BODY)
									 FileName)))
			     (COND
			       ((NULL FromFile)
				 (NC.PrintMsg NIL T FileName " is not on the floppy." (CHARACTER
						  13)
						"Restore cancelled."
						(CHARACTER 13))
				 (RETURN)))
			     (SETQ ToFile (PACKFILENAME (QUOTE HOST)
							    (FILENAMEFIELD (DIRECTORYNAME T)
									     (QUOTE HOST))
							    (QUOTE DIRECTORY)
							    (FILENAMEFIELD (DIRECTORYNAME T)
									     (QUOTE DIRECTORY))
							    (QUOTE VERSION)
							    NIL
							    (QUOTE BODY)
							    FromFile)))
	      (T (SETQ FromFile (INFILEP FileName))
		 (COND
		   ((NULL FromFile)
		     (NC.PrintMsg NIL T FileName " does not exist." (CHARACTER 13)
				    "Backup cancelled."
				    (CHARACTER 13))
		     (RETURN)))
		 (SETQ ToFile (PACKFILENAME (QUOTE HOST)
						(QUOTE {FLOPPY})
						(QUOTE VERSION)
						NIL
						(QUOTE DIRECTORY)
						NIL
						(QUOTE BODY)
						FromFile]
	    (FLOPPY.MODE (QUOTE PILOT))
	    (NC.PrintMsg NIL T "Copying NoteFile " (COND
			     (FromFloppyFlg "from")
			     (T "to"))
			   " floppy.  Please wait ... "
			   (CHARACTER 13))
	    (COND
	      ((OPENP FromFile)
		(NC.PrintMsg NIL T FromFile " cannot be copied because it is open." (CHARACTER
				 13)
			       "Close it and try again."
			       (CHARACTER 13))
		(RETURN NIL)))
	    (SETQ ToFile (COPYFILE FromFile ToFile))
	    (COND
	      (FromFloppyFlg (NC.PrintMsg NIL T "Restore of " FromFile " completed." (CHARACTER
					      13)
					    "NoteFile is now on " ToFile "." (CHARACTER 13))
			     (SETQ NC.DatabaseFileNameSuggestion (PACKFILENAME (QUOTE VERSION)
										   NIL
										   (QUOTE BODY)
										   ToFile)))
	      (T (NC.PrintMsg NIL T "Backup of " FromFile " completed." (CHARACTER 13)
				"Copy of NoteFile is now on " ToFile "." (CHARACTER 13])

(NC.GetNoteFileHeader
  [LAMBDA (NoteFile)                                         (* rht: "15-Nov-85 17:14")

          (* * Fill in the NoteFile object with stuff from the file.)


    (LET ((Stream (fetch (NoteFile Stream) of NoteFile))
	  (FullFileName (fetch (NoteFile FullFileName) of NoteFile)))
                                                             (* Recover the 30 information bytes for the notefile.)
         (SETFILEPTR Stream 0)                             (* 3 bytes for next card ID)
         (replace (NoteFile NextIndexNum) of NoteFile with (NC.ReadPtr Stream 3))
                                                             (* 3 bytes for index size)
         (replace (NoteFile HashArraySize) of NoteFile with (NC.ReadPtr Stream 3))
                                                             (* One dummy byte so that version number stays in 
							     favorite old place.)
         (NC.ReadPtr Stream 1)                               (* 1 byte for notecards version number)
         (replace (NoteFile Version) of NoteFile with (NC.ReadPtr Stream 1))
                                                             (* 3 bytes for next link ID)
         (replace (NoteFile NextLinkNum) of NoteFile with (NC.ReadPtr Stream 3))
                                                             (* 3 bytes for pointer to current checkpt ptr.)
         (replace (NoteFile CheckptPtr) of NoteFile with (NC.ReadPtr Stream 3))
                                                             (* 14 bytes for NoteFile UID.)
         (replace (NoteFile UID) of NoteFile with (NC.ReadUID NoteFile))
                                                             (* 2 bytes for future needs)
         (NC.ReadPtr Stream 2)
     NoteFile])

(NC.GetNoteFileVersion
  [LAMBDA (NoteFile)                                         (* rht: "15-Nov-85 00:32")

          (* * Read and return NoteFile's version number.)


    (WITH.MONITOR (NC.FetchMonitor NoteFile)
		  (LET ((Stream (fetch (NoteFile Stream) of NoteFile)))
		       (SETFILEPTR Stream 7)
		       (NC.ReadPtr Stream 1])

(NC.GetTypeIcon
  [LAMBDA (Type)                                             (* rht: " 1-Oct-85 14:08")

          (* * Return the bitmap icon for the given type.)



          (* * rht 10/1/85: Now checks first if there's a bitmap hung on the Type's prop list.)


    (OR (BITMAPP (GETPROP Type (QUOTE NCTYPEBITMAP)))
	  (SELECTQ Type
		     (FileBox NC.FileBoxIcon)
		     (Sketch NC.SketchCardIcon)
		     ((Graph Browser)
		       NC.GraphCardIcon)
		     NC.TextCardIcon])

(NC.GetUIDFromIndexNum
  [LAMBDA (IndexNum NoteFile)                                (* rht: "15-Nov-85 18:36")

          (* * Go out to the notefile and find the UID for the card at IndexNum on the index.)


    (LET ((Stream (fetch (NoteFile Stream) of NoteFile)))
         (WITH.MONITOR (NC.FetchMonitor NoteFile)
		       (SETFILEPTR Stream (NC.NoteFileLocFromIndexNum IndexNum))
		       (NC.ReadStatus Stream)
		       (NC.ReadUID NoteFile])

(NC.GraphEdgesInconsistentP
  [LAMBDA (Graph QuietFlg)                                   (* rht: "28-Apr-85 21:51")

          (* * Returns NIL if FROMNODES of every node agree in number with sum of everybody's TONODES to that node.
	  Otherwise, return list of inconsistent nodes.)


    (PROG ((GraphNodes (fetch (GRAPH GRAPHNODES) of Graph))
	     NumFromNodes NumToNodes)
	    (RETURN (for Node in GraphNodes bind NodeID
			 when
			  [PROG2 (SETQ NodeID (fetch (GRAPHNODE NODEID) of Node))
				   [NOT (EQP (SETQ NumFromNodes (LENGTH (fetch
										  (GRAPHNODE 
											FROMNODES)
										   of Node)))
						 (SETQ NumToNodes
						   (for OtherNode in GraphNodes
						      sum (for ToNode in (fetch (GRAPHNODE
											  TONODES)
										  of OtherNode)
							       when
								(EQ NodeID
								      (if (EQ (CAR ToNode)
										  LINKPARAMS)
									  then (CADR ToNode)
									else ToNode))
							       count ToNode]
				   (OR QuietFlg (PRINT (CONCAT NodeID ": " NumFromNodes 
								     " From nodes, "
								     NumToNodes " To nodes."]
			 collect Node])

(NC.GrapherBasedP
  [LAMBDA (CardOrTypeName)                                   (* fgh: "17-Nov-85 21:06")

          (* * Returns T if NoteCardType is a note card type that is based on Grapher or else an ID of such a note card.
	  NIL otherise.)


    (LET [(TypeName (COND
		      ((NC.CardP CardOrTypeName)
			(NC.RetrieveType CardOrTypeName))
		      (T CardOrTypeName]
         (NC.IsSubTypeOfP TypeName (QUOTE Graph])

(NC.InsertLinkInOrdering
  [LAMBDA (SourceCard DestinationCard LinkLabel DisplayMode NoSpacerFlg OrderingFn)
                                                             (* fgh: " 1-Sep-86 13:23")
                                                             (* Insert a link to DestinationCard in SourceID.
							     Place to insert is dertermined alphabetically.)

          (* * rht 6/14/85: Fixed the CHLIM uses according to Intermezzo changes. Also took out some SEL setting that was 
	  useless. And changed TEDIT.SETSEL calls. Now uses OrderingFn arg so can do any sorts of orderings user wants.)



          (* * kirk: 14Nov85: deleted use of of DatabaseStream and created Cached version)



          (* * fgh 5/16/86 Replaced spuriois reference to Orphans card and replaced with correct reference to SourceCard.)



          (* * kef 7/28/86: Added call to obtain write locks on SUBSTANCE and all links in the case when the card is not 
	  NC.ActiveCardP.)



          (* * kef 7/31/86: Added "balancing" of write lock ownership with NC.DeactivateCard.)



          (* * kef 8/7/86: Now cached changes only occur if the card is currently being edited.)



          (* * fgh 8/30/86 Adapted to NC.IfMultipleCardPartsNotBusy.)



          (* * fgh 9/1/86 Rescinded kef's change of 8/7/86. Cached but not visible cards may be dirty and therefor should not
	  be reread from the NF.)


    (if (NC.ActiveCardP SourceCard)
	then (NC.IfMultipleCardPartsNotBusy SourceCard (SUBSTANCE TOLINKS FROMLINKS GLOBALTOLINKS)
					      (NC.CachedInsertLinkInOrdering SourceCard 
									       DestinationCard 
									       LinkLabel DisplayMode 
									       NoSpacerFlg OrderingFn)
					      )
      else (WITH.MONITOR (NC.FetchMonitor (fetch (Card NoteFile) of SourceCard))
			   (NC.IfMultipleCardPartsNotBusy
			     SourceCard
			     (SUBSTANCE TOLINKS FROMLINKS GLOBALTOLINKS)
			     (if (NC.CardP (NC.GetNoteCard SourceCard))
				 then 

          (* * This next set of obtain write locks is only to make sure that we come out even when NC.DeactivateCard releases
	  the write locks. Note that the SourceCard will be deactivated upon exit of the RESETLST, as set up by the 
	  RESETSAVE.)


					(RESETSAVE (for CardPart
							in (QUOTE (SUBSTANCE TOLINKS 
										 GLOBALTOLINKS 
										 PROPLIST))
							do (APPLY* (fetch (Card 
									  ObtainWritePermissionFn)
									  of SourceCard)
								       SourceCard CardPart))
						     (BQUOTE (NC.DeactivateCard , SourceCard)))
					(NC.CachedInsertLinkInOrdering SourceCard DestinationCard 
									 LinkLabel DisplayMode 
									 NoSpacerFlg OrderingFn)
					(NC.PutMainCardData SourceCard)
					(NC.PutLinks SourceCard])

(NC.InsertLinksInText
  [LAMBDA (TextStream LinkLabel)                             (* pmi: " 5-Dec-86 10:13")

          (* * Add several links to the text all with the same link label.)



          (* * pmi 12/5/86: Modified message to NC.SelectNoteCards to mention SHIFT-selection.)


    (PROG (Window SourceCard DestinationCards)
	    [SETQ SourceCard (NC.CoerceToCard (SETQ Window (WINDOW.FROM.TEDIT.THING 
										       TextStream]
	    (SETQ DestinationCards (NC.SelectNoteCards NIL [FUNCTION (LAMBDA (Card)
							       (COND
								 ((NOT (NC.SameCardP Card 
										       SourceCard))
								   T)
								 (T (NC.PrintMsg (NC.FetchWindow
										     SourceCard)
										   T 
							    "A Card/Box cannot point to itself. "
										   (CHARACTER
										     13)
										   
									     "Selection ignored."
										   (CHARACTER
										     13))
								    NIL]
							   NC.SelectingMultipleCardsMenu SourceCard 
							   NIL 
				       "Please shift-select the Cards or Boxes to be pointed to."))
	    (NC.ClearMsg Window T)
	    (for DestinationCard in DestinationCards do (NC.InsertLinkInText TextStream 
										     LinkLabel 
										  DestinationCard 
										     SourceCard NIL])

(NC.ListDatabaseFiles
  [LAMBDA NIL                                                (* rht: "23-May-85 13:21")
                                                             (* Do a DIR on all of the NoteFiles on the current 
							     connected directory.)

          (* * rht 5/22/85: Now prompts user with search pattern based on current connected directory.)


    (PROG (Files SearchPattern)
	    (RESETLST (RESETSAVE (TTYDISPLAYSTREAM PROMPTWINDOW))
			(RESETSAVE NIL (LIST (QUOTE WINDOWPROP)
						 PROMPTWINDOW
						 (QUOTE PAGEFULLFN)
						 (WINDOWPROP PROMPTWINDOW (QUOTE PAGEFULLFN)
							       NIL)))
			(GIVE.TTY.PROCESS PROMPTWINDOW)
			(SETQ SearchPattern (NC.AskUser "Search pattern: " NIL
							    (CONCAT (DIRECTORYNAME T)
								      "*.NoteFile")
							    T NIL))
			(CLEARBUF T)
			(NC.PrintMsg NIL T "Searching ...")
			(if (AND SearchPattern (SETQ Files (FILDIR SearchPattern)))
			    then (NC.ClearMsg NIL)
				   (for File in Files do (printout PROMPTWINDOW File T))
			  else (NC.PrintMsg NIL T "There are no files matching the pattern: " 
						SearchPattern])

(NC.MapRegistry
  [LAMBDA (RegistryCard Function CollectResultPredicate)     (* rht: "26-Feb-86 15:08")

          (* * Map over the entries in RegistryCard's hash array applying function to the Name and UID for each entry.
	  This code is basically stolen from NC.MapCards. Note that RegistryCard must be active when this is called.)


    (LET (CollectionList)
         [COND
	   [CollectResultPredicate (MAPHASH (NC.FetchSubstance RegistryCard)
					      (FUNCTION (LAMBDA (Value Key)
						  (BLOCK)
						  (if (APPLY* CollectResultPredicate Value Key)
						      then (push CollectionList
								     (APPLY* Function Value Key))
						    else (APPLY* Function Value Key]
	   (T (MAPHASH (NC.FetchSubstance RegistryCard)
			 (FUNCTION (LAMBDA (Value Key)
			     (BLOCK)
			     (APPLY* Function Value Key]
     CollectionList])

(NC.MarkIndexEntryFree
  [LAMBDA (Card)                                             (* rht: "14-Nov-85 18:24")

          (* * rht 1/30/85: Now writes to index array rather than to file.)



          (* * rht 11/12/85: Now handles new Card formats.)


    (replace (Card Status) of Card with (QUOTE FREE))
    (replace (Card MainLoc) of Card with -1)
    (replace (Card LinksLoc) of Card with -1)
    (replace (Card TitleLoc) of Card with -1)
    (replace (Card PropListLoc) of Card with -1)
    (replace (Card IndexDirtyFlg) of Card with T])

(NC.MoveTTYWindow
  [LAMBDA (OnOrOff)                                          (* fgh: " 9-Apr-84 19:11")
    (AND (NEQ (TTYDISPLAYSTREAM)
		  PROMPTWINDOW)
	   (COND
	     ((EQ OnOrOff (QUOTE ON))
	       (MOVEW (WFROMDS (TTYDISPLAYSTREAM))
			100 100)
	       (QUOTE OFF))
	     (T (MOVEW (WFROMDS (TTYDISPLAYSTREAM))
			 1000 2000)
		(QUOTE ON])

(NC.NotBrowserHookP
  [LAMBDA (Link)                                             (* rht: "17-Nov-85 21:00")
    (NEQ (fetch (Link Label) of Link)
	   NC.BrowserContentsLinkLabel])

(NC.NoteCardsGraphP
  [LAMBDA (Graph)                                            (* rht: "22-Aug-85 21:01")

          (* * Return non-nil if Graph was created by notecards. Now checks the MoveNodeFn. Is there a better way?)


    (EQ (fetch (GRAPH GRAPH.MOVENODEFN) of Graph)
	  (QUOTE NC.GraphMoveNodeFn])

(NC.NoteFileTitleMiddleButtonFn
  [LAMBDA (NoteFile)                                         (* kirk: "27-Jun-86 21:39")

          (* * kirk first created)


    (LET ((NoteFileMenu (fetch (NoteFile Menu) of NoteFile))
	  NoteFileMenuWindow Menu)
         (SPAWN.MOUSE)
         (SETQ NoteFileMenuWindow (WFROMMENU NoteFileMenu))
         [OR (SETQ Menu (WINDOWPROP NoteFileMenuWindow (QUOTE NoteFileFullName)))
	       (WINDOWPROP NoteFileMenuWindow (QUOTE NoteFileFullName)
			     (SETQ Menu (create MENU
						    CENTERFLG ← NIL
						    TITLE ← (fetch (NoteFile FullFileName)
							       of NoteFile)
						    MENUTITLEFONT ← NC.MenuFont]
         (MENU Menu])

(NC.NumberFromID
  [LAMBDA (NoteCardID)                                       (* rht: "29-Oct-85 15:38")

          (* * Peel off the "NC" prefix from a notecard ID and return the integer.)



          (* * rht 10/29/85: Now accepts numeric ID arg.)


    (OR (FIXP NoteCardID)
	  (SUBATOM NoteCardID 3])

(NC.OwnWriteLockP
  [LAMBDA (Card CardPart)                                    (* Feuerman "30-Jul-86 15:41")

          (* * Returns T if the CLIENT thinks that he owns the writelock for the given card part. NOTE THIS SAYS NOTHING 
	  ABOUT WHAT THE SERVER THINKS!!)


    (PROG [(OldValue (NC.FetchUserDataProp Card (PACK* CardPart (QUOTE WRITELOCK]
	    (RETURN (COND
			((NUMBERP OldValue)
			  (GREATERP OldValue 0))
			(T OldValue])

(NC.PushCopyLinkIcon
  [LAMBDA (LinkIcon Window)                                  (* fgh: " 6-Feb-86 22:29")

          (* * Do a push-copy of LinkIcon from Window)



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


    (LET (Card NewLinkIcon ScreenPosition NewWindow WindowPositionX WindowPositionY InsertPos)
         (SETQ ScreenPosition (GETPOSITION))
         (SETQ NewWindow (WHICHW ScreenPosition))
         (SETQ WindowPositionX (LASTMOUSEX NewWindow))
         (SETQ WindowPositionY (LASTMOUSEY NewWindow))
         [COND
	   ((AND (WINDOWP NewWindow)
		   (SETQ Card (NC.CoerceToCard NewWindow)))
	     (SETQ InsertPos (NC.ApplyFn TranslateWindowPositionFn Card WindowPositionX 
					   WindowPositionY))
	     (SETQ NewLinkIcon (APPLY* (IMAGEOBJPROP LinkIcon (QUOTE COPYFN))
					   LinkIcon))
	     (AND (NEQ (APPLY* (IMAGEOBJPROP LinkIcon (QUOTE WHENCOPIEDFN))
				     LinkIcon
				     (WINDOWPROP NewWindow (QUOTE DSP))
				     (WINDOWPROP Window (QUOTE TEXTSTREAM))
				     (WINDOWPROP NewWindow (QUOTE TEXTSTREAM)))
			   (QUOTE DON'T))
		    (NC.ApplyFn InsertLinkFn Card NewWindow (NC.FetchLinkFromLinkIcon NewLinkIcon)
				InsertPos]
     NIL])

(NC.PutIndexEntry
  [LAMBDA (Card)                                             (* rht: "15-Nov-85 18:21")

          (* * Write down to the file the index entry for this card.)


    (LET ((NoteFile (fetch (Card NoteFile) of Card)))
         (WITH.MONITOR (NC.FetchMonitor NoteFile)
		       (LET ((Stream (fetch (NoteFile Stream) of NoteFile)))
			    (SETFILEPTR Stream (fetch (Card IndexLoc) of Card))
			    (NC.WriteStatus Stream (fetch (Card Status) of Card))
			    (NC.WriteUID NoteFile (fetch (Card UID) of Card))
			    (NC.WritePtr Stream (fetch (Card MainLoc) of Card)
					 3)
			    (NC.WritePtr Stream (fetch (Card LinksLoc) of Card)
					 3)
			    (NC.WritePtr Stream (fetch (Card TitleLoc) of Card)
					 3)
			    (NC.WritePtr Stream (fetch (Card PropListLoc) of Card)
					 3)
			    (replace (Card IndexDirtyFlg) of Card with NIL])

(NC.PutNoteFileVersion
  [LAMBDA (NoteFile Version)                                 (* rht: "15-Nov-85 00:31")

          (* * Write down a version number in the proper place on the notefile's header. Note that this changes the in-core 
	  value of the version number as well as on the file.)


    (WITH.MONITOR (NC.FetchMonitor NoteFile)
		  (LET ((Stream (fetch (NoteFile Stream) of NoteFile)))
		       (SETFILEPTR Stream 7)
		       (NC.WritePtr Stream Version 1)
		       (replace (NoteFile Version) of NoteFile with Version])

(NC.ReadIndexEntry
  [LAMBDA (NoteFile)                                         (* rht: "15-Nov-85 20:38")

          (* * Get a card from current position of file and install it into notefile.)


    (LET ((Stream (fetch (NoteFile Stream) of NoteFile))
	  IndexLoc)
         (SETQ IndexLoc (GETFILEPTR Stream))
         (NC.InstallCardInNoteFile (create Card
					       Status ← (NC.ReadStatus Stream)
					       UID ← (NC.ReadUID NoteFile)
					       MainLoc ← (NC.ReadPtr Stream 3)
					       LinksLoc ← (NC.ReadPtr Stream 3)
					       TitleLoc ← (NC.ReadPtr Stream 3)
					       PropListLoc ← (NC.ReadPtr Stream 3)
					       IndexLoc ← IndexLoc
					       IndexDirtyFlg ← NIL
					       NoteFile ← NoteFile)
				     NoteFile])

(NC.ReorderVirtualGraphNodes
  [LAMBDA (Graph)                                            (* rht: "29-Aug-85 12:23")

          (* * Move the virtual nodes of Graph to the end. LAYOUTGRAPH puts them at the front, which is inconvenient.
	  Note that this assumes that virtual nodes are grouped at the front.)


    (LET ((Nodes (fetch (GRAPH GRAPHNODES) of Graph))
	  VirtualNodes)
         (SETQ VirtualNodes (for Node in old Nodes while (LISTP (fetch (GRAPHNODE
										       NODEID)
									       of Node))
				 collect Node))
         (replace (GRAPH GRAPHNODES) of Graph with (NCONC Nodes VirtualNodes])

(NC.SameCardIDP
  [LAMBDA (NoteCardID1 NoteCardID2)                          (* rht: "29-Oct-85 17:55")

          (* * Return non-nil if both IDs represent same card.)


    (LET ((NumericalID1 (NC.NumberFromID NoteCardID1))
	  (NumericalID2 (NC.NumberFromID NoteCardID2)))
         (EQP NumericalID1 NumericalID2])

(NC.SetIndexLoc
  [LAMBDA (Card IndexLoc)                                    (* rht: "14-Nov-85 18:27")

          (* * Set the IndexLoc field of the given Card)


    (replace (Card IndexDirtyFlg) of Card with T)
    (replace (Card IndexLoc) of Card with IndexLoc])

(NC.SetInitialPropList
  [LAMBDA (Card)                                             (* fgh: "13-Nov-85 20:27")
    (NC.SetPropList Card (NCONC (LIST (QUOTE Sources)
					    NIL)
				    (NC.FetchPropList Card])

(NC.SetLinkInLinkIcon
  [LAMBDA (LinkIcon Link)                                    (* fgh: "16-Oct-84 23:41")

          (* * Set LinkIcon to be the icon for Link)


    (IMAGEOBJPROP LinkIcon (QUOTE OBJECTDATUM)
		    Link])

(NC.SetWriteLock
  [LAMBDA (Card CardPart)                                    (* Feuerman "30-Jul-86 15:35")

          (* * Adds 1 to the writelock count)


    (PROG [(OldCount (NC.FetchUserDataProp Card (PACK* CardPart (QUOTE WRITELOCK]
	    (RETURN (NC.SetUserDataProp Card (PACK* CardPart (QUOTE WRITELOCK))
					    (COND
					      ((NUMBERP OldCount)
						(ADD1 OldCount))
					      (T 1])

(NC.SketchBasedP
  [LAMBDA (CardOrTypeName)                                   (* fgh: "17-Nov-85 21:07")

          (* * Returns T if Type is a note card type that is based on Sketch.)


    (LET [(TypeName (COND
		      ((NC.CardP CardOrTypeName)
			(NC.RetrieveType CardOrTypeName))
		      (T CardOrTypeName]
         (NC.IsSubTypeOfP TypeName (QUOTE Sketch])

(NC.SkipWhiteSpace
  [LAMBDA (Stream EofPtr SkipNullsFlg)                       (* kirk: "20-Feb-86 15:28")

          (* * Skip over all separator characters. There seem to be nulls at the end of the file sometimes 
	  (char code = 0) so SkipNullsFlg = T calls them white space.)



          (* * fgh 2/19/86 Replaced READC/PEEKC with BIN/PEEKBIN to avoid problems with NS characters in Koto and beyond.)


    (LET ((CurPtr (GETFILEPTR Stream))
	  (SeprChars (GETSEPR)))
         (OR EofPtr (SETQ EofPtr (GETEOFPTR Stream)))
         (if SkipNullsFlg
	     then (SETQ SeprChars (CONS 0 SeprChars)))
         (for Ptr from CurPtr while (AND (LESSP Ptr EofPtr)
						 (FMEMB (\PEEKBIN Stream)
							  SeprChars))
	    do (BIN Stream])

(NC.StoreNoteFile
  [LAMBDA (NoteFile)                                         (* rht: "13-Nov-85 00:10")

          (* * Stuff this notefile in the global notefiles hash array.)


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

(NC.UnSetWriteLock
  [LAMBDA (Card CardPart)                                    (* Feuerman "30-Jul-86 16:27")

          (* * Subtracts 1 to the writelock count)


    (PROG [(OldCount (NC.FetchUserDataProp Card (PACK* CardPart (QUOTE WRITELOCK]
	    (RETURN (NC.SetUserDataProp Card (PACK* CardPart (QUOTE WRITELOCK))
					    (COND
					      ((AND (NUMBERP OldCount)
						      (GREATERP OldCount 0))
						(SUB1 OldCount))
					      (T 0])

(NC.WriteMainCardData
  [LAMBDA (Card CardType Region SubstanceStream UseOldDateFlg)
                                                             (* rht: "15-Nov-85 00:32")

          (* * Write out the junk for a card at current location in Stream finding the substance out on SubstanceStream.
	  Then update index.)



          (* * rht 7/9/85: Now puts out date after identifier. If UseOldDateFlg is non-nil, then use old date, otherwise use 
	  current date.)



          (* * fkr 11/8/85: Now uses notefile and hash array value.)



          (* * rht 11/12/85: Minor changes to call NC.WriteUID, etc. Note that this expects file ptr to be set, 
	  monitorlocked, etc.)


    (LET ((NoteFile (fetch (Card NoteFile) of Card))
	  Stream MainLoc EndLoc SubstanceLoc)
         (SETQ Stream (fetch (NoteFile Stream) of NoteFile))
         (SETQ MainLoc (GETFILEPTR Stream))
         (NC.WriteIdentifier Card NC.ItemIdentifier)
         [NC.WriteDate NoteFile (if UseOldDateFlg
				      then (NC.FetchItemDate Card)
				    else (NC.SetItemDate Card (DATE]
         (NC.WriteUID (fetch (Card UID) of Card))
         (NC.WriteCardType NoteFile CardType)
         (NC.WriteRegion Card)
         (SETQ SubstanceLoc (GETFILEPTR Stream))
         (APPLY* (NC.SubstanceCopyFn CardType)
		   Card SubstanceStream Stream)
         (SETFILEPTR Stream SubstanceLoc)
         (NC.ReadPtr Stream 3)
         (SETQ EndLoc (NC.ReadPtr Stream 3))               (* Update index array.)
         (replace (Card MainLoc) of Card with MainLoc)
                                                             (* Update index.)
         (NC.PutIndexEntry Card)
         (SETFILEPTR Stream EndLoc])

(NC.\TEDIT.LOOKS
  [LAMBDA (TextStream)                                       (* fgh: "31-Mar-84 16:02")
    (\TEDIT.LOOKS (TEXTOBJ TextStream])

(NC.\TEDIT.QUIT
  [LAMBDA (TextStream)                                       (* fgh: "10-May-84 16:27")
    (PROG ((Window (WINDOW.FROM.TEDIT.THING TextStream)))
	    (NC.TEditQuitFn Window)
	    (\TEDIT.QUIT Window])

(NCP.AddTitleBarMenuItems
  [LAMBDA (Window NewMenuItems)                              (* rht: "12-Jul-86 14:11")

          (* * Add the given menu items to the left button menu of Window.)


    (LET [(Menu (WINDOWPROP Window (QUOTE TitleBarLeftButtonMenu]
         (if Menu
	     then (PROG1 (replace (MENU ITEMS) of Menu with (APPEND
									  (fetch (MENU ITEMS)
									     of Menu)
									  NewMenuItems))
			     (replace (MENU IMAGE) of Menu with NIL])

(QUEUE.CREATE
  [LAMBDA NIL                                                (* Feuerman "24-Mar-86 14:20")

          (* * Creates and returns an instance of a new queue.)


    (CONS NIL NIL])

(QUEUE.DEQUEUE
  [LAMBDA (Q)                                                (* Feuerman "24-Mar-86 16:35")
    (PROG1 (CAAR Q)
	     (RPLACA Q (CDAR Q))
	     (OR (CAR Q)
		   (RPLACD Q NIL])

(QUEUE.ENQUEUE
  [LAMBDA (Q ITEM)                                           (* Feuerman "24-Mar-86 14:25")
    (COND
      ((CDR Q)
	(RPLACD (CDR Q)
		  (CONS ITEM))
	(RPLACD Q (CDDR Q)))
      (T (RPLACA Q (CONS ITEM))
	 (RPLACD Q (CAR Q])

(NC.InspectorTitleCommandFn
  [LAMBDA (InspectWindow Object)                             (* pmi: "25-Mar-87 09:56")

          (* * pmi 3/25/87: Changed to call NC.AskYesOrNo instead of making its own Yes/No menu.)



          (* * (AND (EQ (MENU (create MENU ITEMS ← (QUOTE (Yes No)) TITLE ← "Close?")) (QUOTE Yes)) (CLOSEW InspectWindow)))


    (AND (NC.AskYesOrNo NIL "Close?")
	   (CLOSEW InspectWindow])
)
(PUTPROPS NCOBSOLETE COPYRIGHT ("Xerox Corporation" 1986 1987))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (1824 58986 (DRAWBOX 1834 . 2363) (NC.AddLinkToTextCard 2365 . 2829) (
NC.AddLinksToTextCard 2831 . 3226) (NC.AskMoveOrCopyNoteCards 3228 . 5510) (NC.AssignSources 5512 . 
6465) (NC.BitMapFromImageObject 6467 . 7322) (NC.BrowserDeleteCard 7324 . 9448) (
NC.CachedInsertLinkInOrdering 9450 . 11254) (NC.CardTypeFieldInheritedP 11256 . 11623) (
NC.CheckForNeededTruncation 11625 . 16835) (NC.CheckLinkRecordFormat 16837 . 17311) (
NC.CleanupIndexEntries 17313 . 17947) (NC.CloseCards 17949 . 18199) (NC.CollectAndCheckLinks 18201 . 
20552) (NC.CollectCards 20554 . 21441) (NC.ComputeMenuPosition 21443 . 22045) (
NC.CopyCrossFileLinkCard 22047 . 22667) (NC.DeleteCards 22669 . 22928) (NC.DeleteNoteFile 22930 . 
23268) (NC.DeleteSource 23270 . 25674) (NC.DetermineFileBoxes 25676 . 27822) (NC.EditFileBox 27824 . 
28097) (NC.FileNoteCard 28099 . 28664) (NC.FlattenLinkFields 28666 . 29472) (NC.FloppyArchive 29474 . 
32528) (NC.GetNoteFileHeader 32530 . 34422) (NC.GetNoteFileVersion 34424 . 34790) (NC.GetTypeIcon 
34792 . 35305) (NC.GetUIDFromIndexNum 35307 . 35790) (NC.GraphEdgesInconsistentP 35792 . 37063) (
NC.GrapherBasedP 37065 . 37523) (NC.InsertLinkInOrdering 37525 . 40406) (NC.InsertLinksInText 40408 . 
41743) (NC.ListDatabaseFiles 41745 . 42974) (NC.MapRegistry 42976 . 43898) (NC.MarkIndexEntryFree 
43900 . 44535) (NC.MoveTTYWindow 44537 . 44949) (NC.NotBrowserHookP 44951 . 45150) (NC.NoteCardsGraphP
 45152 . 45487) (NC.NoteFileTitleMiddleButtonFn 45489 . 46236) (NC.NumberFromID 46238 . 46571) (
NC.OwnWriteLockP 46573 . 47059) (NC.PushCopyLinkIcon 47061 . 48375) (NC.PutIndexEntry 48377 . 49341) (
NC.PutNoteFileVersion 49343 . 49919) (NC.ReadIndexEntry 49921 . 50703) (NC.ReorderVirtualGraphNodes 
50705 . 51393) (NC.SameCardIDP 51395 . 51735) (NC.SetIndexLoc 51737 . 52039) (NC.SetInitialPropList 
52041 . 52280) (NC.SetLinkInLinkIcon 52282 . 52527) (NC.SetWriteLock 52529 . 52984) (NC.SketchBasedP 
52986 . 53380) (NC.SkipWhiteSpace 53382 . 54210) (NC.StoreNoteFile 54212 . 54505) (NC.UnSetWriteLock 
54507 . 55017) (NC.WriteMainCardData 55019 . 56858) (NC.\TEDIT.LOOKS 56860 . 57020) (NC.\TEDIT.QUIT 
57022 . 57263) (NCP.AddTitleBarMenuItems 57265 . 57811) (QUEUE.CREATE 57813 . 58021) (QUEUE.DEQUEUE 
58023 . 58250) (QUEUE.ENQUEUE 58252 . 58544) (NC.InspectorTitleCommandFn 58546 . 58984)))))
STOP