(FILECREATED "20-Nov-85 19:38:17" {QV}<NOTECARDS>1.3K>FGHPATCH001.;3 22349  

      changes to:  (VARS FGHPATCH001COMS)
		   (FNS NC.GetType NC.PutRegion NC.ReadCardType NC.ReadCardPartHeader 
			NC.WriteCardPartHeader)

      previous date: "20-Nov-85 18:04:31" {QV}<NOTECARDS>1.3K>FGHPATCH001.;1)


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

(PRETTYCOMPRINT FGHPATCH001COMS)

(RPAQQ FGHPATCH001COMS ((* * Redefined from NCDATABASE -- implements {1} length at beginning of 
			     each card part, {2} start and end pointers at begining of a cards 
			     substance are maintained by NoteCards and not by the card type's get and 
			     put fns, {3} common function for reading and writing the header at the 
			     beginning of each card part)
			  (FNS NC.GetNoteCard NC.GetLinks NC.GetTitle NC.GetPropList NC.GetType 
			       NC.PutNoteCard NC.PutLinks NC.PutTitle NC.PutPropList NC.PutRegion)
			  (* * New fns for NCDATABASE that help with the above)
			  (FNS NC.ReadCardPartHeader NC.WriteCardPartHeader)
			  (* * redefined from NCDATABASE to fix small bug)
			  (FNS NC.ReadCardType)))
(* * Redefined from NCDATABASE -- implements {1} length at beginning of each card part, {2} 
start and end pointers at begining of a cards substance are maintained by NoteCards and not by 
the card type's get and put fns, {3} common function for reading and writing the header at the 
beginning of each card part)

