HP 3000 Manuals

HP C/XL BYTECMP Function: Byte Comparison [ SPL to HP C/XL Migration Guide ] MPE/iX 5.0 Documentation


SPL to HP C/XL Migration Guide

HP C/XL BYTECMP Function:  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, where:
                           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 last three parameters
                                   (in SPL, this is the default
                                   case, deleting 3 stack words).
                       sdec = 2  -- Expect only one parameter
                                   after this:  caddr.
                       sdec = 1  -- Expect two parameters after
                                   this:  caddr and laddr.
                       sdec = 0  -- Expect three parameters after
                                   this:  caddr, laddr, and
                                   raddr.
         caddr        --  The value of count at the conclusion of the
                       comparison.  If the strings compare for
                       count bytes, caddr 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.

     ***************************************************************/

     enum CMP {LSS, LEQ, EQU, NEQ, GEQ, GTR };
     short int BYTECMP(left,cmp,right,count,sdec,caddr,laddr,raddr)
       char *left, *right, **laddr, **raddr;
       enum CMP cmp;
       int count, sdec, *caddr;
     {
     #define ADJ  {if (count>0) {--count;++left;++right;}  \
                           else {++count;--eft;--right;}}
       switch (cmp)  {
         case LSS:  /* compare < */
                    while ((count != 0) && (*left < *right))  ADJ;
                    break;
         case LEQ:  /* compare <= */
                    while ((count != 0) && (*left <= *right))  ADJ;
                    break;
         case EQU:  /* compare == */
                    while ((count != 0) && (*left == *right))  ADJ;
                    break;
         case NEQ:  /* compare != */
                    while ((count != 0) && (*left != *right))  ADJ;
                    break;
         case GEQ:  /* compare >= */
                    while ((count != 0) && (*left >= *right))  ADJ;
                    break;
         case GTR:  /* compare > */
                    while ((count != 0) && (*left > *right))  ADJ;
                    break;
       }
       switch (sdec) {
         case 0:  *raddr = right;
         case 1:  *laddr = left;
         case 2:  *caddr = count;
         case 3:  ;  /* nil */
       }
       return (count == 0);
     #undef ADJ
     }



MPE/iX 5.0 Documentation