]>
git.saurik.com Git - wxWidgets.git/blob - wxPython/wxSWIG/Runtime/libtcl.c
7 #if defined(_WIN32) || defined(__WIN32__)
9 # define SWIGEXPORT(a) __declspec(dllexport) a
11 # if defined(__BORLANDC__)
12 # define SWIGEXPORT(a) a _export
14 # define SWIGEXPORT(a) a
18 # define SWIGEXPORT(a) a
21 /*****************************************************************************
25 *****************************************************************************/
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 *);
40 #define SWIGSTATICRUNTIME(a) SWIGEXPORT(a)
42 #define SWIGSTATICRUNTIME(a) static a
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 */
53 /* Pointer cache structure */
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 */
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 */
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;
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
);
81 /* Register a new datatype with the type-checker */
82 SWIGSTATICRUNTIME(void)
83 SWIG_RegisterMapping(char *origtype
, char *newtype
, void *(*cast
)(void *)) {
85 SwigPtrType
*t
= 0,*t1
;
87 /* Allocate the pointer table if necessary */
89 SwigPtrTable
= (SwigPtrType
*) malloc(SwigPtrMax
*sizeof(SwigPtrType
));
93 if (SwigPtrN
>= SwigPtrMax
) {
94 SwigPtrMax
= 2*SwigPtrMax
;
95 SwigPtrTable
= (SwigPtrType
*) realloc((char *) SwigPtrTable
,SwigPtrMax
*sizeof(SwigPtrType
));
97 for (i
= 0; i
< SwigPtrN
; i
++) {
98 if (strcmp(SwigPtrTable
[i
].name
,origtype
) == 0) {
104 t
= &SwigPtrTable
[SwigPtrN
++];
106 t
->len
= strlen(t
->name
);
111 /* Check for existing entries */
113 if ((strcmp(t
->name
,newtype
) == 0)) {
114 if (cast
) t
->cast
= cast
;
119 t1
= (SwigPtrType
*) malloc(sizeof(SwigPtrType
));
121 t1
->len
= strlen(t1
->name
);
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";
135 p
= (unsigned long) ptr
;
151 /* Function for getting a pointer value */
152 SWIGSTATICRUNTIME(char *)
153 SWIG_GetPtr(char *c
, void **ptr
, char *t
)
156 char temp_type
[256], *name
;
157 int i
, len
, start
, end
;
159 SwigCacheType
*cache
;
163 /* Pointer values must start with leading underscore */
166 if (strcmp(c
,"NULL") == 0) return (char *) 0;
170 /* Extract hex value from pointer */
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));
181 if ((!t
) || (strcmp(t
,c
)==0)) return (char *) 0;
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
];
192 for (i
= 0; i
< SWIG_CACHESIZE
; i
++) SwigCache
[i
].stat
= 0;
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)) {
199 if (cache
->tp
->cast
) *ptr
= (*(cache
->tp
->cast
))(*ptr
);
202 SwigLastCache
= (SwigLastCache
+1) & SWIG_CACHEMASK
;
203 if (!SwigLastCache
) cache
= SwigCache
;
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
];
211 /* Try to find a match */
212 while (start
<= end
) {
213 if (strncmp(t
,sp
->name
,sp
->len
) == 0) {
217 /* Try to find entry for our given datatype */
219 if (tp
->len
>= 255) {
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 */
232 if (tp
->cast
) *ptr
= (*(tp
->cast
))(*ptr
);