(DEFINEQ

(NC.GetNoteCard
  (LAMBDA (Card)                                             (* fgh: "20-Nov-85 17:48")

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


    (LET ((NoteFile (fetch (Card NoteFile) of Card)))
         (WITH.MONITOR (NC.FetchMonitor NoteFile)
		       (PROG ((Stream (fetch (NoteFile Stream) of NoteFile))
				ActualID CardType Substance Region CardUID VersionNumber StartPtr 
				EndPtr)
			       (AND (NEQ (fetch (Card Status) of Card)
					     (QUOTE ACTIVE))
				      (RETURN NIL))

          (* * Get Substance)


			       (SETFILEPTR Stream (fetch (Card MainLoc) of Card))

          (* * Read the header info)


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

          (* * read card type and region)


			       (SETQ CardType (NC.ReadCardType NoteFile))
			       (SETQ Region (NC.ReadRegion NoteFile))

          (* * Read the end and strat pts for substance, then call the substance get fn)


			       (SETQ StartPtr (NC.ReadPtr Stream 3))
			       (SETQ EndPtr (NC.ReadPtr Stream 3))
			       (SETQ Substance (APPLY* (NC.GetSubstanceFn CardType)
							   Card StartPtr EndPtr))

          (* * Setup ID with appropriate properties for retrieved card)


			       (NC.SetType Card CardType)
			       (NC.SetRegion Card Region)
			       (NC.SetSubstance Card Substance)

          (* * Get Links)


			       (NC.GetLinks Card)

          (* * GetTitle)


			       (NC.GetTitle Card)

          (* * Get Prop List)


			       (NC.GetPropList Card)

          (* * Activate Card and return)


			       (NC.ActivateCard Card)
			       (RETURN Card))))))

(NC.GetLinks
  (LAMBDA (Card)                                             (* fgh: "20-Nov-85 17:46")

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


    (LET ((NoteFile (fetch (Card NoteFile) of Card)))
         (WITH.MONITOR (NC.FetchMonitor NoteFile)
		       (PROG ((Stream (fetch (NoteFile Stream) of NoteFile))
				CardUID ActualID VersionNumber)
			       (AND (NEQ (fetch (Card Status) of Card)
					     (QUOTE ACTIVE))
				      (RETURN NIL))

          (* * set the fileptr to start of links data)


			       (SETFILEPTR Stream (fetch (Card LinksLoc) of Card))

          (* * Read the header and set the date)


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

          (* * Read the links)


			       (NC.SetToLinks Card (NC.ReadListOfLinks NoteFile))
			       (NC.SetFromLinks Card (NC.ReadListOfLinks NoteFile))
			       (NC.SetGlobalLinks Card (NC.ReadListOfLinks NoteFile))
			       (NC.SetLinksDirtyFlg Card NIL)
			       (RETURN Card))))))

(NC.GetTitle
  (LAMBDA (Card)                                             (* fgh: "20-Nov-85 17:51")
                                                             (* 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)


    (LET ((NoteFile (fetch (Card NoteFile) of Card)))
         (WITH.MONITOR (NC.FetchMonitor NoteFile)
		       (PROG ((Stream (fetch (NoteFile Stream) of NoteFile))
				ActualID Title CardUID VersionNumber)
			       (AND (NEQ (fetch (Card Status) of Card)
					     (QUOTE ACTIVE))
				      (RETURN NIL))

          (* * set the fileptr to the neginning of the data, read the card part header, the read the title)


			       (SETFILEPTR Stream (fetch (Card TitleLoc) of Card))
			       (NC.SetTitleDate Card (NC.ReadCardPartHeader Card 
									      NC.TitlesIdentifier))
			       (NC.SetTitle Card (SETQ Title (NC.ReadTitle NoteFile)))
			       (RETURN Title))))))

(NC.GetPropList
  (LAMBDA (Card)                                             (* fgh: "20-Nov-85 17:49")
                                                             (* 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)


    (LET ((NoteFile (fetch (Card NoteFile) of Card)))
         (WITH.MONITOR (NC.FetchMonitor NoteFile)
		       (PROG ((Stream (fetch (NoteFile Stream) of NoteFile))
				ActualID Props CardUID VersionNumber)
			       (AND (NEQ (fetch (Card Status) of Card)
					     (QUOTE ACTIVE))
				      (RETURN NIL))

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


			       (SETFILEPTR Stream (fetch (Card PropListLoc) of Card))
			       (NC.SetPropListDate Card (NC.ReadCardPartHeader Card 
									       NC.PropsIdentifier))
			       (NC.SetPropList Card (SETQ Props (NC.ReadPropList NoteFile)))
			       (RETURN Props))))))

(NC.GetType
  (LAMBDA (Card)                                             (* fgh: "20-Nov-85 19:35")
                                                             (* Retrieve the NoteCardType of card specified by 
							     NoteCardID 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/18/85; Now returns NIL if status not ACTIVE)



          (* * fkr 10/29/85: Fixed to use new numeric ID format. Also added NC.SetTitle call.)



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



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


    (LET ((NoteFile (fetch (Card NoteFile) of Card)))
         (WITH.MONITOR (NC.FetchMonitor NoteFile)
		       (PROG ((Stream (fetch (NoteFile Stream) of NoteFile))
				ActualID CardType CardUID VersionNumber)
			       (AND (NEQ (fetch (Card Status) of Card)
					     (QUOTE ACTIVE))
				      (RETURN NIL))
			       (SETFILEPTR Stream (fetch (Card MainLoc) of Card))
			       (NC.SetItemDate Card (NC.ReadCardPartHeader Card NC.ItemIdentifier)
						 )
			       (NC.SetType Card (SETQ CardType (NC.ReadCardType NoteFile)))
			       (RETURN CardType))))))

(NC.PutNoteCard
  (LAMBDA (Card UpdateUpdateListFlg UseOldDateFlg)           (* fgh: "20-Nov-85 17:52")

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


    (LET ((NoteFile (fetch (Card NoteFile) of Card)))
         (WITH.MONITOR (NC.FetchMonitor NoteFile)
		       (LET ((Stream (fetch (NoteFile Stream) of NoteFile))
			     DataLoc CardType StartSubstanceLoc)

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


			    (AND UpdateUpdateListFlg (NC.UpdateUpdateList Card))

          (* * First write out the card part header)


			    (SETFILEPTR Stream (SETQ DataLoc (GETEOFPTR Stream)))
			    (NC.WriteCardPartHeader Card NC.ItemIdentifier
						      (COND
							(UseOldDateFlg (NC.FetchItemDate Card))
							(T (NC.SetItemDate Card (DATE)))))

          (* * write out the type and region)


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

          (* * Write out the start and dummy end pointer for the actual substance)


			    (SETQ StartSubstanceLoc (GETFILEPTR Stream))
			    (NC.WritePtr Stream (PLUS StartSubstanceLoc 6)
					 3)
			    (NC.WritePtr Stream 0 3)

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


			    (APPLY* (NC.PutSubstanceFn CardType)
				      Card Stream)

          (* * Update the end pointer at beginning of substance)


			    (SETFILEPTR Stream (PLUS StartSubstanceLoc 3))
			    (NC.WritePtr Stream (GETEOFPTR Stream)
					 3)

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


			    (SETFILEPTR Stream DataLoc)
			    (NC.WritePtr Stream (DIFFERENCE (GETEOFPTR Stream)
							      DataLoc)
					 3)
			    (SETFILEPTR Stream -1)

          (* * 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))
			    (NC.SetMainLoc Card DataLoc)
			Card)))))

