]>
Commit | Line | Data |
---|---|---|
c90f71dd RD |
1 | /************************************************************************** |
2 | * $Header$ | |
3 | * | |
4 | * swigtcl8.swg | |
5 | * | |
6 | * This file provides type-checked pointer support to Tcl 8.0. | |
7 | **********************************************************************/ | |
8 | ||
9 | #if defined(_WIN32) || defined(__WIN32__) | |
10 | # if defined(_MSC_VER) | |
11 | # define SWIGEXPORT(a) __declspec(dllexport) a | |
12 | # else | |
13 | # if defined(__BORLANDC__) | |
14 | # define SWIGEXPORT(a) a _export | |
15 | # else | |
16 | # define SWIGEXPORT(a) a | |
17 | # endif | |
18 | # endif | |
19 | #else | |
20 | # define SWIGEXPORT(a) a | |
21 | #endif | |
22 | ||
23 | #ifdef __cplusplus | |
24 | extern "C" { | |
25 | #endif | |
26 | ||
27 | #ifdef SWIG_GLOBAL | |
28 | #include <tcl.h> | |
29 | #define SWIGSTATICRUNTIME(a) SWIGEXPORT(a) | |
30 | #else | |
31 | #define SWIGSTATICRUNTIME(a) static a | |
32 | #endif | |
33 | ||
34 | #ifdef SWIG_NOINCLUDE | |
35 | extern void SWIG_SetPointerObj(Tcl_Obj *, void *, char *); | |
36 | extern void SWIG_RegisterMapping(char *, char *, void *(*)(void *)); | |
37 | extern char *SWIG_GetPointerObj(Tcl_Interp *, Tcl_Obj *, void **, char *); | |
38 | extern int SWIG_MakePtr(char *, const void *, char *); | |
39 | extern void SWIG_RegisterType(); | |
40 | #else | |
41 | ||
42 | /* These are internal variables. Should be static */ | |
43 | ||
44 | typedef struct SwigPtrType { | |
45 | char *name; | |
46 | int len; | |
47 | void *(*cast)(void *); | |
48 | struct SwigPtrType *next; | |
49 | } SwigPtrType; | |
50 | ||
51 | /* Pointer cache structure */ | |
52 | ||
53 | typedef struct { | |
54 | int stat; /* Status (valid) bit */ | |
55 | SwigPtrType *tp; /* Pointer to type structure */ | |
56 | char name[256]; /* Given datatype name */ | |
57 | char mapped[256]; /* Equivalent name */ | |
58 | } SwigCacheType; | |
59 | ||
60 | static int SwigPtrMax = 64; /* Max entries that can be currently held */ | |
61 | static int SwigPtrN = 0; /* Current number of entries */ | |
62 | static int SwigPtrSort = 0; /* Status flag indicating sort */ | |
63 | static int SwigStart[256]; /* Array containing start locations (for searching) */ | |
64 | static SwigPtrType *SwigPtrTable = 0; /* Table containing pointer equivalences */ | |
65 | ||
66 | /* Cached values */ | |
67 | ||
68 | #define SWIG_CACHESIZE 8 | |
69 | #define SWIG_CACHEMASK 0x7 | |
70 | static SwigCacheType SwigCache[SWIG_CACHESIZE]; | |
71 | static int SwigCacheIndex = 0; | |
72 | static int SwigLastCache = 0; | |
73 | ||
74 | /* Sort comparison function */ | |
75 | static int swigsort(const void *data1, const void *data2) { | |
76 | SwigPtrType *d1 = (SwigPtrType *) data1; | |
77 | SwigPtrType *d2 = (SwigPtrType *) data2; | |
78 | return strcmp(d1->name,d2->name); | |
79 | } | |
80 | ||
81 | /* Binary Search function */ | |
82 | static int swigcmp(const void *key, const void *data) { | |
83 | char *k = (char *) key; | |
84 | SwigPtrType *d = (SwigPtrType *) data; | |
85 | return strncmp(k,d->name,d->len); | |
86 | } | |
87 | ||
88 | ||
89 | /*--------------------------------------------------------------------- | |
90 | * SWIG_RegisterMapping(char *origtype, char *newtype, void *(*cast)(void *)) | |
91 | * | |
92 | * Register a new type-mapping with the type-checking system. | |
93 | *---------------------------------------------------------------------*/ | |
94 | ||
95 | SWIGSTATICRUNTIME(void) | |
96 | SWIG_RegisterMapping(char *origtype, char *newtype, void *(*cast)(void *)) { | |
97 | ||
98 | int i; | |
99 | SwigPtrType *t = 0, *t1; | |
100 | ||
101 | if (!SwigPtrTable) { | |
102 | SwigPtrTable = (SwigPtrType *) malloc(SwigPtrMax*sizeof(SwigPtrType)); | |
103 | SwigPtrN = 0; | |
104 | } | |
105 | if (SwigPtrN >= SwigPtrMax) { | |
106 | SwigPtrMax = 2*SwigPtrMax; | |
107 | SwigPtrTable = (SwigPtrType *) realloc(SwigPtrTable,SwigPtrMax*sizeof(SwigPtrType)); | |
108 | } | |
109 | for (i = 0; i < SwigPtrN; i++) | |
110 | if (strcmp(SwigPtrTable[i].name,origtype) == 0) { | |
111 | t = &SwigPtrTable[i]; | |
112 | break; | |
113 | } | |
114 | if (!t) { | |
115 | t = &SwigPtrTable[SwigPtrN]; | |
116 | t->name = origtype; | |
117 | t->len = strlen(origtype); | |
118 | t->cast = 0; | |
119 | t->next = 0; | |
120 | SwigPtrN++; | |
121 | } | |
122 | while (t->next) { | |
123 | if (strcmp(t->name,newtype) == 0) { | |
124 | if (cast) t->cast = cast; | |
125 | return; | |
126 | } | |
127 | t = t->next; | |
128 | } | |
129 | t1 = (SwigPtrType *) malloc(sizeof(SwigPtrType)); | |
130 | t1->name = newtype; | |
131 | t1->len = strlen(newtype); | |
132 | t1->cast = cast; | |
133 | t1->next = 0; | |
134 | t->next = t1; | |
135 | SwigPtrSort = 0; | |
136 | } | |
137 | ||
138 | ||
139 | /*--------------------------------------------------------------------- | |
140 | * void SWIG_SetPointerObj(Tcl_Obj *objPtr, void *ptr, char *type) | |
141 | * | |
142 | * Sets a Tcl object to a pointer value. | |
143 | * ptr = void pointer value | |
144 | * type = string representing type | |
145 | * | |
146 | *---------------------------------------------------------------------*/ | |
147 | ||
148 | SWIGSTATICRUNTIME(void) | |
149 | SWIG_SetPointerObj(Tcl_Obj *objPtr, void *_ptr, char *type) { | |
150 | static char _hex[16] = | |
151 | {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', | |
152 | 'a', 'b', 'c', 'd', 'e', 'f'}; | |
153 | unsigned long _p, _s; | |
154 | char _result[20], *_r; /* Note : a 64-bit hex number = 16 digits */ | |
155 | char _temp[20], *_c; | |
156 | _r = _result; | |
157 | _p = (unsigned long) _ptr; | |
158 | if (_p > 0) { | |
159 | while (_p > 0) { | |
160 | _s = _p & 0xf; | |
161 | *(_r++) = _hex[_s]; | |
162 | _p = _p >> 4; | |
163 | } | |
164 | *_r = '_'; | |
165 | _c = &_temp[0]; | |
166 | while (_r >= _result) | |
167 | *(_c++) = *(_r--); | |
168 | *_c = 0; | |
169 | Tcl_SetStringObj(objPtr,_temp,-1); | |
170 | } else { | |
171 | Tcl_SetStringObj(objPtr,"NULL",-1); | |
172 | } | |
173 | if (_ptr) | |
174 | Tcl_AppendToObj(objPtr,type,-1); | |
175 | } | |
176 | ||
177 | /* This is for backwards compatibility */ | |
178 | ||
179 | SWIGSTATICRUNTIME(int) | |
180 | SWIG_MakePtr(char *_c, const void *_ptr, char *type) | |
181 | { | |
182 | static char _hex[16] = | |
183 | {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', | |
184 | 'a', 'b', 'c', 'd', 'e', 'f'}; | |
185 | unsigned long _p, _s; | |
186 | char _result[20], *_r; | |
187 | int l = 0; | |
188 | _r = _result; | |
189 | _p = (unsigned long) _ptr; | |
190 | if (_p > 0) { | |
191 | while (_p > 0) { | |
192 | _s = _p & 0xf; | |
193 | *(_r++) = _hex[_s]; | |
194 | _p = _p >> 4; | |
195 | l++; | |
196 | } | |
197 | *_r = '_'; | |
198 | l++; | |
199 | while (_r >= _result) | |
200 | *(_c++) = *(_r--); | |
201 | _r = type; | |
202 | while (*_r) | |
203 | *(_c++) = *(_r++); | |
204 | *(_c) = 0; | |
205 | } else { | |
206 | strcpy (_c, "NULL"); | |
207 | } | |
208 | return l; | |
209 | } | |
210 | ||
211 | /*--------------------------------------------------------------------- | |
212 | * char *SWIG_GetPointerObj(Tcl_Interp *interp, Tcl_Obj *objPtr, void **ptr, char *type) | |
213 | * | |
214 | * Attempts to extract a pointer value from our pointer type. | |
215 | * Upon failure, returns a string corresponding to the actual datatype. | |
216 | * Upon success, returns NULL and sets the pointer value in ptr. | |
217 | *---------------------------------------------------------------------*/ | |
218 | ||
219 | SWIGSTATICRUNTIME(char *) | |
220 | SWIG_GetPointerObj(Tcl_Interp *interp, Tcl_Obj *objPtr, void **ptr, char *_t) { | |
221 | unsigned long _p; | |
222 | char temp_type[256]; | |
223 | char *name; | |
224 | int i, len; | |
225 | SwigPtrType *sp,*tp; | |
226 | SwigCacheType *cache; | |
227 | int start, end; | |
228 | char *_c; | |
229 | _p = 0; | |
230 | ||
231 | /* Extract the pointer value as a string */ | |
232 | _c = Tcl_GetStringFromObj(objPtr, &i); | |
233 | ||
234 | /* Pointer values must start with leading underscore */ | |
235 | if (*_c == '_') { | |
236 | _c++; | |
237 | /* Extract hex value from pointer */ | |
238 | while (*_c) { | |
239 | if ((*_c >= '0') && (*_c <= '9')) | |
240 | _p = (_p << 4) + (*_c - '0'); | |
241 | else if ((*_c >= 'a') && (*_c <= 'f')) | |
242 | _p = (_p << 4) + ((*_c - 'a') + 10); | |
243 | else | |
244 | break; | |
245 | _c++; | |
246 | } | |
247 | ||
248 | if (_t) { | |
249 | if (strcmp(_t,_c)) { | |
250 | if (!SwigPtrSort) { | |
251 | qsort((void *) SwigPtrTable, SwigPtrN, sizeof(SwigPtrType), swigsort); | |
252 | for (i = 0; i < 256; i++) { | |
253 | SwigStart[i] = SwigPtrN; | |
254 | } | |
255 | for (i = SwigPtrN-1; i >= 0; i--) { | |
256 | SwigStart[(int) (SwigPtrTable[i].name[1])] = i; | |
257 | } | |
258 | for (i = 255; i >= 1; i--) { | |
259 | if (SwigStart[i-1] > SwigStart[i]) | |
260 | SwigStart[i-1] = SwigStart[i]; | |
261 | } | |
262 | SwigPtrSort = 1; | |
263 | for (i = 0; i < SWIG_CACHESIZE; i++) | |
264 | SwigCache[i].stat = 0; | |
265 | } | |
266 | ||
267 | /* First check cache for matches. Uses last cache value as starting point */ | |
268 | cache = &SwigCache[SwigLastCache]; | |
269 | for (i = 0; i < SWIG_CACHESIZE; i++) { | |
270 | if (cache->stat) { | |
271 | if (strcmp(_t,cache->name) == 0) { | |
272 | if (strcmp(_c,cache->mapped) == 0) { | |
273 | cache->stat++; | |
274 | *ptr = (void *) _p; | |
275 | if (cache->tp->cast) *ptr = (*(cache->tp->cast))(*ptr); | |
276 | return (char *) 0; | |
277 | } | |
278 | } | |
279 | } | |
280 | SwigLastCache = (SwigLastCache+1) & SWIG_CACHEMASK; | |
281 | if (!SwigLastCache) cache = SwigCache; | |
282 | else cache++; | |
283 | } | |
284 | /* We have a type mismatch. Will have to look through our type | |
285 | mapping table to figure out whether or not we can accept this datatype */ | |
286 | ||
287 | start = SwigStart[(int) _t[1]]; | |
288 | end = SwigStart[(int) _t[1]+1]; | |
289 | sp = &SwigPtrTable[start]; | |
290 | while (start < end) { | |
291 | if (swigcmp(_t,sp) == 0) break; | |
292 | sp++; | |
293 | start++; | |
294 | } | |
295 | if (start > end) sp = 0; | |
296 | /* Try to find a match for this */ | |
297 | while (start <= end) { | |
298 | if (swigcmp(_t,sp) == 0) { | |
299 | name = sp->name; | |
300 | len = sp->len; | |
301 | tp = sp->next; | |
302 | /* Try to find entry for our given datatype */ | |
303 | while(tp) { | |
304 | if (tp->len >= 255) { | |
305 | return _c; | |
306 | } | |
307 | strcpy(temp_type,tp->name); | |
308 | strncat(temp_type,_t+len,255-tp->len); | |
309 | if (strcmp(_c,temp_type) == 0) { | |
310 | ||
311 | strcpy(SwigCache[SwigCacheIndex].mapped,_c); | |
312 | strcpy(SwigCache[SwigCacheIndex].name,_t); | |
313 | SwigCache[SwigCacheIndex].stat = 1; | |
314 | SwigCache[SwigCacheIndex].tp = tp; | |
315 | SwigCacheIndex = SwigCacheIndex & SWIG_CACHEMASK; | |
316 | ||
317 | /* Get pointer value */ | |
318 | *ptr = (void *) _p; | |
319 | if (tp->cast) *ptr = (*(tp->cast))(*ptr); | |
320 | return (char *) 0; | |
321 | } | |
322 | tp = tp->next; | |
323 | } | |
324 | } | |
325 | sp++; | |
326 | start++; | |
327 | } | |
328 | /* Didn't find any sort of match for this data. | |
329 | Get the pointer value and return the received type */ | |
330 | *ptr = (void *) _p; | |
331 | return _c; | |
332 | } else { | |
333 | /* Found a match on the first try. Return pointer value */ | |
334 | *ptr = (void *) _p; | |
335 | return (char *) 0; | |
336 | } | |
337 | } else { | |
338 | /* No type specified. Good luck */ | |
339 | *ptr = (void *) _p; | |
340 | return (char *) 0; | |
341 | } | |
342 | } else { | |
343 | if (strcmp (_c, "NULL") == 0) { | |
344 | *ptr = (void *) 0; | |
345 | return (char *) 0; | |
346 | } | |
347 | *ptr = (void *) 0; | |
348 | return _c; | |
349 | } | |
350 | } | |
351 | ||
352 | /*--------------------------------------------------------------------- | |
353 | * void SWIG_RegisterType() | |
354 | * | |
355 | * Registers our new datatype with an interpreter. | |
356 | *---------------------------------------------------------------------*/ | |
357 | ||
358 | SWIGSTATICRUNTIME(void) | |
359 | SWIG_RegisterType() { | |
360 | /* Does nothing at the moment */ | |
361 | } | |
362 | ||
363 | #endif | |
364 | ||
365 | #ifdef __cplusplus | |
366 | } | |
367 | #endif |