SCAN Statement [ SPL to HP C/XL Migration Guide ] MPE/iX 5.0 Documentation
SPL to HP C/XL Migration Guide
SCAN Statement
Table 5-30. SCAN Statement
---------------------------------------------------------------------------------------------
| | |
| SPL | HP C/XL Equivalent |
| | |
---------------------------------------------------------------------------------------------
| | |
| scan-statement: | No direct equivalent. |
| | |
| SCAN byte-ref {WHILE | |
| UNTIL} testword | |
| | |
| [, stack-decr] | |
| | |
---------------------------------------------------------------------------------------------
| | |
| byte-ref is one of: | Same as SPL, except * stack reference must |
| | be recoded. |
| array/pointer-id | |
| | |
| array/pointer-id ( index ) | |
| | |
| * | |
| | |
---------------------------------------------------------------------------------------------
| | |
| testword is one of: | |
| | |
| integer constant | |
| INTEGER or LOGICAL variable | |
| string constant of one or two characters | |
| * | |
| | |
---------------------------------------------------------------------------------------------
| | |
| First character of testword is | |
| terminal-char. Second character of | |
| testword is test-char. If terminal-char is | |
| omitted, it is NUL (numeric 0). | |
| | |
---------------------------------------------------------------------------------------------
| | |
| 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 address
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 occurrence
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 "% ";
In this case, these statements might become:
NUM = strchr(B1,' ') - B1;"
or
NUM = strcspn(B1,"% ");
NOTE The HP C/XL library function memchr can be used to scan strings
that are not terminated by NUL ('\0', numeric value 0). For more
information on memchr and its related functions and on the str...
series of functions, see the HP C/XL Library Reference Manual.
The HP C/XL SCANU function, shown in Figure 5-25, duplicates the
SCAN-UNTIL operation.
________________________________________________________
| |
| int SCANU(ba,test,sdec,scan_adr) |
| char *ba, *scan_adr; |
| unsigned short test; |
| int sdec; |
| { |
| char termc, testc, *temp; |
| temp = ba; |
| termc = (char)test >> 8; |
| testc = (char)test & 0xFF; |
| while ((*ba != testc) && (*ba != testc)) ba++;|
| switch (sdec) |
| { |
| case 0: ; /* fall through to case 1 */ |
| case 1: *scan_adr = ba; |
| case 2: ; /* nil */ |
| } |
| return(ba - temp); |
| } |
________________________________________________________
Figure 5-25. HP C/XL SCANU Function: SCAN-UNTIL Statement
MPE/iX 5.0 Documentation