(NC.PutLinks
  (LAMBDA (Card UseOldDateFlg)                               (* fgh: "20-Nov-85 17:55")

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


    (LET ((NoteFile (fetch (Card NoteFile) of Card)))
         (WITH.MONITOR (NC.FetchMonitor NoteFile)
		       (LET ((Stream (fetch (NoteFile Stream) of NoteFile))
			     DataLoc)

          (* * Check to make sure this is an active note card.)


			    (AND (NEQ (fetch (Card Status) of Card)
					  (QUOTE ACTIVE))
				   (NC.ReportError "NC.PutLinks" (CONCAT (NC.FetchTitle Card)
									     
								   " is not an active note card.")))

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


			    (SETFILEPTR Stream (SETQ DataLoc (GETEOFPTR Stream)))
			    (NC.WriteCardPartHeader Card NC.LinksIdentifier
						      (COND
							(UseOldDateFlg (NC.FetchLinksDate Card))
							(T (NC.SetLinksDate Card (DATE)))))
			    (NC.WriteListOfLinks NoteFile (NC.FetchToLinks Card))
			    (NC.WriteListOfLinks NoteFile (NC.FetchFromLinks Card))
			    (NC.WriteListOfLinks NoteFile (NC.FetchGlobalLinks Card))

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


			    (SETFILEPTR Stream DataLoc)
			    (NC.WritePtr Stream (DIFFERENCE (GETEOFPTR Stream)
							      DataLoc)
					 3)
			    (SETFILEPTR Stream -1)

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


			    (NC.SetLinksLoc Card DataLoc)
			    (NC.SetLinksDirtyFlg Card)
			Card)))))

(NC.PutTitle
  (LAMBDA (Card UseOldDateFlg)                               (* fgh: "20-Nov-85 17:59")

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


    (LET ((NoteFile (fetch (Card NoteFile) of Card)))
         (WITH.MONITOR (NC.FetchMonitor NoteFile)
		       (LET ((Stream (fetch (NoteFile Stream) of NoteFile))
			     DataLoc)

          (* * Check to make sure this is an active note card.)


			    (AND (NEQ (fetch (Card Status) of Card)
					  (QUOTE ACTIVE))
				   (NC.ReportError "NC.PutTitle" (CONCAT (NC.FetchTitle Card)
									     
								   " is not an active note card.")))

          (* * First write out the title.)


			    (SETFILEPTR Stream (SETQ DataLoc (GETEOFPTR Stream)))
			    (NC.WriteCardPartHeader Card NC.TitlesIdentifier
						      (COND
							(UseOldDateFlg (NC.FetchTitleDate Card))
							(T (NC.SetTitleDate Card (DATE)))))
			    (NC.WriteTitle NoteFile (NC.FetchTitle Card))

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


			    (SETFILEPTR Stream DataLoc)
			    (NC.WritePtr Stream (DIFFERENCE (GETEOFPTR Stream)
							      DataLoc)
					 3)
			    (SETFILEPTR Stream -1)

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


			    (NC.SetTitleLoc Card DataLoc)
			    (NC.SetTitleDirtyFlg Card)
			Card)))))

(NC.PutPropList
  (LAMBDA (Card UseOldDateFlg)                               (* fgh: "20-Nov-85 17:58")

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


    (LET ((NoteFile (fetch (Card NoteFile) of Card)))
         (WITH.MONITOR (NC.FetchMonitor NoteFile)
		       (LET ((Stream (fetch (NoteFile Stream) of NoteFile))
			     DataLoc)

          (* * Check to make sure this is an active note card.)


			    (AND (NEQ (fetch (Card Status) of Card)
					  (QUOTE ACTIVE))
				   (NC.ReportError "NC.PutLinks" (CONCAT (NC.FetchTitle Card)
									     
								   " is not an active note card.")))

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


			    (SETFILEPTR Stream (SETQ DataLoc (GETEOFPTR Stream)))
			    (NC.WriteCardPartHeader Card NC.PropsIdentifier
						      (COND
							(UseOldDateFlg (NC.FetchPropListDate Card))
							(T (NC.SetPropListDate Card (DATE)))))
			    (NC.WritePropList NoteFile (NC.FetchPropList Card))

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


			    (SETFILEPTR Stream DataLoc)
			    (NC.WritePtr Stream (DIFFERENCE (GETEOFPTR Stream)
							      DataLoc)
					 3)
			    (SETFILEPTR Stream -1)

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


			    (NC.SetPropListLoc Card DataLoc)
			    (NC.SetPropListDirtyFlg Card)
			Card)))))

