(FILECREATED " 2-Mar-87 23:32:50" {QV}<NOTECARDS>1.3K>NEXT>RHTPATCH210.;3 88294  

      changes to:  (VARS RHTPATCH210COMS)
		   (FNS NCP.ReportError NCP.SelectCards NC.SelectNoteCards NC.ReportError)

      previous date: " 2-Mar-87 22:22:26" {QV}<NOTECARDS>1.3K>NEXT>RHTPATCH210.;1)


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

(PRETTYCOMPRINT RHTPATCH210COMS)

(RPAQQ RHTPATCH210COMS ((* * Fixes bug #448: NCP.SketchBasedP, NCP.GraphBasedP, etc. now cause 
			     autoload if card type isn't defined. Fixed Lyric bug reported by Kirk 
			     and Jeff whereby NCP.ReportError was being called with string arg. 
			     Changed all the calls to NCP.ReportError. For NC.ReportError, I just 
			     coerced the function name to be an atom. Fix to bug #128: Changed calls 
			     to NC.PrintMsg and NC.ClearMsg in NC.SelectNoteCards to use PromptWindow 
			     rather than InstigatingWindow. Fix to bug #342: In NCP.SelectCards, now 
			     makes sure instigating card is displayed, else passes NIL to 
			     NC.SelectNoteCards.)
	(* * Changes to NCPROGINT)
	(FNS NCP.IsSubTypeOfP NCP.TextBasedP NCP.SketchBasedP NCP.GraphBasedP)
	(FNS NCP.CreateNoteFile NCP.CloseNoteFiles NCP.CheckpointNoteFiles NCP.AbortNoteFiles 
	     NCP.RepairNoteFile NCP.FileNameFromNoteFile NCP.ChangeCardTypeFields NCP.CardTypeSuper 
	     NCP.CardTypeLinkDisplayMode NCP.CardTypeFn NCP.CardTypeVar NCP.CardTypeDisplayedInMenu 
	     NCP.CreateCard NCP.CreateBrowserCard NCP.MakeDocument NCP.MakeLinkIndex NCP.OpenCard 
	     NCP.CloseCards NCP.DisplayCard NCP.UndisplayCards NCP.CacheCards NCP.UncacheCards 
	     NCP.CardTitle NCP.FileCards NCP.UnfileCards NCP.CardParents NCP.FileBoxChildren 
	     NCP.GetLinks NCP.CardProp NCP.CardAddProp NCP.CardDelProp NCP.CardSubstance 
	     NCP.CardRegion NCP.CardAddText NCP.ChangeLoc NCP.DeleteCards NCP.SameCardP 
	     NCP.CreateLink NCP.LocalGlobalLink NCP.GlobalGlobalLink NCP.GlobalLocalLink 
	     NCP.LocalLocalLink NCP.LinkDesc NCP.LinkDisplayMode NCP.LinkType NCP.LinkSource 
	     NCP.LinkDestination NCP.DeleteLinks NCP.SameLinkP NCP.CreateLinkType NCP.DeleteLinkType 
	     NCP.RenameLinkType NCP.CardDates NCP.DocumentParameters NCP.NoteCardsParameters 
	     NCP.RegisterCardByName NCP.LookupCardByName NCP.UnregisterName NCP.CardUserDataProp 
	     NCP.NoteFileProp)
	(FNS NCP.SelectCards NCP.ReportError)
	(* * Change to NCUTILITIES)
	(FNS NC.ReportError)
	(* * Change to NCINTERFACE)
	(FNS NC.SelectNoteCards)
	(DECLARE: DONTEVAL@LOAD DOEVAL@COMPILE DONTCOPY COMPILERVARS
		  (ADDVARS (NLAMA)
			   (NLAML)
			   (LAMA NCP.NoteFileProp NCP.CardUserDataProp NCP.LinkType 
				 NCP.LinkDisplayMode NCP.CardSubstance NCP.CardProp NCP.CardTitle 
				 NCP.CardTypeDisplayedInMenu)))))
