|
|
1.1 root 1: # include <ingres.h>
2: # include <access.h>
3: # include <symbol.h>
4: # include <aux.h>
5: # include <sccs.h>
6:
7: SCCSID(@(#)compare.c 7.1 2/5/81)
8:
9: icompare(ax, bx, frmt, frml)
10: char *ax, *bx, frmt, frml;
11: {
12: register ANYTYPE *a, *b;
13: register int length;
14: ANYTYPE atemp, btemp;
15:
16: length = frml & I1MASK;
17: if (frmt == CHAR)
18: return (scompare(ax, length, bx, length));
19: a = &atemp;
20: b = &btemp;
21: bmove(ax, (char *) a, length);
22: bmove(bx, (char *) b, length);
23: if (bequal((char *) a, (char *) b, length))
24: return (0);
25: switch (frmt)
26: {
27: case INT:
28: switch (length)
29: {
30: case 1:
31: return (a->i1type - b->i1type);
32: case 2:
33: return (a->i2type - b->i2type);
34: case 4:
35: return (a->i4type > b->i4type ? 1 : -1);
36: }
37: break;
38:
39: case FLOAT:
40: if (frml == 4)
41: return (a->f4type > b->f4type ? 1 : -1);
42: else
43: return (a->f8type > b->f8type ? 1 : -1);
44: break;
45: }
46: syserr("compare: t=%d,l=%d", frmt, frml);
47: /*NOTREACHED*/
48: }
49: /*
50: ** KCOMPARE -- key compare
51: **
52: ** compares all domains indicated by SETKEY in the tuple to the
53: ** corressponding domains in the key.
54: ** the comparison is done according to the format of the domain
55: ** as specified in the descriptor.
56: **
57: ** function values:
58: ** <0 tuple < key
59: ** =0 tuple = key
60: ** >0 tuple > key
61: */
62:
63: kcompare (dx, tuple, key)
64: DESC *dx; /*relation descriptor */
65: char tuple[MAXTUP]; /*tuple to be compared */
66: char key[MAXTUP]; /*second tuple or key */
67: {
68: register int i, tmp;
69: register DESC *d;
70:
71: d = dx;
72: for (i = 1; i <= d->reldum.relatts; i++)
73: if (d->relgiven[i])
74: if (tmp = icompare(&tuple[d->reloff[i]],
75: &key[d->reloff[i]],
76: d->relfrmt[i],
77: d->relfrml[i]))
78: {
79: return (tmp);
80: }
81: return (0);
82: }
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.