(FILECREATED "10-Jun-87 17:40:48" {QV}<NOTECARDS>1.3K>NEXT>RGPATCH048.;1 5661   

      changes to:  (VARS RGPATCH048COMS)
		   (FNS NC.PutMainCardData))


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

(PRETTYCOMPRINT RGPATCH048COMS)

(RPAQQ RGPATCH048COMS ((* * rg 6/10/87 NC.PutMainCardData now adds a links cache if card didn't 
			    already have one)
			 (* * changes to NCDATABASE)
			 (FNS NC.PutMainCardData)))
(* * rg 6/10/87 NC.PutMainCardData now adds a links cache if card didn't already have one)

(* * changes to NCDATABASE)

(DEFINEQ

(NC.PutMainCardData
  [LAMBDA (Card UpdateUpdateListFlg UseOldDateFlg OverrideStream)
                                                             (* Randy.Gobbel "10-Jun-87 17:34")

          (* * Write note card specified by ID to the database specified by Database stream)



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



          (* * rht 11/10/85: Updated to handle NoteFile and Card scheme.)



          (* * fgh 11/20/85 Added call to NC.WriteCardPartHeader and the mechanism to write the start and end pointers of the
	  substance before calling the card type's putfn.)



          (* * kirk 29Nov85 Renamed from NC.PutNoteCard)



          (* * rht 1/23/86: Now takes optional OverrideStream arg. This, if given, overrides stream of card's notefile.)



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



          (* * fgh 2/6/86 Added support for version numbers on the substance put fn.)



          (* * kirk 14Feb86 Merged above two changes)



          (* * rht 2/14/86: Fixed so call to NC.WriteCardType takes Stream as arg.)



          (* * rht 2/17/86: Fixed so calls to NC.WriteCardPartHeader and to NC.WriteRegion take Stream arg.)



          (* * kef 7/16/86: Makes use of the NoteFile device vector PutCardPartFn.)



          (* * kef 8/1/86: Added notification of status change.)



          (* * fgh 8/31/86 Adapted to use NC.DoCardPartFn.)



          (* * pmi 11/4/86 Reinstated Randy's change (1/23/86) which somehow got lost.)



          (* * rht 11/14/86: Now makes sure hung var PutSuccessfulLoc is NIL if we were passed an OverrideStream.)



          (* * rg 6/10/87 adds links cache if none already exists)


    (DECLARE (GLOBALVARS NC.ItemIdentifier))
    (LET (PutSuccessfulLoc)
         (WITH.MONITOR (NC.FetchMonitor (fetch (Card NoteFile) of Card))
		       (NC.DoCardPartFn Put Card (QUOTE SUBSTANCE)
					(LET ((Stream (OR (STREAMP OverrideStream)
							    (NC.CoerceToNoteFileStream Card)))
					      StartDataLoc EndLoc CardType StartSubstanceLoc 
					      SubstanceVersion)

          (* * Record update date on update list if necessary.)


					     (AND UpdateUpdateListFlg (NC.UpdateUpdateList Card))

          (* * First write out the card part header)


					     (SETQ StartDataLoc (GETFILEPTR Stream))
					     (NC.WriteCardPartHeader Card NC.ItemIdentifier
								       [COND
									 (UseOldDateFlg (
										 NC.FetchItemDate
											  Card))
									 (T (NC.SetItemDate
									      Card
									      (DATE]
								       Stream)

          (* * write out the type and region)


					     (NC.WriteCardType Stream (SETQ CardType
								   (NC.RetrieveType Card)))
					     (NC.WriteRegion Card Stream)

          (* * Write out the dummy length pointer for and version byte the actual substance)


					     (SETQ StartSubstanceLoc (GETFILEPTR Stream))
					     (NC.WritePtr Stream 0 4)

          (* * Write out the substance of the card.)


					     (SETQ SubstanceVersion (NC.ApplyFn PutFn Card Stream))

          (* * Update the length pointer at beginning of substance Subtract four so that length is the length of the actual 
	  substance and doesn't include the length pointer and version byte maintained here. Also updated the version number 
	  returned by the put fn.)


					     (SETQ EndLoc (GETFILEPTR Stream))
					     (SETFILEPTR Stream StartSubstanceLoc)
					     (NC.WritePtr Stream (DIFFERENCE (DIFFERENCE EndLoc 
										StartSubstanceLoc)
									       4)
							  3)
					     (SETQ SubstanceVersion (OR SubstanceVersion 0))
					     (NC.WritePtr Stream SubstanceVersion 1)

          (* * Update the length field at the beginning of the card info)


					     (SETFILEPTR Stream StartDataLoc)
					     (NC.WritePtr Stream (DIFFERENCE EndLoc StartDataLoc)
							  3)
					     (SETFILEPTR Stream EndLoc)

          (* * Now update the Index to reflect the new data just written. Done last in case the substance putting bombed for 
	  some reason.)


					     (replace (Card Status) of Card with (QUOTE
											 ACTIVE))
                                                             (* cause links cache to be created if not already in 
							     existence)
					     (OR (fetch (Card Links) of Card)
						   (replace (Card FromLinks) of Card
						      with NIL))

          (* * Don't put a reasonable value in the hung variable PutSuccessfulLoc if we were passed OverrideStream.)


					     (SETQ PutSuccessfulLoc
					       (if OverrideStream
						   then NIL
						 else StartDataLoc))
					 Card])
)
(PUTPROPS RGPATCH048 COPYRIGHT ("Xerox Corporation" 1987))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (582 5580 (NC.PutMainCardData 592 . 5578)))))
STOP