$ ! ***************************************************************************
$ ! *                                                                         *
$ ! * (c) WSSIZE.COM                                                          *
$ ! *                                                                         *
$ ! ***************************************************************************
$ !
$ ! ------------------------------------------------------------***************
$ !
$ ! Copyright    : Barendse & Bosman Office Automation B.V.
$ !                C. Kouwenbergzoom 221     -------------
$ !                3065 GK  ROTTERDAM       | Info@BBI.nl |
$ !                The Netherlands           -------------
$ !
$ ! Version      : V5.0.03 - 15 November 2001 (originaly build in 1989!)
$ !
$ ! Description  : This procedure shows a dynamic display of working sets on
$ !                your OpenVMS-system. The following characters will be used:
$ !
$ !                chr | from    | until
$ !                ----+---------+------
$ !                 .  | 0       | DEFAULT
$ !                 -  | DEFAULT | QUOTA
$ !                 +  | QUOTA   | EXTENT
$ !                 P  | number of pages in use
$ !                 S  | actual working set size
$ !
$ ! Parameters   : input  P1 > Scale in Kb/Chr.
$ !                            Default is a scale of 100 Kb/Chr.
$ !                       P2 > Refresh interval in seconds.
$ !                            Default is an interval of 5 seconds.
$ !                       P3 > Match condition. Use 'pid' to refer to a process
$ !                            when including F$GETJPI in the condition-string.
$ !                            Default is all interactive processes.
$ !                output    > Dynamic display showing working set size.
$ !
$ ! Example      : $ @WSSIZE "20" "3" "" ! Focus on WSDEF (small scale)
$ !
$ ! Remarks      : o This procedures assumes:
$ !                  W.S.-DEFAULT <= W.S.-QUOTA <= W.S.-EXTENT.
$ !                o When specifying a match-condition in P3, no syntax-
$ !                  validation will take place.
$ !                o This procedure uses the PIPE-command. Please modify
$ !                  if your OpenVMS-system doesn't support this command.
$ !                o Use this procedure as you like, but please don't remove
$ !                  this header and copyright-note. Send an e-mail to
$ !                  Info@BBI.nl with your comments.
$ !
$ ! Changed      : by      : +author;
$ !                version : +release; - +date;
$ !                reason  : +description;
$ !
$ ! ------------------------------------------------------------***************
$ !
$ main:                                                       ! MAINROUTINE
$    !
$    GOSUB initialize
$    !
$    CALL  wssize
$    !
$    GOSUB finish
$    !
$ EXIT                                                        ! ENDMAINROUTINE
$ !
$ ! ------------------------------------------------------------***************

$ ! ------------------------------------------------------------***************
$ !
$ initialize:
$    !
$    PIPE esc = "" ; esc[0,8] = %X1B
$    PIPE csi = "" ; csi[0,8] = %X9B
$    !
$    ! Clear display, set cursor off, define scroll area and terminal width.
$    ! ---------------------------------------------------------------------
$    !
$    WRITE SYS$OUTPUT "''csi'r''csi'J''csi'?25l"
$    !
$    bgn_line  =  2
$    end_line  = 24
$    !
$    SET TERMINAL /WIDTH=132
$    !
$    ! Set input-parameters.
$    ! ---------------------
$    !
$    IF P1 .EQS. "" THEN P1 = 100
$    IF P2 .EQS. "" THEN P2 = 5
$    IF P3 .EQS. "" THEN P3 = " F$GETJPI( pid, ""MODE"" ) .EQS. ""INTERACTIVE"" "
$    !
$    scale    = P1
$    interval = P2
$    match    = P3
$    !
$ RETURN
$ !
$ ! ------------------------------------------------------------***************