(* * Fixes bug #448: NCP.SketchBasedP, NCP.GraphBasedP, etc. now cause autoload if card type 
isn't defined. Fixed Lyric bug reported by Kirk and Jeff whereby NCP.ReportError was being 
called with string arg. Changed all the calls to NCP.ReportError. For NC.ReportError, I just 
coerced the function name to be an atom. Fix to bug #128: Changed calls to NC.PrintMsg and 
NC.ClearMsg in NC.SelectNoteCards to use PromptWindow rather than InstigatingWindow. Fix to bug
 #342: In NCP.SelectCards, now makes sure instigating card is displayed, else passes NIL to 
NC.SelectNoteCards.)

(* * Changes to NCPROGINT)

(DEFINEQ

(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)))))
)
(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.CloseNoteFiles
  (LAMBDA (NoteFilesOrT QuietFlg AutoConfirmFlg)             (* rht: " 2-Mar-87 21:58")

          (* * 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 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.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.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.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.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.CreateCard
  (LAMBDA (Type NoteFile Title NoDisplayFlg Props ParentFileBoxes TypeSpecificArgs)
                                                             (* rht: " 2-Mar-87 22:09")

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


    (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.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.CreateBrowserCard
  (LAMBDA (NoteFile Title ParamList NoDisplayFlg Props ParentFileBoxes)
                                                             (* rht: " 2-Mar-87 22:00")

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


    (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))
					    ((NOT (NCP.ValidLinkTypeP LinkType NoteFile))
					      (NCP.ReportError (QUOTE NCP.CreateBrowserCard)
								 (CONCAT LinkType 
									" not a valid link type."))
					      NIL)
					    (T (LIST LinkType)))))
         (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.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)))))
)

