(FILECREATED "14-Dec-87 20:22:50" {QV}<NOTECARDS>1.3K>LIBRARY>NCLOGGER.;4 20466 changes to: (VARS NCLOGGERCOMS) previous date: "18-Mar-87 17:26:12" {QV}<NOTECARDS>1.3K>LIBRARY>NCLOGGER.;3) (* Copyright (c) 1987 by Xerox Corporation. All rights reserved.) (PRETTYCOMPRINT NCLOGGERCOMS) (RPAQQ NCLOGGERCOMS ((* * This package instruments NoteCards so that entries are written to a log file whenever certain "monitored" events take place.) (* * Have to load NCBROWSERCARD because we advise some of its functions later.) [DECLARE: COPY FIRST (P (NC.LoadFileFromDirectories (QUOTE NCBROWSERCARD] (GLOBALVARS NCLOG.GlobalLogInfo NCLOG.UIDHashArray NCLOG.HashArraySize NCLOG.UIDCtr) (GLOBALVARS NC.OrigReadTable) (INITVARS (NCLOG.UIDCtr 0)) (VARS (NCLOG.HashArraySize 100) (NCLOG.UIDHashArray (NC.CreateUIDHashArray NCLOG.HashArraySize)) (NCLOG.GlobalLogInfo NIL)) (RECORDS NCLogInfo) (* * "External" interface fns.) (FNS NCLOG.StartLogging NCLOG.StopLogging NCLOG.SuspendLogging NCLOG.LoggingOnP) (* * Internal stuff) (FNS NCLOG.FetchLogInfo NCLOG.SetLogInfo NCLOG.LogEvent NCLOG.WriteEventToLogStream NCLOG.WriteLogFileHeader) (* * Stuff to handle the printing of various NC objects.) (FNS NCLOG.CardObjectDEFPRINTFn NCLOG.LinkDEFPRINTFn NCLOG.NoteFileDEFPRINTFn NCLOG.UIDDEFPRINTFn NCLOG.SingleArgDEFPRINT NCLOG.NumFromUID NCLOG.StringFromUID) (* * Here's the advice for the functions that we want to monitor.) (* * Operations that happen to an open notefile.) (ADVISE NC.EditNoteCard NC.QuitCard NC.MakeNoteCard NC.DeleteNoteCardInternal) (ADVISE NC.ActivateCard NC.DeactivateCard) (ADVISE NC.CardSaveFn NC.PutLinks NC.PutMainCardData NC.PutPropList NC.PutTitle) (ADVISE NC.AssignTitle) (ADVISE NC.MakeLink NC.DelToLink) (ADVISE NC.UpdateBrowserCard NC.RelayoutBrowserCard) (* * Other operations.) (ADVISE NC.AddCardType))) (* * This package instruments NoteCards so that entries are written to a log file whenever certain "monitored" events take place.) (* * Have to load NCBROWSERCARD because we advise some of its functions later.) (DECLARE: COPY FIRST (NC.LoadFileFromDirectories (QUOTE NCBROWSERCARD)) ) (DECLARE: DOEVAL@COMPILE DONTCOPY (GLOBALVARS NCLOG.GlobalLogInfo NCLOG.UIDHashArray NCLOG.HashArraySize NCLOG.UIDCtr) ) (DECLARE: DOEVAL@COMPILE DONTCOPY (GLOBALVARS NC.OrigReadTable) ) (RPAQ? NCLOG.UIDCtr 0) (RPAQQ NCLOG.HashArraySize 100) (RPAQ NCLOG.UIDHashArray (NC.CreateUIDHashArray NCLOG.HashArraySize)) (RPAQQ NCLOG.GlobalLogInfo NIL) [DECLARE: EVAL@COMPILE (DATATYPE NCLogInfo (LoggingStream LoggingOnFlg NoticedUIDs)) ] (/DECLAREDATATYPE (QUOTE NCLogInfo) (QUOTE (POINTER POINTER POINTER)) (QUOTE ((NCLogInfo 0 POINTER) (NCLogInfo 2 POINTER) (NCLogInfo 4 POINTER))) (QUOTE 6)) (* * "External" interface fns.) (DEFINEQ (NCLOG.StartLogging (LAMBDA (NoteFile LoggingFileName) (* rht: "18-Mar-87 15:56") (* * 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.) (LET* ((NCLogInfo (OR (NCLOG.FetchLogInfo NoteFile) (NCLOG.SetLogInfo NoteFile (create NCLogInfo)))) (LoggingStream (fetch (NCLogInfo LoggingStream) of NCLogInfo)) (LoggingOnFlg (fetch (NCLogInfo LoggingOnFlg) of NCLogInfo))) (OR LoggingFileName (SETQ LoggingFileName (QUOTE {NODIRCORE}NCLOGFILE))) (COND (LoggingOnFlg (* * Logging is already on. Bail out.) NIL) ((AND LoggingStream (OPENP LoggingStream (QUOTE BOTH))) (* * Logging file exists and is open.) (replace (NCLogInfo LoggingOnFlg) of NCLogInfo with T) LoggingStream) (T (* * There's no LoggingStream or it's closed, so make one using LoggingFileName.) (if (SETQ LoggingStream (OPENSTREAM (OR LoggingStream LoggingFileName) (QUOTE BOTH))) then (replace (NCLogInfo LoggingStream) of NCLogInfo with LoggingStream) (replace (NCLogInfo LoggingOnFlg) of NCLogInfo with T) (NCLOG.WriteLogFileHeader LoggingStream NoteFile) LoggingStream else NIL)))))) (NCLOG.StopLogging (LAMBDA (NoteFile WriteLegendFlg) (* rht: "18-Mar-87 12:03") (* * 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.) (DECLARE (GLOBALVARS NC.OrigReadTable)) (if (NCLOG.LoggingOnP NoteFile) then (LET* ((NCLogInfo (NCLOG.FetchLogInfo NoteFile)) (LoggingStream (fetch (NCLogInfo LoggingStream) of NCLogInfo))) (NCLOG.SuspendLogging NoteFile) (if (AND WriteLegendFlg LoggingStream (OPENP LoggingStream)) then (LET ((StartLegendLoc (GETFILEPTR LoggingStream))) (for UID in (fetch (NCLogInfo NoticedUIDs) of NCLogInfo) 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 NCLogInfo with NIL) (replace (NCLogInfo NoticedUIDs) of NCLogInfo with NIL)))))) (NCLOG.SuspendLogging (LAMBDA (NoteFile) (* rht: "18-Mar-87 11:14") (* * Temporarily turn off the logging on NoteFile, but don't close LoggingStream.) (LET (NCLogInfo) (AND (SETQ NCLogInfo (NCLOG.FetchLogInfo NoteFile)) (replace (NCLogInfo LoggingOnFlg) of NCLogInfo with NIL))))) (NCLOG.LoggingOnP (LAMBDA (NoteFile) (* rht: "18-Mar-87 11:18") (* * Return non-nil if logging is turned on for NoteFile.) (LET ((NCLogInfo (NCLOG.FetchLogInfo NoteFile))) (AND NCLogInfo (fetch (NCLogInfo LoggingOnFlg) of NCLogInfo))))) ) (* * Internal stuff) (DEFINEQ (NCLOG.FetchLogInfo (LAMBDA (NoteFile) (* rht: "18-Mar-87 15:56") (* * Fetch the NCLogInfo record from the NoteFile if any. If NoteFile is nil, then return the global one.) (DECLARE (GLOBALVARS NCLOG.GlobalLogInfo)) (COND ((type? NoteFile NoteFile) (NCP.NoteFileProp NoteFile (QUOTE NCLogInfo))) ((NULL NoteFile) NCLOG.GlobalLogInfo) (T NIL)))) (NCLOG.SetLogInfo (LAMBDA (NoteFile NewLogInfoRecord) (* rht: "18-Mar-87 15:55") (* * Replace the NCLogInfo record for NoteFile. If NoteFile is nil, then replace the global one.) (COND ((type? NoteFile NoteFile) (NCP.NoteFileProp NoteFile (QUOTE NCLogInfo) NewLogInfoRecord) NewLogInfoRecord) ((NULL NoteFile) (SETQ NCLOG.GlobalLogInfo NewLogInfoRecord) NewLogInfoRecord) (T NIL)))) (NCLOG.LogEvent (LAMBDA (EventType NoteFile EventArgs) (* rht: "18-Mar-87 16:14") (* * 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.) (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 (AND (type? NoteFile NoteFile) (NCLOG.LoggingOnP NoteFile) (SETQ NoteFileLogInfo (NCLOG.FetchLogInfo NoteFile)) (SETQ LoggingStream (fetch (NCLogInfo LoggingStream) of NoteFileLogInfo)) (OPENP LoggingStream (QUOTE OUTPUT))) then (NCLOG.WriteEventToLogStream LoggingStream NoteFileLogInfo EventType NoteFile EventTime (MKLIST EventArgs)))))) (NCLOG.WriteEventToLogStream (LAMBDA (Stream NCLogInfo EventType NoteFile EventTime EventArgs) (* rht: "18-Mar-87 11:50") (* * Write given event, time, NoteFile and args to stream. Temporarily change the UID print fn so that UIDs and other objects will get printed to the stream in a readable manner.) (DECLARE (GLOBALVARS NC.OrigReadTable)) (RESETLST (RESETSAVE (NCLOG.SingleArgDEFPRINT (LIST (QUOTE CardObject) (FUNCTION NCLOG.CardObjectDEFPRINTFn)))) (RESETSAVE (NCLOG.SingleArgDEFPRINT (LIST (QUOTE Link) (FUNCTION NCLOG.LinkDEFPRINTFn)))) (RESETSAVE (NCLOG.SingleArgDEFPRINT (LIST (QUOTE NoteFile) (FUNCTION NCLOG.NoteFileDEFPRINTFn)) )) (RESETSAVE (NCLOG.SingleArgDEFPRINT (LIST (QUOTE UID) (FUNCTION NCLOG.UIDDEFPRINTFn)))) (PRINT (BQUOTE (, EventType , EventTime , NoteFile ,@ EventArgs)) Stream NC.OrigReadTable)))) (NCLOG.WriteLogFileHeader (LAMBDA (LoggingStream NoteFile) (* rht: "18-Mar-87 16:00") (* * Write header info to the logging file for this notefile. Currently, this is just an event having type StartLogging.) (NCLOG.LogEvent (QUOTE StartLogging) NoteFile (AND (type? NoteFile NoteFile) (fetch (NoteFile FullFileName) of NoteFile))))) ) (* * Stuff to handle the printing of various NC objects.) (DEFINEQ (NCLOG.CardObjectDEFPRINTFn (LAMBDA (Card Stream) (* rht: "11-Mar-87 22:27") (* * This is called when PRINT, PRIN1, etc. try to print instance of Card datatype. Only meant to be used under NCLOG.WriteEventToLogStream.) (if (AND Stream (NEQ Stream (QUOTE T)) (NOT (IMAGESTREAMP Stream))) then (PRINT (fetch (Card UID) of Card) Stream NC.OrigReadTable) T else NIL))) (NCLOG.LinkDEFPRINTFn (LAMBDA (Link Stream) (* rht: "11-Mar-87 22:28") (* * This is called when PRINT, PRIN1, etc. try to print instance of Link datatype. Only meant to be used under NCLOG.WriteEventToLogStream.) (if (AND Stream (NEQ Stream (QUOTE T)) (NOT (IMAGESTREAMP Stream))) then (PRINT (fetch (Link UID) of Link) Stream NC.OrigReadTable) T else NIL))) (NCLOG.NoteFileDEFPRINTFn (LAMBDA (NoteFile Stream) (* rht: "11-Mar-87 22:28") (* * This is called when PRINT, PRIN1, etc. try to print instance of NoteFile datatype. Only meant to be used under NCLOG.WriteEventToLogStream.) (if (AND Stream (NEQ Stream (QUOTE T)) (NOT (IMAGESTREAMP Stream))) then (PRINT (fetch (NoteFile UID) of NoteFile) Stream NC.OrigReadTable) T else NIL))) (NCLOG.UIDDEFPRINTFn (LAMBDA (UID Stream) (* rht: "18-Mar-87 17:25") (* * This is called when PRINT, PRIN1, etc. try to print instance of UID datatype. Only meant to be used under NCLOG.WriteEventToLogStream.) (DECLARE (GLOBALVARS NC.OrigReadTable)) (if (AND Stream (NEQ Stream (QUOTE T)) (NOT (IMAGESTREAMP Stream))) then (LET ((NCLogInfo (CAR (NLSETQ (STKARG (QUOTE NCLogInfo) (QUOTE NCLOG.WriteEventToLogStream)))))) (if NCLogInfo then (pushnew (fetch (NCLogInfo NoticedUIDs) of NCLogInfo) UID))) (PRINT (NCLOG.NumFromUID UID) Stream NC.OrigReadTable) T else NIL))) (NCLOG.SingleArgDEFPRINT (LAMBDA (TypeAndFn) (* rht: "11-Mar-87 17:03") (* * An incredibly dorky hack to get around the brain-damaged way RESETLST works. Need this because though DEFPRINT returns the old value, it takes two args thus is unsuitable for RESETSAVE. UGH!) (LIST (CAR TypeAndFn) (DEFPRINT (CAR TypeAndFn) (CADR TypeAndFn))))) (NCLOG.NumFromUID (LAMBDA (UID) (* rht: "17-Mar-87 17:17") (* * Translate the UID into an integer using a global hash array. This is to save space on the logging file.) (DECLARE (GLOBALVARS NCLOG.UIDHashArray NCLOG.UIDCtr)) (OR (GETHASH UID NCLOG.UIDHashArray) (PUTHASH UID (add NCLOG.UIDCtr 1) NCLOG.UIDHashArray)))) (NCLOG.StringFromUID (LAMBDA (UID) (* rht: "11-Mar-87 15:59") (* * Return an atom made from the numbers making up UID separated by commas.) (CONCAT (QUOTE U) (ffetch (UID UID0) of UID) (QUOTE ,) (ffetch (UID UID1) of UID) (QUOTE ,) (ffetch (UID UID2) of UID) (QUOTE ,) (ffetch (UID UID3) of UID) (QUOTE ,) (ffetch (UID UID4) of UID) (QUOTE ,) (ffetch (UID UID5) of UID) (QUOTE ,) (ffetch (UID UID6) of UID)))) ) (* * Here's the advice for the functions that we want to monitor.) (* * Operations that happen to an open notefile.) (PUTPROPS NC.EditNoteCard READVICE (NIL (BEFORE NIL (NCLOG.LogEvent (QUOTE EditCard.Begin) (fetch (Card NoteFile) of Card) Card)) (AFTER NIL (NCLOG.LogEvent (QUOTE EditCard.End) (fetch (Card NoteFile) of Card) Card)))) (PUTPROPS NC.QuitCard READVICE [NIL [BEFORE NIL (LET ((Card (NC.CoerceToCard CardIdentifier))) (NCLOG.LogEvent (QUOTE QuitCard.Begin) (fetch (Card NoteFile) of Card) (LIST Card Don'tDeactivateFlg] (AFTER NIL (LET ((Card (NC.CoerceToCard CardIdentifier))) (NCLOG.LogEvent (QUOTE QuitCard.End) (fetch (Card NoteFile) of Card) (LIST Card Don'tDeactivateFlg]) (PUTPROPS NC.MakeNoteCard READVICE [NIL (BEFORE NIL (NCLOG.LogEvent (QUOTE MakeCard.Begin) NoteFile (LIST NoteCardType Title NoDisplayFlg))) (AFTER NIL (NCLOG.LogEvent (QUOTE MakeCard.End) NoteFile (LIST NoteCardType Title (NC.CoerceToCard !VALUE]) (PUTPROPS NC.DeleteNoteCardInternal READVICE (NIL (BEFORE NIL (NCLOG.LogEvent (QUOTE DelCard) (fetch (Card NoteFile) of Card) Card)))) (READVISE NC.EditNoteCard NC.QuitCard NC.MakeNoteCard NC.DeleteNoteCardInternal) (PUTPROPS NC.ActivateCard READVICE (NIL (BEFORE NIL (NCLOG.LogEvent (QUOTE CacheCard) (fetch (Card NoteFile) of Card) Card)))) (PUTPROPS NC.DeactivateCard READVICE (NIL (BEFORE NIL (NCLOG.LogEvent (QUOTE UncacheCard) (fetch (Card NoteFile) of Card) Card)))) (READVISE NC.ActivateCard NC.DeactivateCard) (PUTPROPS NC.CardSaveFn READVICE [NIL (BEFORE NIL (LET ((Card (NC.CoerceToCard WindowOrID))) (NCLOG.LogEvent (QUOTE SaveCard.Begin) (fetch (Card NoteFile) of Card) Card))) (AFTER NIL (LET ((Card (NC.CoerceToCard WindowOrID))) (NCLOG.LogEvent (QUOTE SaveCard.End) (fetch (Card NoteFile) of Card) Card]) (PUTPROPS NC.PutLinks READVICE (NIL (BEFORE NIL (NCLOG.LogEvent (QUOTE PutLinks) (fetch (Card NoteFile) of Card) Card)))) (PUTPROPS NC.PutMainCardData READVICE (NIL (BEFORE NIL (NCLOG.LogEvent (QUOTE PutMainCardData) (fetch (Card NoteFile) of Card) Card)))) (PUTPROPS NC.PutPropList READVICE (NIL (BEFORE NIL (NCLOG.LogEvent (QUOTE PutPropList) (fetch (Card NoteFile) of Card) Card)))) (PUTPROPS NC.PutTitle READVICE (NIL (BEFORE NIL (NCLOG.LogEvent (QUOTE PutTitle) (fetch (Card NoteFile) of Card) Card)))) (READVISE NC.CardSaveFn NC.PutLinks NC.PutMainCardData NC.PutPropList NC.PutTitle) (PUTPROPS NC.AssignTitle READVICE [NIL [BEFORE NIL (LET ((Card (NC.CoerceToCard CardIdentifier))) (NCLOG.LogEvent (QUOTE AssignTitle.Begin) (fetch (Card NoteFile) of Card) (LIST Card (NC.FetchTitle Card] (AFTER NIL (LET ((Card (NC.CoerceToCard CardIdentifier))) (NCLOG.LogEvent (QUOTE AssignTitle.End) (fetch (Card NoteFile) of Card) (LIST Card (NC.FetchTitle Card]) (READVISE NC.AssignTitle) (PUTPROPS NC.MakeLink READVICE [NIL (AFTER NIL (LET [(NoteFile (fetch (Card NoteFile) of (OR (NC.CoerceToCard SourceCard) (NC.CoerceToCard Window] (if (type? Link !VALUE) then (NCLOG.LogEvent (QUOTE MakeLink) NoteFile (LIST !VALUE (fetch (Link SourceCard) of !VALUE) (fetch (Link DestinationCard) of !VALUE) (fetch (Link Label) of !VALUE) (fetch (Link AnchorMode) of !VALUE) (fetch (Link DisplayMode) of !VALUE))) else (NCLOG.LogEvent (QUOTE MakeLink) NoteFile !VALUE]) (PUTPROPS NC.DelToLink READVICE (NIL (BEFORE NIL (NCLOG.LogEvent (QUOTE DelLink) (fetch (Card NoteFile) of (fetch (Link SourceCard) of Link)) Link)))) (READVISE NC.MakeLink NC.DelToLink) (PUTPROPS NC.UpdateBrowserCard READVICE [NIL (BEFORE NIL (LET ((Card (NC.CoerceToCard Window))) (NCLOG.LogEvent (QUOTE RecomputeBrowser.Begin) (fetch (Card NoteFile) of Card) Card))) (AFTER NIL (LET ((Card (NC.CoerceToCard Window))) (NCLOG.LogEvent (QUOTE RecomputeBrowser.End) (fetch (Card NoteFile) of Card) Card]) (PUTPROPS NC.RelayoutBrowserCard READVICE [NIL (BEFORE NIL (LET ((Card (NC.CoerceToCard Window))) (NCLOG.LogEvent (QUOTE RelayoutBrowser.Begin) (fetch (Card NoteFile) of Card) Card))) (AFTER NIL (LET ((Card (NC.CoerceToCard Window))) (NCLOG.LogEvent (QUOTE RelayoutBrowser.End) (fetch (Card NoteFile) of Card) Card]) (READVISE NC.UpdateBrowserCard NC.RelayoutBrowserCard) (* * Other operations.) (PUTPROPS NC.AddCardType READVICE (NIL (BEFORE NIL (NCLOG.LogEvent (QUOTE AddCardType) NIL TypeName)))) (READVISE NC.AddCardType) (PUTPROPS NCLOGGER COPYRIGHT ("Xerox Corporation" 1987)) (DECLARE: DONTCOPY (FILEMAP (NIL (3107 6684 (NCLOG.StartLogging 3117 . 4606) (NCLOG.StopLogging 4608 . 5960) ( NCLOG.SuspendLogging 5962 . 6348) (NCLOG.LoggingOnP 6350 . 6682)) (6712 10688 (NCLOG.FetchLogInfo 6722 . 7189) (NCLOG.SetLogInfo 7191 . 7680) (NCLOG.LogEvent 7682 . 9147) (NCLOG.WriteEventToLogStream 9149 . 10239) (NCLOG.WriteLogFileHeader 10241 . 10686)) (10753 14624 (NCLOG.CardObjectDEFPRINTFn 10763 . 11268) (NCLOG.LinkDEFPRINTFn 11270 . 11769) (NCLOG.NoteFileDEFPRINTFn 11771 . 12285) ( NCLOG.UIDDEFPRINTFn 12287 . 13079) (NCLOG.SingleArgDEFPRINT 13081 . 13523) (NCLOG.NumFromUID 13525 . 13956) (NCLOG.StringFromUID 13958 . 14622))))) STOP