forked from softace/sqliteodbc
-
Notifications
You must be signed in to change notification settings - Fork 0
/
extfunc.patch
313 lines (283 loc) · 7.22 KB
/
extfunc.patch
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
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
--- extfunc.c.orig 2010-04-09 09:30:28.000000000 +0200
+++ extfunc.c 2010-04-09 09:24:27.000000000 +0200
@@ -116,7 +116,6 @@
#define HAVE_COSH 1
#define HAVE_TANH 1
#define HAVE_LOG10 1
-#define HAVE_ISBLANK 1
#define SQLITE_SOUNDEX 1
#define HAVE_TRIM 1 /* LMH 2007-03-25 if sqlite has trim functions */
@@ -127,7 +126,6 @@
#include "sqlite3.h"
#endif
-#include <ctype.h>
/* relicoder */
#include <math.h>
#include <string.h>
@@ -160,40 +158,39 @@
typedef struct map{
node *base;
cmp_func cmp;
- short free;
} map;
/*
** creates a map given a comparison function
*/
-map map_make(cmp_func cmp);
+static map map_make(cmp_func cmp);
/*
** inserts the element e into map m
*/
-void map_insert(map *m, void *e);
+static void map_insert(map *m, void *e);
/*
** executes function iter over all elements in the map, in key increasing order
*/
-void map_iterate(map *m, map_iterator iter, void* p);
+static void map_iterate(map *m, map_iterator iter, void* p);
/*
** frees all memory used by a map
*/
-void map_destroy(map *m);
+static void map_destroy(map *m);
/*
** compares 2 integers
** to use with map_make
*/
-int int_cmp(const void *a, const void *b);
+static int int_cmp(const void *a, const void *b);
/*
** compares 2 doubles
** to use with map_make
*/
-int double_cmp(const void *a, const void *b);
+static int double_cmp(const void *a, const void *b);
#endif /* _MAP_H_ */
@@ -244,6 +241,26 @@
3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4,
};
+/*
+** Own (ASCII only) implementation of toupper(), tolower(),
+** and isalpha()
+*/
+
+static int toupper(int c){
+ if ((c>='a') && (c<='z')) return c-0x20;
+ return c;
+}
+
+static int tolower(int c){
+ if ((c>='A') && (c<='Z')) return c+0x20;
+ return c;
+}
+
+static int isalpha(int c){
+ if ((c>='A') && (c<='Z')) return 1;
+ if ((c>='a') && (c<='z')) return 1;
+ return 0;
+}
/*
** This table maps from the number of trailing bytes in a UTF-8 character
@@ -360,7 +377,7 @@
if (errno == 0) {\
sqlite3_result_double(context, val);\
} else {\
- sqlite3_result_error(context, strerror(errno), errno);\
+ sqlite3_result_error(context, "domain error", -1); \
}\
break;\
}\
@@ -555,7 +572,7 @@
if (errno == 0) {
sqlite3_result_double(context, val);
} else {
- sqlite3_result_error(context, strerror(errno), errno);
+ sqlite3_result_error(context, "domain error", -1);
}
}
}
@@ -620,7 +637,7 @@
assert( argc==1 );
switch( sqlite3_value_type(argv[0]) ){
case SQLITE_INTEGER: {
- i64 iVal = sqlite3_value_int64(argv[0]);
+ iVal = sqlite3_value_int64(argv[0]);
sqlite3_result_int64(context, iVal);
break;
}
@@ -645,7 +662,7 @@
assert( argc==1 );
switch( sqlite3_value_type(argv[0]) ){
case SQLITE_INTEGER: {
- i64 iVal = sqlite3_value_int64(argv[0]);
+ iVal = sqlite3_value_int64(argv[0]);
sqlite3_result_int64(context, iVal);
break;
}
@@ -704,16 +721,6 @@
}
}
-/*
-** Some systems (win32 among others) don't have an isblank function, this will emulate it.
-** This function is not UFT-8 safe since it only analyses a byte character.
-*/
-#ifndef HAVE_ISBLANK
-int isblank(char c){
- return( ' '==c || '\t'==c );
-}
-#endif
-
static void properFunc(sqlite3_context *context, int argc, sqlite3_value **argv){
const unsigned char *z; /* input string */
unsigned char *zo; /* output string */
@@ -736,7 +743,7 @@
zt = zo;
while( (r = *(z++))!=0 ){
- if( isblank(r) ){
+ if( (r==' ') || (r=='\t') ){
c=1;
}else{
if( c==1 ){
@@ -1349,6 +1356,15 @@
sqlite3_free(rz);
}
+static void* xcalloc(size_t nmemb, size_t size){
+ void* ret = calloc(nmemb, size);
+ return ret;
+}
+
+static void xfree(void* p){
+ free(p);
+}
+
/*
** An instance of the following structure holds the context of a
** stdev() or variance() aggregate computation.
@@ -1424,7 +1440,7 @@
p = sqlite3_aggregate_context(context, sizeof(*p));
if( 0==(p->m) ){
- p->m = calloc(1, sizeof(map));
+ p->m = xcalloc(1, sizeof(map));
if( type==SQLITE_INTEGER ){
/* map will be used for integers */
*(p->m) = map_make(int_cmp);
@@ -1440,12 +1456,12 @@
if( 0==p->is_double ){
xi = sqlite3_value_int64(argv[0]);
- iptr = (i64*)calloc(1,sizeof(i64));
+ iptr = (i64*)xcalloc(1,sizeof(i64));
*iptr = xi;
map_insert(p->m, iptr);
}else{
xd = sqlite3_value_double(argv[0]);
- dptr = (double*)calloc(1,sizeof(double));
+ dptr = (double*)xcalloc(1,sizeof(double));
*dptr = xd;
map_insert(p->m, dptr);
}
@@ -1531,7 +1547,7 @@
if( p && p->m ){
map_iterate(p->m, modeIterate, p);
map_destroy(p->m);
- free(p->m);
+ xfree(p->m);
if( 1==p->mn ){
if( 0==p->is_double )
@@ -1552,7 +1568,7 @@
p->done=0;
map_iterate(p->m, medianIterate, p);
map_destroy(p->m);
- free(p->m);
+ xfree(p->m);
if( 0==p->is_double )
if( 1==p->mn )
@@ -1705,7 +1721,7 @@
** functions. This should be the only routine in this file with
** external linkage.
*/
-int RegisterExtensionFunctions(sqlite3 *db){
+static int RegisterExtensionFunctions(sqlite3 *db){
static const struct FuncDef {
char *zName;
signed char nArg;
@@ -1843,28 +1859,18 @@
}
#endif /* COMPILE_SQLITE_EXTENSIONS_AS_LOADABLE_MODULE */
-map map_make(cmp_func cmp){
+static map map_make(cmp_func cmp){
map r;
r.cmp=cmp;
r.base = 0;
-
return r;
}
-void* xcalloc(size_t nmemb, size_t size, char* s){
- void* ret = calloc(nmemb, size);
- return ret;
-}
-
-void xfree(void* p){
- free(p);
-}
-
-void node_insert(node** n, cmp_func cmp, void *e){
+static void node_insert(node** n, cmp_func cmp, void *e){
int c;
node* nn;
if(*n==0){
- nn = (node*)xcalloc(1,sizeof(node), "for node");
+ nn = (node*)xcalloc(1,sizeof(node));
nn->data = e;
nn->count = 1;
*n=nn;
@@ -1882,11 +1888,11 @@
}
}
-void map_insert(map *m, void *e){
+static void map_insert(map *m, void *e){
node_insert(&(m->base), m->cmp, e);
}
-void node_iterate(node *n, map_iterator iter, void* p){
+static void node_iterate(node *n, map_iterator iter, void* p){
if(n){
if(n->l)
node_iterate(n->l, iter, p);
@@ -1896,11 +1902,11 @@
}
}
-void map_iterate(map *m, map_iterator iter, void* p){
+static void map_iterate(map *m, map_iterator iter, void* p){
node_iterate(m->base, iter, p);
}
-void node_destroy(node *n){
+static void node_destroy(node *n){
if(0!=n){
xfree(n->data);
if(n->l)
@@ -1912,11 +1918,11 @@
}
}
-void map_destroy(map *m){
+static void map_destroy(map *m){
node_destroy(m->base);
}
-int int_cmp(const void *a, const void *b){
+static int int_cmp(const void *a, const void *b){
int64_t aa = *(int64_t *)(a);
int64_t bb = *(int64_t *)(b);
/* printf("cmp %d <=> %d\n",aa,bb); */
@@ -1928,7 +1934,7 @@
return 1;
}
-int double_cmp(const void *a, const void *b){
+static int double_cmp(const void *a, const void *b){
double aa = *(double *)(a);
double bb = *(double *)(b);
/* printf("cmp %d <=> %d\n",aa,bb); */
@@ -1940,8 +1946,4 @@
return 1;
}
-void print_elem(void *e, int64_t c, void* p){
- int ee = *(int*)(e);
- printf("%d => %lld\n", ee,c);
-}