Guardian Programmer's Guide

Table Of Contents
Formatting and Manipulating Character Data
Guardian Programmer’s Guide 421922-014
19 - 9
Format-Directed Formatting
The code fragment shown below processes some alphanumeric characters and some
numeric characters.
The first part of the code fragment sets up the edit descriptors for seven alphanumeric
data items to be retrieved using the first data descriptor and displayed with five
characters each, and for seven integer data items to be retrieved from the array
pointed to by the second data descriptor and displayed in five character positions each.
The FORMATCONVERT procedure returns an internal form of the edit descriptors in
the IFORMAT variable.
The code fragment sets up two arrays: one to contain the seven items of alphanumeric
data (DAYS^ARRAY) and one to contain numeric data (INT^ARRAY). Two data
descriptors point to these arrays: VLIST[0] points to DAYS^ARRAY, and VLIST[1]
points to INT^ARRAY. In addition to the pointers, these data descriptors also indicate
the scale factor, the size of each data element, and the number of occurrences.
Finally, the code fragment calls the FORMATDATA procedure. The major input
parameters to this procedure are the data descriptors in the VLIST array and the
internal format in WFORMAT. Note that WFORMAT is a word pointer to the string
array returned by the FORMATCONVERT procedure in IFORMAT.
!Set up the edit descriptors and convert to internal form:
EFORMAT ':=' "7(A5),7(I5)";
SCALES := 0;
CONVERSION := 1;
ERROR := FORMATCONVERT(IFORMAT,
IFORMATLEN,
EFORMAT,
EFORMATLEN,
SCALES,
SCALE^COUNT,
CONVERSION);
IF ERROR <= 0 THEN ...
!Set up arrays for the days of the week and the date:
DAYS^ARRAY ':=' ["MON","TUE","WED","THU","FRI","SAT","SUN"];
INT^ARRAY ':=' [1,2,3,4,5,6,7];
!Set up list elements that point to the above arrays:
VLIST^LEN := 2;
FLAGS := 0;
VLIST[0].ELEMENT^PTR := @DAYS^ARRAY;
VLIST[0].ELEMENT^SCALE := 0;
VLIST[0].ELEMENT^TYPE := 0;
VLIST[0].ELEMENT^LENGTH := 4;
VLIST[0].ELEMENT^OCCURS := 1;
VLIST[1].ELEMENT^PTR := @INT^ARRAY;
VLIST[1].ELEMENT^SCALE := 0;
VLIST[1].ELEMENT^TYPE := 2;
VLIST[1].ELEMENT^LENGTH := 2;
VLIST[1].ELEMENT^OCCURS := 7;