(FILECREATED "21-Nov-85 23:43:22" {QV}<NOTECARDS>1.3K>FGHPATCH005.;4 17860  

      changes to:  (FNS NC.GetNoteCard NC.MakeCardTypesList NC.PutNoteCard NC.GetTextSubstance 
			NC.PutTextSubstance NC.TextCopySubstance NC.GetSketchSubstance 
			NC.SketchCopySubstance NC.GetGraphSubstance NC.GraphCopySubstance 
			NC.ListCardGetFn NC.ListCardCopyFn)
		   (VARS FGHPATCH005COMS)

      previous date: "21-Nov-85 21:13:00" {QV}<NOTECARDS>1.3K>FGHPATCH005.;1)


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

(PRETTYCOMPRINT FGHPATCH005COMS)

(RPAQQ FGHPATCH005COMS ((* * Redefined from NCDATABASE -- implements substance length instead of 
			     start and end pointers at the beginning of the storage for a card's 
			     substance)
			  (FNS NC.GetNoteCard NC.PutNoteCard)
			  (* * Redefined from NCTEXTCARD to implement the fact that NoteCards now 
			     handles the start and end pointers at the beginning of each substance's 
			     storage on the disk)
			  (FNS NC.GetTextSubstance NC.TextCopySubstance NC.PutTextSubstance)
			  (* * Redefined from NCSKETCHCARD to implement the fact that NoteCards now 
			     handles the start and end pointers at the beginning of each substance's 
			     storage on the disk)
			  (FNS NC.GetSketchSubstance NC.SketchCopySubstance)
			  (* * Redefined from NCGRAPHCARD to implement the fact that NoteCards now 
			     handles the start and end pointers at the beginning of each substance's 
			     storage on the disk)
			  (FNS NC.GetGraphSubstance NC.GraphCopySubstance)
			  (* * Redefined from NCLISTCARD to implement the fact that NoteCards now 
			     handles the start and end pointers at the beginning of each substance's 
			     storage on the disk)
			  (FNS NC.ListCardGetFn NC.ListCardCopyFn)
			  (* * redefined fron NCTYPESMECH to make default copyfn be copybytes)
			  (FNS NC.MakeCardTypesList)))