$ ! ------------------------------------------------------------***************
$ !
$ wssize:                                                       SUBROUTINE
$    !
$    ! Set exit-condition.
$    ! -------------------
$    !
$    ctrl = F$ENVIRONMENT( "CONTROL" )
$    SET CONTROL=Y
$    ON  CONTROL_Y THEN GOTO exit_handler
$    !
$    !
$    ! Write header, display first screen normal.
$    ! ------------------------------------------
$    !
$    WRITE SYS$OUTPUT F$FAO( "''csi'H''csi'7m!14AS''csi'27m  >!8* 1!9* 2!9* 3!9* 4!9* 5!9* 6!9* 7!9* 8!9* 9!9* 0!9* 1", "''scale' Kb/chr" )
$    toggle_bold = "''csi'1m"
$    !
$    repeat:
$       !
$       ! Start at first line.
$       ! --------------------
$       !
$       line = bgn_line
$       !
$       ! Toggle display between normal and bold.
$       ! ---------------------------------------
$       !
$       IF toggle_bold .EQS. "''csi'1m"
$       THEN
$          toggle_bold = "''csi'22m"
$          inverse     = "''csi'1m"
$       ELSE
$          toggle_bold = "''csi'1m"
$          inverse     = "''csi'22m"
$       ENDIF
$       !
$       ! First process.
$       ! --------------
$       !
$       pid = F$PID( context )
$       while: IF .NOT. (pid .NES. "") THEN GOTO end_while
$          !
$          IF 'match'
$          THEN
$             !
$             ! Determine and Set diplay-values.
$             ! --------------------------------
$             !
$             prcnam = F$GETJPI( pid, "PRCNAM" )
$             !
$             g1 = (F$GETJPI( pid, "DFWSCNT"  ) / 2 / 'scale') ! WSDEFAULT or PQL_DWSDEFAULT
$             g2 = (F$GETJPI( pid, "WSQUOTA"  ) / 2 / 'scale') ! WSQUOTA or PQL_DWSQUOTA
$             g3 = (F$GETJPI( pid, "WSEXTENT" ) / 2 / 'scale') ! WSEXTENT or PQL_DWSEXTENT
$             g3 = g3 - g2
$             g2 = g2 - g1
$             IF g1 .GT. 132 THEN PIPE g1 = 132 ; g2 = 132 ; g3 = 132
$             IF g2 .GT. 132 THEN PIPE g2 = 132 ; g3 = 132
$             IF g3 .GT. 132 THEN PIPE g3 = 132
$             !
$             p  = F$GETJPI( pid, "PPGCNT" ) + F$GETJPI( pid, "GPGCNT" )
$             s  = F$GETJPI( pid, "WSSIZE" )
$             p  = p / 2 / 'scale' + 15
$             s  = s / 2 / 'scale' + 15
$             !
$             IF p .GT. 132 THEN p = 132
$             sign = "S"
$             IF s .GT. 132 THEN PIPE sign = "''inverse'''esc'(0`''esc'(B''toggle_bold'" ; s = 132
$             !
$             ! Construct output-line.
$             ! ----------------------
$             !
$             fixed  = F$FAO( "!2ZL", line )
$             string = F$FAO( "!136AS", F$FAO( "''csi'''fixed'H!14AS: !''g1'*.!''g2'*-!''g3'*+''csi'K", prcnam  ) )
$             !
$             ! Write line.
$             ! -----------
$             !
$             WRITE SYS$OUTPUT "''toggle_bold'" + string
$             WRITE SYS$OUTPUT "''csi'A''csi'''p'CP"
$             WRITE SYS$OUTPUT "''csi'A''csi'''s'C''sign'"
$             !
$             ! Set for next line. Wait if this was the last line for this
$             ! display.
$             ! ----------------------------------------------------------
$             !
$             line = line + 1
$             IF line .EQ. end_line THEN PIPE WAIT 00:00:'interval' ; line = bgn_line
$             !
$          ENDIF
$          !
$          ! Next process.
$          ! -------------
$          !
$          pid = F$PID( Context )
$          !
$          GOTO while
$       end_while:
$       !
$       ! Clear display beyond last line.
$       ! -------------------------------
$       !
$       IF line .EQ. bgn_line
$       THEN
$          WRITE SYS$OUTPUT "''csi'2H''csi'J''csi'A"
$       ELSE
$          WRITE SYS$OUTPUT "''csi'J''csi'A"
$       ENDIF
$       !
$       ! Wait before starting again. 
$       ! ---------------------------
$       !
$       WAIT 00:00:'interval'
$       !
$    GOTO repeat
$    !
$ EXIT

$ exit_handler:
$    !
$    ! Restore process settings.
$    ! -------------------------
$    !
$    PIPE SET NOCONTROL=(Y,T) ; IF ctrl .NES. "" THEN SET CONTROL=('ctrl')
$    SET TERMINAL /WIDTH=80
$    WRITE SYS$OUTPUT "''csi'r''csi'J''csi'?25h''csi'22m"
$    !
$ EXIT
$                                                               ENDSUBROUTINE
$ !
$ ! ------------------------------------------------------------***************

$ ! ------------------------------------------------------------***************
$ !
$ finish:                                                       SUBROUTINE
$    !
$    ! Clear screen. Set cursor on.
$    ! ----------------------------
$    !
$    WRITE SYS$OUTPUT "''csi'r''csi'2J''csi'?25h''csi'22m"
$    !
$ EXIT
$                                                               ENDSUBROUTINE
$ !
$ ! ------------------------------------------------------------***************