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

Message-Id:  <8911120010.AA07753@crdgw1.ge.com>
Received: From RELAY.CS.NET by GIZMO.SRI.COM with TCP; Sat, 11 NOV 89 00:10:07 PDT
Received: from relay2.cs.net by RELAY.CS.NET id aa07417; 10 Nov 89 22:57 EST
Received: from a.cs.okstate.edu by RELAY.CS.NET id aj00506; 10 Nov 89 23:53 EST
Received: from nemo.math.okstate.edu by a.cs.okstate.edu id ac29700;
          10 Nov 89 20:40 CST
Date: Fri, 10 Nov 89 20:38 CDT
From: Gregg Wonderly <GREGG%nemo.math.okstate.edu@RELAY.CS.NET>
Subject: SCRSMB part .15 of 20
To: info-vax@KL.SRI.COM
X-Vms-To: in%"info-vax@kl.sri.com"

-+-+-+-+-+-+-+-+ START OF PART 15 -+-+-+-+-+-+-+-+
X                            jobs(idx).fail_label = ' '
X                            if (i .lt. BUFSIZ) then
X                                call get_suc_fail (idx, line, i)
X                            endif
X                        endif
X
X                        jobs(idx).state = ST$_RECV
X
X                        do k=1, j
X                            jobs(idx).recv_str (k:k) = outbuf (k:k)
X                        end do
X                        jobs(idx).recv_str_len = j
X
X                        call sched_read (idx)
X
X*                   Match the existing input with the string given.  Success
X*                   and Failure labels may be present, so use those to
X*                   GOTO the "proper", next action.
X
X                    else if (line (1:wlen) .eq. 'match') then
X                        do k=1, j
X                            jobs(idx).recv_str (k:k) = outbuf (k:k)
X                        end do
X                        jobs(idx).recv_str_len = j
X
X                        i = i + 1
X                        call skip_space (line, i)
X                        jobs(idx).suc_label = ' '
X                        jobs(idx).fail_label = ' '
X                        if (i .lt. BUFSIZ) then
X                            call get_suc_fail (idx, line, i)
X                        endif
X
X                        matched = .false.
X                        if (jobs(idx).iosb(2) .ne. 0) then
X                            matched = input_matches (idx, jobs(idx).iosb(2))
X                        endif
X
X                        if ((matched) .and.
X     .                              (jobs(idx).suc_label(1:1) .ne. ' ')) the
Vn
X                            jobs(idx).state = ST$_GOTOSUCC
X                        else if (jobs(idx).fail_label(1:1) .ne. ' ') then
X                            jobs(idx).state = ST$_GOTOFAIL
X                        endif
X
X*                       Queue another AST to actually handle the GOTO
X
X                        call signal (dclast (exprocess, jobs(idx).ast_arg,))
X
X*                   Unconditionally goto a new location in the script.
X
X                    else if (line (1:wlen) .eq. 'goto') then
X                        if (.not. goto_script_label (idx, outbuf)) then
X                            call log_sys (SCRSMB__BADSCRIPT,
X     .                          'Goto label, ''' // outbuf(1:j) //
X     .                          ''', not found in script.', idx)
X                            call close_script (idx)
X                            call close_trans (idx)
X                            call dealloc_dev (idx)
X                            jobs(idx).state = ST$_RETRYDEVS
X                        endif
X
X                        call signal (dclast (exprocess,
X     .                                          jobs(idx).ast_arg,))
X
X*                   Completely restart the connection process, some kind
X*                   of fatal error has probably occured in the use of a
X*                   particular device.
X
X                    else if (line (1:wlen) .eq. 'restart') 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
X*                   We are connected, start sending the printed data.
X
X                    else if (line (1:wlen) .eq. 'go') then
X                        call close_devs (idx)
X                        jobs(idx).state = ST$_CONNECT
X                        call signal (dclast (exprocess,
X     .                              jobs(idx).ast_arg,))
X
X*                   This is the end of processing.
X
X                    else if (line (1:wlen) .eq. 'end') then
X                        jobs(idx).state = ST$_COMPLETION
X                        jobs(idx).timeout = atoi (outbuf, i)
X                        jobs(idx).recv_str = outbuf(1:10)
X                        call signal (dclast (exprocess,
X     .                              jobs(idx).ast_arg,))
X
X*                   There is no possible way that this queue can continue
X*                   to work, so stop it.
X
X                    else if (line (1:wlen) .eq. 'abort') then
X                        call close_trans (idx)
X                        call close_script (idx)
X                        call close_devs (idx)
X                        call dealloc_dev (idx)
X                        call log_sys (%val (SS$_CANCEL),
X     .                      'Queue cannot continue due to script error', idx
V)
X                        call abort_queue (idx, %descr(outbuf(1:j)),
X     .                          SCRSMB__SCROPER)
X
X*                   There is no possible way that this print job can be
X*                   completed, so $SNDJBC a cancel request!
X
X                    else if (line (1:wlen) .eq. 'quit') then
X                        call close_script (idx)
X                        call close_trans (idx)
X                        call close_devs (idx)
X                        call dealloc_dev (idx)
X                        call log_sys (%val (SS$_CANCEL),
X     .                      'Job cannot continue due to script error', idx)
X                        call abort_job (idx, %descr(outbuf(1:j)))
X
X*                   Log a message to PRINT operators
X
X                    else if (line (1:wlen) .eq. 'oper') then
X                        call log_sys (SCRSMB__SCROPER, %descr(outbuf(1:j)),
V idx)
X                        call signal (dclast (exprocess, jobs(idx).ast_arg,))
X
X*                   Log a message string to the logfile
X
X                    else if (line (1:wlen) .eq. 'log') then
X                        call log_str (SCRSMB__SCRLOG, %descr(outbuf(1:j)), i
Vdx)
X                        call signal (dclast (exprocess, jobs(idx).ast_arg,))
X                    else if (line (1:wlen) .eq. 'transact') then
X                        call open_trans (idx)
X                        call signal (dclast (exprocess, jobs(idx).ast_arg,))
X
X*                   A label, so ignore it.
X
X                    else if (line (wlen:wlen) .eq. ':') then
X                        call signal (dclast (exprocess,
X     .                              jobs(idx).ast_arg,))
X
X*                   A comment line begins with "!".
X
X                    else if (line (1:1) .ne. '!') then
X                        jobs(idx).state = ST$_RETRYDEVS
X                        call log_sys (SCRSMB__BADSCRIPT,
X     .                          'Bad command: ''' // line(1:length(line)) //
X     .                          ''' in script', idx)
X                        call close_script (idx)
X                        call close_trans (idx)
X                        call dealloc_dev (idx)
X                        call signal (dclast (exprocess,
X     .                              jobs(idx).ast_arg,))
X                    endif                           `032
X
X*                   End of file gets you a retry on a new device plus an err
Vor
X*                   message to the operators console.
X
X                else
X                    jobs(idx).state = ST$_RETRYDEVS
X                    call log_sys (SCRSMB__BADSCRIPT,`032
X     .                   'Unexpected file read error or premature EOF', idx)
X                    call close_script (idx)
X                    call close_trans (idx)
X                    call dealloc_dev (idx)
X                    call signal (dclast (exprocess, jobs(idx).ast_arg,))
X                endif
X
X*               Goto sucess label
X
X            else if (state .eq. ST$_GOTOSUCC) then
X                found = goto_script_label (idx, jobs(idx).suc_label)
X
X                if (.not. found) then
X                    jobs(idx).state = ST$_RETRYDEVS
X                    call close_script (idx)
X                    call close_trans (idx)
X                    call dealloc_dev (idx)
X                    call log_sys (SCRSMB__BADSCRIPT,
X     .                  'Success label, ''' //
X     .                  jobs(idx).suc_label(1:blength(jobs(idx).suc_label))
V //
X     .                  ''' not found in script', idx)
X                else
X                    jobs(idx).state = ST$_SCRIPT
X                endif
X
X                call signal (dclast (exprocess, jobs(idx).ast_arg,))
X
X*           Goto failure label
X
X            else if (state .eq. ST$_GOTOFAIL) then
X                found = goto_script_label (idx, jobs(idx).fail_label)
X
X                if (.not. found) then
X                    jobs(idx).state = ST$_RETRYDEVS
X                    call close_script (idx)
X                    call close_trans (idx)
X                    call dealloc_dev (idx)
X                    call log_sys (SCRSMB__BADSCRIPT,
X     .                  'Failure label, ''' //
X     .                  jobs(idx).suc_label(1:blength(jobs(idx).suc_label))
V //
X     .                  ''' not found in script', idx)
X                else
X                    jobs(idx).state = ST$_SCRIPT
X                endif
X                call signal (dclast (exprocess, jobs(idx).ast_arg,))
X
X*           A timeout occured during a receive, so we will continue by tryin
Vg
X*           the next device in the devices list.
X
X            else if (state .eq. ST$_TIMEOUT) then
X                call close_script (idx)
X                call close_trans (idx)
X                call dealloc_dev (idx)
X
X                jobs(idx).state = ST$_RETRYDEVS
X                jobs(idx).device = ' '
X
X                call signal (dclast (exprocess,
X     .                              jobs(idx).ast_arg,))
X
X*           An async $QIO write has completed, so check the status
X*           and make sure that it is OK.
X
X            else if (state .eq. ST$_WRITE) then
X                if ((jobs(idx).iosb(1) .and. 1) .ne. 1) then
X                    stat = jobs(idx).iosb(1)
X                    call log_err (%val (stat), idx,
X     .                  'Can''t write to device')
X                endif
X                jobs(idx).state = ST$_SCRIPT
X                call signal (dclast (exprocess,
X     .                              jobs(idx).ast_arg,))
X
X*           An async $QIO read has completed, so check the status and
X*           make the proper decision on what to do on success or failure.
X
X            else if (state .eq. ST$_RECV) then
X                stat = jobs(idx).iosb(1)
X
X                if (stat) then
X                    call trans_log_num (idx, 'recv succeeds, VMS status: ',
X     .                                                                  stat
V)
X                else
X                    call trans_log_num (idx, 'recv failed, VMS status: ',
X     .                                                                  stat
V)
X                endif
X
X*               On failure to read anything at all, check to see if it was
X*               SS$_HANGUP or SS$_TIMEOUT.  If it was, then use an existing
X*               failure label, or set the state to ST$_TIMEOUT if there is
X*               no failure label.
X
X                if (((stat .and. 1) .ne. 1) .and.
X     .                                      (jobs(idx).iosb(2) .eq. 0)) then
X
X*                   Use an existing failure label first
X
X                    if (jobs(idx).fail_label(1:1) .ne. ' ') then
X                            jobs(idx).state = ST$_GOTOFAIL
X                    else
X
X*                       If no failure label exists, then send an operator
X*                       message if the error was fatal.
X
X                        jobs(idx).state = ST$_TIMEOUT
X                        if ((stat .ne. SS$_TIMEOUT) .and.
X     .                                         (stat .ne. SS$_HANGUP)) then
X                            call log_sys (%val (stat),
X     .                                  'Can''t read from device', idx)
X                        endif
X                    endif
X
X*                   Continue processing by queuing another AST
X
X                    call signal (dclast (exprocess,
X     .                                  jobs(idx).ast_arg,))
X                else`032
X
X*                   The the input read contains the string we are
X*                   looking for, then check for a Success label, and
X*                   goto it, otherwise continue script processing on
X*                   the next input line.
X
X                    call trans_log_str (idx, 'recv''d string is: ',
X     .                      jobs(idx).recv_buf(1:jobs(idx).iosb(2)))
X
X                    if (input_matches (idx, jobs(idx).iosb(2))) then
X                        if (jobs(idx).suc_label(1:1) .ne. ' ') then
X                            jobs(idx).state = ST$_GOTOSUCC
X                        else
X                            jobs(idx).state = ST$_SCRIPT
X                        endif
X                        call signal (dclast (exprocess,
X     .                              jobs(idx).ast_arg,))
X                    else
X
X*                       The input did not match, so look at the
X*                       failure label.  If it begins with a '+', then
X*                       don't use it, because it is only supposed to
X*                       be used on HARD faliures, I.E. timeouts, or
X*                       other serious errors, not mismatched input.
X
X*                       This allows a sequence of "match" statements to
X*                       follow a single read so the error processing can
X*                       be done.
X
X                        if (jobs(idx).fail_label(1:1) .eq. '+') then
X                            jobs(idx).state = ST$_SCRIPT
X                            call signal (dclast (exprocess,
X     .                              jobs(idx).ast_arg,))
X                        else
X
X*                           If there is no '+', then issue another read, and
X*                           get another line of data to look at.
X
X                            call sched_read (idx)
X                        endif
X                    endif
X                endif
X
X*           The entire print job should be completed when this case is enter
Ved.
X
X            else if (state .eq. ST$_COMPLETION) then
X
X*               Free all of our resources, and wait for a while to let other
Vs
X*               at the devices.
X
+-+-+-+-+-+-+-+-  END  OF PART 15 +-+-+-+-+-+-+-+-