(* * Redefined from NCDATABASE -- implements substance length instead of start and end 
pointers at the beginning of the storage for a card's substance)

(DEFINEQ

(NC.GetNoteCard
  (LAMBDA (Card)                                             (* fgh: "21-Nov-85 23:29")

          (* 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))
				CardType Substance Region Length CourierStream NSAddress)
			       (COND
				 ((type? NSADDRESS Stream)
				   (SETQ NSAddress Stream)
				   (replace (NoteFile Stream) of NoteFile
				      with (SETQ Stream (COURIER.CALL
						 (SETQ CourierStream (COURIER.OPEN Stream))
						 (QUOTE NoteCards)
						 (QUOTE GetCardPart)
						 (NC.ConvertUIDToCourier (fetch (NoteFile UID)
									      of NoteFile))
						 (NC.ConvertUIDToCourier (fetch (Card UID)
									      of Card))
						 0 NIL)))))
			       (AND (NEQ (fetch (Card Status) of Card)
					     (QUOTE ACTIVE))
				      (RETURN NIL))

          (* * Get Substance)


			       (AND (NULL CourierStream)
				      (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 length of substance, then call the substance get fn)


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

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


			       (NC.SetType Card CardType)
			       (NC.SetRegion Card Region)
			       (NC.SetSubstance Card Substance)
			       (AND CourierStream (CLOSEF Stream)
				      (CLOSEF CourierStream)
				      (replace (NoteFile Stream) of NoteFile with NSAddress))

          (* * 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.PutNoteCard
  (LAMBDA (Card UpdateUpdateListFlg UseOldDateFlg)           (* fgh: "21-Nov-85 21:58")

          (* * 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 dummy length pointer for the actual substance)


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

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


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

          (* * Update the length pointer at beginning of substance Subtract three so that length is the length of the actual 
	  substance and doesn't include the length pointer maintained here. NIL)


			    (SETFILEPTR Stream StartSubstanceLoc)
			    (NC.WritePtr Stream (DIFFERENCE (DIFFERENCE (GETEOFPTR Stream)
									    StartSubstanceLoc)
							      3)
					 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)))))
)
(* * Redefined from NCTEXTCARD to implement the fact that NoteCards now handles the start and 
end pointers at the beginning of each substance's storage on the disk)

(DEFINEQ

(NC.GetTextSubstance
  (LAMBDA (Card Length)                                      (* fgh: "21-Nov-85 21:47")
                                                             (* Get a text stream from the database file)

          (* * fgh 11/13/85 Updated to handle Card objects.)



          (* * fgh 11/20/85 NoteCards now passes down start and end pointer as args.)



          (* * fgh 11/21/85 Now passed Length instead of start and end ptrs.)


    (LET ((TempStream (OPENSTREAM (QUOTE {NODIRCORE})
				    (QUOTE BOTH)
				    (QUOTE NEW)))
	  (Stream (fetch (NoteFile Stream) of (fetch (Card NoteFile) of Card)))
	  StartFormatPtr TempFileEof TextStream StartPtr OriginalLocation)

          (* * Find out the original location of the start of the text stream on the NoteFile for surgery on file absolute 
	  pointers.)


         (SETQ OriginalLocation (NC.ReadPtr Stream 4))

          (* * Copy text stream to a NODIRCORE file from the current location. Number of bytes copied should be Length minus 
	  the 4 bytes already read for OriginalLocation)


         (COPYBYTES Stream TempStream (SETQ StartPtr (GETFILEPTR Stream))
		      (PLUS StartPtr (DIFFERENCE Length 4)))

          (* * fix up file absolute pinter to the beginning of the formatting nformation)


         (COND
	   ((IGREATERP (SETQ TempFileEof (GETEOFPTR TempStream))
			 2)
	     (SETFILEPTR TempStream (IDIFFERENCE TempFileEof 2))
	     (COND
	       ((EQUAL (IQUOTIENT (\WIN TempStream)
				      100)
			 NC.TEditPasswordDividedBy100)
		 (SETFILEPTR TempStream (IDIFFERENCE TempFileEof 8))
		 (SETQ StartFormatPtr (\DWIN TempStream))
		 (SETFILEPTR TempStream (IDIFFERENCE TempFileEof 8))
		 (\DWOUT TempStream (DIFFERENCE StartFormatPtr OriginalLocation))))))

          (* * return an open textstream on the temp file)


         (SETQ TextStream (OPENTEXTSTREAM TempStream NIL NIL NIL (NC.MakeTEditPropsList)))
         (STREAMPROP TextStream (QUOTE NoteCardObject)
		       Card)
     TextStream)))

(NC.TextCopySubstance
  (LAMBDA (Card FromStream ToStream Length)                  (* fgh: "21-Nov-85 21:26")

          (* * Copy a text substance from FromStream to ToStream.)



          (* * fgh 11/20/85 NoteCards now passes the Start and End pointers of the FromStream as args and properly sets the 
	  pointers on the ToStream)



          (* * fgh 11/21/85 Now passed Length instead of start and end ptrs.)


    (LET* ((FromStartPtr (GETFILEPTR FromStream))
	   (FromEndPtr (PLUS Length FromStartPtr)))
          (COPYBYTES FromStream ToStream FromStartPtr FromEndPtr))
    T))

(NC.PutTextSubstance
  (LAMBDA (Card)                                             (* fgh: "21-Nov-85 21:50")
                                                             (* Put text substance from card ID on the database 
							     file)

          (* * rht 9/13/85: Now doesn't try to write piece table at all if substance has zero length.)



          (* * fgh 11/13/85 Updated to handle NoteFile, Card objects.)



          (* * fgh 11/20/85 removed code to handle start and end pointers)


    (LET ((Substance (NC.FetchSubstance Card))
	  (Stream (fetch (NoteFile Stream) of (fetch (Card NoteFile) of Card)))
	  StartPtr)

          (* * First write down the file location of the beginnning of the text stream so it can be used to fix up TEDits 
	  file absolute pointers when we read it back up.)


         (SETQ StartPtr (PLUS 4 (GETFILEPTR Stream)))
         (NC.WritePtr Stream StartPtr 4)

          (* * The write down the text stream)


         (COND
	   ((NOT (ZEROP (fetch (TEXTOBJ TEXTLEN) of (TEXTOBJ Substance))))
	     (TEDIT.PUT.PCTB (TEXTOBJ Substance)
			       Stream))))))
)
(* * Redefined from NCSKETCHCARD to implement the fact that NoteCards now handles the start 
and end pointers at the beginning of each substance's storage on the disk)

(DEFINEQ

(NC.GetSketchSubstance
  (LAMBDA (Card Length)                                      (* fgh: "21-Nov-85 21:09")

          (* Get sketch substance from Database stream. Database stream is positioned. READ the global sketch description, 
	  the locasl sketch scale and region viewed. Also read in any cached bit maps for the MAPS system.)



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



          (* * fgh 11/20/85 NoteCards now passes start and enptrs down.)



          (* * fgh 11/21/85 Now passed Length instead of start and end ptrs.)


    (LET ((Stream (fetch (NoteFile Stream) of (fetch (Card NoteFile) of Card)))
	  Sketch Scale RegionViewed)

          (* * Get the substance)


         (SETQ Sketch (HREAD Stream))
         (SETQ Scale (READ Stream))
         (SETQ RegionViewed (READ Stream))
         (while (EQ (READ Stream)
			(QUOTE ###CACHEDMAP###))
	    do (NC.GetCachedMap Stream))
         (LIST Sketch Scale RegionViewed))))

(NC.SketchCopySubstance
  (LAMBDA (Card FromStream ToStream Length)                  (* fgh: "21-Nov-85 21:12")

          (* * Copy a sketch substance from FromStream to ToStream.)



          (* * fgh 11/14/85 Updated to handle Card object.)



          (* * fgh 11/20/85 NoteCards now handles the start and end ptrs -- passing the from ptrs as args and properly 
	  setting the to ptrs.)



          (* * fgh 11/21/85 Now passes length instead of start and end ptrs.)



          (* * Copy the bytes)


    (LET* ((FromStartPtr (GETFILEPTR FromStream))
	   (FromEndPtr (PLUS Length FromStartPtr)))
          (COPYBYTES FromStream ToStream FromStartPtr FromEndPtr))
    T))
)
(* * Redefined from NCGRAPHCARD to implement the fact that NoteCards now handles the start and
 end pointers at the beginning of each substance's storage on the disk)

(DEFINEQ

(NC.GetGraphSubstance
  (LAMBDA (Card Length)                                      (* fgh: "21-Nov-85 21:12")

          (* * fgh 11/14/85 Updated to handle Card object.)



          (* * fgh 11/20/85 NoteCards now passes start and end ptrs down.)



          (* * fgh 11/21/85 Now passes length instead of start and end ptrs.)


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

          (* * Read the Graph)


         (HREAD Stream))))

(NC.GraphCopySubstance
  (LAMBDA (Card FromStream ToStream FromStartPtr FromEndPtr)
                                                             (* fgh: "21-Nov-85 21:11")

          (* * Copy a graph substance from FromStream to ToStream.)



          (* * fgh 11/14/85 Updated to handle Card object.)



          (* * fgh 11/20/85 NoteCards now handles the start and end ptrs -- passing the from ptrs as args and properly 
	  setting the to ptrs.)



          (* * fgh 11/21/85 Now passes length instead of start and end ptrs.)



          (* * Copy the bytes)


    (LET* ((FromStartPtr (GETFILEPTR FromStream))
	   (FromEndPtr (PLUS Length FromStartPtr)))
          (COPYBYTES FromStream ToStream FromStartPtr FromEndPtr))
    T))
)
(* * Redefined from NCLISTCARD to implement the fact that NoteCards now handles the start and 
end pointers at the beginning of each substance's storage on the disk)

(DEFINEQ

(NC.ListCardGetFn
  (LAMBDA (Card Length)                                      (* fgh: "21-Nov-85 21:12")

          (* * Get the list substance from the disk)



          (* * fgh 11/20/85 NoteCards now passes start and end ptrs down.)



          (* * fgh 11/21/85 Now passes length instead of start and end ptrs.)


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

(NC.ListCardCopyFn
  (LAMBDA (Card FromStream ToStream Length)                  (* fgh: "21-Nov-85 21:11")

          (* * Copy a list substance from FromStream to ToStream.)



          (* * Copy the bytes,)



          (* * fgh 11/20/85 NoteCards now handles the start and end ptrs -- passing the from ptrs as args and properly 
	  setting the to ptrs.)



          (* * fgh 11/21/85 Now passes length instead of start and end ptrs.)


    (LET* ((FromStartPtr (GETFILEPTR FromStream))
	   (FromEndPtr (PLUS Length FromStartPtr)))
          (COPYBYTES FromStream ToStream FromStartPtr FromEndPtr))
    T))
)
(* * redefined fron NCTYPESMECH to make default copyfn be copybytes)

(DEFINEQ

(NC.MakeCardTypesList
  (LAMBDA NIL                                                (* fgh: "21-Nov-85 23:42")

          (* * Make initial set of card types.)


    (SETQ NC.CardTypes (LIST (create NoteCardType
					   TypeName ←(QUOTE NoteCard)
					   SuperType ← NIL
					   CopyFn ←(FUNCTION (LAMBDA (Card ToStream FromStream 
									     Length)
                                                             (* Copy a card's substance using copybytes.)
					       (LET* ((FromStartPtr (GETFILEPTR FromStream))
						      (FromEndPtr (PLUS Length FromStartPtr)))
						     (COPYBYTES FromStream ToStream FromStartPtr 
								  FromEndPtr)
						 T)))
					   LinkDisplayMode ←(create LINKDISPLAYMODE
								      ATTACHBITMAPFLG ← T)
					   DefaultWidth ← 100
					   DefaultHeight ← 100)))
    (SETQ NC.NoteCardTypeMenu)))
)
(PUTPROPS FGHPATCH005 COPYRIGHT ("Xerox Corporation" 1985))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (2055 7816 (NC.GetNoteCard 2065 . 5079) (NC.PutNoteCard 5081 . 7814)) (7989 12020 (
NC.GetTextSubstance 7999 . 10182) (NC.TextCopySubstance 10184 . 10807) (NC.PutTextSubstance 10809 . 
12018)) (12195 14009 (NC.GetSketchSubstance 12205 . 13282) (NC.SketchCopySubstance 13284 . 14007)) (
14183 15496 (NC.GetGraphSubstance 14193 . 14710) (NC.GraphCopySubstance 14712 . 15494)) (15669 16800 (
NC.ListCardGetFn 15679 . 16146) (NC.ListCardCopyFn 16148 . 16798)) (16876 17778 (NC.MakeCardTypesList 
16886 . 17776)))))
STOP