(FILECREATED " 4-Nov-86 12:09:07" {QV}<NOTECARDS>1.3K>NEXT>PMIPATCH001.;1 24048  

      changes to:  (VARS PMIPATCH001COMS)
		   (FNS NC.GetMainCardData NC.GetLinks NC.GetTitle NC.GetPropList NC.PutMainCardData 
			NC.PutLinks NC.PutTitle NC.PutPropList))


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

(PRETTYCOMPRINT PMIPATCH001COMS)

(RPAQQ PMIPATCH001COMS ((* * These changes fix problems with copying cards caused by earlier
			     (RHT 1/86)
			     changes being lost)
			  (* * Changes to NCDATABASE)
			  (FNS NC.GetMainCardData NC.GetLinks NC.GetTitle NC.GetPropList 
			       NC.PutMainCardData NC.PutLinks NC.PutTitle NC.PutPropList)))
(* * These changes fix problems with copying cards caused by earlier (RHT 1/86) changes being 
lost)

(* * Changes to NCDATABASE)

(DEFINEQ

(NC.GetMainCardData
  (LAMBDA (Card OverrideStream)                              (* pmi: " 4-Nov-86 11:51")

          (* Get a note card from the database. If IncludeDeletedCardsFlg is NIL, then return immediately if card is deleted 
	  or free. Otherwise, get dekleted but not free cards.)



          (* * rht 1/31/85: Now reads pointers from index array rather than file.)



          (* * rht 7/9/85: Now gets date if notefile has newer data format.)



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



          (* * fgh 11/20/85 Added call to NC.ReadCardPartHeader and put in code to read Start and End pointers before calling
	  card type's getfn.)



          (* * kirk 27Nov85 abstracted this function out of NC.GetNoteCard)



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



          (* * rht 1/28/86: Now passes extra arg to NC.ReadCardPartHeader indicating that when we're overriding the notefile 
	  stream, you shouldn't force UIDs on stream and in card to match.)



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



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



          (* * kirk 14Feb86 Merged the above 4 changes)



          (* * kef 7/16/86: Uses the device vector GetCardPartFn to set up the stream and stream pointer for reading.)



          (* * kef 8/1/86: Moved the check for ACTIVE status to beginning.)



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



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


    (DECLARE (GLOBALVARS NC.ItemIdentifier))
    (if (EQ (fetch (Card Status) of Card)
		(QUOTE ACTIVE))
	then (WITH.MONITOR (NC.FetchMonitor (fetch (Card NoteFile) of Card))
			     (NC.DoCardPartFn Get Card (QUOTE SUBSTANCE)
					      (LET ((Stream (OR (STREAMP OverrideStream)
								  (NC.CoerceToNoteFileStream Card)))
						    Length SubstanceVersion)

          (* * Read the header info)


					           (NC.SetItemDate Card (NC.ReadCardPartHeader
								       Card NC.ItemIdentifier Stream 
								       OverrideStream))

          (* * read card type and region)


					           (NC.SetType Card (NC.ReadCardType Stream))
					           (NC.SetRegion Card (NC.ReadRegion Stream))

          (* * Read the length of substance, then call the substance get fn)


					           (SETQ Length (NC.ReadPtr Stream 3))
					           (SETQ SubstanceVersion (NC.GetPtr Stream 1))
					           (NC.SetSubstance Card
								      (NC.ApplyFn GetFn Card Length 
										  Stream 
										 SubstanceVersion))
					       Card))))))

(NC.GetLinks
  (LAMBDA (Card OverrideStream)                              (* pmi: " 4-Nov-86 11:50")

          (* * rht 1/31/85: Now reads pointers from index array.)



          (* * rht 2/9/85: Now fixes display formats on links read in.)



          (* * rht 7/9/85: Now gets date if notefile has newer data format.)



          (* * fkr 11/8/85 Updated to handle new Card scheme and NoteFile objects.)



          (* * fgh 11/20/85 Added call to NC.ReadCardPartHeader)



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



          (* * rht 1/28/86: Now passes extra arg to NC.ReadCardPartHeader indicating that when we're overriding the notefile 
	  stream, you shouldn't force UIDs on stream and in card to match.)



          (* * kef 7/16/86: Uses the device vector GetCardPartFn to set up the stream and stream pointer for reading.)



          (* * kef 8/1/86: Moved the check for ACTIVE status to beginning.)



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



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


    (DECLARE (GLOBALVARS NC.LinksIdentifier))
    (COND
      ((EQ (fetch (Card Status) of Card)
	     (QUOTE ACTIVE))
	(WITH.MONITOR (NC.FetchMonitor (fetch (Card NoteFile) of Card))
		      (NC.DoCardPartFn Get Card (QUOTE LINKS)
				       (LET ((Stream (OR (STREAMP OverrideStream)
							   (NC.CoerceToNoteFileStream Card))))

          (* * Read the header and set the date)


					    (NC.SetLinksDate Card (NC.ReadCardPartHeader Card 
									       NC.LinksIdentifier 
											   Stream 
										   OverrideStream))

          (* * Read the links)


					    (NC.SetToLinks Card (NC.ReadListOfLinks Stream))
					    (NC.SetFromLinks Card (NC.ReadListOfLinks Stream))
					    (NC.SetGlobalLinks Card (NC.ReadListOfLinks Stream))
					    (NC.SetLinksDirtyFlg Card NIL)
					Card)))))))

(NC.GetTitle
  (LAMBDA (Card OverrideStream)                              (* pmi: " 4-Nov-86 11:50")
                                                             (* Retrieve title for card specified by Card from the 
							     database specified by DatabaseStream)

          (* * rht 1/31/85: Now reads pointers from index array rather than file.)



          (* * rht 7/9/85: Now gets date if notefile has newer data format.)



          (* * kirk 10/28/85 Now returns NIL if Status not ACTIVE)



          (* * fkr 10/29/85: Fixed to use new numeric ID format.)



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



          (* * fgh 11/20/85 Added call to NC.ReadCardPartHeader)



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



          (* * rht 1/28/86: Now passes extra arg to NC.ReadCardPartHeader indicating that when we're overriding the notefile 
	  stream, you shouldn't force UIDs on stream and in card to match.)



          (* * kef 7/16/86: Uses the device vector GetCardPartFn to set the stream and stream pointer in preparation for the 
	  read.)



          (* * kef 7/24/86: Added check of NewCardFlg.)



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



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


    (DECLARE (GLOBALVARS NC.TitlesIdentifier))
    (COND
      ((fetch (Card NewCardFlg) of Card)
	NIL)
      ((EQ (fetch (Card Status) of Card)
	     (QUOTE ACTIVE))
	(WITH.MONITOR (NC.FetchMonitor (fetch (Card NoteFile) of Card))
		      (NC.DoCardPartFn Get Card (QUOTE TITLE)

          (* * Now we've actually executed the BEFORE part of the GETFN, while in a RESETLST that will ensure execution of 
	  the AFTER part upon exit. This means that right now the Stream slot of the NoteFile is a random access stream with 
	  the file pointer set to the beginning of the card part.)


				       (LET ((Stream (OR (STREAMP OverrideStream)
							   (NC.CoerceToNoteFileStream Card)))
					     Title)
					    (NC.SetTitleDate Card (NC.ReadCardPartHeader Card 
									      NC.TitlesIdentifier 
											   Stream 
										   OverrideStream))
					    (NC.SetTitle Card (SETQ Title (NC.ReadTitle Stream))
							   )
					Title)))))))

(NC.GetPropList
  (LAMBDA (Card OverrideStream)                              (* pmi: " 4-Nov-86 11:50")
                                                             (* Retrieve the prop list for card specified by ID 
							     from the database specified by DatabaseStream)

          (* * rht 1/31/85: Now reads pointers from index array rather than file.)



          (* * rht 7/9/85: Now gets date if notefile has newer data format.)



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



          (* * fgh 11/20/85 Added call to NC.ReadCardPartHeader)



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



          (* * rht 1/28/86: Now passes extra arg to NC.ReadCardPartHeader indicating that when we're overriding the notefile 
	  stream, you shouldn't force UIDs on stream and in card to match.)



          (* * kef 7/16/86: Uses the device vector GetCardPartFn to set up the stream and stream pointer for reading.)



          (* * kef 8/1/86: Moved the check for ACTIVE status to beginning.)



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



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


    (DECLARE (GLOBALVARS NC.PropsIdentifier))
    (if (EQ (fetch (Card Status) of Card)
		(QUOTE ACTIVE))
	then (WITH.MONITOR (NC.FetchMonitor (fetch (Card NoteFile) of Card))
			     (NC.DoCardPartFn Get Card (QUOTE PROPLIST)
					      (LET ((Stream (OR (STREAMP OverrideStream)
								  (NC.CoerceToNoteFileStream Card)))
						    Props)

          (* * set the fileptr to the beginning of the data, read the header, then read the prop list)


					           (NC.SetPropListDate Card
									 (NC.ReadCardPartHeader
									   Card NC.PropsIdentifier 
									   Stream OverrideStream))
					           (NC.SetPropList Card (SETQ Props (
									 NC.ReadPropList Stream)))
					       Props))))))

(NC.PutMainCardData
  (LAMBDA (Card UpdateUpdateListFlg UseOldDateFlg OverrideStream)
                                                             (* pmi: " 4-Nov-86 11:51")

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


    (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))
					     (SETQ PutSuccessfulLoc StartDataLoc)
					 Card))))))

(NC.PutLinks
  (LAMBDA (Card UseOldDateFlg OverrideStream)                (* pmi: " 4-Nov-86 11:52")

          (* * Put the link data for ID onto the database file.)



          (* * rht 1/30/85: Changed to use index array instead of file.)



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



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



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



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



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

                                                             (* Check to make sure this is an active note card.)
    (DECLARE (GLOBALVARS NC.LinksIdentifier))
    (AND (NEQ (fetch (Card Status) of Card)
		  (QUOTE ACTIVE))
	   (NC.ReportError "NC.PutLinks" (CONCAT (NC.FetchTitle Card)
						     " is not an active note card.")))
    (LET (PutSuccessfulLoc)
         (WITH.MONITOR (NC.FetchMonitor (fetch (Card NoteFile) of Card))
		       (NC.DoCardPartFn Put Card (QUOTE LINKS)
					(LET ((Stream (OR (STREAMP OverrideStream)
							    (NC.CoerceToNoteFileStream Card)))
					      StartLoc EndLoc)

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


					     (SETQ StartLoc (GETFILEPTR Stream))
					     (NC.WriteCardPartHeader Card NC.LinksIdentifier
								       (COND
									 (UseOldDateFlg (
										NC.FetchLinksDate
											  Card))
									 (T (NC.SetLinksDate
									      Card
									      (DATE))))
								       Stream)
					     (NC.WriteListOfLinks Stream (NC.FetchToLinks Card))
					     (NC.WriteListOfLinks Stream (NC.FetchFromLinks
								      Card))
					     (NC.WriteListOfLinks Stream (NC.FetchGlobalLinks
								      Card))

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


					     (SETQ EndLoc (GETFILEPTR Stream))
					     (SETFILEPTR Stream StartLoc)
					     (NC.WritePtr Stream (DIFFERENCE EndLoc StartLoc)
							  3)
					     (SETFILEPTR Stream EndLoc)

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

(NC.PutTitle
  (LAMBDA (Card UseOldDateFlg OverrideStream)                (* pmi: " 4-Nov-86 11:53")

          (* * Put the title of card ID onto DatabaseStream)



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



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



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



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



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

                                                             (* Check to make sure this is an active note card.)
    (DECLARE (GLOBALVARS NC.TitlesIdentifier))
    (AND (NEQ (fetch (Card Status) of Card)
		  (QUOTE ACTIVE))
	   (NC.ReportError "NC.PutTitle" (CONCAT (NC.FetchTitle Card)
						     " is not an active note card.")))
    (LET (PutSuccessfulLoc)
         (WITH.MONITOR (NC.FetchMonitor (fetch (Card NoteFile) of Card))
		       (NC.DoCardPartFn Put Card (QUOTE TITLE)
					(LET ((Stream (OR (STREAMP OverrideStream)
							    (NC.CoerceToNoteFileStream Card)))
					      StartLoc EndLoc)

          (* * First write out the title.)


					     (SETQ StartLoc (GETFILEPTR Stream))
					     (NC.WriteCardPartHeader Card NC.TitlesIdentifier
								       (COND
									 (UseOldDateFlg (
										NC.FetchTitleDate
											  Card))
									 (T (NC.SetTitleDate
									      Card
									      (DATE))))
								       Stream)
					     (NC.WriteTitle Stream (NC.FetchTitle Card))

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


					     (SETQ EndLoc (GETFILEPTR Stream))
					     (SETFILEPTR Stream StartLoc)
					     (NC.WritePtr Stream (DIFFERENCE EndLoc StartLoc)
							  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.)


					     (NC.SetTitleDirtyFlg 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))))))

(NC.PutPropList
  (LAMBDA (Card UseOldDateFlg OverrideStream)                (* pmi: " 4-Nov-86 11:53")

          (* * Put the prop list for ID onto the database file.)



          (* * rht 1/30/85: Changed to use index array instead of file.)



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



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



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



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



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

                                                             (* Check to make sure this is an active note card.)
    (DECLARE (GLOBALVARS NC.PropsIdentifier))
    (AND (NEQ (fetch (Card Status) of Card)
		  (QUOTE ACTIVE))
	   (NC.ReportError "NC.PutPropList" (CONCAT (NC.FetchTitle Card)
							" is not an active note card.")))
    (LET (PutSuccessfulLoc)
         (WITH.MONITOR (NC.FetchMonitor (fetch (Card NoteFile) of Card))
		       (NC.DoCardPartFn Put Card (QUOTE PROPLIST)
					(LET ((Stream (OR (STREAMP OverrideStream)
							    (NC.CoerceToNoteFileStream Card)))
					      StartLoc EndLoc)

          (* * Write the proplist at the end of the database file.)


					     (SETQ StartLoc (GETFILEPTR Stream))
					     (NC.WriteCardPartHeader Card NC.PropsIdentifier
								       (COND
									 (UseOldDateFlg (
									     NC.FetchPropListDate
											  Card))
									 (T (NC.SetPropListDate
									      Card
									      (DATE))))
								       Stream)
					     (NC.WritePropList Stream (NC.FetchPropList Card))

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


					     (SETQ EndLoc (GETFILEPTR Stream))
					     (SETFILEPTR Stream StartLoc)
					     (NC.WritePtr Stream (DIFFERENCE EndLoc StartLoc)
							  3)
					     (SETFILEPTR Stream EndLoc)

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


					     (NC.SetPropListDirtyFlg 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))))))
)
(PUTPROPS PMIPATCH001 COPYRIGHT ("Xerox Corporation" 1986))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (824 23966 (NC.GetMainCardData 834 . 3744) (NC.GetLinks 3746 . 5874) (NC.GetTitle 5876
 . 8400) (NC.GetPropList 8402 . 10544) (NC.PutMainCardData 10546 . 14858) (NC.PutLinks 14860 . 18043) 
(NC.PutTitle 18045 . 20940) (NC.PutPropList 20942 . 23964)))))
STOP