1: #include "../h/rt.h"
2:
3: /*
4: * x == y - test if x is lexically equal to y.
5: */
6:
7: lexeq(nargs, arg2, arg1, arg0)
8: int nargs;
9: struct descrip arg2, arg1, arg0;
10: {
11: DclSave
12: register int t, i;
13: register char *s1, *s2;
14: char sbuf1[MAXSTRING], sbuf2[MAXSTRING];
15: extern char *alcstr();
16:
17: SetBound;
18: /*
19: * x and y must be strings. Save the cvstr return value for y because
20: * y is the result (if any).
21: */
22: if (cvstr(&arg1, sbuf1) == NULL)
23: runerr(103, &arg1);
24: if ((t = cvstr(&arg2, sbuf2)) == NULL)
25: runerr(103, &arg2);
26:
27: /*
28: * If the strings have different lengths they can't be equal
29: */
30: if (STRLEN(arg1) != STRLEN(arg2))
31: fail();
32:
33: /*
34: * compare the strings
35: */
36: i = STRLEN(arg1);
37: s1 = STRLOC(arg1);
38: s2 = STRLOC(arg2);
39: while (i--)
40: if (*s1++ != *s2++)
41: fail();
42:
43: /*
44: * Return y as the result of the comparison. If y was converted to
45: * a string, a copy of it is allocated.
46: */
47: arg0 = arg2;
48: if (t == 1)
49: STRLOC(arg0) = alcstr(STRLOC(arg0), STRLEN(arg0));
50: ClearBound;
51: }
52:
53: Opblock(lexeq,2,"==")
Defined functions
lexeq
defined in line
7; used 1 times