]> git.saurik.com Git - wxWidgets.git/blob - wxPython/wxSWIG/swig_lib/tcl/swigtcl.swg
Since I have made several changes to SWIG over the years to accomodate
[wxWidgets.git] / wxPython / wxSWIG / swig_lib / tcl / swigtcl.swg
1 /*
2 * $Header$
3 *
4 * swigtcl.swg
5 */
6
7 #if defined(_WIN32) || defined(__WIN32__)
8 # if defined(_MSC_VER)
9 # define SWIGEXPORT(a) __declspec(dllexport) a
10 # else
11 # if defined(__BORLANDC__)
12 # define SWIGEXPORT(a) a _export
13 # else
14 # define SWIGEXPORT(a) a
15 # endif
16 # endif
17 #else
18 # define SWIGEXPORT(a) a
19 #endif
20
21 /*****************************************************************************
22 * $Header$
23 *
24 * swigptr.swg
25 *****************************************************************************/
26
27 #include <stdlib.h>
28
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
32
33 #ifdef SWIG_NOINCLUDE
34 extern void SWIG_MakePtr(char *, void *, char *);
35 extern void SWIG_RegisterMapping(char *, char *, void *(*)(void *));
36 extern char *SWIG_GetPtr(char *, void **, char *);
37 #else
38
39 #ifdef SWIG_GLOBAL
40 #define SWIGSTATICRUNTIME(a) SWIGEXPORT(a)
41 #else
42 #define SWIGSTATICRUNTIME(a) static a
43 #endif
44
45 /* SWIG pointer structure */
46 typedef struct SwigPtrType {
47 char *name; /* Datatype name */
48 int len; /* Length (used for optimization) */
49 void *(*cast)(void *); /* Pointer casting function */
50 struct SwigPtrType *next; /* Linked list pointer */
51 } SwigPtrType;
52
53 /* Pointer cache structure */
54 typedef struct {
55 int stat; /* Status (valid) bit */
56 SwigPtrType *tp; /* Pointer to type structure */
57 char name[256]; /* Given datatype name */
58 char mapped[256]; /* Equivalent name */
59 } SwigCacheType;
60
61 static int SwigPtrMax = 64; /* Max entries that can be currently held */
62 static int SwigPtrN = 0; /* Current number of entries */
63 static int SwigPtrSort = 0; /* Status flag indicating sort */
64 static int SwigStart[256]; /* Starting positions of types */
65 static SwigPtrType *SwigPtrTable = 0; /* Table containing pointer equivalences */
66
67 /* Cached values */
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 /* Register a new datatype with the type-checker */
82 SWIGSTATICRUNTIME(void)
83 SWIG_RegisterMapping(char *origtype, char *newtype, void *(*cast)(void *)) {
84 int i;
85 SwigPtrType *t = 0,*t1;
86
87 /* Allocate the pointer table if necessary */
88 if (!SwigPtrTable) {
89 SwigPtrTable = (SwigPtrType *) malloc(SwigPtrMax*sizeof(SwigPtrType));
90 }
91
92 /* Grow the table */
93 if (SwigPtrN >= SwigPtrMax) {
94 SwigPtrMax = 2*SwigPtrMax;
95 SwigPtrTable = (SwigPtrType *) realloc((char *) SwigPtrTable,SwigPtrMax*sizeof(SwigPtrType));
96 }
97 for (i = 0; i < SwigPtrN; i++) {
98 if (strcmp(SwigPtrTable[i].name,origtype) == 0) {
99 t = &SwigPtrTable[i];
100 break;
101 }
102 }
103 if (!t) {
104 t = &SwigPtrTable[SwigPtrN++];
105 t->name = origtype;
106 t->len = strlen(t->name);
107 t->cast = 0;
108 t->next = 0;
109 }
110
111 /* Check for existing entries */
112 while (t->next) {
113 if ((strcmp(t->name,newtype) == 0)) {
114 if (cast) t->cast = cast;
115 return;
116 }
117 t = t->next;
118 }
119 t1 = (SwigPtrType *) malloc(sizeof(SwigPtrType));
120 t1->name = newtype;
121 t1->len = strlen(t1->name);
122 t1->cast = cast;
123 t1->next = 0;
124 t->next = t1;
125 SwigPtrSort = 0;
126 }
127
128 /* Make a pointer value string */
129 SWIGSTATICRUNTIME(void)
130 SWIG_MakePtr(char *c, const void *ptr, char *type) {
131 static char hex[17] = "0123456789abcdef";
132 unsigned long p, s;
133 char result[24], *r;
134 r = result;
135 p = (unsigned long) ptr;
136 if (p > 0) {
137 while (p > 0) {
138 s = p & 0xf;
139 *(r++) = hex[s];
140 p = p >> 4;
141 }
142 *r = '_';
143 while (r >= result)
144 *(c++) = *(r--);
145 strcpy (c, type);
146 } else {
147 strcpy (c, "NULL");
148 }
149 }
150
151 /* Function for getting a pointer value */
152 SWIGSTATICRUNTIME(char *)
153 SWIG_GetPtr(char *c, void **ptr, char *t)
154 {
155 unsigned long p;
156 char temp_type[256], *name;
157 int i, len, start, end;
158 SwigPtrType *sp,*tp;
159 SwigCacheType *cache;
160 register int d;
161
162 p = 0;
163 /* Pointer values must start with leading underscore */
164 if (*c != '_') {
165 *ptr = (void *) 0;
166 if (strcmp(c,"NULL") == 0) return (char *) 0;
167 else c;
168 }
169 c++;
170 /* Extract hex value from pointer */
171 while (d = *c) {
172 if ((d >= '0') && (d <= '9'))
173 p = (p << 4) + (d - '0');
174 else if ((d >= 'a') && (d <= 'f'))
175 p = (p << 4) + (d - ('a'-10));
176 else
177 break;
178 c++;
179 }
180 *ptr = (void *) p;
181 if ((!t) || (strcmp(t,c)==0)) return (char *) 0;
182
183 if (!SwigPtrSort) {
184 qsort((void *) SwigPtrTable, SwigPtrN, sizeof(SwigPtrType), swigsort);
185 for (i = 0; i < 256; i++) SwigStart[i] = SwigPtrN;
186 for (i = SwigPtrN-1; i >= 0; i--) SwigStart[(int) (SwigPtrTable[i].name[1])] = i;
187 for (i = 255; i >= 1; i--) {
188 if (SwigStart[i-1] > SwigStart[i])
189 SwigStart[i-1] = SwigStart[i];
190 }
191 SwigPtrSort = 1;
192 for (i = 0; i < SWIG_CACHESIZE; i++) SwigCache[i].stat = 0;
193 }
194 /* First check cache for matches. Uses last cache value as starting point */
195 cache = &SwigCache[SwigLastCache];
196 for (i = 0; i < SWIG_CACHESIZE; i++) {
197 if (cache->stat && (strcmp(t,cache->name) == 0) && (strcmp(c,cache->mapped) == 0)) {
198 cache->stat++;
199 if (cache->tp->cast) *ptr = (*(cache->tp->cast))(*ptr);
200 return (char *) 0;
201 }
202 SwigLastCache = (SwigLastCache+1) & SWIG_CACHEMASK;
203 if (!SwigLastCache) cache = SwigCache;
204 else cache++;
205 }
206 /* Type mismatch. Look through type-mapping table */
207 start = SwigStart[(int) t[1]];
208 end = SwigStart[(int) t[1]+1];
209 sp = &SwigPtrTable[start];
210
211 /* Try to find a match */
212 while (start <= end) {
213 if (strncmp(t,sp->name,sp->len) == 0) {
214 name = sp->name;
215 len = sp->len;
216 tp = sp->next;
217 /* Try to find entry for our given datatype */
218 while(tp) {
219 if (tp->len >= 255) {
220 return c;
221 }
222 strcpy(temp_type,tp->name);
223 strncat(temp_type,t+len,255-tp->len);
224 if (strcmp(c,temp_type) == 0) {
225 strcpy(SwigCache[SwigCacheIndex].mapped,c);
226 strcpy(SwigCache[SwigCacheIndex].name,t);
227 SwigCache[SwigCacheIndex].stat = 1;
228 SwigCache[SwigCacheIndex].tp = tp;
229 SwigCacheIndex = SwigCacheIndex & SWIG_CACHEMASK;
230 /* Get pointer value */
231 *ptr = (void *) p;
232 if (tp->cast) *ptr = (*(tp->cast))(*ptr);
233 return (char *) 0;
234 }
235 tp = tp->next;
236 }
237 }
238 sp++;
239 start++;
240 }
241 return c;
242 }
243
244 #endif
245
246 #ifdef __cplusplus
247 }
248 #endif
249