1 2 #ifndef Py_CURSES_H 3 #define Py_CURSES_H 4 5 #ifdef __APPLE__ 6 /* 7 ** On Mac OS X 10.2 [n]curses.h and stdlib.h use different guards 8 ** against multiple definition of wchar_t. 9 */ 10 #ifdef _BSD_WCHAR_T_DEFINED_ 11 #define _WCHAR_T 12 #endif 13 14 /* the following define is necessary for OS X 10.6; without it, the 15 Apple-supplied ncurses.h sets NCURSES_OPAQUE to 1, and then Python 16 can't get at the WINDOW flags field. */ 17 #define NCURSES_OPAQUE 0 18 #endif /* __APPLE__ */ 19 20 #ifdef __FreeBSD__ 21 /* 22 ** On FreeBSD, [n]curses.h and stdlib.h/wchar.h use different guards 23 ** against multiple definition of wchar_t and wint_t. 24 */ 25 #ifdef _XOPEN_SOURCE_EXTENDED 26 #ifndef __FreeBSD_version 27 #include <osreldate.h> 28 #endif 29 #if __FreeBSD_version >= 500000 30 #ifndef __wchar_t 31 #define __wchar_t 32 #endif 33 #ifndef __wint_t 34 #define __wint_t 35 #endif 36 #else 37 #ifndef _WCHAR_T 38 #define _WCHAR_T 39 #endif 40 #ifndef _WINT_T 41 #define _WINT_T 42 #endif 43 #endif 44 #endif 45 #endif 46 47 #ifdef HAVE_NCURSES_H 48 #include <ncurses.h> 49 #else 50 #include <curses.h> 51 #ifdef HAVE_TERM_H 52 /* for tigetstr, which is not declared in SysV curses */ 53 #include <term.h> 54 #endif 55 #endif 56 57 #if defined(__MINGW32__) && !defined(_ISPAD) 58 #define _ISPAD 0x10 59 #endif 60 61 #ifdef HAVE_NCURSES_H 62 /* configure was checking <curses.h>, but we will 63 use <ncurses.h>, which has all these features. */ 64 #ifndef WINDOW_HAS_FLAGS 65 #define WINDOW_HAS_FLAGS 1 66 #endif 67 #ifndef MVWDELCH_IS_EXPRESSION 68 #define MVWDELCH_IS_EXPRESSION 1 69 #endif 70 #endif 71 72 #ifdef __cplusplus 73 extern "C" { 74 #endif 75 76 #define PyCurses_API_pointers 4 77 78 /* Type declarations */ 79 80 typedef struct { 81 PyObject_HEAD 82 WINDOW *win; 83 } PyCursesWindowObject; 84 85 #define PyCursesWindow_Check(v) (Py_TYPE(v) == &PyCursesWindow_Type) 86 87 #define PyCurses_CAPSULE_NAME "_curses._C_API" 88 89 90 #ifdef CURSES_MODULE 91 /* This section is used when compiling _cursesmodule.c */ 92 93 #else 94 /* This section is used in modules that use the _cursesmodule API */ 95 96 static void **PyCurses_API; 97 98 #define PyCursesWindow_Type (*(PyTypeObject *) PyCurses_API[0]) 99 #define PyCursesSetupTermCalled {if (! ((int (*)(void))PyCurses_API[1]) () ) return NULL;} 100 #define PyCursesInitialised {if (! ((int (*)(void))PyCurses_API[2]) () ) return NULL;} 101 #define PyCursesInitialisedColor {if (! ((int (*)(void))PyCurses_API[3]) () ) return NULL;} 102 103 #define import_curses() \ 104 PyCurses_API = (void **)PyCapsule_Import(PyCurses_CAPSULE_NAME, 1); 105 106 #endif 107 108 /* general error messages */ 109 static char *catchall_ERR = "curses function returned ERR"; 110 static char *catchall_NULL = "curses function returned NULL"; 111 112 /* Function Prototype Macros - They are ugly but very, very useful. ;-) 113 114 X - function name 115 TYPE - parameter Type 116 ERGSTR - format string for construction of the return value 117 PARSESTR - format string for argument parsing 118 */ 119 120 #define NoArgNoReturnFunction(X) \ 121 static PyObject *PyCurses_ ## X (PyObject *self) \ 122 { \ 123 PyCursesInitialised \ 124 return PyCursesCheckERR(X(), # X); } 125 126 #define NoArgOrFlagNoReturnFunction(X) \ 127 static PyObject *PyCurses_ ## X (PyObject *self, PyObject *args) \ 128 { \ 129 int flag = 0; \ 130 PyCursesInitialised \ 131 switch(PyTuple_Size(args)) { \ 132 case 0: \ 133 return PyCursesCheckERR(X(), # X); \ 134 case 1: \ 135 if (!PyArg_ParseTuple(args, "i;True(1) or False(0)", &flag)) return NULL; \ 136 if (flag) return PyCursesCheckERR(X(), # X); \ 137 else return PyCursesCheckERR(no ## X (), # X); \ 138 default: \ 139 PyErr_SetString(PyExc_TypeError, # X " requires 0 or 1 arguments"); \ 140 return NULL; } } 141 142 #define NoArgReturnIntFunction(X) \ 143 static PyObject *PyCurses_ ## X (PyObject *self) \ 144 { \ 145 PyCursesInitialised \ 146 return PyInt_FromLong((long) X()); } 147 148 149 #define NoArgReturnStringFunction(X) \ 150 static PyObject *PyCurses_ ## X (PyObject *self) \ 151 { \ 152 PyCursesInitialised \ 153 return PyString_FromString(X()); } 154 155 #define NoArgTrueFalseFunction(X) \ 156 static PyObject *PyCurses_ ## X (PyObject *self) \ 157 { \ 158 PyCursesInitialised \ 159 if (X () == FALSE) { \ 160 Py_INCREF(Py_False); \ 161 return Py_False; \ 162 } \ 163 Py_INCREF(Py_True); \ 164 return Py_True; } 165 166 #define NoArgNoReturnVoidFunction(X) \ 167 static PyObject *PyCurses_ ## X (PyObject *self) \ 168 { \ 169 PyCursesInitialised \ 170 X(); \ 171 Py_INCREF(Py_None); \ 172 return Py_None; } 173 174 #ifdef __cplusplus 175 } 176 #endif 177 178 #endif /* !defined(Py_CURSES_H) */ 179 180 181