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
|
//*****************************************************************************
//
// numbers.c
//
// This provides a wrapper around integers, doubles, and longs so we can pass
// them around as pointers.
//
//*****************************************************************************
#include "mud.h"
#include "numbers.h"
//*****************************************************************************
// integers
//*****************************************************************************
struct int_struct {
int val;
};
INTEGER *newInteger(int val) {
INTEGER *integer = malloc(sizeof(INTEGER));
integer->val = val;
return integer;
}
void deleteInteger(INTEGER *integer) {
free(integer);
}
int integerGetVal(INTEGER *integer) {
return integer->val;
}
void integerSetVal(INTEGER *integer, int val) {
integer->val = val;
}
int integerCmp(INTEGER *int1, INTEGER *int2) {
if(int1->val == int2->val)
return 0;
else if(int1->val > int2->val)
return 1;
else
return -1;
}
//*****************************************************************************
// doubles
//*****************************************************************************
struct double_struct {
double val;
};
DOUBLE *newDouble(double val) {
DOUBLE *dbl = malloc(sizeof(DOUBLE));
dbl->val = val;
return dbl;
}
void deleteDouble(DOUBLE *dbl) {
free(dbl);
}
double doubleGetVal(DOUBLE *dbl) {
return dbl->val;
}
void doubleSetVal(DOUBLE *dbl, double val) {
dbl->val = val;
}
int doubleCmp(DOUBLE *dbl1, DOUBLE *dbl2) {
if(dbl1->val == dbl2->val)
return 0;
else if(dbl1->val > dbl2->val)
return 1;
else
return -1;
}
//*****************************************************************************
// longs
//*****************************************************************************
struct long_struct {
long val;
};
LONG *newLong(long val) {
LONG *lng = malloc(sizeof(LONG));
lng->val = val;
return lng;
}
void deleteLong(LONG *lng) {
free(lng);
}
long longGetVal(LONG *lng) {
return lng->val;
}
void longSetVal(LONG *lng, long val) {
lng->val = val;
}
int longCmp(LONG *lng1, LONG *lng2) {
if(lng1->val == lng2->val)
return 0;
else if(lng1->val > lng2->val)
return 1;
else
return -1;
}
//*****************************************************************************
// booleans
//*****************************************************************************
struct boolean_struct {
bool val;
};
BOOLEAN *newBoolean(bool val) {
BOOLEAN *bl = malloc(sizeof(BOOLEAN));
bl->val = val;
return bl;
}
void deleteBoolean(BOOLEAN *bl) {
free(bl);
}
bool booleanGetVal(BOOLEAN *bl) {
return bl->val;
}
void booleanSetVal(BOOLEAN *bl, bool val) {
bl->val = val;
}
int booleanCmp(BOOLEAN *bl1, BOOLEAN *bl2) {
if(bl1->val == bl2->val)
return 0;
else if(bl1->val > bl2->val)
return 1;
else
return -1;
}
|