(NC.PutRegion
  (LAMBDA (Card)                                             (* fgh: "20-Nov-85 19:37")

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



          (* * rht 11/12/85: Updated to handle new Notefile and cardID format.)



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


    (LET ((NoteFile (fetch (Card NoteFile) of Card)))
         (WITH.MONITOR (NC.FetchMonitor NoteFile)
		       (LET ((Stream (fetch (NoteFile Stream) of NoteFile))
			     CardUID ActualID VersionNumber)

          (* * Check to make sure this is an active note card.)


			    (AND (NEQ (fetch (Card Status) of Card)
					  (QUOTE ACTIVE))
				   (NC.ReportError "NC.PutNoteCard" (CONCAT (NC.FetchTitle
										  Card)
										
								   " is not an active note card.")))
			    (SETFILEPTR Stream (fetch (Card MainLoc) of Card))
			    (NC.ReadCardPartHeader Card NC.ItemIdentifier)
			    (NC.ReadCardType NoteFile)
			    (NC.WriteRegion Card)
			Card)))))
)
(* * New fns for NCDATABASE that help with the above)

(DEFINEQ

(NC.ReadCardPartHeader
  (LAMBDA (Card Identifier)                                  (* fgh: "20-Nov-85 17:41")

          (* * Read the header for a card part and return the date from the header)


    (LET ((Stream (fetch (NoteFile Stream) of (fetch (Card NoteFile) of Card)))
	  VersionNumber Date ActualID CardUID)

          (* * Skip the length info)


         (NC.ReadPtr Stream 3)

          (* * Read the identifier and the version)


         (COND
	   ((NOT (SETQ VersionNumber (NC.ReadIdentifier NoteFile Identifier)))
	     (NC.ReportError "NC.ReadCardPartHeader" (CONCAT (NC.FetchTitle Card)
								 " Error while reading NoteFile" 
								 " -- incorrect identifier."))))
         (COND
	   ((GEQ VersionNumber 1)
	     (SETQ Date (NC.ReadDate NoteFile))))
         (SETQ ActualID (NC.ReadUID NoteFile))
         (COND
	   ((NOT (NC.SameUIDP ActualID (SETQ CardUID (fetch (Card UID) of Card))))
	     (NC.ReportError "NC.ReadCardPartHeader" (CONCAT 
						 "ID mismatch while reading item.  Expected ID: "
								 CardUID "   Found ID: " ActualID))))
     Date)))

(NC.WriteCardPartHeader
  (LAMBDA (Card Identifier Date)                             (* fgh: "20-Nov-85 17:32")

          (* * write the header of a card part onto the NoteFile)


    (LET ((NoteFile (fetch (Card NoteFile) of Card))
	  Stream)

          (* * leave space for the length information)


         (SETQ Stream (fetch (NoteFile Stream) of NoteFile))
         (NC.WritePtr Stream 0 3)

          (* * write the card part identifier)


         (NC.WriteIdentifier NoteFile Identifier)

          (* * write the date)


         (NC.WriteDate NoteFile Date)

          (* * write the cards uid)


         (NC.WriteUID NoteFile (fetch (Card UID) of Card)))))
)
(* * redefined from NCDATABASE to fix small bug)

(DEFINEQ

(NC.ReadCardType
  (LAMBDA (NoteFileOrStream)                                 (* fgh: "20-Nov-85 19:31")

          (* * Get a card type off of the file.)


    (LET ((Stream (OR (STREAMP NoteFileOrStream)
			(fetch (NoteFile Stream) of NoteFileOrStream))))
         (PROG1 (READ (fetch (NoteFile Stream) of NoteFile))

          (* * read past CR)


		  (BIN Stream)))))
)
(PUTPROPS FGHPATCH001 COPYRIGHT ("Xerox Corporation" 1985))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (1455 19762 (NC.GetNoteCard 1465 . 3846) (NC.GetLinks 3848 . 5333) (NC.GetTitle 5335 . 
6866) (NC.GetPropList 6868 . 8268) (NC.GetType 8270 . 9747) (NC.PutNoteCard 9749 . 12350) (NC.PutLinks
 12352 . 14581) (NC.PutTitle 14583 . 16554) (NC.PutPropList 16556 . 18652) (NC.PutRegion 18654 . 19760
)) (19823 21776 (NC.ReadCardPartHeader 19833 . 21034) (NC.WriteCardPartHeader 21036 . 21774)) (21832 
22267 (NC.ReadCardType 21842 . 22265)))))
STOP