From:	CRDGW2::CRDGW2::MRGATE::"SMTP::CRVAX.SRI.COM::RELAY-INFO-VAX" 11-NOV-1989 21:37
To:	MRGATE::"ARISIA::EVERHART"
Subj:	SCRSMB part .14 of 20

Message-Id:  <8911112356.AA07640@crdgw1.ge.com>
Received: From RELAY.CS.NET by GIZMO.SRI.COM with TCP; Sat, 11 NOV 89 00:10:00 PDT
Received: from relay2.cs.net by RELAY.CS.NET id aa07414; 10 Nov 89 22:56 EST
Received: from a.cs.okstate.edu by RELAY.CS.NET id ai00506; 10 Nov 89 23:50 EST
Received: from nemo.math.okstate.edu by a.cs.okstate.edu id ab29700;
          10 Nov 89 20:39 CST
Date: Fri, 10 Nov 89 20:38 CDT
From: Gregg Wonderly <GREGG%nemo.math.okstate.edu@RELAY.CS.NET>
Subject: SCRSMB part .14 of 20
To: info-vax@KL.SRI.COM
X-Vms-To: in%"info-vax@kl.sri.com"

-+-+-+-+-+-+-+-+ START OF PART 14 -+-+-+-+-+-+-+-+
X
X*       File information
X
X        parameter ERRFILE = 'SCRSMB$ROOT:`091LOG`093ERR.LOG'
X        parameter DEVSLIST = 'SCRSMB$ROOT:`091DAT`093DEVICES.DAT'
X        parameter SCRIPTROOT = 'SCRSMB$SCRIPT:`091000000`093.DAT'
X        parameter TRANSFILE = 'SCRSMB$ROOT:`091LOG`093'
X        parameter ERRUNIT = 10
X        parameter BASEFILENO = 11
X        parameter BASESCRIPT = (BASEFILENO)
X        parameter BASEDEVS = (BASEFILENO + MAX_JOBS + 1)
X        parameter BASETRANS = (BASEFILENO + MAX_JOBS + MAX_JOBS + 1)
X
X*       select_dev() return codes.
X
X        parameter GD$_GOTONE = 1
X        parameter GD$_NOALLOC = 2
X        parameter GD$_ERRALLOC = 3
X        parameter GD$_NODEVS = 4
X        parameter GD$_PENDING = 5
X        parameter GD$_FILEERR = 6
X
X*       Number of VAX clock ticks in a second.
X
X        parameter SECONDS = 10000000
X
X*       Time to wait (seconds) between trys while in ST$_RETRYDEVS state.
X
X        parameter ALLOC_TIME = 3
$ CALL UNPACK [.SRC]PARAMS.INC;47 2134315941
$ create/nolog 'f'
X****************************************************************************
V**
X*
X*       Function:   PROCESS
X*       Usage:      Called at AST level to perform next step in script
X*                   processing.
X*       Purpose:    This routine is the meat of the script processing
X*                   functions.  During script processing, this routine is
X*                   used as the entry point to AST's that are queued either
X*                   as the result of $QIO, $SETIMR, or $DCLAST system
X*                   services.
X*       Output:     Another step in the script process is completed.
X*
X****************************************************************************
V**
X
X        subroutine process (idx)
X            implicit none
X
X            include 'alldefs.inc'
X            include 'funcdef.inc'
X
X            integer idx, state, got_dev, daytim(1:2), l_len
X            integer i, j, k, stat, wlen, secs, psm_report, parmno
X
X            character*(BUFSIZ) line, outbuf, inbuf
X            character ch, endch
X
X            external get_suc_fail, sched_read, copy_word
X            external skip_space, goto_script_label
X            external psm_report, dealloc_dev, log_sys
X            external call_func
X            logical found, matched, goto_script_label
X            integer call_func
X
X            outbuf = ' '
X            state = jobs(idx).state
X
X            if (jobs(idx).cancel) then
X
X*               When cancel is selected in the middle of the script
X*               processing, but before connection, then stop processing.
X
X                call close_devs (idx)
X                call close_script (idx)
X                call close_trans (idx)
X
X*               Ignore any errors for deassigning and deallocating the
X*               device, because the channel might actually be invalid
X
X                call cancel_queue (idx)
X                stat = sys$cancel (jobs(idx).chan)
X                call dealloc_dev (idx)
X                jobs(idx).state = ST$_CANCEL
X                jobs(idx).used = .false.
X            else if (state .eq. ST$_BEGIN) then`032
X                if (.not. open_devs (idx)) then
X                    call log_sys (SCRSMB__NODEVFILE, ' ', idx)
X                    call delta_secs (daytim, 60)
X
X                    call signal (sys$setimr (, %ref(daytim), exprocess,
X     .                          jobs(idx).ast_arg,))
X                else
X                    jobs(idx).state = ST$_GETDEVICE
X                    call signal (dclast (exprocess,
X     .                          jobs(idx).ast_arg,))
X                endif
X
X*           Select a device to allocate if possible
X
X            else if ((state .eq. ST$_GETDEVICE) .or.
X     .                                      (state .eq. ST$_RETRYDEVS)) then
X
X*               Read a device, and try to allocate it.
X
X                got_dev = select_dev (idx)
X
X*               No devices listed for this queue.
X
X                if (got_dev .eq. GD$_NODEVS) then
X                    call log_sys (SCRSMB__NODEVS,`032
X     .                'There are no devices listed as available to this queu
Ve',
X     .                idx)
X
X                    call close_devs (idx)
X
X                    jobs(idx).state = ST$_BEGIN
X                    jobs(idx).device = ' '
X
X                    call delta_secs (daytim, 60)
X
X                    call signal (sys$setimr (, %ref(daytim), exprocess,
X     .                          jobs(idx).ast_arg,))
X
X*               Alloc succeeded, and channel assigned.
X
X                else if (got_dev .eq. GD$_GOTONE) then
X                    jobs(idx).state = ST$_GETSCRIPT
X                    call signal (dclast (exprocess,
X     .                          jobs(idx).ast_arg,))
X
X*               An error occurred during the allocate
X
X                else if (got_dev .eq. GD$_ERRALLOC) then
X                    call log_sys (SCRSMB__ERRORALLOC,
X     .                  'An invalid device is listed', idx)
X
X                    jobs(idx).state = ST$_RETRYDEVS
X                    call signal (dclast (exprocess,
X     .                          jobs(idx).ast_arg,))
X
X*               No devices were available, but at least one was tried.
X
X                else if ((got_dev .eq. GD$_NOALLOC) .or.
X     .                                      (got_dev .eq. GD$_FILEERR)) then
X
X*                   Set an AST completion timer to try the devices
X*                   again.
X
X                    call delta_secs (daytim, ALLOC_TIME)
X
X                    jobs(idx).state = ST$_RETRYDEVS
X                    jobs(idx).device = ' '
X
X                    call signal (sys$setimr (, %ref(daytim), exprocess,
X     .                          jobs(idx).ast_arg))
X                else if (got_dev .ne. GD$_PENDING) then
X                    call log_sys (SCRSMB__BADGETDEV,
X     .                                  'Can''t get a device to use', idx)
X                    call delta_secs (daytim, ALLOC_TIME)
X                    jobs(idx).state = ST$_RETRYDEVS
X                    call signal (sys$setimr (, %ref(daytim), exprocess,
X     .                          jobs(idx).ast_arg))
X                else
X                    jobs(idx).state = ST$_PENDING
X                endif
X            else if (state .eq. ST$_PENDING) then
X                if (jobs(idx).iosb(1)) then
X                    jobs(idx).state = ST$_GETSCRIPT
X                else
X                    jobs(idx).state = ST$_RETRYDEVS
X                endif
X                call signal (dclast (exprocess, jobs(idx).ast_arg,))
X            else if (state .eq. ST$_GETSCRIPT) then
X                if (.not. open_script (idx)) then
X                    call log_sys (SCRSMB__NOSCRIPT,
X     .                      'Job is delaying, waiting for a script', idx)
X                    call dealloc_dev (idx)
X                    jobs(idx).state = ST$_RETRYDEVS
X                    call delta_secs (daytim, 60)
X                    call signal (sys$setimr (, %ref(daytim), exprocess,
X     .                          jobs(idx).ast_arg))
X
X                else
X                    jobs(idx).state = ST$_SCRIPT
X                    call signal (dclast (exprocess, jobs(idx).ast_arg,))
X                endif
X            else if (state .eq. ST$_SCRIPT) then
X                if (get_script_line (line, idx)) then
X
X                    call trans_log_str (idx, 'script line is: ',
X     .                                                  line(1:length(line))
V)
X
X*                   Get the text to xmit/recv
X
X                    i = 1
X                    call skip_space (line, i)
X
X*                   Remove any leading spaces from the line
X
X                    line = line (i:)
X
X*                   Figure out length of command portion, and save it in wle
Vn
X
X                    i = 1
X                    do while ((i .le. length (line)) .and. (line(i:i) .ne. '
V '))
X                        i = i + 1
X                    end do
X                    wlen = i - 1
X
X*                   Skip to first parameter
X
X                    call skip_space (line, i)
X
X                    endch = line(i:i)
X                    if (endch .eq. '"') then
X                        i = i + 1
X                    else
X                        endch = ' '
X                    endif
X
X*                   Put the first parameter into the buffer
X
X                    j = 1
X                    do while ((i .le. length (line)) .and.
X     .                                              (line(i:i) .ne. endch))
X                        if (line(i:i) .eq. '\') then
X                            i = i + 1
X                            ch = line (i:i)
X
X                            if (ch .eq. 'r') then
X                                ch = chr (13)
X                            else if (ch .eq. 'n') then
X                                ch = chr (10)
X                            else if (ch .eq. 'b') then
X                                ch = chr (8)
X                            else if (ch .eq. '$') then
X                                ch = '$'
X                            else if (ch .eq. 'f') then
X                                ch = chr (12)
X                            else if (ch .eq. '0') then
X                                ch = chr (atoo (line (i:), i))
X                            endif
X
X                            outbuf (j:j) = ch
X                        else if (line(i:i) .eq. '$') then
X                            i = i + 1
X                            parmno = atoi(line(i:i+1), k)
X                            if (parmno .gt. 9) i=i+1
X                            k=1
X                            do while (k .le. jobs(idx).params(parmno).len)
X                                ch = jobs(idx).params(parmno).str(k:k)
X
X                                if (ch .eq. '\') then
X                                    k = k + 1
X                                    ch = jobs(idx).params(parmno).str(k:k)
X
X                                    if (ch .eq. 'r') then
X                                        ch = chr (13)
X                                    else if (ch .eq. 'n') then
X                                        ch = chr (10)
X                                    else if (ch .eq. 'b') then
X                                        ch = chr (8)
X                                    else if (ch .eq. '$') then
X                                        ch = '$'
X                                    else if (ch .eq. 'f') then
X                                        ch = chr (12)
X                                    else if (ch .eq. '0') then
X                                        ch = chr (
X     .                           atoo (jobs(idx).params(parmno).str(k:), k))
X                                    endif
X
X                                    outbuf (j:j) = ch
X                                else
X                                    outbuf (j:j) = ch
X                                endif
X
X                                j=j+1
X                                k=k+1
X                            end do
X                            j = j - 1
X                        else
X                            outbuf (j:j) = line (i:i)
X                        endif
X
X                        j = j + 1
X                        i = i + 1
X                    end do
X                    j = j - 1
X
X                    jobs(idx).recv_str = ' '
X                    do k=1, wlen
X                        jobs(idx).recv_str (k:k) = line (k:k)
X                    end do
X                    jobs(idx).recv_str_len = wlen
X
X*                   Wait the specified number of seconds
X
X                    if (line (1:wlen) .eq. 'wait') then
X                        secs = atoi (outbuf(1:j), i)`032
X                        call delta_secs (daytim, secs)
X                        call signal (sys$setimr (, %ref(daytim), exprocess,
X     .                          jobs(idx).ast_arg))
X
X*                   Write out the string specified
X
X                    else if (line (1:wlen) .eq. 'xmit') then
X                        jobs(idx).state = ST$_WRITE
X                        do k=1, i-wlen
X                            jobs(idx).recv_str (k:k) = line (k+wlen+1:k+wlen
V+1)
X                        end do
X                        jobs(idx).recv_str_len = i-wlen
X
X                        stat = call_func (methods(jobs(idx).method).write,
X     .                      jobs(idx),
X     .                      %val (jobs(idx).chan),
X     .                      IO$_WRITEPBLK,
X     .                      jobs(idx).iosb,
X     .                      exprocess,
X     .                      jobs(idx).ast_arg,
X     .                      %val (%loc (outbuf)),
X     .                      j)
X
X*                       If the write fails, then restart.
X
X                        if ((stat .and. 1) .ne. 1) then
X                            call close_devs (idx)
X                            call close_script (idx)
X                            call close_trans (idx)
X                            jobs(idx).state = ST$_BEGIN
X                            call dealloc_dev (idx)
X                            call signal (dclast (exprocess,
X     .                              jobs(idx).ast_arg,))
X                        endif
X
X*                   Read data from the port, looking for the string given.
X*                   If a timeout value is given, then use that to limit
X*                   the time that we wait.  Success and Failure labels may
X*                   also be present, so squirrel those away for use when the
X*                   read actually completes
X
X                    else if (line(1:wlen) .eq. 'recv') then
X
X*                       Find the beginning of the next string
X
X                        i = i + 1
X                        call skip_space (line, i)
X                        if (i .lt. BUFSIZ) then
X                            if (line(i:i) .eq. '-') then
X                                jobs(idx).timeout = -1
X                                i = i + 1
X                            else
X                                jobs(idx).timeout = atoi (line(i:), i)
X                            endif
X
X                            call skip_space (line, i)
X                            jobs(idx).suc_label = ' '
+-+-+-+-+-+-+-+-  END  OF PART 14 +-+-+-+-+-+-+-+-

