(FILECREATED "14-AUG-83 17:00:37" {PHYLUM}<LISPCORE>SOURCES>DMISC.;59 32797  

      changes to:  (FNS \DIRTYBACKGROUND \SAVEVMBACKGROUND)
		   (VARS DMISCCOMS)

      previous date: " 7-AUG-83 17:08:26" {PHYLUM}<LISPCORE>SOURCES>DMISC.;58)


(* Copyright (c) 1982, 1983 by Xerox Corporation)

(PRETTYCOMPRINT DMISCCOMS)

(RPAQQ DMISCCOMS [(COMS (FNS TENEX))
		  [COMS (FNS BACKSPACEDEL)
			(DECLARE: DOCOPY DONTEVAL@LOAD (P (BACKSPACEDEL \ORIGTERMTABLE)
							  (BACKSPACEDEL NIL]
		  (COMS (* timeall functions)
			(FNS TIMEALL COPYMISCSTATS COPYTIMESTATS CREATEMISCSTATS DIFFMISCSTATS 
			     DIFFTIMESTATS PRINTMISCSTATS PRINTMISCSTATSITEM)
			(DECLARE: DONTCOPY (RECORDS STATSOBJECT)))
		  [COMS (FNS PERIODICALLYRECLAIM)
			[INITVARS (RECLAIMWAIT 4)
				  (\LASTRECLAIM (\DAYTIME0 (NCREATE (QUOTE FIXP]
			(DECLARE: DONTEVAL@LOAD DOCOPY (APPENDVARS (BACKGROUNDFNS PERIODICALLYRECLAIM]
		  [COMS (* should flush, maybe)
			(FNS WAITFORINPUT \WAITFORSYSBUFP)
			(GLOBALRESOURCES (\DISMISSBOX (CREATECELL \FIXP]
		  (FNS APROPOS)
		  (COMS (FNS \DIRTYBACKGROUND \SAVEVMBACKGROUND \HOWMANYPAGES)
			(INITVARS (BACKGROUNDPAGEMIN 40)
				  (BACKGROUNDPAGECNT 0)
				  (BACKGROUNDPAGEFREQ 4))
			(INITVARS (SAVINGCURSOR)
				  (SAVEVMMAX 600)
				  (SAVEVMWAIT 300))
			(ADDVARS (BACKGROUNDFNS \DIRTYBACKGROUND)
				 (TTYBACKGROUNDFNS \SAVEVMBACKGROUND))
			(GLOBALVARS BACKGROUNDPAGEMIN BACKGROUNDPAGEFREQ BACKGROUNDPAGECNT))
		  (COMS (* Setting the time)
			(FNS SETTIME))
		  [COMS (* functions for turning the display off.)
			(FNS DISPLAYDOWN SETDISPLAYHEIGHT VIDEORATE)
			(INITVARS (\VIDEORATE (QUOTE NORMAL)))
			(DECLARE: DONTEVAL@LOAD DOCOPY (ADDVARS (BREAKRESETFORMS (SETDISPLAYHEIGHT
										   T))
								(RESETFORMS (SETDISPLAYHEIGHT T]
		  (DECLARE: DONTEVAL@LOAD DOCOPY (VARS (#EOLCHARS 1))
			    [P (OR (LISTP (EVALV (QUOTE EDITCHARACTERS)))
				   (RPAQ EDITCHARACTERS (QUOTE (J X Z Y N]
			    (ADDVARS (POSTGREETFORMS (CNDIR))
				     (LISPUSERSDIRECTORIES)))
		  [COMS (PROP VARTYPE BAKTRACELST)
			(ALISTS (BREAKMACROS BT BTV BTVPP BT!)
				(BAKTRACELST EVAL APPLY))
			(DECLARE: DONTEVAL@LOAD DOCOPY (INITVARS (CLEANUPOPTIONS (QUOTE (RC]
		  (COMS (PROP ARGNAMES MISSPELLED?)
			(ADVISE MISSPELLED?-IN-FNCHECK))
		  (COMS (ADVISE LOGOUT)
			(ADDVARS (BEFORELOGOUTFORMS)
				 (AFTERLOGOUTFORMS)))
		  (DECLARE: DONTEVAL@LOAD DOCOPY (INITVARS (ADVISEDFNS)))
		  [COMS (* from FASTARRAYS)
			(FNS POINTERARRAY WORDARRAY FIXPARRAY)
			(P (MAPC (QUOTE ((ELT FASTELT FASTELTN FASTELTW)
					 (SETA FASTSETA FASTSETAN FASTSETAW)
					 (GETHASH IGETHASH)
					 (PUTHASH IPUTHASH)))
				 (FUNCTION (LAMBDA (X)
						   (MAPC (CDR X)
							 (FUNCTION (LAMBDA (Y)
									   (MOVD? (CAR X)
										  Y]
		  (COMS (* Versions etc)
			(FNS REALMEMORYSIZE LISPVERSION MICROCODEVERSION BCPLVERSION REQUIREVERSION))
		  (COMS (* Misc ops)
			(FNS READPRINTERPORT WRITEPRINTERPORT \MISC1.UFN \MISC2.UFN))
		  [COMS (* printer stuff)
			(FNS PRINTERMODE LISTFILES)
			(PROP VARTYPE PRINTERMODES)
			(ALISTS (PRINTERMODES NONE))
			(DECLARE: DONTEVAL@LOAD DOCOPY (P (PRINTERMODE (QUOTE NONE]
		  (LOCALVARS . T)
		  (DECLARE: DONTEVAL@LOAD DOEVAL@COMPILE DONTCOPY COMPILERVARS (ADDVARS (NLAMA 
											LISTFILES)
											(NLAML 
											  TIMEALL)
											(LAMA])
(DEFINEQ

(TENEX
  [LAMBDA (STR)                                              (* lmm "29-APR-81 10:40")
    (RESETLST (PROG (REM.CM)
		    (SETQ REM.CM (OPENFILE (QUOTE {DSK}REM.CM;1)
					   (QUOTE OUTPUT)))
		    (RESETSAVE NIL (LIST [FUNCTION (LAMBDA (X)
					     (AND RESETSTATE (PROGN (CLOSEF? X)
								    (CLOSEF (OPENFILE X (QUOTE OUTPUT]
					 REM.CM))
		    (PRIN3 STR REM.CM)
		    (PRIN3 "
LISP.run
" REM.CM)
		    (CLOSEF REM.CM)
		    (LOGOUT])
)
(DEFINEQ

(BACKSPACEDEL
  [LAMBDA (TTBL)                                             (* lmm "24-JUN-80 23:16")

          (* Hack for causing char-delete to backspace display. Also suppress ## when reach the left margin.
	  -
	  This should be executed after the chardelete in TTBL has been established. -
	  ERASECHARCODE is in INITCONSTANTS on LLPARAMS)


    (DELETECONTROL (QUOTE 1STCHDEL)
		   (CHARACTER ERASECHARCODE)
		   TTBL)
    (DELETECONTROL (QUOTE NTHCHDEL)
		   (CHARACTER ERASECHARCODE)
		   TTBL)
    (DELETECONTROL (QUOTE POSTCHDEL)
		   "" TTBL)
    (DELETECONTROL (QUOTE EMPTYCHDEL)
		   "" TTBL)
    (DELETECONTROL (QUOTE NOECHO)
		   NIL TTBL)
    (ECHOCONTROL ERASECHARCODE (QUOTE REAL])
)
(DECLARE: DOCOPY DONTEVAL@LOAD 
(BACKSPACEDEL \ORIGTERMTABLE)
(BACKSPACEDEL NIL)
)



(* timeall functions)

(DEFINEQ

(TIMEALL
  [NLAMBDA (TIMEFORM NUMBEROFTIMES TIMEWHAT INTERPFLG SHOWCODE)
                                                             (* bvm: "10-MAR-83 12:58")

          (* collects and prints stats on TIMEFORM. TIMEWHAT indicates what to collect stats on: if T, all of the system 
	  times are collected; if NIL, the system times plus all data allocations are kept; if a list, it should be a list 
	  of DATATYPES (or numbers) and may include the atom TIME if system times should be included.
	  This function sets the variables BEFORESTATS, AFTERSTATS and DIFFERENCESTATS to the values of the stats objects 
	  before, after and the difference between them. These can be examined via the function PRINTMISCSTATS.)


    (DECLARE (GLOBALVARS BEFORESTATS AFTERSTATS DIFFERENCESTATS DFNFLG OPTIMIZATIONSOFF)
	     (SPECVARS LCFIL STRF LAPFLG))
    (PROG [VALUE (TIMEFLG (OR (NULL TIMEWHAT)
			      (EQ TIMEWHAT T)
			      (MEMB (QUOTE TIME)
				    TIMEWHAT)))
		 (DATATYPES (COND
			      ((NULL TIMEWHAT)
				(DATATYPES))
			      ((EQ TIMEWHAT T)
				NIL)
			      (T (for X inside TIMEWHAT bind NAME
				    join (COND
					   ((SETQ NAME (DATATYPEP X))
					     (CONS NAME))
					   ((EQ X (QUOTE TIME))
					     NIL)
					   (T (printout T X " is not a datatype." T)
					      NIL]           (* create all necessary storage before performing test 
							     form.)
          (OR (NUMBERP NUMBEROFTIMES)
	      (SETQ NUMBEROFTIMES 1))
          [COND
	    ([OR (NLISTP AFTERSTATS)
		 (NOT (EQUAL DATATYPES (fetch DATATYPES of AFTERSTATS]
	      (SETQ DIFFERENCESTATS (CREATEMISCSTATS DATATYPES TIMEFLG))
	      (SETQ BEFORESTATS (CREATEMISCSTATS DATATYPES TIMEFLG))
	      (SETQ AFTERSTATS (CREATEMISCSTATS DATATYPES TIMEFLG]
          [COND
	    [(OR INTERPFLG (EQ NUMBEROFTIMES 1))
	      (COPYMISCSTATS BEFORESTATS DATATYPES)
	      (SETQ VALUE (FRPTQ NUMBEROFTIMES (EVAL TIMEFORM]
	    (T [RESETVARS ((DFNFLG T)
			   (OPTIMIZATIONSOFF T))
		          (PROG ((STRF T)
				 (LCFIL)
				 (LAPFLG SHOWCODE))
			        (COMPILE1 (QUOTE TIMEDUMMYFUNCTION)
					  (LIST (QUOTE LAMBDA)
						NIL
						(LIST (QUOTE FRPTQ)
						      NUMBEROFTIMES TIMEFORM]
	       (COPYMISCSTATS BEFORESTATS DATATYPES)
	       (SETQ VALUE (TIMEDUMMYFUNCTION]
          (COPYMISCSTATS AFTERSTATS DATATYPES T)
          (PRINTMISCSTATS (DIFFMISCSTATS BEFORESTATS AFTERSTATS DIFFERENCESTATS)
			  DATATYPES)
          (RETURN VALUE])

(COPYMISCSTATS
  [LAMBDA (STATS DATATYPES BEFOREFLG)                        (* bvm: "28-MAR-82 22:00")

          (* smashes the fields of STATS to be the current values of stats in the system. BEFOREFLG indicates whether 
	  elapsed time should be taken before or after the bulk of the work.)


    (DECLARE (GLOBALVARS \MISCSTATS))
    [COND
      (BEFOREFLG (CLOCK0 (fetch ELAPSEDTIME of STATS))
		 (for TYPE in DATATYPES as X on (fetch DATACOUNTERS of STATS)
		    do (RPLACA X (BOXCOUNT TYPE]
    (AND (fetch TIMEBLOCK of STATS)
	 (COPYTIMESTATS \MISCSTATS (fetch TIMEBLOCK of STATS)))
    (COND
      ((NOT BEFOREFLG)
	(for TYPE in DATATYPES as X on (fetch DATACOUNTERS of STATS) do (RPLACA X (BOXCOUNT TYPE)))
	(CLOCK0 (fetch ELAPSEDTIME of STATS])

(COPYTIMESTATS
  [LAMBDA (REFSTATS STATS)                                   (* bvm: "28-MAR-82 21:57")
    (replace SWAPWAITTIME of STATS with (fetch SWAPWAITTIME of REFSTATS))
    (replace KEYBOARDWAITTIME of STATS with (fetch KEYBOARDWAITTIME of REFSTATS))
    (replace GCTIME of STATS with (fetch GCTIME of REFSTATS))
    (replace PAGEFAULTS of STATS with (fetah PAGEFAULTS of REFSTATS))
    (replace SWAPWRITES of STATS with (fetch SWAPWRITES of REFSTATS))
    (replace TOTALTIME of STATS with (fetch TOTALTIME of REFSTATS))
    (replace STARTTIME of STATS with (fetch STARTTIME of REFSTATS))
    (replace DISKIOTIME of STATS with (fetch DISKIOTIME of REFSTATS))
    (replace NETIOTIME of STATS with (fetch NETIOTIME of REFSTATS))
    (replace DISKIOOPS of STATS with (fetch DISKIOOPS of REFSTATS))
    (replace NETIOOPS of STATS with (fetch NETIOOPS of REFSTATS])

(CREATEMISCSTATS
  [LAMBDA (DATATYPES TIMEBLOCKFLG)                           (* bvm: " 6-OCT-82 15:28")
                                                             (* creates a stats object for the types datatypes.)
    (create STATSOBJECT
	    ELAPSEDTIME ←(CLOCK 0)
	    TIMEBLOCK ←(AND TIMEBLOCKFLG (create MISCSTATS))
	    DATACOUNTERS ←(APPEND DATATYPES)
	    DATATYPES ← DATATYPES])

(DIFFMISCSTATS
  [LAMBDA (BEFORE AFTER DIFFERENCES)                         (* bvm: " 6-OCT-82 15:30")
                                                             (* puts the differences between two stats objects in a 
							     third stats object.)
    [for D on (fetch DATACOUNTERS of DIFFERENCES) as B in (fetch DATACOUNTERS of BEFORE)
       as A in (fetch DATACOUNTERS of AFTER) as TYPE in (fetch DATATYPES of DIFFERENCES)
       bind (LARGECNT ← 0)
	    LARGECNTTAIL
       do (COND
	    ((EQ TYPE (QUOTE FIXP))
	      (SETQ LARGECNTTAIL D)))
	  (OR (SMALLP (COND
			(LARGECNTTAIL B)
			(T A)))
	      (add LARGECNT 2))

          (* The BOXCOUNT in COPYMISCSTATS for this datatype came out large, and thus did 2 number boxes 
	  (one to fetch main count, one to add in aux cnt), counted in the stats period)


	  (FRPLACA D (IDIFFERENCE A B))
       finally (COND
		 ((AND (IGREATERP LARGECNT 0)
		       LARGECNTTAIL)                         (* Adjust FIXP count to take into account all BOXCOUNT's
							     that used up largep's)
		   (FRPLACA LARGECNTTAIL (IDIFFERENCE (CAR LARGECNTTAIL)
						      LARGECNT]
    (replace ELAPSEDTIME of DIFFERENCES with (IDIFFERENCE (fetch ELAPSEDTIME of AFTER)
							  (fetch ELAPSEDTIME of BEFORE)))
    (AND (fetch TIMEBLOCK of BEFORE)
	 (fetch TIMEBLOCK of AFTER)
	 (fetch TIMEBLOCK of DIFFERENCES)
	 (DIFFTIMESTATS (fetch TIMEBLOCK of BEFORE)
			(fetch TIMEBLOCK of AFTER)
			(fetch TIMEBLOCK of DIFFERENCES)))
    DIFFERENCES])

(DIFFTIMESTATS
  [LAMBDA (BEFOREBLOCK AFTERBLOCK DIFFERENCESBLOCK)          (* bvm: "28-MAR-82 21:58")
                                                             (* copies the difference between two stats blocks into a
							     third stats block.)
    (replace SWAPWAITTIME of DIFFERENCESBLOCK with (IDIFFERENCE (fetch SWAPWAITTIME of AFTERBLOCK)
								(fetch SWAPWAITTIME of BEFOREBLOCK)))
    (replace KEYBOARDWAITTIME of DIFFERENCESBLOCK with (IDIFFERENCE (fetch KEYBOARDWAITTIME
								       of AFTERBLOCK)
								    (fetch KEYBOARDWAITTIME
								       of BEFOREBLOCK)))
    (replace GCTIME of DIFFERENCESBLOCK with (IDIFFERENCE (fetch GCTIME of AFTERBLOCK)
							  (fetch GCTIME of BEFOREBLOCK)))
    (replace PAGEFAULTS of DIFFERENCESBLOCK with (IDIFFERENCE (fetch PAGEFAULTS of AFTERBLOCK)
							      (fetch PAGEFAULTS of BEFOREBLOCK)))
    (replace SWAPWRITES of DIFFERENCESBLOCK with (IDIFFERENCE (fetch SWAPWRITES of AFTERBLOCK)
							      (fetch SWAPWRITES of BEFOREBLOCK)))
    (replace TOTALTIME of DIFFERENCESBLOCK with (IDIFFERENCE (fetch TOTALTIME of AFTERBLOCK)
							     (fetch TOTALTIME of BEFOREBLOCK)))
    (replace STARTTIME of DIFFERENCESBLOCK with (IDIFFERENCE (fetch STARTTIME of AFTERBLOCK)
							     (fetch STARTTIME of BEFOREBLOCK)))
    (replace DISKIOTIME of DIFFERENCESBLOCK with (IDIFFERENCE (fetch DISKIOTIME of AFTERBLOCK)
							      (fetch DISKIOTIME of BEFOREBLOCK)))
    (replace NETIOTIME of DIFFERENCESBLOCK with (IDIFFERENCE (fetch NETIOTIME of AFTERBLOCK)
							     (fetch NETIOTIME of BEFOREBLOCK)))
    (replace DISKIOOPS of DIFFERENCESBLOCK with (IDIFFERENCE (fetch DISKIOOPS of AFTERBLOCK)
							     (fetch DISKIOOPS of BEFOREBLOCK)))
    (replace NETIOOPS of DIFFERENCESBLOCK with (IDIFFERENCE (fetch NETIOOPS of AFTERBLOCK)
							    (fetch NETIOOPS of BEFOREBLOCK)))
    DIFFERENCESBLOCK])

(PRINTMISCSTATS
  [LAMBDA (STATS DATATYPES)                                  (* bvm: " 6-JAN-83 18:13")
                                                             (* prints the fields of MISCSTATS)
    [PROG ((CPUTIME (fetch ELAPSEDTIME of STATS)))
          (PRINTMISCSTATSITEM "Elapsed Time" CPUTIME T)
          (COND
	    ((fetch TIMEBLOCK of STATS)                      (* printout time stats)
	      (PROG ((STATSBLOCK (fetch TIMEBLOCK of STATS))
		     MSECS)
		    [SETQ CPUTIME (IDIFFERENCE CPUTIME (SETQ MSECS (fetch SWAPWAITTIME of STATSBLOCK]
		    (PRINTMISCSTATSITEM "SWAP time" MSECS T)
		    [SETQ CPUTIME (IDIFFERENCE CPUTIME (SETQ MSECS (fetch KEYBOARDWAITTIME
								      of STATSBLOCK]
		    (PRINTMISCSTATSITEM "KEYWAIT time" MSECS T)
		    [SETQ CPUTIME (IDIFFERENCE CPUTIME (SETQ MSECS (fetch GCTIME of STATSBLOCK]
		    (PRINTMISCSTATSITEM "GC time" MSECS T)
		    [SETQ CPUTIME (IDIFFERENCE CPUTIME (SETQ MSECS (fetch DISKIOTIME of STATSBLOCK]
		    (PRINTMISCSTATSITEM "Disk i/o time" MSECS T)
		    (PRINTMISCSTATSITEM "CPU Time" CPUTIME T)
		    (PRINTMISCSTATSITEM (QUOTE PAGEFAULTS)
					(fetch PAGEFAULTS of STATSBLOCK))
		    (PRINTMISCSTATSITEM (QUOTE SWAPWRITES)
					(fetch SWAPWRITES of STATSBLOCK))
		    (PRINTMISCSTATSITEM (QUOTE DISKOPS)
					(fetch DISKOPS of STATSBLOCK))
		    (PRINTMISCSTATSITEM (QUOTE NETIOTIME)
					(fetch NETIOTIME of STATSBLOCK)
					T)
		    (PRINTMISCSTATSITEM (QUOTE NETIOOPS)
					(fetch NETIOOPS of STATSBLOCK]
                                                             (* construct a list of the elements that will fit on one
							     line.)
    (bind PRINTABLES RESULT COL←0
	  (LINELENGTH ←(LINELENGTH)) for DT in DATATYPES as DIF in (fetch DATACOUNTERS of STATS)
       unless (EQ DIF 0)
       do [COND
	    ((IGREATERP (SETQ COL (IPLUS COL (NCHARS DT)))
			LINELENGTH)                          (* line break)
	      (SETQ PRINTABLES (NCONC1 PRINTABLES (DREVERSE RESULT)))
	      (SETQ RESULT)
	      (SETQ COL (NCHARS DT]
	  (SETQ RESULT (CONS (CONS (add COL 1)
				   (CONS DT DIF))
			     RESULT))
       finally [COND
		 (RESULT (SETQ PRINTABLES (NCONC1 PRINTABLES (DREVERSE RESULT]
	       (for LINE in PRINTABLES
		  do (for PR in LINE
			do (LISPXPRIN1 (CADR PR)
				       T)                    (* Print datatype names)
			   (LISPXTAB (CAR PR)
				     NIL T))
		     (LISPXTERPRI T)
		     (for PR in LINE
			do (LISPXPRIN2 (CDDR PR)
				       T)                    (* Print amount used)
			   (LISPXTAB (CAR PR)
				     NIL T))
		     (LISPXTERPRI T])

(PRINTMISCSTATSITEM
  [LAMBDA (STR NUM TIMEFLG)                                  (* bvm: "26-MAR-82 16:25")
    (COND
      ((NOT (EQP NUM 0))
	(LISPXPRIN1 STR T)
	(LISPXPRIN1 " = ")
	(COND
	  (TIMEFLG (LISPXTAB 16 0 T)
		   (PRINTNUM (QUOTE (FLOAT 9 NIL NIL NIL 3))
			     (SETQ NUM (FQUOTIENT NUM 1000.0))
			     T)                              (* 3 significant digits)
		   (LISPXPRIN2 NUM T T T)                    (* Record on history without printing)
		   (LISPXPRIN1 " seconds" T))
	  (T (LISPXPRIN2 NUM T)))
	(LISPXTERPRI T])
)
(DECLARE: DONTCOPY 
[DECLARE: EVAL@COMPILE 

(RECORD STATSOBJECT (ELAPSEDTIME TIMEBLOCK DATACOUNTERS . DATATYPES))
]
)
(DEFINEQ

(PERIODICALLYRECLAIM
  [LAMBDA NIL                                                (* bvm: "21-JUL-83 16:49")
    (DECLARE (GLOBALVARS \RECLAIM.COUNTDOWN \LASTUSERACTION RECLAIMWAIT \LASTRECLAIM))
    (PROG (LU)
          (if (AND \RECLAIM.COUNTDOWN (\SECONDSCLOCKGREATERP \LASTUSERACTION RECLAIMWAIT)
		   (\SECONDSCLOCKGREATERP \LASTRECLAIM RECLAIMWAIT))
	      then (RECLAIM)
		   (\DAYTIME0 \LASTRECLAIM])
)

(RPAQ? RECLAIMWAIT 4)

(RPAQ? \LASTRECLAIM (\DAYTIME0 (NCREATE (QUOTE FIXP))))
(DECLARE: DONTEVAL@LOAD DOCOPY 

(APPENDTOVAR BACKGROUNDFNS PERIODICALLYRECLAIM)
)



(* should flush, maybe)

(DEFINEQ

(WAITFORINPUT
  [LAMBDA (N)                                                (* bvm: "30-JUN-81 10:42")
    (COND
      [(FIXP N)
	(GLOBALRESOURCE (\DISMISSBOX)
            (PROG ((NOW (CLOCK0 \DISMISSBOX))
		   (N-100 (IDIFFERENCE N 100))
		   ELAPSED)
	      LP  (COND
		    ((READP T)
		      (RETURN T))
		    ((IGREATERP (SETQ ELAPSED (CLOCKDIFFERENCE NOW))
				N)                           (* Time's up, return with no input)
		      (RETURN))
		    ((ILESSP ELAPSED N-100)                  (* only run background task if at least 100 msecs left)
		      (\TTYBACKGROUND)))
	          (GO LP)))]
      (N                                                     (* Getting OFD avoids time wasted in directory search, 
							     leaves more time for \TTYBACKGROUND)
	 (bind (OFD ←(\GETOFD N (QUOTE INPUT))) until (OR (READP T)
							  (READP OFD))
	    do (\TTYBACKGROUND)))
      (T (until (READP T) do (\TTYBACKGROUND])

(\WAITFORSYSBUFP
  [LAMBDA (N)                                                (* bvm: "21-JUL-83 14:06")
    (COND
      [(FIXP N)
	(GLOBALRESOURCE (\DISMISSBOX)
			(PROG ((NOW (CLOCK0 \DISMISSBOX)))
			  LP  (COND
				((\SYSBUFP)
				  (RETURN T))
				((NOT (TTY.PROCESSP))
				  (\WAIT.FOR.TTY))
				((IGREATERP (CLOCKDIFFERENCE NOW)
					    N)               (* Time's up, return with no input)
				  (RETURN))
				(T (BLOCK)))
			      (GO LP]
      (T (until (\SYSBUFP)
	    do (BLOCK)
	       (\WAIT.FOR.TTY])
)

(RPAQQ \DISMISSBOX NIL)
(DECLARE: DOEVAL@COMPILE DONTCOPY

(ADDTOVAR GLOBALVARS \DISMISSBOX)
)
(DECLARE: DOEVAL@COMPILE DONTCOPY 
(PUTDEF (QUOTE \DISMISSBOX)
	(QUOTE GLOBALRESOURCES)
	(QUOTE (CREATECELL \FIXP)))
)
(DEFINEQ

(APROPOS
  [LAMBDA (STRING ALLFLG)                                    (* lmm " 3-JUN-83 01:08")
    (MAPATOMS (FUNCTION (LAMBDA (ATOM)                       (* Gregor "24-MAR-83 09:23")
		  (COND
		    ([AND (OR (GETD ATOM)
			      (NEQ (GETATOMVAL ATOM)
				   (QUOTE NOBIND))
			      (GETPROPLIST ATOM))
			  (STRPOS STRING ATOM)
			  (OR ALLFLG (AND (NOT (GENSYM? ATOM))
					  (NEQ (CHCON1 ATOM)
					       (CHARCODE \]
		      (COND
			((GETD ATOM)
			  (printout T "A Function - " ATOM , (ARGLIST ATOM)
				    T)))
		      [COND
			((BOUNDP ATOM)
			  (RESETFORM (PRINTLEVEL 3 3)
				     (printout T "A Variable - " ATOM , .P2 (EVALV ATOM)
					       T]
		      (COND
			((GETPROPLIST ATOM)
			  (PRINTOUT T "Properties " ATOM , .P2 (PROPNAMES ATOM)
				    T])
)
(DEFINEQ

(\DIRTYBACKGROUND
  [LAMBDA NIL                                                (* lmm "14-AUG-83 16:08")
    (DECLARE (GLOBALVARS SAVEVMMAX \LASTUSERACTION SAVEVMWAIT SAVINGCURSOR \DIRTYPAGEHINT))
    (COND
      ((AND BACKGROUNDPAGEFREQ (ILEQ (add BACKGROUNDPAGECNT -1)
				     0))
	(\WRITEDIRTYPAGE BACKGROUNDPAGEMIN)
	(SETQ BACKGROUNDPAGECNT BACKGROUNDPAGEFREQ])

(\SAVEVMBACKGROUND
  [LAMBDA NIL                                                (* lmm "14-AUG-83 16:55")
    (COND
      ((AND (ILESSP \DIRTYPAGEHINT SAVEVMMAX)
	    (NEQ (fetch (IFPAGE Key) of \InterfacePage)
		 \IFPValidKey)
	    (FIXP SAVEVMWAIT)
	    (ILESSP (SETQ \DIRTYPAGEHINT (\HOWMANYPAGES (QUOTE DIRTY)))
		    SAVEVMMAX)
	    (\SECONDSCLOCKGREATERP \LASTUSERACTION SAVEVMWAIT))
	(RESETLST (AND SAVINGCURSOR (GETD (QUOTE CURSOR))
		       (RESETSAVE (CURSOR SAVINGCURSOR)))
		  (SAVEVM])

(\HOWMANYPAGES
  [LAMBDA (FLG)                                              (* bvm: "18-FEB-82 23:05")
    (\NPAGESBIT (SELECTQ FLG
			 (DIRTY 1)
			 (REF 0)
			 (LOCKED 2)
			 (OR (SMALLP FLG)
			     (\ILLEGAL.ARG FLG])
)

(RPAQ? BACKGROUNDPAGEMIN 40)

(RPAQ? BACKGROUNDPAGECNT 0)

(RPAQ? BACKGROUNDPAGEFREQ 4)

(RPAQ? SAVINGCURSOR )

(RPAQ? SAVEVMMAX 600)

(RPAQ? SAVEVMWAIT 300)

(ADDTOVAR BACKGROUNDFNS \DIRTYBACKGROUND)

(ADDTOVAR TTYBACKGROUNDFNS \SAVEVMBACKGROUND)
(DECLARE: DOEVAL@COMPILE DONTCOPY

(ADDTOVAR GLOBALVARS BACKGROUNDPAGEMIN BACKGROUNDPAGEFREQ BACKGROUNDPAGECNT)
)



(* Setting the time)

(DEFINEQ

(SETTIME
  [LAMBDA (DT)                                               (* bvm: " 1-SEP-14 21:59")
    (PROG [(IDT (COND
		  [DT (LISP.TO.ALTO.DATE (OR (IDATE DT)
					     (ERROR "Invalid date" DT]
		  (T (NETDAYTIME0]
      RETRY
          [COND
	    ((NOT IDT)
	      (printout T "Enter date and time as string in double quotes: ")
	      (COND
		([SETQ IDT (IDATE (OR (SETQ DT (READ T T))
				      (RETURN "time not set"]
		  (SETQ IDT (LISP.TO.ALTO.DATE IDT)))
		(T (printout T "Sorry, couldn't parse that" T)
		   (GO RETRY]
          (\SETDAYTIME0 (COND
			  ((SMALLP IDT)
			    (create FIXP
				    HINUM ←(\HINUM IDT)
				    LONUM ←(\LONUM IDT)))
			  (T IDT)))
          (RETURN (DATE])
)



(* functions for turning the display off.)

(DEFINEQ

(DISPLAYDOWN
  [LAMBDA (FORM NSCANLINES)                                  (* rrb "27-MAR-82 12:23")
                                                             (* evaluates form with the number of scan lines set 
							     down.)
    (RESETFORM (SETDISPLAYHEIGHT (OR (SMALLP NSCANLINES)
				     0))
	       (EVAL FORM])

(SETDISPLAYHEIGHT
  [LAMBDA (NSCANLINES)
    (DECLARE (GLOBALVARS \DisplayStarted \EM.DISPLAYHEAD))   (* bvm: " 5-JAN-83 18:48")
                                                             (* sets the number of scan lines to be displayed.)
                                                             (* returns previous setting.)
                                                             (* the number of lines in the dcb is 1/2 of the total.
							     High bit is on to indicate long pointers.)
    (OR \DisplayStarted (HELP "Display must be initialized."))
    (AND \EM.DISPLAYHEAD (PROG [(MAGICADDR (EMPOINTER (IPLUS (\GETBASE \EM.DISPLAYHEAD 0)
							     3]
			       (RETURN (PROG1 (ITIMES [LOGAND (\GETBASE MAGICADDR 0)
							      (CONSTANT (SUB1 (EXPT 2 (SUB1 
										      BITSPERWORD]
						      2)     (* number of dcb lines may need to be even.)
					      (COND
						(NSCANLINES (COND
							      [(SMALLP NSCANLINES)
								(COND
								  ((IGREATERP 0 NSCANLINES)
								    (\ILLEGAL.ARG NSCANLINES))
								  ((IGREATERP NSCANLINES SCREENHEIGHT)
								    (SETQ NSCANLINES SCREENHEIGHT]
							      ((EQ NSCANLINES T)
								(SETQ NSCANLINES SCREENHEIGHT))
							      (T (\ILLEGAL.ARG NSCANLINES)))
							    (\PUTBASE
							      MAGICADDR 0
							      (LOGOR (ITIMES (LRSH NSCANLINES 2)
									     2)
								     (CONSTANT (EXPT 2 (SUB1 
										      BITSPERWORD])

(VIDEORATE
  [LAMBDA (TYPE)                                             (* bvm: " 7-AUG-83 17:08")
    (DECLARE (GLOBALVARS \VIDEORATE))
    (PROG1 \VIDEORATE                                        (* Return old setting)
	   (AND TYPE (SETQ \VIDEORATE (SELECTC \MACHINETYPE
					       (\DOLPHIN (SELECTQ TYPE
								  ((NORMAL 77)
								    (\DSPRATE 9)
								    (QUOTE NORMAL))
								  ((TAPE 60)
								    (\DSPRATE 139)
								    (QUOTE TAPE))
								  (\ILLEGAL.ARG TYPE)))
					       (\DORADO (SELECTQ TYPE
								 ((NORMAL 77)
								   (\DSPRATE 18 14 430)
								   (QUOTE NORMAL))
								 ((TAPE 60)
								   (\DSPRATE 18 14 560)
								   (QUOTE TAPE))
								 ((PHILLIPS TAPEP)
								   (\DSPRATE 58 25 520)
								   (QUOTE PHILLIPS))
								 (\ILLEGAL.ARG TYPE)))
					       (\DANDELION (SELECTQ TYPE
								    ((NORMAL 77)
								      (\DEVICE.OUTPUT 14 7)
								      (QUOTE NORMAL))
								    ((TAPE 60)
								      (\DEVICE.OUTPUT 142 7)
								      (QUOTE TAPE))
								    (\ILLEGAL.ARG TYPE)))
					       (QUOTE NORMAL])
)

(RPAQ? \VIDEORATE (QUOTE NORMAL))
(DECLARE: DONTEVAL@LOAD DOCOPY 

(ADDTOVAR BREAKRESETFORMS (SETDISPLAYHEIGHT T))

(ADDTOVAR RESETFORMS (SETDISPLAYHEIGHT T))
)
(DECLARE: DONTEVAL@LOAD DOCOPY 

(RPAQQ #EOLCHARS 1)

[OR (LISTP (EVALV (QUOTE EDITCHARACTERS)))
    (RPAQ EDITCHARACTERS (QUOTE (J X Z Y N]


(ADDTOVAR POSTGREETFORMS (CNDIR))

(ADDTOVAR LISPUSERSDIRECTORIES )
)

(PUTPROPS BAKTRACELST VARTYPE ALIST)

(ADDTOVAR BREAKMACROS (BT (BAKTRACE LASTPOS NIL (BREAKREAD (QUOTE LINE))
				    0 T))
		      (BTV (BAKTRACE LASTPOS NIL (BREAKREAD (QUOTE LINE))
				     1 T))
		      (BTVPP (PROG ((SYSPRETTYFLG T))
				   (BAKTRACE LASTPOS NIL (CONS (QUOTE DUMMYFRAMEP)
							       (BREAKREAD (QUOTE LINE)))
					     1 T)))
		      (BT! (BAKTRACE LASTPOS NIL (BREAKREAD (QUOTE LINE))
				     0 T)))

(ADDTOVAR BAKTRACELST (EVAL (**BREAK** LISPX ERRORSET BREAK1A BREAK1)
			    (**TOP** LISPX ERRORSET EVALQT T)
			    (**EDITOR** ((MAPCAR APPLY)
					 (ERRORSET LISPX))
					ERRORSET ERRORSET ERRORSET EDITL1 EDITL0 ERRORSET
					((ERRORSET ERRORSET ERRORSET EDITL1 EDITL0 ERRORSET)
					 -)
					EDITL ERRORSET ERRORSET EDITE ((EDITF)
					 (EDITV)
					 (EDITP)
					 -))
			    (**USEREXEC** ERRORSET LISPX ERRORSET ERRORSET USEREXEC))
		      (APPLY (**BREAK** LISPX ERRORSET BREAK1A BREAK1)
			     (**TOP** LISPX ERRORSET EVALQT T)
			     (**EDITOR** LISPX ERRORSET ERRORSET ERRORSET EDITL1 EDITL0 ERRORSET
					 ((ERRORSET ERRORSET ERRORSET EDITL1 EDITL0 ERRORSET)
					  -)
					 EDITL ERRORSET ERRORSET EDITE ((EDITF)
					  (EDITV)
					  (EDITP)
					  -))
			     (**USEREXEC** LISPX ERRORSET ERRORSET USEREXEC)))
(DECLARE: DONTEVAL@LOAD DOCOPY 

(RPAQ? CLEANUPOPTIONS (QUOTE (RC)))
)

(PUTPROPS MISSPELLED? ARGNAMES (XWORD REL SPLST FLG TAIL FN))

(PUTPROPS MISSPELLED?-IN-FNCHECK READVICE [(FNCHECK . MISSPELLED?)
	   (BIND NIL (FILES BLOCK BLOCK/FN))
	   (BEFORE NIL (AND (EQ SPLST USERWORDS)
			    (SETQ FILES (WHEREIS XWORD))
			    [SOME FILES (FUNCTION (LAMBDA
						    (FL)
						    (SOME (OR (GETP FL (QUOTE FILEGROUP))
							      (LIST FL))
							  (FUNCTION
							    (LAMBDA
							      (FL)
							      (SOME (FILECOMSLST FL (QUOTE BLOCKS))
								    (FUNCTION
								      (LAMBDA
									(X)
									(AND (CAR (SETQ BLOCK X))
									     (MEMB XWORD BLOCK]
			    (GETD (SETQ BLOCK/FN (PACK* (QUOTE \)
							(CAR BLOCK)
							(QUOTE /)
							XWORD)))
			    (RETURN BLOCK/FN])
(READVISE MISSPELLED?-IN-FNCHECK)

(PUTPROPS LOGOUT ARGNAMES (FAST))

(PUTPROPS LOGOUT READVICE [NIL [BEFORE NIL (MAPC BEFORELOGOUTFORMS (FUNCTION (LAMBDA
									       (X)
									       (ERSETQ (EVAL X]
			       (AFTER NIL (MAPC AFTERLOGOUTFORMS (FUNCTION (LAMBDA
									     (X)
									     (ERSETQ (EVAL X])
(READVISE LOGOUT)

(ADDTOVAR BEFORELOGOUTFORMS )

(ADDTOVAR AFTERLOGOUTFORMS )
(DECLARE: DONTEVAL@LOAD DOCOPY 

(RPAQ? ADVISEDFNS )
)



(* from FASTARRAYS)

(DEFINEQ

(POINTERARRAY
  [LAMBDA (N INIT)                                           (* lmm " 4-DEC-80 16:58")
    (ARRAY N (QUOTE POINTER)
	   INIT 0])

(WORDARRAY
  [LAMBDA (N)                                                (* lmm " 4-DEC-80 16:58")
    (ARRAY N (QUOTE SMALLPOSP)
	   0 0])

(FIXPARRAY
  [LAMBDA (N)                                                (* lmm " 4-DEC-80 16:58")
    (ARRAY N (QUOTE FIXP)
	   0 0])
)
[MAPC (QUOTE ((ELT FASTELT FASTELTN FASTELTW)
	      (SETA FASTSETA FASTSETAN FASTSETAW)
	      (GETHASH IGETHASH)
	      (PUTHASH IPUTHASH)))
      (FUNCTION (LAMBDA (X)
			(MAPC (CDR X)
			      (FUNCTION (LAMBDA (Y)
						(MOVD? (CAR X)
						       Y]



(* Versions etc)

(DEFINEQ

(REALMEMORYSIZE
  [LAMBDA NIL                                                (* bvm: "19-JAN-83 17:06")
    (fetch NRealPages of \InterfacePage])

(LISPVERSION
  [LAMBDA NIL                                                (* bvm: "19-JAN-83 17:07")
    (fetch LVersion of \InterfacePage])

(MICROCODEVERSION
  [LAMBDA NIL                                                (* bvm: "19-JAN-83 17:07")
    (fetch RVersion of \InterfacePage])

(BCPLVERSION
  [LAMBDA NIL                                                (* bvm: "19-JAN-83 17:07")
    (fetch BVersion of \InterfacePage])

(REQUIREVERSION
  [LAMBDA (LISP MICROCODE BCPL)                              (* bvm: "19-JAN-83 17:15")
    (PROG (TYPE NEEDED)
          (RETURN (COND
		    ([SETQ TYPE (OR (AND LISP (LESSP (fetch LVersion of \InterfacePage)
						     (SETQ NEEDED LISP))
					 (QUOTE LISP))
				    (AND MICROCODE (LESSP (fetch RVersion of \InterfacePage)
							  (SETQ NEEDED MICROCODE))
					 (QUOTE MICROCODE))
				    (AND BCPL (LESSP (fetch BVersion of \InterfacePage)
						     (SETQ NEEDED BCPL))
					 (QUOTE BCPL]
		      (ERROR (CONCAT "This " TYPE 
				     " version is too old.  The minimum version required is ")
			     NEEDED)
		      NIL)
		    (T T])
)



(* Misc ops)

(DEFINEQ

(READPRINTERPORT
  [LAMBDA NIL                                                (* bvm: "18-JAN-83 18:06")
    ((OPCODES READPRINTERPORT])

(WRITEPRINTERPORT
  [LAMBDA (DATUM)                                            (* bvm: "18-JAN-83 18:06")
    ((OPCODES WRITEPRINTERPORT)
     DATUM])

(\MISC1.UFN
  [LAMBDA (ARG ALPHA)                                        (* bvm: "18-JAN-83 18:07")
    (RAID "Unimplemented MISC1 op" ALPHA])

(\MISC2.UFN
  [LAMBDA (ARG1 ARG2 ALPHA)                                  (* bvm: "18-JAN-83 18:07")
    (RAID "Unimplemented MISC2 op" ALPHA])
)



(* printer stuff)

(DEFINEQ

(PRINTERMODE
  [LAMBDA (MODE)                   (* lmm " 4-JUL-83 13:52")
    (PROG1 PRINTERMODE (COND
	     (MODE [for X in (CDR (OR (ASSOC MODE PRINTERMODES)
				      (LISPERROR "ILLEGAL ARG" MODE)))
		      do (COND
			   ((LISTP (CAR X))
			     (EVAL (CAR X)))
			   (T (SETTOPVAL (CAR X)
					 (CDR X]
		   (SETQ PRINTERMODE MODE])

(LISTFILES
  [NLAMBDA FILES                                             (* rmk: "13-JUN-82 23:53")
    (DECLARE (GLOBALVARS NOTLISTEDFILES FILELST))
    (for FILE FULLNAME in (OR FILES NOTLISTEDFILES)
       join (COND
	      [[SETQ FULLNAME (FINDFILE (COND
					  [(AND (MEMB FILE FILELST)
						(CDAR (LISTP (GETPROP FILE (QUOTE FILEDATES]
					  (T 

          (* User specified version number and/or directory, so list that file regardless of filedates property , or FILE is
	  not on FILELST, in which case ignore filedates.)


					     FILE]
		(COND
		  ((LISTFILES1 FULLNAME)
		    (SETQ NOTLISTEDFILES (REMOVE (NAMEFIELD FULLNAME T)
						 NOTLISTEDFILES))
		    (CONS FULLNAME]
	      (T (printout T FILE " not found." T])
)

(PUTPROPS PRINTERMODES VARTYPE ALIST)

(ADDTOVAR PRINTERMODES [NONE (PRINTER.BITMAPSCALE . NILL)
			     (PRINTER.BITMAPFILE . PROG2)
			     (PRINTER.SENDTOPRINTER . NILL)
			     ((MOVD (QUOTE NILL)
				    (QUOTE LISTFILES1])
(DECLARE: DONTEVAL@LOAD DOCOPY 
(PRINTERMODE (QUOTE NONE))
)
(DECLARE: DOEVAL@COMPILE DONTCOPY

(LOCALVARS . T)
)
(DECLARE: DONTEVAL@LOAD DOEVAL@COMPILE DONTCOPY COMPILERVARS 

(ADDTOVAR NLAMA LISTFILES)

(ADDTOVAR NLAML TIMEALL)

(ADDTOVAR LAMA )
)
(PUTPROPS DMISC COPYRIGHT ("Xerox Corporation" 1982 1983))
(DECLARE: DONTCOPY
  (FILEMAP (NIL (3299 3770 (TENEX 3309 . 3768)) (3771 4508 (BACKSPACEDEL 3781 . 4506)) (4622 16773 (
TIMEALL 4632 . 7158) (COPYMISCSTATS 7160 . 8027) (COPYTIMESTATS 8029 . 9125) (CREATEMISCSTATS 9127 . 
9537) (DIFFMISCSTATS 9539 . 11216) (DIFFTIMESTATS 11218 . 13409) (PRINTMISCSTATS 13411 . 16217) (
PRINTMISCSTATSITEM 16219 . 16771)) (16897 17337 (PERIODICALLYRECLAIM 16907 . 17335)) (17545 19060 (
WAITFORINPUT 17555 . 18521) (\WAITFORSYSBUFP 18523 . 19058)) (19280 20089 (APROPOS 19290 . 20087)) (
20090 21235 (\DIRTYBACKGROUND 20100 . 20482) (\SAVEVMBACKGROUND 20484 . 21002) (\HOWMANYPAGES 21004 . 
21233)) (21660 22389 (SETTIME 21670 . 22387)) (22441 25350 (DISPLAYDOWN 22451 . 22794) (
SETDISPLAYHEIGHT 22796 . 24248) (VIDEORATE 24250 . 25348)) (28330 28783 (POINTERARRAY 28340 . 28490) (
WORDARRAY 28492 . 28638) (FIXPARRAY 28640 . 28781)) (29065 30407 (REALMEMORYSIZE 29075 . 29236) (
LISPVERSION 29238 . 29394) (MICROCODEVERSION 29396 . 29557) (BCPLVERSION 29559 . 29715) (
REQUIREVERSION 29717 . 30405)) (30429 31049 (READPRINTERPORT 30439 . 30583) (WRITEPRINTERPORT 30585 . 
30743) (\MISC1.UFN 30745 . 30895) (\MISC2.UFN 30897 . 31047)) (31076 32216 (PRINTERMODE 31086 . 31444)
 (LISTFILES 31446 . 32214)))))
STOP