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