aboutsummaryrefslogtreecommitdiff
path: root/pkg/utilities/nttools/lib/compare.x
blob: b05a50c16408ee9a116d582c64ac46cc86485939 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
.help compare
.nf___________________________________________________________________________

Comparison routines used to sort table columns. There are two sets of routines,
compasc[bdirt] for sorting in ascending order and compdsc[bdirt] for sorting in
descending order. The last letter indicates the type of data compared in the
sort. All routines return an integer that indicates the results of comparison.
The value of the integer is set according to the following scheme: 

		Ascending				Descending

	if mem[i] < mem[j], order = -1		if mem[i] > mem[j], order = -1
	if mem[i] == mem[j], order = 0		if mem[i] == mem[j], order = 0
	if mem[i] > mem[j], order =  1		if mem[i] < mem[j], order =  1

.endhelp_______________________________________________________________________

# B.Simon	16-Sept-87	First Code

# COMPASCB -- Boolean comparison routine used for sort in ascending order

int procedure compascb (i, j)

int	i	# i: Index to first array element in comparison
int	j	# i: Index to second element in comparison
#--
include	"compare.com"

int	order

begin
	# false < true

	if (! Memb[dataptr+i-1] && Memb[dataptr+j-1])
	    order = -1
	else if (Memb[dataptr+i-1] && ! Memb[dataptr+j-1])
	    order = 1
	else
	    order = 0

	return (order)
end

# COMPASCD -- Double comparison routine used for sort in ascending order

int procedure compascd (i, j)

int	i	# i: Index to first array element in comparison
int	j	# i: Index to second element in comparison
#--
include	"compare.com"

int	order

begin

	if (Memd[dataptr+i-1] < Memd[dataptr+j-1])
	    order = -1
	else if (Memd[dataptr+i-1] > Memd[dataptr+j-1])
	    order = 1
	else
	    order = 0

	return (order)
end

# COMPASCI -- Integer comparison routine used for sort in ascending order

int procedure compasci (i, j)

int	i	# i: Index to first array element in comparison
int	j	# i: Index to second element in comparison
#--
include	"compare.com"

int	order

begin

	if (Memi[dataptr+i-1] < Memi[dataptr+j-1])
	    order = -1
	else if (Memi[dataptr+i-1] > Memi[dataptr+j-1])
	    order = 1
	else
	    order = 0

	return (order)
end

# COMPASCR -- Real comparison routine used for sort in ascending order

int procedure compascr (i, j)

int	i	# i: Index to first array element in comparison
int	j	# i: Index to second element in comparison
#--
include	"compare.com"

int	order

begin

	if (Memr[dataptr+i-1] < Memr[dataptr+j-1])
	    order = -1
	else if (Memr[dataptr+i-1] > Memr[dataptr+j-1])
	    order = 1
	else
	    order = 0

	return (order)
end

# COMPASCT -- Text comparison routine used for sort in ascending order

int procedure compasct (i, j)

int	i	# i: Index to first array element in comparison
int	j	# i: Index to second element in comparison
#--
include	"compare.com"

int	order

bool	strlt(), strgt()

begin

	if (strlt (Memc[dataptr+(i-1)*(lendata+1)],
		   Memc[dataptr+(j-1)*(lendata+1)]) )
	    order = -1
	else if (strgt (Memc[dataptr+(i-1)*(lendata+1)],
	                Memc[dataptr+(j-1)*(lendata+1)]) )
	    order = 1
	else
	    order = 0

	return (order)
end
                     
# COMPDSCB -- Boolean comparison routine used for sort in descending order

int procedure compdscb (i, j)

int	i	# i: Index to first array element in comparison
int	j	# i: Index to second element in comparison
#--
include	"compare.com"

int	order

begin
	# true > false

	if (Memb[dataptr+i-1] && ! Memb[dataptr+j-1])
	    order = -1
	else if (! Memb[dataptr+i-1] && Memb[dataptr+j-1])
	    order = 1
	else
	    order = 0

	return (order)
end

# COMPDSCD -- Double comparison routine used for sort in descending order

int procedure compdscd (i, j)

int	i	# i: Index to first array element in comparison
int	j	# i: Index to second element in comparison
#--
include	"compare.com"

int	order

begin

	if (Memd[dataptr+i-1] > Memd[dataptr+j-1])
	    order = -1
	else if (Memd[dataptr+i-1] < Memd[dataptr+j-1])
	    order = 1
	else
	    order = 0

	return (order)
end

# COMPDSCI -- Integer comparison routine used for sort in descending order

int procedure compdsci (i, j)

int	i	# i: Index to first array element in comparison
int	j	# i: Index to second element in comparison
#--
include	"compare.com"

int	order

begin

	if (Memi[dataptr+i-1] > Memi[dataptr+j-1])
	    order = -1
	else if (Memi[dataptr+i-1] < Memi[dataptr+j-1])
	    order = 1
	else
	    order = 0

	return (order)
end

# COMPDSCR -- Real comparison routine used for sort in descending order

int procedure compdscr (i, j)

int	i	# i: Index to first array element in comparison
int	j	# i: Index to second element in comparison
#--
include	"compare.com"

int	order

begin

	if (Memr[dataptr+i-1] > Memr[dataptr+j-1])
	    order = -1
	else if (Memr[dataptr+i-1] < Memr[dataptr+j-1])
	    order = 1
	else
	    order = 0

	return (order)
end

# COMPDSCT -- Text comparison routine used for sort in descending order

int procedure compdsct (i, j)

int	i	# i: Index to first array element in comparison
int	j	# i: Index to second element in comparison
#--
include	"compare.com"

int	order

bool	strgt(), strlt()

begin

	if (strgt (Memc[dataptr+(i-1)*(lendata+1)],
		   Memc[dataptr+(j-1)*(lendata+1)]) )
	    order = -1
	else if (strlt (Memc[dataptr+(i-1)*(lendata+1)],
	                Memc[dataptr+(j-1)*(lendata+1)]) )
	    order = 1
	else
	    order = 0

	return (order)
end