TAL Programmer's Guide

Scanning Arrays
Using Arrays
7–20 096254 Tandem Computers Incorporated
Determining What
Stopped the Scan
To determine what stopped the scan, test $CARRY in an IF statement immediately
after the SCAN or RSCAN statement. If $CARRY is true after a SCAN UNTIL, the test
character did not occur. If $CARRY is true after SCAN WHILE, a character other than
the test character did not occur. Here are examples for using $CARRY:
IF $CARRY THEN ... ; !If test character not found
IF NOT $CARRY THEN ... ; !If test character found
To determine the number of multibyte elements processed, divide (next address '–'
byte address of the array) by the number of bytes per element, using unsigned
arithmetic.
Scanning Bytes in
Word-Aligned Arrays
Operating system procedures require that procedure parameters use INT arrays,
which are word aligned. To scan bytes in a word-aligned array, convert the word
address of the array to a byte address by using the unsigned left-shift operation
('<<' 1).
The following example converts the word address of an INT array to a byte address.
The assignment statement stores the resulting byte address into a STRING pointer.
The SCAN statement then scans the bytes in the array until it finds a comma:
INT .words[-1:3] := [0,"Doe, J",0];
!Declare INT array (WORDS)
STRING .byte_ptr := @words[0] '<<' 1;
!Declare BYTE_PTR; initialize
! with byte address of WORDS[0]
SCAN byte_ptr[0] UNTIL ","; !Scan bytes in WORDS
Multipart Scan Example These declarations apply to a series of scan statement examples that follow:
INT .int_array[-1:9] := [0," Smith, Maurice ",0];
!INT_ARRAY
STRING .sptr := @int_array[0] '<<' 1;
!STRING pointer to INT_ARRAY[0]
STRING .start_last_name, !
.end_last_name, !
.start_first_name, !STRING pointers for next address
.end_first_name, !
.comma; !
INT offset, !
length; !INT variables