(FILECREATED "12-Sep-86 00:54:31" {QV}<NOTECARDS>1.3K>NEXT>RHTPATCH107.;2 6928   

      changes to:  (FNS NCLocalDevice.PutCardPart)
		   (VARS RHTPATCH107COMS)

      previous date: "11-Sep-86 21:39:06" {QV}<NOTECARDS>1.3K>NEXT>RHTPATCH107.;1)


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

(PRETTYCOMPRINT RHTPATCH107COMS)

(RPAQQ RHTPATCH107COMS ((* * Change to NCDATABASE)
			  (FNS NC.PutFromLinks)
			  (* * Change to NCLOCALDEVICE)
			  (FNS NCLocalDevice.PutCardPart)))
(* * Change to NCDATABASE)

(DEFINEQ

(NC.PutFromLinks
  (LAMBDA (Card)                                             (* rht: "11-Sep-86 21:32")

          (* * The top level function for writing out only the FROMLINKS of a card. Became a necessary function in the 
	  process of implementing the Server.)



          (* * rht 9/11/86: Now checks for card active via NC.CardActiveP rather than by checking for ACTIVE status.)

                                                             (* Check to make sure this is an active note card.)
    (DECLARE (GLOBALVARS NC.LinksIdentifier))
    (if (NOT (NC.ActiveCardP Card))
	then (NC.ReportError "NC.PutFromLinks" (CONCAT (NC.FetchTitle Card)
							     " is not an active note card.")))
    (LET (PutSuccessfulLoc)
         (WITH.MONITOR (NC.FetchMonitor (fetch (Card NoteFile) of Card))
		       (RESETLST (RESETSAVE (APPLY* (fetch (NoteFile PutCardPartFn)
							     of (fetch (Card NoteFile)
								     of Card))
							  Card
							  (QUOTE FROMLINKS)
							  (QUOTE BEFORE))
						(BQUOTE (APPLY* , (fetch (NoteFile 
										    PutCardPartFn)
									 of (fetch (Card NoteFile)
										 of Card))
								    , Card FROMLINKS AFTER)))
				   (LET ((Stream (NC.CoerceToNoteFileStream Card))
					 StartLoc)

          (* * Write the links data at the end of the database file.)


				        (SETQ StartLoc (GETFILEPTR Stream))
				        (NC.WriteCardPartHeader Card NC.LinksIdentifier
								  (NC.SetLinksDate Card (DATE))
								  Stream)
				        (NC.WriteListOfLinks Stream (NC.FetchFromLinks Card))

          (* * Now update the index to point to the link data just written. Done last in case writing of links doesn't 
	  complete okay.)


				        (NC.SetLinksDirtyFlg Card)

          (* * Now, since we were successful, we'll bind the PutSuccessfulLoc variable, which will be used freely by the 
	  AFTER PutCardPartFns to determine first if the Put succeeded, and if so, where in the stream it was Put.)


				        (SETQ PutSuccessfulLoc StartLoc)
				    Card))))))
)
(* * Change to NCLOCALDEVICE)

(DEFINEQ

(NCLocalDevice.PutCardPart
  (LAMBDA (Card CardPartName WhenFlg)                        (* rht: "12-Sep-86 00:52")

          (* * This is the local single user device put card part function.)



          (* * The free variable PutSuccessfulLoc is bound in the calling function, either NC.PutTitle or NC.PutLinks, etc. 
	  If NIL, then the Put wasn't successful, so report the error. If non-NIL, then it should be the position in the file
	  where we put the card part, so now we can set the appropriate card part loc slot to be that number.)



          (* * kef 7/28/86: Added REGION possibility to CardPartName.)



          (* * rht&fgh 9/12/86: Now doesn't try to read links card parts if card is new in FROMLINKS/BEFORE case.)


    (DECLARE (GLOBALVARS NC.LinksIdentifier))
    (SELECTQ WhenFlg
	       (BEFORE (SELECTQ CardPartName
				  (FROMLINKS

          (* * In this case, let's grab the TOLINKS and GLOBALTOLINKS as they exist on the file still, and save them on the 
	  Card's UserProps, so that we can use them in the AFTER function to write them.)


				    (WITH.MONITOR (NC.FetchMonitor (fetch (Card NoteFile)
									of Card))
						  (LET (ToLinks GlobalLinks)
						       (if (NOT (NC.FetchNewCardFlg Card))
							   then
							    (SETFILEPTR (fetch (NoteFile Stream)
									     of
									      (fetch (Card NoteFile)
										 of Card))
									  (fetch (Card LinksLoc)
									     of Card))
							    (NC.ReadCardPartHeader
							      Card NC.LinksIdentifier
							      (fetch (NoteFile Stream)
								 of (fetch (Card NoteFile)
									 of Card)))
							    (SETQ ToLinks
							      (NC.ReadListOfLinks
								(fetch (NoteFile Stream)
								   of (fetch (Card NoteFile)
									   of Card))))
							    (NC.ReadListOfLinks
							      (fetch (NoteFile Stream)
								 of (fetch (Card NoteFile)
									 of Card)))
							    (SETQ GlobalLinks
							      (NC.ReadListOfLinks
								(fetch (NoteFile Stream)
								   of (fetch (Card NoteFile)
									   of Card)))))
						       (NC.PutProp Card (QUOTE OldLinks)
								     (CONS ToLinks GlobalLinks)))
						  (SETFILEPTR (fetch (NoteFile Stream)
								   of (fetch (Card NoteFile)
									   of Card))
								-1)))
				  ((TITLE SUBSTANCE LINKS PROPLIST)
				    (SETFILEPTR (fetch (NoteFile Stream)
						     of (fetch (Card NoteFile) of Card))
						  -1))
				  (REGION                    (* In the region case, set the file pointer to the 
							     spot in the NoteFile just past the Card Type in the 
							     header information.)
					  (SETFILEPTR (fetch (NoteFile Stream)
							   of (fetch (Card NoteFile)
								   of Card))
							(fetch (Card MainLoc) of Card))
					  (NC.ReadCardPartHeader Card NC.ItemIdentifier
								   (fetch (NoteFile Stream)
								      of (fetch (Card NoteFile)
									      of Card)))
					  (NC.ReadCardType (fetch (NoteFile Stream)
								of (fetch (Card NoteFile)
									of Card))))
				  (SHOULDNT (CONCAT "Bad card part name:  " CardPartName))))
	       (AFTER (AND PutSuccessfulLoc (SELECTQ CardPartName
							 (TITLE (NC.SetTitleLoc Card 
										 PutSuccessfulLoc))
							 (SUBSTANCE (NC.SetMainLoc Card 
										 PutSuccessfulLoc))
							 (LINKS (NC.SetLinksLoc Card 
										 PutSuccessfulLoc))
							 (PROPLIST (NC.SetPropListLoc Card 
										 PutSuccessfulLoc))
							 (FROMLINKS (NCLocalDevice.PutFromLinks
									Card PutSuccessfulLoc))
							 (REGION NIL)
							 (SHOULDNT (CONCAT 
									  "Bad card part name:  "
									       CardPartName)))))
	       (SHOULDNT (CONCAT "Don't understand WhenFlg argument:  " WhenFlg)))))
)
(PUTPROPS RHTPATCH107 COPYRIGHT ("Xerox Corporation" 1986))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (544 2764 (NC.PutFromLinks 554 . 2762)) (2801 6846 (NCLocalDevice.PutCardPart 2811 . 
6844)))))
STOP