SPL to HP C/XL Migration Guide (30231-90001)

5-37
| In SCAN-UNTIL, scan starts at
byte-ref
and | |
| continues until either
test-char
or | |
|
terminal-char
is found. | |
| | |
| In SCAN-WHILE, scan starts at
byte-ref
and | |
| continues until either
terminal-char
is | |
| found or character NOT matching
test-char
| |
| is found. | |
| | |
| Carry bit in status register is set to one | |
| if
terminal-char
was found; otherwise, it | |
| is set to zero. | |
| | |
| The address of the terminating byte is | |
| placed on the stack. | |
| | |
---------------------------------------------------------------------------------------------
| | |
| May be used (without
stack-decr
) as an | |
| arithmetic function. Its value is the | |
| number of words or bytes scanned. | |
| | |
---------------------------------------------------------------------------------------------
The SCAN statement in SPL searches a string of bytes for either of two
characters, a test character and a terminating character. The statement
may be used either as a function to return the number of bytes scanned,
or with a stack decrement value to leave information on the stack.
The HP C/XL library contains string search functions which perform
similar operations. For example, the SPL statements
SCAN B1 WHILE " ",0; <<scan while zero or blank>>
T := TOS; <<testword, always unchanged>>
@S1 := TOS; <<address of first blank>>
may be duplicated in HP C/XL by
s1 = strchr(b1,' ');
The strchr function searches for a single character, returning an ad-
dress where it was found. To look for two characters, as SCAN does,
another function may be used:
s1 = b1 + strcspn(b1,"% ");
The function strcspn returns a count of the number of characters which
were
not
any of the characters in the second parameter. This value
added to the address being searched yields the address of the first oc-
currence of a character in the string supplied as the second parameter.
SCAN may be used as a function. For example,
NUM := SCAN B1 UNTIL " ";
or
NUM := SCAN B1 UNTIL "% ";