HP C/XL SCANW Function: Scan While [ SPL to HP C/XL Migration Guide ] MPE/iX 5.0 Documentation
SPL to HP C/XL Migration Guide
HP C/XL SCANW Function: Scan While
/********************************************************************
SCANW SPL SCAN WHILE
This emulates the SCAN while statement in SPL, for example:
NUM := (SCAN B1 WHILE TEST, 0);
T := TOS; <<test word -- unchanged>>
@S1 := TOS;
which may be converted to C with:
LEN := SCANW(B1,TEST,0,&S1);
The parameters to SCANW are:
ba -- The address to be scanned.
test -- The testword. This is two bytes; the first is
the terminate character, the second is the test
character. Either of these will terminate the
scan operation.
sdec -- The SPL stack decrement. In this context, the
value of this parameter will determine if the
function accesses the last parameter, as follows:
sdec = 2 -- Ignore the last parameter (which
need not be present).
sdec = 1 -- Expect one parameter after this,
scan_addr.
sdec = 0 -- Same as 1. In SPL, an sdec of 1 or
2 deletes the test word from the
stack, which is always unchanged
after the SCAN operation.
scan_addr -- The address of the char which stopped the SCAN
operation (i.e. failed to equal either the terminal
or the test character).
The return value of the function is the number of bytes moved.
********************************************************************/
short int SCANW(ba,test,sdec,scan_addr)
char *ba, **scan_addr;
unsigned short test;
int sdec;
{
char temc, testc, *temp;
temp = ba;
termc = (char)test >> 8;
testc = (char)test & OxFF;
while ((*ba == testc) || (*ba == testc)) ba++;
switch (sdec) {
case 0: ; /* fall through to case 1 */
case 1: *scan_addr = ba;
case 2: ; /* nil */
}
return(ba-temp);
}
MPE/iX 5.0 Documentation