SPL BYTECMP Procedure: Byte Comparison [ SPL to HP C/XL Migration Guide ] MPE/iX 5.0 Documentation
SPL to HP C/XL Migration Guide
SPL BYTECMP Procedure: Byte Comparison
<< BYTECMP SPL COMPARE BYTE STRINGS >>
<< >>
<< This emulates the byte string compare expression in SPL, >>
<< for example: >>
<< IF A < B,(N),0; >>
<< NN := TOS; {count} >>
<< @AA := TOS; {left address after compare} >>
<< @BB := TOS; {right address after compare} >>
<< This may be converted to C with: >>
<< if (BYTECMP(a,LSS,b,n,0,&nn,&aa,&bb))....>>
<< >>
<< The parameters to BYTECMP are: >>
<< left -- The left address to be compared. >>
<< cmp -- The comparison to be made. Here the following >>
<< syntax exists. >>
<< LSS means < >>
<< LEQ means <= >>
<< EQU means == >>
<< NEQ means <> >>
<< GEQ means >= >>
<< GTR means > >>
<< right -- The right address to be compared. >>
<< count -- The maximum number of bytes to compare. >>
<< 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 = 3 -- Ignore the last three >>
<< parameters (in SPL, this is >>
<< the default case, deleting >>
<< three stack words). >>
<< sdec = 2 -- Expect only one parameter after>>
<< this, cnt. >>
<< sdec = 1 -- Expect two parameters after >>
<< this, cnt and laddr. >>
<< sdec = 0 -- Expect three parameters after >>
<< this, cnt, laddr, and raddr. >>
<< cnt -- The value of "count" at the conclusion of the >>
<< comparison. If the strings compare for count >>
<< bytes, cnt will equal zero. >>
<< laddr -- The address of the char within the left string >>
<< which failed to match. >>
<< raddr -- The address of the char within the right string>>
<< which failed to match. >>
DEFINE LSS=0#, LEQ=1#, EQU=2#, NEQ=3#, GEQ=4#, GTR=5#;
INTEGER PROCEDURE BYTECMP(left,cmp,right,count,sdec,cnt,laddr,raddr);
VALUE left, cmp, right, count, sdec, cnt, laddr, raddr;
LOGICAL left, right, laddr, raddr;
INTEGER cmp, count, sdec, cnt;
BEGIN
DEFINE ADJ =
DO BEGIN
IF count > 0
THEN BEGIN count:=count-1; @lftp:=@lftp+1; @rhtp:=@rhtp+1; END
ELSE BEGIN count:=count+1; @lftp:=@lftp-1; @rhtp:=@rhtp-1; END;
END#;
BYTE POINTER lftp, rhtp, laddrp, raddrp;
INTEGER POINTER cntp;
@lftp := left;
@rhtp := rht;
@cntp := cnt;
@laddrp := laddr;
@raddrp := raddr;
CASE cmp OF
BEGIN
<<LSS: compare < >>
BEGIN WHILE (count <> 0) AND (lftp < rhtp) ADJ END;
<<LEQ: compare <= >>
BEGIN WHILE (count <> 0) AND (lftp <= rhtp) ADJ END;
<<EQU: compare == >>
BEGIN WHILE (count <> 0) AND (lftp == rhtp) ADJ END;
<<NEQ: compare <> >>
BEGIN WHILE (count <> 0) AND (lftp <> rhtp) ADJ END;
<<GEQ: compare >= >>
BEGIN WHILE (count <> 0) AND (lftp >= rhtp) ADJ END;
<<GTR: compare > >>
BEGIN WHILE (count <> 0) AND (lftp > rhtp) ADJ END;
END;
CASE sdec OF
BEGIN
<< 0 >> GOTO sdec 0;
<< 1 >> GOTO sdec 1;
<< 2 >> GOTO sdec 2;
<< 3 >> GOTO sdec 3;
END;
sdec0: raddrp := rhtp;
sdec1: laddrp := lftp;
sdec2: cntp := count;
sdec3: ; << nil >>
BYTECMP := IF count = 0 THEN 1 ELSE 0;
END;
MPE/iX 5.0 Documentation