Annotation of 43BSD/contrib/icon/rt/equiv.c, revision 1.1.1.1

1.1       root        1: #include "../h/rt.h"
                      2: 
                      3: /*
                      4:  * equiv - test equivalence of two objects.
                      5:  */
                      6: 
                      7: equiv(arg1, arg2)
                      8: struct descrip *arg1, *arg2;
                      9:    {
                     10:    register int result, i;
                     11:    register char *s1, *s2;
                     12: 
                     13:    result = 0;
                     14: 
                     15:       /*
                     16:        * If the descriptors are identical, the objects are equivalent.
                     17:        */
                     18:    if (arg1->type == arg2->type && BLKLOC(*arg1) == BLKLOC(*arg2))
                     19:       result = 1;
                     20:    else if (QUAL(*arg1) && QUAL(*arg2)) {
                     21: 
                     22:       /*
                     23:        * Both objects are strings, or one is &null and the other a string,
                     24:        * If either is &null the other isn't or we wouldn't have
                     25:        *  gotten this far.
                     26:        *  If both are strings of equal length, compare their characters.
                     27:        */
                     28: 
                     29:       if (NULLDESC(*arg1) || NULLDESC(*arg2))
                     30:          result = 0;
                     31:       else if ((i = STRLEN(*arg1)) == STRLEN(*arg2)) {
                     32:          s1 = STRLOC(*arg1);
                     33:          s2 = STRLOC(*arg2);
                     34:          result = 1;
                     35:          while (i--)
                     36:            if (*s1++ != *s2++) {
                     37:               result = 0;
                     38:               break;
                     39:               }
                     40:          }
                     41:       }
                     42:    else if (arg1->type == arg2->type)
                     43:       switch (TYPE(*arg1)) {
                     44:          /*
                     45:           * For integers and reals, just compare the values.
                     46:           */
                     47:          case T_INTEGER:
                     48:             result = (INTVAL(*arg1) == INTVAL(*arg2));
                     49:             break;
                     50: #ifdef LONGS
                     51:          case T_LONGINT:
                     52:             result =
                     53:                (BLKLOC(*arg1)->longint.intval == BLKLOC(*arg2)->longint.intval);
                     54:             break;
                     55: #endif LONGS
                     56:          case T_REAL:
                     57:             result =
                     58:                (BLKLOC(*arg1)->realblk.realval == BLKLOC(*arg2)->realblk.realval);
                     59:             break;
                     60:          case T_CSET:
                     61:             /*
                     62:              * Compare the bit arrays of the csets.
                     63:              */
                     64:             result = 1;
                     65:             for (i = 0; i < CSETSIZE; i++)
                     66:                if (BLKLOC(*arg1)->cset.bits[i] != BLKLOC(*arg2)->cset.bits[i]) {
                     67:                   result = 0;
                     68:                   break;
                     69:                   }
                     70:          }
                     71:    else
                     72:       /*
                     73:        * arg1 and arg2 are of different types, so they can't be
                     74:        *  equivalent.
                     75:        */
                     76:       result = 0;
                     77: 
                     78:    return (result);
                     79:    }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.