(DEFINE-FILE-INFO PACKAGE "INTERLISP" READTABLE "INTERLISP" BASE 10)
(FILECREATED " 4-Sep-87 07:32:05" |{MCS:MCS:STANFORD}<LANE>REMOTEPSW.;8| 19748  

      changes to%:  (VARS REMOTEPSWCOMS REMOTE.PROCESS.ERRORS)
                    (FNS REMOTE.PROCESS.ERROR \REMOTE.PSWOP.SELECTED \REMOTE.PROCESS.TTY)
                    (COURIERPROGRAMS PROCESS)

      previous date%: "26-Aug-87 12:15:04" |{MCS:MCS:STANFORD}<LANE>REMOTEPSW.;5|)


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

(PRETTYCOMPRINT REMOTEPSWCOMS)

(RPAQQ REMOTEPSWCOMS ((FNS REMOTE.PROCESS.STATUS.WINDOW)
                      (COURIERPROGRAMS PROCESS)
                      (DECLARE%: DONTCOPY (RECORDS PROCESSDATA REMOTE.PSW.MENUS)
                             (CONSTANTS (SELECTIONSHADE 520)))
                      (FNS REMOTE.PROCESS.BACKTRACE REMOTE.PSW.REDISPLAY REMOTE.PROCESS.ERROR 
                           \REMOTE.GET.PROCESS.DATA \REMOTE.PROCESS.BACKTRACE \REMOTE.PROCESS.KILL 
                           \REMOTE.PROCESS.RESTART \REMOTE.PROCESS.SUSPEND \REMOTE.PROCESS.TTY 
                           \REMOTE.PROCESS.WAKE \REMOTE.PSW.SELECTED \REMOTE.PSWOP.SELECTED)
                      (VARS REMOTE.PROCESS.ERRORS)
                      (GLOBALVARS REMOTE.PROCESS.ERRORS PROCOP.WAKEMENU)
                      (FILES COURIERDEFS)))
