Lines 14-2409
Link Here
|
14 |
* |
14 |
* |
15 |
*/ |
15 |
*/ |
16 |
|
16 |
|
17 |
|
|
|
18 |
#define SWIGCODE |
19 |
/* Implementation : PYTHON */ |
20 |
|
21 |
#define SWIGPYTHON |
22 |
#include <string.h> |
23 |
#include <stdlib.h> |
24 |
/*********************************************************************** |
25 |
* $Header:$ |
26 |
* swig_lib/python/python.cfg |
27 |
* |
28 |
* This file contains coded needed to add variable linking to the |
29 |
* Python interpreter. C variables are added as a new kind of Python |
30 |
* datatype. |
31 |
* |
32 |
* Also contains supporting code for building python under Windows |
33 |
* and things like that. |
34 |
* |
35 |
* $Log:$ |
36 |
************************************************************************/ |
37 |
|
38 |
#ifdef __cplusplus |
39 |
extern "C" { |
40 |
#endif |
41 |
#include "Python.h" |
42 |
#ifdef __cplusplus |
43 |
} |
44 |
#endif |
45 |
|
46 |
/* Definitions for Windows/Unix exporting */ |
47 |
#if defined(__WIN32__) |
48 |
# if defined(_MSC_VER) |
49 |
# define SWIGEXPORT(a,b) __declspec(dllexport) a b |
50 |
# else |
51 |
# if defined(__BORLANDC__) |
52 |
# define SWIGEXPORT(a,b) a _export b |
53 |
# else |
54 |
# define SWIGEXPORT(a,b) a b |
55 |
# endif |
56 |
# endif |
57 |
#else |
58 |
# define SWIGEXPORT(a,b) a b |
59 |
#endif |
60 |
|
61 |
#ifdef SWIG_GLOBAL |
62 |
#ifdef __cplusplus |
63 |
#define SWIGSTATIC extern "C" |
64 |
#else |
65 |
#define SWIGSTATIC |
66 |
#endif |
67 |
#endif |
68 |
|
69 |
#ifndef SWIGSTATIC |
70 |
#define SWIGSTATIC static |
71 |
#endif |
72 |
|
73 |
typedef struct { |
74 |
char *name; |
75 |
PyObject *(*get_attr)(void); |
76 |
int (*set_attr)(PyObject *); |
77 |
} swig_globalvar; |
78 |
|
79 |
typedef struct swig_varlinkobject { |
80 |
PyObject_HEAD |
81 |
swig_globalvar **vars; |
82 |
int nvars; |
83 |
int maxvars; |
84 |
} swig_varlinkobject; |
85 |
|
86 |
/* ---------------------------------------------------------------------- |
87 |
swig_varlink_repr() |
88 |
|
89 |
Function for python repr method |
90 |
---------------------------------------------------------------------- */ |
91 |
|
92 |
static PyObject * |
93 |
swig_varlink_repr(swig_varlinkobject *v) |
94 |
{ |
95 |
v = v; |
96 |
return PyString_FromString("<Global variables>"); |
97 |
} |
98 |
|
99 |
/* --------------------------------------------------------------------- |
100 |
swig_varlink_print() |
101 |
|
102 |
Print out all of the global variable names |
103 |
--------------------------------------------------------------------- */ |
104 |
|
105 |
static int |
106 |
swig_varlink_print(swig_varlinkobject *v, FILE *fp, int flags) |
107 |
{ |
108 |
|
109 |
int i = 0; |
110 |
flags = flags; |
111 |
fprintf(fp,"Global variables { "); |
112 |
while (v->vars[i]) { |
113 |
fprintf(fp,"%s", v->vars[i]->name); |
114 |
i++; |
115 |
if (v->vars[i]) fprintf(fp,", "); |
116 |
} |
117 |
fprintf(fp," }\n"); |
118 |
return 0; |
119 |
} |
120 |
|
121 |
/* -------------------------------------------------------------------- |
122 |
swig_varlink_getattr |
123 |
|
124 |
This function gets the value of a variable and returns it as a |
125 |
PyObject. In our case, we'll be looking at the datatype and |
126 |
converting into a number or string |
127 |
-------------------------------------------------------------------- */ |
128 |
|
129 |
static PyObject * |
130 |
swig_varlink_getattr(swig_varlinkobject *v, char *n) |
131 |
{ |
132 |
int i = 0; |
133 |
char temp[128]; |
134 |
|
135 |
while (v->vars[i]) { |
136 |
if (strcmp(v->vars[i]->name,n) == 0) { |
137 |
return (*v->vars[i]->get_attr)(); |
138 |
} |
139 |
i++; |
140 |
} |
141 |
sprintf(temp,"C global variable %s not found.", n); |
142 |
PyErr_SetString(PyExc_NameError,temp); |
143 |
return NULL; |
144 |
} |
145 |
|
146 |
/* ------------------------------------------------------------------- |
147 |
swig_varlink_setattr() |
148 |
|
149 |
This function sets the value of a variable. |
150 |
------------------------------------------------------------------- */ |
151 |
|
152 |
static int |
153 |
swig_varlink_setattr(swig_varlinkobject *v, char *n, PyObject *p) |
154 |
{ |
155 |
char temp[128]; |
156 |
int i = 0; |
157 |
while (v->vars[i]) { |
158 |
if (strcmp(v->vars[i]->name,n) == 0) { |
159 |
return (*v->vars[i]->set_attr)(p); |
160 |
} |
161 |
i++; |
162 |
} |
163 |
sprintf(temp,"C global variable %s not found.", n); |
164 |
PyErr_SetString(PyExc_NameError,temp); |
165 |
return 1; |
166 |
} |
167 |
|
168 |
statichere PyTypeObject varlinktype = { |
169 |
/* PyObject_HEAD_INIT(&PyType_Type) Note : This doesn't work on some machines */ |
170 |
PyObject_HEAD_INIT(0) |
171 |
0, |
172 |
"varlink", /* Type name */ |
173 |
sizeof(swig_varlinkobject), /* Basic size */ |
174 |
0, /* Itemsize */ |
175 |
0, /* Deallocator */ |
176 |
(printfunc) swig_varlink_print, /* Print */ |
177 |
(getattrfunc) swig_varlink_getattr, /* get attr */ |
178 |
(setattrfunc) swig_varlink_setattr, /* Set attr */ |
179 |
0, /* tp_compare */ |
180 |
(reprfunc) swig_varlink_repr, /* tp_repr */ |
181 |
0, /* tp_as_number */ |
182 |
0, /* tp_as_mapping*/ |
183 |
0, /* tp_hash */ |
184 |
}; |
185 |
|
186 |
/* Create a variable linking object for use later */ |
187 |
|
188 |
SWIGSTATIC PyObject * |
189 |
SWIG_newvarlink(void) |
190 |
{ |
191 |
swig_varlinkobject *result = 0; |
192 |
result = PyMem_NEW(swig_varlinkobject,1); |
193 |
varlinktype.ob_type = &PyType_Type; /* Patch varlinktype into a PyType */ |
194 |
result->ob_type = &varlinktype; |
195 |
/* _Py_NewReference(result); Does not seem to be necessary */ |
196 |
result->nvars = 0; |
197 |
result->maxvars = 64; |
198 |
result->vars = (swig_globalvar **) malloc(64*sizeof(swig_globalvar *)); |
199 |
result->vars[0] = 0; |
200 |
result->ob_refcnt = 0; |
201 |
Py_XINCREF((PyObject *) result); |
202 |
return ((PyObject*) result); |
203 |
} |
204 |
|
205 |
SWIGSTATIC void |
206 |
SWIG_addvarlink(PyObject *p, char *name, |
207 |
PyObject *(*get_attr)(void), int (*set_attr)(PyObject *p)) |
208 |
{ |
209 |
swig_varlinkobject *v; |
210 |
v= (swig_varlinkobject *) p; |
211 |
|
212 |
if (v->nvars >= v->maxvars -1) { |
213 |
v->maxvars = 2*v->maxvars; |
214 |
v->vars = (swig_globalvar **) realloc(v->vars,v->maxvars*sizeof(swig_globalvar *)); |
215 |
if (v->vars == NULL) { |
216 |
fprintf(stderr,"SWIG : Fatal error in initializing Python module.\n"); |
217 |
exit(1); |
218 |
} |
219 |
} |
220 |
v->vars[v->nvars] = (swig_globalvar *) malloc(sizeof(swig_globalvar)); |
221 |
v->vars[v->nvars]->name = (char *) malloc(strlen(name)+1); |
222 |
strcpy(v->vars[v->nvars]->name,name); |
223 |
v->vars[v->nvars]->get_attr = get_attr; |
224 |
v->vars[v->nvars]->set_attr = set_attr; |
225 |
v->nvars++; |
226 |
v->vars[v->nvars] = 0; |
227 |
} |
228 |
|
229 |
|
230 |
|
231 |
/***************************************************************************** |
232 |
* $Header:$ |
233 |
* |
234 |
* swigptr.swg |
235 |
* |
236 |
* This file contains supporting code for the SWIG run-time type checking |
237 |
* mechanism. The following functions are available : |
238 |
* |
239 |
* SWIG_RegisterMapping(char *origtype, char *newtype, void *(*cast)(void *)); |
240 |
* |
241 |
* Registers a new type-mapping with the type-checker. origtype is the |
242 |
* original datatype and newtype is an equivalent type. cast is optional |
243 |
* pointer to a function to cast pointer values between types (this |
244 |
* is typically used to cast pointers from derived classes to base classes in C++) |
245 |
* |
246 |
* SWIG_MakePtr(char *buffer, void *ptr, char *typestring); |
247 |
* |
248 |
* Makes a pointer string from a pointer and typestring. The result is returned |
249 |
* in buffer which is assumed to hold enough space for the result. |
250 |
* |
251 |
* char * SWIG_GetPtr(char *buffer, void **ptr, char *type) |
252 |
* |
253 |
* Gets a pointer value from a string. If there is a type-mismatch, returns |
254 |
* a character string to the received type. On success, returns NULL. |
255 |
* |
256 |
* |
257 |
* You can remap these functions by making a file called "swigptr.swg" in |
258 |
* your the same directory as the interface file you are wrapping. |
259 |
* |
260 |
* These functions are normally declared static, but this file can be |
261 |
* can be used in a multi-module environment by redefining the symbol |
262 |
* SWIGSTATIC. |
263 |
*****************************************************************************/ |
264 |
|
265 |
#include <stdlib.h> |
266 |
|
267 |
#ifdef SWIG_GLOBAL |
268 |
#ifdef __cplusplus |
269 |
#define SWIGSTATIC extern "C" |
270 |
#else |
271 |
#define SWIGSTATIC |
272 |
#endif |
273 |
#endif |
274 |
|
275 |
#ifndef SWIGSTATIC |
276 |
#define SWIGSTATIC static |
277 |
#endif |
278 |
|
279 |
|
280 |
/* SWIG pointer structure */ |
281 |
|
282 |
typedef struct SwigPtrType { |
283 |
char *name; /* Datatype name */ |
284 |
int len; /* Length (used for optimization) */ |
285 |
void *(*cast)(void *); /* Pointer casting function */ |
286 |
struct SwigPtrType *next; /* Linked list pointer */ |
287 |
} SwigPtrType; |
288 |
|
289 |
/* Pointer cache structure */ |
290 |
|
291 |
typedef struct { |
292 |
int stat; /* Status (valid) bit */ |
293 |
SwigPtrType *tp; /* Pointer to type structure */ |
294 |
char name[256]; /* Given datatype name */ |
295 |
char mapped[256]; /* Equivalent name */ |
296 |
} SwigCacheType; |
297 |
|
298 |
/* Some variables */ |
299 |
|
300 |
static int SwigPtrMax = 64; /* Max entries that can be currently held */ |
301 |
/* This value may be adjusted dynamically */ |
302 |
static int SwigPtrN = 0; /* Current number of entries */ |
303 |
static int SwigPtrSort = 0; /* Status flag indicating sort */ |
304 |
static int SwigStart[256]; /* Starting positions of types */ |
305 |
|
306 |
/* Pointer table */ |
307 |
static SwigPtrType *SwigPtrTable = 0; /* Table containing pointer equivalences */ |
308 |
|
309 |
/* Cached values */ |
310 |
|
311 |
#define SWIG_CACHESIZE 8 |
312 |
#define SWIG_CACHEMASK 0x7 |
313 |
static SwigCacheType SwigCache[SWIG_CACHESIZE]; |
314 |
static int SwigCacheIndex = 0; |
315 |
static int SwigLastCache = 0; |
316 |
|
317 |
/* Sort comparison function */ |
318 |
static int swigsort(const void *data1, const void *data2) { |
319 |
SwigPtrType *d1 = (SwigPtrType *) data1; |
320 |
SwigPtrType *d2 = (SwigPtrType *) data2; |
321 |
return strcmp(d1->name,d2->name); |
322 |
} |
323 |
|
324 |
/* Binary Search function */ |
325 |
static int swigcmp(const void *key, const void *data) { |
326 |
char *k = (char *) key; |
327 |
SwigPtrType *d = (SwigPtrType *) data; |
328 |
return strncmp(k,d->name,d->len); |
329 |
} |
330 |
|
331 |
/* Register a new datatype with the type-checker */ |
332 |
|
333 |
SWIGSTATIC |
334 |
void SWIG_RegisterMapping(char *origtype, char *newtype, void *(*cast)(void *)) { |
335 |
|
336 |
int i; |
337 |
SwigPtrType *t = 0,*t1; |
338 |
|
339 |
/* Allocate the pointer table if necessary */ |
340 |
|
341 |
if (!SwigPtrTable) { |
342 |
SwigPtrTable = (SwigPtrType *) malloc(SwigPtrMax*sizeof(SwigPtrType)); |
343 |
SwigPtrN = 0; |
344 |
} |
345 |
/* Grow the table */ |
346 |
if (SwigPtrN >= SwigPtrMax) { |
347 |
SwigPtrMax = 2*SwigPtrMax; |
348 |
SwigPtrTable = (SwigPtrType *) realloc((char *) SwigPtrTable,SwigPtrMax*sizeof(SwigPtrType)); |
349 |
} |
350 |
for (i = 0; i < SwigPtrN; i++) |
351 |
if (strcmp(SwigPtrTable[i].name,origtype) == 0) { |
352 |
t = &SwigPtrTable[i]; |
353 |
break; |
354 |
} |
355 |
if (!t) { |
356 |
t = &SwigPtrTable[SwigPtrN]; |
357 |
t->name = origtype; |
358 |
t->len = strlen(t->name); |
359 |
t->cast = 0; |
360 |
t->next = 0; |
361 |
SwigPtrN++; |
362 |
} |
363 |
|
364 |
/* Check for existing entry */ |
365 |
|
366 |
while (t->next) { |
367 |
if ((strcmp(t->name,newtype) == 0)) { |
368 |
if (cast) t->cast = cast; |
369 |
return; |
370 |
} |
371 |
t = t->next; |
372 |
} |
373 |
|
374 |
/* Now place entry (in sorted order) */ |
375 |
|
376 |
t1 = (SwigPtrType *) malloc(sizeof(SwigPtrType)); |
377 |
t1->name = newtype; |
378 |
t1->len = strlen(t1->name); |
379 |
t1->cast = cast; |
380 |
t1->next = 0; |
381 |
t->next = t1; |
382 |
SwigPtrSort = 0; |
383 |
} |
384 |
|
385 |
/* Make a pointer value string */ |
386 |
|
387 |
SWIGSTATIC |
388 |
void SWIG_MakePtr(char *_c, const void *_ptr, char *type) { |
389 |
static char _hex[16] = |
390 |
{'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', |
391 |
'a', 'b', 'c', 'd', 'e', 'f'}; |
392 |
unsigned long _p, _s; |
393 |
char _result[20], *_r; /* Note : a 64-bit hex number = 16 digits */ |
394 |
_r = _result; |
395 |
_p = (unsigned long) _ptr; |
396 |
if (_p > 0) { |
397 |
while (_p > 0) { |
398 |
_s = _p & 0xf; |
399 |
*(_r++) = _hex[_s]; |
400 |
_p = _p >> 4; |
401 |
} |
402 |
*_r = '_'; |
403 |
while (_r >= _result) |
404 |
*(_c++) = *(_r--); |
405 |
} else { |
406 |
strcpy (_c, "NULL"); |
407 |
} |
408 |
if (_ptr) |
409 |
strcpy (_c, type); |
410 |
} |
411 |
|
412 |
/* Define for backwards compatibility */ |
413 |
|
414 |
#define _swig_make_hex SWIG_MakePtr |
415 |
|
416 |
/* Function for getting a pointer value */ |
417 |
|
418 |
SWIGSTATIC |
419 |
char *SWIG_GetPtr(char *_c, void **ptr, char *_t) |
420 |
{ |
421 |
unsigned long _p; |
422 |
char temp_type[256]; |
423 |
char *name; |
424 |
int i, len; |
425 |
SwigPtrType *sp,*tp; |
426 |
SwigCacheType *cache; |
427 |
int start, end; |
428 |
_p = 0; |
429 |
|
430 |
/* Pointer values must start with leading underscore */ |
431 |
if (*_c == '_') { |
432 |
_c++; |
433 |
/* Extract hex value from pointer */ |
434 |
while (*_c) { |
435 |
if ((*_c >= '0') && (*_c <= '9')) |
436 |
_p = (_p << 4) + (*_c - '0'); |
437 |
else if ((*_c >= 'a') && (*_c <= 'f')) |
438 |
_p = (_p << 4) + ((*_c - 'a') + 10); |
439 |
else |
440 |
break; |
441 |
_c++; |
442 |
} |
443 |
|
444 |
if (_t) { |
445 |
if (strcmp(_t,_c)) { |
446 |
if (!SwigPtrSort) { |
447 |
qsort((void *) SwigPtrTable, SwigPtrN, sizeof(SwigPtrType), swigsort); |
448 |
for (i = 0; i < 256; i++) { |
449 |
SwigStart[i] = SwigPtrN; |
450 |
} |
451 |
for (i = SwigPtrN-1; i >= 0; i--) { |
452 |
SwigStart[(int) (SwigPtrTable[i].name[1])] = i; |
453 |
} |
454 |
for (i = 255; i >= 1; i--) { |
455 |
if (SwigStart[i-1] > SwigStart[i]) |
456 |
SwigStart[i-1] = SwigStart[i]; |
457 |
} |
458 |
SwigPtrSort = 1; |
459 |
for (i = 0; i < SWIG_CACHESIZE; i++) |
460 |
SwigCache[i].stat = 0; |
461 |
} |
462 |
|
463 |
/* First check cache for matches. Uses last cache value as starting point */ |
464 |
cache = &SwigCache[SwigLastCache]; |
465 |
for (i = 0; i < SWIG_CACHESIZE; i++) { |
466 |
if (cache->stat) { |
467 |
if (strcmp(_t,cache->name) == 0) { |
468 |
if (strcmp(_c,cache->mapped) == 0) { |
469 |
cache->stat++; |
470 |
*ptr = (void *) _p; |
471 |
if (cache->tp->cast) *ptr = (*(cache->tp->cast))(*ptr); |
472 |
return (char *) 0; |
473 |
} |
474 |
} |
475 |
} |
476 |
SwigLastCache = (SwigLastCache+1) & SWIG_CACHEMASK; |
477 |
if (!SwigLastCache) cache = SwigCache; |
478 |
else cache++; |
479 |
} |
480 |
/* We have a type mismatch. Will have to look through our type |
481 |
mapping table to figure out whether or not we can accept this datatype */ |
482 |
|
483 |
start = SwigStart[(int) _t[1]]; |
484 |
end = SwigStart[(int) _t[1]+1]; |
485 |
sp = &SwigPtrTable[start]; |
486 |
while (start < end) { |
487 |
if (swigcmp(_t,sp) == 0) break; |
488 |
sp++; |
489 |
start++; |
490 |
} |
491 |
if (start >= end) sp = 0; |
492 |
/* Try to find a match for this */ |
493 |
if (sp) { |
494 |
while (swigcmp(_t,sp) == 0) { |
495 |
name = sp->name; |
496 |
len = sp->len; |
497 |
tp = sp->next; |
498 |
/* Try to find entry for our given datatype */ |
499 |
while(tp) { |
500 |
if (tp->len >= 255) { |
501 |
return _c; |
502 |
} |
503 |
strcpy(temp_type,tp->name); |
504 |
strncat(temp_type,_t+len,255-tp->len); |
505 |
if (strcmp(_c,temp_type) == 0) { |
506 |
|
507 |
strcpy(SwigCache[SwigCacheIndex].mapped,_c); |
508 |
strcpy(SwigCache[SwigCacheIndex].name,_t); |
509 |
SwigCache[SwigCacheIndex].stat = 1; |
510 |
SwigCache[SwigCacheIndex].tp = tp; |
511 |
SwigCacheIndex = SwigCacheIndex & SWIG_CACHEMASK; |
512 |
|
513 |
/* Get pointer value */ |
514 |
*ptr = (void *) _p; |
515 |
if (tp->cast) *ptr = (*(tp->cast))(*ptr); |
516 |
return (char *) 0; |
517 |
} |
518 |
tp = tp->next; |
519 |
} |
520 |
sp++; |
521 |
/* Hmmm. Didn't find it this time */ |
522 |
} |
523 |
} |
524 |
/* Didn't find any sort of match for this data. |
525 |
Get the pointer value and return the received type */ |
526 |
*ptr = (void *) _p; |
527 |
return _c; |
528 |
} else { |
529 |
/* Found a match on the first try. Return pointer value */ |
530 |
*ptr = (void *) _p; |
531 |
return (char *) 0; |
532 |
} |
533 |
} else { |
534 |
/* No type specified. Good luck */ |
535 |
*ptr = (void *) _p; |
536 |
return (char *) 0; |
537 |
} |
538 |
} else { |
539 |
if (strcmp (_c, "NULL") == 0) { |
540 |
*ptr = (void *) 0; |
541 |
return (char *) 0; |
542 |
} |
543 |
*ptr = (void *) 0; |
544 |
return _c; |
545 |
} |
546 |
} |
547 |
|
548 |
/* Compatibility mode */ |
549 |
|
550 |
#define _swig_get_hex SWIG_GetPtr |
551 |
|
552 |
#define SWIG_init initcooledit |
553 |
|
554 |
#define SWIG_name "cooledit" |
555 |
|
556 |
|
557 |
#define GLOBAL_STARTUP_FILE "global.py" |
558 |
|
559 |
#include <config.h> |
560 |
#include <stdio.h> |
561 |
#include <stdlib.h> |
562 |
#include <signal.h> |
563 |
#include <sys/types.h> |
564 |
#if HAVE_SYS_WAIT_H |
565 |
#include <sys/wait.h> |
566 |
#endif |
567 |
|
568 |
#include <X11/Xlib.h> |
569 |
#include <X11/Xutil.h> |
570 |
#include <X11/Xatom.h> |
571 |
#include "lkeysym.h" |
572 |
|
573 |
#include "stringtools.h" |
574 |
#include "coolwidget.h" |
575 |
#include "edit.h" |
576 |
#include "editcmddef.h" |
577 |
#include "editoptions.h" |
578 |
#include "shell.h" /* MAX_NUM_SCRIPTS */ |
579 |
#include "find.h" |
580 |
#include "mad.h" |
581 |
|
582 |
|
583 |
void coolpython_init (int argc, char **argv); |
584 |
void coolpython_shut (void); |
585 |
int coolpython_key (unsigned int state, unsigned int keycode, KeySym keysym); |
586 |
void coolpython_command (WEdit * edit, int i); |
587 |
void coolpython_typechange (Window win); |
588 |
|
589 |
void initcooledit (); |
590 |
static void coolpython_display_error (int set_sys_last_vars); |
591 |
|
592 |
|
593 |
#define CHECK_CURRENT if (!last_edit) return; |
594 |
#define CHECK_CURRENT_RETURN(x) if (!last_edit) return (x); |
595 |
|
596 |
extern CWidget *edit[]; |
597 |
extern long current_edit; |
598 |
extern long last_edit; |
599 |
|
600 |
static PyObject *name_space = 0; |
601 |
|
602 |
/* {{{ bindings */ |
603 |
|
604 |
#define MAX_GLOBAL_BINDINGS 1000 |
605 |
#define MAX_CURRENT_BINDINGS 1000 |
606 |
|
607 |
#define GLOBAL_BINDING(i) ((i) + MAX_CURRENT_BINDINGS) |
608 |
#define CURRENT_BINDING(i) ((i) + 0) |
609 |
#define BINDING_GLOBAL(i) ((i) - MAX_CURRENT_BINDINGS) |
610 |
#define BINDING_CURRENT(i) ((i) - 0) |
611 |
|
612 |
struct python_binding { |
613 |
PyObject *function; |
614 |
char *statement; |
615 |
KeySym keysym; |
616 |
int modifiers; |
617 |
struct python_binding *next; |
618 |
}; |
619 |
|
620 |
static struct { |
621 |
char *statement; |
622 |
KeySym keysym; |
623 |
int modifiers; |
624 |
} bindings[MAX_GLOBAL_BINDINGS]; |
625 |
|
626 |
int last_binding = 0; |
627 |
|
628 |
static void free_current_bindings (void *x) |
629 |
{ |
630 |
struct python_binding *b, *n; |
631 |
for (b = (struct python_binding *) x; b; b = n) { |
632 |
n = b->next; |
633 |
if (b->statement) |
634 |
free (b->statement); |
635 |
Py_XDECREF (b->function); |
636 |
free (b); |
637 |
} |
638 |
} |
639 |
|
640 |
/* returns non-zero on error: i.e. max bindings reached */ |
641 |
static int add_binding (PyObject * function, char *statement, KeySym keysym, int modifiers) |
642 |
{ |
643 |
struct python_binding **b, *p; |
644 |
int i; |
645 |
b = (struct python_binding **) &(edit[current_edit]->user); |
646 |
for (i = 0; *b; b = &((*b)->next), i++) { |
647 |
if (i >= MAX_CURRENT_BINDINGS) |
648 |
return 1; |
649 |
p = *b; |
650 |
if (p->keysym == keysym && p->modifiers == modifiers) { |
651 |
Py_XDECREF (p->function); |
652 |
p->function = 0; |
653 |
if (p->statement) { |
654 |
free (p->statement); |
655 |
p->statement = 0; |
656 |
} |
657 |
if (!function && !statement) { |
658 |
p = (*b)->next; |
659 |
free (*b); |
660 |
*b = p; |
661 |
return 0; |
662 |
} else { |
663 |
goto no_alloc; |
664 |
} |
665 |
} |
666 |
} |
667 |
p = *b = malloc (sizeof (struct python_binding)); |
668 |
p->next = 0; |
669 |
no_alloc: |
670 |
if (function) { |
671 |
Py_INCREF (function); |
672 |
p->function = function; |
673 |
p->statement = 0; |
674 |
} else if (statement) { |
675 |
p->function = 0; |
676 |
p->statement = (char *) strdup (statement); |
677 |
} else { |
678 |
free (p); |
679 |
return 0; |
680 |
} |
681 |
p->keysym = keysym; |
682 |
p->modifiers = modifiers; |
683 |
edit[current_edit]->free_user = free_current_bindings; |
684 |
return 0; |
685 |
} |
686 |
|
687 |
static int add_bindings (PyObject *function, KeySym keysym1, KeySym keysym2, int modifiers) |
688 |
{ |
689 |
int r = 0; |
690 |
while (keysym1 <= keysym2) |
691 |
if ((r = add_binding (function, 0, keysym1++, modifiers))) |
692 |
break; |
693 |
return r; |
694 |
} |
695 |
|
696 |
int coolpython_key (unsigned int state, unsigned int keycode, KeySym keysym) |
697 |
{ |
698 |
struct python_binding *b; |
699 |
int i; |
700 |
CWidget *w; |
701 |
/* make sure we are really an editor since bindings should not apply in input/text/other widgets */ |
702 |
w = CWidgetOfWindow (CGetFocus ()); |
703 |
if (!w) |
704 |
return -1; |
705 |
if (w->kind != C_EDITOR_WIDGET) |
706 |
return -1; |
707 |
/* check bindings for current editor */ |
708 |
for (i = 0, b = (struct python_binding *) edit[current_edit]->user; b; b = b->next, i++) |
709 |
if (b->keysym == keysym && b->modifiers == state) |
710 |
return CURRENT_BINDING (i); |
711 |
/* check global bindings */ |
712 |
for (i = 0; i < last_binding; i++) |
713 |
if (bindings[i].keysym == keysym && bindings[i].modifiers == state) |
714 |
return GLOBAL_BINDING (i); |
715 |
return -1; |
716 |
} |
717 |
|
718 |
/* }}} bindings */ |
719 |
|
720 |
static void move (long i) |
721 |
{ |
722 |
CHECK_CURRENT; |
723 |
edit_cursor_move (edit[current_edit]->editor, i); |
724 |
} |
725 |
|
726 |
static void move_lines (long i) |
727 |
{ |
728 |
CHECK_CURRENT; |
729 |
if (i > 0) |
730 |
edit_move_up (edit[current_edit]->editor, i, 0); |
731 |
else if (i < 0) |
732 |
edit_move_down (edit[current_edit]->editor, i, 0); |
733 |
} |
734 |
|
735 |
static void move_to (long i) |
736 |
{ |
737 |
CHECK_CURRENT; |
738 |
edit_cursor_move (edit[current_edit]->editor, i - edit[current_edit]->editor->curs1); |
739 |
} |
740 |
|
741 |
static void insert (char *s) |
742 |
{ |
743 |
CHECK_CURRENT; |
744 |
for (; *s; s++) |
745 |
edit_insert (edit[current_edit]->editor, (long) *s); |
746 |
} |
747 |
|
748 |
static void delete (long i) |
749 |
{ |
750 |
CHECK_CURRENT; |
751 |
if (i > 0) |
752 |
while (i-- && edit[current_edit]->editor->curs2 > 0) |
753 |
edit_delete (edit[current_edit]->editor); |
754 |
} |
755 |
|
756 |
static void back_space (long i) |
757 |
{ |
758 |
CHECK_CURRENT; |
759 |
if (i > 0) |
760 |
while (i-- && edit[current_edit]->editor->curs1 > 0) |
761 |
edit_backspace (edit[current_edit]->editor); |
762 |
} |
763 |
|
764 |
static void insert_ahead (char *s) |
765 |
{ |
766 |
long l, r; |
767 |
CHECK_CURRENT; |
768 |
r = l = strlen (s); |
769 |
s += l - 1; |
770 |
for (; l >= 0; s--, l--) |
771 |
edit_insert_ahead (edit[current_edit]->editor, (long) *s); |
772 |
} |
773 |
|
774 |
static long current (void) |
775 |
{ |
776 |
CHECK_CURRENT_RETURN (-1); |
777 |
return edit[current_edit]->editor->curs1; |
778 |
} |
779 |
|
780 |
static long current_line (void) |
781 |
{ |
782 |
CHECK_CURRENT_RETURN (-1); |
783 |
return edit[current_edit]->editor->curs_line; |
784 |
} |
785 |
|
786 |
static long bol (long i) |
787 |
{ |
788 |
CHECK_CURRENT_RETURN (-1); |
789 |
if (i > edit[current_edit]->editor->total_lines || i < 0) |
790 |
return -1; |
791 |
return edit_find_line (edit[current_edit]->editor, i); |
792 |
} |
793 |
|
794 |
static long eol (long i) |
795 |
{ |
796 |
CHECK_CURRENT_RETURN (-1); |
797 |
if (i > edit[current_edit]->editor->total_lines || i < 0) |
798 |
return -1; |
799 |
return edit_eol (edit[current_edit]->editor, bol (i)); |
800 |
} |
801 |
|
802 |
static long find_forwards (long from, char *s) |
803 |
{ |
804 |
CHECK_CURRENT_RETURN (-1); |
805 |
if (!*s) |
806 |
return -1; |
807 |
for (; from < edit[current_edit]->editor->last_byte; from++) { |
808 |
if (*s == edit_get_byte (edit[current_edit]->editor, from)) { |
809 |
int i; |
810 |
for (i = 1;; i++) { |
811 |
if (!s[i]) |
812 |
return from; |
813 |
if (s[i] == edit_get_byte (edit[current_edit]->editor, from + i)) |
814 |
continue; |
815 |
break; |
816 |
} |
817 |
} |
818 |
} |
819 |
return -1; |
820 |
} |
821 |
|
822 |
static long find_backwards (long from, char *s) |
823 |
{ |
824 |
CHECK_CURRENT_RETURN (-1); |
825 |
if (!*s) |
826 |
return -1; |
827 |
for (; from >= 0; from--) { |
828 |
if (*s == edit_get_byte (edit[current_edit]->editor, from)) { |
829 |
int i; |
830 |
for (i = 1;; i++) { |
831 |
if (!s[i]) |
832 |
return from; |
833 |
if (s[i] == edit_get_byte (edit[current_edit]->editor, from + i)) |
834 |
continue; |
835 |
break; |
836 |
} |
837 |
} |
838 |
} |
839 |
return -1; |
840 |
} |
841 |
|
842 |
static PyObject *edit__get_text (PyObject * self, PyObject * args) |
843 |
{ |
844 |
PyObject *result; |
845 |
char *r, *p; |
846 |
long i, j = -1, l; |
847 |
if (!PyArg_ParseTuple (args, "|ll:get_text", &i, &j)) |
848 |
return NULL; |
849 |
if (i == -1) |
850 |
i = edit[current_edit]->editor->curs1; |
851 |
if (j == -1) |
852 |
j = i + 1; |
853 |
l = j - i; |
854 |
if (l < 0) { |
855 |
PyErr_SetString (PyExc_ValueError, _("second offset is less than first")); |
856 |
return NULL; |
857 |
} |
858 |
p = r = malloc (l + 1); |
859 |
if (i < 0) |
860 |
i = 0; |
861 |
if (j >= edit[current_edit]->editor->last_byte) |
862 |
j = edit[current_edit]->editor->last_byte; |
863 |
for (; i < j; i++) |
864 |
*p++ = edit_get_byte (edit[current_edit]->editor, i); |
865 |
*p = '\0'; |
866 |
result = PyString_FromStringAndSize (r, l); |
867 |
free (r); |
868 |
return result; |
869 |
} |
870 |
|
871 |
|
872 |
|
873 |
static PyObject *edit__get_line (PyObject * self, PyObject * args) |
874 |
{ |
875 |
PyObject *result; |
876 |
char *r, *p; |
877 |
int i, j, l, l1 = -1, l2 = -1; |
878 |
if (!PyArg_ParseTuple (args, "|ii:get_line", &l1, &l2)) |
879 |
return NULL; |
880 |
if (l1 == -1) |
881 |
l1 = edit[current_edit]->editor->curs_line; |
882 |
if (l2 == -1) |
883 |
l2 = l1; |
884 |
i = bol (l1); |
885 |
j = eol (l2); |
886 |
l = j - i; |
887 |
if (l < 0) { |
888 |
PyErr_SetString (PyExc_ValueError, _("second offset is less than first")); |
889 |
return NULL; |
890 |
} |
891 |
p = r = malloc (l + 1); |
892 |
if (i < 0) |
893 |
i = 0; |
894 |
if (j >= edit[current_edit]->editor->last_byte) |
895 |
j = edit[current_edit]->editor->last_byte; |
896 |
for (; i < j; i++) |
897 |
*p++ = edit_get_byte (edit[current_edit]->editor, i); |
898 |
*p = '\0'; |
899 |
result = PyString_FromStringAndSize (r, l); |
900 |
free (r); |
901 |
return result; |
902 |
} |
903 |
|
904 |
|
905 |
|
906 |
static long line (long i) |
907 |
{ |
908 |
CHECK_CURRENT_RETURN (-1); |
909 |
if (i > edit[current_edit]->editor->curs1) |
910 |
return edit[current_edit]->editor->curs_line + edit_count_lines (edit[current_edit]->editor, edit[current_edit]->editor->curs1, i); |
911 |
return edit[current_edit]->editor->curs_line - edit_count_lines (edit[current_edit]->editor, i, edit[current_edit]->editor->curs1); |
912 |
} |
913 |
|
914 |
static void command (long i) |
915 |
{ |
916 |
CHECK_CURRENT; |
917 |
edit_execute_cmd (edit[current_edit]->editor, i, -1); |
918 |
} |
919 |
|
920 |
/* window functions */ |
921 |
static void focus (void) |
922 |
{ |
923 |
CHECK_CURRENT; |
924 |
CFocus (edit[current_edit]); |
925 |
XRaiseWindow (CDisplay, edit[current_edit]->parentid); |
926 |
CRaiseWindows (); |
927 |
current_to_top (); |
928 |
} |
929 |
|
930 |
static long set_editor (char *filename_with_path) |
931 |
{ |
932 |
char *f, *d, *p; |
933 |
int i, r = 1; |
934 |
d = pathdup (filename_with_path); |
935 |
p = strrchr (d, '/'); |
936 |
if (p) { |
937 |
p++; |
938 |
f = (char *) strdup (p); |
939 |
*p = '\0'; |
940 |
} else { |
941 |
free (d); |
942 |
return 1; |
943 |
} |
944 |
for (i = 0; i < last_edit; i++) { |
945 |
if (strcmp (f, edit[i]->editor->filename)) |
946 |
continue; |
947 |
if (strcmp (d, edit[i]->editor->dir)) |
948 |
continue; |
949 |
current_edit = i; |
950 |
r = 0; |
951 |
break; |
952 |
} |
953 |
free (d); |
954 |
free (f); |
955 |
return r; |
956 |
} |
957 |
|
958 |
static void close_window (long force) |
959 |
{ |
960 |
if (force) |
961 |
edit[current_edit]->editor->stopped = 1; |
962 |
else |
963 |
edit_execute_command (edit[current_edit]->editor, CK_Exit, -1); |
964 |
} |
965 |
|
966 |
static void new_window (void) |
967 |
{ |
968 |
new_window_callback (0); |
969 |
} |
970 |
|
971 |
static int load (char *filename) |
972 |
{ |
973 |
return edit_load_file_from_filename (edit[current_edit]->editor, filename); |
974 |
} |
975 |
|
976 |
static void status (char *text) |
977 |
{ |
978 |
char id[33]; |
979 |
CWidget *w; |
980 |
strcpy (id, CIdentOf (edit[current_edit])); |
981 |
strcat (id, ".text"); |
982 |
w = CIdent (id); |
983 |
free (w->text); |
984 |
w->text = (char *) strdup (text); |
985 |
render_status (w, 0); |
986 |
} |
987 |
|
988 |
static char *file (void) |
989 |
{ |
990 |
return edit[current_edit]->editor->filename; |
991 |
} |
992 |
|
993 |
static char *directory (void) |
994 |
{ |
995 |
return edit[current_edit]->editor->dir; |
996 |
} |
997 |
|
998 |
static long modified (void) |
999 |
{ |
1000 |
return (long) edit[current_edit]->editor->modified; |
1001 |
} |
1002 |
|
1003 |
static char *input_dialog (char *title, char *prompt, char *def) |
1004 |
{ |
1005 |
static char x[4096]; |
1006 |
char *p; |
1007 |
p = CInputDialog (title, 0, 0, 0, 60 * FONT_MEAN_WIDTH, def, title, "%s", prompt); |
1008 |
if (!p) |
1009 |
return 0; |
1010 |
else |
1011 |
strncpy (x, p, 4095); |
1012 |
free (p); |
1013 |
return x; |
1014 |
} |
1015 |
|
1016 |
static char *load_file_dialog (char *title, char *dir, char *def) |
1017 |
{ |
1018 |
static char x[4096]; |
1019 |
char *p; |
1020 |
p = CGetLoadFile (0, 0, 0, dir, def, title); |
1021 |
if (!p) |
1022 |
return 0; |
1023 |
else |
1024 |
strncpy (x, p, 4095); |
1025 |
free (p); |
1026 |
return x; |
1027 |
} |
1028 |
|
1029 |
static char *save_file_dialog (char *title, char *dir, char *def) |
1030 |
{ |
1031 |
static char x[4096]; |
1032 |
char *p; |
1033 |
p = CGetSaveFile (0, 0, 0, dir, def, title); |
1034 |
if (!p) |
1035 |
return 0; |
1036 |
else |
1037 |
strncpy (x, p, 4095); |
1038 |
free (p); |
1039 |
return x; |
1040 |
} |
1041 |
|
1042 |
static char *status_input (char *prompt, char *def) |
1043 |
{ |
1044 |
char id[33]; |
1045 |
int width = 0; |
1046 |
XEvent xevent; |
1047 |
KeySym k; |
1048 |
static char t[260]; |
1049 |
char *r; |
1050 |
CState s; |
1051 |
CWidget *w, *p = 0, *i; |
1052 |
r = 0; |
1053 |
strcpy (id, CIdentOf (edit[current_edit])); |
1054 |
strcat (id, ".text"); |
1055 |
CBackupState (&s); |
1056 |
CDisable ("*"); |
1057 |
w = CIdent (id); |
1058 |
if (*prompt) { |
1059 |
p = CDrawText ("status_prompt", edit[current_edit]->parentid, CXof (w), CYof (w), "%s", prompt); |
1060 |
width = CWidthOf (p); |
1061 |
} |
1062 |
i = CDrawTextInput ("status_input", edit[current_edit]->parentid, CXof (w) + width, CYof (w), |
1063 |
CWidthOf (edit[current_edit]) - width, AUTO_HEIGHT, 256, def); |
1064 |
CFocus (i); |
1065 |
for (;;) { |
1066 |
CNextEvent (&xevent, 0); |
1067 |
if (xevent.type == KeyPress) { |
1068 |
k = CKeySym (&xevent); |
1069 |
if (k == XK_KP_Enter || k == XK_Return) { |
1070 |
strcpy (t, i->text); |
1071 |
r = t; |
1072 |
break; |
1073 |
} |
1074 |
if (k == XK_Escape) |
1075 |
break; |
1076 |
} |
1077 |
} |
1078 |
if (p) |
1079 |
CDestroyWidget (p->ident); |
1080 |
CDestroyWidget (i->ident); |
1081 |
CRestoreState (&s); |
1082 |
return r; |
1083 |
} |
1084 |
|
1085 |
static void message_dialog (char *title, char *message) |
1086 |
{ |
1087 |
CMessageDialog (0, 0, 0, 0, title, "%s", message); |
1088 |
} |
1089 |
|
1090 |
static void error_dialog (char *title, char *message) |
1091 |
{ |
1092 |
CErrorDialog (0, 0, 0, title, "%s", message); |
1093 |
} |
1094 |
|
1095 |
static long tab_width (void) |
1096 |
{ |
1097 |
return (long) TAB_SIZE; |
1098 |
} |
1099 |
|
1100 |
static long column_pixels (long i) |
1101 |
{ |
1102 |
return 0; |
1103 |
} |
1104 |
|
1105 |
static long buffer_size (void) |
1106 |
{ |
1107 |
return edit[current_edit]->editor->last_byte; |
1108 |
} |
1109 |
|
1110 |
static void key_press (void) |
1111 |
{ |
1112 |
edit_push_key_press (edit[current_edit]->editor); |
1113 |
} |
1114 |
|
1115 |
static void redraw_page (void) |
1116 |
{ |
1117 |
edit[current_edit]->editor->force |= REDRAW_PAGE; |
1118 |
edit_update_curs_row (edit[current_edit]->editor); |
1119 |
edit_update_curs_col (edit[current_edit]->editor); |
1120 |
} |
1121 |
|
1122 |
static int shell_output (char *title, char *s, char *name) |
1123 |
{ |
1124 |
return execute_background_display_output (title, s, name); |
1125 |
} |
1126 |
|
1127 |
|
1128 |
|
1129 |
PyObject *edit__get_editors (PyObject * self, PyObject * args) |
1130 |
{ |
1131 |
PyObject *ret; |
1132 |
int i; |
1133 |
char *p; |
1134 |
if (!PyArg_ParseTuple (args, ":get_editors")) |
1135 |
return NULL; |
1136 |
ret = PyTuple_New (last_edit); |
1137 |
for (i = 0; i < last_edit; i++) { |
1138 |
if (edit[i]->editor->filename && edit[i]->editor->dir) { |
1139 |
p = malloc (strlen (edit[i]->editor->filename) + strlen (edit[i]->editor->dir) + 1); |
1140 |
strcpy (p, edit[i]->editor->dir); |
1141 |
strcat (p, edit[i]->editor->filename); |
1142 |
PyTuple_SetItem (ret, i, PyString_FromString (p)); |
1143 |
free (p); |
1144 |
} else { |
1145 |
PyTuple_SetItem (ret, i, Py_None); |
1146 |
} |
1147 |
} |
1148 |
return ret; |
1149 |
} |
1150 |
|
1151 |
|
1152 |
|
1153 |
PyObject *edit__indent (PyObject * self, PyObject * args) |
1154 |
{ |
1155 |
int extra = 0; |
1156 |
if (!PyArg_ParseTuple (args, "|i:indent", &extra)) |
1157 |
return NULL; |
1158 |
edit_auto_indent (edit[current_edit]->editor, extra, 0); |
1159 |
Py_INCREF (Py_None); |
1160 |
return Py_None; |
1161 |
} |
1162 |
|
1163 |
|
1164 |
|
1165 |
PyObject *edit__file_type (PyObject * self, PyObject * args) |
1166 |
{ |
1167 |
PyObject *ret; |
1168 |
char *type = 0; |
1169 |
if (!PyArg_ParseTuple (args, "|s:file_type", &type)) |
1170 |
return NULL; |
1171 |
ret = PyString_FromString (edit[current_edit]->editor->syntax_type ? edit[current_edit]->editor->syntax_type : ""); |
1172 |
if (type) { |
1173 |
edit_load_syntax (edit[current_edit]->editor, 0, type); |
1174 |
edit[current_edit]->editor->explicit_syntax = 1; |
1175 |
edit[current_edit]->editor->force |= REDRAW_PAGE; |
1176 |
} |
1177 |
return ret; |
1178 |
} |
1179 |
|
1180 |
|
1181 |
|
1182 |
PyObject *edit__query_dialog (PyObject * self, PyObject * args) |
1183 |
{ |
1184 |
char *heading, *text; |
1185 |
char *b1 = 0, *b2 = 0, *b3 = 0, *b4 = 0, *b5 = 0, *b6 = 0, *b7 = 0, |
1186 |
*b8 = 0, *b9 = 0, *b10 = 0; |
1187 |
int i; |
1188 |
if (!PyArg_ParseTuple (args, "ss|ssssssssss:query_dialog", &heading, &text, &b1, &b2, &b3, &b4, &b5, &b6, &b7, &b8, &b9, &b10)) |
1189 |
return NULL; |
1190 |
i = CQueryDialog (0, 0, 0, heading, text, b1, b2, b3, b4, b5, b6, b7, b8, b9, b10, NULL); |
1191 |
return PyInt_FromLong (i); |
1192 |
} |
1193 |
|
1194 |
|
1195 |
|
1196 |
PyObject *edit__overwrite (PyObject * self, PyObject * args) |
1197 |
{ |
1198 |
PyObject *ret; |
1199 |
int i = -1; |
1200 |
if (!PyArg_ParseTuple (args, "|i:overwrite", &i)) |
1201 |
return NULL; |
1202 |
ret = PyInt_FromLong (edit[current_edit]->editor->overwrite); |
1203 |
if (i != -1) { |
1204 |
edit[current_edit]->editor->overwrite = (i != 0); |
1205 |
CSetCursorColor (edit[current_edit]->editor->overwrite ? color_palette (24) : color_palette (19)); |
1206 |
} |
1207 |
return ret; |
1208 |
} |
1209 |
|
1210 |
|
1211 |
|
1212 |
PyObject *edit__generic_dialog (PyObject * self, PyObject * args) |
1213 |
{ |
1214 |
PyObject *a1 = 0, *a2 = 0, *a3 = 0, *a4 = 0, *a5 = 0, *a6 = 0, *a7 = 0, *result = 0; |
1215 |
|
1216 |
char **inputs; |
1217 |
char **input_labels; |
1218 |
char **input_names; |
1219 |
char **input_tool_hints; |
1220 |
char ***inputs_result; |
1221 |
|
1222 |
char **check_labels; |
1223 |
char **check_tool_hints; |
1224 |
static int *check_values; |
1225 |
int **check_values_result; |
1226 |
int options = 0; |
1227 |
|
1228 |
char *heading = 0; |
1229 |
int r, n_inputs, n_checks, width = -1, i; |
1230 |
|
1231 |
if (!PyArg_ParseTuple (args, "sO!O!O!O!O!O!O!|ii:gtk_dialog_cauldron", |
1232 |
&heading, |
1233 |
&PyTuple_Type, &a1, |
1234 |
&PyTuple_Type, &a2, |
1235 |
&PyTuple_Type, &a3, |
1236 |
&PyTuple_Type, &a4, |
1237 |
&PyTuple_Type, &a5, |
1238 |
&PyTuple_Type, &a6, |
1239 |
&PyTuple_Type, &a7, |
1240 |
&width, |
1241 |
&options |
1242 |
)) |
1243 |
return NULL; |
1244 |
|
1245 |
n_inputs = min (PyTuple_Size (a1), min (PyTuple_Size (a2), PyTuple_Size (a3))); |
1246 |
n_checks = min (PyTuple_Size (a5), PyTuple_Size (a6)); |
1247 |
|
1248 |
inputs = malloc ((n_inputs + 1) * sizeof (char *)); |
1249 |
input_labels = malloc ((n_inputs + 1) * sizeof (char *)); |
1250 |
input_names = malloc ((n_inputs + 1) * sizeof (char *)); |
1251 |
input_tool_hints = malloc ((n_inputs + 1) * sizeof (char *)); |
1252 |
inputs_result = malloc ((n_inputs + 1) * sizeof (char **)); |
1253 |
|
1254 |
check_labels = malloc ((n_checks + 1) * sizeof (char *)); |
1255 |
check_tool_hints = malloc ((n_checks + 1) * sizeof (char *)); |
1256 |
check_values = malloc ((n_checks + 1) * sizeof (int)); |
1257 |
check_values_result = malloc ((n_checks + 1) * sizeof (int *)); |
1258 |
|
1259 |
for (i = 0; i < n_inputs; i++) { |
1260 |
PyObject *item; |
1261 |
item = PyTuple_GetItem (a1, i); |
1262 |
inputs[i] = PyString_Check (item) ? PyString_AsString (item) : ""; |
1263 |
item = PyTuple_GetItem (a2, i); |
1264 |
input_labels[i] = PyString_Check (item) ? PyString_AsString (item) : ""; |
1265 |
item = PyTuple_GetItem (a3, i); |
1266 |
input_names[i] = PyString_Check (item) ? PyString_AsString (item) : ""; |
1267 |
input_tool_hints[i] = 0; |
1268 |
if (i < PyTuple_Size (a4)) { |
1269 |
item = PyTuple_GetItem (a4, i); |
1270 |
if (PyString_Check (item)) |
1271 |
input_tool_hints[i] = PyString_AsString (item); |
1272 |
} |
1273 |
inputs_result[i] = &inputs[i]; |
1274 |
} |
1275 |
inputs_result[i] = 0; |
1276 |
|
1277 |
for (i = 0; i < n_checks; i++) { |
1278 |
PyObject *item; |
1279 |
item = PyTuple_GetItem (a5, i); |
1280 |
check_values[i] = PyInt_Check (item) ? PyInt_AsLong (item) : 0; |
1281 |
item = PyTuple_GetItem (a6, i); |
1282 |
check_labels[i] = PyString_Check (item) ? PyString_AsString (item) : ""; |
1283 |
check_tool_hints[i] = 0; |
1284 |
if (i < PyTuple_Size (a7)) { |
1285 |
item = PyTuple_GetItem (a7, i); |
1286 |
if (PyString_Check (item)) |
1287 |
check_tool_hints[i] = PyString_AsString (item); |
1288 |
} |
1289 |
check_values_result[i] = &check_values[i]; |
1290 |
} |
1291 |
check_values_result[i] = 0; |
1292 |
|
1293 |
r = CInputsWithOptions (0, 0, 0, heading, inputs_result, input_labels, input_names, input_tool_hints, check_values_result, check_labels, check_tool_hints, options, max (width > 0 ? width : 60, 20)); |
1294 |
if (!r) { |
1295 |
result = PyTuple_New (2); |
1296 |
PyTuple_SetItem (result, 0, PyTuple_New (n_inputs)); |
1297 |
for (i = 0; i < n_inputs; i++) |
1298 |
PyTuple_SetItem (PyTuple_GetItem (result, 0), i, PyString_FromString (inputs[i])); |
1299 |
PyTuple_SetItem (result, 1, PyTuple_New (n_checks)); |
1300 |
for (i = 0; i < n_checks; i++) |
1301 |
PyTuple_SetItem (PyTuple_GetItem (result, 1), i, PyInt_FromLong ((long) check_values[i])); |
1302 |
} else { |
1303 |
result = Py_None; |
1304 |
Py_INCREF (result); |
1305 |
} |
1306 |
|
1307 |
free (inputs); |
1308 |
free (input_labels); |
1309 |
free (input_names); |
1310 |
free (input_tool_hints); |
1311 |
free (inputs_result); |
1312 |
free (check_labels); |
1313 |
free (check_tool_hints); |
1314 |
free (check_values); |
1315 |
free (check_values_result); |
1316 |
|
1317 |
return result; |
1318 |
} |
1319 |
|
1320 |
|
1321 |
|
1322 |
extern int column_highlighting; |
1323 |
|
1324 |
PyObject *edit__markers (PyObject * self, PyObject * args) |
1325 |
{ |
1326 |
PyObject *ret; |
1327 |
long m1 = -1000000000, m2 = -1000000000; |
1328 |
int c1 = -1000000000, c2 = -1000000000; |
1329 |
int column = -1; |
1330 |
long r1, r2; |
1331 |
if (!PyArg_ParseTuple (args, "|lliii:markers", &m1, &m2, &column, &c1, &c2)) |
1332 |
return NULL; |
1333 |
if (eval_marks (edit[current_edit]->editor, &r1, &r2)) { |
1334 |
Py_INCREF (Py_None); |
1335 |
ret = Py_None; |
1336 |
} else { |
1337 |
ret = PyTuple_New (5); |
1338 |
PyTuple_SetItem (ret, 0, PyInt_FromLong (r1)); |
1339 |
PyTuple_SetItem (ret, 1, PyInt_FromLong (r2)); |
1340 |
PyTuple_SetItem (ret, 3, PyInt_FromLong (column_highlighting)); |
1341 |
PyTuple_SetItem (ret, 4, PyInt_FromLong (min (edit[current_edit]->editor->column1, edit[current_edit]->editor->column2))); |
1342 |
PyTuple_SetItem (ret, 5, PyInt_FromLong (max (edit[current_edit]->editor->column1, edit[current_edit]->editor->column2))); |
1343 |
} |
1344 |
if (m1 != -1000000000) { |
1345 |
edit[current_edit]->editor->mark1 = m1; |
1346 |
edit[current_edit]->editor->mark2 = m2 < 0 ? -1 : m2; |
1347 |
if (column == 0 || column == -1000000000 || c1 == -1000000000 || c2 == -1000000000) { |
1348 |
if (column_highlighting) |
1349 |
edit_push_action (edit[current_edit]->editor, COLUMN_ON); |
1350 |
edit_push_markers (edit[current_edit]->editor); |
1351 |
column_highlighting = 0; |
1352 |
edit[current_edit]->editor->column1 = edit[current_edit]->editor->column2 = 0; |
1353 |
} else { |
1354 |
if (!column_highlighting) |
1355 |
edit_push_action (edit[current_edit]->editor, COLUMN_OFF); |
1356 |
edit_push_markers (edit[current_edit]->editor); |
1357 |
column_highlighting = 1; |
1358 |
edit[current_edit]->editor->column1 = c1; |
1359 |
edit[current_edit]->editor->column2 = c2 < 0 ? -1 : c2; |
1360 |
} |
1361 |
} |
1362 |
return ret; |
1363 |
} |
1364 |
|
1365 |
|
1366 |
|
1367 |
PyObject *edit__get_key (PyObject * self, PyObject * args) |
1368 |
{ |
1369 |
PyObject *ret; |
1370 |
XEvent xevent; |
1371 |
CState s; |
1372 |
KeySym k = NoSymbol; |
1373 |
char *t; |
1374 |
if (!PyArg_ParseTuple (args, ":get_key")) |
1375 |
return NULL; |
1376 |
CBackupState (&s); |
1377 |
CDisable ("*"); |
1378 |
for (;;) { |
1379 |
CNextEvent (&xevent, 0); |
1380 |
if (xevent.type == KeyPress) { |
1381 |
k = CKeySym (&xevent); |
1382 |
if (k && !mod_type_key (k)) |
1383 |
break; |
1384 |
} |
1385 |
} |
1386 |
CRestoreState (&s); |
1387 |
ret = PyTuple_New (2); |
1388 |
t = XKeysymToString (k); |
1389 |
if (t) |
1390 |
PyTuple_SetItem (ret, 0, PyString_FromString (t)); |
1391 |
else |
1392 |
PyTuple_SetItem (ret, 0, Py_None); |
1393 |
PyTuple_SetItem (ret, 1, PyInt_FromLong (xevent.xkey.state)); |
1394 |
return ret; |
1395 |
} |
1396 |
|
1397 |
|
1398 |
|
1399 |
PyObject *edit__key (PyObject * self, PyObject * args) |
1400 |
{ |
1401 |
int i, found = 0; |
1402 |
int modifiers; |
1403 |
char *key = 0; |
1404 |
KeySym keysym; |
1405 |
char *statement = 0; |
1406 |
if (!PyArg_ParseTuple (args, "si|s:key", &key, &modifiers, &statement)) |
1407 |
return NULL; |
1408 |
if (!strncmp (key, "XK_", 3)) |
1409 |
key += 3; |
1410 |
keysym = XStringToKeysym (key); |
1411 |
if (keysym == NoSymbol) { |
1412 |
char e[128]; |
1413 |
sprintf (e, _ ("No such key \"%s\".\n\tCheck the header file keysymdef.h on your\n\tsystem for a list of valid keys."), key); |
1414 |
PyErr_SetString (PyExc_ValueError, e); |
1415 |
return NULL; |
1416 |
} |
1417 |
/* is the key already bound? */ |
1418 |
for (i = 0; i < last_binding; i++) |
1419 |
if (bindings[i].modifiers == modifiers && bindings[i].keysym == keysym) { |
1420 |
found = 1; |
1421 |
if (bindings[i].statement) |
1422 |
free (bindings[i].statement); |
1423 |
memset (&bindings[i], 0, sizeof (bindings[0])); |
1424 |
if (i == last_binding - 1) |
1425 |
last_binding--; |
1426 |
break; |
1427 |
} |
1428 |
/* check for an empty space in the array */ |
1429 |
if (!found && statement) |
1430 |
for (i = 0; i < last_binding; i++) |
1431 |
if (!bindings[i].statement) { |
1432 |
found = 1; |
1433 |
break; |
1434 |
} |
1435 |
/* extend the array */ |
1436 |
if (!found && statement) { |
1437 |
if (last_binding >= MAX_GLOBAL_BINDINGS) { |
1438 |
PyErr_SetString (PyExc_ValueError, _ ("maximum number of key bindings reached")); |
1439 |
return NULL; |
1440 |
} |
1441 |
i = last_binding; |
1442 |
} |
1443 |
if (statement) { |
1444 |
bindings[i].statement = (char *) strdup (statement); |
1445 |
bindings[i].modifiers = modifiers; |
1446 |
bindings[i].keysym = keysym; |
1447 |
if (i == last_binding) |
1448 |
last_binding++; |
1449 |
} |
1450 |
Py_INCREF (Py_None); |
1451 |
return Py_None; |
1452 |
} |
1453 |
|
1454 |
|
1455 |
|
1456 |
PyObject *edit__bind (PyObject * self, PyObject * args) |
1457 |
{ |
1458 |
char e[128]; |
1459 |
int modifiers; |
1460 |
char *key1 = 0, *key2 = 0; |
1461 |
KeySym keysym1, keysym2; |
1462 |
PyObject *function = 0; |
1463 |
if (!PyArg_ParseTuple (args, "ssi|O!:bind", &key1, &key2, &modifiers, &PyFunction_Type, &function)) |
1464 |
return NULL; |
1465 |
if (!strncmp (key1, "XK_", 3)) |
1466 |
key1 += 3; |
1467 |
if (!strncmp (key2, "XK_", 3)) |
1468 |
key2 += 3; |
1469 |
keysym1 = XStringToKeysym (key1); |
1470 |
keysym2 = XStringToKeysym (key2); |
1471 |
if (keysym1 == NoSymbol) { |
1472 |
sprintf (e, _ ("No such key \"%s\".\n\tCheck the header file keysymdef.h on your\n\tsystem for a list of valid keys."), key1); |
1473 |
PyErr_SetString (PyExc_ValueError, e); |
1474 |
return NULL; |
1475 |
} |
1476 |
if (keysym2 == NoSymbol) { |
1477 |
sprintf (e, _ ("No such key \"%s\".\n\tCheck the header file keysymdef.h on your\n\tsystem for a list of valid keys."), key2); |
1478 |
PyErr_SetString (PyExc_ValueError, e); |
1479 |
return NULL; |
1480 |
} |
1481 |
if (add_bindings (function, keysym1, keysym2, modifiers)) { |
1482 |
sprintf (e, _ ("Reached max number of bindings. Some key in range \"%s\" - \"%s\" not bound."), key1, key2); |
1483 |
PyErr_SetString (PyExc_ValueError, e); |
1484 |
return NULL; |
1485 |
} |
1486 |
Py_INCREF (Py_None); |
1487 |
return Py_None; |
1488 |
} |
1489 |
|
1490 |
|
1491 |
|
1492 |
static void coolpython_constants (PyObject * d) |
1493 |
{ |
1494 |
struct key_list *k; |
1495 |
for (k = get_command_list (); *k->key_name; k++) |
1496 |
if (k->command) |
1497 |
PyDict_SetItemString (d, k->key_name, PyInt_FromLong ((long) k->command)); |
1498 |
PyDict_SetItemString (d, "ShiftMask", PyInt_FromLong ((long) ShiftMask)); |
1499 |
PyDict_SetItemString (d, "LockMask", PyInt_FromLong ((long) LockMask)); |
1500 |
PyDict_SetItemString (d, "ControlMask", PyInt_FromLong ((long) ControlMask)); |
1501 |
PyDict_SetItemString (d, "AltMask", PyInt_FromLong ((long) MyAltMask)); |
1502 |
PyDict_SetItemString (d, "Mod1Mask", PyInt_FromLong ((long) Mod1Mask)); |
1503 |
PyDict_SetItemString (d, "Mod2Mask", PyInt_FromLong ((long) Mod2Mask)); |
1504 |
PyDict_SetItemString (d, "Mod3Mask", PyInt_FromLong ((long) Mod3Mask)); |
1505 |
PyDict_SetItemString (d, "Mod4Mask", PyInt_FromLong ((long) Mod4Mask)); |
1506 |
PyDict_SetItemString (d, "Mod5Mask", PyInt_FromLong ((long) Mod5Mask)); |
1507 |
PyDict_SetItemString (d, "LIBDIR", PyString_FromString (LIBDIR)); |
1508 |
|
1509 |
PyDict_SetItemString (d, "Mod5Mask", PyInt_FromLong ((long) Mod5Mask)); |
1510 |
|
1511 |
PyDict_SetItemString (d, "INPUTS_WITH_OPTIONS_BROWSE_LOAD_1", PyInt_FromLong ((long) INPUTS_WITH_OPTIONS_BROWSE_LOAD_1)); |
1512 |
PyDict_SetItemString (d, "INPUTS_WITH_OPTIONS_BROWSE_LOAD_2", PyInt_FromLong ((long) INPUTS_WITH_OPTIONS_BROWSE_LOAD_2)); |
1513 |
PyDict_SetItemString (d, "INPUTS_WITH_OPTIONS_BROWSE_LOAD_3", PyInt_FromLong ((long) INPUTS_WITH_OPTIONS_BROWSE_LOAD_3)); |
1514 |
PyDict_SetItemString (d, "INPUTS_WITH_OPTIONS_BROWSE_LOAD_4", PyInt_FromLong ((long) INPUTS_WITH_OPTIONS_BROWSE_LOAD_4)); |
1515 |
PyDict_SetItemString (d, "INPUTS_WITH_OPTIONS_BROWSE_LOAD_5", PyInt_FromLong ((long) INPUTS_WITH_OPTIONS_BROWSE_LOAD_5)); |
1516 |
PyDict_SetItemString (d, "INPUTS_WITH_OPTIONS_BROWSE_LOAD_6", PyInt_FromLong ((long) INPUTS_WITH_OPTIONS_BROWSE_LOAD_6)); |
1517 |
|
1518 |
PyDict_SetItemString (d, "INPUTS_WITH_OPTIONS_BROWSE_SAVE_1", PyInt_FromLong ((long) INPUTS_WITH_OPTIONS_BROWSE_SAVE_1)); |
1519 |
PyDict_SetItemString (d, "INPUTS_WITH_OPTIONS_BROWSE_SAVE_2", PyInt_FromLong ((long) INPUTS_WITH_OPTIONS_BROWSE_SAVE_2)); |
1520 |
PyDict_SetItemString (d, "INPUTS_WITH_OPTIONS_BROWSE_SAVE_3", PyInt_FromLong ((long) INPUTS_WITH_OPTIONS_BROWSE_SAVE_3)); |
1521 |
PyDict_SetItemString (d, "INPUTS_WITH_OPTIONS_BROWSE_SAVE_4", PyInt_FromLong ((long) INPUTS_WITH_OPTIONS_BROWSE_SAVE_4)); |
1522 |
PyDict_SetItemString (d, "INPUTS_WITH_OPTIONS_BROWSE_SAVE_5", PyInt_FromLong ((long) INPUTS_WITH_OPTIONS_BROWSE_SAVE_5)); |
1523 |
PyDict_SetItemString (d, "INPUTS_WITH_OPTIONS_BROWSE_SAVE_6", PyInt_FromLong ((long) INPUTS_WITH_OPTIONS_BROWSE_SAVE_6)); |
1524 |
|
1525 |
PyDict_SetItemString (d, "INPUTS_WITH_OPTIONS_BROWSE_DIR_1", PyInt_FromLong ((long) INPUTS_WITH_OPTIONS_BROWSE_DIR_1)); |
1526 |
PyDict_SetItemString (d, "INPUTS_WITH_OPTIONS_BROWSE_DIR_2", PyInt_FromLong ((long) INPUTS_WITH_OPTIONS_BROWSE_DIR_2)); |
1527 |
PyDict_SetItemString (d, "INPUTS_WITH_OPTIONS_BROWSE_DIR_3", PyInt_FromLong ((long) INPUTS_WITH_OPTIONS_BROWSE_DIR_3)); |
1528 |
PyDict_SetItemString (d, "INPUTS_WITH_OPTIONS_BROWSE_DIR_4", PyInt_FromLong ((long) INPUTS_WITH_OPTIONS_BROWSE_DIR_4)); |
1529 |
PyDict_SetItemString (d, "INPUTS_WITH_OPTIONS_BROWSE_DIR_5", PyInt_FromLong ((long) INPUTS_WITH_OPTIONS_BROWSE_DIR_5)); |
1530 |
PyDict_SetItemString (d, "INPUTS_WITH_OPTIONS_BROWSE_DIR_6", PyInt_FromLong ((long) INPUTS_WITH_OPTIONS_BROWSE_DIR_6)); |
1531 |
} |
1532 |
|
1533 |
void coolpython_run_file (char *filename) |
1534 |
{ |
1535 |
FILE *f; |
1536 |
PyObject *e; |
1537 |
f = fopen (filename, "r"); |
1538 |
if (!f) { |
1539 |
CErrorDialog (0, 0, 0, _("Python Error"), get_sys_error (_(" Error trying to open %s ")), filename); |
1540 |
return; |
1541 |
} |
1542 |
e = PyRun_File (f, filename, Py_file_input, name_space, name_space); |
1543 |
fclose (f); |
1544 |
if (!e) { |
1545 |
coolpython_display_error (1); |
1546 |
return; |
1547 |
} |
1548 |
Py_DECREF (e); |
1549 |
} |
1550 |
|
1551 |
static int coolpython_argc = 0; |
1552 |
static char **coolpython_argv = 0; |
1553 |
|
1554 |
void coolpython_shut (void) |
1555 |
{ |
1556 |
int i; |
1557 |
#if 0 |
1558 |
Py_Finalize (); |
1559 |
#endif |
1560 |
for (i = 0; i < last_binding; i++) |
1561 |
if (bindings[i].statement) { |
1562 |
free (bindings[i].statement); |
1563 |
memset (&bindings[i], 0, sizeof (bindings[0])); |
1564 |
} |
1565 |
last_binding = 0; |
1566 |
} |
1567 |
|
1568 |
void coolpython_init (int argc, char **argv) |
1569 |
{ |
1570 |
PyObject *e; |
1571 |
char s[1024]; |
1572 |
int fd = -1; |
1573 |
Py_Initialize (); |
1574 |
if (argv) { |
1575 |
PySys_SetArgv (coolpython_argc = argc, coolpython_argv = argv); |
1576 |
} else { |
1577 |
if (coolpython_argv) |
1578 |
PySys_SetArgv (coolpython_argc, coolpython_argv); |
1579 |
} |
1580 |
#if 0 |
1581 |
Py_XDECREF (name_space); |
1582 |
#endif |
1583 |
name_space = PyModule_GetDict (PyImport_AddModule ("__main__")); |
1584 |
initcooledit (); |
1585 |
sprintf (s, "from cooledit import *\n\ |
1586 |
import sys\n\ |
1587 |
sys.path.append('%s')\n\ |
1588 |
sys.path.append('%s%s')\n\ |
1589 |
", LIBDIR, home_dir, EDIT_DIR); |
1590 |
e = PyRun_String (s, Py_file_input, name_space, name_space); |
1591 |
if (!e) { |
1592 |
PyErr_Print (); |
1593 |
CErrorDialog (0, 0, 0, _ ("Python Error"), _ (" Error initialising Python ")); |
1594 |
return; |
1595 |
} |
1596 |
Py_DECREF (e); |
1597 |
coolpython_constants (name_space); |
1598 |
sprintf (s, "%s/%s", LIBDIR, GLOBAL_STARTUP_FILE); |
1599 |
coolpython_run_file (s); |
1600 |
sprintf (s, "%s%s/%s", home_dir, EDIT_DIR, GLOBAL_STARTUP_FILE); |
1601 |
if ((fd = open (s, O_RDONLY)) >= 0) |
1602 |
coolpython_run_file (s); |
1603 |
if (fd >= 0) |
1604 |
close (fd); |
1605 |
} |
1606 |
|
1607 |
int coolpython_run_function (PyObject * function, char *key_name, int modifiers) |
1608 |
{ |
1609 |
PyObject *p, *ret; |
1610 |
p = PyTuple_New (2); |
1611 |
PyTuple_SetItem (p, 0, PyString_FromString (key_name)); |
1612 |
PyTuple_SetItem (p, 1, PyInt_FromLong ((long) modifiers)); |
1613 |
ret = PyObject_CallObject (function, p); |
1614 |
edit[current_edit]->editor->prev_col = edit_get_col (edit[current_edit]->editor); |
1615 |
Py_DECREF (p); |
1616 |
if (ret == NULL) { |
1617 |
coolpython_display_error (1); |
1618 |
return -1; |
1619 |
} |
1620 |
Py_DECREF (ret); |
1621 |
PyErr_Clear (); |
1622 |
return 0; |
1623 |
} |
1624 |
|
1625 |
int coolpython_run_statement (char *statement) |
1626 |
{ |
1627 |
PyObject *v; |
1628 |
v = PyRun_String (statement, Py_file_input, name_space, name_space); |
1629 |
if (v == NULL) { |
1630 |
coolpython_display_error (1); |
1631 |
return -1; |
1632 |
} |
1633 |
edit[current_edit]->editor->prev_col = edit_get_col (edit[current_edit]->editor); |
1634 |
Py_DECREF (v); |
1635 |
PyErr_Clear (); |
1636 |
return 0; |
1637 |
} |
1638 |
|
1639 |
static void type_change (int i) |
1640 |
{ |
1641 |
char s[256]; |
1642 |
sprintf (s, "type_change ('%s')", edit[i]->editor->syntax_type ? edit[i]->editor->syntax_type : ""); |
1643 |
free_current_bindings (edit[i]->user); |
1644 |
edit[i]->user = 0; |
1645 |
coolpython_run_statement (s); |
1646 |
} |
1647 |
|
1648 |
void coolpython_typechange (Window win) |
1649 |
{ |
1650 |
int temp_current_edit; |
1651 |
temp_current_edit = current_edit; |
1652 |
for (current_edit = 0; current_edit < last_edit; current_edit++) |
1653 |
if (win == edit[current_edit]->winid) { |
1654 |
type_change (current_edit); |
1655 |
break; |
1656 |
} |
1657 |
current_edit = temp_current_edit; |
1658 |
} |
1659 |
|
1660 |
void menu_python_reload (unsigned long ignored) |
1661 |
{ |
1662 |
int temp_current_edit; |
1663 |
coolpython_shut (); |
1664 |
coolpython_init (0, 0); |
1665 |
temp_current_edit = current_edit; |
1666 |
for (current_edit = 0; current_edit < last_edit; current_edit++) |
1667 |
type_change (current_edit); |
1668 |
current_edit = temp_current_edit; |
1669 |
} |
1670 |
|
1671 |
/* this is similar to the function edit__menu - if you change here, change there as well */ |
1672 |
static PyObject *edit__replace_insert_menu (PyObject * self, PyObject * args, int insert) |
1673 |
{ |
1674 |
char *menu_name, *old_item = 0, *new_item = 0, *statement = 0; |
1675 |
char ident[33]; |
1676 |
CWidget *w; |
1677 |
if (!PyArg_ParseTuple (args, "ssss:replace_menu", &menu_name, &old_item, &new_item, &statement)) |
1678 |
return NULL; |
1679 |
if (!strcasecmp (menu_name, "util")) { |
1680 |
strcpy (ident, edit[current_edit]->ident); |
1681 |
strcat (ident, ".util"); |
1682 |
} else if (!strcasecmp (menu_name, "command")) { |
1683 |
strcpy (ident, "menu.commandmenu"); |
1684 |
} else if (!strcasecmp (menu_name, "readme")) { |
1685 |
strcpy (ident, "menu.readme"); |
1686 |
} else if (!strcasecmp (menu_name, "search")) { |
1687 |
strcpy (ident, "menu.searchmenu"); |
1688 |
} else if (!strcasecmp (menu_name, "edit")) { |
1689 |
strcpy (ident, "menu.editmenu"); |
1690 |
} else if (!strcasecmp (menu_name, "file")) { |
1691 |
strcpy (ident, "menu.filemenu"); |
1692 |
} else { |
1693 |
char e[160]; |
1694 |
sprintf (e, "%s \"%s\". %s\n\"Util\", \"File\", \"Edit\", \"Search\", \"Command\", \"Options\" or \"Readme\".", _ ("No such menu:"), _ ("Possible menus are:"), menu_name); |
1695 |
PyErr_SetString (PyExc_ValueError, e); |
1696 |
return NULL; |
1697 |
} |
1698 |
{ |
1699 |
char *p; |
1700 |
int i; |
1701 |
w = CIdent (ident); |
1702 |
if (w) { |
1703 |
if (insert) |
1704 |
CInsertMenuItem (ident, old_item, new_item, '~', (callfn) coolpython_run_statement, 0); |
1705 |
else |
1706 |
CReplaceMenuItem (ident, old_item, new_item, '~', (callfn) coolpython_run_statement, 0); |
1707 |
i = CHasMenuItem (ident, new_item); |
1708 |
if (i < 0) { |
1709 |
char e[160]; |
1710 |
sprintf (e, "%s: %s", _ ("Menu replace failed: Check that there is such a menu item"), old_item); |
1711 |
PyErr_SetString (PyExc_ValueError, e); |
1712 |
return NULL; |
1713 |
} |
1714 |
/* hack: we want statement to free with destruction of the menu item */ |
1715 |
p = w->menu[i].text; |
1716 |
w->menu[i].text = malloc (strlen (p) + strlen (statement) + 2); |
1717 |
strcpy (w->menu[i].text, p); |
1718 |
strcpy (w->menu[i].text + strlen (p) + 1, statement); |
1719 |
w->menu[i].data = (unsigned long) (w->menu[i].text + strlen (p) + 1); |
1720 |
free (p); |
1721 |
} |
1722 |
} |
1723 |
Py_INCREF (Py_None); |
1724 |
return Py_None; |
1725 |
} |
1726 |
|
1727 |
PyObject *edit__insert_menu (PyObject * self, PyObject * args) |
1728 |
{ |
1729 |
return edit__replace_insert_menu (self, args, 1); |
1730 |
} |
1731 |
|
1732 |
PyObject *edit__replace_menu (PyObject * self, PyObject * args) |
1733 |
{ |
1734 |
return edit__replace_insert_menu (self, args, 0); |
1735 |
} |
1736 |
|
1737 |
/* this is similar to the function edit__replace_menu - if you change here, change there as well */ |
1738 |
PyObject *edit__menu (PyObject * self, PyObject * args) |
1739 |
{ |
1740 |
char *menu_name, *menu_item = 0, *statement = 0; |
1741 |
char ident[33]; |
1742 |
CWidget *w; |
1743 |
if (!PyArg_ParseTuple (args, "s|ss:menu", &menu_name, &menu_item, &statement)) |
1744 |
return NULL; |
1745 |
if (!strcasecmp (menu_name, "util")) { |
1746 |
strcpy (ident, edit[current_edit]->ident); |
1747 |
strcat (ident, ".util"); |
1748 |
} else if (!strcasecmp (menu_name, "command")) { |
1749 |
strcpy (ident, "menu.commandmenu"); |
1750 |
} else if (!strcasecmp (menu_name, "readme")) { |
1751 |
strcpy (ident, "menu.readme"); |
1752 |
} else if (!strcasecmp (menu_name, "search")) { |
1753 |
strcpy (ident, "menu.searchmenu"); |
1754 |
} else if (!strcasecmp (menu_name, "edit")) { |
1755 |
strcpy (ident, "menu.editmenu"); |
1756 |
} else if (!strcasecmp (menu_name, "file")) { |
1757 |
strcpy (ident, "menu.filemenu"); |
1758 |
} else { |
1759 |
char e[160]; |
1760 |
sprintf (e, "%s \"%s\". %s\n\"Util\", \"File\", \"Edit\", \"Search\", \"Command\", \"Options\" or \"Readme\".", _ ("No such menu:"), _ ("Possible menus are:"), menu_name); |
1761 |
PyErr_SetString (PyExc_ValueError, e); |
1762 |
return NULL; |
1763 |
} |
1764 |
if (!menu_item) { |
1765 |
w = CIdent (ident); |
1766 |
if (w) { |
1767 |
int i; |
1768 |
for (i = w->numlines - 1; i >= 0; i--) |
1769 |
CRemoveMenuItemNumber (ident, i); |
1770 |
} |
1771 |
} else if (!statement) { |
1772 |
CRemoveMenuItem (ident, menu_item); |
1773 |
} else { |
1774 |
char *p; |
1775 |
int i; |
1776 |
w = CIdent (ident); |
1777 |
if (w) { |
1778 |
CAddMenuItem (ident, menu_item, '~', (callfn) coolpython_run_statement, 0); |
1779 |
i = w->numlines - 1; |
1780 |
/* hack: we want statement to free with destruction of the menu item */ |
1781 |
p = w->menu[i].text; |
1782 |
w->menu[i].text = malloc (strlen (p) + strlen (statement) + 2); |
1783 |
strcpy (w->menu[i].text, p); |
1784 |
strcpy (w->menu[i].text + strlen (p) + 1, statement); |
1785 |
w->menu[i].data = (unsigned long) (w->menu[i].text + strlen (p) + 1); |
1786 |
free (p); |
1787 |
} |
1788 |
} |
1789 |
Py_INCREF (Py_None); |
1790 |
return Py_None; |
1791 |
} |
1792 |
|
1793 |
PyObject *edit__gettext (PyObject * self, PyObject * args) |
1794 |
{ |
1795 |
char *s; |
1796 |
if (!PyArg_ParseTuple (args, "s:gettext", &s)) |
1797 |
return NULL; |
1798 |
return PyString_FromString ((char *) _ ((char *) s)); |
1799 |
} |
1800 |
|
1801 |
|
1802 |
|
1803 |
void coolpython_command (WEdit * edit, int i) |
1804 |
{ |
1805 |
int k; |
1806 |
struct python_binding *b; |
1807 |
if (i >= GLOBAL_BINDING (0) && i < GLOBAL_BINDING (MAX_GLOBAL_BINDINGS)) { |
1808 |
/* lcc breaks here */ |
1809 |
int j; |
1810 |
j = BINDING_GLOBAL (i); |
1811 |
i = j; |
1812 |
if (i >= 0 || i < last_binding) |
1813 |
coolpython_run_statement (bindings[i].statement); |
1814 |
} else if (i >= CURRENT_BINDING (0) && i < CURRENT_BINDING (MAX_CURRENT_BINDINGS)) { |
1815 |
i = BINDING_CURRENT (i); |
1816 |
for (k = 0, b = (struct python_binding *) edit->widget->user; b && k <= i; b = b->next, k++) { |
1817 |
if (i == k) { |
1818 |
if (b->statement) |
1819 |
coolpython_run_statement (b->statement); |
1820 |
else |
1821 |
coolpython_run_function (b->function, XKeysymToString (b->keysym), b->modifiers); |
1822 |
} |
1823 |
} |
1824 |
} |
1825 |
} |
1826 |
|
1827 |
static void coolpython_display_error (int set_sys_last_vars) |
1828 |
{ |
1829 |
PyObject *e; |
1830 |
char t[1024]; |
1831 |
PyObject *exception, *v, *tb, *d; |
1832 |
PyErr_Fetch (&exception, &v, &tb); |
1833 |
PyErr_NormalizeException (&exception, &v, &tb); |
1834 |
if (exception == NULL) |
1835 |
return; |
1836 |
if (set_sys_last_vars) { |
1837 |
PySys_SetObject ("last_type", exception); |
1838 |
PySys_SetObject ("last_value", v); |
1839 |
PySys_SetObject ("last_traceback", tb); |
1840 |
} |
1841 |
d = PyModule_GetDict (PyImport_AddModule ("__main__")); |
1842 |
PyDict_SetItemString (d, "exc_type", exception); |
1843 |
PyDict_SetItemString (d, "exc_value", v); |
1844 |
PyDict_SetItemString (d, "exc_traceback", tb ? tb : Py_None); |
1845 |
sprintf (t, "\n\ |
1846 |
import cooledit\n\ |
1847 |
import traceback\n\ |
1848 |
s = \"\"\n\ |
1849 |
for filename, line, function, text in traceback.extract_tb(exc_traceback):\n\ |
1850 |
s = s + ' File \"%%s\", line %%d, in %%s\\n %%s' %% (filename, line, function, text)\n\ |
1851 |
if s[-1] != '\\n':\n\ |
1852 |
s = s + '\\n'\n\ |
1853 |
for l in traceback.format_exception_only(exc_type, exc_value):\n\ |
1854 |
s = s + ' ' + l\n\ |
1855 |
if s[-1] != '\\n':\n\ |
1856 |
s = s + '\\n'\n\ |
1857 |
cooledit.error_dialog (\"%s\", s)\n\ |
1858 |
", _("Python Interpretor Error")); |
1859 |
e = PyRun_String (t, Py_file_input, d, d); |
1860 |
if (!e) { |
1861 |
PyErr_Print(); |
1862 |
CErrorDialog (0, 0, 0, _("Python Error"), _(" Error trying to display traceback. \n Message dumped to stderr ")); |
1863 |
} |
1864 |
Py_XDECREF (e); |
1865 |
Py_XDECREF (d); |
1866 |
Py_XDECREF (exception); |
1867 |
Py_XDECREF (v); |
1868 |
Py_XDECREF (tb); |
1869 |
} |
1870 |
|
1871 |
static PyObject *_wrap_buffer_size(PyObject *self, PyObject *args) { |
1872 |
PyObject * _resultobj; |
1873 |
long _result; |
1874 |
|
1875 |
self = self; |
1876 |
if(!PyArg_ParseTuple(args,":buffer_size")) |
1877 |
return NULL; |
1878 |
_result = (long )buffer_size(); |
1879 |
_resultobj = Py_BuildValue("l",_result); |
1880 |
return _resultobj; |
1881 |
} |
1882 |
|
1883 |
static PyObject *_wrap_move(PyObject *self, PyObject *args) { |
1884 |
PyObject * _resultobj; |
1885 |
long _arg0; |
1886 |
|
1887 |
self = self; |
1888 |
if(!PyArg_ParseTuple(args,"l:move",&_arg0)) |
1889 |
return NULL; |
1890 |
move(_arg0); |
1891 |
Py_INCREF(Py_None); |
1892 |
_resultobj = Py_None; |
1893 |
return _resultobj; |
1894 |
} |
1895 |
|
1896 |
static PyObject *_wrap_move_lines(PyObject *self, PyObject *args) { |
1897 |
PyObject * _resultobj; |
1898 |
long _arg0; |
1899 |
|
1900 |
self = self; |
1901 |
if(!PyArg_ParseTuple(args,"l:move_lines",&_arg0)) |
1902 |
return NULL; |
1903 |
move_lines(_arg0); |
1904 |
Py_INCREF(Py_None); |
1905 |
_resultobj = Py_None; |
1906 |
return _resultobj; |
1907 |
} |
1908 |
|
1909 |
static PyObject *_wrap_move_to(PyObject *self, PyObject *args) { |
1910 |
PyObject * _resultobj; |
1911 |
long _arg0; |
1912 |
|
1913 |
self = self; |
1914 |
if(!PyArg_ParseTuple(args,"l:move_to",&_arg0)) |
1915 |
return NULL; |
1916 |
move_to(_arg0); |
1917 |
Py_INCREF(Py_None); |
1918 |
_resultobj = Py_None; |
1919 |
return _resultobj; |
1920 |
} |
1921 |
|
1922 |
static PyObject *_wrap_insert(PyObject *self, PyObject *args) { |
1923 |
PyObject * _resultobj; |
1924 |
char * _arg0; |
1925 |
|
1926 |
self = self; |
1927 |
if(!PyArg_ParseTuple(args,"s:insert",&_arg0)) |
1928 |
return NULL; |
1929 |
insert(_arg0); |
1930 |
Py_INCREF(Py_None); |
1931 |
_resultobj = Py_None; |
1932 |
return _resultobj; |
1933 |
} |
1934 |
|
1935 |
static PyObject *_wrap_delete(PyObject *self, PyObject *args) { |
1936 |
PyObject * _resultobj; |
1937 |
long _arg0; |
1938 |
|
1939 |
self = self; |
1940 |
if(!PyArg_ParseTuple(args,"l:delete",&_arg0)) |
1941 |
return NULL; |
1942 |
delete(_arg0); |
1943 |
Py_INCREF(Py_None); |
1944 |
_resultobj = Py_None; |
1945 |
return _resultobj; |
1946 |
} |
1947 |
|
1948 |
static PyObject *_wrap_back_space(PyObject *self, PyObject *args) { |
1949 |
PyObject * _resultobj; |
1950 |
long _arg0; |
1951 |
|
1952 |
self = self; |
1953 |
if(!PyArg_ParseTuple(args,"l:back_space",&_arg0)) |
1954 |
return NULL; |
1955 |
back_space(_arg0); |
1956 |
Py_INCREF(Py_None); |
1957 |
_resultobj = Py_None; |
1958 |
return _resultobj; |
1959 |
} |
1960 |
|
1961 |
static PyObject *_wrap_insert_ahead(PyObject *self, PyObject *args) { |
1962 |
PyObject * _resultobj; |
1963 |
char * _arg0; |
1964 |
|
1965 |
self = self; |
1966 |
if(!PyArg_ParseTuple(args,"s:insert_ahead",&_arg0)) |
1967 |
return NULL; |
1968 |
insert_ahead(_arg0); |
1969 |
Py_INCREF(Py_None); |
1970 |
_resultobj = Py_None; |
1971 |
return _resultobj; |
1972 |
} |
1973 |
|
1974 |
static PyObject *_wrap_current(PyObject *self, PyObject *args) { |
1975 |
PyObject * _resultobj; |
1976 |
long _result; |
1977 |
|
1978 |
self = self; |
1979 |
if(!PyArg_ParseTuple(args,":current")) |
1980 |
return NULL; |
1981 |
_result = (long )current(); |
1982 |
_resultobj = Py_BuildValue("l",_result); |
1983 |
return _resultobj; |
1984 |
} |
1985 |
|
1986 |
static PyObject *_wrap_current_line(PyObject *self, PyObject *args) { |
1987 |
PyObject * _resultobj; |
1988 |
long _result; |
1989 |
|
1990 |
self = self; |
1991 |
if(!PyArg_ParseTuple(args,":current_line")) |
1992 |
return NULL; |
1993 |
_result = (long )current_line(); |
1994 |
_resultobj = Py_BuildValue("l",_result); |
1995 |
return _resultobj; |
1996 |
} |
1997 |
|
1998 |
static PyObject *_wrap_bol(PyObject *self, PyObject *args) { |
1999 |
PyObject * _resultobj; |
2000 |
long _result; |
2001 |
long _arg0; |
2002 |
|
2003 |
self = self; |
2004 |
if(!PyArg_ParseTuple(args,"l:bol",&_arg0)) |
2005 |
return NULL; |
2006 |
_result = (long )bol(_arg0); |
2007 |
_resultobj = Py_BuildValue("l",_result); |
2008 |
return _resultobj; |
2009 |
} |
2010 |
|
2011 |
static PyObject *_wrap_eol(PyObject *self, PyObject *args) { |
2012 |
PyObject * _resultobj; |
2013 |
long _result; |
2014 |
long _arg0; |
2015 |
|
2016 |
self = self; |
2017 |
if(!PyArg_ParseTuple(args,"l:eol",&_arg0)) |
2018 |
return NULL; |
2019 |
_result = (long )eol(_arg0); |
2020 |
_resultobj = Py_BuildValue("l",_result); |
2021 |
return _resultobj; |
2022 |
} |
2023 |
|
2024 |
static PyObject *_wrap_find_forwards(PyObject *self, PyObject *args) { |
2025 |
PyObject * _resultobj; |
2026 |
long _result; |
2027 |
long _arg0; |
2028 |
char * _arg1; |
2029 |
|
2030 |
self = self; |
2031 |
if(!PyArg_ParseTuple(args,"ls:find_forwards",&_arg0,&_arg1)) |
2032 |
return NULL; |
2033 |
_result = (long )find_forwards(_arg0,_arg1); |
2034 |
_resultobj = Py_BuildValue("l",_result); |
2035 |
return _resultobj; |
2036 |
} |
2037 |
|
2038 |
static PyObject *_wrap_find_backwards(PyObject *self, PyObject *args) { |
2039 |
PyObject * _resultobj; |
2040 |
long _result; |
2041 |
long _arg0; |
2042 |
char * _arg1; |
2043 |
|
2044 |
self = self; |
2045 |
if(!PyArg_ParseTuple(args,"ls:find_backwards",&_arg0,&_arg1)) |
2046 |
return NULL; |
2047 |
_result = (long )find_backwards(_arg0,_arg1); |
2048 |
_resultobj = Py_BuildValue("l",_result); |
2049 |
return _resultobj; |
2050 |
} |
2051 |
|
2052 |
static PyObject *_wrap_line(PyObject *self, PyObject *args) { |
2053 |
PyObject * _resultobj; |
2054 |
long _result; |
2055 |
long _arg0; |
2056 |
|
2057 |
self = self; |
2058 |
if(!PyArg_ParseTuple(args,"l:line",&_arg0)) |
2059 |
return NULL; |
2060 |
_result = (long )line(_arg0); |
2061 |
_resultobj = Py_BuildValue("l",_result); |
2062 |
return _resultobj; |
2063 |
} |
2064 |
|
2065 |
static PyObject *_wrap_command(PyObject *self, PyObject *args) { |
2066 |
PyObject * _resultobj; |
2067 |
long _arg0; |
2068 |
|
2069 |
self = self; |
2070 |
if(!PyArg_ParseTuple(args,"l:command",&_arg0)) |
2071 |
return NULL; |
2072 |
command(_arg0); |
2073 |
Py_INCREF(Py_None); |
2074 |
_resultobj = Py_None; |
2075 |
return _resultobj; |
2076 |
} |
2077 |
|
2078 |
static PyObject *_wrap_focus(PyObject *self, PyObject *args) { |
2079 |
PyObject * _resultobj; |
2080 |
|
2081 |
self = self; |
2082 |
if(!PyArg_ParseTuple(args,":focus")) |
2083 |
return NULL; |
2084 |
focus(); |
2085 |
Py_INCREF(Py_None); |
2086 |
_resultobj = Py_None; |
2087 |
return _resultobj; |
2088 |
} |
2089 |
|
2090 |
static PyObject *_wrap_set_editor(PyObject *self, PyObject *args) { |
2091 |
PyObject * _resultobj; |
2092 |
long _result; |
2093 |
char * _arg0; |
2094 |
|
2095 |
self = self; |
2096 |
if(!PyArg_ParseTuple(args,"s:set_editor",&_arg0)) |
2097 |
return NULL; |
2098 |
_result = (long )set_editor(_arg0); |
2099 |
_resultobj = Py_BuildValue("l",_result); |
2100 |
return _resultobj; |
2101 |
} |
2102 |
|
2103 |
static PyObject *_wrap_close_window(PyObject *self, PyObject *args) { |
2104 |
PyObject * _resultobj; |
2105 |
long _arg0; |
2106 |
|
2107 |
self = self; |
2108 |
if(!PyArg_ParseTuple(args,"l:close_window",&_arg0)) |
2109 |
return NULL; |
2110 |
close_window(_arg0); |
2111 |
Py_INCREF(Py_None); |
2112 |
_resultobj = Py_None; |
2113 |
return _resultobj; |
2114 |
} |
2115 |
|
2116 |
static PyObject *_wrap_new_window(PyObject *self, PyObject *args) { |
2117 |
PyObject * _resultobj; |
2118 |
|
2119 |
self = self; |
2120 |
if(!PyArg_ParseTuple(args,":new_window")) |
2121 |
return NULL; |
2122 |
new_window(); |
2123 |
Py_INCREF(Py_None); |
2124 |
_resultobj = Py_None; |
2125 |
return _resultobj; |
2126 |
} |
2127 |
|
2128 |
static PyObject *_wrap_load(PyObject *self, PyObject *args) { |
2129 |
PyObject * _resultobj; |
2130 |
int _result; |
2131 |
char * _arg0; |
2132 |
|
2133 |
self = self; |
2134 |
if(!PyArg_ParseTuple(args,"s:load",&_arg0)) |
2135 |
return NULL; |
2136 |
_result = (int )load(_arg0); |
2137 |
_resultobj = Py_BuildValue("i",_result); |
2138 |
return _resultobj; |
2139 |
} |
2140 |
|
2141 |
static PyObject *_wrap_status(PyObject *self, PyObject *args) { |
2142 |
PyObject * _resultobj; |
2143 |
char * _arg0; |
2144 |
|
2145 |
self = self; |
2146 |
if(!PyArg_ParseTuple(args,"s:status",&_arg0)) |
2147 |
return NULL; |
2148 |
status(_arg0); |
2149 |
Py_INCREF(Py_None); |
2150 |
_resultobj = Py_None; |
2151 |
return _resultobj; |
2152 |
} |
2153 |
|
2154 |
static PyObject *_wrap_modified(PyObject *self, PyObject *args) { |
2155 |
PyObject * _resultobj; |
2156 |
int _result; |
2157 |
|
2158 |
self = self; |
2159 |
if(!PyArg_ParseTuple(args,":modified")) |
2160 |
return NULL; |
2161 |
_result = (int )modified(); |
2162 |
_resultobj = Py_BuildValue("i",_result); |
2163 |
return _resultobj; |
2164 |
} |
2165 |
|
2166 |
static PyObject *_wrap_file(PyObject *self, PyObject *args) { |
2167 |
PyObject * _resultobj; |
2168 |
char * _result; |
2169 |
|
2170 |
self = self; |
2171 |
if(!PyArg_ParseTuple(args,":file")) |
2172 |
return NULL; |
2173 |
_result = (char *)file(); |
2174 |
_resultobj = Py_BuildValue("s", _result); |
2175 |
return _resultobj; |
2176 |
} |
2177 |
|
2178 |
static PyObject *_wrap_directory(PyObject *self, PyObject *args) { |
2179 |
PyObject * _resultobj; |
2180 |
char * _result; |
2181 |
|
2182 |
self = self; |
2183 |
if(!PyArg_ParseTuple(args,":directory")) |
2184 |
return NULL; |
2185 |
_result = (char *)directory(); |
2186 |
_resultobj = Py_BuildValue("s", _result); |
2187 |
return _resultobj; |
2188 |
} |
2189 |
|
2190 |
static PyObject *_wrap_input_dialog(PyObject *self, PyObject *args) { |
2191 |
PyObject * _resultobj; |
2192 |
char * _result; |
2193 |
char * _arg0; |
2194 |
char * _arg1; |
2195 |
char * _arg2; |
2196 |
|
2197 |
self = self; |
2198 |
if(!PyArg_ParseTuple(args,"sss:input_dialog",&_arg0,&_arg1,&_arg2)) |
2199 |
return NULL; |
2200 |
_result = (char *)input_dialog(_arg0,_arg1,_arg2); |
2201 |
_resultobj = Py_BuildValue("s", _result); |
2202 |
return _resultobj; |
2203 |
} |
2204 |
|
2205 |
static PyObject *_wrap_load_file_dialog(PyObject *self, PyObject *args) { |
2206 |
PyObject * _resultobj; |
2207 |
char * _result; |
2208 |
char * _arg0; |
2209 |
char * _arg1; |
2210 |
char * _arg2; |
2211 |
|
2212 |
self = self; |
2213 |
if(!PyArg_ParseTuple(args,"sss:load_file_dialog",&_arg0,&_arg1,&_arg2)) |
2214 |
return NULL; |
2215 |
_result = (char *)load_file_dialog(_arg0,_arg1,_arg2); |
2216 |
_resultobj = Py_BuildValue("s", _result); |
2217 |
return _resultobj; |
2218 |
} |
2219 |
|
2220 |
static PyObject *_wrap_save_file_dialog(PyObject *self, PyObject *args) { |
2221 |
PyObject * _resultobj; |
2222 |
char * _result; |
2223 |
char * _arg0; |
2224 |
char * _arg1; |
2225 |
char * _arg2; |
2226 |
|
2227 |
self = self; |
2228 |
if(!PyArg_ParseTuple(args,"sss:save_file_dialog",&_arg0,&_arg1,&_arg2)) |
2229 |
return NULL; |
2230 |
_result = (char *)save_file_dialog(_arg0,_arg1,_arg2); |
2231 |
_resultobj = Py_BuildValue("s", _result); |
2232 |
return _resultobj; |
2233 |
} |
2234 |
|
2235 |
static PyObject *_wrap_status_input(PyObject *self, PyObject *args) { |
2236 |
PyObject * _resultobj; |
2237 |
char * _result; |
2238 |
char * _arg0; |
2239 |
char * _arg1; |
2240 |
|
2241 |
self = self; |
2242 |
if(!PyArg_ParseTuple(args,"ss:status_input",&_arg0,&_arg1)) |
2243 |
return NULL; |
2244 |
_result = (char *)status_input(_arg0,_arg1); |
2245 |
_resultobj = Py_BuildValue("s", _result); |
2246 |
return _resultobj; |
2247 |
} |
2248 |
|
2249 |
static PyObject *_wrap_message_dialog(PyObject *self, PyObject *args) { |
2250 |
PyObject * _resultobj; |
2251 |
char * _arg0; |
2252 |
char * _arg1; |
2253 |
|
2254 |
self = self; |
2255 |
if(!PyArg_ParseTuple(args,"ss:message_dialog",&_arg0,&_arg1)) |
2256 |
return NULL; |
2257 |
message_dialog(_arg0,_arg1); |
2258 |
Py_INCREF(Py_None); |
2259 |
_resultobj = Py_None; |
2260 |
return _resultobj; |
2261 |
} |
2262 |
|
2263 |
static PyObject *_wrap_error_dialog(PyObject *self, PyObject *args) { |
2264 |
PyObject * _resultobj; |
2265 |
char * _arg0; |
2266 |
char * _arg1; |
2267 |
|
2268 |
self = self; |
2269 |
if(!PyArg_ParseTuple(args,"ss:error_dialog",&_arg0,&_arg1)) |
2270 |
return NULL; |
2271 |
error_dialog(_arg0,_arg1); |
2272 |
Py_INCREF(Py_None); |
2273 |
_resultobj = Py_None; |
2274 |
return _resultobj; |
2275 |
} |
2276 |
|
2277 |
static PyObject *_wrap_column_pixels(PyObject *self, PyObject *args) { |
2278 |
PyObject * _resultobj; |
2279 |
long _result; |
2280 |
long _arg0; |
2281 |
|
2282 |
self = self; |
2283 |
if(!PyArg_ParseTuple(args,"l:column_pixels",&_arg0)) |
2284 |
return NULL; |
2285 |
_result = (long )column_pixels(_arg0); |
2286 |
_resultobj = Py_BuildValue("l",_result); |
2287 |
return _resultobj; |
2288 |
} |
2289 |
|
2290 |
static PyObject *_wrap_key_press(PyObject *self, PyObject *args) { |
2291 |
PyObject * _resultobj; |
2292 |
|
2293 |
self = self; |
2294 |
if(!PyArg_ParseTuple(args,":key_press")) |
2295 |
return NULL; |
2296 |
key_press(); |
2297 |
Py_INCREF(Py_None); |
2298 |
_resultobj = Py_None; |
2299 |
return _resultobj; |
2300 |
} |
2301 |
|
2302 |
static PyObject *_wrap_redraw_page(PyObject *self, PyObject *args) { |
2303 |
PyObject * _resultobj; |
2304 |
|
2305 |
self = self; |
2306 |
if(!PyArg_ParseTuple(args,":redraw_page")) |
2307 |
return NULL; |
2308 |
redraw_page(); |
2309 |
Py_INCREF(Py_None); |
2310 |
_resultobj = Py_None; |
2311 |
return _resultobj; |
2312 |
} |
2313 |
|
2314 |
static PyObject *_wrap_shell_output(PyObject *self, PyObject *args) { |
2315 |
PyObject * _resultobj; |
2316 |
int _result; |
2317 |
char * _arg0; |
2318 |
char * _arg1; |
2319 |
char * _arg2; |
2320 |
|
2321 |
self = self; |
2322 |
if(!PyArg_ParseTuple(args,"sss:shell_output",&_arg0,&_arg1,&_arg2)) |
2323 |
return NULL; |
2324 |
_result = (int )shell_output(_arg0,_arg1,_arg2); |
2325 |
_resultobj = Py_BuildValue("i",_result); |
2326 |
return _resultobj; |
2327 |
} |
2328 |
|
2329 |
static PyMethodDef cooleditMethods[] = { |
2330 |
{ "_", edit__gettext, 1 }, |
2331 |
{ "gettext", edit__gettext, 1 }, |
2332 |
{ "insert_menu", edit__insert_menu, 1 }, |
2333 |
{ "replace_menu", edit__replace_menu, 1 }, |
2334 |
{ "menu", edit__menu, 1 }, |
2335 |
{ "bind", edit__bind, 1 }, |
2336 |
{ "key", edit__key, 1 }, |
2337 |
{ "get_key", edit__get_key, 1 }, |
2338 |
{ "markers", edit__markers, 1 }, |
2339 |
{ "generic_dialog", edit__generic_dialog, 1 }, |
2340 |
{ "overwrite", edit__overwrite, 1 }, |
2341 |
{ "query_dialog", edit__query_dialog, 1 }, |
2342 |
{ "file_type", edit__file_type, 1 }, |
2343 |
{ "indent", edit__indent, 1 }, |
2344 |
{ "get_editors", edit__get_editors, 1 }, |
2345 |
{ "shell_output", _wrap_shell_output, 1 }, |
2346 |
{ "redraw_page", _wrap_redraw_page, 1 }, |
2347 |
{ "key_press", _wrap_key_press, 1 }, |
2348 |
{ "column_pixels", _wrap_column_pixels, 1 }, |
2349 |
{ "error_dialog", _wrap_error_dialog, 1 }, |
2350 |
{ "message_dialog", _wrap_message_dialog, 1 }, |
2351 |
{ "status_input", _wrap_status_input, 1 }, |
2352 |
{ "save_file_dialog", _wrap_save_file_dialog, 1 }, |
2353 |
{ "load_file_dialog", _wrap_load_file_dialog, 1 }, |
2354 |
{ "input_dialog", _wrap_input_dialog, 1 }, |
2355 |
{ "directory", _wrap_directory, 1 }, |
2356 |
{ "file", _wrap_file, 1 }, |
2357 |
{ "modified", _wrap_modified, 1 }, |
2358 |
{ "status", _wrap_status, 1 }, |
2359 |
{ "load", _wrap_load, 1 }, |
2360 |
{ "new_window", _wrap_new_window, 1 }, |
2361 |
{ "close_window", _wrap_close_window, 1 }, |
2362 |
{ "set_editor", _wrap_set_editor, 1 }, |
2363 |
{ "focus", _wrap_focus, 1 }, |
2364 |
{ "command", _wrap_command, 1 }, |
2365 |
{ "line", _wrap_line, 1 }, |
2366 |
{ "find_backwards", _wrap_find_backwards, 1 }, |
2367 |
{ "find_forwards", _wrap_find_forwards, 1 }, |
2368 |
{ "eol", _wrap_eol, 1 }, |
2369 |
{ "bol", _wrap_bol, 1 }, |
2370 |
{ "current_line", _wrap_current_line, 1 }, |
2371 |
{ "current", _wrap_current, 1 }, |
2372 |
{ "insert_ahead", _wrap_insert_ahead, 1 }, |
2373 |
{ "back_space", _wrap_back_space, 1 }, |
2374 |
{ "delete", _wrap_delete, 1 }, |
2375 |
{ "insert", _wrap_insert, 1 }, |
2376 |
{ "move_to", _wrap_move_to, 1 }, |
2377 |
{ "move_lines", _wrap_move_lines, 1 }, |
2378 |
{ "move", _wrap_move, 1 }, |
2379 |
{ "buffer_size", _wrap_buffer_size, 1 }, |
2380 |
{ "get_line", edit__get_line, 1 }, |
2381 |
{ "get_text", edit__get_text, 1 }, |
2382 |
{ NULL, NULL } |
2383 |
}; |
2384 |
static PyObject *SWIG_globals; |
2385 |
#ifdef __cplusplus |
2386 |
extern "C" |
2387 |
#endif |
2388 |
SWIGEXPORT(void,initcooledit)() { |
2389 |
PyObject *m, *d; |
2390 |
SWIG_globals = SWIG_newvarlink(); |
2391 |
m = Py_InitModule("cooledit", cooleditMethods); |
2392 |
d = PyModule_GetDict(m); |
2393 |
/* |
2394 |
* These are the pointer type-equivalency mappings. |
2395 |
* (Used by the SWIG pointer type-checker). |
2396 |
*/ |
2397 |
SWIG_RegisterMapping("_signed_long","_long",0); |
2398 |
SWIG_RegisterMapping("_long","_unsigned_long",0); |
2399 |
SWIG_RegisterMapping("_long","_signed_long",0); |
2400 |
SWIG_RegisterMapping("_unsigned_long","_long",0); |
2401 |
SWIG_RegisterMapping("_signed_int","_int",0); |
2402 |
SWIG_RegisterMapping("_unsigned_short","_short",0); |
2403 |
SWIG_RegisterMapping("_signed_short","_short",0); |
2404 |
SWIG_RegisterMapping("_unsigned_int","_int",0); |
2405 |
SWIG_RegisterMapping("_short","_unsigned_short",0); |
2406 |
SWIG_RegisterMapping("_short","_signed_short",0); |
2407 |
SWIG_RegisterMapping("_int","_unsigned_int",0); |
2408 |
SWIG_RegisterMapping("_int","_signed_int",0); |
2409 |
} |