(NCP.OpenCard
  (LAMBDA (Card Region/Position TypeSpecificArgs)            (* rht: " 2-Mar-87 22:09")

          (* * 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 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)                                   (* rht: " 2-Mar-87 22:00")

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



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


    (for Card in (MKLIST Cards) bind Win (OldProc ←(TTY.PROCESS))
       do (if (NOT (NC.ValidCardP Card))
		then (NCP.ReportError (QUOTE NCP.CloseCards)
					  (CONCAT Card " not an existing card or filebox."))
	      elseif (AND (NCP.CardCachedP Card)
			      (NEQ (NC.QuitCard Card T NIL NIL NIL NIL NIL QuietFlg)
				     (QUOTE DON'T))
			      (SETQ Win (NC.FetchWindow Card)))
		then (bind (Process ←(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)            (* rht: " 2-Mar-87 22:09")

          (* * display Card on the screen.)



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


    (if (NC.ValidCardP Card)
	then (if (NCP.CardCachedP Card)
		   then (LET ((OldProc (TTY.PROCESS)))
			       (PROG1 (NC.EditNoteCard 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)                   (* rht: " 2-Mar-87 22:00")

          (* * 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 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)                                   (* rht: " 2-Mar-87 22:10")

          (* * 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 NIL QuietFlg))
					     ))))

(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.GetLinks
  (LAMBDA (Cards DestinationCards Labels NoteFile)           (* rht: " 2-Mar-87 22:02")

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


    (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 (LET ((HadLinksCachedFlg (NC.LinksCachedP Card)))
			         (PROG1 (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)
					  (OR HadLinksCachedFlg (NC.UncacheLinks Card))))))
	   (DestinationCards (for Card in ValidDestinationCards eachtime (BLOCK)
				join (LET ((HadLinksCachedFlg (NC.LinksCachedP Card)))
					    (PROG1 (for Link in (NC.RetrieveFromLinks Card)
							when (COND
								 (Labels (FMEMB
									   (fetch (Link Label)
									      of Link)
									   Labels))
								 (T T))
							collect Link)
						     (OR HadLinksCachedFlg (NC.UncacheLinks
							     Card))))))
	   (T (NCP.MapLinks NoteFile (FUNCTION PROG1)
			    (FUNCTION (LAMBDA (Link)
				(if Labels
				    then (FMEMB (fetch (Link Label) of Link)
						    Labels)
				  else T)))))))))

(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: " 2-Mar-87 22:02")

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


    (if (NC.ValidCardP Card)
	then (LET* ((PropList (NC.RetrievePropList Card))
		      (OldPropValue (LISTGET PropList Property)))
		     (if (NOT (FMEMB ItemToAdd (MKLIST OldPropValue)))
			 then (LISTPUT PropList Property (APPEND (MKLIST OldPropValue)
								       (LIST 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 (Card)                                             (* 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/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)
		    (OR (SETQ WasActive (NCP.CardCachedP Card))
			  (NCP.CacheCards Card))
		    (PROG1 (NC.FetchRegion Card)
			     (OR WasActive (NCP.UncacheCards Card T))))
      else (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.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.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: " 2-Mar-87 22:04")

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


    (PROG ((CoercedDisplayMode (NCP.CoerceToLinkDisplayMode (OR DisplayMode (NCP.CardType
									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)                                             (* rht: " 2-Mar-87 22:11")

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


    (COND
      ((NCP.ValidLink Link)
	(LIST (fetch (Link Label) of Link)
		(NCP.LinkAnchorDesc Link NIL)
		(NCP.LinkAnchorDesc Link T)))
      (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.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.CreateLinkType
  (LAMBDA (LinkType NoteFile)                                (* rht: " 2-Mar-87 22:05")

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


    (if (FMEMB LinkType (NCP.LinkTypes NoteFile))
	then (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.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)))

(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.RegisterCardByName
  (LAMBDA (Name Card)                                        (* rht: " 2-Mar-87 22:12")

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



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


    (if (NC.ValidCardP Card)
	then (NC.RegisterCardByName (fetch (NoteFile RegistryCard) of (NCP.NoteFileFromCard
										Card))
					Name Card)
      else (NCP.ReportError (QUOTE NCP.RegisterCardByName)
				(CONCAT Card " is not a valid notecard.")))))

(NCP.LookupCardByName
  (LAMBDA (Name NoteFile)                                    (* rht: " 2-Mar-87 22:12")

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



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


    (if (NCP.OpenNoteFileP NoteFile)
	then (NC.LookupCardByName (fetch (NoteFile RegistryCard) of NoteFile)
				      Name)
      else (NCP.ReportError (QUOTE NCP.LookupCardByName)
				(CONCAT NoteFile " is not an open notefile.")))))

(NCP.UnregisterName
  (LAMBDA (Name NoteFile)                                    (* rht: " 2-Mar-87 22:12")

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



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


    (if (NCP.OpenNoteFileP NoteFile)
	then (NC.UnregisterName (fetch (NoteFile RegistryCard) of NoteFile)
				    Name)
      else (NCP.ReportError (QUOTE NCP.UnregisterName)
				(CONCAT NoteFile " is not an open notefile.")))))

(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)))))
)
(DEFINEQ

(NCP.SelectCards
  (LAMBDA (InstigatingCardOrWindow SingleCardFlg SelectionPredicate Msg CheckForCancelFlg)
                                                             (* rht: " 2-Mar-87 22:52")

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


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

(DEFINEQ

(NC.ReportError
  (LAMBDA (FromFunction Msg)                                 (* rht: " 2-Mar-87 22:22")

          (* * fgh 9/4/86 If \NC.NoBreakInReportError is non-NIL just prints msg in prompt window and cause ERROR!.)



          (* * rht 3/2/87: coerced the function name to be an atom to fix a bug showing up in lyric.)


    (DECLARE (GLOBALVARS \NC.NoBreakInReportError))
    (if \NC.NoBreakInReportError
	then (FLASHW PROMPTWINDOW)
	       (CLRPROMPT)
	       (PROMPTPRINT "NoteCards Error")
	       (PROMPTPRINT Msg)
	       (ERROR!)
      else (APPLY* (FUNCTION BREAK1)
		       T T (MKATOM FromFunction)
		       NIL NIL (LIST Msg)))))
)
(* * Change to NCINTERFACE)

(DEFINEQ

(NC.SelectNoteCards
  (LAMBDA (SingleCardFlg SelectionPredicate Menu InstigatingCardOrWindow Msg CheckForCancelFlg)
                                                             (* rht: " 2-Mar-87 22:39")

          (* Select a set of note cards or a single note card, depending on SingleCardFlg. Works by interpreting all mouse 
	  presses until a card has been chosen (if SingleCardFlg is T) or until the Done button has been pressed 
	  (if SingleCardFlg is NIL). If the mouse press occus within a Title bar of a notecard, add that note card to the 
	  selected list. Otherwise, if you are pointing into a note card, call the BUTTONEVENTFN for that note card.
	  The Selection in Progress flag has been set, so all note card BUTTONEVENTFNs should know to ignore all presses 
	  except those that occur on link icons. Link icon presses should simply add the desination of that link to the 
	  selected note cards list.)



          (* * rht 8/1/84: Changed second RESETSAVE call to give NC.ClearMsg a NIL argument.)



          (* * rht 1/9/85: Fixed so now prints name of selected item even it's a link.)



          (* * rht 2/15/85: Now can backspace over last selection chosen. Added new arg Msg so that when we reprint the list,
	  we can reprint the message as well.)



          (* * rht 3/23/85: Added the CheckForCancelFlg arg, which if non-nil causes Cancel to be handled differently then 
	  Done after no selections. Namely, Cancel will return the atom CANCELLED whereas Done with no selections returns 
	  NIL. If CheckForCancelFlg is NIL then NIL is returned in both cases.)



          (* * fgh 11/14/85 Updated to handle Card and NoteFile objects.)



          (* * rht 11/18/85: Fixed so able to select when InstigatingNoteFile is NIL.)



          (* * fgh 12/20/85 Totally rewritten for 1.3 selection mechanism. Based on COPYINSERT now rather than on takingf 
	  over the mouse process.)



          (* * fgh 1/15/86 Added call to SPAWN.MOUSE in case this is called under the mouse process)



          (* * kirk 25Apr86 Changed to use SessionIcon (NC.NoteCardsIconWindow) rather than PROMPTWINDOW if no Instigating 
	  window is supplied.)



          (* * fgh 7/5/86 Added code to put CRs into printout of selected cards in order to keep prompt window from getting 
	  infinitely wide to accomdate the printout.)



          (* * rht 10/5/86: Now allows choice of cards from remote notefile.)



          (* * rht 10/18/86: Give TTY process to process that originally had it if possible.)



          (* * rht & pmi 11/14/86: Now checks for valid card before testing SelectionPredicate.)



          (* * pmi 12/5/86 Modified prompt messages to mention SHIFT-selection.)



          (* * pmi 12/12/86: Removed obsolete ReturnLinksFlg argument.)



          (* * rht 3/2/87: Fix to bug #128: Changed calls to NC.PrintMsg and NC.ClearMsg to use PromptWindow rather than 
	  InstigatingWindow.)


    (RESETLST (LET (Window Card ButtonEventFn InstigatingWindow InstigatingCard InstigatingNoteFile 
			     MenuWindow PromptWindow CopyInsertEvent SelectedCards 
			     PromptWindowProcess OldTTYProcess)
		     (OR SelectionPredicate (SETQ SelectionPredicate (FUNCTION TRUE)))
		     (COND
		       ((NC.CardP InstigatingCardOrWindow)
			 (SETQ InstigatingWindow (NC.FetchWindow InstigatingCardOrWindow))
			 (SETQ PromptWindow (NC.AttachPromptWindow InstigatingWindow)))
		       ((WINDOWP InstigatingCardOrWindow)
			 (SETQ InstigatingWindow InstigatingCardOrWindow)
			 (SETQ PromptWindow (NC.AttachPromptWindow InstigatingWindow)))
		       (T (SETQ InstigatingWindow (SETQ PromptWindow (NC.AttachPromptWindow
				NC.NoteCardsIconWindow)))))
		     (SETQ InstigatingCard (NC.CoerceToCard InstigatingCardOrWindow))
		     (SETQ InstigatingNoteFile (AND InstigatingCard (fetch (Card NoteFile)
									   of InstigatingCard)))
		     (NC.PrintMsg PromptWindow T (COND
				      (Msg (CONCAT Msg (CHARACTER 13)))
				      (T ""))
				    "Items shift-selected:  ")
		     (SETQ OldTTYProcess (TTY.PROCESS))

          (* * if we are running under the mouse process, start up a new mouse process)


		     (AND (EQ (QUOTE MOUSE)
				  (PROCESSPROP (THIS.PROCESS)
						 (QUOTE NAME)))
			    (SPAWN.MOUSE))

          (* * Set up the prompt window for proper use by the CopyInsertFn)


		     (WINDOWPROP PromptWindow (QUOTE COPYINSERTFN)
				   (FUNCTION NC.SelectNoteCardsCopyInsertFn))
		     (WINDOWPROP PromptWindow (QUOTE CopyInsertEvent)
				   (SETQ CopyInsertEvent (CREATE.EVENT (QUOTE CopyInsertEvent)))
				   )
		     (RESETSAVE (WINDOWPROP PromptWindow (QUOTE SelectedCards)
						NIL)
				  (BQUOTE (WINDOWPROP , PromptWindow (QUOTE SelectedCards)
							  NIL)))
		     (RESETSAVE (WINDOWPROP PromptWindow (QUOTE SelectingCards)
						T)
				  (BQUOTE (WINDOWPROP , PromptWindow SelectingCards NIL)))

          (* * Make the process behind the prompt window includiong control for a blibnking cursor)


		     (WINDOWPROP PromptWindow (QUOTE PROCESS)
				   (SETQ PromptWindowProcess
				     (ADD.PROCESS (QUOTE (PROG NIL (BLOCK)
								     (TTYDISPLAYSTREAM
								       (PROCESSPROP (THIS.PROCESS)
										      (QUOTE WINDOW)
										      ))
								     XXXX
								     (BIN)
								     (BLOCK)
								     (GO XXXX)))
						    (QUOTE WINDOW)
						    PromptWindow
						    (QUOTE NAME)
						    (QUOTE SelectNoteCardsProc)
						    (QUOTE TTYENTRYFN)
						    (FUNCTION (LAMBDA (Process)
							(PROCESSPROP Process (QUOTE OldCaret)
								       (CARET CROSSHAIRS))
							(ECHOMODE)))
						    (QUOTE TTYEXITFN)
						    (FUNCTION (LAMBDA (Process)
							(CARET (PROCESSPROP Process (QUOTE
										  OldCaret)))
							(ECHOMODE T))))))
		     (RESETSAVE NIL (BQUOTE (DEL.PROCESS , PromptWindowProcess)))

          (* * Insure the prompt window is cleared on the way out)


		     (RESETSAVE NIL (BQUOTE (PROGN (AND (HASTTYWINDOWP , 
									      PromptWindowProcess)
								(TTY.PROCESS
								  (if (AND (PROCESSP , 
										    OldTTYProcess)
									       (HASTTYWINDOWP
										 , OldTTYProcess))
								      then , OldTTYProcess
								    else T)))
							 (NC.ClearMsg , PromptWindow T))))

          (* * Set up the menu above the prompt window)

                                                             (* fix in case MENUPOSITION is set incorrectly in menu
							     passed down)
		     (replace (MENU MENUPOSITION) of Menu
			with (CONSTANT (create POSITION
						     XCOORD ← 0
						     YCOORD ← 0)))
		     (RESETSAVE (ATTACHMENU Menu PromptWindow (if InstigatingWindow
								      then (QUOTE TOP)
								    else (QUOTE BOTTOM))
						(QUOTE LEFT))
				  (BQUOTE (PROGN (DETACHWINDOW (WFROMMENU , Menu))
						     (DELETEMENU , Menu T))))

          (* * If there is an instigating window, make sure it and all its attachments are visible on the screen.)


		     (if InstigatingWindow
			 then (NC.MoveWindowOntoScreen InstigatingWindow))

          (* * Give the prompt window the tty process)


		     (TTY.PROCESS (WINDOWPROP PromptWindow (QUOTE PROCESS)))

          (* * Loop as long as necessary)


		     (until (OR (EQ SelectedCards (QUOTE CANCELLED))
				    (AND SingleCardFlg SelectedCards)
				    (EQ (CAR SelectedCards)
					  (QUOTE DONE)))
			do (

          (* * Wait for the user to respond by copy inserting something into the prompt window)


			      (until (EQ CopyInsertEvent (AWAIT.EVENT CopyInsertEvent))
				 do NIL)

          (* * Get the latest selection list)


			      (SETQ SelectedCards (WINDOWPROP PromptWindow (QUOTE SelectedCards)
								  ))
			      (RESETLST 

          (* * Turn off the caret)


					  (RESETSAVE (TTY.PROCESS (THIS.PROCESS)))

          (* * If the last thing wasn't a done or cancel, process the new selection)


					  (COND
					    ((AND (NEQ (CAR SelectedCards)
							   (QUOTE DONE))
						    (NEQ SelectedCards (QUOTE CANCELLED))
						    (NEQ (CAR SelectedCards)
							   (QUOTE *New% Card*)))

          (* * Check to make sure that the selection is valid)


					      (COND
						((EQ (CAR SelectedCards)
						       (QUOTE *Undo% Selection*))
                                                             (* Chop off two elements from the list -
							     the indicator and the previous item.)
						  (WINDOWPROP PromptWindow (QUOTE SelectedCards)
								(SETQ SelectedCards (CDDR 
										    SelectedCards)))
						  (NC.ClearMsg PromptWindow NIL))
						((OR (NOT (NC.ValidCardP (CAR SelectedCards)))
						       (NULL (APPLY* SelectionPredicate
									 (CAR SelectedCards))))
                                                             (* Does this card match the slection predicate)
						  (NC.PrintMsg PromptWindow T 
								 "*** Invalid selection. ***"
								 (CHARACTER 13))
						  (WINDOWPROP PromptWindow (QUOTE SelectedCards)
								(SETQ SelectedCards (CDR 
										    SelectedCards))))
						(T           (* A valid selection.)
						   (NC.ClearMsg PromptWindow NIL)))

          (* * Print the results in the prompt window)


					      (NC.PrintMsg PromptWindow NIL
							     (COND
							       (Msg (CONCAT Msg (CHARACTER 13)))
							       (T ""))
							     "Items selected:  ")
					      (for Card in (REVERSE SelectedCards)
						 do
						  (NC.PrintMsg PromptWindow NIL (NC.RetrieveTitle
								   Card)
								 ",  ")
						  (if (AND InstigatingWindow
							       (GREATERP
								 (DSPXPOSITION NIL PromptWindow)
								 (TIMES 1.25 (WINDOWPROP
									    InstigatingWindow
									    (QUOTE WIDTH)))))
						      then (NC.PrintMsg PromptWindow NIL
									    (CHARACTER 13)))))))))

          (* * Return the result)


		     (PROG1 (COND
				((EQ SelectedCards (QUOTE CANCELLED))
				  (COND
				    (CheckForCancelFlg (QUOTE CANCELLED))
				    (T NIL)))
				(SingleCardFlg (if (EQ (CAR SelectedCards)
							   (QUOTE DONE))
						   then NIL
						 else (CAR SelectedCards)))
				(T (if (EQ (CAR SelectedCards)
					       (QUOTE DONE))
				       then (DREVERSE (CDR SelectedCards))
				     else (DREVERSE SelectedCards))))
			      (WINDOWPROP PromptWindow (QUOTE SelectedCards)
					    NIL))))))
)
(DECLARE: DONTEVAL@LOAD DOEVAL@COMPILE DONTCOPY COMPILERVARS 

(ADDTOVAR NLAMA )

(ADDTOVAR NLAML )

(ADDTOVAR LAMA NCP.NoteFileProp NCP.CardUserDataProp NCP.LinkType NCP.LinkDisplayMode 
				  NCP.CardSubstance NCP.CardProp NCP.CardTitle 
				  NCP.CardTypeDisplayedInMenu)
)
(PUTPROPS RHTPATCH210 COPYRIGHT ("Xerox Corporation" 1987))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (3383 5813 (NCP.IsSubTypeOfP 3393 . 3947) (NCP.TextBasedP 3949 . 4538) (NCP.SketchBasedP
 4540 . 5176) (NCP.GraphBasedP 5178 . 5811)) (5814 73816 (NCP.CreateNoteFile 5824 . 6497) (
NCP.CloseNoteFiles 6499 . 7584) (NCP.CheckpointNoteFiles 7586 . 8323) (NCP.AbortNoteFiles 8325 . 9056)
 (NCP.RepairNoteFile 9058 . 9780) (NCP.FileNameFromNoteFile 9782 . 10321) (NCP.ChangeCardTypeFields 
10323 . 10814) (NCP.CardTypeSuper 10816 . 11279) (NCP.CardTypeLinkDisplayMode 11281 . 11777) (
NCP.CardTypeFn 11779 . 12741) (NCP.CardTypeVar 12743 . 13723) (NCP.CardTypeDisplayedInMenu 13725 . 
15031) (NCP.CreateCard 15033 . 17092) (NCP.CreateBrowserCard 17094 . 19015) (NCP.MakeDocument 19017 . 
20531) (NCP.MakeLinkIndex 20533 . 21846) (NCP.OpenCard 21848 . 22462) (NCP.CloseCards 22464 . 23468) (
NCP.DisplayCard 23470 . 24267) (NCP.UndisplayCards 24269 . 25389) (NCP.CacheCards 25391 . 26104) (
NCP.UncacheCards 26106 . 27073) (NCP.CardTitle 27075 . 28055) (NCP.FileCards 28057 . 29309) (
NCP.UnfileCards 29311 . 31825) (NCP.CardParents 31827 . 32522) (NCP.FileBoxChildren 32524 . 33116) (
NCP.GetLinks 33118 . 36293) (NCP.CardProp 36295 . 37648) (NCP.CardAddProp 37650 . 38698) (
NCP.CardDelProp 38700 . 39880) (NCP.CardSubstance 39882 . 41199) (NCP.CardRegion 41201 . 41995) (
NCP.CardAddText 41997 . 43243) (NCP.ChangeLoc 43245 . 44635) (NCP.DeleteCards 44637 . 45486) (
NCP.SameCardP 45488 . 45973) (NCP.CreateLink 45975 . 47343) (NCP.LocalGlobalLink 47345 . 51396) (
NCP.GlobalGlobalLink 51398 . 53103) (NCP.GlobalLocalLink 53105 . 53512) (NCP.LocalLocalLink 53514 . 
53926) (NCP.LinkDesc 53928 . 54623) (NCP.LinkDisplayMode 54625 . 56337) (NCP.LinkType 56339 . 58420) (
NCP.LinkSource 58422 . 58857) (NCP.LinkDestination 58859 . 59313) (NCP.DeleteLinks 59315 . 59979) (
NCP.SameLinkP 59981 . 60466) (NCP.CreateLinkType 60468 . 61135) (NCP.DeleteLinkType 61137 . 62471) (
NCP.RenameLinkType 62473 . 64205) (NCP.CardDates 64207 . 65185) (NCP.DocumentParameters 65187 . 67225)
 (NCP.NoteCardsParameters 67227 . 69984) (NCP.RegisterCardByName 69986 . 70561) (NCP.LookupCardByName 
70563 . 71095) (NCP.UnregisterName 71097 . 71621) (NCP.CardUserDataProp 71623 . 72605) (
NCP.NoteFileProp 72607 . 73814)) (73817 75832 (NCP.SelectCards 73827 . 75094) (NCP.ReportError 75096
 . 75830)) (75867 76599 (NC.ReportError 75877 . 76597)) (76634 87923 (NC.SelectNoteCards 76644 . 87921
)))))
STOP