(DEFINEQ

(REMOTE.PROCESS.STATUS.WINDOW
  [LAMBDA (HOST)                                             (* ; "Edited 26-Aug-87 12:11 by cdl")

    (LET ((COURIERSTREAM (COURIER.OPEN HOST))
          (WINDOW (CREATEW (CREATEREGION 0 0 100 100)
                         HOST NIL T)))
         (WINDOWPROP WINDOW 'COURIERSTREAM COURIERSTREAM)
         [WINDOWADDPROP WINDOW 'CLOSEFN (FUNCTION (LAMBDA (WINDOW)
                                                    (CLOSEF? (WINDOWPROP WINDOW 'COURIERSTREAM]
         (REMOTE.PSW.REDISPLAY WINDOW)
         (MOVEW WINDOW)
         WINDOW])
)

(COURIERPROGRAM PROCESS (1199 0)
    TYPES
      [[PROCESSDATA (RECORD (SELECTED PROCESS)
                           (PROCESSES (SEQUENCE PROCESS]
       (PROCESS ATOM)
       (STATUS ATOM)
       (COMMAND (ENUMERATION (BT 0)
                       (BTV 1)
                       (BTV* 7)
                       (BTV! 39]
    INHERITS
      (INTERLISP)
    PROCEDURES
      ((GET.PROCESS.DATA 0 NIL RETURNS (PROCESSDATA)
              REPORTS NIL IMPLEMENTEDBY \REMOTE.GET.PROCESS.DATA)
       (BACKTRACE 1 (PROCESS COMMAND BULK.DATA.SINK)
              RETURNS NIL REPORTS NIL IMPLEMENTEDBY \REMOTE.PROCESS.BACKTRACE)
       (KILL 2 (PROCESS)
             RETURNS NIL REPORTS (NO.SUCH.PROCESS TTY.PROCESS SYSTEM.PROCESS)
             IMPLEMENTEDBY \REMOTE.PROCESS.KILL)
       (RESTART 3 (PROCESS)
              RETURNS NIL REPORTS (NO.SUCH.PROCESS)
              IMPLEMENTEDBY \REMOTE.PROCESS.RESTART)
       (WAKE 4 (PROCESS STATUS)
             RETURNS NIL REPORTS (NO.SUCH.PROCESS)
             IMPLEMENTEDBY \REMOTE.PROCESS.WAKE)
       (SUSPEND 5 (PROCESS)
              RETURNS NIL REPORTS (NO.SUCH.PROCESS)
              IMPLEMENTEDBY \REMOTE.PROCESS.SUSPEND)
       (GET.TTY.PROCESS 6 NIL RETURNS (PROCESS)
              REPORTS NIL IMPLEMENTEDBY \REMOTE.PROCESS.TTY)
       (SET.TTY.PROCESS 7 (PROCESS)
              RETURNS NIL REPORTS (NO.SUCH.PROCESS)
              IMPLEMENTEDBY \REMOTE.PROCESS.TTY))
    ERRORS
      ((NO.SUCH.PROCESS 0)
       (TTY.PROCESS 1)
       (SYSTEM.PROCESS 3)))
(DECLARE%: DONTCOPY 
(DECLARE%: EVAL@COMPILE

(RECORD PROCESSDATA (SELECTED PROCESSES))

(RECORD REMOTE.PSW.MENUS (COMMANDMENU PROCESSMENU))
)

(DECLARE%: EVAL@COMPILE 

(RPAQQ SELECTIONSHADE 520)

(CONSTANTS (SELECTIONSHADE 520))
)
)
(DEFINEQ

(REMOTE.PROCESS.BACKTRACE
  [LAMBDA (PROCESS CMD WINDOW)                               (* ; "Edited 26-Aug-87 11:15 by cdl")

    (DECLARE (GLOBALVARS BACKTRACEFONT PROCBACKTRACEHEIGHT))
    (PROG (PLACE REGION BACKTRACEWINDOW BULK.DATA.STREAM)
          (if [NOT (WINDOWP (SETQ BACKTRACEWINDOW (CAR (ATTACHEDWINDOWS WINDOW]
              then (SETQ REGION (WINDOWPROP WINDOW 'REGION))
                   (SETQ BACKTRACEWINDOW (CREATEW (create REGION
                                                         BOTTOM ←
                                                         (if (LESSP (fetch (REGION BOTTOM)
                                                                       of REGION)
                                                                    PROCBACKTRACEHEIGHT)
                                                             then (SETQ PLACE 'TOP)
                                                                  (fetch (REGION TOP) of REGION)
                                                           else (SETQ PLACE 'BOTTOM)
                                                                (DIFFERENCE (fetch (REGION BOTTOM)
                                                                               of REGION)
                                                                       PROCBACKTRACEHEIGHT))
                                                         HEIGHT ← PROCBACKTRACEHEIGHT using REGION)
                                                "Process backtrace" NIL T))
                   (ATTACHWINDOW BACKTRACEWINDOW WINDOW PLACE 'JUSTIFY 'LOCALCLOSE)
                   (DSPSCROLL 'OFF BACKTRACEWINDOW)
                   (DSPFONT [OR BACKTRACEFONT (FONTCREATE '(GACHA 8]
                          BACKTRACEWINDOW))
          (DSPRESET BACKTRACEWINDOW)
          (SETQ BULK.DATA.STREAM (COURIER.CALL (WINDOWPROP WINDOW 'COURIERSTREAM)
                                        'PROCESS
                                        'BACKTRACE PROCESS CMD NIL))
          (COPYBYTES BULK.DATA.STREAM BACKTRACEWINDOW)
          (CLOSEF BULK.DATA.STREAM])

(REMOTE.PSW.REDISPLAY
  [LAMBDA (WINDOW PROCESSDATA)                               (* ; "Edited 26-Aug-87 11:16 by cdl")

    (DECLARE (GLOBALVARS DEFAULTFONT))
    (PROG (COURIERSTREAM PMENU OPMENU SELECTED WIDTH)
          (SETQ COURIERSTREAM (WINDOWPROP WINDOW 'COURIERSTREAM))
          [if (NULL PROCESSDATA)
              then (SETQ PROCESSDATA (COURIER.CALL COURIERSTREAM 'PROCESS 'GET.PROCESS.DATA]
          (for ATTACHEDWINDOW in (WINDOWPROP WINDOW 'ATTACHEDWINDOWS) do (DETACHWINDOW ATTACHEDWINDOW
                                                                                )
                                                                         (CLOSEW ATTACHEDWINDOW))
          (with REMOTE.PSW.MENUS (WINDOWPROP WINDOW 'MENU)
                (if COMMANDMENU
                    then (SETQ OPMENU COMMANDMENU)
                  else (SETQ OPMENU
                        (create MENU
                               ITEMS ←
                               '(BT WHO? KILL BTV KBD← RESTART BTV* INFO WAKE BTV! UPDATE SUSPEND)
                               WHENSELECTEDFN ← (FUNCTION \REMOTE.PSWOP.SELECTED)
                               CENTERFLG ← T
                               MENUCOLUMNS ← 3)))
                (if PROCESSMENU
                    then (DELETEMENU PROCESSMENU NIL WINDOW)))
          (SETQ PMENU (create MENU
                             ITEMS ← (with PROCESSDATA PROCESSDATA PROCESSES)
                             WHENSELECTEDFN ← (FUNCTION \REMOTE.PSW.SELECTED)
                             MENUFONT ← DEFAULTFONT
                             CENTERFLG ← T))
          [SHAPEW WINDOW (create REGION
                                WIDTH ← [WIDTHIFWINDOW (SETQ WIDTH (MAX (fetch IMAGEWIDTH
                                                                           of PMENU)
                                                                        (fetch IMAGEWIDTH
                                                                           of OPMENU]
                                HEIGHT ← (HEIGHTIFWINDOW (PLUS (fetch IMAGEHEIGHT of PMENU)
                                                               (fetch IMAGEHEIGHT of OPMENU)
                                                               4)
                                                T) using (WINDOWPROP WINDOW 'REGION]
          (if (NULL (with REMOTE.PSW.MENUS (WINDOWPROP WINDOW 'MENUS)
                          COMMANDMENU))
              then (ADDMENU OPMENU WINDOW (create POSITION
                                                 XCOORD ← (QUOTIENT (DIFFERENCE WIDTH
                                                                           (fetch IMAGEWIDTH
                                                                              of OPMENU))
                                                                 2)
                                                 YCOORD ← 0)))
          (ADDMENU PMENU WINDOW (create POSITION
                                       XCOORD ← (QUOTIENT (DIFFERENCE (with REGION (DSPCLIPPINGREGION
                                                                                    NIL WINDOW)
                                                                            WIDTH)
                                                                 (fetch IMAGEWIDTH of PMENU))
                                                       2)
                                       YCOORD ← (PLUS (fetch IMAGEHEIGHT of OPMENU)
                                                      4)))
          (if (SETQ SELECTED (with PROCESSDATA PROCESSDATA SELECTED))
              then (if (FMEMB SELECTED (with PROCESSDATA PROCESSDATA PROCESSES))
                       then (SHADEITEM SELECTED PMENU SELECTIONSHADE)))
          (WINDOWPROP WINDOW 'PROCESSDATA PROCESSDATA])

(REMOTE.PROCESS.ERROR
  [LAMBDA (ERROR)                                            (* ; "Edited  4-Sep-87 07:30 by cdl")
                                                             (* DECLARATIONS%: (RECORD ERROR
                                                             (NIL TYPE)) (RECORD ALST
                                                             (KEY . VALUE)))
    (LET ((ALST (ASSOC (with ERROR ERROR TYPE)
                       REMOTE.PROCESS.ERRORS)))
         (if ALST
             then (PROMPTPRINT (with ALST ALST VALUE))
           else (PROMPTPRINT (with ERROR ERROR TYPE)
                       (with ALST (ASSOC T REMOTE.PROCESS.ERRORS)
                             VALUE])

(\REMOTE.GET.PROCESS.DATA
  [LAMBDA NIL                                                (* ; "Edited 26-Aug-87 11:33 by cdl")

    (DECLARE (GLOBALVARS \PROCESSES))
    `(RETURN (,(PROCESS.NAME (TTY.PROCESS)) ,(in \PROCESSES collect PROCESS.NAME])

(\REMOTE.PROCESS.BACKTRACE
  [LAMBDA (COURIERSTREAM PROGRAM PROCEDURE PROCESS COMMAND BULK.DATA.STREAM)
                                                             (* cdl " 5-Dec-85 18:28")
    (if (NULL (SETQ PROCESS (FIND.PROCESS PROCESS)))
        then '(ABORT NO.SUCH.PROCESS)
      else (LET (STKP (PLVLFILEFLG T)
                      (FX (fetch (PROCESS PROCFX) of PROCESS)))
                (BAKTRACE (if (ZEROP FX)
                              then                           (* The currently active proc!)
                                   (FUNCTION \REMOTE.PROCESS.BACKTRACE)
                            else (SETQ STKP (\MAKESTACKP NIL FX)))
                       NIL NIL (SELECTQ COMMAND
                                   (BT 0)
                                   (BTV 1)
                                   (BTV* 7)
                                   (BTV! 39)
                                   0)
                       BULK.DATA.STREAM)
                (if STKP
                    then (RELSTK STKP)))
           '(RETURN])

(\REMOTE.PROCESS.KILL
  [LAMBDA (COURIERSTREAM PROGRAM PROCEDURE PROCESS)          (* cdl " 3-Dec-85 18:59")
    (if (NOT (SETQ PROCESS (FIND.PROCESS PROCESS)))
        then '(ABORT NO.SUCH.PROCESS)
      elseif (EQ PROCESS (TTY.PROCESS))
        then '(ABORT TTY.PROCESS)
      elseif (fetch PROCSYSTEMP of PROCESS)
        then '(ABORT SYSTEM.PROCESS)
      else (DEL.PROCESS PROCESS)
           '(RETURN])

(\REMOTE.PROCESS.RESTART
  [LAMBDA (COURIERSTREAM PROGRAM PROCEDURE PROCESS)          (* cdl " 3-Dec-85 19:09")
    (if (NOT (SETQ PROCESS (FIND.PROCESS PROCESS)))
        then '(ABORT NO.SUCH.PROCESS)
      else (RESTART.PROCESS PROCESS)
           '(RETURN])

(\REMOTE.PROCESS.SUSPEND
  [LAMBDA (COURIERSTREAM PROGRAM PROCEDURE PROCESS)          (* cdl " 3-Dec-85 19:16")
    (if (NOT (SETQ PROCESS (FIND.PROCESS PROCESS)))
        then '(ABORT NO.SUCH.PROCESS)
      else (if (NEQ PROCESS (THIS.PROCESS))
               then (SUSPEND.PROCESS PROCESS))
           '(RETURN])

(\REMOTE.PROCESS.TTY
  [LAMBDA (COURIERSTREAM PROGRAM PROCEDURE PROCESS)          (* ; "Edited  3-Sep-87 18:04 by cdl")

    (if PROCESS
        then (if (NOT (SETQ PROCESS (FIND.PROCESS PROCESS)))
                 then '(ABORT NO.SUCH.PROCESS)
               else (TTY.PROCESS PROCESS)
                    '(RETURN))
      else `(RETURN ,(if (TTY.PROCESS)
                         then (PROCESS.NAME (TTY.PROCESS])

(\REMOTE.PROCESS.WAKE
  [LAMBDA (COURIERSTREAM PROGRAM PROCEDURE PROCESS STATUS)   (* cdl " 3-Dec-85 19:12")
    (if (NOT (SETQ PROCESS (FIND.PROCESS PROCESS)))
        then '(ABORT NO.SUCH.PROCESS)
      else (WAKE.PROCESS PROCESS STATUS)
           '(RETURN])

(\REMOTE.PSW.SELECTED
  [LAMBDA (ITEM MENU BUTTON)                                 (* cdl " 3-Dec-85 20:00")
    (with PROCESSDATA (WINDOWPROP (WFROMMENU MENU)
                             'PROCESSDATA)
          (if (AND SELECTED (NEQ ITEM SELECTED))
              then (SHADEITEM SELECTED MENU WHITESHADE))
          (SHADEITEM ITEM MENU SELECTIONSHADE)
          (SETQ SELECTED ITEM])

(\REMOTE.PSWOP.SELECTED
  [LAMBDA (ITEM MENU BUTTON)                                 (* ; "Edited  3-Sep-87 18:10 by cdl")

    (ALLOW.BUTTON.EVENTS)
    (LET
     [VALUE PROCESS ERROR NEWPROCESSDATA (WINDOW (WFROMMENU MENU))
            (COURIERSTREAM (WINDOWPROP (WFROMMENU MENU)
                                  'COURIERSTREAM]
     (with PROCESSDATA (WINDOWPROP WINDOW 'PROCESSDATA)
           (if [NOT (EQUAL PROCESSES (fetch (PROCESSDATA PROCESSES) of (SETQ NEWPROCESSDATA
                                                                        (COURIER.CALL COURIERSTREAM
                                                                               'PROCESS
                                                                               'GET.PROCESS.DATA]
               then (if (MEMB SELECTED (fetch (PROCESSDATA PROCESSES) of NEWPROCESSDATA))
                        then (replace (PROCESSDATA SELECTED) of NEWPROCESSDATA with SELECTED))
                    (REMOTE.PSW.REDISPLAY WINDOW NEWPROCESSDATA)))
     (with
      PROCESSDATA
      (WINDOWPROP WINDOW 'PROCESSDATA)
      (if [NOT (EQUAL PROCESSES (fetch (PROCESSDATA PROCESSES) of (SETQ NEWPROCESSDATA
                                                                   (COURIER.CALL COURIERSTREAM
                                                                          'PROCESS
                                                                          'GET.PROCESS.DATA]
          then (if (MEMB SELECTED (fetch (PROCESSDATA PROCESSES) of NEWPROCESSDATA))
                   then (replace (PROCESSDATA SELECTED) of NEWPROCESSDATA with SELECTED))
               (REMOTE.PSW.REDISPLAY WINDOW NEWPROCESSDATA))
      (SELECTQ ITEM
          (WHO? (if (SETQ PROCESS (COURIER.CALL COURIERSTREAM 'PROCESS 'GET.TTY.PROCESS))
                    then (with REMOTE.PSW.MENUS (WINDOWPROP WINDOW 'MENU)
                               (\REMOTE.PSW.SELECTED PROCESS PROCESSMENU))
                  else (PROMPTPRINT "No process has the tty!!!")))
          (UPDATE NIL)
          (if SELECTED
              then
              (SELECTQ ITEM
                  (KBD← (if (SETQ ERROR (COURIER.CALL COURIERSTREAM 'PROCESS 'SET.TTY.PROCESS 
                                               SELECTED 'RETURNERRORS))
                            then (REMOTE.PROCESS.ERROR ERROR)))
                  ((BT BTV BTV* BTV!) 
                       (REMOTE.PROCESS.BACKTRACE SELECTED ITEM WINDOW))
                  (INFO (PROMPTPRINT "Not yet implemented"))
                  (KILL (if (SETQ ERROR (COURIER.CALL COURIERSTREAM 'PROCESS 'KILL SELECTED
                                               'RETURNERRORS))
                            then (REMOTE.PROCESS.ERROR ERROR)
                          else (REMOTE.PSW.REDISPLAY WINDOW)))
                  (RESTART (if (SETQ ERROR (COURIER.CALL COURIERSTREAM 'PROCESS 'RESTART SELECTED
                                                  'RETURNERRORS))
                               then (REMOTE.PROCESS.ERROR ERROR)))
                  (WAKE (PROG NIL
                              (if (SETQ ERROR
                                   (COURIER.CALL
                                    COURIERSTREAM
                                    'PROCESS
                                    'WAKE SELECTED
                                    (SELECTQ [MENU (OR PROCOP.WAKEMENU
                                                       (SETQ PROCOP.WAKEMENU
                                                        (create MENU
                                                               ITEMS ← '((NIL 'NULL)
                                                                         T Other)
                                                               TITLE ← "WakeUp Value"
                                                               CENTERFLG ← T]
                                        (NIL (RETURN))
                                        (NULL NIL)
                                        (T T)
                                        (Other (CAR (OR (LISTP (PROCESS.READ 
                                                                 "Value to return to woken process: "
                                                                      ))
                                                        (RETURN))))
                                        NIL)
                                    'RETURNERRORS))
                                  then (REMOTE.PROCESS.ERROR ERROR))))
                  (SUSPEND (if (SETQ ERROR (COURIER.CALL COURIERSTREAM 'PROCESS 'SUSPEND SELECTED
                                                  'RETURNERRORS))
                               then (REMOTE.PROCESS.ERROR ERROR)))
                  NIL])
)

(RPAQQ REMOTE.PROCESS.ERRORS ((NO.SUCH.PROCESS . "Process not found!")
                              (TTY.PROCESS . "Can't, TTY process!")
                              (SYSTEM.PROCESS . "Can't, SYSTEM process!")
                              (T . " remote process error!")))
(DECLARE%: DOEVAL@COMPILE DONTCOPY

(GLOBALVARS REMOTE.PROCESS.ERRORS PROCOP.WAKEMENU)
)
(FILESLOAD COURIERDEFS)
(PUTPROPS REMOTEPSW COPYRIGHT ("Xerox Corporation & Stanford University" 1985 1986 1987))
(DECLARE%: DONTCOPY
  (FILEMAP (NIL (1388 1986 (REMOTE.PROCESS.STATUS.WINDOW 1398 . 1984)) (3760 19241 (
REMOTE.PROCESS.BACKTRACE 3770 . 5918) (REMOTE.PSW.REDISPLAY 5920 . 9905) (REMOTE.PROCESS.ERROR 9907 . 
10659) (\REMOTE.GET.PROCESS.DATA 10661 . 10931) (\REMOTE.PROCESS.BACKTRACE 10933 . 12033) (
\REMOTE.PROCESS.KILL 12035 . 12491) (\REMOTE.PROCESS.RESTART 12493 . 12777) (\REMOTE.PROCESS.SUSPEND 
12779 . 13125) (\REMOTE.PROCESS.TTY 13127 . 13586) (\REMOTE.PROCESS.WAKE 13588 . 13873) (
\REMOTE.PSW.SELECTED 13875 . 14286) (\REMOTE.PSWOP.SELECTED 14288 . 19239)))))
STOP