Guardian Programmer's Guide

Table Of Contents
Communicating With Printers
Guardian Programmer’s Guide 421922-014
11 - 31
Sample Program for Using a Printer
sent to the operator. However, if the information being printed is not considered
critical, the line can be reprinted (and may thus be duplicated).
Sample Program for Using a Printer
The following example modifies the inventory program developed in Section 5,
Communicating With Disk Files. It now includes an option to print the contents of the
data file. This example also includes logic to read the name of the printer or spooler
collector you wish to print to from the OUT file named in the Startup message.
The example adds some new procedures and makes changes to the MAIN and
GET^COMMAND procedures as follows:
The MAIN and GET^COMMAND procedures now contain logic to process an
option “p” to print the contents of the data file.
Option “p” selects the PRINT^FILE procedure. This procedure puts one print line
of information in a buffer and then sends the buffer to the PRINT^OUT procedure
for printing. PRINT^FILE does this by reading each record in turn from the data
file, taking each field in turn, putting the information into the buffer with suitable
leading text, and then calling PRINT^OUT.
In addition to sending the formatted buffer to the line printer, the PRINT^OUT
procedure also performs error checking and error processing. By calling the
FILEERROR procedure, it is able to decide whether to retry a particular error, wait
for a user response before retrying, or abend the operation.
The INIT and SAVE^STARTUP^MESSAGE procedures have been added to
perform file initialization. The terminal file name is taken from the IN file name of
the Startup message.
?INSPECT,SYMBOLS,NOMAP,NOCODE
?NOLIST, SOURCE $TOOLS.ZTOOLD04.ZSYSTAL
?LIST
LITERAL MAXFLEN = ZSYS^VAL^LEN^FILENAME; !maximum file-
! name length
LITERAL OLD = 0;
LITERAL NEW = 1;
LITERAL BUFSIZE = 132;
LITERAL PARTSIZE= 6;
LITERAL DESCSIZE= 60;
LITERAL SUPPSIZE= 60;
LITERAL ABEND = 1;
STRING .SBUFFER[0:BUFSIZE]; !I/O buffer (one extra char)
STRING .S^PTR; !pointer to end of string
INT PARTFILE^NUM; !part file number
Note. This example assumes a 5515/5516/5518 printer. To make the example work with
another type of printer, you need to change the escape sequences used by the PRINT^FILE
procedure for underlining text for the mechanism used on the printer you have.