(FILECREATED "13-Jan-86 21:01:15" {QV}<NOTECARDS>1.3K>FGHPATCH012.;1 7334         changes to:  (VARS FGHPATCH012COMS)		   (FNS NC.OpenDatabaseFile))(* Copyright (c) 1986 by Xerox Corporation. All rights reserved.)(PRETTYCOMPRINT FGHPATCH012COMS)(RPAQQ FGHPATCH012COMS ((* * From NCDATABASE bug fix to OpenDatabaseFile)			  (FNS NC.OpenDatabaseFile)))(* * From NCDATABASE bug fix to OpenDatabaseFile)(DEFINEQ(NC.OpenDatabaseFile  (LAMBDA (NoteFileOrFileName Access Don'tCacheTypesAndTitlesFlg QuietFlg Don'tCreateFlg 			      Convertw/oConfirmFlg Don'tCreateArrayFlg Don'tTruncateFlg 			      Don'tCreateInterfaceFlg Don'tGetSpecialCardsFlg)                                                             (* fgh: "13-Jan-86 20:57")          (* * Open an already existing NoteFile and return a NoteFile object)          (* * rht 8/7/84: For nonexistent files, asks user whether to create unless Don'tCreateFlg is non-nil.)          (* * rht 1/9/85: Checks NC.UncachingNotCompleted global var. If non-nil, then previous notefile died unnaturally, 	  so we first clear junk off the IDs.)          (* * rht 8/6/85: Added Don'tTruncateFlg, which, if on, prevents the check for truncation.)          (* * fgh 10/16/85 Updated to use new cacheing scheme.)          (* * kirk 10/29/85: Now does cacheing of types and titles as background process.)          (* * fkr 11/8/85: Converted from Streams to NoteFile object.)          (* * kirk 30Nov85 Added a check for correct version number.)          (* * rht 12/6/85: Moved Kirk's above patch to NC.CheckForNeededConversion and modified somewhat.	  Added check for plausible header.)          (* * rht 1/8/86: Now reuses old notefile object if there is one for this filename.)          (* * fgh 1/13/86: Fixed bug with returning File Name with embedded call to CreateDatabaseFile.	  Now just calls OpenDatabaseFile recursively using result of CreateDatabaseFile.)    (PROG (NoteFile FileName Name Stream NewStream Card CardTotal)	    (OR Access (SETQ Access (QUOTE BOTH)))	    (SETQ FileName (COND		((type? NoteFile NoteFileOrFileName)		  (SETQ NoteFile NoteFileOrFileName)		  (fetch (NoteFile FullFileName) of NoteFileOrFileName))		(T NoteFileOrFileName)))	    (if (NOT (OR FileName (SETQ FileName (NC.DatabaseFileName 								      "Name of NoteFile to open:"										" -- " T))))		then (RETURN NIL))	    (if (OPENP FileName)		then (NC.PrintMsg NIL T FileName " is an already open file." (CHARACTER 13))		       (RETURN NIL))	    (if (NOT (SETQ Name (INFILEP FileName)))		then (COND			 (Don'tCreateFlg (NC.PrintMsg NIL T "Couldn't find NoteFile " FileName "."							(CHARACTER 13))					 (RETURN NIL))			 ((NC.YesP (NC.AskUser (CONCAT "Unable to find NoteFile " FileName "."							     (CHARACTER 13)							     						     "Want to create new NoteFile by that name? ")						   " -- " "Yes" T NIL T NIL T))			   (SETQ NoteFile (NC.CreateDatabaseFile FileName NIL "Opening NoteFile" 								     T))			   (if (NOT (type? NoteFile NoteFile))			       then (NC.PrintMsg NIL T "Unable to create Notefile " FileName "."						     (CHARACTER 13))				      (RETURN NIL)			     else (RETURN (NC.OpenDatabaseFile NoteFile Access 								     Don'tCacheTypesAndTitlesFlg 								     QuietFlg Don'tCreateFlg 								     Convertw/oConfirmFlg 								     Don'tCreateArrayFlg 								     Don'tTruncateFlg 								     Don'tCreateInterfaceFlg 								     Don'tGetSpecialCardsFlg))))			 (T (RETURN NIL))))	    (OR QuietFlg (NC.PrintMsg NIL T "Opening ... " (CHARACTER 13)))	    (if (NULL (SETQ Stream (CAR (ERSETQ (OPENSTREAM Name Access (QUOTE OLD)									(QUOTE ((TYPE BINARY))))))))		then (NC.PrintMsg NIL T "Couldn't open " FileName "." (CHARACTER 13))		       (RETURN NIL))                       (* Use existing notefile object if there is one for 							     this file name.)	    (OR (type? NoteFile NoteFile)		  (SETQ NoteFile (OR (NC.NoteFileFromFileName FileName)					 (create NoteFile))))	    (replace (NoteFile Stream) of NoteFile with Stream)	    (replace (NoteFile FullFileName) of NoteFile with (FULLNAME Stream))	    (NC.SetMonitor NoteFile (CREATE.MONITORLOCK (MKATOM (CONCAT Name ":LOCK"))))	    (NC.GetNoteFileHeader NoteFile)                (* See if notefile is out of date.							     If so, convert to current version.)	    (if (NOT (NC.CheckForNeededConversion NoteFile Convertw/oConfirmFlg))		then (CLOSEF (fetch (NoteFile Stream) of NoteFile))		       (NC.PrintMsg NIL T "Open cancelled.")		       (RETURN NIL))                       (* See if notefile header seems reasonable.							     If not, bail out.)	    (if (NOT (NC.PlausibleNoteFileHeaderP NoteFile))		then (NC.PrintMsg NIL NIL 				      "Notefile has bad header.  Please see a NoteCards wizard."				      (CHARACTER 13)				      "Open cancelled.")		       (RETURN NIL))	    (COND	      ((NULL Don'tTruncateFlg)                     (* Can either bail out entirely or run inspector and 							     then bail out.)		(SELECTQ (SETQ NewStream (NC.CheckForNeededTruncation NoteFile Access))			   (ABORT (CLOSEF Stream)				  (NC.PrintMsg NIL T "Open cancelled.")				  (RETURN NIL))			   (ABORTANDINSPECT (CLOSEF Stream)					    (NC.ScavengerPhase1 Name)					    (RETURN NIL))			   NIL)		(AND (STREAMP NewStream)		       (replace (NoteFile Stream) of NoteFile with NewStream))))	    (OR Don'tCreateArrayFlg (NC.BuildHashArray NoteFile))          (* * Make sure the NF can't be closed by CLOSEALL)	    (WHENCLOSE (fetch (NoteFile Stream) of NoteFile)			 (QUOTE CLOSEALL)			 (QUOTE NO))	    (COND	      ((NULL Don'tCacheTypesAndTitlesFlg)          (* Cache all of the titles in this database)		(replace (NoteFile CachingProcess) of NoteFile		   with (ADD.PROCESS (LIST (FUNCTION NC.CacheTypesAndTitles)						 NoteFile)))))                                                             (* Stash the special cards into the NoteFile object.)	    (OR Don'tGetSpecialCardsFlg (NC.GetSpecialCards NoteFile))                                                             (* Stash the notefile in the global notefiles hash 							     array.)	    (NC.StoreNoteFile NoteFile)	    (COND	      ((NULL Don'tCreateInterfaceFlg)              (* Make an interface menu for this notefile.)		(NC.SetUpNoteFileInterface NoteFile)))	    (AND (NULL QuietFlg)		   (NC.PrintMsg NIL T "Opened " (FULLNAME Stream)				  (CHARACTER 13)))	    (SETQ NC.LastNoteFileOpened NoteFile)	    (RETURN NoteFile)))))(PUTPROPS FGHPATCH012 COPYRIGHT ("Xerox Corporation" 1986))(DECLARE: DONTCOPY  (FILEMAP (NIL (428 7252 (NC.OpenDatabaseFile 438 . 7250)))))STOP