(FILECREATED " 2-Jul-87 00:44:45" {ICE}<KOOMEN>LISPUSERS>KOTO>VSTATS.;9 66072  

      changes to:  (FNS VStatsOptions-Inspect VStatsSpace-InitDisk)

      previous date: "19-Jun-87 01:54:50" {ICE}<KOOMEN>LISPUSERS>KOTO>VSTATS.;8)


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

(PRETTYCOMPRINT VSTATSCOMS)

(RPAQQ VSTATSCOMS [(* * User interface * *)
		     (FNS VSTATS)
		     (INITVARS (VSTATS.ALWAYS? NIL)
			       (VSTATS.BLACK? NIL)
			       (VSTATS.CLOCK.INTERVAL 1)
			       (VSTATS.MUTIL.HYSTERESIS 20)
			       (VSTATS.MUTIL.INTERVAL 1)
			       (VSTATS.POSITION (create POSITION XCOORD ← SCREENWIDTH YCOORD ← 
							SCREENHEIGHT))
			       (VSTATS.SPACE.INTERVAL 300)
			       (VSTATS.SPACE.PANIC.LEVEL 95)
			       (VSTATS.SPACE.SHOW.DISK? T))
		     (* * VSTATS support stuff * *)
		     (LOCALVARS . T)
		     (FILES (SYSLOAD FROM LISPUSERS)
			    READNUMBER)
		     [DECLARE: EVAL@COMPILE DONTCOPY (FILES (SOURCE)
							    EXPORTS.ALL)
			       (GLOBALVARS \TimeZoneComp \BeginDST \EndDST \DayLightSavings 
					   TIME.ZONES)
			       (CONSTANTS (\4YearsDays (ADD1 (ITIMES 365 4]
		     (COMS (DECLARE: DONTCOPY (MACROS HALF)
				     (RECORDS VSTATSPCTINFO VSTATSTIMERINFO))
			   (INITRECORDS VSTATSPCTINFO VSTATSTIMERINFO))
		     [INITVARS (VStatsOff? T)
			       (VStatsWindow)
			       (VStatsDsp)
			       (VStatsCurrentTime (SETUPTIMER 0 NIL (QUOTE TICKS]
		     (FNS VStats-CenterRegion VStats-CreatePCTs VStats-Display VStats-DisplayPct 
			  VStats-DrawLine VStats-GetPCTsRegion VStats-Init VStats-InitInterval 
			  VStats-MouseWait VStats-ReDisplay? VStats-SetDisplayColor VStats-SetUpTimer 
			  VStats-TimerExpired? VStats-Percentage)
		     (* * option support stuff * *)
		     (INITVARS (VStatsOptionsWindow))
		     (FNS VStatsOptions-Inspect VStatsOptions-FetchFn VStatsOptions-PropCommandFn 
			  VStatsOptions-PropPrintFn VStatsOptions-PropertiesFn VStatsOptions-RNumber 
			  VStatsOptions-SelectionFn VStatsOptions-StoreFn 
			  VStatsOptions-ValueCommandFn)
		     (* * clock support stuff * *)
		     (INITVARS (VStatsClockFont)
			       (VStatsClockReset?)
			       (VStatsClockTimer))
		     (FNS VStatsClock-Display VStatsClock-DisplayDigits VStatsClock-DisplayMonth 
			  VStatsClock-Init VStatsClock-ReDisplay VStatsClock-Read VStatsClock-Ticks? 
			  VStatsClock-UnpackDate)
		     (* * space support stuff * *)
		     (INITVARS (VStatsSpaceDiskPages)
			       (VStatsSpaceFont)
			       (VStatsSpacePCTs)
			       (VStatsSpaceTimer))
		     (INITVARS (\LASTVMEMFILEPAGE 16383))
		     (FNS VStatsSpace-Display VStatsSpace-Init VStatsSpace-InitDisk 
			  VStatsSpace-InitPanicLevel VStatsSpace-ReDisplay VStatsSpace-Read 
			  VStatsSpace-ShrinkInterval VStatsSpace-Ticks?)
		     (* * machine utilization support stuff * *)
		     (INITVARS (VStatsMUtilFont)
			       (VStatsMUtilOrigState)
			       (VStatsMUtilPCTs)
			       (VStatsMUtilTimer))
		     (FNS VStatsMUtil-Display VStatsMUtil-Init VStatsMUtil-InitState 
			  VStatsMUtil-ReDisplay VStatsMUtil-Read VStatsMUtil-Ticks?)
		     (* * These ought to be system functions!!! * *)
		     (FNS CLOCKTICKS ALTOPARTITIONS DISKUSEDPAGES DISKTOTALPAGES)
		     (* Lisp before Lute version does not have a TOPWP function to test if window is 
			on top)
		     (FNS VStats-TOPWP)
		     (P (MOVD? (QUOTE VStats-TOPWP)
			       (QUOTE TOPWP)))
		     (* * Initialize on LOAD * *)
		     (VARS (BackgroundMenu))
		     (ADDVARS (BackgroundMenuCommands ("VStats" (QUOTE (VSTATS (QUOTE On)))
								
					      "Running display of clock and/or space utilization")))
		     (DECLARE: DONTEVAL@LOAD DOCOPY (P (COND ((OR VSTATS.CLOCK.INTERVAL 
								  VSTATS.SPACE.INTERVAL 
								  VSTATS.MUTIL.INTERVAL)
							      (VSTATS (QUOTE ON])
(* * User interface * *)

(DEFINEQ

(VSTATS
  [LAMBDA (on/off)                                           (* Koomen "19-Jun-87 01:11")
    (DECLARE (GLOBALVARS AFTERSYSOUTFORMS BACKGROUNDFNS VStatsDsp VStatsOff? VStatsWindow))
    (if (WINDOWP VStatsWindow)
	then (CLOSEW VStatsWindow))
    (if (WINDOWP VStatsOptionsWindow)
	then (CLOSEW VStatsOptionsWindow))
    (SETQ on/off (AND (LITATOM on/off)
			  (U-CASE on/off)))
    [SETQ VStatsOff? (OR (NULL on/off)
			     (EQ on/off (QUOTE OFF]
    (if (NOT VStatsOff?)
	then (if (NOT (VStats-Init))
		   then (VStatsOptions-Inspect)
			  (SETQ VStatsOff? T)))
    (LET [(BackGroundFn (FUNCTION VStats-ReDisplay?))
	  (AfterSysoutForm (QUOTE (VSTATS T]
         (if VStatsOff?
	     then (SETQ VStatsOptionsWindow)
		    (SETQ VStatsWindow (SETQ VStatsDsp))
		    (SETQ BACKGROUNDFNS (REMOVE BackGroundFn BACKGROUNDFNS))
		    (SETQ AFTERSYSOUTFORMS (REMOVE AfterSysoutForm AFTERSYSOUTFORMS))
		    (QUOTE Off)
	   else (VStats-Display)
		  (OR (MEMBER BackGroundFn BACKGROUNDFNS)
			(push BACKGROUNDFNS BackGroundFn))
		  (OR (MEMBER AfterSysoutForm AFTERSYSOUTFORMS)
			(push AFTERSYSOUTFORMS AfterSysoutForm))
		  (QUOTE On])
)

(RPAQ? VSTATS.ALWAYS? NIL)

(RPAQ? VSTATS.BLACK? NIL)

(RPAQ? VSTATS.CLOCK.INTERVAL 1)

(RPAQ? VSTATS.MUTIL.HYSTERESIS 20)

(RPAQ? VSTATS.MUTIL.INTERVAL 1)

(RPAQ? VSTATS.POSITION (create POSITION XCOORD ← SCREENWIDTH YCOORD ← SCREENHEIGHT))

(RPAQ? VSTATS.SPACE.INTERVAL 300)

(RPAQ? VSTATS.SPACE.PANIC.LEVEL 95)

(RPAQ? VSTATS.SPACE.SHOW.DISK? T)
(* * VSTATS support stuff * *)

(DECLARE: DOEVAL@COMPILE DONTCOPY

(LOCALVARS . T)
)
(FILESLOAD (SYSLOAD FROM LISPUSERS)
	   READNUMBER)
(DECLARE: EVAL@COMPILE DONTCOPY 
(FILESLOAD (SOURCE)
	   EXPORTS.ALL)

(DECLARE: DOEVAL@COMPILE DONTCOPY

(GLOBALVARS \TimeZoneComp \BeginDST \EndDST \DayLightSavings TIME.ZONES)
)

(DECLARE: EVAL@COMPILE 

(RPAQ \4YearsDays (ADD1 (ITIMES 365 4)))

[CONSTANTS (\4YearsDays (ADD1 (ITIMES 365 4]
)
)
(DECLARE: DONTCOPY 
(DECLARE: EVAL@COMPILE 
(DEFMACRO HALF (X)
	  (BQUOTE (LRSH (\, X)
			1)))
)

[DECLARE: EVAL@COMPILE 

(RECORD VSTATSPCTINFO (NAME LABEL NEWPCT OLDPCT LBLREGION BARREGION MAXBARHEIGHT))

(RECORD VSTATSTIMERINFO (INTERVAL TIMER LASTSETUP)
			  INTERVAL ← 0 TIMER ← (SETUPTIMER 0 NIL (QUOTE TICKS))
			  LASTSETUP ← (SETUPTIMER 0 NIL (QUOTE TICKS)))
]
)

(RPAQ? VStatsOff? T)

(RPAQ? VStatsWindow )

(RPAQ? VStatsDsp )

(RPAQ? VStatsCurrentTime (SETUPTIMER 0 NIL (QUOTE TICKS)))
(DEFINEQ

(VStats-CenterRegion
  [LAMBDA (region width bottom pctlist)                      (* Koomen "12-Jan-87 17:37")
    (PROG [(delta (HALF (IDIFFERENCE width (fetch (REGION WIDTH) of region]
	    (replace (REGION LEFT) of region with delta)
	    (replace (REGION BOTTOM) of region with bottom)
	    (for pct in pctlist bind (r)
	       do (SETQ r (fetch (VSTATSPCTINFO BARREGION) of pct))
		    (replace (REGION LEFT) of r with (IPLUS delta (fetch (REGION LEFT)
									     of r)))
		    (replace (REGION BOTTOM) of r with bottom)
		    (SETQ r (fetch (VSTATSPCTINFO LBLREGION) of pct))
		    (replace (REGION LEFT) of r with (IPLUS delta (fetch (REGION LEFT)
									     of r)))
		    (replace (REGION BOTTOM) of r with bottom])

(VStats-CreatePCTs
  [LAMBDA (font names&labels)                                (* Koomen "12-Jan-87 17:38")
    (PROG [pctlist (lblwidths 0)
		     (lblheight (ITIMES 2 (FONTHEIGHT font)))
		     (barwidth (STRINGWIDTH "A" font))
		     (barheight (IPLUS (FONTHEIGHT font)
					 (FONTPROP font (QUOTE ASCENT]
	    (SETQ pctlist
	      (for name&lbl in names&labels bind (name lbl lblwidth)
		 collect (SETQ name (CAR name&lbl))
			   (SETQ lbl (CDR name&lbl))
			   (SETQ lblwidth (STRINGWIDTH lbl font))
			   (SETQ lblwidths (IPLUS lblwidths lblwidth))
			   (create VSTATSPCTINFO
				     NAME ← name
				     LABEL ← lbl
				     NEWPCT ← 0
				     OLDPCT ← 0
				     LBLREGION ←
				     (create REGION
					       LEFT ← 0
					       BOTTOM ← 0
					       WIDTH ← lblwidth
					       HEIGHT ← lblheight)
				     BARREGION ←
				     (create REGION
					       LEFT ← 0
					       BOTTOM ← 0
					       WIDTH ← 0
					       HEIGHT ← barheight)
				     MAXBARHEIGHT ← barheight)))
	    [for pct in pctlist bind (r w x)
	       first (SETQ w (HALF (ITIMES 3 barwidth)))
		       (SETQ x (IDIFFERENCE w barwidth))
	       do (SETQ r (fetch (VSTATSPCTINFO BARREGION) of pct))
		    (replace (REGION LEFT) of r with x)
		    (replace (REGION WIDTH) of r with barwidth)
		    (SETQ r (fetch (VSTATSPCTINFO LBLREGION) of pct))
		    (replace (REGION LEFT) of r with (IPLUS x w))
		    (SETQ x (IPLUS w (fetch (REGION RIGHT) of r]
	    (RETURN pctlist])

(VStats-Display
  [LAMBDA (ThruMouse?)                                       (* Koomen "16-Apr-87 16:53")
    (DECLARE (GLOBALVARS VStatsClockRegion VStatsClockTimer VStatsMUtilRegion VStatsMUtilTimer 
			     VStatsSpaceRegion VStatsSpaceTimer VStatsWindow))
    (PROG (r1 r2 r3)
	    (if ThruMouse?
		then (if (NOT (VStats-MouseWait VStatsWindow))
			   then (RETURN)))
	    (DSPFILL NIL NIL NIL VStatsDsp)
	    (if (SETQ r1 VStatsClockRegion)
		then (VStats-SetUpTimer VStatsClockTimer)
		       (VStatsClock-Display))
	    (if (SETQ r2 VStatsSpaceRegion)
		then (VStats-SetUpTimer VStatsSpaceTimer)
		       (VStatsSpace-Display))
	    (if (SETQ r3 VStatsMUtilRegion)
		then (VStats-SetUpTimer VStatsMUtilTimer)
		       (VStatsMUtil-Display))
	    (if (AND r1 r2 r3)
		then (VStats-DrawLine r1 r2)
		       (VStats-DrawLine r2 r3)
	      elseif (AND r1 r2)
		then (VStats-DrawLine r1 r2)
	      elseif (AND r1 r3)
		then (VStats-DrawLine r1 r3)
	      elseif (AND r2 r3)
		then (VStats-DrawLine r2 r3])

(VStats-DisplayPct
  [LAMBDA (PCT BOX.ALWAYS?)                                  (* Koomen "12-Jan-87 17:24")
    (DECLARE (GLOBALVARS BLACKSHADE VSTATS.BLACK? VStatsDsp WHITESHADE))
    (PROG ((shade (if VSTATS.BLACK?
			then WHITESHADE
		      else BLACKSHADE))
	     (oldpct (fetch (VSTATSPCTINFO OLDPCT) of PCT))
	     (newpct (fetch (VSTATSPCTINFO NEWPCT) of PCT))
	     (lblregion (fetch (VSTATSPCTINFO LBLREGION) of PCT))
	     (barregion (fetch (VSTATSPCTINFO BARREGION) of PCT))
	     (maxbarheight (fetch (VSTATSPCTINFO MAXBARHEIGHT) of PCT)))

          (* * Print percentage as d.dd * *)


	    (MOVETO (fetch (REGION LEFT) of lblregion)
		      (fetch (REGION BOTTOM) of lblregion)
		      VStatsDsp)
	    (BOUT VStatsDsp (IPLUS (IQUOTIENT newpct 100)
				       (CHARCODE "0")))
	    (BOUT VStatsDsp (CHARCODE "."))
	    (BOUT VStatsDsp (IPLUS (IQUOTIENT (IREMAINDER newpct 100)
						    10)
				       (CHARCODE "0")))
	    (BOUT VStatsDsp (IPLUS (IREMAINDER newpct 10)
				       (CHARCODE "0")))

          (* * Display percentage graphically in box * *)


	    (replace (REGION HEIGHT) of barregion with (IQUOTIENT (ITIMES newpct 
										    maxbarheight)
									  100))
	    (if (OR BOX.ALWAYS? (ILESSP newpct oldpct))
		then (GRAYBOXAREA (fetch (REGION LEFT) of barregion)
				      (fetch (REGION BOTTOM) of barregion)
				      (fetch (REGION WIDTH) of barregion)
				      maxbarheight 1 shade VStatsDsp))
	    (DSPFILL barregion shade NIL VStatsDsp])

(VStats-DrawLine
  [LAMBDA (hiregion loregion)                                (* Koomen "12-Jan-87 17:38")
    (DECLARE (GLOBALVARS VStatsDsp))
    (PROG [(x1 (DSPLEFTMARGIN NIL VStatsDsp))
	     (x2 (DSPRIGHTMARGIN NIL VStatsDsp))
	     (y (SUB1 (HALF (IPLUS (fetch (REGION BOTTOM) of hiregion)
				       (fetch (REGION TOP) of loregion]
	    (DRAWLINE x1 y x2 y 2 (QUOTE INVERT)
			VStatsDsp])

(VStats-GetPCTsRegion
  [LAMBDA (pctlist)                                          (* Koomen "12-Jan-87 17:34")
    (DECLARE (GLOBALVARS SCREENWIDTH))
    (for pct in pctlist bind barregion lblregion (minleft ← SCREENWIDTH)
				   (maxright ← 0)
				   (maxheight ← 0)
       do (SETQ barregion (fetch (VSTATSPCTINFO BARREGION) of pct))
	    (SETQ lblregion (fetch (VSTATSPCTINFO LBLREGION) of pct))
	    [SETQ minleft (IMIN minleft (IMIN (fetch (REGION LEFT) of barregion)
						    (fetch (REGION LEFT) of lblregion]
	    [SETQ maxright (IMAX maxright (IMAX (fetch (REGION RIGHT) of barregion)
						      (fetch (REGION RIGHT) of lblregion]
	    [SETQ maxheight (IMAX maxheight (IMAX (fetch (REGION HEIGHT) of barregion)
							(fetch (REGION HEIGHT) of lblregion]
       finally (RETURN (create REGION
				     LEFT ← 0
				     BOTTOM ← 0
				     WIDTH ← (ADD1 (IDIFFERENCE maxright minleft))
				     HEIGHT ← maxheight])

(VStats-Init
  [LAMBDA NIL                                                (* Koomen "19-Jun-87 00:58")
    (DECLARE (GLOBALVARS LASTMOUSEBUTTONS SCREENHEIGHT SCREENWIDTH VSTATS.POSITION 
			     VStatsClockRegion VStatsDsp VStatsMUtilPCTs VStatsMUtilRegion VStatsOff? 
			     VStatsSpacePCTs VStatsSpaceRegion VStatsWindow WBorder))
    (PROG [clockwidth clockheight spacewidth spaceheight mutilwidth mutilheight wleft wbottom 
			wwidth wheight wposition wregion (width 0)
			(height 0)
			(bottom 0)
			(border WBorder)
			(spacing (HALF (ITIMES 3 WBorder]
	    (if (VStatsClock-Init)
		then (SETQ clockwidth (fetch (REGION WIDTH) of VStatsClockRegion))
		       (SETQ width (IMAX width clockwidth))
		       (SETQ clockheight (fetch (REGION HEIGHT) of VStatsClockRegion))
		       (SETQ height (IPLUS height clockheight spacing)))
	    (if (VStatsSpace-Init)
		then (SETQ spacewidth (fetch (REGION WIDTH) of VStatsSpaceRegion))
		       (SETQ width (IMAX width spacewidth))
		       (SETQ spaceheight (fetch (REGION HEIGHT) of VStatsSpaceRegion))
		       (SETQ height (IPLUS height spaceheight spacing)))
	    (if (VStatsMUtil-Init)
		then (SETQ mutilwidth (fetch (REGION WIDTH) of VStatsMUtilRegion))
		       (SETQ width (IMAX width mutilwidth))
		       (SETQ mutilheight (fetch (REGION HEIGHT) of VStatsMUtilRegion))
		       (SETQ height (IPLUS height mutilheight spacing)))
	    (if (ZEROP width)
		then (RETURN))
	    (SETQ width (IPLUS width spacing))
	    (SETQ wwidth (WIDTHIFWINDOW width border))
	    (SETQ wheight (HEIGHTIFWINDOW height NIL border))
	    (SETQ wposition (OR (POSITIONP VSTATS.POSITION)
				    (GETBOXPOSITION wwidth wheight NIL NIL NIL 
						      "Indicate placement of VSTATS window:")))
	    [SETQ wleft (IMAX 0 (IMIN (fetch (POSITION XCOORD) of wposition)
					    (IDIFFERENCE SCREENWIDTH (ADD1 wwidth]
	    [SETQ wbottom (IMAX 0 (IMIN (fetch (POSITION YCOORD) of wposition)
					      (IDIFFERENCE SCREENHEIGHT (ADD1 wheight]
	    (if (NOT (POSITIONP VSTATS.POSITION))
		then (SETQ VSTATS.POSITION (create POSITION
							 XCOORD ← wleft
							 YCOORD ← wbottom)))
	    (SETQ wregion (create REGION
				      LEFT ← wleft
				      BOTTOM ← wbottom
				      WIDTH ← wwidth
				      HEIGHT ← wheight))
	    (SETQ VStatsWindow (CREATEW wregion NIL border))
	    (SETQ VStatsDsp (WINDOWPROP VStatsWindow (QUOTE DSP)))
	    (VStats-SetDisplayColor)
	    (SETQ bottom (IQUOTIENT spacing 4))
	    (if VStatsMUtilRegion
		then (VStats-CenterRegion VStatsMUtilRegion width bottom VStatsMUtilPCTs)
		       (SETQ bottom (IPLUS bottom mutilheight spacing)))
	    (if VStatsSpaceRegion
		then (VStats-CenterRegion VStatsSpaceRegion width bottom VStatsSpacePCTs)
		       (SETQ bottom (IPLUS bottom spaceheight spacing)))
	    (if VStatsClockRegion
		then (VStats-CenterRegion VStatsClockRegion width bottom)
		       (SETQ bottom (IPLUS bottom clockheight spacing)))
	    [WINDOWPROP VStatsWindow (QUOTE REPAINTFN)
			  (FUNCTION (LAMBDA (w)
			      (VStats-Display]
	    [WINDOWPROP VStatsWindow (QUOTE CLOSEFN)
			  (FUNCTION (LAMBDA (w)
			      (DECLARE (GLOBALVARS VStatsOff?))
			      (SETQ VStatsOff? T]
	    [WINDOWPROP VStatsWindow (QUOTE AFTERMOVEFN)
			  (FUNCTION (LAMBDA (w)
			      (DECLARE (GLOBALVARS VSTATS.POSITION))
			      (PROG ((r (WINDOWREGION w)))
				      (SETQ VSTATS.POSITION (create POSITION
									XCOORD ←
									(fetch (REGION LEFT)
									   of r)
									YCOORD ←
									(fetch (REGION BOTTOM)
									   of r]
	    [WINDOWPROP VStatsWindow (QUOTE BUTTONEVENTFN)
			  (FUNCTION (LAMBDA (w)
			      (if (LASTMOUSESTATE (ONLY LEFT))
				  then (VStats-Display T)
				elseif (LASTMOUSESTATE (ONLY MIDDLE))
				  then (VStatsOptions-Inspect T]
	    (WINDOWPROP VStatsWindow (QUOTE SHRINKFN)
			  (QUOTE DON'T))
	    (WINDOWPROP VStatsWindow (QUOTE RESHAPEFN)
			  (QUOTE DON'T))
	    (RETURN T])

(VStats-InitInterval
  [LAMBDA (VSTATSTIMER INTERVAL MAXINTERVAL)                 (* HaKo "12-Jun-86 22:45")

          (* * If Interval is a positive number, initialize the timer with the corresponding number of clock ticks and return
	  it, otherwise return NIL)


    (if (AND (NUMBERP INTERVAL)
		 (GREATERP INTERVAL 0))
	then (replace (VSTATSTIMERINFO INTERVAL) of VSTATSTIMER
		  with (CLOCKTICKS (MAX 1 (MIN INTERVAL MAXINTERVAL))
				       (QUOTE SECONDS])

(VStats-MouseWait
  [LAMBDA (WINDOW)                                           (* Koomen "16-Apr-87 16:59")
                                                             (* ;; 
							     
"Wait until the mouse buttons are up or mouse out of the window.  Return T if mouse is still in the window")
                                                             (* ;; "DISABLED!!!")
    (OR T (bind (REGION ← (WINDOWREGION WINDOW)) do (if (NOT (INSIDEP REGION 
										      LASTMOUSEX 
										      LASTMOUSEY))
								  then (RETURN)
								elseif (MOUSESTATE UP)
								  then (RETURN T])

(VStats-ReDisplay?
  [LAMBDA NIL                                                (* HaKo " 4-Apr-86 16:12")
    (DECLARE (GLOBALVARS VStatsClockRegion VStatsClockTimer VStatsMUtilRegion VStatsMUtilTimer 
			     VStatsOff? VStatsSpaceRegion VStatsSpaceTimer))
    (if VStatsOff?
	then (VSTATS (QUOTE Off))
      else (if VStatsClockRegion
		 then (if (VStats-TimerExpired? VStatsClockTimer)
			    then (VStatsClock-ReDisplay)))
	     (if VStatsSpaceRegion
		 then (if (VStats-TimerExpired? VStatsSpaceTimer)
			    then (VStatsSpace-ReDisplay)))
	     (if VStatsMUtilRegion
		 then (if (VStats-TimerExpired? VStatsMUtilTimer)
			    then (VStatsMUtil-ReDisplay])

(VStats-SetDisplayColor
  [LAMBDA NIL                                                (* HaKo " 2-Jul-86 16:01")
    (DECLARE (GLOBALVARS BLACKSHADE VSTATS.BLACK? VStatsDsp WHITESHADE))
    (if VStatsDsp
	then (if VSTATS.BLACK?
		   then (DSPTEXTURE BLACKSHADE VStatsDsp)
			  (DSPSOURCETYPE (QUOTE INVERT)
					   VStatsDsp)
		 else (DSPTEXTURE WHITESHADE VStatsDsp)
			(DSPSOURCETYPE (QUOTE INPUT)
					 VStatsDsp])

(VStats-SetUpTimer
  [LAMBDA (TIMERINFO)                                        (* HaKo "15-Jan-86 16:51")
    (\RCLK (fetch (VSTATSTIMERINFO LASTSETUP) of TIMERINFO))
    (SETUPTIMER (fetch (VSTATSTIMERINFO INTERVAL) of TIMERINFO)
		  (fetch (VSTATSTIMERINFO TIMER) of TIMERINFO)
		  (QUOTE TICKS])

(VStats-TimerExpired?
  [LAMBDA (TIMERINFO)                                        (* HaKo "15-Jan-86 17:06")

          (* * Knowing the last time the timer was set allows us to test for wrap around. Using the standard TIMEREXPIRED? 
	  the timer could be set at some big positive number (say MAX.FIXP -
	  100), If we don't get to check the machine clock between the timer's value and the largest positive number the 
	  machine clock will wrap around to some big negative number (say MAX.FIXP + 100) and it will be quite a while before
	  the machine clock is again GREATERP than our timer!)


    (DECLARE (GLOBALVARS VStatsCurrentTime))
    (\RCLK VStatsCurrentTime)
    (if (OR (IGREATERP VStatsCurrentTime (fetch (VSTATSTIMERINFO TIMER) of TIMERINFO))
		(ILESSP VStatsCurrentTime (fetch (VSTATSTIMERINFO LASTSETUP) of TIMERINFO)))
	then (VStats-SetUpTimer TIMERINFO])

(VStats-Percentage
  [LAMBDA (X Y)                                              (* Koomen "24-Mar-87 15:45")
                                                             (* ;; 
							     
"Desperately tries to use SMALLP's and avoid doing IQUOTIENT's or creating FIXP's or FLOATP's.")
    (if (ILEQ X 0)
	then 0
      elseif (IGEQ X Y)
	then 100
      else (PROG (Z)
		     (if (IGREATERP Y (CONSTANT (LRSH MAX.SMALLP 1)))
			 then (SETQ Y (IQUOTIENT Y 100))
		       elseif (ILEQ X (CONSTANT (IQUOTIENT MAX.SMALLP 200)))
			 then (RETURN (IQUOTIENT (IPLUS (ITIMES X 200)
								Y)
						       (LLSH Y 1)))
		       elseif [AND (IGREATERP X (LRSH Y 1))
				       (ILEQ (SETQ Z (IDIFFERENCE Y X))
					       (CONSTANT (IQUOTIENT MAX.SMALLP 200]
			 then [RETURN (IDIFFERENCE 100 (IQUOTIENT (IPLUS (ITIMES Z 200)
										   Y)
									  (LLSH Y 1]
		       else (SETQ Z (IQUOTIENT MAX.SMALLP Y))
			      (SETQ X (ITIMES Z X))
			      (SETQ Y (IQUOTIENT (ITIMES Z Y)
						     100)))
		     (RETURN (IQUOTIENT (IPLUS X (LRSH Y 1))
					    Y])
)
(* * option support stuff * *)


(RPAQ? VStatsOptionsWindow )
(DEFINEQ

(VStatsOptions-Inspect
  [LAMBDA (ThruMouse?)                                       (* Koomen " 2-Jul-87 00:43")
    (DECLARE (GLOBALVARS LASTMOUSEBUTTONS LASTMOUSEX LASTMOUSEY VStatsOptionsWindow VStatsWindow))
    (PROG [(OPTIONS (QUOTE (VSTATS.BLACK? VSTATS.ALWAYS? VSTATS.SPACE.SHOW.DISK? 
					      VSTATS.MUTIL.HYSTERESIS VSTATS.SPACE.PANIC.LEVEL 
					      VSTATS.CLOCK.INTERVAL VSTATS.SPACE.INTERVAL 
					      VSTATS.MUTIL.INTERVAL]
	    (if ThruMouse?
		then (if (NOT (VStats-MouseWait VStatsWindow))
			   then (RETURN)))
	    (if (WINDOWP VStatsOptionsWindow)
		then (MOVEW VStatsOptionsWindow LASTMOUSEX LASTMOUSEY)
		       (MOVEW VStatsOptionsWindow)
		       (INSPECTW.REDISPLAY VStatsOptionsWindow OPTIONS)
	      else (SETQ VStatsOptionsWindow (INSPECTW.CREATE OPTIONS (FUNCTION 
								      VStatsOptions-PropertiesFn)
								    (FUNCTION VStatsOptions-FetchFn)
								    (FUNCTION VStatsOptions-StoreFn)
								    (FUNCTION 
								      VStatsOptions-PropCommandFn)
								    (FUNCTION 
								     VStatsOptions-ValueCommandFn)
								    (AND NIL
									   (FUNCTION TitleCommandFn)
									   )
								    "VStats Options"
								    (FUNCTION 
								      VStatsOptions-SelectionFn)
								    (AND NIL (QUOTE Where))
								    (FUNCTION 
								      VStatsOptions-PropPrintFn])

(VStatsOptions-FetchFn
  [LAMBDA (OPTIONS OPTION)                                   (* Koomen "19-Jun-87 01:01")
    (DECLARE (GLOBALVARS VSTATS.ALWAYS? VSTATS.BLACK? VSTATS.MUTIL.HYSTERESIS 
			     VSTATS.SPACE.SHOW.DISK? VStatsWindow))
    (SELECTQ OPTION
	       [VSTATS.POSITION (if (WINDOWP VStatsWindow)
				    then (LET ((R (WINDOWREGION VStatsWindow)))
					        (create POSITION
							  XCOORD ← (fetch (REGION LEFT)
									of R)
							  YCOORD ← (fetch (REGION BOTTOM)
									of R]
	       (VSTATS.ALWAYS? (if VSTATS.ALWAYS?
				   then (QUOTE Yes)
				 else (QUOTE No)))
	       (VSTATS.BLACK? (if VSTATS.BLACK?
				  then (QUOTE Inverted)
				else (QUOTE Normal)))
	       (VSTATS.CLOCK.INTERVAL (if (VStatsClock-Ticks?)
					  then VSTATS.CLOCK.INTERVAL
					else (QUOTE Disabled)))
	       (VSTATS.SPACE.INTERVAL (if (VStatsSpace-Ticks?)
					  then VSTATS.SPACE.INTERVAL
					else (QUOTE Disabled)))
	       [VSTATS.SPACE.SHOW.DISK? (if (NULL VStatsSpaceDisk)
					    then (QUOTE Disabled)
					  else (OR (FILENAMEFIELD VStatsSpaceDisk (QUOTE
									  DIRECTORY))
						       (FILENAMEFIELD VStatsSpaceDisk (QUOTE
									  HOST]
	       [VSTATS.SPACE.PANIC.LEVEL (LET ((pct (VStatsSpace-InitPanicLevel)))
					      (if pct
						  then pct
						else (QUOTE Disabled]
	       (VSTATS.MUTIL.INTERVAL (if (VStatsMUtil-Ticks?)
					  then VSTATS.MUTIL.INTERVAL
					else (QUOTE Disabled)))
	       (VSTATS.MUTIL.HYSTERESIS (if (AND (NUMBERP VSTATS.MUTIL.HYSTERESIS)
						     (GREATERP VSTATS.MUTIL.HYSTERESIS 0))
					    then VSTATS.MUTIL.HYSTERESIS
					  else (QUOTE Cumulative)))
	       (ERROR "Unknown VStats option: " OPTION])

(VStatsOptions-PropCommandFn
  [LAMBDA (OPTION OPTIONS WINDOW)                            (* HaKo " 2-Jul-86 14:00")
    (PROMPTPRINT (SELECTQ OPTION
			      (VSTATS.ALWAYS? 
				 "Update VStats window even if partially or completely occluded.")
			      (VSTATS.BLACK? "Display VStats window in inverse video.")
			      (VSTATS.CLOCK.INTERVAL 
				     "Number of seconds between clock updates. Disabled if <= 0.")
			      (VSTATS.SPACE.INTERVAL 
			 "Number of seconds between space utilization updates. Disabled if <= 0.")
			      (VSTATS.SPACE.SHOW.DISK? "Display percentage of local disk space used.")
			      (VSTATS.SPACE.PANIC.LEVEL 
	    "Percentage at which VStats window will start flashing `out of space soon' warnings.")
			      (VSTATS.MUTIL.INTERVAL 
		       "Number of seconds between machine utilization updates. Disabled if <= 0.")
			      (VSTATS.MUTIL.HYSTERESIS 
"Number of intervals over which machine utilization will be averaged.  Cumulative average used if <= 0."
						       )
			      (VSTATS.POSITION "Position of VStats window.")
			      (ERROR "Unknown VStats option: " OPTION])

(VStatsOptions-PropPrintFn
  [LAMBDA (OPTION OPTIONS)                                   (* HaKo " 3-Jul-86 08:45")
    (SELECTQ OPTION
	       (VSTATS.ALWAYS? (QUOTE Update.Always?))
	       (VSTATS.BLACK? (QUOTE Display.Color))
	       (VSTATS.CLOCK.INTERVAL (QUOTE Clock.Update.Interval))
	       (VSTATS.SPACE.INTERVAL (QUOTE Space.Update.Interval))
	       (VSTATS.SPACE.SHOW.DISK? (QUOTE Show.Disk.Space?))
	       (VSTATS.SPACE.PANIC.LEVEL (QUOTE Space.Panic.Level))
	       (VSTATS.MUTIL.INTERVAL (QUOTE MUtil.Update.Interval))
	       (VSTATS.MUTIL.HYSTERESIS (QUOTE MUtil.Hysteresis))
	       (VSTATS.POSITION (QUOTE Window.Position))
	       (ERROR "Unknown VSTATS option: " OPTION])

(VStatsOptions-PropertiesFn
  [LAMBDA (OPTIONS)                                          (* HaKo "25-Jun-86 17:30")
    OPTIONS])

(VStatsOptions-RNumber
  [LAMBDA (LABEL FLOAT? NOTNUMVAL NOTPOSVAL)                 (* HaKo " 2-Jul-86 15:33")
    (LET ((N (RNUMBER LABEL NIL NIL NIL T FLOAT?)))
         (if (NOT (NUMBERP N))
	     then NOTNUMVAL
	   elseif (GREATERP N 0)
	     then N
	   else NOTPOSVAL])

(VStatsOptions-SelectionFn
  [LAMBDA (OPTION VALUE? WINDOW)                             (* HaKo " 2-Jul-86 14:10")
    (if (NOT VALUE?)
	then (VStatsOptions-PropCommandFn OPTION NIL WINDOW])

(VStatsOptions-StoreFn
  [LAMBDA (OPTIONS OPTION NEWVALUE)                          (* Koomen "18-Jun-87 22:54")
    (DECLARE (GLOBALVARS VSTATS.ALWAYS? VSTATS.BLACK? VSTATS.CLOCK.INTERVAL 
			     VSTATS.MUTIL.HYSTERESIS VSTATS.MUTIL.INTERVAL VSTATS.POSITION 
			     VSTATS.SPACE.INTERVAL VSTATS.SPACE.PANIC.LEVEL VSTATS.SPACE.SHOW.DISK? 
			     VStatsWindow))
    (LET (INIT?)
         (SELECTQ OPTION
		    [VSTATS.ALWAYS? (SETQ VSTATS.ALWAYS? (EQ NEWVALUE (QUOTE Yes]
		    (VSTATS.BLACK? (SETQ VSTATS.BLACK? (EQ NEWVALUE (QUOTE Inverted)))
				   (if VStatsWindow
				       then (VStats-SetDisplayColor)
					      (VStats-Display)))
		    [VSTATS.CLOCK.INTERVAL (LET [(OLDOFF (NULL (VStatsClock-Ticks?]
					        (SETQ VSTATS.CLOCK.INTERVAL (NUMBERP NEWVALUE))
					        (SETQ INIT? (NEQ OLDOFF (NULL (
									       VStatsClock-Ticks?]
		    [VSTATS.SPACE.INTERVAL (LET [(OLDOFF (NULL (VStatsSpace-Ticks?]
					        (SETQ VSTATS.SPACE.INTERVAL (NUMBERP NEWVALUE))
					        (SETQ INIT? (NEQ OLDOFF (NULL (
									       VStatsSpace-Ticks?]
		    [VSTATS.MUTIL.INTERVAL (LET [(OLDOFF (NULL (VStatsMUtil-Ticks?]
					        (SETQ VSTATS.MUTIL.INTERVAL (NUMBERP NEWVALUE))
					        (SETQ INIT? (NEQ OLDOFF (NULL (
									       VStatsMUtil-Ticks?]
		    (VSTATS.SPACE.PANIC.LEVEL (SETQ VSTATS.SPACE.PANIC.LEVEL NEWVALUE)
					      (VStatsSpace-InitPanicLevel))
		    (VSTATS.SPACE.SHOW.DISK? (SETQ VSTATS.SPACE.SHOW.DISK? NEWVALUE)
					     (SETQ INIT? T))
		    (VSTATS.MUTIL.HYSTERESIS (SETQ VSTATS.MUTIL.HYSTERESIS NEWVALUE)
					     (SETQ INIT? T))
		    (VSTATS.POSITION (SETQ VSTATS.POSITION NEWVALUE)
				     (if VStatsWindow
					 then (MOVEW VStatsWindow NEWVALUE)))
		    (ERROR "Unknown VSTATS option: " OPTION))
         (if (AND VStatsWindow INIT?)
	     then (VSTATS (QUOTE On])

(VStatsOptions-ValueCommandFn
  [LAMBDA (OLDVALUE OPTION OPTIONS WINDOW)                   (* Koomen "18-Jun-87 22:37")
    (DECLARE (GLOBALVARS VStatsOptionsWindow VStatsWindow))
    (PROG (NEWVALUE)
	    (if (NOT (VStats-MouseWait VStatsOptionsWindow))
		then (RETURN))
	    (SETQ NEWVALUE (SELECTQ OPTION
					(VSTATS.ALWAYS? (OR (MENU (create MENU
										ITEMS ←
										(QUOTE
										  (Yes No))
										CENTERFLG ← T))
							      OLDVALUE))
					(VSTATS.BLACK? (OR (MENU (create MENU
									       ITEMS ←
									       (QUOTE (Normal
											  Inverted))
									       CENTERFLG ← T))
							     OLDVALUE))
					((VSTATS.CLOCK.INTERVAL VSTATS.SPACE.INTERVAL 
								VSTATS.MUTIL.INTERVAL)
					  (VStatsOptions-RNumber "New interval: " T OLDVALUE
								   (QUOTE Disabled)))
					(VSTATS.SPACE.SHOW.DISK? (OR (VStatsSpace-InitDisk T)
								       OLDVALUE))
					(VSTATS.SPACE.PANIC.LEVEL (VStatsOptions-RNumber
								    "New panic level: " NIL OLDVALUE
								    (QUOTE Disabled)))
					(VSTATS.MUTIL.HYSTERESIS (VStatsOptions-RNumber
								   "MUtil hysteresis: " NIL OLDVALUE
								   (QUOTE Cumulative)))
					(VSTATS.POSITION (if VStatsWindow
							     then
							      (LET ((R (WINDOWREGION VStatsWindow)))
							           (GETBOXPOSITION
								     (fetch (REGION WIDTH)
									of R)
								     (fetch (REGION HEIGHT)
									of R)
								     (fetch (REGION LEFT)
									of R)
								     (fetch (REGION BOTTOM)
									of R)))
							   else (GETPOSITION)))
					(ERROR "Unknown VSTATS option: " OPTION)))
	    (if (NOT (EQUAL NEWVALUE OLDVALUE))
		then (INSPECTW.REPLACE WINDOW OPTION NEWVALUE])
)
(* * clock support stuff * *)


(RPAQ? VStatsClockFont )

(RPAQ? VStatsClockReset? )

(RPAQ? VStatsClockTimer )
(DEFINEQ

(VStatsClock-Display
  [LAMBDA NIL                                                (* Koomen "12-Jan-87 16:37")
    (DECLARE (GLOBALVARS VStatsClockDay VStatsClockDayPos VStatsClockDisplaySeconds? 
			     VStatsClockFont VStatsClockHr VStatsClockHrPos VStatsClockMin 
			     VStatsClockMinPos VStatsClockMon VStatsClockMonPos VStatsClockRegion 
			     VStatsClockSec VStatsClockSecPos VStatsClockXPos VStatsClockYPos 
			     VStatsClockYr VStatsClockYrPos VStatsDsp))
    (VStatsClock-Read)
    (SETQ VStatsClockXPos (fetch (REGION LEFT) of VStatsClockRegion))
    [SETQ VStatsClockYPos (IPLUS (fetch (REGION BOTTOM) of VStatsClockRegion)
				     (FONTPROP VStatsClockFont (QUOTE DESCENT]
    (MOVETO VStatsClockXPos VStatsClockYPos VStatsDsp)
    (DSPFONT VStatsClockFont VStatsDsp)
    (SETQ VStatsClockDayPos (DSPXPOSITION NIL VStatsDsp))
    (VStatsClock-DisplayDigits VStatsClockDayPos VStatsClockDay)
    (BOUT VStatsDsp (CHARCODE "-"))
    (SETQ VStatsClockMonPos (DSPXPOSITION NIL VStatsDsp))
    (VStatsClock-DisplayMonth VStatsClockMonPos VStatsClockMon)
    (BOUT VStatsDsp (CHARCODE "-"))
    (SETQ VStatsClockYrPos (DSPXPOSITION NIL VStatsDsp))
    (VStatsClock-DisplayDigits VStatsClockYrPos VStatsClockYr)
    (BOUT VStatsDsp (CHARCODE " "))
    (SETQ VStatsClockHrPos (DSPXPOSITION NIL VStatsDsp))
    (VStatsClock-DisplayDigits VStatsClockHrPos VStatsClockHr)
    (BOUT VStatsDsp (CHARCODE ":"))
    (SETQ VStatsClockMinPos (DSPXPOSITION NIL VStatsDsp))
    (VStatsClock-DisplayDigits VStatsClockMinPos VStatsClockMin)
    (if VStatsClockDisplaySeconds?
	then (BOUT VStatsDsp (CHARCODE ":"))
	       (SETQ VStatsClockSecPos (DSPXPOSITION NIL VStatsDsp))
	       (VStatsClock-DisplayDigits VStatsClockSecPos VStatsClockSec])

(VStatsClock-DisplayDigits
  [LAMBDA (dspxpos n)                                        (* HaKo " 1-Aug-85 10:10")
    (DECLARE (GLOBALVARS VStatsDsp))
    (DSPXPOSITION dspxpos VStatsDsp)
    (BOUT VStatsDsp (IPLUS (IQUOTIENT (IREMAINDER n 100)
					    10)
			       (CHARCODE "0")))
    (BOUT VStatsDsp (IPLUS (IREMAINDER n 10)
			       (CHARCODE "0"])

(VStatsClock-DisplayMonth
  [LAMBDA (dspxpos m)                                        (* HaKo " 1-Aug-85 10:13")
    (DECLARE (GLOBALVARS VStatsDsp))
    (PROG ((i (ADD1 (ITIMES 3 m)))
	     (lbl "JanFebMarAprMayJunJulAugSepOctNovDec"))
	    (DSPXPOSITION dspxpos VStatsDsp)
	    (BOUT VStatsDsp (OR (NTHCHARCODE lbl i)
				    (CHARCODE "?")))
	    (BOUT VStatsDsp (OR (NTHCHARCODE lbl (IPLUS i 1))
				    (CHARCODE "?")))
	    (BOUT VStatsDsp (OR (NTHCHARCODE lbl (IPLUS i 2))
				    (CHARCODE "?"])

(VStatsClock-Init
  [LAMBDA NIL                                                (* HaKo "13-Jun-86 00:44")

          (* * If the clock interval is not a FIXP or not positive, the clock display is disabled. (MENU VStatsOptionsMenu))


    (DECLARE (GLOBALVARS VStatsClockDisplaySeconds? VStatsClockFont VStatsClockRegion))
    (if (VStatsClock-Ticks?)
	then [LET ((datestr (DATE)))
		    [if (NOT (FONTP VStatsClockFont))
			then (SETQ VStatsClockFont (FONTCREATE (QUOTE (GACHA 12 BOLD]
		    (if (NOT VStatsClockDisplaySeconds?)
			then (SETQ datestr (SUBSTRING datestr 1 -4)))
		    (SETQ VStatsClockRegion (create REGION
							LEFT ← 0
							BOTTOM ← 0
							WIDTH ← (STRINGWIDTH datestr 
										 VStatsClockFont)
							HEIGHT ← (FONTHEIGHT VStatsClockFont]
      else (SETQ VStatsClockRegion NIL])

(VStatsClock-ReDisplay
  [LAMBDA NIL                                                (* HaKo "12-Jun-86 23:04")
    (DECLARE (GLOBALVARS VSTATS.ALWAYS? VStatsClockDay VStatsClockDayPos 
			     VStatsClockDisplaySeconds? VStatsClockFont VStatsClockHr 
			     VStatsClockHrPos VStatsClockMin VStatsClockMinPos VStatsClockMon 
			     VStatsClockMonPos VStatsClockReset? VStatsClockSec VStatsClockSecPos 
			     VStatsClockYPos VStatsClockYr VStatsClockYrPos VStatsDsp VStatsWindow))
    (if (OR VSTATS.ALWAYS? (TOPWP VStatsWindow))
	then (PROG ((oldday VStatsClockDay)
			(oldmon VStatsClockMon)
			(oldyr VStatsClockYr)
			(oldhr VStatsClockHr)
			(oldmin VStatsClockMin)
			(oldsec VStatsClockSec))
		       (DSPFONT VStatsClockFont VStatsDsp)
		       (DSPYPOSITION VStatsClockYPos VStatsDsp)
		       (VStatsClock-Read)
		       (if (NEQ VStatsClockDay oldday)
			   then (SETQ VStatsClockReset? T))
		       (if (AND VStatsClockReset? (NEQ VStatsClockHr oldhr)
				    (\NET.SETTIME))
			   then (SETQ VStatsClockReset? NIL)
				  (VStatsClock-Read))
		       (if (NEQ VStatsClockDay oldday)
			   then (VStatsClock-DisplayDigits VStatsClockDayPos VStatsClockDay))
		       (if (NEQ VStatsClockMon oldmon)
			   then (VStatsClock-DisplayMonth VStatsClockMonPos VStatsClockMon))
		       (if (NEQ VStatsClockYr oldyr)
			   then (VStatsClock-DisplayDigits VStatsClockYrPos VStatsClockYr))
		       (if (NEQ VStatsClockHr oldhr)
			   then (VStatsClock-DisplayDigits VStatsClockHrPos VStatsClockHr))
		       (if (NEQ VStatsClockMin oldmin)
			   then (VStatsClock-DisplayDigits VStatsClockMinPos VStatsClockMin))
		       (if (AND VStatsClockDisplaySeconds? (NEQ VStatsClockSec oldsec))
			   then (VStatsClock-DisplayDigits VStatsClockSecPos VStatsClockSec])

(VStatsClock-Read
  [LAMBDA NIL                                                (* Koomen "26-Mar-87 15:13")
    (DECLARE (GLOBALVARS VStatsClockDay VStatsClockHr VStatsClockMin VStatsClockMon 
			     VStatsClockSec VStatsClockYr))

          (* APPLY (FUNCTION (LAMBDA (yr mon day hr min sec dst) (SETQ VStatsClockDay day) (SETQ VStatsClockMon mon) 
	  (SETQ VStatsClockYr yr) (SETQ VStatsClockHr hr) (SETQ VStatsClockMin min) (SETQ VStatsClockSec sec))) 
	  (\UNPACKDATE))


    (VStatsClock-UnpackDate])

(VStatsClock-Ticks?
  [LAMBDA NIL                                                (* Koomen "12-Jan-87 17:20")
    (DECLARE (GLOBALVARS VSTATS.CLOCK.INTERVAL VStatsClockDisplaySeconds? VStatsClockTimer))
    (LET [(NTICKS (VStats-InitInterval (OR VStatsClockTimer (SETQ VStatsClockTimer
						 (create VSTATSTIMERINFO)))
					 VSTATS.CLOCK.INTERVAL
					 (CONSTANT (TIMES 5 60]
         [SETQ VStatsClockDisplaySeconds? (AND NTICKS (ILESSP NTICKS (CLOCKTICKS
								      1
								      (QUOTE MINUTE]
     NTICKS])

(VStatsClock-UnpackDate
  [LAMBDA (D)                                                (* Koomen "26-Mar-87 15:11")
                                                             (* Adapted from \UNPACKDATE on 
							     <Lisp>Koto>Sources>IOCHAR dated "28-Jun-85 18:07:58")
    (DECLARE (GLOBALVARS VStatsClockDay VStatsClockHr VStatsClockMin VStatsClockMon 
			     VStatsClockSec VStatsClockYr))
                                                             (* bvm: "28-Jun-85 18:07")

          (* Converts an internal Lisp date D into a list of integers (Year Month Day Hours Minutes Seconds daylightp 
	  DayOfWeek). D defaults to current date. -
	  DayOfWeek is zero for Monday -
	  -
	  D is first converted to the alto standard, a 32-bit unsigned integer, representing the number of seconds since jan 
	  1, 1901-Gmt. We have to be a little tricky in our computations to avoid the sign bit.)


    (SETQ D (OR D (DAYTIME)))
    (PROG ((CHECKDLS \DayLightSavings)
	     (DQ (IQUOTIENT (LOGAND MAX.FIXP (LRSH (LISP.TO.ALTO.DATE D)
							 1))
			      30))
	     MONTH SEC HR DAY4 YDAY WDAY YEAR4 TOTALDAYS MIN DLS)
                                                             (* DQ is number of minutes since day 0, getting us 
							     past the sign bit problem.)
	    (SETQ SEC (IMOD [IPLUS D (CONSTANT (IDIFFERENCE 60 (IMOD MIN.FIXP 60]
				60))
	    (SETQ MIN (IREMAINDER DQ 60))

          (* No we can adjust to the current time zone. Since this might cause DQ to go negative, first add in 4 years worth 
	  of hours, making the base date be Jan 1, 1897)


	    (SETQ HR (IREMAINDER (SETQ DQ (IDIFFERENCE (IPLUS (IQUOTIENT DQ 60)
									(CONSTANT (ITIMES 24 
										      \4YearsDays)))
							       \TimeZoneComp))
				     24))
	    (SETQ TOTALDAYS (IQUOTIENT DQ 24))
	DTLOOP
	    (SETQ DAY4 (IREMAINDER TOTALDAYS \4YearsDays))
                                                             (* DAY4 = number of days since last leap year day 0)
	    [SETQ DAY4 (IPLUS DAY4 (CDR (\DTSCAN DAY4 (QUOTE ((789 . 3)
									 (424 . 2)
									 (59 . 1)
									 (0 . 0]
                                                             (* pretend every year is a leap year, adding one for 
							     days after Feb 28)
	    (SETQ YEAR4 (IQUOTIENT TOTALDAYS \4YearsDays))
                                                             (* YEAR4 = number of years til that last leap year / 
							     4)
	    (SETQ YDAY (IREMAINDER DAY4 366))            (* YDAY is the ordinal day in the year 
							     (jan 1 = zero))
	    (SETQ WDAY (IREMAINDER (IPLUS TOTALDAYS 3)
				       7))
	    [COND
	      ((AND CHECKDLS (SETQ DLS (\ISDST? YDAY HR WDAY)))

          (* This date is during daylight savings, so add 1 hour. Third arg is day of the week, which we determine by taking 
	  days mod 7 plus offset. Monday = zero in this scheme. Jan 1 1897 was actually a Friday (not Thursday=3), but we're 
	  cheating--1900 was not a leap year)


		(COND
		  ((IGREATERP (SETQ HR (ADD1 HR))
				23)

          (* overflowed into the next day. This case is too hard (we might have overflowed the month, for example), so just 
	  go back and recompute)


		    (SETQ TOTALDAYS (ADD1 TOTALDAYS))
		    (SETQ HR 0)
		    (SETQ CHECKDLS NIL)
		    (GO DTLOOP]
	    [SETQ MONTH (\DTSCAN YDAY (QUOTE ((335 . 11)
						     (305 . 10)
						     (274 . 9)
						     (244 . 8)
						     (213 . 7)
						     (182 . 6)
						     (152 . 5)
						     (121 . 4)
						     (91 . 3)
						     (60 . 2)
						     (31 . 1)
						     (0 . 0]
                                                             (* Now return year, month, day, hr, min, sec)

          (* RETURN (LIST (IPLUS 1897 (ITIMES YEAR4 4) (IQUOTIENT DAY4 366)) (CDR MONTH) (ADD1 (IDIFFERENCE YDAY 
	  (CAR MONTH))) HR MIN SEC DLS WDAY))


	    (SETQ VStatsClockYr (IPLUS 1897 (ITIMES YEAR4 4)
					   (IQUOTIENT DAY4 366)))
	    (SETQ VStatsClockMon (CDR MONTH))
	    [SETQ VStatsClockDay (ADD1 (IDIFFERENCE YDAY (CAR MONTH]
	    (SETQ VStatsClockHr HR)
	    (SETQ VStatsClockMin MIN)
	    (SETQ VStatsClockSec SEC])
)
(* * space support stuff * *)


(RPAQ? VStatsSpaceDiskPages )

(RPAQ? VStatsSpaceFont )

(RPAQ? VStatsSpacePCTs )

(RPAQ? VStatsSpaceTimer )

(RPAQ? \LASTVMEMFILEPAGE 16383)
(DEFINEQ

(VStatsSpace-Display
  [LAMBDA NIL                                                (* Koomen "12-Jan-87 16:37")
    (DECLARE (GLOBALVARS VStatsDsp VStatsSpaceFont VStatsSpacePCTs VStatsSpaceRegion))
    (PROG [x (xoffset (fetch (REGION LEFT) of VStatsSpaceRegion))
	       (yoffset (IPLUS (fetch (REGION BOTTOM) of VStatsSpaceRegion)
				 (FONTPROP VStatsSpaceFont (QUOTE HEIGHT]
	    (DSPFONT VStatsSpaceFont VStatsDsp)
	    (MOVETO xoffset yoffset VStatsDsp)
	    (for PCT in VStatsSpacePCTs
	       do (DSPXPOSITION (fetch (REGION LEFT) of (fetch (VSTATSPCTINFO LBLREGION)
								   of PCT))
				    VStatsDsp)
		    (printout VStatsDsp (fetch (VSTATSPCTINFO LABEL) of PCT)))
	    (TERPRI VStatsDsp)
	    (SETQ yoffset (DSPYPOSITION NIL VStatsDsp))
	    (VStatsSpace-Read)
	    (for PCT in VStatsSpacePCTs
	       do (replace (REGION BOTTOM) of (fetch (VSTATSPCTINFO LBLREGION) of PCT)
		       with yoffset)
		    (replace (REGION BOTTOM) of (fetch (VSTATSPCTINFO BARREGION) of PCT)
		       with yoffset)
		    (VStats-DisplayPct PCT T])

(VStatsSpace-Init
  [LAMBDA NIL                                                (* Koomen "18-Jun-87 17:22")

          (* * If the space interval is not a FIXP or not positive, the space display is disabled, and this function returns 
	  NIL. Otherwise it returns the region required for the space display.)


    (DECLARE (GLOBALVARS VSTATS.SPACE.SHOW.DISK? VStatsSpaceDiskPages VStatsSpaceFont 
			     VStatsSpacePCTs VStatsSpaceRegion))
    (if (VStatsSpace-Ticks?)
	then [if (NOT (FONTP VStatsSpaceFont))
		   then (SETQ VStatsSpaceFont (FONTCREATE (QUOTE (GACHA 10]
	       (VStatsSpace-InitDisk)
	       (VStatsSpace-InitPanicLevel)
	       [SETQ VStatsSpacePCTs (VStats-CreatePCTs VStatsSpaceFont
							    (if VStatsSpaceDisk
								then (QUOTE ((DATA . "Data")
										  (ATOM . "Atom")
										  (VMEM . "VMem")
										  (DISK . "Disk")))
							      else (QUOTE ((DATA . "Data")
										(ATOM . "Atom")
										(VMEM . "VMem"]
	       (SETQ VStatsSpaceRegion (VStats-GetPCTsRegion VStatsSpacePCTs))
      else (SETQ VStatsSpaceRegion NIL])

(VStatsSpace-InitDisk
  [LAMBDA (ASK?)                                             (* Koomen " 2-Jul-87 00:41")
    (DECLARE (GLOBALVARS VSTATS.SPACE.PANIC.LEVEL VStatsSpacePanicLevel))
    [if ASK?
	then (LET [(DISK (MENU (create MENU
					     ITEMS ← (APPEND (QUOTE (*OFF* *DEFAULT* ("")))
								 (SELECTQ (MACHINETYPE)
									    ((DANDELION DAYBREAK DOVE)
									      (for V
										 in (VOLUMES)
										 when (
										   LISPDIRECTORYP
											  V)
										 collect V))
									    (DORADO (PROMPTPRINT
										      
							  "This takes a little while; hang on...")
										    (ALTOPARTITIONS)
										    )
									    NIL))
					     CENTERFLG ← T]
		    (if DISK
			then (SETQ VSTATS.SPACE.SHOW.DISK?
				 (if (EQ DISK (QUOTE *OFF*))
				     then NIL
				   elseif (EQ DISK (QUOTE *DEFAULT*))
				     then T
				   else (SELECTQ (MACHINETYPE)
						     ((DANDELION DAYBREAK DOVE)
						       (PACKFILENAME (QUOTE HOST)
								       (QUOTE DSK)
								       (QUOTE DIRECTORY)
								       DISK))
						     (DORADO (PACKFILENAME (QUOTE HOST)
									     DISK))
						     NIL]
    [SETQ VStatsSpaceDisk (if VSTATS.SPACE.SHOW.DISK?
				then (CAR (NLSETQ (DIRECTORYNAME (if (EQ 
									  VSTATS.SPACE.SHOW.DISK? T)
									     then "{DSK}"
									   else 
									  VSTATS.SPACE.SHOW.DISK?]
    (SETQ VStatsSpaceDiskPages (if VStatsSpaceDisk
				     then (DISKTOTALPAGES VStatsSpaceDisk)))
    (if (FIXP VStatsSpaceDiskPages)
	then VStatsSpaceDisk
      else (SETQ VStatsSpaceDisk NIL])

(VStatsSpace-InitPanicLevel
  [LAMBDA (ASK?)                                             (* Koomen "12-Jan-87 17:21")
    (DECLARE (GLOBALVARS VSTATS.SPACE.PANIC.LEVEL VStatsSpacePanicLevel))
    (if ASK?
	then (SETQ VSTATS.SPACE.PANIC.LEVEL (RNUMBER "Panic level (): ")))
    (SETQ VStatsSpacePanicLevel (if (AND (BOUNDP (QUOTE VSTATS.SPACE.PANIC.LEVEL))
					       (NUMBERP VSTATS.SPACE.PANIC.LEVEL)
					       (LESSP VSTATS.SPACE.PANIC.LEVEL 100)
					       (GREATERP VSTATS.SPACE.PANIC.LEVEL 0))
				      then (FIX (if (LESSP VSTATS.SPACE.PANIC.LEVEL 1)
							then (TIMES VSTATS.SPACE.PANIC.LEVEL 100)
						      else VSTATS.SPACE.PANIC.LEVEL])

(VStatsSpace-ReDisplay
  [LAMBDA NIL                                                (* Koomen "12-Jan-87 16:42")
    (DECLARE (GLOBALVARS VSTATS.ALWAYS? VStatsDsp VStatsSpaceFont VStatsSpacePCTs 
			     VStatsSpacePanicLevel VStatsWindow))
    (VStatsSpace-Read)
    (PROG ((flashes 0))
	    [if VStatsSpacePanicLevel
		then (for pct in VStatsSpacePCTs bind delta
			  do (SETQ delta (IDIFFERENCE (fetch (VSTATSPCTINFO NEWPCT)
							       of pct)
							    VStatsSpacePanicLevel))
			       (if (IGREATERP delta 0)
				   then (SETQ flashes (IPLUS flashes delta]
	    (if (OR VSTATS.ALWAYS? (IGREATERP flashes 0)
			(TOPWP VStatsWindow))
		then (DSPFONT VStatsSpaceFont VStatsDsp)
		       (for pct in VStatsSpacePCTs when (NEQ (fetch (VSTATSPCTINFO NEWPCT)
									of pct)
								     (fetch (VSTATSPCTINFO OLDPCT)
									of pct))
			  do (VStats-DisplayPct pct))
		       (if (IGREATERP flashes 0)
			   then (FLASHWINDOW VStatsWindow flashes)
				  (VStatsSpace-ShrinkInterval (ITIMES flashes 5])

(VStatsSpace-Read
  [LAMBDA NIL                                                (* Koomen "18-Jun-87 17:23")
                                                             (* DECLARATIONS: (RECORD SPACEDATA 
							     (MDSFREE MDSFRAC 8MBFRAC ATOMSFREE ATOMFRAC)))
    (DECLARE (GLOBALVARS VStatsSpaceDiskPages VStatsSpacePCTs \LASTVMEMFILEPAGE))
    (for PCT in VStatsSpacePCTs bind (heap ← (STORAGE.LEFT))
       do (replace (VSTATSPCTINFO OLDPCT) of PCT with (fetch (VSTATSPCTINFO NEWPCT)
								 of PCT))
	    (replace (VSTATSPCTINFO NEWPCT) of PCT
	       with (SELECTQ (fetch (VSTATSPCTINFO NAME) of PCT)
				 [DATA (FIX (FDIFFERENCE 100.5 (FTIMES 100.0
									     (fetch MDSFRAC
										of heap]
				 [ATOM (FIX (FDIFFERENCE 100.5 (FTIMES 100.0
									       (fetch ATOMFRAC
										  of heap]
				 (VMEM (VStats-Percentage (VMEMSIZE)
							    \LASTVMEMFILEPAGE))
				 (DISK (VStats-Percentage (IDIFFERENCE VStatsSpaceDiskPages
									   (DISKFREEPAGES 
										  VStatsSpaceDisk))
							    VStatsSpaceDiskPages))
				 (SHOULDNT])

(VStatsSpace-ShrinkInterval
  [LAMBDA (shrinkpct)                                        (* Koomen "12-Jan-87 17:25")
    (DECLARE (GLOBALVARS VStatsSpaceTimer))
    (PROG ([delta (IMAX 50 (IDIFFERENCE 100 (OR shrinkpct 25]
	     (oldint (fetch (VSTATSTIMERINFO INTERVAL) of VStatsSpaceTimer))
	     newint)
	    [SETQ newint (IMAX (IQUOTIENT (ITIMES oldint delta)
						100)
				   (CLOCKTICKS 30 (QUOTE SECONDS]
	    (if (ILESSP newint oldint)
		then (replace (VSTATSTIMERINFO INTERVAL) of VStatsSpaceTimer with newint)
		       (VStats-SetUpTimer VStatsSpaceTimer])

(VStatsSpace-Ticks?
  [LAMBDA NIL                                                (* Koomen "12-Jan-87 15:49")
    (DECLARE (GLOBALVARS VSTATS.SPACE.INTERVAL VStatsSpaceTimer))
    (VStats-InitInterval (OR VStatsSpaceTimer (SETQ VStatsSpaceTimer (create VSTATSTIMERINFO))
				 )
			   VSTATS.SPACE.INTERVAL
			   (CONSTANT (TIMES 15 60])
)
(* * machine utilization support stuff * *)


(RPAQ? VStatsMUtilFont )

(RPAQ? VStatsMUtilOrigState )

(RPAQ? VStatsMUtilPCTs )

(RPAQ? VStatsMUtilTimer )
(DEFINEQ

(VStatsMUtil-Display
  [LAMBDA NIL                                                (* Koomen "12-Jan-87 16:46")
    (DECLARE (GLOBALVARS VStatsDsp VStatsMUtilFont VStatsMUtilPCTs VStatsMUtilRegion))
    (PROG [x (xoffset (fetch (REGION LEFT) of VStatsMUtilRegion))
	       (yoffset (IPLUS (fetch (REGION BOTTOM) of VStatsMUtilRegion)
				 (FONTPROP VStatsMUtilFont (QUOTE HEIGHT]
	    (DSPFONT VStatsMUtilFont VStatsDsp)
	    (MOVETO xoffset yoffset VStatsDsp)
	    (for PCT in VStatsMUtilPCTs
	       do (DSPXPOSITION (fetch (REGION LEFT) of (fetch (VSTATSPCTINFO LBLREGION)
								   of PCT))
				    VStatsDsp)
		    (printout VStatsDsp (fetch (VSTATSPCTINFO LABEL) of PCT)))
	    (TERPRI VStatsDsp)
	    (SETQ yoffset (DSPYPOSITION NIL VStatsDsp))
	    (VStatsMUtil-Read)
	    (for PCT in VStatsMUtilPCTs
	       do (replace (REGION BOTTOM) of (fetch (VSTATSPCTINFO LBLREGION) of PCT)
		       with yoffset)
		    (replace (REGION BOTTOM) of (fetch (VSTATSPCTINFO BARREGION) of PCT)
		       with yoffset)
		    (VStats-DisplayPct PCT T])

(VStatsMUtil-Init
  [LAMBDA NIL                                                (* HaKo "13-Jun-86 01:29")

          (* * If the machine utilization interval is not a FIXP or not positive, the machine utilization display is 
	  disabled, and this function returns NIL. Otherwise it returns the region required for the machine utilization 
	  display.)


    (DECLARE (GLOBALVARS AFTERLOGOUTFORMS VStatsMUtilFont VStatsMUtilPCTs VStatsMUtilRegion))
    (LET [(AfterLogoutForm (QUOTE (VStatsMUtil-InitState]
         (if (VStatsMUtil-Ticks?)
	     then (VStatsMUtil-InitState)
		    (OR (MEMBER AfterLogoutForm AFTERLOGOUTFORMS)
			  (push AFTERLOGOUTFORMS AfterLogoutForm))
		    [if (NOT (FONTP VStatsMUtilFont))
			then (SETQ VStatsMUtilFont (FONTCREATE (QUOTE (GACHA 10]
		    [SETQ VStatsMUtilPCTs (VStats-CreatePCTs VStatsMUtilFont
								 (QUOTE ((CPU . " CPU")
									    (IO . " I/O")
									    (GC . "  GC")
									    (SWAP . "Swap"]
		    (SETQ VStatsMUtilRegion (VStats-GetPCTsRegion VStatsMUtilPCTs))
	   else (SETQ AFTERLOGOUTFORMS (REMOVE AfterLogoutForm AFTERLOGOUTFORMS))
		  (SETQ VStatsMUtilRegion NIL])

(VStatsMUtil-InitState
  [LAMBDA (DONT.SET.ORIG?)                                   (* HaKo " 3-Feb-86 14:45")
    (DECLARE (GLOBALVARS VSTATS.MUTIL.HYSTERESIS VStatsMUtilDiffState VStatsMUtilNextState 
			     VStatsMUtilOrigState VStatsMUtilStateRing))
    (if (NULL VStatsMUtilOrigState)
	then (SETQ VStatsMUtilOrigState (CREATEMISCSTATS NIL T))
	       (SETQ VStatsMUtilDiffState (CREATEMISCSTATS NIL T))
	       (SETQ VStatsMUtilNextState)
	       (SETQ VStatsMUtilStateRing))
    (if VStatsMUtilStateRing
	then                                               (* Break the old ring so it can be GC'd)
	       (RPLACD VStatsMUtilStateRing))
    (OR DONT.SET.ORIG? (COPYMISCSTATS VStatsMUtilOrigState))
    (if (AND (NUMBERP VSTATS.MUTIL.HYSTERESIS)
		 (GREATERP VSTATS.MUTIL.HYSTERESIS 0))
	then                                               (* Build a ring of MISCSTATS records)
	       [SETQ VStatsMUtilStateRing (for i from 0 to VSTATS.MUTIL.HYSTERESIS
					       bind s collect (PROG1 (SETQ s
									     (CREATEMISCSTATS
									       NIL T))
									   (COPYMISCSTATS s]
                                                             (* Complete the circle)
	       (RPLACD (LAST VStatsMUtilStateRing)
			 VStatsMUtilStateRing)
	       (SETQ VStatsMUtilNextState)
      else (SETQ VStatsMUtilNextState (CREATEMISCSTATS NIL T))
	     (COPYMISCSTATS VStatsMUtilNextState)
	     (SETQ VStatsMUtilStateRing])

(VStatsMUtil-ReDisplay
  [LAMBDA NIL                                                (* HaKo "26-Mar-86 15:53")
    (DECLARE (GLOBALVARS VSTATS.ALWAYS? VStatsDsp VStatsMUtilFont VStatsMUtilPCTs VStatsWindow))
    (if (OR VSTATS.ALWAYS? (TOPWP VStatsWindow))
	then (VStatsMUtil-Read)
	       (DSPFONT VStatsMUtilFont VStatsDsp)
	       (for pct in VStatsMUtilPCTs when (NEQ (fetch (VSTATSPCTINFO NEWPCT)
								of pct)
							     (fetch (VSTATSPCTINFO OLDPCT)
								of pct))
		  do (VStats-DisplayPct pct])

(VStatsMUtil-Read
  [LAMBDA NIL                                                (* Koomen "26-Mar-87 16:26")

          (* State is kept on a LIST whose CAR is a FIXP given to CLOCK0 to obtain elapsed time, and whose CADR is a 
	  blockrecord a la \MISCSTATS. The functions CREATEMISCSTATS COPYMISCSTATS and DIFFMISCSTATS are peovided by 
	  Interlisp-D (cf. file SOURCES>DMISC (-- contains the \MISCSTAT record decl also)))



          (* * (To reinitialize, execute (SETQ VStatsMUtilOrigState)))


    (DECLARE (GLOBALVARS VStatsMUtilDiffState VStatsMUtilNextState VStatsMUtilOrigState 
			     VStatsMUtilPCTs VStatsMUtilStateRing))
    (PROG (oldstate newstate stats io gc swap elapsed cpu)
	    (if VStatsMUtilStateRing
		then (SETQ newstate (pop VStatsMUtilStateRing))
		       (SETQ oldstate (CAR VStatsMUtilStateRing))
	      else (SETQ newstate VStatsMUtilNextState)
		     (SETQ oldstate VStatsMUtilOrigState))
	    (COPYMISCSTATS newstate)
	    (DIFFMISCSTATS oldstate newstate VStatsMUtilDiffState)
	    (SETQ stats (CADR VStatsMUtilDiffState))
	    [SETQ io (IPLUS (IMAX 0 (fetch (MISCSTATS NETIOTIME) of stats))
				(IMAX 0 (fetch (MISCSTATS DISKIOTIME) of stats]
	    (SETQ gc (IMAX 0 (fetch (MISCSTATS GCTIME) of stats)))
	    (SETQ swap (IMAX 0 (fetch (MISCSTATS SWAPWAITTIME) of stats)))
	    (SETQ elapsed (IMAX (CAR VStatsMUtilDiffState)
				    (IPLUS io gc swap)))
	    [SETQ cpu (IMAX 0 (IDIFFERENCE 100 (IPLUS (SETQ io (VStats-Percentage io 
											  elapsed))
							      (SETQ gc (VStats-Percentage gc 
											  elapsed))
							      (SETQ swap (VStats-Percentage
								  swap elapsed]
	    (for PCT in VStatsMUtilPCTs
	       do (replace (VSTATSPCTINFO OLDPCT) of PCT with (fetch (VSTATSPCTINFO NEWPCT)
									 of PCT))
		    (replace (VSTATSPCTINFO NEWPCT) of PCT with (SELECTQ (fetch
										   (VSTATSPCTINFO
										     NAME)
										    of PCT)
										 (CPU cpu)
										 (IO io)
										 (GC gc)
										 (SWAP swap)
										 (SHOULDNT])

(VStatsMUtil-Ticks?
  [LAMBDA NIL                                                (* Koomen "12-Jan-87 15:49")
    (DECLARE (GLOBALVARS VSTATS.MUTIL.INTERVAL VStatsMUtilTimer))
    (VStats-InitInterval (OR VStatsMUtilTimer (SETQ VStatsMUtilTimer (create VSTATSTIMERINFO))
				 )
			   VSTATS.MUTIL.INTERVAL
			   (CONSTANT (TIMES 5 60])
)
(* * These ought to be system functions!!! * *)

(DEFINEQ

(CLOCKTICKS
  [LAMBDA (interval timerunits)                              (* Koomen "12-Jan-87 17:22")
    (DECLARE (GLOBALVARS \RCLKSECOND))
    (PROG ((ticks (if (NULL interval)
			then 1
		      elseif (NOT (NUMBERP interval))
			then (ERROR "Non-numeric arg: " interval)
		      elseif (NOT (GREATERP interval 0))
			then (ERROR "Non-positive arg: " interval)
		      else interval)))
	    (SELECTQ (U-CASE timerunits)
		       ((TICK TICKS))
		       ((MSEC MILLISEC MSECS MILLISECS)
			 (SETQ ticks (FTIMES .001 \RCLKSECOND ticks)))
		       ((NIL SEC SECOND SECS SECONDS)
			 (SETQ ticks (TIMES \RCLKSECOND ticks)))
		       ((MIN MINUTE MINS MINUTES)
			 (SETQ ticks (TIMES 60 \RCLKSECOND ticks)))
		       ((HR HOUR HRS HOURS)
			 (SETQ ticks (TIMES 3600 \RCLKSECOND ticks)))
		       (ERROR "unknown timerunits: " timerunits))
	    (RETURN (if (FLOATP ticks)
			  then (FIX (FPLUS ticks .5))
			else ticks])

(ALTOPARTITIONS
  [LAMBDA NIL                                                (* Koomen "19-Jun-87 00:39")
                                                             (* ;;; "NASTY!!!  Bypassing partition passwords")
    (SELECTQ (MACHINETYPE)
	       [DORADO (LET [(TFUN (FUNCTION (LAMBDA NIL T]
			    (RESETLST [RESETSAVE NIL (BQUOTE (PUTD
								     \M44CHECKPASSWORD
								     (\, (GETD (QUOTE 
										\M44CHECKPASSWORD]
					[PUTD (QUOTE \M44CHECKPASSWORD)
						(OR (if (LITATOM TFUN)
							  then (GETD TFUN)
							else TFUN)
						      (GETD (QUOTE NILL]
					(for I from 1 while (\TESTPARTITION I)
					   when [CAR (NLSETQ (INFILEP (PACK* "{DSK" I 
										    "}SYS.BOOT;1"]
					   collect (PACK* "DSK" I]
	       NIL])

(DISKUSEDPAGES
  [LAMBDA (DSK RECOMPUTE)                                    (* Koomen "19-Jun-87 01:46")
                                                             (* ;; 
							     
"Hard-wired constant for Dorado partition size.  Probably wrong, but adding up file sizes is way too slow (~ 8 secs)"
)
    (SELECTQ (MACHINETYPE)
	       [(DANDELION DAYBREAK DOVE)
		 (if (EQ (QUOTE DSK)
			     (FILENAMEFIELD (DIRECTORYNAME "{DSK}")
					      (QUOTE HOST)))
		     then                                  (* ;; "Local disk directory has been created")
			    (IDIFFERENCE (VOLUMESIZE DSK RECOMPUTE)
					   (DISKFREEPAGES DSK RECOMPUTE]
	       [DORADO (if [SETQ DSK (CAR (NLSETQ (DIRECTORYNAME (OR DSK "{DSK}"]
			   then (if RECOMPUTE
				      then (for F in (FILDIR DSK) sum (GETFILEINFO
										  F
										  (QUOTE SIZE)))
				    else (IMAX 0 (IDIFFERENCE 22750 (DISKFREEPAGES DSK 
											RECOMPUTE]
	       NIL])

(DISKTOTALPAGES
  [LAMBDA (DSK RECOMPUTE)                                    (* Koomen "19-Jun-87 01:46")
    (SELECTQ (MACHINETYPE)
	       ((DANDELION DAYBREAK DOVE)
		 (if (EQ (QUOTE DSK)
			     (FILENAMEFIELD (DIRECTORYNAME "{DSK}")
					      (QUOTE HOST)))
		     then                                  (* ;; "Local disk directory has been created")
			    (VOLUMESIZE DSK RECOMPUTE)))
	       [DORADO (if [SETQ DSK (CAR (NLSETQ (DIRECTORYNAME (OR DSK "{DSK}"]
			   then (IPLUS (DISKFREEPAGES DSK RECOMPUTE)
					   (DISKUSEDPAGES DSK RECOMPUTE]
	       NIL])
)



(* Lisp before Lute version does not have a TOPWP function to test if window is on top)

(DEFINEQ

(VStats-TOPWP
  [LAMBDA (WINDOW)                                           (* HaKo " 8-Jul-85 14:27")
    (DECLARE (GLOBALVARS TOPW))

          (* * NOTE: the calls to FETCHFIELD should be replaced by the indicated fetch instructions)


    (if (OPENWP WINDOW)
	then (PROG (R (W TOPW))
		   LP  (COND
			 ((EQ W WINDOW)
			   (RETURN WINDOW))
			 ([REGIONSINTERSECTP (FETCHFIELD (QUOTE (WINDOW 6 POINTER))
							     W)
					       (OR R (SETQ R (FETCHFIELD (QUOTE (WINDOW
											  6 POINTER))
									       WINDOW]

          (* * (REGIONSINTERSECTP (fetch (WINDOW REG) of W) (OR R (SETQ R (fetch (WINDOW REG) of WINDOW)))))


			   (RETURN NIL))
			 ((SETQ W (FETCHFIELD (QUOTE (WINDOW 2 POINTER))
						  W))

          (* * (SETQ W (fetch (WINDOW NEXTW) of X)))


			   (GO LP])
)
(MOVD? (QUOTE VStats-TOPWP)
       (QUOTE TOPWP))
(* * Initialize on LOAD * *)


(RPAQQ BackgroundMenu NIL)

(ADDTOVAR BackgroundMenuCommands ("VStats" (QUOTE (VSTATS (QUOTE On)))
					     "Running display of clock and/or space utilization"))
(DECLARE: DONTEVAL@LOAD DOCOPY 
[COND ((OR VSTATS.CLOCK.INTERVAL VSTATS.SPACE.INTERVAL VSTATS.MUTIL.INTERVAL)
       (VSTATS (QUOTE ON]
)
(PUTPROPS VSTATS COPYRIGHT ("Xerox Corporation" 1985 1986 1987))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (3837 5196 (VSTATS 3847 . 5194)) (6576 23213 (VStats-CenterRegion 6586 . 7475) (
VStats-CreatePCTs 7477 . 9222) (VStats-Display 9224 . 10411) (VStats-DisplayPct 10413 . 12120) (
VStats-DrawLine 12122 . 12578) (VStats-GetPCTsRegion 12580 . 13696) (VStats-Init 13698 . 18185) (
VStats-InitInterval 18187 . 18716) (VStats-MouseWait 18718 . 19386) (VStats-ReDisplay? 19388 . 20158) 
(VStats-SetDisplayColor 20160 . 20636) (VStats-SetUpTimer 20638 . 20977) (VStats-TimerExpired? 20979
 . 21929) (VStats-Percentage 21931 . 23211)) (23285 33182 (VStatsOptions-Inspect 23295 . 24758) (
VStatsOptions-FetchFn 24760 . 26682) (VStatsOptions-PropCommandFn 26684 . 27822) (
VStatsOptions-PropPrintFn 27824 . 28569) (VStatsOptions-PropertiesFn 28571 . 28708) (
VStatsOptions-RNumber 28710 . 29028) (VStatsOptions-SelectionFn 29030 . 29244) (VStatsOptions-StoreFn 
29246 . 31304) (VStatsOptions-ValueCommandFn 31306 . 33180)) (33312 44749 (VStatsClock-Display 33322
 . 35250) (VStatsClock-DisplayDigits 35252 . 35664) (VStatsClock-DisplayMonth 35666 . 36258) (
VStatsClock-Init 36260 . 37191) (VStatsClock-ReDisplay 37193 . 39148) (VStatsClock-Read 39150 . 39688)
 (VStatsClock-Ticks? 39690 . 40266) (VStatsClock-UnpackDate 40268 . 44747)) (44949 53340 (
VStatsSpace-Display 44959 . 46169) (VStatsSpace-Init 46171 . 47360) (VStatsSpace-InitDisk 47362 . 
49153) (VStatsSpace-InitPanicLevel 49155 . 49901) (VStatsSpace-ReDisplay 49903 . 51082) (
VStatsSpace-Read 51084 . 52298) (VStatsSpace-ShrinkInterval 52300 . 52960) (VStatsSpace-Ticks? 52962
 . 53338)) (53517 60835 (VStatsMUtil-Display 53527 . 54737) (VStatsMUtil-Init 54739 . 56000) (
VStatsMUtil-InitState 56002 . 57594) (VStatsMUtil-ReDisplay 57596 . 58184) (VStatsMUtil-Read 58186 . 
60456) (VStatsMUtil-Ticks? 60458 . 60833)) (60890 64587 (CLOCKTICKS 60900 . 61968) (ALTOPARTITIONS 
61970 . 62847) (DISKUSEDPAGES 62849 . 63925) (DISKTOTALPAGES 63927 . 64585)) (64684 65590 (
VStats-TOPWP 64694 . 65588)))))
STOP