;CaptureAndSend.WAS     v1.0

;*****************************************************************************
;*                                                                           *
;* CaptureAndSend.WAS                                                        *
;* Copyright (C) 1998 Symantec                                               *
;* All rights reserved.                                                      *
;*                                                                           *
;* Written by:  Symantec ASPECT Assist                                       *
;* 11/30/97                                                                  *
;*                                                                           *                                                                             
;* This script file captures information from the Terminal screen, and then  *
;* transmits the Capture file to another host system.                        *
;*                                                                           *
;*                                                                           *
;* This ASPECT script is intended only as a sample of ASPECT programming.    *
;* Symantec makes no warranty of any kind, express or implied, including     *
;* without limitation, any warranties of merchantability and/or fitness      *
;* for a particular purpose.  Use of this program is at your own risk.       *
;*                                                                           *
;* Technical Support is not provided on this script.                         *                                                                          *
;*****************************************************************************

;*************************************************************************
;* MACRO                                                                 *
;*************************************************************************
#define CapSpec "C:\*.cap"                       ; File Spec for Capture File Box.
#define FileSpec "C:\*.txt"                      ; File Spec for Input File Box.


;***************************************************************************
;*                                                                         *
;* MAIN                                                                    *
;*                                                                         *
;* This procedure gets the Capture File and Input File from the user.      *
;* It then calls StartProcess to process the input file and start the      *                               
;* Capture file.                                                           *
;*                                                                         *
;* Calls:            StartProcess                                          *
;* Called by:        None                                                  *
;* Modifies Globals: None                                                  *
;* Returns:          None                                                  *
;*                                                                         *
;***************************************************************************
proc main

   string InputFile, CapFile
   integer Choice
   
   if sdlgsaveas "Capture File Saved Name" CapSpec CapFile 
                                              ; Save capture file.
                                              
      if sdlgfopen "Choose Input File" FileSpec SINGLE InputFile  
                                              ; Select input file.
         StartProcess(CapFile, InputFile)     ; Call StartProcess.
      else
         sdlgmsgbox " Input File Not Selected     " "Script will end." STOP OK Choice
      endif
   else
      sdlgmsgbox " Capture File Not Selected     " "Script will end." STOP OK Choice
   endif
endproc


;***************************************************************************
;*                                                                         *
;* StartProcess                                                            *
;*                                                                         *
;* This procedure starts the Capture file with the CapFile path and name,  *
;* then opens the input file.  It will process the input file one line at  *
;* at a time sending the read line to the host system, and then waiting    *
;* for an ASCII 17 to be sent from the host system to continue.            *
;*                                                                         *
;* Calls:            None                                                  *
;* Called by:        Main                                                  *
;* Modifies Globals: None                                                  *
;* Returns:          None                                                  *
;*                                                                         *
;***************************************************************************
proc StartProcess
param string CapFile, InputFile

   string ReadLine, FileName, PathName
   string ASCII_17 = ""                      ; ASCII 17 character.
   integer TestLen

   getfilename FileName CapFile               ; Extract file name from path.
   getpathname PathName CapFile               ; Extract path without file name.
   set capture overwrite on                   ; Overwrite the capture file if exists.
   set capture path PathName                  ; Set the capture path.
   set capture file FileName                  ; Set the capture file name.
   capture ON                                 ; Start capturing the session.
   if fopen 0 InputFile READ TEXT             ; Open file for read only.
      while not feof 0                        ; Loop while not end of file.
         fgets 0 ReadLine                     ; Get line from file.
         strlen ReadLine TestLen              ; Get the length of Readlin.
         if testlen < 1                       ; If just the EOF marker
            exitwhile                         ; exit.
         endif 
         transmit ReadLine                    ; Transmit the read line to the host.
         transmit "^M^J"                      ; Transmit a CR/LF for the host.
         waitfor ASCII_17 5                   ; Waitfor Special Character for 5 sec.
      endwhile
      fclose 0                                ; Close file opened for read.
   else
      errormsg "Couldn't open file `"%s`"." InputFile
   endif
endproc
