(FILECREATED "18-Jan-88 17:12:15" {QV}<NOTECARDS>1.3KNEXT>NCPROGINT.;8 164265 

      changes to:  (FNS NCP.CollectCards NCP.OpenNoteFile NCP.CreateCard NCP.ValidCardP 
			NCP.CreateLinkType NCP.ListRegisteredCards NCP.DisplayedCards 
			NCP.AddNoteFileIconMiddleButtonItems)
		   (VARS NCPROGINTCOMS)

      previous date: "30-Nov-87 15:52:09" {QV}<NOTECARDS>1.3KNEXT>NCPROGINT.;7)


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

(PRETTYCOMPRINT NCPROGINTCOMS)

(RPAQQ NCPROGINTCOMS [(* * Notefile creation and access)
	(FNS NCP.CreateNoteFile NCP.OpenNoteFile NCP.OpenNoteFileP NCP.ListOfOpenNoteFiles 
	     NCP.CloseNoteFiles NCP.CheckpointNoteFiles NCP.AbortNoteFiles NCP.CompactNoteFile 
	     NCP.CompactNoteFileInPlace NCP.RepairNoteFile NCP.DeleteNoteFile 
	     NCP.NoteFileFromFileName NCP.FileNameFromNoteFile NCP.NoteFileMenu NCP.CheckInNoteFile 
	     NCP.CheckOutNoteFile NCP.LockFileName NCP.NumCardSlotsRemaining NCP.ExpandNoteFileIndex 
	     NCP.NoteFileClosingP NCP.NoteFileAddProp)
	(* * Creating and accessing NoteCard types and substances.)
	(FNS NCP.CardTypes NCP.CreateCardType NCP.DeleteCardType NCP.CreateCardTypeStub 
	     NCP.ChangeCardTypeFields NCP.CardTypeSuper NCP.CardTypeLinkDisplayMode NCP.CardTypeFn 
	     NCP.CardTypeVar NCP.CardTypeP NCP.CardTypeFnP NCP.CardTypeVarP NCP.CardTypeFns 
	     NCP.CardTypeVars NCP.CardTypeDisplayedInMenu NCP.IsSubTypeOfP NCP.TextBasedP 
	     NCP.SketchBasedP NCP.GraphBasedP NCP.AutoLoadCardType NCP.AddSpecialCard 
	     NCP.RemoveSpecialCard NCP.CardsOfTypes)
	(MACROS NCP.ApplyCardTypeFn NCP.ApplySuperTypeFn)
	(* * Creating Notecards and fileboxes)
	(FNS NCP.CreateCard NCP.CreateTextCard NCP.CreateFileBox NCP.CreateBrowserCard 
	     NCP.CreateSketchCard NCP.CreateGraphCard NCP.MakeDocument NCP.MakeLinkIndex)
	(* * Opening, closing, activating, display, etc.)
	(FNS NCP.OpenCard NCP.CloseCards NCP.DisplayCard NCP.UndisplayCards NCP.CacheCards 
	     NCP.UncacheCards NCP.CardCachedP NCP.CardDisplayedP NCP.CardWindow NCP.WindowFromCard 
	     NCP.CardFromWindow NCP.CardFromTextStream)
	(* * Accessing cards and boxes)
	(FNS NCP.CardType NCP.ValidCardP NCP.CardTitle NCP.FileCards NCP.UnfileCards NCP.CardParents 
	     NCP.FileBoxChildren NCP.CardNeighbors NCP.GetLinks NCP.CardPropList NCP.CardProp 
	     NCP.CardAddProp NCP.CardDelProp NCP.CardSubstance NCP.CardRegion NCP.CardAddText 
	     NCP.ChangeLoc NCP.DeleteCards NCP.FileBoxP NCP.AllCards NCP.AllBoxes NCP.ContentsFileBox 
	     NCP.OrphansFileBox NCP.ToBeFiledFileBox NCP.NoteFileFromCard NCP.CardNoteFile 
	     NCP.SameCardP NCP.CoerceToCard NCP.DetermineDisplayRegion NCP.LockListOfCards 
	     NCP.GetCrossFileLinkDestCard NCP.CardBeingDeletedP NCP.NewCardP)
	(MACROS NCP.MapCards NCP.MapCardsOfType)
	(MACROS NCP.WithLockedCards)
	(* * Collecting, copying, moving, deleting, cards)
	(FNS NCP.CollectCards NCP.CopyCards NCP.MoveCards)
	(* * Creating and accessing links)
	(FNS NCP.CreateLink NCP.LocalGlobalLink NCP.GlobalGlobalLink NCP.GlobalLocalLink 
	     NCP.LocalLocalLink NCP.LinkDesc NCP.LinkDisplayMode NCP.LinkType NCP.LinkSource 
	     NCP.LinkDestination NCP.DeleteLinks NCP.ValidLinkP NCP.AllLinks NCP.SameLinkP 
	     NCP.LinkFromLinkIcon NCP.MakeLinkIcon NCP.MarkCardDirty)
	(MACROS NCP.MapLinks NCP.MapLinksOfType)
	(* * Creating and accessing link labels.)
	(FNS NCP.CreateLinkType NCP.DeleteLinkType NCP.RenameLinkType NCP.LinkTypes 
	     NCP.ReverseLinkTypes NCP.UserLinkTypes NCP.ValidLinkTypeP NCP.SystemLinkTypeP)
	(* * Dealing with card parts dates.)
	(RECORDS NOTECARDDATES)
	(FNS NCP.CardDates)
	(* * Open events card)
	(FNS NCP.GetOpenEventsCard NCP.GetCloseEventsCard NCP.MarkAsNotNeedingFiling)
	(* * Functions for adding menu items)
	(FNS NCP.AddSessionIconMenuItem NCP.RemoveSessionIconMenuItem NCP.RestoreSessionIconMenu 
	     NCP.AddNoteFileIconMenuItem NCP.RemoveNoteFileIconMenuItem NCP.RestoreNoteFileIconMenu 
	     NC.CreateSessionIconNoteFileMenuItem NCP.AddDefaultNoteFileIconMiddleButtonItems 
	     NCP.NoticedNoteFileNamesMenu NCP.AddTitleBarMenuItemsToType 
	     NCP.AddTitleBarMenuItemsToWindow NCP.LinkIconAttachedBitMap NCP.SessionIconWindow 
	     NCP.BringUpSessionIcon)
	(* * Miscellaneous)
	(FNS NCP.TitleSearch NCP.PropSearch NCP.WhichCard NCP.WhichNoteFile NCP.SelectCards 
	     NCP.DocumentParameters NCP.NoteCardsParameters NCP.PrintMsg NCP.ClearMsg NCP.AskUser 
	     NCP.AskYesOrNo NCP.RegisterCardByName NCP.ListRegisteredCards NCP.LookupCardByName 
	     NCP.UnregisterName NCP.DisplayedCards NCP.CardUserDataProp NCP.NoteFileProp 
	     NCP.SetUpTitleBar NCP.AddNoteFileIconMiddleButtonItems NCP.NoteFileIconWindow)
	(DECLARE: DONTEVAL@LOAD (P (MOVD (QUOTE NCP.WhichCard)
					 (QUOTE NCP.WC)
					 T)
				   (MOVD (QUOTE NCP.WhichNoteFile)
					 (QUOTE NCP.WNF)
					 T)))
	(* * Handy internal functions)
	(FNS NCP.ReportError NCP.ReportWarning NCP.LinkAnchorDesc NCP.GetTypeRecord 
	     NCP.AddLeftButtonTitleBarMenuItems NCP.AddMiddleButtonTitleBarMenuItems 
	     NCP.CoerceToLinkDisplayMode NCP.CoerceToInterestedWindow)
	(* * Global variables.)
	(GLOBALVARS NCP.ErrorBrkWhenFlg NCP.LinkDisplayModes NCP.TypeFnsAssocLst NCP.NoteCardTypeFns 
		    NCP.NoteCardTypeVars NC.MakeDocParameters NC.CardTypes NC.SubstanceTypes 
		    NC.SystemLinkLabels NC.FiledCardLinkLabel NC.SubBoxLinkLabel 
		    NC.SelectingCardsMenu NC.SelectingCardMenu NC.UCASESystemLinkLabels 
		    NC.SourceLinkLabel NC.NoteCardsParameters)
	[INITVARS (NCP.ErrorBrkWhenFlg NIL)
		  (NCP.DefaultLinkIconAttachedBitMapSize 17)
		  (NCP.LinkDisplayModes (QUOTE (Icon Title Label Both)))
		  (NCP.NoteCardTypeFns (QUOTE (MakeFn EditFn QuitFn GetFn PutFn CopyFn MarkDirtyFn 
						      DirtyPFn CollectLinksFn DeleteLinksFn 
						      UpdateLinkIconsFn InsertLinkFn 
						      TranslateWindowPositionFn)))
		  (NCP.NoteCardTypeVars (QUOTE (SuperType StubFlg FullDefinitionFile LinkDisplayMode 
							  DefaultWidth DefaultHeight 
							  LinkAnchorModesSupported DisplayedInMenuFlg 
							  LinkIconAttachedBitMap LeftButtonMenuItems 
							  MiddleButtonMenuItems]
	(* * Following is for backward compatibility with 1.2)
	(DECLARE: DONTEVAL@LOAD (P (MOVD (QUOTE NCP.OpenCard)
					 (QUOTE NCP.BringUpCard)
					 T)
				   (MOVD (QUOTE NCP.CacheCards)
					 (QUOTE NCP.ActivateCards)
					 T)
				   (MOVD (QUOTE NCP.CardCachedP)
					 (QUOTE NCP.ActiveCardP)
					 T)
				   (MOVD (QUOTE NCP.CardTypeFnP)
					 (QUOTE NCP.ValidCardTypeFn)
					 T)
				   (MOVD (QUOTE NCP.CardTypeP)
					 (QUOTE NCP.ValidCardType)
					 T)
				   (MOVD (QUOTE NCP.CardTypeVarP)
					 (QUOTE NCP.ValidCardTypeVar)
					 T)
				   (MOVD (QUOTE NCP.CloseCards)
					 (QUOTE NCP.DeactivateCards)
					 T)
				   (MOVD (QUOTE NCP.ValidCardP)
					 (QUOTE NCP.ValidCard)
					 T)
				   (MOVD (QUOTE NCP.ContentsFileBox)
					 (QUOTE NCP.GetContentsFileBox)
					 T)
				   (MOVD (QUOTE NCP.OrphansFileBox)
					 (QUOTE NCP.GetOrphansFileBox)
					 T)
				   (MOVD (QUOTE NCP.ToBeFiledFileBox)
					 (QUOTE NCP.GetToBeFiledFileBox)
					 T)
				   (MOVD (QUOTE NCP.LinkSource)
					 (QUOTE NCP.GetLinkSource)
					 T)
				   (MOVD (QUOTE NCP.LinkDestination)
					 (QUOTE NCP.GetLinkDestination)
					 T)
				   (MOVD (QUOTE NCP.CreateLinkType)
					 (QUOTE NCP.CreateLinkLabel)
					 T)
				   (MOVD (QUOTE NCP.DeleteLinkType)
					 (QUOTE NCP.DeleteLinkLabel)
					 T)
				   (MOVD (QUOTE NCP.RenameLinkType)
					 (QUOTE NCP.RenameLinkLabel)
					 T)
				   (MOVD (QUOTE NCP.LinkTypes)
					 (QUOTE NCP.GetLinkLabels)
					 T)
				   (MOVD (QUOTE NCP.UserLinkTypes)
					 (QUOTE NCP.GetUserLinkLabels)
					 T)
				   (MOVD (QUOTE NCP.ReverseLinkTypes)
					 (QUOTE NCP.GetReverseLinkLabels)
					 T)
				   (MOVD (QUOTE NCP.ValidLinkTypeP)
					 (QUOTE NCP.ValidLinkLabel)
					 T)
				   (MOVD (QUOTE NCP.ValidLinkP)
					 (QUOTE NCP.ValidLink)
					 T)))
	(DECLARE: DONTEVAL@LOAD DOEVAL@COMPILE DONTCOPY COMPILERVARS
		  (ADDVARS (NLAMA)
			   (NLAML)
			   (LAMA NCP.NoteFileProp NCP.CardUserDataProp NCP.PrintMsg NCP.PropSearch 
				 NCP.LinkType NCP.LinkDisplayMode NCP.CardRegion NCP.CardSubstance 
				 NCP.CardProp NCP.CardTitle NCP.CardTypeDisplayedInMenu])
(* * Notefile creation and access)

(DEFINEQ

(NCP.CreateNoteFile
  [LAMBDA (FileName QuietFlg)                                (* rht: " 2-Mar-87 21:58")

          (* * Prog intface function for creating a notefile.)



          (* * rht 11/16/86: Changed call to NCP.ReportError)


    (LET ((FileNameWithExt (NC.DatabaseFileName NIL NIL NIL NIL FileName)))
         (if (INFILEP FileNameWithExt)
	     then (NCP.ReportError (QUOTE NCP.CreateNoteFile)
				       (CONCAT "NCP.CreateNoteFile" "Filename " FileNameWithExt 
						 " already exists."))
		    NIL
	   else (NC.CreateDatabaseFile FileNameWithExt NIL NIL NIL NIL NIL NIL QuietFlg)
		  FileNameWithExt])

(NCP.OpenNoteFile
  [LAMBDA (NoteFileOrFileName Don'tCreateFlg Convertw/oConfirmFlg QuietFlg MenuPosition ReadOnlyFlg 
			      Don'tCreateInterfaceFlg)       (* pmi: "24-Nov-87 09:27")

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



          (* * pmi 11/24/87: Deleted extra NIL in call to NC.OpenNoteFile.)


    (if (type? NoteFile NoteFileOrFileName)
	then (NC.OpenNoteFile NoteFileOrFileName 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])

(NCP.OpenNoteFileP
  [LAMBDA (NoteFile)                                         (* Newman "13-Nov-86 17:28")

          (* * Non-nil if NoteFile is an open notefile.)



          (* * rht 9/19/86: Fixed to return nil if notefile has no stream.)



          (* * dvn 11/13/86 Changed to call NC.NoteFileOpenP)


    (NC.NoteFileOpenP NoteFile])

(NCP.ListOfOpenNoteFiles
  [LAMBDA NIL                                                (* rht: "19-Sep-86 22:52")

          (* * Return list of all currently open notefiles.)



          (* * rht 9/19/86: Fixed to return only notefiles currently open, not all that were ever open.)


    (for NoteFile in (NC.ListOfNoteFiles) when (NCP.OpenNoteFileP NoteFile) collect
										       NoteFile])

(NCP.CloseNoteFiles
  [LAMBDA (NoteFilesOrT QuietFlg AutoConfirmFlg)             (* Randy.Gobbel " 4-Mar-87 16:16")

          (* * Prog's intface function for closing a notefile.)



          (* * rht 11/17/85: Updated to handle new card and notefile objects.)



          (* * rht 7/7/86: Now takes list of notefiles. If arg is T, then close all open notefiles.)



          (* * rht 11/16/86: Changed call to NCP.ReportError)



          (* * 11/16/86: Now calls NC.CloseNoteFile instead of NC.CloseDatabaseFile.)



          (* * rht 2/16/87: Now takes AutoConfirmFlg and passes to NC.CloseNoteFile.)


    (for NoteFile in (if (EQ NoteFilesOrT T)
			     then (NCP.ListOfOpenNoteFiles)
			   else (MKLIST NoteFilesOrT))
       do (if (NOT (NCP.OpenNoteFileP NoteFile))
		then (NCP.ReportError (QUOTE NCP.CloseNoteFiles)
					  (CONCAT "Argument " NoteFile 
						    " is not a currently open notefile."))
		       NIL
	      else (NC.CloseNoteFile NoteFile NIL QuietFlg])

(NCP.CheckpointNoteFiles
  [LAMBDA (NoteFilesOrT QuietFlg)                            (* rht: " 2-Mar-87 21:58")

          (* * Checkpoint the given notefiles. If T then checkpoint all open notefiles.)



          (* * rht 11/16/86: Changed call to NCP.ReportError)


    (for NoteFile in (if (EQ NoteFilesOrT T)
			     then (NCP.ListOfOpenNoteFiles)
			   else (MKLIST NoteFilesOrT))
       do (if (NOT (NCP.OpenNoteFileP NoteFile))
		then (NCP.ReportError (QUOTE NCP.CheckpointNoteFiles)
					  (CONCAT "Argument " NoteFile 
						    " is not a currently open notefile."))
		       NIL
	      else (NC.CheckpointDatabase NoteFile QuietFlg])

(NCP.AbortNoteFiles
  [LAMBDA (NoteFilesOrT Don'tConfirmFlg QuietFlg)            (* rht: " 2-Mar-87 21:59")

          (* * Abort the given notefiles. If T then abort all open notefiles.)



          (* * rht 11/16/86: Changed call to NCP.ReportError)


    (for NoteFile in (if (EQ NoteFilesOrT T)
			     then (NCP.ListOfOpenNoteFiles)
			   else (MKLIST NoteFilesOrT))
       do (if (NOT (NCP.OpenNoteFileP NoteFile))
		then (NCP.ReportError (QUOTE NCP.AbortNotefiles)
					  (CONCAT "Argument " NoteFile 
						    " is not a currently open notefile."))
		       NIL
	      else (NC.AbortSession NoteFile NIL Don'tConfirmFlg QuietFlg])

(NCP.CompactNoteFile
  [LAMBDA (FromNoteFileOrFileName ToFileName InPlaceFlg)     (* rht: " 7-Jul-86 19:23")

          (* * Prog's intface function for compacting a notefile. FromNoteFile can be either a NoteFile or a file name.)


    (NC.CompactNoteFile FromNoteFileOrFileName ToFileName InPlaceFlg])

(NCP.CompactNoteFileInPlace
  [LAMBDA (NoteFileOrFileName)                               (* rht: " 7-Jul-86 15:45")

          (* * Prog's intface function for compacting a notefile in place.)


    (NCP.CompactNoteFile NoteFileOrFileName NIL T])

(NCP.RepairNoteFile
  [LAMBDA (NoteFileOrFileName ReadSubstancesFlg)             (* rht: " 2-Mar-87 22:08")

          (* * Prog's intface function for running inspect&repair on a notefile.)



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



          (* * rht 11/16/86: Changed call to NCP.ReportError)


    (if (NCP.OpenNoteFileP NoteFileOrFileName)
	then (NCP.ReportError (QUOTE NCP.RepairNoteFile)
				  (CONCAT "Can't inspect&repair an open notefile: " 
					    NoteFileOrFileName))
      else (NC.InspectAndRepairNoteFile NoteFileOrFileName ReadSubstancesFlg])

(NCP.DeleteNoteFile
  [LAMBDA (NoteFileOrFileName Don'tConfirmFlg QuietFlg)      (* pmi: "31-Mar-87 18:31")

          (* * Prog's intface function for deleting a notefile.)



          (* * pmi 3/31/97: Changed prompt from "Name of NoteFile to open:" to "Name of NoteFile to delete:")


    (if (type? NoteFile NoteFileOrFileName)
	then (NC.DeleteDatabaseFile NoteFileOrFileName NIL Don'tConfirmFlg QuietFlg)
      else (LET ((FileNameWithExt (NC.DatabaseFileName "Name of NoteFile to delete:" " -- " T NIL 
							   NoteFileOrFileName)))
	          (AND FileNameWithExt (NC.DeleteDatabaseFile FileNameWithExt NIL Don'tConfirmFlg 
								  QuietFlg])

(NCP.NoteFileFromFileName
  [LAMBDA (FileName)                                         (* rht: " 7-Jul-86 19:34")

          (* * Find notefile object for this filename, if any.)


    (NC.NoteFileFromFileName FileName])

(NCP.FileNameFromNoteFile
  [LAMBDA (NoteFile)                                         (* rht: " 2-Mar-87 22:08")

          (* * Grab filename off of this notefile object.)



          (* * rht 11/16/86: Changed call to NCP.ReportError)


    (if (NOT (type? NoteFile NoteFile))
	then (NCP.ReportError (QUOTE NCP.FileNameFromNoteFile)
				  (CONCAT "Arg to NCP.FileNameFromNoteFile is not a notefile: " 
					    NoteFile))
      else (fetch (NoteFile FullFileName) of NoteFile])

(NCP.NoteFileMenu
  [LAMBDA (NoteFile)                                         (* rht: "14-Jul-86 10:31")

          (* * Fetch the notefile's menu.)


    (AND (type? NoteFile NoteFile)
	   (fetch (NoteFile Menu) of NoteFile])

(NCP.CheckInNoteFile
  [LAMBDA (FromFile ToFile)                                  (* rht: "19-Dec-84 20:22")

          (* * Check lock file for ToFile. If none, then just copy FromFile to ToFile. If there is one, then must be owned by
	  us. If date of ToFile is more recent than date of lock file, then ask for user confirmation.)


    (PROG (LockFile User)
	    (SETQ ToFile (NC.DatabaseFileName "Name of file to check in to: " "--" T T ToFile))
	    [COND
	      ((SETQ LockFile (INFILEP (NCP.LockFileName ToFile)))
                                                             (* lock file exists.)
		(COND
		  ((EQ (GETFILEINFO LockFile (QUOTE LENGTH))
			 0)                                  (* Lock file is empty so delete it.)
		    (DELFILE LockFile))
		  ([NEQ (USERNAME NIL T)
			  (SETQ User (READ (SETQ LockFile (OR (OPENP LockFile (QUOTE
										 INPUT))
								      (OPENFILE LockFile
										  (QUOTE INPUT)
										  (QUOTE OLD]
                                                             (* someone else is playing with it.)
		    (PRIN1 (CONCAT "Can't check in because file was locked by " User " at "
				       (GETFILEINFO LockFile (QUOTE WRITEDATE))
				       (CHARACTER 13)
				       "To override, delete lock file and try again."
				       (CHARACTER 13)))
		    (CLOSEF LockFile)
		    (RETURN NIL))
		  ((ILESSP (GETFILEINFO LockFile (QUOTE IWRITEDATE))
			     (GETFILEINFO ToFile (QUOTE IWRITEDATE)))
                                                             (* Someone wrote the file since we locked it.)
		    (PRIN1 (CONCAT "Can't check in because file was locked by " User " at "
				       (GETFILEINFO LockFile (QUOTE WRITEDATE))
				       " but written by someone at "
				       (GETFILEINFO ToFile (QUOTE WRITEDATE))
				       (CHARACTER 13)
				       "To override, delete lock file and try again."
				       (CHARACTER 13)))
		    (RETURN NIL))
		  (T                                         (* It's the lock file we wrote when checking out so 
							     just delete it.)
		     (CLOSEF LockFile)
		     (DELFILE LockFile]
	    (SETQ FromFile (NC.DatabaseFileName "Name of file to check in from: " "--" T T 
						    FromFile))
	    (PRIN1 (CONCAT "Copying " FromFile " to " ToFile " ... "))
	    (COPYFILE FromFile ToFile)
	    (PRIN1 (CONCAT "Done." (CHARACTER 13)))
	    (RETURN (FULLNAME ToFile])

(NCP.CheckOutNoteFile
  [LAMBDA (FromFile ToFile)                                  (* Randy.Gobbel "18-Nov-86 15:42")

          (* * Copy FromFile to ToFile unless FromFile is locked. Create a lock file in FromFile's directory.)



          (* * rg 11/18/86: Replaced call to obsolete VERSIONNUMBER fn with FILENAMEFIELD)


    (PROG (LockFile User)
	    (SETQ FromFile (NC.DatabaseFileName "Name of file to check out: " "--" T T FromFile))
	LP  (SETQ LockFile (NCP.LockFileName FromFile))
	    (COND
	      [(INFILEP LockFile)                          (* lock file already exists.)
		(COND
		  ((EQ (GETFILEINFO LockFile (QUOTE LENGTH))
			 0)                                  (* Lock file is empty. Delete and start over.)
		    (DELFILE LockFile)
		    (GO LP))
		  (T                                         (* someone else already is playing with it.)
		     [SETQ LockFile (OR (OPENP LockFile (QUOTE INPUT))
					    (OPENFILE LockFile (QUOTE INPUT)
							(QUOTE OLD]
		     (SETQ User (READ LockFile))
		     (PRIN1 (CONCAT "File is locked by: " User (CHARACTER 13)))
		     (CLOSEF LockFile)
		     (RETURN NIL]
	      [(SETQ LockFile (OPENFILE LockFile (QUOTE OUTPUT)))
		(COND
		  ((EQ (FILENAMEFIELD LockFile (QUOTE VERSION))
			 1)
		    (PRINT (USERNAME NIL T)
			     LockFile)
		    (CLOSEF LockFile))
		  (T                                         (* someone else created one before us.
							     Delete this one and try again.)
		     (DELFILE (CLOSEF LockFile))
		     (GO LP]
	      (T                                             (* something when wrong)
		 (PRIN1 (CONCAT "Trouble in NC.CheckOutNoteFile." (CHARACTER 13)))
		 (RETURN NIL)))
	    (SETQ ToFile (NC.DatabaseFileName "Name of file to check out to: " "--" T T ToFile))
	    (PRIN1 (CONCAT "Copying " FromFile " to " ToFile " ... "))
	    (COPYFILE FromFile ToFile)
	    (PRIN1 (CONCAT "Done." (CHARACTER 13)))
	    (RETURN (FULLNAME ToFile])

(NCP.LockFileName
  [LAMBDA (FileName)                                         (* rht: "19-Dec-84 12:09")
                                                             (* returns the name of the lock file associated with 
							     FileName)
    (PACKFILENAME (LIST (QUOTE EXTENSION)
			    (PACK* (FILENAMEFIELD FileName (QUOTE EXTENSION))
				     "LOCKFILE")
			    (QUOTE VERSION)
			    1
			    (QUOTE BODY)
			    FileName])

(NCP.NumCardSlotsRemaining
  [LAMBDA (NoteFile)                                         (* rht: "24-May-87 00:04")

          (* * Return the number of card slots remaining in NoteFile. After they run out, it will have to have its index 
	  expanded.)


    (if (NCP.OpenNoteFileP NoteFile)
	then (DIFFERENCE (fetch (NoteFile HashArraySize) of NoteFile)
			     (NC.TotalCardsInNoteFile NoteFile))
      else (NCP.ReportError (QUOTE NCP.NumCardSlotsRemaining)
				(CONCAT NoteFile " is not an open notefile."])

(NCP.ExpandNoteFileIndex
  [LAMBDA (NoteFile NumNewSlots QuietFlg)                    (* rht: "24-May-87 00:37")

          (* * Expand NoteFile's index in place after first checkpointing. Add room for NumNewSlots new slots.)


    (LET (WasOpenFlg)
         (if (SETQ WasOpenFlg (NCP.OpenNoteFileP NoteFile))
	     then (NCP.CheckpointNoteFiles NoteFile QuietFlg)
	   else (NCP.OpenNoteFile NoteFile T NIL QuietFlg NIL NIL T))
         (NC.ExpandIndexInPlace NoteFile (PLUS (fetch (NoteFile HashArraySize) of NoteFile)
						   NumNewSlots)
				  NIL NIL NIL QuietFlg)
         (OR WasOpenFlg (NCP.CloseNoteFiles NoteFile QuietFlg])

(NCP.NoteFileClosingP
  [LAMBDA (DontCheckForAbortFlg)                             (* DSJ: " 7-Nov-87 00:28")

          (* * dsj 10/12/87. This fn looks up the stack to see if the notefile's being closed. Not pretty, but there's no 
	  other way to tell. Unless DontCheckForAbortFlg, aborting the notefile counts as closing it.)


    (OR (RELSTK (STKPOS (QUOTE NC.CloseNoteFile)))
	  (AND (NOT DontCheckForAbortFlg)
		 (RELSTK (STKPOS (QUOTE NC.AbortSession])

(NCP.NoteFileAddProp
  [LAMBDA (NoteFile PROP NEWVALUE)                           (* pmi: "23-Oct-87 15:02")

          (* * Prog. int. way into NC.NoteFileAddProp.)


    (NC.NoteFileAddProp NoteFile PROP NEWVALUE])
)
(* * Creating and accessing NoteCard types and substances.)

(DEFINEQ

(NCP.CardTypes
  [LAMBDA NIL                                                (* rht: "26-Oct-84 17:06")

          (* * Return list of all known card type names.)


    (NC.ListOfCardTypes])

(NCP.CreateCardType
  [LAMBDA (TypeName SuperType FnsAssocList VarsAssocList)    (* rht: "16-Nov-86 22:46")

          (* * Make a new card type. If there is already a card type by that name, then print message and overwrite.)



          (* * rht 11/17/85: Updated to handle new card and notefile objects.)



          (* * rht 11/16/86: Changed call to NCP.ReportWarning)


    (if (FMEMB TypeName (NCP.CardTypes))
	then (NCP.ReportWarning "NCP.CreateCardType" (CONCAT "Redefining NoteCard type: " 
								   TypeName)))
    (NC.AddCardType TypeName SuperType FnsAssocList VarsAssocList)
    TypeName])

(NCP.DeleteCardType
  [LAMBDA (TypeName DeleteSubTypesFlg)                       (* Randy.Gobbel "15-Sep-87 18:50")
    (NC.DeleteCardType TypeName DeleteSubTypesFlg])

(NCP.CreateCardTypeStub
  [LAMBDA (TypeName SuperType FullDefinitionFileName FnsAssocList VarsAssocList ListOfFILLMEFields)
                                                             (* Randy.Gobbel "17-Dec-86 14:21")

          (* * Make a stub for a new card type. If there is already a card type by that name, then print message and 
	  overwrite.)



          (* * rht 11/16/86: Changed call to NCP.ReportError)



          (* * rg 12/17/86: Added ListOfFILLMEFields argument.)


    (if (FMEMB TypeName (NCP.CardTypes))
	then (NCP.ReportWarning "NCP.CreateCardTypeStub" (CONCAT "Redefining NoteCard type: " 
								       TypeName)))
    (NC.AddCardTypeStub TypeName SuperType FullDefinitionFileName FnsAssocList VarsAssocList 
			  ListOfFILLMEFields)
    TypeName])

(NCP.ChangeCardTypeFields
  [LAMBDA (TypeName FnsAssocList VarsAssocList)              (* rht: " 2-Mar-87 22:08")

          (* * Change the given fields of TypeName.)



          (* * rht 11/16/86: Changed call to NCP.ReportError)


    (if (NCP.CardTypeP TypeName)
	then (NC.RecomputeCardType TypeName FnsAssocList VarsAssocList)
      else (NCP.ReportError (QUOTE NCP.ChangeCardTypeFields)
				(CONCAT "Undefined card type: " TypeName])

(NCP.CardTypeSuper
  [LAMBDA (Type)                                             (* rht: " 2-Mar-87 21:59")

          (* * Return the super type for this type.)



          (* * rht 11/16/86: Changed call to NCP.ReportError)


    (if (NCP.CardTypeP Type)
	then (NC.GetCardTypeField SuperType Type)
      else (NCP.ReportError (QUOTE NCP.CardTypeSuper)
				(CONCAT Type " is not a loaded NoteCard type."))
	     NIL])

(NCP.CardTypeLinkDisplayMode
  [LAMBDA (Type)                                             (* rht: " 2-Mar-87 21:59")

          (* * Return the link display mode for this type.)



          (* * rht 11/16/86: Changed call to NCP.ReportError)


    (if (NCP.CardTypeP Type)
	then (NC.GetCardTypeField LinkDisplayMode Type)
      else (NCP.ReportError (QUOTE NCP.CardTypeLinkDisplayMode)
				(CONCAT Type " is not a loaded NoteCard type."))
	     NIL])

(NCP.CardTypeFn
  [LAMBDA (TypeName Fn)                                      (* rht: " 2-Mar-87 22:09")

          (* * Return the function stored as the Fn for TypeName's record.)



          (* * rht 7/7/86: Replaced NIL DEC in RECORDACCESS call with RECLOOK)



          (* * rht 8/25/86: Changed RECORDACCESS to slightly less scuzzy call to NC.GetCardTypeField, the advantage is that 
	  the latter will force autoload if necessary.)



          (* * rht 11/16/86: Changed call to NCP.ReportError)


    (if (NCP.CardTypeP TypeName)
	then (if (NCP.ValidCardTypeFn Fn)
		   then (EVAL (BQUOTE (NC.GetCardTypeField , Fn TypeName)))
		 else (NCP.ReportError (QUOTE NCP.CardTypeFn)
					   (CONCAT Fn " is not a kind of Fn for NoteCard types.")))
      else (NCP.ReportError (QUOTE NCP.CardTypeFn)
				(CONCAT TypeName " is not a loaded NoteCard type."))
	     NIL])

(NCP.CardTypeVar
  [LAMBDA (TypeName Var)                                     (* rht: " 2-Mar-87 22:09")

          (* * Return the variable stored as the Var for TypeName's record.)



          (* * kirk 26Feb86 Replaced NIL DEC in RECORDACCESS call with RECLOOK)



          (* * rht 8/25/86: Changed RECORDACCESS to slightly less scuzzy call to NC.GetCardTypeField, the advantage is that 
	  the latter will force autoload if necessary.)



          (* * rht 11/16/86: Changed call to NCP.ReportError)


    (if (NCP.CardTypeP TypeName)
	then (if (NCP.ValidCardTypeVar Var)
		   then (EVAL (BQUOTE (NC.GetCardTypeField , Var TypeName)))
		 else (NCP.ReportError (QUOTE NCP.CardTypeVar)
					   (CONCAT Var " is not a kind of Var for NoteCard types."))
		     )
      else (NCP.ReportError (QUOTE NCP.CardTypeVar)
				(CONCAT TypeName " is not a loaded NoteCard type."))
	     NIL])

(NCP.CardTypeP
  [LAMBDA (TypeName)                                         (* rht: "26-Oct-84 17:48")

          (* * Returns non-nil if this TypeName is an existing NoteCard type.)


    (AND (FMEMB TypeName (NC.ListOfCardTypes))
	   TypeName])

(NCP.CardTypeFnP
  [LAMBDA (CardTypeFn)                                       (* rht: " 7-Jul-86 21:26")

          (* * Returns non-nil if CardTypeFn is one of the Fn fields of the NoteCardType record.)


    (AND (FMEMB CardTypeFn NCP.NoteCardTypeFns)
	   CardTypeFn])

(NCP.CardTypeVarP
  [LAMBDA (CardTypeVar)                                      (* rht: " 7-Jul-86 21:28")

          (* * Returns non-nil if CardTypeVar is one of the Var fields of the NoteCardType record.)


    (AND (FMEMB CardTypeVar NCP.NoteCardTypeVars)
	   CardTypeVar])

(NCP.CardTypeFns
  [LAMBDA NIL                                                (* rht: " 7-Jul-86 20:58")

          (* * Returns list of the fns fields of the NoteCardType record.)


    NCP.NoteCardTypeFns])

(NCP.CardTypeVars
  [LAMBDA NIL                                                (* rht: " 7-Jul-86 20:59")

          (* * Returns list of the vars fields of the NoteCardType record.)


    NCP.NoteCardTypeVars])

(NCP.CardTypeDisplayedInMenu
  [LAMBDA Args                                               (* rht: " 2-Mar-87 21:59")

          (* * Expects one or two args: CardType and optional new value for CardDisplayedInMenuFlg. Always returns the old 
	  value of CardDisplayedInMenuFlg for given card type.)



          (* * rht 7/15/86: Changed to call NCP.ChangeCardTypeFields)



          (* * rht 11/16/86: Changed call to NCP.ReportError)


    (LET (CardType OldVal)
         (if (OR (EQ Args 1)
		     (EQ Args 2))
	     then (if (NCP.CardTypeP (SETQ CardType (ARG Args 1)))
			then [PROG1 (SETQ OldVal (NCP.CardTypeVar CardType (QUOTE 
									       DisplayedInMenuFlg)))
					(if (AND (EQ Args 2)
						     (NEQ OldVal (EQ Args 2)))
					    then (NCP.ChangeCardTypeFields
						     CardType NIL (BQUOTE ((DisplayedInMenuFlg
									       ,
									       (EQ Args 2]
		      else (NCP.ReportError (QUOTE NCP.CardTypeDisplayedInMenu)
						(CONCAT CardType " is not a loaded NoteCard type."))
			     NIL)
	   else (NCP.ReportError (QUOTE NCP.CardTypeDisplayedInMenu)
				     "Improper number of args to NCP.CardTypeDisplayedInMenu.")
		  NIL])

(NCP.IsSubTypeOfP
  [LAMBDA (SubTypeName SupposedSuperTypeName)                (* rht: " 2-Mar-87 21:54")

          (* * Return non-nil if SubTypeName inherits somewhere up the hierarchy from SupposedSuperTypeName)



          (* * rht 8/19/86: Fixed typo bug.)



          (* * rht 11/16/86: Changed call to NCP.ReportError)



          (* * rht 3/2/87: No longer checks for valid card type, thus allowing autoloading if card type not currently 
	  loaded.)


    (NC.IsSubTypeOfP SubTypeName SupposedSuperTypeName])

(NCP.TextBasedP
  [LAMBDA (CardOrCardType)                                   (* rht: " 2-Mar-87 21:55")

          (* * This card or card type is a subtype of Text.)



          (* * rht 11/16/86: Changed call to NCP.ReportError)



          (* * rht 3/2/87: No longer checks for valid card type, thus allowing autoloading if card type not currently 
	  loaded.)


    (LET ((CardType (if (NC.CardP CardOrCardType)
			then (NCP.CardType CardOrCardType)
		      else CardOrCardType)))
         (NC.IsSubTypeOfP CardType (QUOTE Text])

(NCP.SketchBasedP
  [LAMBDA (CardOrCardType)                                   (* rht: " 2-Mar-87 21:55")

          (* * This card type is a subtype of Sketch.)



          (* * rht 10/15/86: Fixed typo.)



          (* * rht 11/16/86: Changed call to NCP.ReportError)



          (* * rht 3/2/87: No longer checks for valid card type, thus allowing autoloading if card type not currently 
	  loaded.)


    (LET ((CardType (if (NC.CardP CardOrCardType)
			then (NCP.CardType CardOrCardType)
		      else CardOrCardType)))
         (NC.IsSubTypeOfP CardType (QUOTE Sketch])

(NCP.GraphBasedP
  [LAMBDA (CardOrCardType)                                   (* rht: " 2-Mar-87 21:54")

          (* * This card type is a subtype of Graph.)



          (* * rht 10/15/86: Fixed typo.)



          (* * rht 11/16/86: Changed call to NCP.ReportError)



          (* * rht 3/2/87: No longer checks for valid card type, thus allowing autoloading if card type not currently 
	  loaded.)


    (LET ((CardType (if (NC.CardP CardOrCardType)
			then (NCP.CardType CardOrCardType)
		      else CardOrCardType)))
         (NC.IsSubTypeOfP CardType (QUOTE Graph])

(NCP.AutoLoadCardType
  [LAMBDA (TypeName)                                         (* rht: "15-Jul-86 18:45")

          (* * Try to load the file containing TypeName looking in NOTECARDSDIRECTORIES.)


    (NC.AutoLoadCardType TypeName (QUOTE SuperType])

(NCP.AddSpecialCard
  [LAMBDA (Card)                                             (* rht: "23-Nov-86 13:33")

          (* * Adds this card to list of special cards hung off notefile's "SpecialCards" user data prop unless it's already 
	  there.)


    (LET ((NoteFile (NCP.CardNoteFile Card)))
         (if (for SpecialCard in (NCP.NoteFileProp NoteFile (QUOTE SpecialCards))
		  never (NCP.SameCardP Card SpecialCard))
	     then (NC.NoteFileAddProp NoteFile (QUOTE SpecialCards)
					  Card])

(NCP.RemoveSpecialCard
  [LAMBDA (Card)                                             (* rht: "20-Nov-86 15:07")

          (* * Removes this card from list of special cards hung off notefile's "SpecialCards" user data prop.)


    (NC.NoteFileDelProp (fetch (Card NoteFile) of Card)
			  (QUOTE SpecialCards)
			  Card
			  (FUNCTION NC.SameCardP])

(NCP.CardsOfTypes
  [LAMBDA (CardsOrNoteFile Types)                            (* pmi: "18-Aug-87 11:17")

          (* * pmi 7/14/87: First created to return all cards in CardsOrNoteFile which are of any of the types in Types.
	  CardsOrNoteFile should be a card, a list of cards, or an open notefile. Types = NIL will return all cards in 
	  CardsOrNoteFile.)



          (* * pmi 8/18/87: Modified to take an open notefile or a list of cards.)


    (LET (Cards)
         (if (NCP.OpenNoteFileP CardsOrNoteFile)
	     then (SETQ Cards (NCP.AllCards CardsOrNoteFile))
	   else (SETQ Cards (MKLIST CardsOrNoteFile)))
         (if Types
	     then (SETQ Types (MKLIST Types))
		    (for Card in Cards when (FMEMB (NCP.CardType Card)
							   Types)
		       collect Card)
	   else Cards])
)
(DECLARE: EVAL@COMPILE 
(DEFMACRO NCP.ApplyCardTypeFn (Fn Card &REST Args)
	  (* * Apply the cardtypefn Fn to Card and the rest of the args.)
	  (BQUOTE (NC.ApplyFn , Fn , Card ,@ Args)))
(DEFMACRO NCP.ApplySuperTypeFn (Fn Card &REST Args)
	  (* * Apply the cardtypefn Fn of Card's super type to the given args.)
	  (BQUOTE (NC.ApplySupersFn , Fn , Card ,@ Args)))
)
(* * Creating Notecards and fileboxes)

(DEFINEQ

(NCP.CreateCard
  [LAMBDA (Type NoteFile Title NoDisplayFlg Props ParentFileBoxes TypeSpecificArgs)
                                                             (* pmi: "10-Dec-87 10:27")

          (* * Creates a new notecard with given type, title, props and parents. Any of those args can be nil.
	  Type being NIL will cause user to be asked. Makes a card with initially empty substance.)



          (* * rht 11/20/84: Had to add a horrible kluge: if creating a document card in which embedded links may be copied, 
	  then need to have document card visible on screen. This is because ID is currently unattainable from just the 
	  Textstream -
	  need to have a window. Until that is fixed, we temporarily bring up the document card while it's being filled in.)



          (* * rht 11/17/85: Updated to handle new card and notefile objects.)



          (* * rht 7/10/86: Ripped out the above described document kludge.)



          (* * rht 8/21/86: Now sticks (APPEND Props) on the card's proplist, i.e. a top level copy.)



          (* * rht 11/16/86: Changed call to NCP.ReportError)



          (* * dsj 9/23/87: Added (NC.RetrievePropList Card) to APPEND to preserve properties set by user's makefn.)



          (* * pmi 12/10/87: Added dsj's change; see above comment.)


    (if (NCP.CardTypeP Type)
	then (LET (Card CardIdentifier)
		    (if (SETQ CardIdentifier (NC.MakeNoteCard Type NoteFile Title NoDisplayFlg 
								    TypeSpecificArgs))
			then (SETQ Card (if (WINDOWP CardIdentifier)
						then (NCP.CardFromWindow CardIdentifier)
					      else CardIdentifier))
			       (if Props
				   then (NC.SetPropList Card (APPEND Props (
									     NC.RetrievePropList
									     Card)))
					  (NC.SetPropListDirtyFlg Card T))
			       [for Box in (MKLIST ParentFileBoxes)
				  do (if (NCP.FileBoxP Box)
					   then (NCP.FileCards Card Box)
					 else (NCP.ReportError (QUOTE NCP.CreateCard)
								   (CONCAT Box 
								      " not an existing filebox."]
			       Card))
      else (NCP.ReportError (QUOTE NCP.CreateCard)
				(CONCAT "Unknown card type: " Type))
	     NIL])

(NCP.CreateTextCard
  [LAMBDA (NoteFile Title NoDisplayFlg Props ParentFileBoxes)
                                                             (* rht: "18-Nov-85 01:13")

          (* * Creates a new TEXT notecard with given title, props and parents. Makes a card with initially empty 
	  textstream.)



          (* * rht 11/17/85: Updated to handle new card and notefile objects.)


    (NCP.CreateCard (QUOTE Text)
		      NoteFile Title NoDisplayFlg Props ParentFileBoxes])

(NCP.CreateFileBox
  [LAMBDA (NoteFile Title NoDisplayFlg Props ChildCardsBoxes ParentFileBoxes)
                                                             (* rht: "10-Jul-86 17:43")

          (* * Creates a new Filebox with given title, props, children and parents. Does not display the card, but does give 
	  it an initial textstream)



          (* * rht 11/17/85: Updated to handle new card and notefile objects.)


    (LET ((Card (NCP.CreateCard (QUOTE FileBox)
				  NoteFile Title NoDisplayFlg Props ParentFileBoxes)))
         (NCP.FileCards ChildCardsBoxes Card)
     Card])

(NCP.CreateBrowserCard
  [LAMBDA (NoteFile Title ParamList NoDisplayFlg Props ParentFileBoxes)
                                                             (* rht: " 9-Mar-87 17:27")

          (* * Creates a new browser notecard with given type, title, props, parents, starting ID and link labels.)



          (* * rht 11/17/85: Updated to handle new card and notefile objects.)



          (* * rht 8/21/86: Changed call from NCP.ValidLinkType to NCP.ValidLinkTypeP.)



          (* * rht 11/16/86: Changed call to NCP.ReportError)



          (* * rht 3/7/87: Now properly accepts link types with "←" prefixes.)


    (LET (ValidLinkTypes LinkTypes NewParamList)
         [SETQ ValidLinkTypes (for LinkType in (SETQ LinkTypes (LISTGET ParamList
										  (QUOTE LINKTYPES))
						       )
				   join (COND
					    ((EQ LinkType (QUOTE ALL))
					      (NCP.LinkTypes NoteFile))
					    ((EQ LinkType (QUOTE ←ALL))
					      (NCP.ReverseLinkTypes NoteFile))
					    ((OR (NCP.ValidLinkTypeP LinkType NoteFile)
						   (AND (STREQUAL (SUBSTRING LinkType 1 1)
								      "←")
							  (NCP.ValidLinkTypeP (SUBATOM LinkType 2)
										NoteFile)))
					      (LIST LinkType))
					    (T (NCP.ReportError (QUOTE NCP.CreateBrowserCard)
								  (CONCAT LinkType 
									" not a valid link type."))
					       NIL]
         (SETQ ValidLinkTypes (INTERSECTION ValidLinkTypes ValidLinkTypes))
         (if (AND LinkTypes (NULL ValidLinkTypes))
	     then NIL
	   else                                            (* Make a copy of the user's param list since she may 
							     not want it to get rplaca'd.)
		  (if ParamList
		      then (SETQ NewParamList (COPY ParamList))
			     (LISTPUT NewParamList (QUOTE LINKTYPES)
					ValidLinkTypes)
		    else (SETQ NewParamList (LIST (QUOTE LINKTYPES)
							ValidLinkTypes)))
		  (NCP.CreateCard (QUOTE Browser)
				    NoteFile Title NoDisplayFlg Props ParentFileBoxes NewParamList])

(NCP.CreateSketchCard
  [LAMBDA (NoteFile Title NoDisplayFlg Props ParentFileBoxes)
                                                             (* rht: "18-Nov-85 01:15")

          (* * Creates a new SKETCH/MAP notecard with given title, props and parents.)



          (* * rht 11/17/85: Updated to handle new card and notefile objects.)


    (NCP.CreateCard (QUOTE Sketch)
		      NoteFile Title NoDisplayFlg Props ParentFileBoxes])

(NCP.CreateGraphCard
  [LAMBDA (NoteFile Title NoDisplayFlg Props ParentFileBoxes)
                                                             (* rht: "18-Nov-85 01:16")

          (* * Creates a new GRAPH notecard with given title, props and parents.)



          (* * rht 11/17/85: Updated to handle new card and notefile objects.)


    (NCP.CreateCard (QUOTE Graph)
		      NoteFile Title NoDisplayFlg Props ParentFileBoxes])

(NCP.MakeDocument
  [LAMBDA (NoteFile RootCard ParamProps NoDisplayFlg Props ParentFileBoxes)
                                                             (* rht: " 2-Mar-87 22:00")

          (* * Do a MakeDocument starting from RootCard according to parameters in ParamProps if non-nil.
	  Otherwise use the default parameters. Note that ParamProps are *only* used for the duration of this MakeDocument 
	  and do not affect the default parameter values.)



          (* * rht 11/17/85: Updated to handle new card and notefile objects.)



          (* * rht 8/25/86: Now passes non-nil QuietFlg to NCP.UncacheCards.)



          (* * rht 11/16/86: Changed call to NCP.ReportError)


    (LET (CurParams DocCard WasActive)
         (if (NC.ValidCardP RootCard)
	     then (AND (NOT (SETQ WasActive (NCP.CardCachedP RootCard)))
			   (NCP.CacheCards RootCard))
		    (if ParamProps
			then (SETQ CurParams (NCP.DocumentParameters ParamProps)))
		    (SETQ DocCard (NCP.CreateCard (QUOTE Document)
						      NoteFile NIL NoDisplayFlg Props ParentFileBoxes 
						      RootCard))
		    (if ParamProps
			then (SETPROPLIST (QUOTE NC.MakeDocParameters)
					      CurParams))
		    (AND (NOT WasActive)
			   (NCP.UncacheCards RootCard T))
		    DocCard
	   else (NCP.ReportError (QUOTE NCP.MakeDocument)
				     (CONCAT RootCard " not a valid card or filebox."))
		  NIL])

(NCP.MakeLinkIndex
  [LAMBDA (NoteFile LinkTypes BackPointersP NoDisplayFlg Props ParentFileBoxes)
                                                             (* rht: " 2-Mar-87 22:00")

          (* * Do a MakeLinkIndex on LinkTypes inserting backpointers according to BackPointersP.)



          (* * rht 11/17/85: Updated to handle new card and notefile objects.)



          (* * rht 11/16/86: Changed call to NCP.ReportError)


    (LET [(ValidLinkTypes (for LinkType in (MKLIST LinkTypes)
			     join (COND
				      ((EQ LinkType (QUOTE ALL))
					(NCP.LinkTypes NoteFile))
				      ((EQ LinkType (QUOTE ←ALL))
					(NCP.ReverseLinkTypes NoteFile))
				      ((NOT (NCP.ValidLinkType LinkType NoteFile))
					(NCP.ReportError (QUOTE NCP.MakeLinkIndex)
							   (CONCAT LinkType 
								     " not a valid link label."))
					NIL)
				      (T (LIST LinkType]
         (SETQ ValidLinkTypes (INTERSECTION ValidLinkTypes ValidLinkTypes))
         (if (AND LinkTypes (NULL ValidLinkTypes))
	     then NIL
	   else (NCP.CreateCard (QUOTE LinkIndex)
				    NoteFile NIL NoDisplayFlg Props ParentFileBoxes (LIST 
										   ValidLinkTypes 
										    BackPointersP])
)
(* * Opening, closing, activating, display, etc.)

(DEFINEQ

(NCP.OpenCard
  [LAMBDA (Card Region/Position TypeSpecificArgs ReadOnly)   (* Randy.Gobbel " 5-Nov-87 16:01")

          (* * Cache this card, if necessary, and display on the screen.)



          (* * rht 11/16/86: Changed call to NCP.ReportError)


    (if (NC.ValidCardP Card)
	then [LET ((OldProc (TTY.PROCESS)))
		    (PROG1 (NC.EditNoteCard Card (OR ReadOnly (fetch (NoteFile ReadOnlyFlg)
								       of (fetch (Card NoteFile)
									       of Card)))
						Region/Position TypeSpecificArgs)
			     (AND (PROCESSP OldProc)
				    (TTY.PROCESS OldProc]
      else (NCP.ReportError (QUOTE NCP.OpenCard)
				(CONCAT Card " not an existing card or box."])

(NCP.CloseCards
  [LAMBDA (Cards QuietFlg)                                   (* Randy.Gobbel " 2-Apr-87 16:59")

          (* * Uncache and undisplay any active cards in Cards)



          (* * rht 11/16/86: Changed call to NCP.ReportError)



          (* * rht 3/9/87: Fixed so that wouldn't try to get PROCESS windowprop from NIL Win.)



          (* * rg 3/9/87 fixed args to NC.QuitCard ; added NC.ProtectedSessionOperation wrapper)



          (* * rg 4/2/87 changed NC.ProtectedSessionOperation to NCP.WithLockedCards ; added NC.IfAllCardsFree wrapper)


    (NCP.WithLockedCards (NC.IfAllCardsFree (NC.LockListOfCards (MKLIST Cards)
								  "Close Cards")
					    (for Card in (MKLIST Cards) bind Win
										     (OldProc
										       ←
										       (TTY.PROCESS)
										       )
					       do (if (NOT (NC.ValidCardP Card))
							then (NCP.ReportError "NCP.CloseCards"
										  (CONCAT Card 
							      " not an existing card or filebox."))
						      elseif (AND (NCP.CardCachedP Card)
								      (NEQ (NC.QuitCard Card T 
											    NIL NIL 
											    NIL NIL 
											 QuietFlg)
									     (QUOTE CANCELLED))
								      (SETQ Win (NC.FetchWindow
									  Card)))
							then
							 (bind [Process ←
									  (AND Win
										 (WINDOWPROP
										   Win
										   (QUOTE PROCESS]
							    until (OR (NULL Process)
									  (PROCESS.FINISHEDP 
											  Process))
							    do (BLOCK)))
					       finally (AND (PROCESSP OldProc)
								(TTY.PROCESS OldProc))
							 (RETURN Card])

(NCP.DisplayCard
  [LAMBDA (Card Region/Position TypeSpecificArgs ReadOnly)   (* Randy.Gobbel " 5-Nov-87 16:01")

          (* * display Card on the screen.)



          (* * rht 11/16/86: Changed call to NCP.ReportError)



          (* * rg 11/4/87 added ReadOnly)


    (if (NC.ValidCardP Card)
	then (if (NCP.CardCachedP Card)
		   then [LET ((OldProc (TTY.PROCESS)))
			       (PROG1 (NC.EditNoteCard Card (OR ReadOnly
								      (fetch (NoteFile ReadOnlyFlg)
									 of (fetch (Card NoteFile)
										 of Card)))
							   Region/Position TypeSpecificArgs)
					(AND (PROCESSP OldProc)
					       (TTY.PROCESS OldProc]
		 else (NCP.ReportError (QUOTE NCP.DisplayCard)
					   (CONCAT Card 
					     " must be cached before displayed: NCP.DisplayCard.")))
      else (NCP.ReportError (QUOTE NCP.DisplayCard)
				(CONCAT Card " not an existing card or box."])

(NCP.UndisplayCards
  [LAMBDA (Cards QuietFlg WriteChangesFlg)                   (* Randy.Gobbel " 4-Mar-87 14:42")

          (* * If card is valid and displayed, then undisplay it but leave it cached. If WriteChangesFlg is non-nil, then 
	  save changes to the file, otherwise saving will wait until card is uncached.)



          (* * rht 11/16/86: Changed call to NCP.ReportError)


    (for Card in (MKLIST Cards) do [COND
					     ((NOT (NC.ValidCardP Card))
					       (NCP.ReportError (QUOTE NCP.UndisplayCards)
								  (CONCAT Card 
							      " not an existing card or filebox.")))
					     ((NOT (NCP.CardDisplayedP Card))
					       (NCP.PrintMsg NIL T Card 
						       " already undisplayed: NCP.UndisplayCards"))
					     (T (LET ((OldProc (TTY.PROCESS)))
						     (PROG1 (NC.QuitCard Card T (NOT 
										  WriteChangesFlg)
									     NIL NIL NIL QuietFlg T)
							      (AND (PROCESSP OldProc)
								     (TTY.PROCESS OldProc]
       finally (RETURN Card])

(NCP.CacheCards
  [LAMBDA (Cards)                                            (* rht: " 2-Mar-87 22:01")

          (* * Cache all the info for any inactive cards in Cards)



          (* * rht 11/16/86: Changed call to NCP.ReportError)


    (for Card in (MKLIST Cards) do (COND
					     ((NOT (NC.ValidCardP Card))
					       (NCP.ReportError (QUOTE NCP.CacheCards)
								  (CONCAT Card 
							      " not an existing card or filebox.")))
					     ((NCP.CardCachedP Card)
					       (NCP.PrintMsg NIL T Card 
							       " already cached: NCP.CacheCards."))
					     (T (NC.GetNoteCard Card)))
       finally (RETURN Card])

(NCP.UncacheCards
  [LAMBDA (Cards QuietFlg)                                   (* Randy.Gobbel " 4-Mar-87 14:43")

          (* * Uncache and undisplay any active cards in Cards)



          (* * rht 11/16/86: Changed call to NCP.ReportError)


    (for Card in (MKLIST Cards) do (COND
					     ((NOT (NC.ValidCardP Card))
					       (NCP.ReportError (QUOTE NCP.UncacheCards)
								  (CONCAT Card 
							      " not an existing card or filebox.")))
					     ((NOT (NCP.CardCachedP Card))
					       (NCP.ReportError (QUOTE NCP.UncacheCards)
								  (CONCAT Card 
							    " must be cached before can uncache.")))
					     ((NCP.CardDisplayedP Card)
					       (NCP.ReportError (QUOTE NCP.UncacheCards)
								  (CONCAT Card 
						       " must be undisplayed before can uncache.")))
					     (T (NC.QuitCard Card NIL NIL NIL NIL NIL QuietFlg])

(NCP.CardCachedP
  [LAMBDA (Card)                                             (* rht: "10-Jul-86 21:57")

          (* * Return non-nil if card is cached.)


    (NC.ActiveCardP Card])

(NCP.CardDisplayedP
  [LAMBDA (Card)                                             (* rht: "10-Jul-86 22:08")

          (* * Return non-nil if card is currently displayed on screen.)


    (AND (NCP.CardCachedP Card)
	   (NCP.WindowFromCard Card])

(NCP.CardWindow
  [LAMBDA (Card)                                             (* rht: "18-Nov-85 17:43")

          (* * Returns T if card corresponding to Card is currently on the screen, i.e. has an active window.)



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


    (AND (NC.ValidCardP Card)
	   (NC.FetchWindow Card])

(NCP.WindowFromCard
  [LAMBDA (Card)                                             (* rht: "11-Jul-86 10:21")

          (* * Returns T if card corresponding to Card is currently on the screen, i.e. has an active window.)


    (NCP.CardWindow Card])

(NCP.CardFromWindow
  [LAMBDA (Win)                                              (* rht: "10-Jul-86 22:10")

          (* * Return the card corresponding to Win, if Win is a notecard window.)


    (NC.CoerceToCard Win])

(NCP.CardFromTextStream
  [LAMBDA (TextStream)                                       (* rht: "12-Jul-86 14:55")

          (* * Return the card corresponding to TextStream, if TextStream is a text card's textstream.)


    (NC.CoerceToCard TextStream])
)
(* * Accessing cards and boxes)

(DEFINEQ

(NCP.CardType
  [LAMBDA (Card)                                             (* rht: "18-Nov-85 01:23")

          (* * Return the type of ID or NIL if no such ID.)



          (* * rht 11/17/85: Updated to handle new card and notefile objects.)


    (AND (NC.ValidCardP Card)
	   (NC.RetrieveType Card])

(NCP.ValidCardP
  [LAMBDA (Card)                                             (* pmi: "10-Dec-87 11:34")

          (* * Non-nil if ID corresponds to extant card in current notefile. Returns type of card or nil.)



          (* * pmi 12/10/87: Changed to call NC.ValidCardP rather than NC.CardType (how odd!) as a check for validity.
	  Also now returns the card if successful.)


    (if (NC.ValidCardP Card)
	then Card])

(NCP.CardTitle
  [LAMBDA Args                                               (* rht: " 2-Mar-87 22:01")

          (* * Expects one or two args, the Card and an optional new title. If the latter is present then change the title of
	  ID. In any case, return the old title.)



          (* * rht 11/17/85: Updated to handle new card and notefile objects.)



          (* * rht 11/16/86: Changed call to NCP.ReportError)


    (LET (Card)
         (COND
	   ((AND (NEQ Args 1)
		   (NEQ Args 2))
	     (NCP.ReportError (QUOTE NCP.CardTitle)
				"Improper number of arguments to NCP.CardBoxTitle.")
	     NIL)
	   [(NC.ValidCardP (SETQ Card (ARG Args 1)))
	     (PROG1 (NC.RetrieveTitle Card)
		      (if (EQ Args 2)
			  then (NC.AssignTitle Card NIL (ARG Args 2]
	   (T (NCP.ReportError (QUOTE NCP.CardTitle)
				 (CONCAT Card " not an existing card or box."))
	      NIL])

(NCP.FileCards
  [LAMBDA (CardBoxList BoxList)                              (* rht: " 2-Mar-87 22:01")

          (* * File every card or box in CardBoxList in every box in BoxList. Either arg can be an atom or list.
	  Check for cycles.)



          (* * rht 11/17/85: Updated to handle new card and notefile objects.)



          (* * rht 11/16/86: Changed call to NCP.ReportError)


    (SETQ CardBoxList (for Card in (MKLIST CardBoxList)
			   unless (if (NOT (NC.ValidCardP Card))
					then (NCP.ReportError (QUOTE NCP.FileCards)
								  (CONCAT Card 
						     " not an existing card or box.  Can't file."))
					       T)
			   collect Card))
    (SETQ BoxList (for Card in (MKLIST BoxList) unless (if (NOT (NCP.FileBoxP Card))
								     then (NCP.ReportError
									      (QUOTE NCP.FileCards)
									      (CONCAT Card 
						" not an existing filebox.  Can't be filed into."))
									    T)
		       collect Card))
    (if (AND BoxList CardBoxList)
	then (for Box in BoxList when (NC.FileBoxCollectChildren NIL Box CardBoxList T)
		  collect Box)
      else NIL])

(NCP.UnfileCards
  [LAMBDA (CardBoxList BoxList)                              (* rht: " 2-Mar-87 22:01")

          (* * Unfile every card or box in CardBoxList from every box in BoxList. Either arg can be a litatom ID.
	  Either can also be the litatom ALL. If CardBoxList is ALL then clear out all children from every element of 
	  BoxList. If BoxList is ALL then unlink all parents of every element of CardBoxList.)



          (* * rht 11/17/85: Updated to handle new card and notefile objects.)



          (* * rht 11/16/86: Changed call to NCP.ReportError)


    (if (NEQ CardBoxList (QUOTE ALL))
	then (SETQ CardBoxList (for Card in (MKLIST CardBoxList)
				      unless (if (NOT (NC.ValidCardP Card))
						   then (NCP.ReportError (QUOTE NCP.UnfileCards)
									     (CONCAT Card 
						   " not an existing card or box.  Can't unfile."))
							  T)
				      collect Card)))
    (if (NEQ BoxList (QUOTE ALL))
	then (SETQ BoxList (for Card in (MKLIST BoxList)
				  unless (if (NOT (NCP.FileBoxP Card))
					       then (NCP.ReportError (QUOTE NCP.UnfileCards)
									 (CONCAT Card 
								      " not an existing filebox."))
						      T)
				  collect Card)))
    [if (NEQ CardBoxList (QUOTE ALL))
	then [if (EQ BoxList (QUOTE ALL))
		   then                                    (* Unfile every element of CardBoxList from all its 
							     parents.)
			  [for Card in CardBoxList do (NCP.DeleteLinks (NCP.GetLinks
										 NIL Card
										 (LIST 
									    NC.FiledCardLinkLabel 
									       NC.SubBoxLinkLabel]
		 else                                      (* Unfile every element of CardBoxList from a 
							     selection of its parents.)
			(for Card in CardBoxList do (for Box in BoxList
							     do (NCP.DeleteLinks
								    (NCP.GetLinks Box Card
										    (LIST 
									    NC.FiledCardLinkLabel 
									       NC.SubBoxLinkLabel]
      else (if (EQ BoxList (QUOTE ALL))
		 then (SETQ BoxList (NCP.AllBoxes)))
	     (for Box in BoxList do (NCP.DeleteLinks (NCP.GetLinks Box NIL
									     (LIST 
									    NC.FiledCardLinkLabel 
									       NC.SubBoxLinkLabel]
    (AND CardBoxList BoxList])

(NCP.CardParents
  [LAMBDA (Card)                                             (* rht: " 2-Mar-87 22:10")

          (* * Return the list of fileboxes in which Card has been filed.)



          (* * rht 11/17/85: Updated to handle new card and notefile objects.)



          (* * rht 11/16/86: Changed call to NCP.ReportError)


    (if (NC.ValidCardP Card)
	then (for Link in (NCP.GetLinks NIL Card (LIST NC.FiledCardLinkLabel 
								 NC.SubBoxLinkLabel))
		  collect (fetch (Link SourceCard) of Link))
      else (NCP.ReportError (QUOTE NCP.CardParents)
				(CONCAT Card " is not an existing card or filebox."])

(NCP.FileBoxChildren
  [LAMBDA (Box)                                              (* rht: " 2-Mar-87 22:10")

          (* * Return the list of children of Box in proper order.)



          (* * rht 11/16/86: Changed call to NCP.ReportError)


    (COND
      ((NCP.FileBoxP Box)
	(for Link in (NCP.GetLinks Box NIL (LIST NC.FiledCardLinkLabel NC.SubBoxLinkLabel))
	   collect (fetch (Link DestinationCard) of Link)))
      (T (NCP.ReportError (QUOTE NCP.FileBoxChildren)
			    (CONCAT Box " is not an existing filebox."])

(NCP.CardNeighbors
  [LAMBDA (Cards LinkTypes FollowCrossFileLinksFlg)          (* rht: " 6-Jun-87 17:41")

          (* * Return a list of cards one link from Card in the forward direction having some link of type in LinkTypes.
	  LinkTypes can contain atoms starting with "←" in which case it's a backward link. LinkTypes can contain either or 
	  both of ANY and ←ANY, meaning to include any forward or backward links, respectively.)



          (* * rht 6/6/87: Added FollowCrossFileLinksFlg; if non-nil, then try to follow cross-file links into remote 
	  notefiles, else ignore them.)


    (if (NULL LinkTypes)
	then [for Link in (NCP.GetLinks Cards)
		  join (LET ((DestCard (fetch (Link DestinationCard) of Link)))
			      (MKLIST (if (NC.CrossFileLinkCardP DestCard)
					    then (if FollowCrossFileLinksFlg
						       then (NC.GetCrossFileLinkDestCard DestCard)
						     else NIL)
					  else DestCard]
      else (LET (ForwardLinkTypes BackwardLinkTypes)
	          (for LinkType in (MKLIST LinkTypes) do (if (EQ (NTHCHAR LinkType 1)
									     (QUOTE ←))
								     then (pushnew 
										BackwardLinkTypes
										       (SUBATOM
											 LinkType 2))
								   else (pushnew ForwardLinkTypes 
										     LinkType)))
	          (UNION [AND ForwardLinkTypes (for Link
						      in (NCP.GetLinks
							     Cards NIL (if (FMEMB (QUOTE ANY)
										      
										 ForwardLinkTypes)
									   then NIL
									 else ForwardLinkTypes))
						      join
						       (LET ((DestCard (fetch (Link DestinationCard)
									  of Link)))
							    (MKLIST (if (NC.CrossFileLinkCardP
									      DestCard)
									  then (if 
									  FollowCrossFileLinksFlg
										     then
										      (
								      NC.GetCrossFileLinkDestCard
											DestCard)
										   else NIL)
									else DestCard]
			   (AND BackwardLinkTypes (for Link
						       in (NCP.GetLinks
							      NIL Cards (if (FMEMB (QUOTE
											 ANY)
										       
										BackwardLinkTypes)
									    then NIL
									  else BackwardLinkTypes))
						       join
							(LET ((SrcCard (fetch (Link SourceCard)
									  of Link)))
							     (MKLIST (if (NC.CrossFileLinkCardP
									       SrcCard)
									   then
									    (if 
									  FollowCrossFileLinksFlg
										then (
								      NC.GetCrossFileLinkDestCard
											 SrcCard)
									      else NIL)
									 else SrcCard])

(NCP.GetLinks
  [LAMBDA (Cards DestinationCards Labels NoteFile)           (* rht: "29-May-87 16:48")

          (* * Returns a list of all links from Cards to DestinationCards whose link label is one of Labels.
	  Labels can be nil, in which case all such links are returned. Cards and DestinationCards can each be atomic.
	  Each can also be nil. For example, if DestinationCards is nil, then all links pointing from Cards to anywhere with 
	  given labels are returned. Note that if both Cards and DestinationCards are nil, then will return all links whose 
	  label is one of Labels. If all three args are nil, then return all links in the current notefile.)



          (* * rht 11/17/85: Updated to handle new card and notefile objects.)



          (* * rht 8/29/86: Now blocks in loops and checks whether links cached before retrieving.)



          (* * rht 11/16/86: Changed call to NCP.ReportError)



          (* * rht&pmi 5/29/87: No longer has to uncache links because of change to NC.RetrieveFromLinks and 
	  NC.RetrieveToLinks.)


    (LET (ValidCards ValidDestinationCards)
         (SETQ Labels (MKLIST Labels))
         (SETQ ValidCards (for Card in (MKLIST Cards) eachtime (BLOCK)
			       unless (COND
					  ((NOT (NC.ValidCardP Card))
					    (NCP.ReportError (QUOTE NCP.GetLinks)
							       (CONCAT Card 
								  " not an existing card or box."))
					    T))
			       collect Card))
         (SETQ ValidDestinationCards (for Card in (MKLIST DestinationCards) eachtime
										     (BLOCK)
					  unless (COND
						     ((NOT (NC.ValidCardP Card))
						       (NCP.ReportError (QUOTE NCP.GetLinks)
									  (CONCAT Card 
								  " not an existing card or box."))
						       T))
					  collect Card))
         (COND
	   (Cards (for Card in ValidCards eachtime (BLOCK)
		     join (for Link in (NC.RetrieveToLinks Card)
			       when (COND
					(DestinationCards (FMEMB (fetch (Link DestinationCard)
								      of Link)
								   ValidDestinationCards))
					(T T))
			       when (COND
					(Labels (FMEMB (fetch (Link Label) of Link)
							 Labels))
					(T T))
			       collect Link)))
	   (DestinationCards (for Card in ValidDestinationCards eachtime (BLOCK)
				join (for Link in (NC.RetrieveFromLinks Card)
					  when (COND
						   (Labels (FMEMB (fetch (Link Label)
								       of Link)
								    Labels))
						   (T T))
					  collect Link)))
	   (T (NCP.MapLinks NoteFile (FUNCTION PROG1)
			    (FUNCTION (LAMBDA (Link)
				(if Labels
				    then (FMEMB (fetch (Link Label) of Link)
						    Labels)
				  else T])

(NCP.CardPropList
  [LAMBDA (Card)                                             (* rht: "18-Nov-85 01:45")

          (* * Return the ID's property list)



          (* * rht 11/17/85: Updated to handle new card and notefile objects.)


    (NC.RetrievePropList Card])

(NCP.CardProp
  [LAMBDA Args                                               (* rht: " 2-Mar-87 22:02")

          (* * Expects two or three arguments: ID, Property, and optional new value. Returns the old value.
	  Assigns the new value if given. Semantics are just like WINDOWPROP.)



          (* * rht 11/17/85: Updated to handle new card and notefile objects.)



          (* * rht 11/16/86: Changed call to NCP.ReportError)


    (LET (Card PropList)
         (COND
	   ((AND (NEQ Args 2)
		   (NEQ Args 3))
	     (NCP.ReportError (QUOTE NCP.CardProp)
				(CONCAT "Improper number of args: " Args))
	     NIL)
	   [(NC.ValidCardP (SETQ Card (ARG Args 1)))
	     (PROG1 (LISTGET (SETQ PropList (NC.RetrievePropList Card))
				 (ARG Args 2))
		      (if (EQ Args 3)
			  then [if PropList
				     then (LISTPUT PropList (ARG Args 2)
						       (ARG Args 3))
				   else (NC.SetPropList Card (LIST (ARG Args 2)
									 (ARG Args 3]
				 (if (NOT (NCP.CardCachedP Card))
				     then (NC.PutPropList Card)
				   else (NC.SetPropListDirtyFlg Card T]
	   (T (NCP.ReportError (QUOTE NCP.CardProp)
				 (CONCAT Card " not an existing card or box."))
	      NIL])

(NCP.CardAddProp
  [LAMBDA (Card Property ItemToAdd)                          (* rht: "28-May-87 00:27")

          (* * Adds ItemToAdd to the value of ID's Property property. Returns the old value. Same semantics as 
	  WINDOWADDPROP.)



          (* * rht 11/17/85: Updated to handle new card and notefile objects.)



          (* * rht 11/16/86: Changed call to NCP.ReportError)



          (* * rht 5/28/87: Fixed bug reported by Mark Frisse. Now works if PropList is NIL, as for a new card.)


    (if (NC.ValidCardP Card)
	then (LET* ((PropList (NC.RetrievePropList Card))
		      (OldPropValue (LISTGET PropList Property)))
		     (if (NOT (FMEMB ItemToAdd (MKLIST OldPropValue)))
			 then [if PropList
				    then (LISTPUT PropList Property (APPEND (MKLIST 
										     OldPropValue)
										  (LIST ItemToAdd)))
				  else (NC.SetPropList Card (BQUOTE (, Property (, ItemToAdd]
				(if (NOT (NCP.CardCachedP Card))
				    then (NC.PutPropList Card)
				  else (NC.SetPropListDirtyFlg Card T)))
		 OldPropValue)
      else (NCP.ReportError (QUOTE NCP.CardAddProp)
				(CONCAT Card " not an existing card or box."))
	     NIL])

(NCP.CardDelProp
  [LAMBDA (Card Property ItemToDelete)                       (* rht: " 2-Mar-87 22:02")

          (* * Deletes ItemToDelete from the Property prop of Card if it is there, returning the previous list.
	  If it's not there, then return NIL. Same semantics as WINDOWDELPROP.)



          (* * rht 11/17/85: Updated to handle new card and notefile objects.)



          (* * rht 11/16/86: Changed call to NCP.ReportError)


    (if (NC.ValidCardP Card)
	then (LET* ((PropList (NC.RetrievePropList Card))
		      (OldPropValue (LISTGET PropList Property)))
		     (COND
		       ((NLISTP OldPropValue)
			 NIL)
		       ((FMEMB ItemToDelete OldPropValue)
			 (LISTPUT PropList Property (for Item in OldPropValue
							 unless (EQ Item ItemToDelete)
							 collect Item))
			 (if (NOT (NCP.CardCachedP Card))
			     then (NC.PutPropList Card)
			   else (NC.SetPropListDirtyFlg Card T))
			 OldPropValue)
		       (T NIL)))
      else (NCP.ReportError (QUOTE NCP.CardDelProp)
				(CONCAT Card " not an existing card or box."))
	     NIL])

(NCP.CardSubstance
  [LAMBDA Args                                               (* rht: " 2-Mar-87 22:03")

          (* * Return the substance for this card.)



          (* * rht 11/17/85: Updated to handle new card and notefile objects.)



          (* * rht 8/8/86: Now can accept one or two args. Always returns old substance, but will replace substance with 
	  second arg if present.)



          (* * 8/25/86: Now passes non-nil QuietFlg to NCP.CloseCards.)



          (* * rht 11/16/86: Changed call to NCP.ReportError)


    (LET (Card)
         (COND
	   ((AND (NEQ Args 1)
		   (NEQ Args 2))
	     (NCP.ReportError (QUOTE NCP.CardSubstance)
				(CONCAT "Improper number of args: " Args))
	     NIL)
	   [(NCP.ValidCardP (SETQ Card (ARG Args 1)))
	     (LET (WasActive)
	          (OR (SETQ WasActive (NCP.CardCachedP Card))
			(NCP.CacheCards Card))
	          (PROG1 (NC.FetchSubstance Card)
			   (if (EQ Args 2)
			       then (NC.SetSubstance Card (ARG Args 2))
				      (NCP.MarkCardDirty Card))
			   (OR WasActive (NCP.CloseCards Card T]
	   (T (NCP.ReportError (QUOTE NCP.CardSubstance)
				 (CONCAT Card " not an existing card."))
	      NIL])

(NCP.CardRegion
  [LAMBDA Args                                               (* rht: "23-May-87 22:42")

          (* * Return the substance for this card.)



          (* * rht 11/17/85: Updated to handle new card and notefile objects.)



          (* * rht 8/25/86: Now passes non-nil QuietFlg to NCP.UncacheCards.)



          (* * rht 11/16/86: Changed call to NCP.ReportError)



          (* * rht 5/23/87: Now takes optional second argument which should be new region for Card.)


    (LET (Card)
         (COND
	   ((AND (NEQ Args 1)
		   (NEQ Args 2))
	     (NCP.ReportError (QUOTE NCP.CardRegion)
				(CONCAT "Improper number of args: " Args))
	     NIL)
	   [(NCP.ValidCardP (SETQ Card (ARG Args 1)))
	     (LET (WasActive Region)
	          (OR (SETQ WasActive (NCP.CardCachedP Card))
			(NCP.CacheCards Card))
	          (PROG1 (NC.FetchRegion Card)
			   [if (EQ Args 2)
			       then (if (REGIONP (SETQ Region (ARG Args 2)))
					  then (NC.SetRegion Card Region)
						 (if (NCP.CardDisplayedP Card)
						     then (SHAPEW (NCP.CardWindow Card)
								      Region)
						   else (NC.PutRegion Card))
					else (NCP.ReportError (QUOTE NCP.CardRegion)
								  (CONCAT Region 
									   " not a valid REGION."]
			   (OR WasActive (NCP.CloseCards Card T]
	   (T (NCP.ReportError (QUOTE NCP.CardRegion)
				 (CONCAT Card " not an existing card."))
	      NIL])

(NCP.CardAddText
  [LAMBDA (Card Text Loc)                                    (* rht: " 2-Mar-87 22:03")

          (* * Adds the Text to ID's window at the given Loc. Loc defaults to the current cursor position.)



          (* * rht 11/17/85: Updated to handle new card and notefile objects.)



          (* * rht 8/25/86: Now passes non-nil QuietFlg to NCP.UncacheCards.)



          (* * rht 11/16/86: Changed call to NCP.ReportError)


    (PROG (WasActiveP)
	    (if (NOT (NC.ValidCardP Card))
		then (NCP.ReportError (QUOTE NCP.CardAddText)
					  (CONCAT Card " is not an existing card or filebox."))
		       (RETURN NIL))
	    (if (NOT (NCP.TextBasedP (NCP.CardType Card)))
		then (NCP.ReportError (QUOTE NCP.CardAddText)
					  "Can only add text to cards with type Text.")
		       (RETURN NIL))
	    (if (NOT (SETQ WasActiveP (NCP.CardCachedP Card)))
		then (NCP.CacheCards Card))
	    (NCP.ChangeLoc Card Loc)
	    (TEDIT.INSERT (NC.FetchSubstance Card)
			    Text)
	    (NC.MarkCardDirty Card)
	    (if (NOT WasActiveP)
		then (NCP.UncacheCards Card T))
	    (RETURN Card])

(NCP.ChangeLoc
  [LAMBDA (Card Loc)                                         (* rht: " 2-Mar-87 22:03")

          (* * Changes the location within ID's textstream to the new loc Loc. Loc can be the litatoms START or END, a 
	  number, or nil. The latter indicates to use the current cursor position. Note that we don't mark card as dirty just
	  because its selection changed. Note that this leaves card active even if inactive when we were called.)



          (* * rht 11/17/85: Updated to handle new card and notefile objects.)



          (* * rht 11/16/86: Changed call to NCP.ReportError)


    (if (AND (NC.ValidCardP Card)
		 (NCP.TextBasedP Card))
	then (if (NOT (NCP.CardCachedP Card))
		   then (NCP.CacheCards Card))
	       (LET ((Stream (NC.FetchSubstance Card)))
		    [SELECTQ Loc
			       ((START 0)
				 (TEDIT.SETSEL Stream 0 0 (QUOTE RIGHT)))
			       (END (TEDIT.SETSEL Stream (ADD1 (fetch (TEXTOBJ TEXTLEN)
								      of (TEXTOBJ Stream)))
						    0
						    (QUOTE RIGHT)))
			       (AND (FIXP Loc)
				      (GEQ Loc 0)
				      (TEDIT.SETSEL Stream Loc 0 (QUOTE RIGHT]
		Card)
      else (NCP.ReportError (QUOTE NCP.ChangeLoc)
				(CONCAT Card " not an existing card or not TEdit based."))
	     NIL])

(NCP.DeleteCards
  [LAMBDA (Cards)                                            (* rht: " 2-Mar-87 22:04")

          (* * Delete the given cards and boxes. Or just one, if Cards is atomic.)



          (* * rht 11/17/85: Updated to handle new card and notefile objects.)



          (* * rht 11/7/86: Now passes flg args to NC.DeleteNoteCards to prevent confirm messages to user.)



          (* * rht 11/16/86: Changed call to NCP.ReportError)


    (SETQ Cards (for Card in (MKLIST Cards) unless (if (NOT (NC.ValidCardP Card))
								 then (NCP.ReportError
									  (QUOTE NCP.DeleteCards)
									  (CONCAT Card 
							       " is not an existing card or box."))
									T)
		     collect Card))
    (AND Cards (NC.DeleteNoteCards Cards T NIL NIL T T])

(NCP.FileBoxP
  [LAMBDA (Card)                                             (* rht: "18-Nov-85 01:58")

          (* * Return T if Card is a Filebox.)



          (* * rht 11/17/85: Updated to handle new card and notefile objects.)


    (EQ (NCP.CardType Card)
	  (QUOTE FileBox])

(NCP.AllCards
  [LAMBDA (NoteFile)                                         (* rht: "18-Nov-85 18:19")

          (* * Return a list of IDs of all cards and boxes.)



          (* * rht 11/17/85: Updated to handle new card and notefile objects.)


    (NC.MapCards NoteFile (FUNCTION PROG1)
		 (FUNCTION TRUE])

(NCP.AllBoxes
  [LAMBDA (NoteFile)                                         (* rht: "18-Nov-85 18:19")

          (* * Return a list of all existing fileboxes.)



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


    (NC.MapCards NoteFile (FUNCTION PROG1)
		 (FUNCTION NCP.FileBoxP])

(NCP.ContentsFileBox
  [LAMBDA (NoteFile)                                         (* rht: "18-Nov-85 02:13")

          (* * Return the top level contents file box.)



          (* * rht 11/17/85: Updated to handle new card and notefile objects.)


    (fetch (NoteFile TableOfContentsCard) of NoteFile])

(NCP.OrphansFileBox
  [LAMBDA (NoteFile)                                         (* rht: "18-Nov-85 02:14")

          (* * Return the orphans contents file box.)



          (* * rht 11/17/85: Updated to handle new card and notefile objects.)


    (fetch (NoteFile OrphansCard) of NoteFile])

(NCP.ToBeFiledFileBox
  [LAMBDA (NoteFile)                                         (* rht: "18-Nov-85 02:15")

          (* * Return the To be filed file box.)



          (* * rht 11/17/85: Updated to handle new card and notefile objects.)


    (fetch (NoteFile ToBeFiledCard) of NoteFile])

(NCP.NoteFileFromCard
  [LAMBDA (Card)                                             (* rht: "12-Jul-86 16:22")

          (* * Get the card's notefile.)


    (AND (NC.ValidCardP Card)
	   (fetch (Card NoteFile) of Card])

(NCP.CardNoteFile
  [LAMBDA (Card)                                             (* rht: "12-Jul-86 16:22")

          (* * Get the card's notefile.)


    (AND (NC.ValidCardP Card)
	   (fetch (Card NoteFile) of Card])

(NCP.SameCardP
  [LAMBDA (Card1 Card2)                                      (* rht: " 2-Mar-87 22:10")

          (* * Returns non-nil if two cards are the same.)



          (* * rht 11/16/86: Changed call to NCP.ReportError)


    (if (AND (NCP.ValidCardP Card1)
		 (NCP.ValidCardP Card2))
	then (NC.SameCardP Card1 Card2)
      else (NCP.ReportError (QUOTE NCP.SameCardP)
				(CONCAT "Args not valid cards: " Card1 Card2])

(NCP.CoerceToCard
  [LAMBDA (CardIdentifier)                                   (* rht: " 8-Aug-86 13:50")

          (* * Return the card object associated with CardIdentifier which can currently be any of a card object, window or 
	  text stream.)


    (NC.CoerceToCard CardIdentifier])

(NCP.DetermineDisplayRegion
  [LAMBDA (Card Region/Position)                             (* rht: " 8-Aug-86 12:09")

          (* * Returns the region that Card would occupy if displayed. If Region/Position not passed in, then checks previous
	  size or default heights and widths for the card type. Also knows about BringUpCardAtPreviousPos.)


    (NC.DetermineDisplayRegion Card Region/Position])

(NCP.LockListOfCards
  [LAMBDA (CardIdentifiers Operation)                        (* Randy.Gobbel "23-Apr-87 14:57")

          (* * rg 4/23/87 created)


    (if (NOT (BOUNDP (QUOTE CardListResetVar)))
	then (NC.ReportError (QUOTE NCP.LockListOfCards)
				 "NCP.LockListOfCards called without RESETLST wrapper"))
    (NC.LockListOfCards CardIdentifiers Operation])

(NCP.GetCrossFileLinkDestCard
  [LAMBDA (CrossFileLinkCard InterestedWindow Don'tOpenDestNoteFileFlg)
                                                             (* rht: " 8-Jun-87 23:24")

          (* * Try to get the remote card corresponding to the given cross-file link card.)


    (AND (NCP.ValidCardP CrossFileLinkCard)
	   (EQ (NCP.CardType CrossFileLinkCard)
		 (QUOTE CrossFileLink))
	   (NC.GetCrossFileLinkDestCard CrossFileLinkCard InterestedWindow Don'tOpenDestNoteFileFlg]
)

(NCP.CardBeingDeletedP
  [LAMBDA (Card)                                             (* pmi: "10-Dec-87 11:40")

          (* * pmi 12/10/87: Created to provide NC.FetchBeingDeletedFlg for the programmer's interface.)


    (NC.FetchBeingDeletedFlg Card])

(NCP.NewCardP
  [LAMBDA (Card)                                             (* pmi: "21-Oct-87 15:54")

          (* * pmi 10/21/87: First created. Allows prog int users to tell if a card has been saved yet.)


    (NC.FetchNewCardFlg Card])
)
(DECLARE: EVAL@COMPILE 
[DEFMACRO NCP.MapCards (NoteFile Function &OPTIONAL CollectResultPredicate)
	  (* * Map down all notecards (including fileboxes)
	     in NoteFile performing Function to each. If CollectResultPredicate is non-nil, then 
	     collect the results of applying Function to those cards satisfying 
	     CollectResultPredicate.)
	  (* * rht 7/13/86: Now only works on non-deleted cards.)
	  (* * rht 7/17/86: rearranged slightly.)
	  (BQUOTE (NC.MapCards , NoteFile , [AND Function (BQUOTE (FUNCTION (LAMBDA
									      (Card)
									      (AND (NCP.ValidCardP
										     Card)
										   (APPLY* , Function 
											   Card]
			       ,
			       (AND CollectResultPredicate (BQUOTE (FUNCTION (LAMBDA
									       (Card)
									       (AND (NCP.ValidCardP
										      Card)
										    (APPLY* , 
									   CollectResultPredicate 
											    Card]
[DEFMACRO NCP.MapCardsOfType (Types NoteFile Function &OPTIONAL CollectResultPredicate)
	  (* * Map down all fileboxes in the current notefile, performing Function to each. If 
	     CollectResultPredicate is non-nil, then collect the results of applying Function to 
	     those cards satisfying CollectResultPredicate.)
	  (* * rht 7/12/86: Now takes arbitrary types to map over.)
	  (* * rht 7/17/86: rearranged slightly.)
	  (BQUOTE (NCP.MapCards , NoteFile , [AND Function
						  (BQUOTE (FUNCTION
							    (LAMBDA
							      (Card)
							      (AND (FMEMB (NCP.CardType Card)
									  (MKLIST , Types))
								   (APPLY* (FUNCTION , Function)
									   Card]
				,
				(AND CollectResultPredicate
				     (BQUOTE (FUNCTION (LAMBDA (Card)
							       (AND (FMEMB (NCP.CardType Card)
									   (MKLIST , Types))
								    (APPLY* (FUNCTION , 
									   CollectResultPredicate)
									    Card]
)
(DECLARE: EVAL@COMPILE 
[DEFMACRO NCP.WithLockedCards (&BODY Body)
	  (BQUOTE (LET (CardListResetVar)
		       (NAMED-RESETLST CardListResetVar ,@ Body]
)
(* * Collecting, copying, moving, deleting, cards)

(DEFINEQ

(NCP.CollectCards
  [LAMBDA (RootCards LinkTypes MaxDepth FollowCrossFileLinksFlg)
                                                             (* pmi: " 4-Dec-87 15:57")

          (* * Starting from RootCards and following link of types in LinkTypes to a max depth of MaxDepth, collect and 
	  return all cards encountered. LinkTypes can contain backward links.)



          (* * rht 8/29/86: Now handles case of NULL MaxDepth. Also handles case when RootCards is single card instead of 
	  list.)



          (* * rht 6/6/87: Added FollowCrossFileLinksFlg; if non-nil, then try to follow cross-file links into remote 
	  notefiles, else ignore them.)



          (* * pmi 12/4/87: Now returns list of cards collected with NO duplicates.)


    (OR MaxDepth (SETQ MaxDepth 65535))
    (if (LEQ MaxDepth 0)
	then RootCards
      else (LET (RealFringe Collection)
	          (RESETLST [RESETSAVE NIL (QUOTE (PROGN (for Card in Collection
								    do (NC.SetUserDataProp
									   Card
									   (QUOTE SeenBefore)
									   NIL]
			      (SETQ RealFringe (MKLIST RootCards))
			      (SETQ Collection (APPEND (MKLIST RootCards)))
			      (for Card in Collection do (NC.SetUserDataProp Card
										     (QUOTE 
										       SeenBefore)
										     T))
			      (for Depth from 1 to MaxDepth eachtime (BLOCK) bind Fringe
				 do (SETQ Fringe (NCP.CardNeighbors RealFringe LinkTypes 
									  FollowCrossFileLinksFlg))
				      (if (NULL Fringe)
					  then (RETURN Collection)
					else (SETQ RealFringe (for Card in Fringe
								     when
								      (NOT (NC.FetchUserDataProp
									       Card
									       (QUOTE SeenBefore)))
								     collect (NC.SetUserDataProp
										 Card
										 (QUOTE SeenBefore)
										 T)
									       (SETQ Collection
										 (CONS Card 
										       Collection))
									       Card)))
				 finally (RETURN Collection])

(NCP.CopyCards
  [LAMBDA (Cards DestNoteFileOrFileBox RootCards QuietFlg CopyExternalToLinksMode)
                                                             (* pmi: "29-Oct-87 16:15")

          (* * Make copies of Cards and all links among them, not including external links. RootCards should be a subset of 
	  Cards or nil. If nil, then all cards in Cards are considered roots. If DestNoteFileOrFileBox is a filebox, then all
	  roots are filed in that box, otherwise, the contents box of the notefile is used.)



          (* * Note that all cards currently must be in the same notefile.)



          (* * pmi 10/29/87: Added CopyExternalToLinksMode argument to be passed down to NC.CopyCards.)


    (NC.CopyCards Cards DestNoteFileOrFileBox RootCards QuietFlg NIL CopyExternalToLinksMode])

(NCP.MoveCards
  [LAMBDA (Cards DestNoteFileOrFileBox RootCards QuietFlg CopyExternalToLinksMode)
                                                             (* pmi: "29-Oct-87 11:19")

          (* * pmi 10/29/87: Move cards into a filebox.)


    (NC.MoveCards Cards DestNoteFileOrFileBox RootCards QuietFlg NIL CopyExternalToLinksMode])
)
(* * Creating and accessing links)

(DEFINEQ

(NCP.CreateLink
  [LAMBDA (Source Destination LinkType DisplayMode)          (* rht: " 2-Mar-87 22:11")

          (* * Create a link from Source to Destination. Source can be a card or a list of two things;
	  card and location spec. Location spec can be as in NCP.ChangeLoc documentation with the added option of the atom 
	  GLOBAL meaning that this should be a global link.)


    (LET (SourceLoc SourceCard)
         (COND
	   ((NC.ValidCardP Source)
	     (NCP.LocalGlobalLink LinkType Source Destination NIL DisplayMode))
	   ((OR [NOT (NC.ValidCardP (SETQ SourceCard (CAR Source]
		  (NLISTP Source)
		  (NULL (CDR Source)))
	     (NCP.ReportError (QUOTE NCP.CreateLink)
				(CONCAT 
			  "'Source' arg is not either a card or a list of card and atom or num: "
					  Source)))
	   ((EQ (SETQ SourceLoc (CADR Source))
		  (QUOTE GLOBAL))
	     (NCP.GlobalGlobalLink LinkType SourceCard Destination))
	   ((OR (FMEMB (CADR Source)
			   (QUOTE (START END NIL)))
		  (FIXP SourceLoc))
	     (NCP.LocalGlobalLink LinkType SourceCard Destination SourceLoc DisplayMode))
	   (T (NCP.ReportError (QUOTE NCP.CreateLink)
				 (CONCAT 
			  "'Source' arg is not either a card or a list of card and atom or num: "
					   Source])

(NCP.LocalGlobalLink
  [LAMBDA (LinkType SourceCard DestinationCard FromLoc DisplayMode)
                                                             (* rht: "27-May-87 11:12")

          (* * Create a link from within the text of the SourceCard card to the DestinationCard card.)



          (* * rht 4/1/85: Changed to handle old-style link display modes.)



          (* * rht 11/17/85: Updated to handle new card and notefile objects.)



          (* * rht 8/25/86: Now passes non-nil QuietFlg to NCP.UncacheCards.)



          (* * rht 11/16/86: Changed call to NCP.ReportError)



          (* * rht 5/27/87: Changed call to NCP.CoerceToLinkDisplayMode slightly.)


    (PROG ((CoercedDisplayMode (NCP.CoerceToLinkDisplayMode (OR DisplayMode SourceCard)))
	     WasActive NoteFile)
	    (if (NULL CoercedDisplayMode)
		then (NCP.ReportError (QUOTE NCP.LocalGlobalLink)
					  (CONCAT DisplayMode " is invalid link display mode."
						    (CHARACTER 13)
						    "No link created."))
		       (RETURN NIL))
	    (if (EQ LinkType NC.FiledCardLinkLabel)
		then (if (AND (NOT (NCP.FileBoxP DestinationCard))
				    (NCP.FileBoxP SourceCard))
			   then (OR (SETQ WasActive (NCP.CardCachedP SourceCard))
					(NCP.CacheCards SourceCard))
				  (NCP.ChangeLoc SourceCard FromLoc)
				  (NCP.FileCards DestinationCard SourceCard)
				  [RETURN (PROG1 (CAR (NCP.GetLinks SourceCard 
									    DestinationCard 
									    NC.FiledCardLinkLabel))
						     (OR WasActive (NCP.UncacheCards SourceCard T]
			 else (NCP.ReportError (QUOTE NCP.LocalGlobalLink)
						   (CONCAT 
						   "FiledCard link must be from a box to a card."
							     (CHARACTER 13)
							     "No link created."))
				(RETURN NIL)))
	    (if (EQ LinkType NC.SubBoxLinkLabel)
		then (if (AND (NCP.FileBoxP DestinationCard)
				    (NCP.FileBoxP SourceCard))
			   then (OR (SETQ WasActive (NCP.CardCachedP SourceCard))
					(NCP.CacheCards SourceCard))
				  (NCP.ChangeLoc SourceCard FromLoc)
				  (NCP.FileCards DestinationCard SourceCard)
				  [RETURN (PROG1 (CAR (NCP.GetLinks SourceCard 
									    DestinationCard 
									    NC.SubBoxLinkLabel))
						     (OR WasActive (NCP.UncacheCards SourceCard T]
			 else (NCP.ReportError (QUOTE NCP.LocalGlobalLink)
						   (CONCAT 
						       "SubBox link must be from a box to a box."
							     (CHARACTER 13)
							     "No link created."))
				(RETURN NIL)))             (* Inserting non-hierarchical link into a filebox.)
	    (if (NCP.FileBoxP SourceCard)
		then (NCP.ReportError (QUOTE NCP.LocalGlobalLink)
					  (CONCAT 
				 "Local links from fileboxes must be either SubBox or FiledCard."
						    (CHARACTER 13)
						    "No link created."))
		       (RETURN NIL))
	    (if [NOT (FMEMB LinkType (NCP.LinkTypes (SETQ NoteFile (fetch (Card NoteFile)
										of SourceCard]
		then (if (NC.AskYesOrNo (CONCAT 
						   "That link type hasn't been used in NoteFile "
							(fetch (NoteFile FullFileName)
							   of NoteFile)
							(CHARACTER 13)
							"Want to create a new link type: " LinkType 
							"? ")
					      "--" NIL T (NC.AttachPromptWindow
						(WFROMMENU (fetch (NoteFile Menu) of NoteFile)))
					      NIL NIL)
			   then (NCP.CreateLinkType LinkType NoteFile)
			 else (RETURN NIL)))
	    (OR (SETQ WasActive (NCP.CardCachedP SourceCard))
		  (NCP.CacheCards SourceCard))
	    (AND FromLoc (NCP.ChangeLoc SourceCard FromLoc))
	    (RETURN (PROG1 (NC.InsertLinkInText (NC.FetchSubstance SourceCard)
						      LinkType DestinationCard SourceCard 
						      CoercedDisplayMode)
			       (OR WasActive (NCP.UncacheCards SourceCard T])

(NCP.GlobalGlobalLink
  [LAMBDA (LinkType FromCard ToCard)                         (* rht: " 2-Mar-87 22:04")

          (* * This builds a global link of type LinkType between FromCard and ToID. Complains if link type is system-defined
	  with restricted semantics. If LinkType is brand new, then asks if user wants to create a new label by that name.)



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



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



          (* * rht 11/16/86: Changed call to NCP.ReportError)


    (LET ((NoteFile (fetch (Card NoteFile) of FromCard))
	  LinkTypes)
         (SETQ LinkTypes (NCP.UserLinkTypes NoteFile))
         (COND
	   ((OR (EQ LinkType NC.SourceLinkLabel)
		  (FMEMB LinkType LinkTypes))

          (* * LinkType type is okay so create the link.)


	     (NC.MakeGlobalLink NIL LinkType ToCard FromCard))
	   ((FMEMB (U-CASE LinkType)
		     NC.UCASESystemLinkLabels)
	     (NCP.ReportError (QUOTE NCP.GlobalGlobalLink)
				(CONCAT "Can't make a global-to-global link of type " LinkType "."))
	     NIL)
	   ((NC.AskYesOrNo (CONCAT "That link type hasn't been used in this NoteFile."
				       (CHARACTER 13)
				       "Want to create a new link type: " LinkType "? ")
			     "--" NIL T (NC.AttachPromptWindow (WFROMMENU (fetch (NoteFile
											 Menu)
										 of NoteFile)))
			     NIL NIL)
	     (NCP.CreateLinkType LinkType NoteFile)

          (* * LinkType type is okay so create the link.)


	     (NC.MakeGlobalLink NIL LinkType ToCard FromCard))
	   (T NIL])

(NCP.GlobalLocalLink
  [LAMBDA (LinkType FromCard ToCard ToLoc)                   (* rht: " 2-Mar-87 22:11")

          (* * Builds a link from the FromID card as a whole to within the text of the ToID card.)



          (* * rht 11/16/86: Changed call to NCP.ReportError)


    (NCP.ReportError (QUOTE NCP.GlobalLocalLink)
		       "Sorry, can't make global to local links yet."])

(NCP.LocalLocalLink
  [LAMBDA (LinkType FromCard ToCard FromLoc ToLoc)           (* rht: " 2-Mar-87 22:11")

          (* * Builds a link from within the text of the FromID card to within the text of the ToID card.)



          (* * rht 11/16/86: Changed call to NCP.ReportError)


    (NCP.ReportError (QUOTE NCP.LocalLocalLink)
		       "Sorry, can't make local to local links yet."])

(NCP.LinkDesc
  [LAMBDA (Link FollowCrossFileLinkFlg)                      (* rht: "29-Oct-87 18:59")

          (* * Return a list structure which describes Link. It consists of (label <fromdesc> <todesc>) where <fromdesc> and 
	  <todesc> describe the anchoring of the link at each end. They each have the form: (<anchormode> <ID> <loc>))



          (* * rht 11/16/86: Changed call to NCP.ReportError)



          (* * rht 10/29/87: Now takes FollowCrossFileLinkFlg arg.)


    (COND
      ((NCP.ValidLink Link)
	(LIST (fetch (Link Label) of Link)
		(NCP.LinkAnchorDesc Link NIL FollowCrossFileLinkFlg)
		(NCP.LinkAnchorDesc Link T FollowCrossFileLinkFlg)))
      (T (NCP.ReportError (QUOTE NCP.LinkDesc)
			    (CONCAT "No such link: " Link])

(NCP.LinkDisplayMode
  [LAMBDA Args                                               (* rht: " 2-Mar-87 22:05")

          (* * Takes either 1 or 2 args. The first is a link, the second an optional new link display mode.
	  Return old display mode in any case; change mode if the second arg is present.)



          (* * rht 7/12/86: Now takes a list of three elements for new displaymode rather than an instance of the 
	  LINKDISPLAYMODE record. Also calls NCP.CoerceToLinkDisplayMode.)



          (* * rht 8/25/86: Now passes non-nil QuietFlg to NCP.UncacheCards.)


    (LET (Link NewMode WasActiveFlg SourceCard)
         (COND
	   ((AND (NEQ Args 1)
		   (NEQ Args 2))
	     (NCP.ReportError (QUOTE NCP.LinkDisplayMode)
				(CONCAT "Improper number of args: " Args))
	     NIL)
	   [(NCP.ValidLink (SETQ Link (ARG Args 1)))
	     (PROG1 (fetch (Link DisplayMode) of Link)
		      (if (EQ Args 2)
			  then (if (SETQ NewMode (NCP.CoerceToLinkDisplayMode (ARG Args 2)))
				     then (OR [SETQ WasActiveFlg (NCP.CardCachedP
						      (SETQ SourceCard (fetch (Link SourceCard)
									    of Link]
						  (NCP.CacheCards SourceCard))
					    (NC.ChangeLinkDisplayMode Link NIL NewMode)
					    (OR WasActiveFlg (NCP.UncacheCards SourceCard T))
				   else (NCP.ReportError (QUOTE NCP.LinkDisplayMode)
							     (CONCAT (ARG Args 2)
								       
								 " is invalid link display mode."]
	   (T (NCP.ReportError (QUOTE NCP.LinkDisplayMode)
				 (CONCAT Link " is not a valid link."))
	      NIL])

(NCP.LinkType
  [LAMBDA Args                                               (* rht: " 2-Mar-87 22:05")

          (* * Takes either 1 or 2 args. The first is a link, the second an optional new label. Return old label in any case;
	  change label if the second arg is present.)



          (* * rht 2/8/85: Now makes sure source card of link is active before calling NC.RelabelLink.)



          (* * rht 8/25/86: Now passes non-nil QuietFlg to NCP.UncacheCards.)


    (LET (Link NewLinkType SourceCard NoteFile)
         (COND
	   ((AND (NEQ Args 1)
		   (NEQ Args 2))
	     (NCP.ReportError (QUOTE NCP.LinkType)
				(CONCAT "Improper number of args: " Args))
	     NIL)
	   [(NCP.ValidLink (SETQ Link (ARG Args 1)))
	     (PROG1 (fetch (Link Label)
			       Link)
		      (if (EQ Args 2)
			  then (COND
				   ((FMEMB (SETQ NewLinkType (ARG Args 2))
					     NC.SystemLinkLabels)
				     (NCP.ReportError (QUOTE NCP.LinkType)
							(CONCAT 
							 "Can't change label to a system label: "
								  NewLinkType)))
				   ((OR [FMEMB NewLinkType (NCP.LinkTypes
						     (SETQ NoteFile (fetch (Card NoteFile)
									 of (SETQ SourceCard
										(fetch
										  (Link SourceCard)
										   of Link]
					  (AND (NC.AskYesOrNo (CONCAT 
					      "That link type hasn't been used in this NoteFile."
									    (CHARACTER 13)
									    
							       "Want to create a new link type: "
									    NewLinkType "? ")
								  "--" NIL T NIL NIL NIL)
						 (NCP.CreateLinkType NewLinkType NoteFile)))
				     (if (NCP.CardCachedP SourceCard)
					 then (NC.RelabelLink Link NIL NewLinkType T)
				       else (NCP.CacheCards SourceCard)
					      (NC.RelabelLink Link NIL NewLinkType T)
					      (NCP.UncacheCards SourceCard T]
	   (T (NCP.ReportError (QUOTE NCP.LinkType)
				 (CONCAT Link " is not a valid link."))
	      NIL])

(NCP.LinkSource
  [LAMBDA (Link)                                             (* rht: " 2-Mar-87 22:11")

          (* * Return the SOURCEID of Link.)



          (* * rht 11/16/86: Changed call to NCP.ReportError)


    (if (NCP.ValidLink Link)
	then (fetch (Link SourceCard) of Link)
      else (NCP.ReportError (QUOTE NCP.LinkSource)
				(CONCAT Link " not an existing link."])

(NCP.LinkDestination
  [LAMBDA (Link)                                             (* rht: " 2-Mar-87 22:11")

          (* * Return the DESTINATIONID of Link.)



          (* * rht 11/16/86: Changed call to NCP.ReportError)


    (COND
      ((NCP.ValidLink Link)
	(fetch (Link DestinationCard) of Link))
      (T (NCP.ReportError (QUOTE NCP.LinkDestination)
			    (CONCAT Link " not an existing link."])

(NCP.DeleteLinks
  [LAMBDA (Links)                                            (* rht: " 2-Mar-87 22:11")

          (* * Delete each link in Links. If Links is one link, then just delete that one.)



          (* * rht 11/18/85: Updated to call new NC.DeleteLink function.)



          (* * rht 11/16/86: Changed call to NCP.ReportError)


    (for Link in (COND
		       ((type? Link Links)
			 (LIST Links))
		       (T Links))
       do (if (NCP.ValidLink Link)
		then (NC.DeleteLink Link)
	      else (NCP.ReportError (QUOTE NCP.DeleteLinks)
					(CONCAT "No such link: " Link])

(NCP.ValidLinkP
  [LAMBDA (Link)                                             (* rht: "18-Jul-86 16:49")

          (* * True if Link is an extant link in current database.)


    (NC.ValidLinkP Link])

(NCP.AllLinks
  [LAMBDA (NoteFile)                                         (* rht: "18-Feb-87 12:00")

          (* * Return a list of all links in the current database.)



          (* * rht 11/18/85: Updated to handle new notefile and card object formats. Note that it doesn't call NCONC to 
	  flatten the lists in case someone else is holding a pointer to the value returned by NC.RetrieveToLinks.)



          (* * rht 2/18/87: Changed to call MAPCONC instead of APPLY'ing APPEND. Note call to APPEND to prevent flatten'ing 
	  of original lists.)


    (MAPCONC (NC.MapCards NoteFile (FUNCTION NC.RetrieveToLinks)
			    (FUNCTION TRUE))
	       (FUNCTION (LAMBDA (X)
		   (APPEND X])

(NCP.SameLinkP
  [LAMBDA (Link1 Link2)                                      (* rht: " 2-Mar-87 22:12")

          (* * Returns non-nil if two links are the same.)



          (* * rht 11/16/86: Changed call to NCP.ReportError)


    (if (AND (NCP.ValidLinkP Link1)
		 (NCP.ValidLinkP Link2))
	then (NC.SameCardP Link1 Link2)
      else (NCP.ReportError (QUOTE NCP.SameLinkP)
				(CONCAT "Args not valid links: " Link1 Link2])

(NCP.LinkFromLinkIcon
  [LAMBDA (LinkIcon)                                         (* rht: " 8-Aug-86 12:14")

          (* * If LinkIcon is an image object for a link icon, return the associated link.)


    (if (NC.LinkIconImageObjP LinkIcon)
	then (IMAGEOBJPROP LinkIcon (QUOTE OBJECTDATUM])

(NCP.MakeLinkIcon
  [LAMBDA (Link)                                             (* rht: " 8-Aug-86 12:18")

          (* * Return a link icon image object for Link.)


    (NC.MakeLinkIcon Link])

(NCP.MarkCardDirty
  [LAMBDA (Card ResetFlg)                                    (* rht: "10-Sep-86 15:39")

          (* * Mark Card's substance as dirty thus forcing it to be written down at the next save. If ResetFlg is non-nil, 
	  then unmark it as dirty.)



          (* * rht 9/10/86: Fixed typo. Card wasn't being passed to NC.MarkCardDirty.)


    (NC.MarkCardDirty Card ResetFlg])
)
(DECLARE: EVAL@COMPILE 
[DEFMACRO NCP.MapLinks (NoteFile Function &OPTIONAL CollectResultPredicate)
	  (* * Map down all links in the current notefile, performing LinkFn to each.)
	  (* * rht 11/18/85: Updated to handle new notefile and card object formats. Now allows 
	     collection of links satisfying CollectResultPredicate.)
	  (* * rht 7/17/86: rearranged slightly.)
	  (* * rht 1/26/87: Now uses MAPCONC rather than APPLY'ing NCONC.)
	  (BQUOTE (MAPCONC [NCP.MapCards , NoteFile [FUNCTION (LAMBDA (Card)
								      (if , CollectResultPredicate 
									  then
									  (for Link in (
									       NC.RetrieveToLinks
										 Card)
									       when
									       (APPLY* , 
									   CollectResultPredicate 
										       Link)
									       collect
									       (APPLY* , Function 
										       Link))
									  else
									  (for Link in (
									       NC.RetrieveToLinks
										 Card)
									       do
									       (APPLY* , Function 
										       Link]
					 ,
					 (AND CollectResultPredicate (BQUOTE (FUNCTION TRUE]
			   (FUNCTION (LAMBDA (X)
					     X]
[DEFMACRO NCP.MapLinksOfType (Types NoteFile Function &OPTIONAL CollectResultPredicate)
	  (* * Map down all links in the given notefile, having one of the given types.)
	  (* * rht 7/17/86: rearranged slightly.)
	  (* * rht 1/26/87: Now uses MAPCONC rather than APPLY'ing NCONC.)
	  (BQUOTE (MAPCONC [NCP.MapCards , NoteFile [FUNCTION
					   (LAMBDA (Card)
						   (if , CollectResultPredicate then
						       (for Link in (NC.RetrieveToLinks Card)
							    when
							    (AND (FMEMB (NCP.LinkType Link)
									(MKLIST , Types))
								 (APPLY* , CollectResultPredicate 
									 Link))
							    collect
							    (APPLY* , Function Link))
						       else
						       (for Link in (NC.RetrieveToLinks Card)
							    when
							    (FMEMB (NCP.LinkType Link)
								   (MKLIST , Types))
							    do
							    (APPLY* , Function Link]
					 ,
					 (AND CollectResultPredicate (BQUOTE (FUNCTION TRUE]
			   (FUNCTION (LAMBDA (X)
					     X]
)
(* * Creating and accessing link labels.)

(DEFINEQ

(NCP.CreateLinkType
  [LAMBDA (LinkType NoteFile QuietFlg)                       (* pmi: "13-Jan-88 15:07")

          (* * Create a new link label unless already defined.)



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



          (* * rht 11/16/86: Changed call to NCP.ReportError)



          (* * pmi 1/13/88: Added QuietFlg argument to control printing of error message)


    (if (FMEMB LinkType (NCP.LinkTypes NoteFile))
	then (OR QuietFlg (NCP.ReportError (QUOTE NCP.CreateLinkType)
						 (CONCAT "Link type already defined: " LinkType ".")
						 ))
	       NIL
      else (NC.StoreLinkLabels NoteFile (CONS LinkType (NCP.UserLinkTypes NoteFile)))
	     LinkType])

(NCP.DeleteLinkType
  [LAMBDA (LinkType NoteFile)                                (* rht: " 2-Mar-87 22:06")

          (* * Checks for any instance of LinkType in the current database. If can't find any then delete the link label, 
	  otherwise error out.)



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



          (* * rht 11/16/86: Changed call to NCP.ReportError)



          (* * rht 2/18/87: Fixed call to NCP.AllLinks to take NoteFile arg.)


    (DECLARE (GLOBALVARS NC.SystemLinkLabels))
    (COND
      ((NOT (FMEMB LinkType (NCP.LinkTypes NoteFile)))
	(NCP.ReportError (QUOTE NCP.DeleteLinkType)
			   (CONCAT "No such link type: " LinkType "."))
	NIL)
      ((FMEMB LinkType NC.SystemLinkLabels)
	(NCP.ReportError (QUOTE NCP.DeleteLinkType)
			   (CONCAT "Can't delete system link type: " LinkType "."))
	NIL)
      ((for Link in (NCP.AllLinks NoteFile) thereis (EQ LinkType (fetch (Link Label)
									      of Link)))
	(NCP.ReportError (QUOTE NCP.DeleteLinkType)
			   (CONCAT "Link type currently in use: " LinkType ". Can't delete."))
	NIL)
      (T (NC.StoreLinkLabels NoteFile (REMOVE LinkType (NCP.UserLinkTypes NoteFile)))
	 LinkType])

(NCP.RenameLinkType
  [LAMBDA (OldLinkType NewLinkType NoteFile)                 (* rht: " 2-Mar-87 22:07")

          (* * Renames all instances of links with OldLinkType to be NewLabel. And deletes the old label OldLabel.
	  If NewLinkType doesn't exist, create it.)



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



          (* * rht 11/11/86: Took out ENV args to FUNCTION because they seemed to be causing stack overflows.)



          (* * rht 11/16/86: Changed call to NCP.ReportError)


    (LET ((LinkTypes (NCP.LinkTypes NoteFile)))
         (COND
	   ((NOT (FMEMB OldLinkType LinkTypes))
	     (NCP.ReportError (QUOTE NCP.RenameLinkType)
				(CONCAT "No such link type: " OldLinkType "."))
	     NIL)
	   ((FMEMB OldLinkType NC.SystemLinkLabels)
	     (NCP.ReportError (QUOTE NCP.RenameLinkType)
				(CONCAT "Can't rename system link type: " OldLinkType "."))
	     NIL)
	   ((FMEMB NewLinkType NC.SystemLinkLabels)
	     (NCP.ReportError (QUOTE NCP.RenameLinkType)
				(CONCAT "Can't rename with a system link type: " NewLinkType "."))
	     NIL)
	   (T (COND
		((NOT (FMEMB NewLinkType LinkTypes))
		  (NCP.CreateLinkType NewLinkType NoteFile)))
                                                             (* Map down all links, relabeling as appropriate.)
	      [NCP.MapLinks NoteFile (FUNCTION (LAMBDA (Link)
				(COND
				  ((EQ OldLinkType (fetch (Link Label) of Link))
				    (NCP.LinkType Link NewLinkType]
	      (NC.StoreLinkLabels NoteFile (REMOVE OldLinkType (NCP.UserLinkTypes NoteFile)))
	      NewLinkType])

(NCP.LinkTypes
  [LAMBDA (NoteFile)                                         (* rht: " 9-Dec-85 15:37")

          (* * Return all link labels including system ones.)



          (* * rht 11/17/85: Updated to handle new card and notefile objects.)


    (NC.RetrieveLinkLabels NoteFile T])

(NCP.ReverseLinkTypes
  [LAMBDA (NoteFile)                                         (* rht: "18-Nov-85 17:33")

          (* * Return all reverse link labels including system ones.)



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


    (for Lab in (NC.RetrieveLinkLabels NoteFile T) collect (PACK* (QUOTE ←)
									    Lab])

(NCP.UserLinkTypes
  [LAMBDA (NoteFile)                                         (* rht: "18-Nov-85 17:34")

          (* * Return list of only the user defined link labels appearing in the current notefile.)



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


    (NC.RetrieveLinkLabels NoteFile NIL])

(NCP.ValidLinkTypeP
  [LAMBDA (LinkType NoteFile)                                (* rht: "12-Jul-86 12:32")

          (* * True if LinkType is a currently defined user or system link label.)



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


    (FMEMB LinkType (NCP.LinkTypes NoteFile])

(NCP.SystemLinkTypeP
  [LAMBDA (LinkType)                                         (* pmi: " 8-Dec-87 15:36")

          (* * dsj 10/24/87: Is LinkType a system link label?)



          (* * pmi 12/8/87: Added dsj's function; see comment above.)


    (NC.SystemLinkLabelP LinkType])
)
(* * Dealing with card parts dates.)

[DECLARE: EVAL@COMPILE 

(TYPERECORD NOTECARDDATES (SUBSTANCEDATE LINKSDATE TITLEDATE PROPLISTDATE))
]
(DEFINEQ

(NCP.CardDates
  [LAMBDA (Card)                                             (* rht: " 2-Mar-87 22:07")

          (* * Returns an instance of the NOTECARDDATES record filled in with the current dates of the card parts of Card.)



          (* * rht 8/25/86: Now passes non-nil QuietFlg to NCP.UncacheCards.)



          (* * rht 11/16/86: Changed call to NCP.ReportError)


    (if (NC.ValidCardP Card)
	then [LET ((WasActive (NCP.CardCachedP Card)))
		    (OR WasActive (NCP.CacheCards Card))
		    (PROG1 (create NOTECARDDATES
				       SUBSTANCEDATE ← (NC.FetchItemDate Card)
				       LINKSDATE ← (NC.FetchLinksDate Card)
				       TITLEDATE ← (NC.FetchTitleDate Card)
				       PROPLISTDATE ← (NC.FetchPropListDate Card))
			     (OR WasActive (NCP.UncacheCards Card T]
      else (NCP.ReportError (QUOTE NCP.CardDates)
				(CONCAT Card " not an existing card."))
	     NIL])
)
(* * Open events card)

(DEFINEQ

(NCP.GetOpenEventsCard
  [LAMBDA (NoteFile)                                         (* rht: " 8-Dec-86 21:31")

          (* * Find the open events card for the given notefile, creating a new one if necessary. Mark the card as not 
	  needing to be filed.)


    (LET ((OpenEventsCard (NCP.LookupCardByName (QUOTE OpenEventsCard)
						  NoteFile)))
         (if (NOT (NCP.ValidCardP OpenEventsCard))
	     then (SETQ OpenEventsCard (NCP.CreateCard (QUOTE List)
							     NoteFile "Open Events" T))
		    (NCP.MarkAsNotNeedingFiling OpenEventsCard)
		    (NCP.RegisterCardByName (QUOTE OpenEventsCard)
					      OpenEventsCard))
     OpenEventsCard])

(NCP.GetCloseEventsCard
  [LAMBDA (NoteFile)                                         (* rht: " 8-Dec-86 21:31")

          (* * Find the close events card for the given notefile, creating a new one if necessary. Mark the card as not 
	  needing to be filed.)


    (LET ((CloseEventsCard (NCP.LookupCardByName (QUOTE CloseEventsCard)
						   NoteFile)))
         (if (NOT (NCP.ValidCardP CloseEventsCard))
	     then (SETQ CloseEventsCard (NCP.CreateCard (QUOTE List)
							      NoteFile "Close Events" T))
		    (NCP.MarkAsNotNeedingFiling CloseEventsCard)
		    (NCP.RegisterCardByName (QUOTE CloseEventsCard)
					      CloseEventsCard))
     CloseEventsCard])

(NCP.MarkAsNotNeedingFiling
  [LAMBDA (Card)                                             (* rht: " 8-Dec-86 21:34")

          (* * Indicate on the card's prop list that it doesn't have to be filed.)


    (NCP.CardProp Card (QUOTE Don'tRequireFilingFlg)
		    T])
)
(* * Functions for adding menu items)

(DEFINEQ

(NCP.AddSessionIconMenuItem
  [LAMBDA (MenuName Item)                                    (* pmi: "13-Jul-87 17:51")

          (* * pmi 7/13/87: New function which allows users to add items to the Session Icon menus. MenuName should be either
	  Card, NoteFile, or Other. Item should be a full menu item.)


    (DECLARE (GLOBALVARS NC.CardOpsItems NC.CardOpsMenu NC.NoteFileOpsItems NC.NoteFileOpsMenu 
			     NC.OtherOpsItems NC.OtherOpsMenu))

          (* * Make sure we have a full menu item.)



          (* * Make sure MenuName in non-NIL)


    (if (NOT (LISTP Item))
	then (NC.ReportError (QUOTE NCP.AddSessionIconMenuItem)
				 "You must provide a FULL menu item.")
	       NIL
      elseif (NULL MenuName)
	then NIL
      else (SELECTQ MenuName
			(Card (if (NOT (MEMBER Item NC.CardOpsItems))
				  then (SETQ NC.CardOpsItems (APPEND NC.CardOpsItems
									   (LIST Item)))
					 (SETQ NC.CardOpsMenu NIL)))
			(NoteFile 

          (* * Since the NoteFile menu is different from the other two, we have to play games to set it up correctly.)


				  (if (for MenuItem in NC.NoteFileOpsItems
					   do (if (EQ (CAR Item)
							    (CAR MenuItem))
						    then (RETURN NIL))
					   finally (RETURN T))
				      then                 (* This item has not already been added to this menu, 
							     so add it.)
					     [SETQ NC.NoteFileOpsItems (APPEND
						 NC.NoteFileOpsItems
						 (LIST (NC.CreateSessionIconNoteFileMenuItem
							   Item]
					     (SETQ NC.NoteFileOpsMenu NIL)))
			(Other (if (NOT (MEMBER Item NC.OtherOpsItems))
				   then (SETQ NC.OtherOpsItems (APPEND NC.OtherOpsItems
									     (LIST Item)))
					  (SETQ NC.OtherOpsMenu NIL)))
			NIL)
	     Item])

(NCP.RemoveSessionIconMenuItem
  [LAMBDA (MenuName ItemName)                                (* pmi: "13-Jul-87 18:11")

          (* * pmi 7/13/87: New function which allows users to remove an item from the Session Icon menus.
	  MenuName should be either Card, NoteFile, or Other. ItemName should be just the name of the item 
	  (the first part of a full menu item.))


    (DECLARE (GLOBALVARS NC.CardOpsItems NC.CardOpsMenu NC.NoteFileOpsItems NC.NoteFileOpsMenu 
			     NC.OtherOpsItems NC.OtherOpsMenu))

          (* * Make sure we have only the name of a menu item.)



          (* * Make sure MenuName in non-NIL)


    (if (LISTP ItemName)
	then (NC.ReportError (QUOTE NCP.RemoveSessionIconMenuItem)
				 "You must provide only the name of the menu item as an atom.")
	       NIL
      elseif (NULL MenuName)
	then NIL
      else 

          (* * Select the appropriate menu.)


	     (SELECTQ MenuName
			(Card (for MenuItem in NC.CardOpsItems when (AND (LISTP MenuItem)
										 (EQ (CAR 
											 MenuItem)
										       ItemName))
				 do (SETQ NC.CardOpsItems (REMOVE MenuItem NC.CardOpsItems))
				      (SETQ NC.CardOpsMenu NIL)
				      (RETURN MenuItem)))
			(NoteFile (for MenuItem in NC.NoteFileOpsItems
				     when (AND (LISTP MenuItem)
						   (EQ (CAR MenuItem)
							 ItemName))
				     do (SETQ NC.NoteFileOpsItems (REMOVE MenuItem 
									      NC.NoteFileOpsItems))
					  (SETQ NC.NoteFileOpsMenu NIL)
					  (RETURN MenuItem)))
			(Other (for MenuItem in NC.OtherOpsItems
				  when (AND (LISTP MenuItem)
						(EQ (CAR MenuItem)
						      ItemName))
				  do (SETQ NC.OtherOpsItems (REMOVE MenuItem NC.OtherOpsItems))
				       (SETQ NC.OtherOpsMenu NIL)
				       (RETURN MenuItem)))
			NIL])

(NCP.RestoreSessionIconMenu
  [LAMBDA (MenuName)                                         (* pmi: "13-Jul-87 18:12")

          (* * pmi 7/13/87: New function which allows users to restore the original menus of the Session Icon.
	  MenuName should be either Card, NoteFile, Other or NIL. NIL Signifies to restore all three of the Session Icon 
	  menus.)


    (DECLARE (GLOBALVARS NC.InitialCardOpsItems NC.CardOpsItems NC.CardOpsMenu 
			     NC.InitialNoteFileOpsItems NC.NoteFileOpsItems NC.NoteFileOpsMenu 
			     NC.InitialOtherOpsItems NC.OtherOpsItems NC.OtherOpsMenu))
    (SELECTQ MenuName
	       (Card (SETQ NC.CardOpsItems NC.InitialCardOpsItems)
		     (SETQ NC.CardOpsMenu NIL))
	       (NoteFile (SETQ NC.NoteFileOpsItems NC.InitialNoteFileOpsItems)
			 (SETQ NC.NoteFileOpsMenu NIL))
	       (Other (SETQ NC.OtherOpsItems NC.InitialOtherOpsItems)
		      (SETQ NC.OtherOpsMenu NIL))
	       (NIL (SETQ NC.CardOpsItems NC.InitialCardOpsItems)
		    (SETQ NC.CardOpsMenu NIL)
		    (SETQ NC.NoteFileOpsItems NC.InitialNoteFileOpsItems)
		    (SETQ NC.NoteFileOpsMenu NIL)
		    (SETQ NC.OtherOpsItems NC.InitialOtherOpsItems)
		    (SETQ NC.OtherOpsMenu NIL))
	       NIL])

(NCP.AddNoteFileIconMenuItem
  [LAMBDA (Item OpenOrClosedOrBoth)                          (* pmi: "14-Jul-87 11:22")

          (* * pmi 7/14/87: New function which allows users to add items to the NoteFile Icon menu. Item should be a full 
	  3-part menu item. OpenOrClosedOrBoth should be one of the atoms: Open, Closed , or Both, to indicate whether the 
	  new item applies to open or closed notefiles.)


    (DECLARE (GLOBALVARS NC.NoteFileIconOperationsMenuItems NC.NoteFileIconOpenOperations 
			     NC.NoteFileIconCloseOperations))
    (PROG (ItemName)

          (* * Make sure OpenOrClosedOrBoth in non-NIL)


	    (if (NULL OpenOrClosedOrBoth)
		then (RETURN NIL))

          (* * Make sure we have a full menu item.)


	    (if (NOT (LISTP Item))
		then (NC.ReportError (QUOTE NCP.AddNoteFileIconMenuItem)
					 "You must provide a FULL menu item.")
		       (RETURN NIL))
	    (SETQ ItemName (CAR Item))

          (* * If this item is not already known, add it to the list.)


	    [if (NOT (MEMBER Item NC.NoteFileIconOperationsMenuItems))
		then (SETQ NC.NoteFileIconOperationsMenuItems (APPEND 
							       NC.NoteFileIconOperationsMenuItems
									    (LIST Item]

          (* * Add the item as either for open notefiles, closed notefiles, or both.)


	    (SELECTQ OpenOrClosedOrBoth
		       (Open                                 (* Add the item to the open notefile list, if it isn't
							     already there.)
			     (if (NOT (MEMBER ItemName NC.NoteFileIconOpenOperations))
				 then (SETQ NC.NoteFileIconOpenOperations (CONS ItemName 
								    NC.NoteFileIconOpenOperations)))
                                                             (* Remove the item from the closed notefile list.)
			     (SETQ NC.NoteFileIconCloseOperations (REMOVE ItemName 
								   NC.NoteFileIconCloseOperations)))
		       (Closed                               (* Add the item to the closed notefile list, if it 
							     isn't already there.)
			       (if (NOT (MEMBER ItemName NC.NoteFileIconCloseOperations))
				   then (SETQ NC.NoteFileIconCloseOperations (CONS ItemName 
								   NC.NoteFileIconCloseOperations)))
                                                             (* Remove the item from the open notefile list.)
			       (SETQ NC.NoteFileIconOpenOperations (REMOVE ItemName 
								    NC.NoteFileIconOpenOperations)))
		       [Both                                 (* Add the item to the open notefile list, if it isn't
							     already there.)
			     (if (NOT (MEMBER ItemName NC.NoteFileIconOpenOperations))
				 then (SETQ NC.NoteFileIconOpenOperations (CONS ItemName 
								    NC.NoteFileIconOpenOperations)))
                                                             (* Add the item to the closed notefile list, if it 
							     isn't already there.)
			     (if (NOT (MEMBER ItemName NC.NoteFileIconCloseOperations))
				 then (SETQ NC.NoteFileIconCloseOperations (CONS ItemName 
								   NC.NoteFileIconCloseOperations]
		       (RETURN NIL))

          (* * Recompute the menus.)


	    (NC.MakeNoteFileIconOperationsMenus)
	    (RETURN Item])

(NCP.RemoveNoteFileIconMenuItem
  [LAMBDA (ItemName)                                         (* pmi: "14-Jul-87 11:23")

          (* * pmi 7/14/87: New function which allows users to remove an item from the NoteFile Icon menu.
	  ItemName should be either the full menu item or just the name of the item (the first part of a full menu item.))


    (DECLARE (GLOBALVARS NC.NoteFileIconOperationsMenuItems NC.NoteFileIconOpenOperations 
			     NC.NoteFileIconCloseOperations))

          (* * Make sure we have only the name of a menu item.)


    (if (LISTP ItemName)
	then (NC.ReportError (QUOTE NCP.AddSessionIconMenuItem)
				 "You must provide only the name of the menu item as an atom.")
	       NIL
      else 

          (* * (NIL Find) the full menu item and remove it.)


	     (for MenuItem in NC.NoteFileIconOperationsMenuItems
		when (AND (LISTP MenuItem)
			      (EQ (CAR MenuItem)
				    ItemName))
		do (SETQ NC.NoteFileIconOperationsMenuItems (REMOVE MenuItem 
							       NC.NoteFileIconOperationsMenuItems))
		     (SETQ NC.NoteFileIconOpenOperations (REMOVE ItemName 
								    NC.NoteFileIconOpenOperations))
		     (SETQ NC.NoteFileIconCloseOperations (REMOVE ItemName 
								   NC.NoteFileIconCloseOperations))
		     (NC.MakeNoteFileIconOperationsMenus)
		     (RETURN MenuItem])

(NCP.RestoreNoteFileIconMenu
  [LAMBDA NIL                                                (* pmi: "13-Jul-87 20:59")

          (* * pmi 7/13/87: New function which allows users to restore the NoteFile Icon menu to its original state.)


    (DECLARE (GLOBALVARS NC.InitialNoteFileIconOperationsMenuItems 
			     NC.NoteFileIconOperationsMenuItems NC.InitialNoteFileIconOpenOperations 
			     NC.NoteFileIconOpenOperations NC.InitialNoteFileIconCloseOperations 
			     NC.NoteFileIconCloseOperations))
    (SETQ NC.NoteFileIconOperationsMenuItems NC.InitialNoteFileIconOperationsMenuItems)
    (SETQ NC.NoteFileIconOpenOperations NC.InitialNoteFileIconOpenOperations)
    (SETQ NC.NoteFileIconCloseOperations NC.InitialNoteFileIconCloseOperations)
    (NC.MakeNoteFileIconOperationsMenus])

(NC.CreateSessionIconNoteFileMenuItem
  [LAMBDA (Item)                                             (* pmi: "10-Jul-87 18:22")

          (* * pmi 7/10/87: Created to format the menu item for the NoteFile menu of the Session Icon.)


    (LET (MenuItem SubItemList SubItems)
         [SETQ MenuItem (BQUOTE (, (CAR Item)
				       (NC.DoNoteFileOp (QUOTE , (CADR Item)))
				       ,
				       (CADDR Item]
         (SETQ SubItemList (CADDDR Item))
         (if (AND SubItemList (EQ (CAR SubItemList)
					(QUOTE SUBITEMS)))
	     then (SETQ SubItems (CDR SubItemList))
		    [APPEND MenuItem (LIST (ATTACH (QUOTE SUBITEMS)
							 (for SubItem in SubItems
							    collect (
							     NC.CreateSessionIconNoteFileMenuItem
									SubItem]
	   else MenuItem])

(NCP.AddDefaultNoteFileIconMiddleButtonItems
  [LAMBDA (NewItems)                                         (* pmi: " 5-Jan-88 15:11")

          (* * 10/23/87. dsj. Uniquely add NewItems to NC.DefaultNoteFileIconMiddleButtonItems so that ALL open notefiles 
	  will have the new menu item without needing to be "initialized" first.)



          (* * pmi 1/5/88: Added this function created by DJ (see above comment). Added GLOBALVARS declaration.)


    (DECLARE (GLOBALVARS NC.DefaultNoteFileIconMiddleButtonItems))
    (AND NewItems (NCONC NC.DefaultNoteFileIconMiddleButtonItems
			     (for NewItem in NewItems collect NewItem
				when (NOT (MEMBER NewItem 
							NC.DefaultNoteFileIconMiddleButtonItems])

(NCP.NoticedNoteFileNamesMenu
  [LAMBDA (IncludeNewNoteFileFlg AllowedOperations InterestedWindow Operation)
                                                             (* pmi: " 9-Dec-87 12:33")

          (* * AllowedOperations should be one of the atoms: OPEN, CLOSED, or NIL for both. Operation should be a string or 
	  atom containing the name of the operation to be performed on the result and the word NoteFile;
	  e.g. (QUOTE Open% NoteFile) This is used in the prompt for a new notefile name.)



          (* * dsj 11/6/87: Give user a menu of noticed notefile names.)



          (* * pmi 12/9/87: Added this function, which was created by dsj (see above comment.))


    (NC.NoticedNoteFileNamesMenu IncludeNewNoteFileFlg AllowedOperations InterestedWindow Operation]
)

(NCP.AddTitleBarMenuItemsToType
  [LAMBDA (Type Button NewMenuItems TopOrBottom)             (* pmi: "31-Dec-87 13:39")

          (* * DSJ: 10/6/87 Add NewMenuItems to the menu items for the card type if not already a menu item.
	  Also use TopOrBottom (one of (QUOTE Top) or (QUOTE Bottom)) to determine where in the menu the new items should be 
	  placed. If TopOrBottom is NIL put on bottom of menu. Button should be one of (QUOTE Left) or 
	  (QUOTE Right,) indicating which menu to add to.)



          (* * pmi 12/31/87: Added DSJ's function (renamed) to the programmer's interface; see comment above.)


    (LET (Items Menu)                                        (* If NULL Items then assume we don't want it for this
							     card type)
         (SETQ Menu (SELECTQ (U-CASE Button)
				 (LEFT (QUOTE LeftButtonMenuItems))
				 (RIGHT (QUOTE RightButtonMenuItems))
				 (NCP.ReportError (QUOTE NCP.AddTitleBarMenuItemsToType)
						    "Button incorrectly specified.")))
         (SETQ Items (NCP.CardTypeVar Type Menu))
         (AND Items
		(NCP.ChangeCardTypeFields
		  Type NIL
		  (BQUOTE (QUOTE (, Menu ,
					(SELECTQ (OR (U-CASE TopOrBottom)
							 (QUOTE BOTTOM))
						   (TOP (NCONC (for NewItem in NewMenuItems
								    collect NewItem
								    when (NOT (MEMBER NewItem 
											    Items)))
								 Items))
						   [BOTTOM (APPEND Items
								     (for NewItem in NewMenuItems
									collect NewItem
									when (NOT (MEMBER
											NewItem Items]
						   (NCP.ReportError (QUOTE 
								   NCP.AddTitleBarMenuItemsToType)
								      
				       "Location of new items in the menu incorrectly specified."])

(NCP.AddTitleBarMenuItemsToWindow
  [LAMBDA (Window Button NewMenuItems TopOrBottom)           (* pmi: "31-Dec-87 13:39")

          (* * pmi 12/31/87: Add the given menu items to the appropriate button menu of Window, as determined by Button.
	  Also use TopOrBottom (one of (QUOTE Top) or (QUOTE Bottom)) to determine where in the menu the new items should be 
	  placed. If TopOrBottom is NIL put on bottom of menu. Button should be one of (QUOTE Left) or 
	  (QUOTE Right,) indicating which menu to add to. This change was borrowed from dsj's implementation of 
	  NCP.AddTitleBarMenuToType.)


    (LET ([Menu (WINDOWPROP Window (SELECTQ (U-CASE Button)
						(LEFT (QUOTE TitleBarLeftButtonMenu))
						(RIGHT (QUOTE TitleBarRightButtonMenu))
						(NCP.ReportError (QUOTE 
								 NCP.AddTitleBarMenuItemsToWindow)
								   "Button incorrectly specified."]
	  Items)
         (if Menu
	     then (SETQ Items (fetch (MENU ITEMS) of Menu))
		    (replace (MENU ITEMS) of Menu
		       with (SELECTQ (OR (U-CASE TopOrBottom)
					       (QUOTE BOTTOM))
					 (TOP (NCONC (for NewItem in NewMenuItems collect
											 NewItem
							  when (NOT (MEMBER NewItem Items)))
						       Items))
					 [BOTTOM (APPEND Items
							   (for NewItem in NewMenuItems
							      collect NewItem
							      when (NOT (MEMBER NewItem Items]
					 (NCP.ReportError (QUOTE NCP.AddTitleBarMenuItemsToWindow)
							    
				       "Location of new items in the menu incorrectly specified.")))
		    (replace (MENU IMAGE) of Menu with NIL])

(NCP.LinkIconAttachedBitMap
  [LAMBDA (TypeName Size)                                    (* pmi: "31-Dec-87 13:32")

          (* * dsj. This returns the link iconattached bitmap of size Size for card type Type. Default size is 17 x 17.0)



          (* * pmi 12/30/87: Added dsj's function to the programmer's interface; see comment above. Placed default value in 
	  new globalvar NCP.DefaultLinkIconAttachedBitMapSize.)


    (DECLARE (GLOBALVARS NCP.DefaultLinkIconAttachedBitMapSize))
    (LET [(BitMap (NCP.CardTypeVar TypeName (QUOTE LinkIconAttachedBitMap]
         (AND BitMap (OR (BITMAPP BitMap)
			     (LISTGET BitMap (OR Size (NUMBERP 
							    NCP.DefaultLinkIconAttachedBitMapSize])

(NCP.SessionIconWindow
  [LAMBDA NIL                                                (* pmi: " 8-Dec-87 15:32")

          (* * pmi 12/8/87: Created to provide programmer's interface access to NC.NoteCardsIconWindow.)


    (DECLARE (GLOBALVARS NC.NoteCardsIconWindow))
    NC.NoteCardsIconWindow])

(NCP.BringUpSessionIcon
  [LAMBDA (IconPosition)                                     (* pmi: " 9-Dec-87 12:07")

          (* * Start up NoteCards by bringing up the NoteCards icon at IconPosition)


    (NC.BringUpNoteCardsIcon (if (POSITIONP IconPosition)
				   then IconPosition])
)
(* * Miscellaneous)

(DEFINEQ

(NCP.TitleSearch
  [LAMBDA (NoteFile Keys CaseSensitiveFlg)                   (* rht: "11-Nov-86 12:38")

          (* * Return a list of all cards which contain each string of Args within their titles.)



          (* * rht 11/18/85: Updated to handle new notefile and card object formats. Note that first arg is now expected to 
	  be a notefile.)



          (* * kirk 26Jun86 Added BLOCK)



          (* * rht 7/12/86: Cleaned up a bit.)



          (* * rht 7/14/86: Now takes 3 args instead of unlimited number and accepts CaseSensitiveFlg.)



          (* * rht 11/11/86: Took out ENV args to FUNCTION because they seemed to be causing stack overflows.)


    (AND (NCP.OpenNoteFileP NoteFile)
	   (NCP.MapCards NoteFile (FUNCTION [LAMBDA (Card)
			     Card])
			 (if CaseSensitiveFlg
			     then [FUNCTION (LAMBDA (Card)
					(LET ((Title (NCP.CardTitle Card)))
					     (for Key in (MKLIST Keys) always (STRPOS
											Key Title]
			   else (FUNCTION (LAMBDA (Card)
				      (LET ((Title (NCP.CardTitle Card)))
				           (for Key in (MKLIST Keys)
					      always (STRPOS (U-CASE Key)
								 (U-CASE Title])

(NCP.PropSearch
  [LAMBDA Args                                               (* rht: "12-Jul-86 12:45")

          (* * Return a list of all IDs which contain each property or property pair appearing in Args.
	  For each atomic element in Args, there must be a property by that name with non-nil value. For each pair 
	  (list of length 2) in Args, there must be a property and value matching that pair.)



          (* * rht 11/18/85: Updated to handle new notefile and card object formats. Note that first arg is now expected to 
	  be a notefile.)



          (* * rht 7/12/86: Cleaned up a bit.)


    (LET ((NoteFile (ARG Args 1)))
         (AND (type? NoteFile NoteFile)
		(NCP.MapCards NoteFile (FUNCTION [LAMBDA (Card)
				  Card])
			      (FUNCTION (LAMBDA (Card)
				  (LET ((PropList (NCP.CardPropList Card))
					Prop)
				       (for i from 2 to Args
					  always (if (ATOM (SETQ Prop (ARG Args i)))
						       then (LISTGET PropList Prop)
						     elseif (AND (LISTP Prop)
								     (EQ (LENGTH Prop)
									   2))
						       then (EQ (LISTGET PropList (CAR Prop))
								    (CADR Prop])

(NCP.WhichCard
  [LAMBDA (WindowOrx y)                                      (* rht: "18-Nov-85 17:42")

          (* * Return the ID of the card at a position determined as follows: If WindowOrx is a position, then use that, if 
	  WindowOrx and y are numbers then use (WindowOrx,y), else use cursor position.)


    (NC.CoerceToCard (OR (WINDOWP WindowOrx)
			     (WHICHW WindowOrx y])

(NCP.WhichNoteFile
  [LAMBDA (WindowOrx y)                                      (* rht: "14-Jul-86 10:38")

          (* * Return the notefile corresponding to the window at a position determined as follows: If WindowOrx is a 
	  position, then use that, if WindowOrx and y are numbers then use (WindowOrx,y), else use cursor position.
	  Works if the window is either for a card or for a notefile menu.)


    (LET [(Window (OR (WINDOWP WindowOrx)
			(WHICHW WindowOrx y]
         (OR (WINDOWPROP Window (QUOTE NoteFile))
	       (LET [(Card (WINDOWPROP Window (QUOTE NoteCardObject]
		    (AND (NCP.ValidCardP Card)
			   (NCP.NoteFileFromCard Card])

(NCP.SelectCards
  [LAMBDA (InstigatingCardOrWindow SingleCardFlg SelectionPredicate Msg CheckForCancelFlg)
                                                             (* Randy.Gobbel " 2-Apr-87 15:38")

          (* * Return a list of cards selected. A menu pops up near the prompt window with "DONE" and "CANCEL" buttons.
	  User selects by clicking in card's title bar.)



          (* * rht 11/18/85: Updated to handle new notefile and card object formats. Now takes optional extra args and passes
	  to NC.SelectNoteCards.)



          (* * pmi 12/12/86: Removed obsolete ReturnLinksFlg argument in call to NC.SelectNoteCards.)



          (* * rht 3/2/87: Fix to bug %#342: Now makes sure instigating card is displayed, else passes NIL to 
	  NC.SelectNoteCards.)



          (* * rg 4/2/87 added NCP.WithLockedCards wrapper)


    (NCP.WithLockedCards (NC.SelectNoteCards SingleCardFlg SelectionPredicate
					       (if SingleCardFlg
						   then NC.SelectingCardMenu
						 else NC.SelectingCardsMenu)
					       (COND
						 ((OPENWP InstigatingCardOrWindow)
						   InstigatingCardOrWindow)
						 ((AND (NCP.ValidCardP InstigatingCardOrWindow)
							 (NCP.CardDisplayedP 
									  InstigatingCardOrWindow))
						   InstigatingCardOrWindow)
						 (T NIL))
					       Msg CheckForCancelFlg])

(NCP.DocumentParameters
  [LAMBDA (NewProps)                                         (* rht: " 2-Mar-87 22:07")

          (* * Returns the old value of the MakeDocument default parameters. If NewProps is non-nil then it should be a prop 
	  list which will be used to change some or all of the current MakeDocument parameters. Only those props whose names 
	  are valid MakeDocument parameters and whose values are permissible values for that name are used.)



          (* * rht 11/6/86: No longer checks for valid link label since that requires a notefile. Also returns just a 
	  proplist of the params that user can change.)



          (* * rht 11/16/86: Changed call to NCP.ReportError)


    (DECLARE (GLOBALVARS NC.MakeDocParameters))
    (LET [(OldParams (for ParamThing in NC.MakeDocParameters unless (EQ (CAR ParamThing)
										(QUOTE --DONE--))
			join (LIST (CAR ParamThing)
				       (GETPROP (QUOTE NC.MakeDocParameters)
						  (CAR ParamThing]
         [if NewProps
	     then (for Params on NewProps by (CDDR NewProps) bind Param NewValue 
									      LegalValues
		       do (SETQ Param (CAR Params))
			    (COND
			      ([NULL (SETQ LegalValues (CDR (FASSOC Param 
									    NC.MakeDocParameters]
				(NCP.ReportError (QUOTE NCP.DocumentParameters)
						   (CONCAT Param " not a document parameter name."))
				)
			      ((OR (AND (FMEMB (SETQ NewValue (CADR Params))
						     LegalValues)
					    (NEQ NewValue (QUOTE Select)))
				     (AND (LISTP NewValue)
					    (FMEMB (QUOTE Select)
						     LegalValues)))
				(PUTPROP (QUOTE NC.MakeDocParameters)
					   Param NewValue))
			      (T (NCP.ReportError (QUOTE NCP.DocumentParameters)
						    (CONCAT NewValue 
							      " is not a permissible value for "
							      Param "."]
     OldParams])

(NCP.NoteCardsParameters
  [LAMBDA (NewParams)                                        (* rht: " 2-Mar-87 22:07")

          (* * Returns the old value of the Notecards parameters. If NewParams is non-nil then it should be a prop list which
	  will be used to change some or all of the current Notecards parameters. Only those props whose names are valid 
	  Notecards parameters and whose values are permissible values for that name are used. On NC.NoteCardsParameters's 
	  prop list under the parameter name is a list of one or two items. The first is the name of the global var.
	  The second if present, is a function of no args which returns a list of legal values for that parameter.
	  We only do type checking if that function is present.)



          (* * rht 3/20/85: Changed to use new GLOBALPARAMETER record, especially the CheckFn field.)



          (* * rht 6/12/86: Now checks first whether there's a PARAMCHECKFN before apply*'ing it.)



          (* * rht 7/12/86: Cleaned up a bit.)



          (* * rht 11/16/86: Changed call to NCP.ReportError)


    (LET (OldParams PropVal ParamCheckFn)
         [SETQ OldParams (for Param in NC.NoteCardsParameters
			      join (SETQ PropVal (GETPROP (QUOTE NC.NoteCardsParameters)
								Param))
				     (LIST Param (EVAL (if (LISTP PropVal)
							       then (fetch (GLOBALPARAMETER
										 PARAMGLOBALVAR)
									 of PropVal)
							     else PropVal]
         [if NewParams
	     then (for Params on NewParams by (CDDR NewParams) bind Param NewValue 
										GlobalVar PropVal
		       do (if (FMEMB (SETQ Param (CAR Params))
					   NC.NoteCardsParameters)
				then (SETQ NewValue (CADR Params))
				       (SETQ PropVal (GETPROP (QUOTE NC.NoteCardsParameters)
								  Param))
				       (SETQ GlobalVar (if (LISTP PropVal)
							     then (fetch (GLOBALPARAMETER 
										   PARAMGLOBALVAR)
								       of PropVal)
							   else PropVal))
				       (if (OR (ATOM PropVal)
						   (NULL (SETQ ParamCheckFn (fetch
							       (GLOBALPARAMETER PARAMCHECKFN)
										   of PropVal)))
						   (APPLY* ParamCheckFn NewValue))
					   then (SET GlobalVar NewValue)
					 else (NCP.ReportError (QUOTE NCP.NoteCardsParameters)
								   (CONCAT NewValue 
							       " is not a permissible value for "
									     Param ".")))
			      else (NCP.ReportError (QUOTE NCP.NoteCardsParameters)
							(CONCAT Param 
							       " not a Notecards parameter name."]
     OldParams])

(NCP.PrintMsg
  [LAMBDA Args                                               (* rht: "10-Jul-86 23:43")

          (* * Expects args of form (<window> <clearFirstFlg> <arg1> <arg2> ...) and prints the <arg>s to <window>'s prompt 
	  window or to the lisp prompt window if <window> is nil. Will clear first if second arg is non-nil.)


    (APPLY (QUOTE NC.PrintMsg)
	     (for i from 1 to Args collect (ARG Args i])

(NCP.ClearMsg
  [LAMBDA (Window ClosePromptWinFlg)                         (* rht: "27-Nov-84 17:53")

          (* * Clears the prompt window for Window. Will close if ClosePromptWinFlg is non-nil.)


    (NC.ClearMsg Window ClosePromptWinFlg])

(NCP.AskUser
  [LAMBDA (Msg Prompt FirstTry ClearFirstFlg MainWindow DontCloseAtEndFlg DontClearAtEndFlg 
	       PROMPTFORWORDFlg)                             (* rht: "30-May-85 21:49")

          (* * Asks a question in the prompt window. Just calls the NC.AskUser function.)


    (NC.AskUser Msg Prompt FirstTry ClearFirstFlg MainWindow DontCloseAtEndFlg DontClearAtEndFlg 
		  PROMPTFORWORDFlg])

(NCP.AskYesOrNo
  [LAMBDA (Msg Prompt FirstTry ClearFirstFlg MainWindow DontCloseAtEndFlg DontClearAtEndFlg)
                                                             (* rht: "12-Jul-86 13:15")

          (* * Asks a yes/no question in the prompt window. Just calls the NC.AskYesOrNo function.)


    (NC.AskYesOrNo Msg Prompt FirstTry ClearFirstFlg MainWindow DontCloseAtEndFlg DontClearAtEndFlg]
)

(NCP.RegisterCardByName
  [LAMBDA (Name Card RegistryCard)                           (* rht: "23-May-87 23:21")

          (* * Hash Card under Name in Card's notefile's system registry card.)



          (* * rht 11/16/86: Changed call to NCP.ReportError)



          (* * rht 5/23/87: Added RegistryCard arg which defaults to the notefile registry card.)


    [OR RegistryCard (SETQ RegistryCard (fetch (NoteFile RegistryCard) of (
									     NCP.NoteFileFromCard
										    Card]
    (COND
      ((NOT (NC.ValidCardP Card))
	(NCP.ReportError (QUOTE NCP.RegisterCardByName)
			   (CONCAT Card " is not a valid notecard.")))
      ([NOT (AND (NC.ValidCardP RegistryCard)
		     (EQ (NCP.CardType RegistryCard)
			   (QUOTE Registry]
	(NCP.ReportError (QUOTE NCP.RegisterCardByName)
			   (CONCAT RegistryCard " is not a valid registry card.")))
      (T (NC.RegisterCardByName RegistryCard Name Card])

(NCP.ListRegisteredCards
  [LAMBDA (NoteFileOrRegistryCard IncludeKeysFlg)            (* pmi: "10-Dec-87 17:19")

          (* * Return the list of cards registered in the RegistryCard or notefile. If IncludeKeysFlg is non-nil, then return
	  dotted pairs of key and card, else just list of cards.)



          (* * pmi 12/10/87: now returns cards instead of UIDs.)


    (LET (RegistryCard NoteFile Result)
         [COND
	   ((NCP.OpenNoteFileP NoteFileOrRegistryCard)
	     (SETQ RegistryCard (fetch (NoteFile RegistryCard) of NoteFileOrRegistryCard))
	     (SETQ NoteFile NoteFileOrRegistryCard))
	   ((AND (NC.ValidCardP NoteFileOrRegistryCard)
		   (EQ (NCP.CardType NoteFileOrRegistryCard)
			 (QUOTE Registry)))
	     (SETQ RegistryCard NoteFileOrRegistryCard)
	     (SETQ NoteFile (NCP.CardNoteFile RegistryCard)))
	   (T (NCP.ReportError (QUOTE NCP.ListRegisteredCards)
				 (CONCAT "Improper arg: " NoteFileOrRegistryCard]
         [if IncludeKeysFlg
	     then [MAPHASH (NCP.CardSubstance RegistryCard)
			       (FUNCTION (LAMBDA (Val Key)
				   (push Result (CONS Key (NC.CardFromUID Val NoteFile]
	   else (MAPHASH (NCP.CardSubstance RegistryCard)
			     (FUNCTION (LAMBDA (Val Key)
				 (push Result (NC.CardFromUID Val NoteFile]
     Result])

(NCP.LookupCardByName
  [LAMBDA (Name NoteFileOrRegistryCard)                      (* rht: "23-May-87 23:37")

          (* * Lookup Name in notefile's system registry card.)



          (* * rht 11/16/86: Changed call to NCP.ReportError)



          (* * rht 5/23/87: Second arg can now be RegistryCard or NoteFile. If the latter, then grab notefile's 
	  RegistryCard.)


    (LET (RegistryCard)
         [COND
	   ((NCP.OpenNoteFileP NoteFileOrRegistryCard)
	     (SETQ RegistryCard (fetch (NoteFile RegistryCard) of NoteFileOrRegistryCard)))
	   ((AND (NC.ValidCardP NoteFileOrRegistryCard)
		   (EQ (NCP.CardType NoteFileOrRegistryCard)
			 (QUOTE Registry)))
	     (SETQ RegistryCard NoteFileOrRegistryCard))
	   (T (NCP.ReportError (QUOTE NCP.LookupCardByName)
				 (CONCAT "Improper arg: " NoteFileOrRegistryCard]
         (NC.LookupCardByName RegistryCard Name])

(NCP.UnregisterName
  [LAMBDA (Name NoteFileOrRegistryCard)                      (* rht: "23-May-87 23:37")

          (* * Lookup Name in notefile's system registry card.)



          (* * rht 11/16/86: Changed call to NCP.ReportError)



          (* * rht 5/23/87: Second arg can now be RegistryCard or NoteFile. If the latter, then grab notefile's 
	  RegistryCard.)


    (LET (RegistryCard)
         [COND
	   ((NCP.OpenNoteFileP NoteFileOrRegistryCard)
	     (SETQ RegistryCard (fetch (NoteFile RegistryCard) of NoteFileOrRegistryCard)))
	   ((AND (NC.ValidCardP NoteFileOrRegistryCard)
		   (EQ (NCP.CardType NoteFileOrRegistryCard)
			 (QUOTE Registry)))
	     (SETQ RegistryCard NoteFileOrRegistryCard))
	   (T (NCP.ReportError (QUOTE NCP.UnregisterName)
				 (CONCAT "Improper arg: " NoteFileOrRegistryCard]
         (NC.UnregisterName RegistryCard Name])

(NCP.DisplayedCards
  [LAMBDA (NoteFiles CardTypes)                              (* pmi: " 7-Dec-87 16:21")

          (* * Return a list of all cards that are currently displayed in a window.)



          (* * dsj 10/1/87: Added NoteFiles and CardTypes args. If either are NIL, then all NoteFiles and/or CardTypes are 
	  considered.)



          (* * pmi 12/7/87: Integrated above change by dsj into NC sources.)


    (SETQ NoteFiles (MKLIST NoteFiles))
    (SETQ CardTypes (MKLIST CardTypes))
    (for Win in (OPENWINDOWS) bind Card when (AND (SETQ Card
								(NC.CoerceToCard
								  (OR (WINDOWPROP Win
										      (QUOTE 
											  ICONFOR))
									Win)))
							      (if NoteFiles
								  then (for NoteFile
									    in NoteFiles
									    bind
									     (CardNoteFile
									       ←
									       (NCP.CardNoteFile
										 Card))
									    thereis (EQ NoteFile 
										     CardNoteFile))
								else T)
							      (if CardTypes
								  then (for Type in CardTypes
									    bind
									     (CardType ←
										       (NCP.CardType
											 Card))
									    thereis (EQ Type 
											 CardType))
								else T))
       collect Card])

(NCP.CardUserDataProp
  [LAMBDA Args                                               (* rht: " 2-Mar-87 22:08")

          (* * Expects two or three arguments: Card, Property, and optional new value. Returns the old value.
	  Assigns the new value if given. Semantics are just like WINDOWPROP.)



          (* * rht 11/16/86: Changed call to NCP.ReportError)


    (LET (Card PropList)
         (COND
	   ((AND (NEQ Args 2)
		   (NEQ Args 3))
	     (NCP.ReportError (QUOTE NCP.CardUserDataProp)
				(CONCAT "Improper number of args: " Args))
	     NIL)
	   [(NC.ValidCardP (SETQ Card (ARG Args 1)))
	     (PROG1 (NC.FetchUserDataProp Card (ARG Args 2))
		      (if (EQ Args 3)
			  then (NC.SetUserDataProp Card (ARG Args 2)
						       (ARG Args 3]
	   (T (NCP.ReportError (QUOTE NCP.CardUserDataProp)
				 (CONCAT Card " not an existing card or box."))
	      NIL])

(NCP.NoteFileProp
  [LAMBDA Args                                               (* rht: " 2-Mar-87 22:08")

          (* * Expects two or three arguments: Notefile, Property, and optional new value. Returns the old value.
	  Assigns the new value if given. Semantics are just like WINDOWPROP.)



          (* * rht 11/16/86: Changed call to NCP.ReportError)


    (LET (NoteFile PropList)
         (COND
	   ((AND (NEQ Args 2)
		   (NEQ Args 3))
	     (NCP.ReportError (QUOTE NCP.NoteFileProp)
				(CONCAT "Improper number of args: " Args))
	     NIL)
	   [(type? NoteFile (SETQ NoteFile (ARG Args 1)))
	     (PROG1 (LISTGET (SETQ PropList (fetch (NoteFile UserProps) of NoteFile))
				 (ARG Args 2))
		      (if (EQ Args 3)
			  then (if PropList
				     then (LISTPUT PropList (ARG Args 2)
						       (ARG Args 3))
				   else (replace (NoteFile UserProps) of NoteFile
					     with (LIST (ARG Args 2)
							    (ARG Args 3]
	   (T (NCP.ReportError (QUOTE NCP.NoteFileProp)
				 (CONCAT NoteFile " not a valid notefile."))
	      NIL])

(NCP.SetUpTitleBar
  [LAMBDA (CardWindow CardType)                              (* rht: " 8-Dec-86 18:00")

          (* * Set up the left and middle button menus for this card. Also handle installation of button event fn.)


    (NC.InstallTitleBarLeftMenu CardWindow CardType)
    (NC.InstallTitleBarMiddleMenu CardWindow CardType)
    (NC.InstallTitleBarButtonEventFn CardWindow (FUNCTION NC.TitleBarButtonEventFn])

(NCP.AddNoteFileIconMiddleButtonItems
  [LAMBDA (NoteFile MenuItems)                               (* pmi: " 5-Jan-88 15:44")

          (* * Add the given MenuItems to the given NoteFile.)



          (* * pmi 1/5/88: Now won't add a menu item if it is already on the menu.)


    (if NoteFile
	then (LET ((ExistingMenuItems (NCP.NoteFileProp NoteFile (QUOTE 
								    NoteFileIconMiddleButtonItems)))
		     (NoteFileIconWindow (NCP.NoteFileIconWindow NoteFile)))
		    [NCP.NoteFileProp NoteFile (QUOTE NoteFileIconMiddleButtonItems)
					(NCONC ExistingMenuItems
						 (for MenuItem in MenuItems collect MenuItem
						    when (NOT (MEMBER MenuItem 
									    ExistingMenuItems]

          (* * Smash stashed menu so as to force recompute.)

                                                             (* Menu is no longer cached on the window.)
                                                             (* (if (OPENWP NoteFileIconWindow) then 
							     (WINDOWPROP NoteFileIconWindow 
							     (QUOTE NoteFileMiddleButtonMenu) NIL)))
		ExistingMenuItems])

(NCP.NoteFileIconWindow
  [LAMBDA (NoteFile)                                         (* rht: "23-Nov-86 15:48")

          (* * Return the icon window for given notefile.)


    (WFROMMENU (fetch (NoteFile Menu) of NoteFile])
)
(DECLARE: DONTEVAL@LOAD 
(MOVD (QUOTE NCP.WhichCard)
      (QUOTE NCP.WC)
      T)
(MOVD (QUOTE NCP.WhichNoteFile)
      (QUOTE NCP.WNF)
      T)
)
(* * Handy internal functions)

(DEFINEQ

(NCP.ReportError
  [LAMBDA (FunctionName Msg)                                 (* rht: " 2-Mar-87 23:31")

          (* * Print out the various elements of Args to the terminal.)



          (* * rht 11/16/86: Now takes different args and does optional break. Consults NCP.ErrorBrkWhenFlg.)



          (* * rht 3/2/87: Now coerces FunctionName to atom in case was passed as string.)


    (DECLARE (GLOBALVARS NCP.ErrorBrkWhenFlg))
    (if (EQ NCP.ErrorBrkWhenFlg (QUOTE NEVER))
	then (PRIN1 "*** NC-PI error: " T)
	       (PRIN1 Msg T)
	       (TERPRI T)
      else (APPLY* (QUOTE BREAK1)
		       T T (MKATOM FunctionName)
		       NIL NIL (LIST Msg])

(NCP.ReportWarning
  [LAMBDA (FunctionName Msg)                                 (* rht: "21-Nov-86 00:34")

          (* * Print out the various elements of Args to the terminal.)



          (* * rht 11/16/86: Now takes different args and does optional break. Consults NCP.ErrorBrkWhenFlg.)


    (DECLARE (GLOBALVARS NCP.ErrorBrkWhenFlg))
    (if (NEQ NCP.ErrorBrkWhenFlg (QUOTE ALWAYS))
	then (PRIN1 "*** NC-PI warning: " T)
	       (PRIN1 Msg T)
	       (TERPRI T)
      else (APPLY* (QUOTE BREAK1)
		       T T FunctionName NIL NIL (LIST Msg])

(NCP.LinkAnchorDesc
  [LAMBDA (Link ToFlg FollowCrossFileLinkFlg)                (* rht: "29-Oct-87 18:58")

          (* * Return a description of the anchoring of Link at one of its endpoints. The description has the form 
	  (<anchormode> <ID> <loc>) If ToFlg is non-nil, then look at the "To" end of the link, otherwise, its "From" end.)



          (* * rht 8/25/86: Now passes non-nil QuietFlg to NCP.UncacheCards.)



          (* * rht 10/29/87: Now takes FollowCrossFileLinkFlg arg.)


    (LET ((DestCard (fetch (Link DestinationCard) of Link))
	  (SrcCard (fetch (Link SourceCard) of Link))
	  Card WasActiveP RemoteCard RemoteCrossFileLinkCard)
         (SETQ Card (if ToFlg
			  then (if (AND FollowCrossFileLinkFlg (NC.CrossFileLinkCardP 
											 DestCard)
					      (SETQ RemoteCard (NC.GetCrossFileLinkDestCard
						  DestCard)))
				     then RemoteCard
				   else DestCard)
			else (if (AND FollowCrossFileLinkFlg (NC.CrossFileLinkCardP SrcCard)
					    (SETQ RemoteCard (NC.GetCrossFileLinkDestCard SrcCard)
					      )
					    (SETQ RemoteCrossFileLinkCard (
						NC.FetchRemoteCrossFileLinkCard SrcCard)))
				   then [PROG1 RemoteCard (SETQ Link (CAR (NCP.GetLinks
										    NIL 
									  RemoteCrossFileLinkCard]
				 else SrcCard)))
         (if (OR (NC.GlobalLinkP Link)
		     ToFlg)
	     then (LIST (QUOTE GLOBAL)
			    Card NIL)
	   else (COND
		    ((NOT (SETQ WasActiveP (NCP.CardCachedP Card)))
		      (NCP.CacheCards Card)))
		  (for Obj in (CAR (NC.CollectReferences Card NIL NIL T))
		     when (NC.SameLinkP Link (CAR Obj))
		     do (COND
			    ((NOT WasActiveP)
			      (NCP.UncacheCards Card T)))
			  (RETURN (LIST (QUOTE LOCAL)
					    Card
					    (CDR Obj])

(NCP.GetTypeRecord
  [LAMBDA (TypeName)                                         (* rht: "18-Nov-85 00:40")

          (* * Return the record corresponding to this type name.)



          (* * rht 11/17/85: Now calls new NC function.)


    (NC.CardTypeRecord TypeName])

(NCP.AddLeftButtonTitleBarMenuItems
  [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])

(NCP.AddMiddleButtonTitleBarMenuItems
  [LAMBDA (Window NewMenuItems)                              (* rht: "17-Nov-86 00:15")

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


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

(NCP.CoerceToLinkDisplayMode
  [LAMBDA (Thing)                                            (* rht: "27-May-87 11:28")

          (* * Thing can be a cardtype, link, atom, list or LINKDISPLAYMODE record.)



          (* * Fixed so that returns non-nil, if Thing is already a linkdisplaymode.)



          (* * rht 5/27/87: Now checks for case of card type up front.)


    (PROG (DisplayMode)
	    (SETQ DisplayMode (COND
		((type? LINKDISPLAYMODE Thing)
		  (RETURN Thing))
		((NCP.CardTypeP Thing)
		  (NCP.CardTypeVar Thing (QUOTE LinkDisplayMode)))
		((NCP.ValidCardP Thing)
		  (NC.FetchLinkDisplayMode Thing))
		((NCP.ValidLinkP Thing)
		  (NCP.LinkDisplayMode Thing))
		(T Thing)))
	    (SETQ DisplayMode (COND
		((type? LINKDISPLAYMODE DisplayMode)
		  (RETURN DisplayMode))
		((FMEMB DisplayMode NCP.LinkDisplayModes)
		  (NC.MakeNewDisplayMode DisplayMode))
		((LISTP DisplayMode)
		  (create LINKDISPLAYMODE
			    SHOWTITLEFLG ← (CAR DisplayMode)
			    SHOWLINKTYPEFLG ← (CADR DisplayMode)
			    ATTACHBITMAPFLG ← (CADDR DisplayMode)))
		(T DisplayMode)))
	    (RETURN (if (type? LINKDISPLAYMODE DisplayMode)
			  then DisplayMode
			else NIL])

(NCP.CoerceToInterestedWindow
  [LAMBDA (WinOrCardOrNoteFile)                              (* pmi: "21-Oct-87 15:56")

          (* * pmi 10/21/87: Created to give prog int users the ability to get a reasonable window from various inputs.)


    (NC.CoerceToInterestedWindow WinOrCardOrNoteFile])
)
(* * Global variables.)

(DECLARE: DOEVAL@COMPILE DONTCOPY

(GLOBALVARS NCP.ErrorBrkWhenFlg NCP.LinkDisplayModes NCP.TypeFnsAssocLst NCP.NoteCardTypeFns 
	    NCP.NoteCardTypeVars NC.MakeDocParameters NC.CardTypes NC.SubstanceTypes 
	    NC.SystemLinkLabels NC.FiledCardLinkLabel NC.SubBoxLinkLabel NC.SelectingCardsMenu 
	    NC.SelectingCardMenu NC.UCASESystemLinkLabels NC.SourceLinkLabel NC.NoteCardsParameters)
)

(RPAQ? NCP.ErrorBrkWhenFlg NIL)

(RPAQ? NCP.DefaultLinkIconAttachedBitMapSize 17)

(RPAQ? NCP.LinkDisplayModes (QUOTE (Icon Title Label Both)))

(RPAQ? NCP.NoteCardTypeFns (QUOTE (MakeFn EditFn QuitFn GetFn PutFn CopyFn MarkDirtyFn DirtyPFn 
					    CollectLinksFn DeleteLinksFn UpdateLinkIconsFn 
					    InsertLinkFn TranslateWindowPositionFn)))

(RPAQ? NCP.NoteCardTypeVars (QUOTE (SuperType StubFlg FullDefinitionFile LinkDisplayMode 
						DefaultWidth DefaultHeight LinkAnchorModesSupported 
						DisplayedInMenuFlg LinkIconAttachedBitMap 
						LeftButtonMenuItems MiddleButtonMenuItems)))
(* * Following is for backward compatibility with 1.2)

(DECLARE: DONTEVAL@LOAD 
(MOVD (QUOTE NCP.OpenCard)
      (QUOTE NCP.BringUpCard)
      T)
(MOVD (QUOTE NCP.CacheCards)
      (QUOTE NCP.ActivateCards)
      T)
(MOVD (QUOTE NCP.CardCachedP)
      (QUOTE NCP.ActiveCardP)
      T)
(MOVD (QUOTE NCP.CardTypeFnP)
      (QUOTE NCP.ValidCardTypeFn)
      T)
(MOVD (QUOTE NCP.CardTypeP)
      (QUOTE NCP.ValidCardType)
      T)
(MOVD (QUOTE NCP.CardTypeVarP)
      (QUOTE NCP.ValidCardTypeVar)
      T)
(MOVD (QUOTE NCP.CloseCards)
      (QUOTE NCP.DeactivateCards)
      T)
(MOVD (QUOTE NCP.ValidCardP)
      (QUOTE NCP.ValidCard)
      T)
(MOVD (QUOTE NCP.ContentsFileBox)
      (QUOTE NCP.GetContentsFileBox)
      T)
(MOVD (QUOTE NCP.OrphansFileBox)
      (QUOTE NCP.GetOrphansFileBox)
      T)
(MOVD (QUOTE NCP.ToBeFiledFileBox)
      (QUOTE NCP.GetToBeFiledFileBox)
      T)
(MOVD (QUOTE NCP.LinkSource)
      (QUOTE NCP.GetLinkSource)
      T)
(MOVD (QUOTE NCP.LinkDestination)
      (QUOTE NCP.GetLinkDestination)
      T)
(MOVD (QUOTE NCP.CreateLinkType)
      (QUOTE NCP.CreateLinkLabel)
      T)
(MOVD (QUOTE NCP.DeleteLinkType)
      (QUOTE NCP.DeleteLinkLabel)
      T)
(MOVD (QUOTE NCP.RenameLinkType)
      (QUOTE NCP.RenameLinkLabel)
      T)
(MOVD (QUOTE NCP.LinkTypes)
      (QUOTE NCP.GetLinkLabels)
      T)
(MOVD (QUOTE NCP.UserLinkTypes)
      (QUOTE NCP.GetUserLinkLabels)
      T)
(MOVD (QUOTE NCP.ReverseLinkTypes)
      (QUOTE NCP.GetReverseLinkLabels)
      T)
(MOVD (QUOTE NCP.ValidLinkTypeP)
      (QUOTE NCP.ValidLinkLabel)
      T)
(MOVD (QUOTE NCP.ValidLinkP)
      (QUOTE NCP.ValidLink)
      T)
)
(DECLARE: DONTEVAL@LOAD DOEVAL@COMPILE DONTCOPY COMPILERVARS 

(ADDTOVAR NLAMA )

(ADDTOVAR NLAML )

(ADDTOVAR LAMA NCP.NoteFileProp NCP.CardUserDataProp NCP.PrintMsg NCP.PropSearch NCP.LinkType 
				  NCP.LinkDisplayMode NCP.CardRegion NCP.CardSubstance NCP.CardProp 
				  NCP.CardTitle NCP.CardTypeDisplayedInMenu)
)
(PUTPROPS NCPROGINT COPYRIGHT ("Xerox Corporation" 1984 1985 1986 1987 1988))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (8241 24100 (NCP.CreateNoteFile 8251 . 8922) (NCP.OpenNoteFile 8924 . 10370) (
NCP.OpenNoteFileP 10372 . 10741) (NCP.ListOfOpenNoteFiles 10743 . 11179) (NCP.CloseNoteFiles 11181 . 
12267) (NCP.CheckpointNoteFiles 12269 . 13003) (NCP.AbortNoteFiles 13005 . 13733) (NCP.CompactNoteFile
 13735 . 14054) (NCP.CompactNoteFileInPlace 14056 . 14318) (NCP.RepairNoteFile 14320 . 15040) (
NCP.DeleteNoteFile 15042 . 15744) (NCP.NoteFileFromFileName 15746 . 15982) (NCP.FileNameFromNoteFile 
15984 . 16521) (NCP.NoteFileMenu 16523 . 16778) (NCP.CheckInNoteFile 16780 . 19410) (
NCP.CheckOutNoteFile 19412 . 21596) (NCP.LockFileName 21598 . 22078) (NCP.NumCardSlotsRemaining 22080
 . 22650) (NCP.ExpandNoteFileIndex 22652 . 23349) (NCP.NoteFileClosingP 23351 . 23864) (
NCP.NoteFileAddProp 23866 . 24098)) (24167 36573 (NCP.CardTypes 24177 . 24382) (NCP.CreateCardType 
24384 . 25039) (NCP.DeleteCardType 25041 . 25220) (NCP.CreateCardTypeStub 25222 . 26051) (
NCP.ChangeCardTypeFields 26053 . 26541) (NCP.CardTypeSuper 26543 . 27005) (NCP.CardTypeLinkDisplayMode
 27007 . 27502) (NCP.CardTypeFn 27504 . 28465) (NCP.CardTypeVar 28467 . 29446) (NCP.CardTypeP 29448 . 
29718) (NCP.CardTypeFnP 29720 . 30010) (NCP.CardTypeVarP 30012 . 30308) (NCP.CardTypeFns 30310 . 30530
) (NCP.CardTypeVars 30532 . 30755) (NCP.CardTypeDisplayedInMenu 30757 . 32055) (NCP.IsSubTypeOfP 32057
 . 32610) (NCP.TextBasedP 32612 . 33198) (NCP.SketchBasedP 33200 . 33833) (NCP.GraphBasedP 33835 . 
34465) (NCP.AutoLoadCardType 34467 . 34742) (NCP.AddSpecialCard 34744 . 35298) (NCP.RemoveSpecialCard 
35300 . 35679) (NCP.CardsOfTypes 35681 . 36571)) (36986 46350 (NCP.CreateCard 36996 . 39315) (
NCP.CreateTextCard 39317 . 39823) (NCP.CreateFileBox 39825 . 40446) (NCP.CreateBrowserCard 40448 . 
42608) (NCP.CreateSketchCard 42610 . 43072) (NCP.CreateGraphCard 43074 . 43529) (NCP.MakeDocument 
43531 . 45043) (NCP.MakeLinkIndex 45045 . 46348)) (46407 54328 (NCP.OpenCard 46417 . 47170) (
NCP.CloseCards 47172 . 48915) (NCP.DisplayCard 48917 . 49910) (NCP.UndisplayCards 49912 . 51014) (
NCP.CacheCards 51016 . 51727) (NCP.UncacheCards 51729 . 52685) (NCP.CardCachedP 52687 . 52887) (
NCP.CardDisplayedP 52889 . 53159) (NCP.CardWindow 53161 . 53552) (NCP.WindowFromCard 53554 . 53818) (
NCP.CardFromWindow 53820 . 54056) (NCP.CardFromTextStream 54058 . 54326)) (54367 82502 (NCP.CardType 
54377 . 54709) (NCP.ValidCardP 54711 . 55165) (NCP.CardTitle 55167 . 56140) (NCP.FileCards 56142 . 
57389) (NCP.UnfileCards 57391 . 59884) (NCP.CardParents 59886 . 60578) (NCP.FileBoxChildren 60580 . 
61168) (NCP.CardNeighbors 61170 . 63949) (NCP.GetLinks 63951 . 66873) (NCP.CardPropList 66875 . 67163)
 (NCP.CardProp 67165 . 68508) (NCP.CardAddProp 68510 . 69802) (NCP.CardDelProp 69804 . 70983) (
NCP.CardSubstance 70985 . 72295) (NCP.CardRegion 72297 . 73872) (NCP.CardAddText 73874 . 75118) (
NCP.ChangeLoc 75120 . 76506) (NCP.DeleteCards 76508 . 77355) (NCP.FileBoxP 77357 . 77666) (
NCP.AllCards 77668 . 78002) (NCP.AllBoxes 78004 . 78349) (NCP.ContentsFileBox 78351 . 78680) (
NCP.OrphansFileBox 78682 . 79000) (NCP.ToBeFiledFileBox 79002 . 79319) (NCP.NoteFileFromCard 79321 . 
79569) (NCP.CardNoteFile 79571 . 79815) (NCP.SameCardP 79817 . 80299) (NCP.CoerceToCard 80301 . 80609)
 (NCP.DetermineDisplayRegion 80611 . 81030) (NCP.LockListOfCards 81032 . 81441) (
NCP.GetCrossFileLinkDestCard 81443 . 81970) (NCP.CardBeingDeletedP 81972 . 82242) (NCP.NewCardP 82244
 . 82500)) (84537 87897 (NCP.CollectCards 84547 . 86704) (NCP.CopyCards 86706 . 87537) (NCP.MoveCards 
87539 . 87895)) (87939 104441 (NCP.CreateLink 87949 . 89309) (NCP.LocalGlobalLink 89311 . 93387) (
NCP.GlobalGlobalLink 93389 . 95091) (NCP.GlobalLocalLink 95093 . 95499) (NCP.LocalLocalLink 95501 . 
95912) (NCP.LinkDesc 95914 . 96726) (NCP.LinkDisplayMode 96728 . 98422) (NCP.LinkType 98424 . 100491) 
(NCP.LinkSource 100493 . 100925) (NCP.LinkDestination 100927 . 101377) (NCP.DeleteLinks 101379 . 
102039) (NCP.ValidLinkP 102041 . 102257) (NCP.AllLinks 102259 . 102999) (NCP.SameLinkP 103001 . 103483
) (NCP.LinkFromLinkIcon 103485 . 103811) (NCP.MakeLinkIcon 103813 . 104023) (NCP.MarkCardDirty 104025
 . 104439)) (106579 112181 (NCP.CreateLinkType 106589 . 107379) (NCP.DeleteLinkType 107381 . 108713) (
NCP.RenameLinkType 108715 . 110439) (NCP.LinkTypes 110441 . 110750) (NCP.ReverseLinkTypes 110752 . 
111158) (NCP.UserLinkTypes 111160 . 111520) (NCP.ValidLinkTypeP 111522 . 111874) (NCP.SystemLinkTypeP 
111876 . 112179)) (112332 113322 (NCP.CardDates 112342 . 113320)) (113352 115099 (
NCP.GetOpenEventsCard 113362 . 114079) (NCP.GetCloseEventsCard 114081 . 114811) (
NCP.MarkAsNotNeedingFiling 114813 . 115097)) (115144 133440 (NCP.AddSessionIconMenuItem 115154 . 
117084) (NCP.RemoveSessionIconMenuItem 117086 . 119056) (NCP.RestoreSessionIconMenu 119058 . 120326) (
NCP.AddNoteFileIconMenuItem 120328 . 123739) (NCP.RemoveNoteFileIconMenuItem 123741 . 125173) (
NCP.RestoreNoteFileIconMenu 125175 . 126003) (NC.CreateSessionIconNoteFileMenuItem 126005 . 126890) (
NCP.AddDefaultNoteFileIconMiddleButtonItems 126892 . 127662) (NCP.NoticedNoteFileNamesMenu 127664 . 
128480) (NCP.AddTitleBarMenuItemsToType 128482 . 130311) (NCP.AddTitleBarMenuItemsToWindow 130313 . 
132042) (NCP.LinkIconAttachedBitMap 132044 . 132805) (NCP.SessionIconWindow 132807 . 133124) (
NCP.BringUpSessionIcon 133126 . 133438)) (133467 154611 (NCP.TitleSearch 133477 . 134737) (
NCP.PropSearch 134739 . 135993) (NCP.WhichCard 135995 . 136414) (NCP.WhichNoteFile 136416 . 137132) (
NCP.SelectCards 137134 . 138525) (NCP.DocumentParameters 138527 . 140551) (NCP.NoteCardsParameters 
140553 . 143301) (NCP.PrintMsg 143303 . 143760) (NCP.ClearMsg 143762 . 144023) (NCP.AskUser 144025 . 
144441) (NCP.AskYesOrNo 144443 . 144861) (NCP.RegisterCardByName 144863 . 145878) (
NCP.ListRegisteredCards 145880 . 147286) (NCP.LookupCardByName 147288 . 148241) (NCP.UnregisterName 
148243 . 149190) (NCP.DisplayedCards 149192 . 150560) (NCP.CardUserDataProp 150562 . 151537) (
NCP.NoteFileProp 151539 . 152737) (NCP.SetUpTitleBar 152739 . 153185) (
NCP.AddNoteFileIconMiddleButtonItems 153187 . 154358) (NCP.NoteFileIconWindow 154360 . 154609)) (
154797 161153 (NCP.ReportError 154807 . 155538) (NCP.ReportWarning 155540 . 156157) (
NCP.LinkAnchorDesc 156159 . 158131) (NCP.GetTypeRecord 158133 . 158423) (
NCP.AddLeftButtonTitleBarMenuItems 158425 . 158981) (NCP.AddMiddleButtonTitleBarMenuItems 158983 . 
159545) (NCP.CoerceToLinkDisplayMode 159547 . 160837) (NCP.CoerceToInterestedWindow 160839 . 161151)))
))
STOP