Andrew M. Kuchling | 0c7a0bd | 2000-12-22 21:51:10 +0000 | [diff] [blame] | 1 | |
| 2 | #ifndef Py_CURSES_H |
| 3 | #define Py_CURSES_H |
| 4 | |
Jack Jansen | 26897bf | 2002-11-22 16:12:57 +0000 | [diff] [blame] | 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 | #endif |
Jack Jansen | d00c13a | 2003-02-28 12:51:18 +0000 | [diff] [blame] | 14 | |
Andrew MacIntyre | 1a90117 | 2003-06-11 12:26:08 +0000 | [diff] [blame^] | 15 | #ifdef __FreeBSD__ |
| 16 | /* |
| 17 | ** On FreeBSD, [n]curses.h and stdlib.h/wchar.h use different guards |
| 18 | ** against multiple definition of wchar_t and wint_t. |
| 19 | */ |
| 20 | #ifdef _XOPEN_SOURCE_EXTENDED |
| 21 | #ifndef _WCHAR_T |
| 22 | #define _WCHAR_T |
| 23 | #endif |
| 24 | #ifndef _WINT_T |
| 25 | #define _WINT_T |
| 26 | #endif |
| 27 | #endif |
| 28 | #endif |
| 29 | |
Jack Jansen | d00c13a | 2003-02-28 12:51:18 +0000 | [diff] [blame] | 30 | #ifdef HAVE_NCURSES_H |
Andrew M. Kuchling | 0c7a0bd | 2000-12-22 21:51:10 +0000 | [diff] [blame] | 31 | #include <ncurses.h> |
| 32 | #else |
| 33 | #include <curses.h> |
Martin v. Löwis | 6953233 | 2001-10-13 09:12:41 +0000 | [diff] [blame] | 34 | #ifdef HAVE_TERM_H |
| 35 | /* for tigetstr, which is not declared in SysV curses */ |
| 36 | #include <term.h> |
| 37 | #endif |
Andrew M. Kuchling | 0c7a0bd | 2000-12-22 21:51:10 +0000 | [diff] [blame] | 38 | #endif |
| 39 | |
Martin v. Löwis | eb9b103 | 2001-10-24 17:10:49 +0000 | [diff] [blame] | 40 | #ifdef HAVE_NCURSES_H |
| 41 | /* configure was checking <curses.h>, but we will |
| 42 | use <ncurses.h>, which has all these features. */ |
| 43 | #ifndef WINDOW_HAS_FLAGS |
| 44 | #define WINDOW_HAS_FLAGS 1 |
| 45 | #endif |
| 46 | #ifndef MVWDELCH_IS_EXPRESSION |
| 47 | #define MVWDELCH_IS_EXPRESSION 1 |
| 48 | #endif |
| 49 | #endif |
| 50 | |
Andrew M. Kuchling | 0c7a0bd | 2000-12-22 21:51:10 +0000 | [diff] [blame] | 51 | #ifdef __cplusplus |
| 52 | extern "C" { |
| 53 | #endif |
| 54 | |
| 55 | #define PyCurses_API_pointers 4 |
| 56 | |
| 57 | /* Type declarations */ |
| 58 | |
| 59 | typedef struct { |
| 60 | PyObject_HEAD |
| 61 | WINDOW *win; |
| 62 | } PyCursesWindowObject; |
| 63 | |
| 64 | #define PyCursesWindow_Check(v) ((v)->ob_type == &PyCursesWindow_Type) |
| 65 | |
| 66 | #ifdef CURSES_MODULE |
| 67 | /* This section is used when compiling _cursesmodule.c */ |
| 68 | |
| 69 | #else |
| 70 | /* This section is used in modules that use the _cursesmodule API */ |
| 71 | |
| 72 | static void **PyCurses_API; |
| 73 | |
| 74 | #define PyCursesWindow_Type (*(PyTypeObject *) PyCurses_API[0]) |
| 75 | #define PyCursesSetupTermCalled {if (! ((int (*)(void))PyCurses_API[1]) () ) return NULL;} |
| 76 | #define PyCursesInitialised {if (! ((int (*)(void))PyCurses_API[2]) () ) return NULL;} |
| 77 | #define PyCursesInitialisedColor {if (! ((int (*)(void))PyCurses_API[3]) () ) return NULL;} |
| 78 | |
| 79 | #define import_curses() \ |
| 80 | { \ |
| 81 | PyObject *module = PyImport_ImportModule("_curses"); \ |
| 82 | if (module != NULL) { \ |
| 83 | PyObject *module_dict = PyModule_GetDict(module); \ |
| 84 | PyObject *c_api_object = PyDict_GetItemString(module_dict, "_C_API"); \ |
| 85 | if (PyCObject_Check(c_api_object)) { \ |
| 86 | PyCurses_API = (void **)PyCObject_AsVoidPtr(c_api_object); \ |
| 87 | } \ |
| 88 | } \ |
| 89 | } |
| 90 | #endif |
| 91 | |
| 92 | /* general error messages */ |
| 93 | static char *catchall_ERR = "curses function returned ERR"; |
| 94 | static char *catchall_NULL = "curses function returned NULL"; |
| 95 | |
Andrew M. Kuchling | 0c7a0bd | 2000-12-22 21:51:10 +0000 | [diff] [blame] | 96 | /* Function Prototype Macros - They are ugly but very, very useful. ;-) |
| 97 | |
| 98 | X - function name |
| 99 | TYPE - parameter Type |
| 100 | ERGSTR - format string for construction of the return value |
| 101 | PARSESTR - format string for argument parsing |
| 102 | */ |
| 103 | |
| 104 | #define NoArgNoReturnFunction(X) \ |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 105 | static PyObject *PyCurses_ ## X (PyObject *self) \ |
Andrew M. Kuchling | 0c7a0bd | 2000-12-22 21:51:10 +0000 | [diff] [blame] | 106 | { \ |
| 107 | PyCursesInitialised \ |
Andrew M. Kuchling | 0c7a0bd | 2000-12-22 21:51:10 +0000 | [diff] [blame] | 108 | return PyCursesCheckERR(X(), # X); } |
| 109 | |
| 110 | #define NoArgOrFlagNoReturnFunction(X) \ |
| 111 | static PyObject *PyCurses_ ## X (PyObject *self, PyObject *args) \ |
| 112 | { \ |
| 113 | int flag = 0; \ |
| 114 | PyCursesInitialised \ |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 115 | switch(PyTuple_Size(args)) { \ |
Andrew M. Kuchling | 0c7a0bd | 2000-12-22 21:51:10 +0000 | [diff] [blame] | 116 | case 0: \ |
| 117 | return PyCursesCheckERR(X(), # X); \ |
| 118 | case 1: \ |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 119 | if (!PyArg_ParseTuple(args, "i;True(1) or False(0)", &flag)) return NULL; \ |
Andrew M. Kuchling | 0c7a0bd | 2000-12-22 21:51:10 +0000 | [diff] [blame] | 120 | if (flag) return PyCursesCheckERR(X(), # X); \ |
| 121 | else return PyCursesCheckERR(no ## X (), # X); \ |
| 122 | default: \ |
| 123 | PyErr_SetString(PyExc_TypeError, # X " requires 0 or 1 arguments"); \ |
| 124 | return NULL; } } |
| 125 | |
| 126 | #define NoArgReturnIntFunction(X) \ |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 127 | static PyObject *PyCurses_ ## X (PyObject *self) \ |
Andrew M. Kuchling | 0c7a0bd | 2000-12-22 21:51:10 +0000 | [diff] [blame] | 128 | { \ |
| 129 | PyCursesInitialised \ |
Andrew M. Kuchling | 0c7a0bd | 2000-12-22 21:51:10 +0000 | [diff] [blame] | 130 | return PyInt_FromLong((long) X()); } |
| 131 | |
| 132 | |
| 133 | #define NoArgReturnStringFunction(X) \ |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 134 | static PyObject *PyCurses_ ## X (PyObject *self) \ |
Andrew M. Kuchling | 0c7a0bd | 2000-12-22 21:51:10 +0000 | [diff] [blame] | 135 | { \ |
| 136 | PyCursesInitialised \ |
Andrew M. Kuchling | 0c7a0bd | 2000-12-22 21:51:10 +0000 | [diff] [blame] | 137 | return PyString_FromString(X()); } |
| 138 | |
| 139 | #define NoArgTrueFalseFunction(X) \ |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 140 | static PyObject *PyCurses_ ## X (PyObject *self) \ |
Andrew M. Kuchling | 0c7a0bd | 2000-12-22 21:51:10 +0000 | [diff] [blame] | 141 | { \ |
| 142 | PyCursesInitialised \ |
Andrew M. Kuchling | 0c7a0bd | 2000-12-22 21:51:10 +0000 | [diff] [blame] | 143 | if (X () == FALSE) { \ |
| 144 | Py_INCREF(Py_False); \ |
| 145 | return Py_False; \ |
| 146 | } \ |
| 147 | Py_INCREF(Py_True); \ |
| 148 | return Py_True; } |
| 149 | |
| 150 | #define NoArgNoReturnVoidFunction(X) \ |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 151 | static PyObject *PyCurses_ ## X (PyObject *self) \ |
Andrew M. Kuchling | 0c7a0bd | 2000-12-22 21:51:10 +0000 | [diff] [blame] | 152 | { \ |
| 153 | PyCursesInitialised \ |
Andrew M. Kuchling | 0c7a0bd | 2000-12-22 21:51:10 +0000 | [diff] [blame] | 154 | X(); \ |
| 155 | Py_INCREF(Py_None); \ |
| 156 | return Py_None; } |
| 157 | |
| 158 | #ifdef __cplusplus |
| 159 | } |
| 160 | #endif |
| 161 | |
| 162 | #endif /* !defined(Py_CURSES_H) */ |
| 163 | |
| 164 | |