(FILECREATED "19-Feb-87 10:06:44" {QV}<NOTECARDS>1.3K>NEXT>RHTPATCH203.;1 6105   

      changes to:  (VARS RHTPATCH203COMS)
		   (FNS NC.AbortSession))


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

(PRETTYCOMPRINT RHTPATCH203COMS)

(RPAQQ RHTPATCH203COMS ((* * Fixes bug #390: Aborting a notefile
			     (and thus also closing notefiles that were open read-only)
			     now kills the CacheTypesAndTitles process.)
			  (* * Change to NCDATABASE)
			  (FNS NC.AbortSession)))
(* * Fixes bug #390: Aborting a notefile (and thus also closing notefiles that were open 
read-only) now kills the CacheTypesAndTitles process.)

(* * Change to NCDATABASE)

(DEFINEQ

(NC.AbortSession
  (LAMBDA (NoteFile InterestedWindow Don'tConfirmFlg QuietFlg)
                                                             (* rht: "19-Feb-87 10:04")

          (* * Kill the current notecards session. Work lost since last checkpoint.)



          (* * rht 7/14/85: Replaced the call to reset the main menu with call to NC.ResetMainMenu. Also took out redundant 
	  reset of PSA.Database, since NC.ForceDatabaseClose is doing that.)



          (* * fgh & rht 10/16/85 Update with new cacheing mechanism.)



          (* * fkr 11/8/85 Updated to handle noteFile object and new CardID scheme.)



          (* * kirk 20Jan86 Added Don'tCloseFlg to leave NoteFile open after done deleting changes.)



          (* * kirk 23Jan86 Changed to use NC.AskYesOrNo)



          (* * rht 7/2/86: No longer bugs you if no changes were made since last checkpoint. Removed Don'tCloseFlg arg and 
	  added InterestedWindow arg.)



          (* * rht 7/6/86: Now clears InterestedWindow of final truncating message.)



          (* * rht 7/13/86: Added Don'tConfirmFlg and QuietFlg args. Note that Don'tConfirmFlg non-nil stops questioning of 
	  user as to losing all changes.)



          (* * kirk 11/17/86 Changed call on SETFILEINFO to pass stream instead of filename.)



          (* * pmi 12/22/86 Made test for open notefile consistent with other NoteFile operations (ie. Checkpoint, Close))



          (* * rht 2/19/87: Added DEL.PROCESS call to kill caching process.)


    (DECLARE (GLOBALVARS NC.MsgDelay))
    (PROG ((Stream (fetch (NoteFile Stream) of NoteFile))
	     (FullFileName (fetch (NoteFile FullFileName) of NoteFile))
	     (LastChkptPtr (fetch (NoteFile CheckptPtr) of NoteFile))
	     EndPtr CardTotal NewBytes ReturnValue)
	    (OR InterestedWindow (SETQ InterestedWindow (WFROMMENU (fetch (NoteFile Menu)
									    of NoteFile))))
	    (if (NULL (ERSETQ (SETQ ReturnValue (NC.NoteFileOpenP NoteFile))))
		then (SETQ ReturnValue (QUOTE OpenPFailed)))
	    (if (NULL ReturnValue)
		then 

          (* * NoteFile is not open.)


		       (NC.PrintMsg InterestedWindow T "Can't abort a closed notefile."
				      (CHARACTER 13))
		       (DISMISS NC.MsgDelay)
		       (NC.ClearMsg InterestedWindow T)
		       (RETURN NIL)
	      elseif (NOT (type? NoteFile ReturnValue))
		then 

          (* * Error return from NoteFileOpenPFn)


		       (if (NULL (ERSETQ (NC.ReportError NIL (CONCAT "OpenP test on " 
									       FullFileName 
									       "failed because "
									       ReturnValue
									       (CHARACTER 13)
									       
							"OK to continue Abort. ↑ to abort Abort."))))
			   then (RETURN ReturnValue)))

          (* * Delete the types and titles caching process if still alive. Have to do it now in order to make checking 
	  operations that follow suitably efficient. Note its a bit too early since we can still cancel this close.
	  But any harm done is loss of speed if NoteFile remains open when close iss cancelled.)


	    (DEL.PROCESS (fetch (NoteFile CachingProcess) of NoteFile))
	    (SETQ EndPtr (GETEOFPTR Stream))
	    (SETQ NewBytes (IDIFFERENCE EndPtr LastChkptPtr))
	    (if (OR (ZEROP NewBytes)
			Don'tConfirmFlg
			(NC.AskYesOrNo (CONCAT "Do you wish to lose all changes since"
						   (CHARACTER 13)
						   "the last checkpoint (" NewBytes " bytes) of " 
						   FullFileName)
					 "--" "Yes" T InterestedWindow NIL T))
		then (LET ((CardNumber 0)
			     (CardTotal (fetch (NoteFile HashArraySize) of NoteFile)))
			    (NC.MapCards NoteFile
					 (FUNCTION (LAMBDA (Card)
					     (LET (Win)
					          (SETQ CardNumber (ADD1 CardNumber))
					          (OR QuietFlg (COND
							  ((ZEROP (IREMAINDER CardNumber 100))
							    (NC.PrintMsg InterestedWindow T 
								"Quitting from active cards ... "
									   (CHARACTER 13)
									   "Processing item number " 
									   CardNumber " out of " 
									   CardTotal "."
									   (CHARACTER 13)))))
					          (COND
						    ((NC.ActiveCardP Card)
						      (SETQ Win (NC.FetchWindow Card))
						      (NC.AbortCard Card QuietFlg)
						      (COND
							(Win (bind (Process ←(WINDOWPROP
										Win
										(QUOTE PROCESS)))
								until (OR (NULL Process)
									      (PROCESS.FINISHEDP
										Process))
								do (BLOCK))
							     (CLOSEW Win))))))))))
		       (COND
			 ((LESSP LastChkptPtr EndPtr)
			   (OR QuietFlg (NC.PrintMsg InterestedWindow T "Truncating file " 
							 FullFileName " ..."))
			   (COND
			     ((NOT (SETFILEINFO Stream (QUOTE LENGTH)
						    LastChkptPtr))
			       (NC.PrintMsg InterestedWindow NIL "Couldn't truncate " FullFileName 
					      "."
					      (CHARACTER 13))))))
		       (NC.ResetNoteFileInterface NoteFile)
		       (NC.ForceDatabaseClose NoteFile))
	    (NC.ClearMsg InterestedWindow T))))
)
(PUTPROPS RHTPATCH203 COPYRIGHT ("Xerox Corporation" 1987))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (695 6023 (NC.AbortSession 705 . 6021)))))
STOP