📄 coolpython.c
字号:
SwigLastCache = (SwigLastCache+1) & SWIG_CACHEMASK; if (!SwigLastCache) cache = SwigCache; else cache++; } /* We have a type mismatch. Will have to look through our type mapping table to figure out whether or not we can accept this datatype */ start = SwigStart[(int) _t[1]]; end = SwigStart[(int) _t[1]+1]; sp = &SwigPtrTable[start]; while (start < end) { if (swigcmp(_t,sp) == 0) break; sp++; start++; } if (start >= end) sp = 0; /* Try to find a match for this */ if (sp) { while (swigcmp(_t,sp) == 0) { name = sp->name; len = sp->len; tp = sp->next; /* Try to find entry for our given datatype */ while(tp) { if (tp->len >= 255) { return _c; } strcpy(temp_type,tp->name); strncat(temp_type,_t+len,255-tp->len); if (strcmp(_c,temp_type) == 0) { strcpy(SwigCache[SwigCacheIndex].mapped,_c); strcpy(SwigCache[SwigCacheIndex].name,_t); SwigCache[SwigCacheIndex].stat = 1; SwigCache[SwigCacheIndex].tp = tp; SwigCacheIndex = SwigCacheIndex & SWIG_CACHEMASK; /* Get pointer value */ *ptr = (void *) _p; if (tp->cast) *ptr = (*(tp->cast))(*ptr); return (char *) 0; } tp = tp->next; } sp++; /* Hmmm. Didn't find it this time */ } } /* Didn't find any sort of match for this data. Get the pointer value and return the received type */ *ptr = (void *) _p; return _c; } else { /* Found a match on the first try. Return pointer value */ *ptr = (void *) _p; return (char *) 0; } } else { /* No type specified. Good luck */ *ptr = (void *) _p; return (char *) 0; } } else { if (strcmp (_c, "NULL") == 0) { *ptr = (void *) 0; return (char *) 0; } *ptr = (void *) 0; return _c; }}/* Compatibility mode */#define _swig_get_hex SWIG_GetPtr#define SWIG_init initcooledit#define SWIG_name "cooledit"#define GLOBAL_STARTUP_FILE "global.py"#include <config.h>#include <stdio.h>#include <stdlib.h>#include <signal.h>#include <sys/types.h>#if HAVE_SYS_WAIT_H#include <sys/wait.h>#endif#include <X11/Xlib.h>#include <X11/Xutil.h>#include <X11/Xatom.h>#include "lkeysym.h"#include "stringtools.h"#include "coolwidget.h"#include "edit.h"#include "editcmddef.h"#include "editoptions.h"#include "shell.h" /* MAX_NUM_SCRIPTS */#include "find.h"#include "mad.h"void coolpython_init (int argc, char **argv);void coolpython_shut (void);int coolpython_key (unsigned int state, unsigned int keycode, KeySym keysym);void coolpython_command (WEdit * edit, int i);void coolpython_typechange (Window win);void initcooledit ();static void coolpython_display_error (int set_sys_last_vars);#define CHECK_CURRENT if (!last_edit) return;#define CHECK_CURRENT_RETURN(x) if (!last_edit) return (x);extern CWidget *edit[];extern long current_edit;extern long last_edit;static PyObject *name_space = 0;/* {{{ bindings */#define MAX_GLOBAL_BINDINGS 1000#define MAX_CURRENT_BINDINGS 1000#define GLOBAL_BINDING(i) ((i) + MAX_CURRENT_BINDINGS)#define CURRENT_BINDING(i) ((i) + 0)#define BINDING_GLOBAL(i) ((i) - MAX_CURRENT_BINDINGS)#define BINDING_CURRENT(i) ((i) - 0)struct python_binding { PyObject *function; char *statement; KeySym keysym; int modifiers; struct python_binding *next;};static struct { char *statement; KeySym keysym; int modifiers;} bindings[MAX_GLOBAL_BINDINGS];int last_binding = 0;static void free_current_bindings (void *x){ struct python_binding *b, *n; for (b = (struct python_binding *) x; b; b = n) { n = b->next; if (b->statement) free (b->statement); Py_XDECREF (b->function); free (b); }}/* returns non-zero on error: i.e. max bindings reached */static int add_binding (PyObject * function, char *statement, KeySym keysym, int modifiers){ struct python_binding **b, *p; int i; b = (struct python_binding **) &(edit[current_edit]->user); for (i = 0; *b; b = &((*b)->next), i++) { if (i >= MAX_CURRENT_BINDINGS) return 1; p = *b; if (p->keysym == keysym && p->modifiers == modifiers) { Py_XDECREF (p->function); p->function = 0; if (p->statement) { free (p->statement); p->statement = 0; } if (!function && !statement) { p = (*b)->next; free (*b); *b = p; return 0; } else { goto no_alloc; } } } p = *b = malloc (sizeof (struct python_binding)); p->next = 0; no_alloc: if (function) { Py_INCREF (function); p->function = function; p->statement = 0; } else if (statement) { p->function = 0; p->statement = (char *) strdup (statement); } else { free (p); return 0; } p->keysym = keysym; p->modifiers = modifiers; edit[current_edit]->free_user = free_current_bindings; return 0;}static int add_bindings (PyObject *function, KeySym keysym1, KeySym keysym2, int modifiers){ int r = 0; while (keysym1 <= keysym2) if ((r = add_binding (function, 0, keysym1++, modifiers))) break; return r;}int coolpython_key (unsigned int state, unsigned int keycode, KeySym keysym){ struct python_binding *b; int i; CWidget *w;/* make sure we are really an editor since bindings should not apply in input/text/other widgets */ w = CWidgetOfWindow (CGetFocus ()); if (!w) return -1; if (w->kind != C_EDITOR_WIDGET) return -1;/* check bindings for current editor */ for (i = 0, b = (struct python_binding *) edit[current_edit]->user; b; b = b->next, i++) if (b->keysym == keysym && b->modifiers == state) return CURRENT_BINDING (i);/* check global bindings */ for (i = 0; i < last_binding; i++) if (bindings[i].keysym == keysym && bindings[i].modifiers == state) return GLOBAL_BINDING (i); return -1;}/* }}} bindings */static void move (long i){ CHECK_CURRENT; edit_cursor_move (edit[current_edit]->editor, i);}static void move_lines (long i){ CHECK_CURRENT; if (i > 0) edit_move_up (edit[current_edit]->editor, i, 0); else if (i < 0) edit_move_down (edit[current_edit]->editor, i, 0);}static void move_to (long i){ CHECK_CURRENT; edit_cursor_move (edit[current_edit]->editor, i - edit[current_edit]->editor->curs1);}static void insert (char *s){ CHECK_CURRENT; for (; *s; s++) edit_insert (edit[current_edit]->editor, (long) *s);}static void delete (long i){ CHECK_CURRENT; if (i > 0) while (i-- && edit[current_edit]->editor->curs2 > 0) edit_delete (edit[current_edit]->editor);}static void back_space (long i){ CHECK_CURRENT; if (i > 0) while (i-- && edit[current_edit]->editor->curs1 > 0) edit_backspace (edit[current_edit]->editor);}static void insert_ahead (char *s){ long l, r; CHECK_CURRENT; r = l = strlen (s); s += l - 1; for (; l >= 0; s--, l--) edit_insert_ahead (edit[current_edit]->editor, (long) *s);}static long current (void){ CHECK_CURRENT_RETURN (-1); return edit[current_edit]->editor->curs1;}static long current_line (void){ CHECK_CURRENT_RETURN (-1); return edit[current_edit]->editor->curs_line;}static long bol (long i){ CHECK_CURRENT_RETURN (-1); if (i > edit[current_edit]->editor->total_lines || i < 0) return -1; return edit_find_line (edit[current_edit]->editor, i);}static long eol (long i){ CHECK_CURRENT_RETURN (-1); if (i > edit[current_edit]->editor->total_lines || i < 0) return -1; return edit_eol (edit[current_edit]->editor, bol (i));}static long find_forwards (long from, char *s){ CHECK_CURRENT_RETURN (-1); if (!*s) return -1; for (; from < edit[current_edit]->editor->last_byte; from++) { if (*s == edit_get_byte (edit[current_edit]->editor, from)) { int i; for (i = 1;; i++) { if (!s[i]) return from; if (s[i] == edit_get_byte (edit[current_edit]->editor, from + i)) continue; break; } } } return -1;}static long find_backwards (long from, char *s){ CHECK_CURRENT_RETURN (-1); if (!*s) return -1; for (; from >= 0; from--) { if (*s == edit_get_byte (edit[current_edit]->editor, from)) { int i; for (i = 1;; i++) { if (!s[i]) return from; if (s[i] == edit_get_byte (edit[current_edit]->editor, from + i)) continue; break; } } } return -1;}static PyObject *edit__get_text (PyObject * self, PyObject * args){ PyObject *result; char *r, *p; long i, j = -1, l; if (!PyArg_ParseTuple (args, "|ll:get_text", &i, &j)) return NULL; if (i == -1) i = edit[current_edit]->editor->curs1; if (j == -1) j = i + 1; l = j - i; if (l < 0) { PyErr_SetString (PyExc_ValueError, _("second offset is less than first")); return NULL; } p = r = malloc (l + 1); if (i < 0) i = 0; if (j >= edit[current_edit]->editor->last_byte) j = edit[current_edit]->editor->last_byte; for (; i < j; i++) *p++ = edit_get_byte (edit[current_edit]->editor, i); *p = '\0'; result = PyString_FromStringAndSize (r, l); free (r); return result;}static PyObject *edit__get_line (PyObject * self, PyObject * args){ PyObject *result; char *r, *p; int i, j, l, l1 = -1, l2 = -1; if (!PyArg_ParseTuple (args, "|ii:get_line", &l1, &l2)) return NULL; if (l1 == -1) l1 = edit[current_edit]->editor->curs_line; if (l2 == -1) l2 = l1; i = bol (l1); j = eol (l2); l = j - i; if (l < 0) { PyErr_SetString (PyExc_ValueError, _("second offset is less than first")); return NULL; } p = r = malloc (l + 1); if (i < 0) i = 0; if (j >= edit[current_edit]->editor->last_byte) j = edit[current_edit]->editor->last_byte; for (; i < j; i++) *p++ = edit_get_byte (edit[current_edit]->editor, i); *p = '\0'; result = PyString_FromStringAndSize (r, l); free (r); return result;}static long line (long i){ CHECK_CURRENT_RETURN (-1); if (i > edit[current_edit]->editor->curs1) return edit[current_edit]->editor->curs_line + edit_count_lines (edit[current_edit]->editor, edit[current_edit]->editor->curs1, i); return edit[current_edit]->editor->curs_line - edit_count_lines (edit[current_edit]->editor, i, edit[current_edit]->editor->curs1);}static void command (long i){ CHECK_CURRENT; edit_execute_cmd (edit[current_edit]->editor, i, -1);}/* window functions */static void focus (void){ CHECK_CURRENT; CFocus (edit[current_edit]); XRaiseWindow (CDisplay, edit[current_edit]->parentid); CRaiseWindows (); current_to_top ();}static long set_editor (char *filename_with_path){ char *f, *d, *p; int i, r = 1; d = pathdup (filename_with_path); p = strrchr (d, '/'); if (p) { p++; f = (char *) strdup (p); *p = '\0'; } else { free (d); return 1; } for (i = 0; i < last_edit; i++) { if (strcmp (f, edit[i]->editor->filename)) continue; if (strcmp (d, edit[i]->editor->dir)) continue; current_edit = i; r = 0;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -