(FILECREATED "14-Dec-87 20:05:55" {QV}<NOTECARDS>1.3KNEXT>PMIPATCH067.;21 17993  

      changes to:  (FNS NCLOG.NumFromUID)

      previous date: "24-Nov-87 17:50:58" {QV}<NOTECARDS>1.3KNEXT>PMIPATCH067.;20)


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

(PRETTYCOMPRINT PMIPATCH067COMS)

(RPAQQ PMIPATCH067COMS ((* * Obsolete in NCLOGGER: NCLOG.FetchLogInfo NCLOG.SetLogInfo)
	(* * New in NCLOGGER)
	(GLOBALVARS NCLOG.ListOfAllEventTypes NCLOG.ListOfEventTypes NCLOG.NumHashArray)
	(VARS (NCLOG.NumHashArray (HASHARRAY NCLOG.HashArraySize))
	      (NCLOG.ListOfAllEventTypes (QUOTE (GetNewCard MakeCard.Begin MakeCard.End 
							    EditCard.Begin EditCard.End 
							    SaveCard.Begin SaveCard.End 
							    QuitCard.Begin QuitCard.End 
							    AssignTitle.Begin AssignTitle.End 
							    CacheCard UncacheCard DelCard MakeLink 
							    DelLink PutMainCardData PutLinks PutTitle 
							    PutPropList RecomputeBrowser.Begin 
							    RecomputeBrowser.End 
							    RelayoutBrowser.Begin RelayoutBrowser.End 
							    AddCardType StartLogging)))
	      (NCLOG.ListOfEventTypes NCLOG.ListOfAllEventTypes))
	(FNS NCLOG.FetchLogInfoList NCLOG.SetLogInfoList NCLOG.OpenLoggingStream 
	     NCLOG.SetEventTypesToLog NCLOG.UIDFromNum)
	(ADVISE NC.GetNewCard)
	(* * Changed in NCLOGGER)
	(RECORDS NCLogInfo)
	(FNS NCLOG.StartLogging NCLOG.SuspendLogging NCLOG.StopLogging NCLOG.LoggingOnP 
	     NCLOG.LogEvent NCLOG.NumFromUID)
	(ADVISE NC.DeleteNoteCardInternal NC.DelToLink)))
(* * Obsolete in NCLOGGER: NCLOG.FetchLogInfo NCLOG.SetLogInfo)

(* * New in NCLOGGER)

(DECLARE: DOEVAL@COMPILE DONTCOPY

(GLOBALVARS NCLOG.ListOfAllEventTypes NCLOG.ListOfEventTypes NCLOG.NumHashArray)
)

(RPAQ NCLOG.NumHashArray (HASHARRAY NCLOG.HashArraySize))

(RPAQQ NCLOG.ListOfAllEventTypes (GetNewCard MakeCard.Begin MakeCard.End EditCard.Begin 
					       EditCard.End SaveCard.Begin SaveCard.End 
					       QuitCard.Begin QuitCard.End AssignTitle.Begin 
					       AssignTitle.End CacheCard UncacheCard DelCard MakeLink 
					       DelLink PutMainCardData PutLinks PutTitle PutPropList 
					       RecomputeBrowser.Begin RecomputeBrowser.End 
					       RelayoutBrowser.Begin RelayoutBrowser.End AddCardType 
					       StartLogging))

(RPAQ NCLOG.ListOfEventTypes NCLOG.ListOfAllEventTypes)
(DEFINEQ

(NCLOG.FetchLogInfoList
  (LAMBDA (NoteFile)                                         (* pmi: "23-Oct-87 15:03")

          (* * Fetch the NCLogInfo records from the NoteFile if any. If NoteFile is nil, then return the global one.)



          (* * pmi 10/23/87: Was NCLOG.FetchLogInfo, changed to handle a list of NCLogInfos on each notefile.)


    (DECLARE (GLOBALVARS NCLOG.GlobalLogInfo))
    (COND
      ((type? NoteFile NoteFile)
	(NCP.NoteFileProp NoteFile (QUOTE NCLogInfoList)))
      ((NULL NoteFile)
	NCLOG.GlobalLogInfo)
      (T NIL))))

(NCLOG.SetLogInfoList
  (LAMBDA (NoteFile NewLogInfoRecord)                        (* pmi: "28-Oct-87 16:06")

          (* * Add this NewLogInfoRecord to the list of the NCLogInfo records for NoteFile. If NoteFile is nil, then replace 
	  the global one.)



          (* * pmi 10/28/87: Was NCLOG.SetLogInfo, changed to keep a list of NCLogInfos on a notefile, instead of just one.
	  Also now reset list of NCLogInfos to NIL if NewLogInfoRecord is NIL.)


    (DECLARE (GLOBALVARS NCLOG.GlobalLogInfo))
    (if (type? NoteFile NoteFile)
	then (if NewLogInfoRecord
		   then (NCP.NoteFileAddProp NoteFile (QUOTE NCLogInfoList)
						 NewLogInfoRecord)
		 else (NCP.NoteFileProp NoteFile (QUOTE NCLogInfoList)
					    NIL))
	       NewLogInfoRecord
      elseif (NULL NoteFile)
	then (SETQ NCLOG.GlobalLogInfo NewLogInfoRecord)
	       NewLogInfoRecord
      else NIL)))

(NCLOG.OpenLoggingStream
  (LAMBDA (NoteFile LoggingFileName LoggingStream NCLogInfo EventTypesToLog)
                                                             (* pmi: "28-Oct-87 17:57")

          (* * Creates a new NCLogInfo record for this notefile and logging filename. Opens a stream to the logging file and 
	  sets the appropriate fields of the NCLogInfo record. Returns the NCLogInfo record, if successful.)



          (* * pmi 10/28/87: Now takes EventTypesToLog argument which determines which set of event types will be logged.)


    (if NCLogInfo
      else (SETQ NCLogInfo (create NCLogInfo))
	     (NCLOG.SetLogInfoList NoteFile NCLogInfo))
    (if (SETQ LoggingStream (OPENSTREAM (OR LoggingStream LoggingFileName)
					      (QUOTE BOTH)))
	then (replace (NCLogInfo LoggingStream) of NCLogInfo with LoggingStream)
	       (replace (NCLogInfo LoggingOnFlg) of NCLogInfo with T)
	       (replace (NCLogInfo LoggingFileName) of NCLogInfo with (FULLNAME LoggingStream)
			  )
	       (replace (NCLogInfo EventTypesToLog) of NCLogInfo with EventTypesToLog)
	       (NCLOG.WriteLogFileHeader LoggingStream NoteFile)
	       NCLogInfo)))

(NCLOG.SetEventTypesToLog
  (LAMBDA (NoteFile NCLogInfo EventTypesToLog)               (* pmi: "28-Oct-87 11:20")

          (* * pmi 10/28/87: Created to change the EventTypesToLog field in the NCLogInfo record of NoteFile.
	  If EventTypesToLog is NIL, then change the EventTypesToLog fields of all NCLogInfo records associated with 
	  NoteFile. If NoteFile is NIL, change the EventTypesToLog field of the global NCLogInfo record.
	  If EventTypesToLog is NIL, then use NCLOG.ListOfEventTypes.)


    (DECLARE (GLOBALVARS NCLOG.GlobalLogInfo NCLOG.ListOfEventTypes))
    (LET ((NCLogInfoList (NCLOG.FetchLogInfoList NoteFile)))
         (OR EventTypesToLog (SETQ EventTypesToLog NCLOG.ListOfEventTypes))
         (if NoteFile
	     then (if NCLogInfo
			then (for NCLogInfoRecord in NCLogInfoList when (EQ NCLogInfoRecord 
										      NCLogInfo)
				  do (replace (NCLogInfo EventTypesToLog) of NCLogInfo
					  with EventTypesToLog))
		      else (for NCLogInfoRecord in NCLogInfoList do (replace (NCLogInfo
											 
										  EventTypesToLog)
									       of NCLogInfo
									       with EventTypesToLog)
				    ))
	   else (replace (NCLogInfo EventTypesToLog) of NCLOG.GlobalLogInfo with 
										  EventTypesToLog)))))

(NCLOG.UIDFromNum
  (LAMBDA (Num)                                              (* pmi: "23-Nov-87 12:06")

          (* * Translate an integer into a UID using a global hash array.)


    (DECLARE (GLOBALVARS NCLOG.NumHashArray))
    (GETHASH Num NCLOG.NumHashArray)))
)

(PUTPROPS NC.GetNewCard READVICE (NIL (AFTER NIL (NCLOG.LogEvent (QUOTE GetNewCard)
								   NoteFile
								   (LIST !VALUE Type)))))
(READVISE NC.GetNewCard)
(* * Changed in NCLOGGER)

[DECLARE: EVAL@COMPILE 

(DATATYPE NCLogInfo (LoggingStream LoggingOnFlg NoticedUIDs EventTypesToLog LoggingFileName))
]
(/DECLAREDATATYPE (QUOTE NCLogInfo)
		  (QUOTE (POINTER POINTER POINTER POINTER POINTER))
		  (QUOTE ((NCLogInfo 0 POINTER)
			  (NCLogInfo 2 POINTER)
			  (NCLogInfo 4 POINTER)
			  (NCLogInfo 6 POINTER)
			  (NCLogInfo 8 POINTER)))
		  (QUOTE 10))
(DEFINEQ

(NCLOG.StartLogging
  (LAMBDA (NoteFile LoggingFileNameOrNCLogInfo EventTypesToLog)
                                                             (* pmi: "29-Oct-87 10:32")

          (* * Turn on logging for NoteFile. If logging was already on, then do nothing and return NIL.
	  If LoggingFileName is NIL, then use a {nodircore} file.)



          (* * pmi 10/23/87: Add current LoggingFileName to NCLogInfo record for this NoteFile)



          (* * pmi 10/27/87: Made changes to accommodate multiple NCLogInfo records per notefile. Also changed so that NIL 
	  for NoteFile means turn on global logging. Now returns the relevent NCLogInfo record.)



          (* * pmi 10/28/87: Now takes EventTypesToLog argument which determines which set of event types will be logged.)


    (DECLARE (GLOBALVARS NCLOG.ListOfEventTypes))
    (LET ((NCLogInfoList (NCLOG.FetchLogInfoList NoteFile))
	  NCLogInfo LoggingFileName LoggingStream)

          (* * Sort out LoggingFileNameOrNCLogInfo)


         (if (type? NCLogInfo LoggingFileNameOrNCLogInfo)
	     then (SETQ NCLogInfo LoggingFileNameOrNCLogInfo)
		    (SETQ LoggingFileName NIL)
	   elseif LoggingFileNameOrNCLogInfo
	     then (SETQ NCLogInfo NIL)
		    (SETQ LoggingFileName (FULLNAME LoggingFileNameOrNCLogInfo (QUOTE NEW)))
	   else (SETQ LoggingFileName (QUOTE {NODIRCORE}NCLOGFILE)))
         (OR EventTypesToLog (SETQ EventTypesToLog NCLOG.ListOfEventTypes))

          (* * Look for LoggingFileNameOrNCLogInfo as either a NCLogInfo record on this notefile or a filename contained in 
	  one of the NCLogInfo records.)


         (if (AND NoteFile NCLogInfoList (OR (FMEMB NCLogInfo NCLogInfoList)
						   (SETQ NCLogInfo
						     (for NCLogInfoRecord in NCLogInfoList
							thereis (EQUAL LoggingFileName
									   (fetch (NCLogInfo 
										  LoggingFileName)
									      of NCLogInfoRecord))))
						   ))
	     then (if (fetch (NCLogInfo LoggingOnFlg) of NCLogInfo)
			then 

          (* * Logging is already on. Bail out.)


			       NIL
		      elseif (AND (SETQ LoggingStream (fetch (NCLogInfo LoggingStream)
							       of NCLogInfo))
				      (OPENP LoggingStream (QUOTE BOTH)))
			then 

          (* * Logging file exists and is open.)


			       (replace (NCLogInfo LoggingOnFlg) of NCLogInfo with T)
			       NCLogInfo
		      else 

          (* * There's no LoggingStream or it's closed, so make one using LoggingFileName.)


			     (NCLOG.OpenLoggingStream NoteFile LoggingFileName LoggingStream 
							NCLogInfo EventTypesToLog))
	   else 

          (* * This notefile has no logging happening; start one op.)


		  (NCLOG.OpenLoggingStream NoteFile LoggingFileName NIL NIL EventTypesToLog)))))

(NCLOG.SuspendLogging
  (LAMBDA (NoteFile NCLogInfo)                               (* pmi: "27-Oct-87 17:43")

          (* * Temporarily turn off the logging on NoteFile, but don't close LoggingStream.)



          (* * pmi 10/27/87: Changed to handle multiple NCLogInfo records per notefile. If no NCLogInfo is specified, suspend
	  its logging. If not, suspend logging on all NCLogInfo records associated with this notefile.
	  Also changed do that a NIL NoteFile means suspend global logging.)


    (DECLARE (GLOBALVARS NCLOG.GlobalLogInfo))
    (LET (NCLogInfoList (NCLOG.FetchLogInfoList NoteFile))
         (if NoteFile
	     then (if NCLogInfo
			then (AND (MEMBER NCLogInfo NCLogInfoList)
				      (replace (NCLogInfo LoggingOnFlg) of NCLogInfo
					 with NIL))
		      else (for NCLogInfoRecord in NCLogInfoList do (replace (NCLogInfo
											 LoggingOnFlg)
									       of NCLogInfoRecord
									       with NIL)))
	   else (replace (NCLogInfo LoggingOnFlg) of NCLOG.GlobalLogInfo with NIL)))))

(NCLOG.StopLogging
  (LAMBDA (NoteFile NCLogInfo WriteLegendFlg)                (* pmi: "28-Oct-87 12:19")

          (* * Turn off notefile logging. Return the result of closing the LoggingStream. If WriteLegendFlg is non-nil, then 
	  write down a legend mapping numbers to UIDs. Write down the location of the start of the legend at the end of the 
	  file.)



          (* * pmi 10/28/87: Changed to handle multiple NCLogInfo records per notefile. If a NCLogInfo is specified, then 
	  stop logging on it. If not, stop logging on all NCLogInfo records associated with this notefile.)


    (DECLARE (GLOBALVARS NC.OrigReadTable))
    (if (NCLOG.LoggingOnP NoteFile NCLogInfo)
	then (LET (NCLogInfoList LoggingStream)
		    (NCLOG.SuspendLogging NoteFile NCLogInfo)
		    (SETQ NCLogInfoList (MKLIST (OR NCLogInfo (NCLOG.FetchLogInfoList 
											 NoteFile))))
		    (for NCLogInfoRecord in NCLogInfoList
		       collect (SETQ LoggingStream (fetch (NCLogInfo LoggingStream)
							  of NCLogInfoRecord))
				 (if (AND WriteLegendFlg LoggingStream (OPENP LoggingStream))
				     then (LET ((StartLegendLoc (GETFILEPTR LoggingStream)))
					         (for UID in (fetch (NCLogInfo NoticedUIDs)
								    of NCLogInfoRecord)
						    do (PRINT (LIST (NCLOG.NumFromUID UID)
									  UID)
								  LoggingStream NC.OrigReadTable))
					         (PRINT StartLegendLoc LoggingStream 
							  NC.OrigReadTable)))
				 (PROG1 (AND LoggingStream (OPENP LoggingStream)
						 (CLOSEF LoggingStream))
					  (replace (NCLogInfo LoggingStream) of NCLogInfoRecord
					     with NIL)
					  (replace (NCLogInfo NoticedUIDs) of NCLogInfoRecord
					     with NIL)))))))

(NCLOG.LoggingOnP
  (LAMBDA (NoteFile NCLogInfo)                               (* pmi: " 3-Nov-87 11:55")

          (* * Return non-nil if logging is turned on for NoteFile.)



          (* * pmi 10/27/87: Changed to handle multiple NCLogInfo records per notefile. If no NCLogInfo is specified and 
	  there is at least one NCLogInfo record on this notefile with a non-NIL LoggingOnFlg, then T is returned.
	  Also, now returns the LoggingOnFlg for NCLOG.GlobalLogInfo if NoteFile is NIL.)


    (DECLARE (GLOBALVARS NCLOG.GlobalLogInfo))
    (LET ((NCLogInfoList (NCLOG.FetchLogInfoList NoteFile)))
         (if NoteFile
	     then (if NCLogInfo
			then (AND (MEMBER NCLogInfo NCLogInfoList)
				      (fetch (NCLogInfo LoggingOnFlg) of NCLogInfo))
		      else (for NCLogInfoRecord in NCLogInfoList thereis (fetch
										   (NCLogInfo 
										     LoggingOnFlg)
										    of 
										  NCLogInfoRecord)))
	   elseif (type? NCLogInfo NCLOG.GlobalLogInfo)
	     then (fetch (NCLogInfo LoggingOnFlg) of NCLOG.GlobalLogInfo)
	   else NIL))))

(NCLOG.LogEvent
  (LAMBDA (EventType NoteFile EventArgs)                     (* pmi: "27-Oct-87 18:09")

          (* * Log an event of type EventType happening to NoteFile with args EventArgs. NoteFile may be NIL if there's no 
	  notefile object. Can log either on global logging stream or on Logging stream for given notefile or both.)



          (* * pmi 10/27/87: Changed to handle multiple NCLogInfo records for a notefile.)


    (LET ((EventTime (IDATE))
	  GlobalLogInfo NoteFileLogInfo LoggingStream)       (* Log on global logging stream if turned on.)
         (if (AND (NCLOG.LoggingOnP NIL)
		      (SETQ GlobalLogInfo (NCLOG.FetchLogInfo NIL))
		      (SETQ LoggingStream (fetch (NCLogInfo LoggingStream) of GlobalLogInfo))
		      (OPENP LoggingStream (QUOTE OUTPUT)))
	     then (NCLOG.WriteEventToLogStream LoggingStream GlobalLogInfo EventType NoteFile 
						   EventTime (MKLIST EventArgs)))
                                                             (* Log on local logging stream if turned on.)
         (if (type? NoteFile NoteFile)
	     then (for NoteFileLogInfo in (NCLOG.FetchLogInfoList NoteFile)
		       when (AND (NCLOG.LoggingOnP NoteFile NoteFileLogInfo)
				     (SETQ LoggingStream (fetch (NCLogInfo LoggingStream)
							      of NoteFileLogInfo))
				     (OPENP LoggingStream (QUOTE OUTPUT))
				     (FMEMB EventType (fetch (NCLogInfo EventTypesToLog)
							   of NoteFileLogInfo)))
		       do (NCLOG.WriteEventToLogStream LoggingStream NoteFileLogInfo EventType 
							   NoteFile EventTime (MKLIST EventArgs)))))
    ))

(NCLOG.NumFromUID
  (LAMBDA (UID)                                              (* pmi: "14-Dec-87 19:15")

          (* * Translate the UID into an integer using a global hash array. This is to save space on the logging file.)



          (* * pmi 11/24/87: Added NCLOG.NumHashArray for getting UID's back from numbers later.)


    (DECLARE (GLOBALVARS NCLOG.UIDHashArray NCLOG.NumHashArray NCLOG.UIDCtr))
    (if (GETHASH UID NCLOG.UIDHashArray)
      else (PUTHASH UID (add NCLOG.UIDCtr 1)
			NCLOG.UIDHashArray)
	     (PUTHASH NCLOG.UIDCtr UID NCLOG.NumHashArray))))
)

(PUTPROPS NC.DeleteNoteCardInternal READVICE (NIL (BEFORE NIL (NCLOG.LogEvent (QUOTE DelCard)
										(fetch (Card NoteFile)
										       of Card)
										(LIST Card
										      (NC.FetchTitle
											Card))))))

(PUTPROPS NC.DelToLink READVICE (NIL (BEFORE NIL (LET ((NoteFile (fetch (Card NoteFile)
									  of
									  (fetch (Link SourceCard)
										 of Link))))
							(if (type? Link Link)
							    then
							    (NCLOG.LogEvent
							      (QUOTE DelLink)
							      NoteFile
							      (LIST Link (fetch (Link SourceCard)
										of Link)
								    (fetch (Link DestinationCard)
									   of Link)
								    (fetch (Link Label)
									   of Link)
								    (fetch (Link AnchorMode)
									   of Link)
								    (fetch (Link DisplayMode)
									   of Link)))
							    else
							    (NCLOG.LogEvent (QUOTE DelLink)
									    NoteFile Link))))))
(READVISE NC.DeleteNoteCardInternal NC.DelToLink)
(PUTPROPS PMIPATCH067 COPYRIGHT ("Xerox Corporation" 1987))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (2361 6882 (NCLOG.FetchLogInfoList 2371 . 2965) (NCLOG.SetLogInfoList 2967 . 3931) (
NCLOG.OpenLoggingStream 3933 . 5205) (NCLOG.SetEventTypesToLog 5207 . 6586) (NCLOG.UIDFromNum 6588 . 
6880)) (7458 16945 (NCLOG.StartLogging 7468 . 10424) (NCLOG.SuspendLogging 10426 . 11558) (
NCLOG.StopLogging 11560 . 13417) (NCLOG.LoggingOnP 13419 . 14588) (NCLOG.LogEvent 14590 . 16322) (
NCLOG.NumFromUID 16324 . 16943)))))
STOP