Guardian Programmer's Guide

Table Of Contents
Formatting and Manipulating Character Data
Guardian Programmer’s Guide 421922-014
19 - 28
List-Directed Formatting
The user responds to the second prompt by typing a name. The name is a character
string and must be enclosed in single quotation marks:
Enter your name (up to 20 characters):
'Tom Sawyer'
The program puts the name into the second of the input buffers. Once again, the
program fills the buffer with blanks before reading from the terminal, eliminating the
need to type a value-termination character after the name.
The program calls the FORMATDATA procedure to convert the data in the input
buffers. FORMATDATA reads the buffers left-to-right, starting with the first buffer.
FORMATDATA uses the first data descriptor (VLIST[0]) in the list of data descriptors to
format the first value: the month. Note that the data type is specified by the data
descriptor as type 0 (character data). If the value in the input buffer is enclosed in
quotation marks, then FORMATDATA places that value into a 10-element string array
pointed to by @MONTH. If the input value is not in single quotation marks, then
FORMATDATA returns error 272 (illegal input character).
Similarly, FORMATDATA reads the second value in the input buffer and processes it
using data descriptor VLIST[1], and so on.
When handling potential errors, this program prompts you to enter your data again if
the error is of a type that is caused by entering incorrect data. For nonrecoverable
errors, the program prints a diagnostic message and exits.
?INSPECT,SYMBOLS,NOMAP,NOCODE
?NOLIST, SOURCE $SYSTEM.ZSYSDEFS.ZSYSTAL
?LIST
!Global literals and variables:
LITERAL MAXFLEN = ZSYS^VAL^LEN^FILENAME; !max file-name
! length
LITERAL BUFSIZE = 512; !size of I/O buffer
INT TERM^NUM; !file number for terminal
INT ERROR; !returned by system procedures
STRING .S^PTR; !string pointer
STRING .SBUFFER[0:511]; !buffer for terminal I/O
?NOLIST
?SOURCE $SYSTEM.SYSTEM.EXTDECS0(FORMATDATA,PROCESS_GETINFO_,
? PROCESS_STOP_,WRITEX,WRITEREADX,FILE_OPEN_,
? INITIALIZER)
?LIST