;DnLoad_And_Print.WAS     v1.0

;*****************************************************************************
;*                                                                           *
;* DnLoad_And_Print.WAS                                                      *
;* Copyright (C) 1998 Symantec                                               *
;* All rights reserved.                                                      *
;*                                                                           *
;* Written by:  Symantec ASPECT Assist                                       *
;* 01/27/97                                                                  *
;*                                                                           *                                                                             
;* This script file downloads a single file from a host system and prints    *
;* it.  The script provides user messages if file transfer or printing is    *
;* unsuccessful, and sets print margins via ASPECT.                          *
;*                                                                           *
;*                                                                           *
;* 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.                         *                                                                          
;*                                                                           *
;*****************************************************************************


;********************************************************************
;* GLOBAL VARIABLES                                                 *
;********************************************************************
string DownloadPath			;holds the download path
string TempFile				;holds file to be printed


;********************************************************************
;* Main ()                                                          *
;*								    *
;* Called by:   None                                                *
;* Modifies globals: None                                           *
;* Calls: Initialize(), PrintFile(), Cleanup()                      * 
;********************************************************************
proc main
integer XferProgress			;holds the transfer status

   Initialize()				;init parameters
   getfile XMODEM TempFile		;download file using XMODEM
   XferProgress=$XFERSTATUS		;init transfer status
   while XferProgress==1		;while transfer in progress
      yield				;yield CPU time
      XferProgress=$XFERSTATUS		;update transfer status
   endwhile
   rxflush				;clear receive buffer
   txflush				;clear transmit buffer
   pause 2
   if XferProgress==2         		;file transfer was successful
      PrintFile()			;print the file
      Cleanup()
   else
      usermsg "Failed to download file, try again..."
      Cleanup()
   endif     
endproc


;********************************************************************
;* Initialize ()                                                    *
;* This procedure inits the Tempfile name and deletes if it is      *
;* present on local harddrive					    *
;* Called by:  main                                                 *
;* Modifies globals:  TempFile                                      *
;********************************************************************
proc Initialize

   fetch dnldpath DownloadPath 		;get the download path
   strfmt TempFile "%s\tteesstt.txt" DownloadPath	;set file name
   if isfile TempFile			;if file is present 
      delfile TempFile			;delete it
   endif
endproc

      
;********************************************************************
;* PrintFile()                                                      *
;* This procedure is used to print the file we download
;* Called by:                                                       *
;* Modifies globals:                                                *
;********************************************************************
proc PrintFile
string WholeLine			;holds a line of text

   if not fopen 0 TempFile READ TEXT	;open file to be printed
      errormsg "Cannot open file to be printed, script will terminate" TempFile
      Cleanup()				;if we cannot open the file, we exit the script
   endif
   if printer open            		;Open the print device.
      printalign LEFT                   ;Set print to left justified
      printmargin 0.5 0.5               ;Set the print margins
      fseek 0 0 0			;go to beginning of file
      while not feof 0			;while not end of file
         fgets 0 WholeLine		;read a line
         if nullstr WholeLine		;if line is blank
            printstr "`n"		;print a new line
            loopwhile
         endif
         printstr WholeLine		;line not blank, print it
         printstr "`n"			;print new line
      endwhile
      printer close           		;close the print device.
      fclose 0				;close file
   else					;could not open print device
      fclose 0
      errormsg "Couldn't open the printer device!, Terminating"
      Cleanup()
   endif
endproc


;********************************************************************
;* Cleanup()                                                        *
;* This procedure simply exits the script                           *
;* Called by: main, printfile                                       *
;* Modifies globals: none                                           *
;********************************************************************
proc Cleanup

   exit
endproc      
