pTAL Guidelines for TAL Programmers

Coding Guidelines
pTAL Guidelines for TAL Programmers527256-002
2-21
Addresses Are Absolute
You might want to use a SCAN or RSCAN statement to scan a string of characters.
The SCAN or RSCAN statement, however, can scan strings only in the user data
segment—the pointer to the data cannot be an extended pointer.
In Example 2-18 on page 2-21, the procedure p scans a string of bytes which must be
either in the lower half of the user data segment or in an extended data segment. If the
string is in an extended data segment, procedure p first moves the string into a local
buffer. To determine whether the string is already in the user data segment, the
program tests the value of the data address. If the address is less than %2000000, the
data is already in the user data segment; otherwise, the data is in an extended data
segment.
Example 2-17. Comparing Two Addresses
STRING .a[0:90];
STRING .ptr;
BADDR max_addr := @a '+' 79;
SCAN a until " " -> @ptr;
IF @ptr '>' max_addr THEN ...
Example 2-18. Determining Location of Data Before Scanning (TAL Only)
PROC p(xptr:cnt);
STRING .EXT xptr;
INT cnt;
BEGIN
STRING .loc;
STRING .buff[0:99];
IF @xptr < %2000000d THEN ! Data already in user data
BEGIN ! segment
@loc := $INT(@xptr); ! Set pointer to data
SCAN loc UNTIL " " -> @loc; ! Scan data
END
ELSE ! Data not in user data seg
BEGIN
buff ':=' xptr FOR cnt BYTES; ! Move data to user data
! segment
SCAN buff UNTIL " " -> @loc; ! Scan data
END
END;