Annotation of researchv10dc/cmd/icon/src/iconx/ocomp.c, revision 1.1.1.1

1.1       root        1: /*
                      2:  * File: ocomp.c
                      3:  *  Contents: lexeq, lexge, lexgt, lexle, lexlt, lexne, numeq, numge,
                      4:  *             numgt, numle, numlt, numne, eqv, neqv
                      5:  */
                      6: 
                      7: #include "../h/rt.h"
                      8: 
                      9: /*
                     10:  * x == y - test if x is lexically equal to y.
                     11:  */
                     12: 
                     13: OpDcl(lexeq,2,"==")
                     14:    {
                     15:    register int t;
                     16:    word i;
                     17:    register char *s1, *s2;
                     18:    char sbuf1[MaxCvtLen], sbuf2[MaxCvtLen];
                     19:    extern char *alcstr();
                     20: 
                     21:    /*
                     22:     * x and y must be strings.  Save the cvstr return value for y because
                     23:     *  y is the result (if any).
                     24:     */
                     25:    if (cvstr(&Arg1, sbuf1) == NULL)
                     26:       runerr(103, &Arg1);
                     27:    if ((t = cvstr(&Arg2, sbuf2)) == NULL)
                     28:       runerr(103, &Arg2);
                     29: 
                     30:    /*
                     31:     * If the strings have different lengths they can't be equal
                     32:     */
                     33:    if (StrLen(Arg1) != StrLen(Arg2))
                     34:       Fail;
                     35: 
                     36:    /*
                     37:     * compare the strings
                     38:     */
                     39:    i = StrLen(Arg1);
                     40:    s1 = StrLoc(Arg1);
                     41:    s2 = StrLoc(Arg2);
                     42:    while (i--)
                     43:       if (*s1++ != *s2++)
                     44:          Fail;
                     45: 
                     46:    /*
                     47:     * Return y as the result of the comparison.  If y was converted to
                     48:     *  a string, a copy of it is allocated.
                     49:     */
                     50:    Arg0 = Arg2;
                     51:    if (t == Cvt) {
                     52:       strreq(StrLen(Arg0));
                     53:       StrLoc(Arg0) = alcstr(StrLoc(Arg0), StrLen(Arg0));
                     54:       }
                     55:    Return;
                     56:    }
                     57: 
                     58: 
                     59: /*
                     60:  * x >>= y - test if x is lexically greater than or equal to y.
                     61:  */
                     62: 
                     63: OpDcl(lexge,2,">>=")
                     64:    {
                     65:    register int t;
                     66:    char sbuf1[MaxCvtLen], sbuf2[MaxCvtLen];
                     67:    extern char *alcstr();
                     68: 
                     69:    /*
                     70:     * x and y must be strings.  Save the cvstr return value for y because
                     71:     *  y is the result (if any).
                     72:     */
                     73:    if (cvstr(&Arg1, sbuf1) == NULL)
                     74:       runerr(103, &Arg1);
                     75:    if ((t = cvstr(&Arg2, sbuf2)) == NULL)
                     76:       runerr(103, &Arg2);
                     77: 
                     78:    /*
                     79:     * lexcmp does the work.
                     80:     */
                     81:    if (lexcmp(&Arg1, &Arg2) < 0)
                     82:       Fail;
                     83: 
                     84:    /*
                     85:     * Return y as the result of the comparison.  If y was converted to
                     86:     *  a string, a copy of it is allocated.
                     87:     */
                     88:    Arg0 = Arg2;
                     89:    if (t == Cvt) {
                     90:       strreq(StrLen(Arg0));
                     91:       StrLoc(Arg0) = alcstr(StrLoc(Arg0), StrLen(Arg0));
                     92:       }
                     93:    Return;
                     94:    }
                     95: 
                     96: 
                     97: /*
                     98:  * x >> y - test if x is lexically greater than y.
                     99:  */
                    100: 
                    101: OpDcl(lexgt,2,">>")
                    102:    {
                    103:    register int t;
                    104:    char sbuf1[MaxCvtLen], sbuf2[MaxCvtLen];
                    105:    extern char *alcstr();
                    106: 
                    107:    /*
                    108:     * x and y must be strings.  Save the cvstr return value for y because
                    109:     *  y is the result (if any).
                    110:     */
                    111:    if (cvstr(&Arg1, sbuf1) == NULL)
                    112:       runerr(103, &Arg1);
                    113:    if ((t = cvstr(&Arg2, sbuf2)) == NULL)
                    114:       runerr(103, &Arg2);
                    115: 
                    116:    /*
                    117:     * lexcmp does the work.
                    118:     */
                    119:    if (lexcmp(&Arg1, &Arg2) <= 0)
                    120:       Fail;
                    121: 
                    122:    /*
                    123:     * Return y as the result of the comparison.  If y was converted to
                    124:     *  a string, a copy of it is allocated.
                    125:     */
                    126:    Arg0 = Arg2;
                    127:    if (t == Cvt) {
                    128:       strreq(StrLen(Arg0));
                    129:       StrLoc(Arg0) = alcstr(StrLoc(Arg0), StrLen(Arg0));
                    130:       }
                    131:    Return;
                    132:    }
                    133: 
                    134: 
                    135: /*
                    136:  * x <<= y - test if x is lexically less than or equal to y.
                    137:  */
                    138: 
                    139: OpDcl(lexle,2,"<<=")
                    140:    {
                    141:    register int t;
                    142:    char sbuf1[MaxCvtLen], sbuf2[MaxCvtLen];
                    143:    extern char *alcstr();
                    144: 
                    145:    /*
                    146:     * x and y must be strings.  Save the cvstr return value for y because
                    147:     *  y is the result (if any).
                    148:     */
                    149:    if (cvstr(&Arg1, sbuf1) == NULL)
                    150:       runerr(103, &Arg1);
                    151:    if ((t = cvstr(&Arg2, sbuf2)) == NULL)
                    152:       runerr(103, &Arg2);
                    153: 
                    154:    /*
                    155:     * lexcmp does the work.
                    156:     */
                    157:    if (lexcmp(&Arg1, &Arg2) > 0)
                    158:       Fail;
                    159: 
                    160:    /*
                    161:     * Return y as the result of the comparison.  If y was converted to
                    162:     *  a string, a copy of it is allocated.
                    163:     */
                    164:    Arg0 = Arg2;
                    165:    if (t == Cvt) {
                    166:       strreq(StrLen(Arg0));
                    167:       StrLoc(Arg0) = alcstr(StrLoc(Arg0), StrLen(Arg0));
                    168:       }
                    169:    Return;
                    170:    }
                    171: 
                    172: 
                    173: /*
                    174:  * x << y - test if x is lexically less than y.
                    175:  */
                    176: 
                    177: OpDcl(lexlt,2,"<<")
                    178:    {
                    179:    register int t;
                    180:    char sbuf1[MaxCvtLen], sbuf2[MaxCvtLen];
                    181:    extern char *alcstr();
                    182: 
                    183:    /*
                    184:     * x and y must be strings.  Save the cvstr return value for y because
                    185:     *  y is the result (if any).
                    186:     */
                    187:    if (cvstr(&Arg1, sbuf1) == NULL)
                    188:       runerr(103, &Arg1);
                    189:    if ((t = cvstr(&Arg2, sbuf2)) == NULL)
                    190:       runerr(103, &Arg2);
                    191: 
                    192:    /*
                    193:     * lexcmp does the work.
                    194:     */
                    195:    if (lexcmp(&Arg1, &Arg2) >= 0)
                    196:       Fail;
                    197: 
                    198:    /*
                    199:     * Return y as the result of the comparison.  If y was converted to
                    200:     *  a string, a copy of it is allocated.
                    201:     */
                    202:    Arg0 = Arg2;
                    203:    if (t == Cvt) {             /* string needs to be allocated */
                    204:       strreq(StrLen(Arg0));
                    205:       StrLoc(Arg0) = alcstr(StrLoc(Arg0), StrLen(Arg0));
                    206:       }
                    207:    Return;
                    208:    }
                    209: 
                    210: 
                    211: /*
                    212:  * x ~== y - test if x is lexically not equal to y.
                    213:  */
                    214: 
                    215: OpDcl(lexne,2,"~==")
                    216:    {
                    217:    register int t;
                    218:    char sbuf1[MaxCvtLen], sbuf2[MaxCvtLen];
                    219:    extern char *alcstr();
                    220: 
                    221:    /*
                    222:     * x and y must be strings.  Save the cvstr return value for y because
                    223:     *  y is the result (if any).
                    224:     */
                    225:    if (cvstr(&Arg1, sbuf1) == NULL)
                    226:       runerr(103, &Arg1);
                    227:    if ((t = cvstr(&Arg2, sbuf2)) == NULL)
                    228:       runerr(103, &Arg2);
                    229: 
                    230:    /*
                    231:     * lexcmp does the work.
                    232:     */
                    233:    if (lexcmp(&Arg1, &Arg2) == 0)
                    234:       Fail;
                    235: 
                    236:    /*
                    237:     * Return y as the result of the comparison.  If y was converted to
                    238:     *  a string, a copy of it is allocated.
                    239:     */
                    240:    Arg0 = Arg2;
                    241:    if (t == Cvt) {             /* string needs to be allocated */
                    242:       strreq(StrLen(Arg0));
                    243:       StrLoc(Arg0) = alcstr(StrLoc(Arg0), StrLen(Arg0));
                    244:       }
                    245:    Return;
                    246:    }
                    247: 
                    248: 
                    249: /*
                    250:  * x = y - test if x is numerically equal to y.
                    251:  */
                    252: 
                    253: OpDcl(numeq,2,"=")
                    254:    {
                    255: 
                    256:    if (numcmp(&Arg1, &Arg2, &Arg0) != 0)
                    257:       Fail;
                    258:    Return;
                    259:    }
                    260: 
                    261: 
                    262: /*
                    263:  * x >= y - test if x is numerically greater or equal to y.
                    264:  */
                    265: 
                    266: OpDcl(numge,2,">=")
                    267:    {
                    268: 
                    269:    if (numcmp(&Arg1, &Arg2, &Arg0) < 0)
                    270:       Fail;
                    271:    Return;
                    272:    }
                    273: 
                    274: 
                    275: /*
                    276:  * x > y - test if x is numerically greater than y.
                    277:  */
                    278: 
                    279: OpDcl(numgt,2,">")
                    280:    {
                    281: 
                    282:    if (numcmp(&Arg1, &Arg2, &Arg0) <= 0)
                    283:       Fail;
                    284:    Return;
                    285:    }
                    286: 
                    287: 
                    288: /*
                    289:  * x <= y - test if x is numerically less than or equal to y.
                    290:  */
                    291: 
                    292: OpDcl(numle,2,"<=")
                    293:    {
                    294: 
                    295:    if (numcmp(&Arg1, &Arg2, &Arg0) > 0)
                    296:       Fail;
                    297:    Return;
                    298:    }
                    299: 
                    300: 
                    301: /*
                    302:  * x < y - test if x is numerically less than y.
                    303:  */
                    304: 
                    305: OpDcl(numlt,2,"<")
                    306:    {
                    307: 
                    308:    if (numcmp(&Arg1, &Arg2, &Arg0) >= 0)
                    309:       Fail;
                    310:    Return;
                    311:    }
                    312: 
                    313: 
                    314: /*
                    315:  * x ~= y - test if x is numerically not equal to y.
                    316:  */
                    317: 
                    318: OpDcl(numne,2,"~=")
                    319: 
                    320:    {
                    321: 
                    322:    if (numcmp(&Arg1, &Arg2, &Arg0) == 0)
                    323:       Fail;
                    324:    Return;
                    325:    }
                    326: 
                    327: 
                    328: /*
                    329:  * x === y - test equivalence of x and y.
                    330:  */
                    331: 
                    332: OpDcl(eqv,2,"===")
                    333:    {
                    334: 
                    335:    /*
                    336:     * Let equiv do all the work, failing if equiv indicates non-equivalence.
                    337:     */
                    338:    if (!equiv(&Arg1, &Arg2))
                    339:       Fail;
                    340: 
                    341:    Arg0 = Arg2;
                    342:    Return;
                    343:    }
                    344: 
                    345: 
                    346: /*
                    347:  * x ~=== y - test inequivalence of x and y.
                    348:  */
                    349: 
                    350: OpDcl(neqv,2,"~===")
                    351:    {
                    352: 
                    353:    /*
                    354:     * equiv does all the work.
                    355:     */
                    356:    if (equiv(&Arg1, &Arg2))
                    357:       Fail;
                    358:    Arg0 = Arg2;
                    359:    Return;
                    360:    }

unix.superglobalmegacorp.com

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