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 | */ |
Serhiy Storchaka | e0fc1af | 2017-10-31 16:12:35 +0200 | [diff] [blame] | 10 | #ifdef _BSD_WCHAR_T_DEFINED_ |
Jack Jansen | 26897bf | 2002-11-22 16:12:57 +0000 | [diff] [blame] | 11 | #define _WCHAR_T |
| 12 | #endif |
Mark Dickinson | 6b3f1ef | 2009-09-06 21:21:05 +0000 | [diff] [blame] | 13 | #endif /* __APPLE__ */ |
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 | */ |
Serhiy Storchaka | e0fc1af | 2017-10-31 16:12:35 +0200 | [diff] [blame] | 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 | |
Miss Islington (bot) | 6ba0b58 | 2017-11-01 05:36:48 -0700 | [diff] [blame^] | 42 | #if !defined(HAVE_CURSES_IS_PAD) && defined(WINDOW_HAS_FLAGS) |
| 43 | /* The following definition is necessary for ncurses 5.7; without it, |
| 44 | some of [n]curses.h set NCURSES_OPAQUE to 1, and then Python |
| 45 | can't get at the WINDOW flags field. */ |
| 46 | #define NCURSES_OPAQUE 0 |
| 47 | #endif |
| 48 | |
Jack Jansen | d00c13a | 2003-02-28 12:51:18 +0000 | [diff] [blame] | 49 | #ifdef HAVE_NCURSES_H |
Andrew M. Kuchling | 0c7a0bd | 2000-12-22 21:51:10 +0000 | [diff] [blame] | 50 | #include <ncurses.h> |
| 51 | #else |
| 52 | #include <curses.h> |
Andrew M. Kuchling | 0c7a0bd | 2000-12-22 21:51:10 +0000 | [diff] [blame] | 53 | #endif |
| 54 | |
Martin v. Löwis | eb9b103 | 2001-10-24 17:10:49 +0000 | [diff] [blame] | 55 | #ifdef HAVE_NCURSES_H |
| 56 | /* configure was checking <curses.h>, but we will |
Miss Islington (bot) | 6ba0b58 | 2017-11-01 05:36:48 -0700 | [diff] [blame^] | 57 | use <ncurses.h>, which has some or all these features. */ |
| 58 | #if !defined(WINDOW_HAS_FLAGS) && !(NCURSES_OPAQUE+0) |
Martin v. Löwis | eb9b103 | 2001-10-24 17:10:49 +0000 | [diff] [blame] | 59 | #define WINDOW_HAS_FLAGS 1 |
| 60 | #endif |
Miss Islington (bot) | 6ba0b58 | 2017-11-01 05:36:48 -0700 | [diff] [blame^] | 61 | #if !defined(HAVE_CURSES_IS_PAD) && NCURSES_VERSION_PATCH+0 >= 20090906 |
| 62 | #define HAVE_CURSES_IS_PAD 1 |
| 63 | #endif |
Martin v. Löwis | eb9b103 | 2001-10-24 17:10:49 +0000 | [diff] [blame] | 64 | #ifndef MVWDELCH_IS_EXPRESSION |
| 65 | #define MVWDELCH_IS_EXPRESSION 1 |
| 66 | #endif |
| 67 | #endif |
| 68 | |
Andrew M. Kuchling | 0c7a0bd | 2000-12-22 21:51:10 +0000 | [diff] [blame] | 69 | #ifdef __cplusplus |
| 70 | extern "C" { |
| 71 | #endif |
| 72 | |
| 73 | #define PyCurses_API_pointers 4 |
| 74 | |
| 75 | /* Type declarations */ |
| 76 | |
| 77 | typedef struct { |
Serhiy Storchaka | e0fc1af | 2017-10-31 16:12:35 +0200 | [diff] [blame] | 78 | PyObject_HEAD |
| 79 | WINDOW *win; |
Andrew M. Kuchling | 0c7a0bd | 2000-12-22 21:51:10 +0000 | [diff] [blame] | 80 | } PyCursesWindowObject; |
| 81 | |
Serhiy Storchaka | e0fc1af | 2017-10-31 16:12:35 +0200 | [diff] [blame] | 82 | #define PyCursesWindow_Check(v) (Py_TYPE(v) == &PyCursesWindow_Type) |
Andrew M. Kuchling | 0c7a0bd | 2000-12-22 21:51:10 +0000 | [diff] [blame] | 83 | |
Larry Hastings | 402b73f | 2010-03-25 00:54:54 +0000 | [diff] [blame] | 84 | #define PyCurses_CAPSULE_NAME "_curses._C_API" |
| 85 | |
| 86 | |
Andrew M. Kuchling | 0c7a0bd | 2000-12-22 21:51:10 +0000 | [diff] [blame] | 87 | #ifdef CURSES_MODULE |
| 88 | /* This section is used when compiling _cursesmodule.c */ |
| 89 | |
| 90 | #else |
| 91 | /* This section is used in modules that use the _cursesmodule API */ |
| 92 | |
| 93 | static void **PyCurses_API; |
| 94 | |
| 95 | #define PyCursesWindow_Type (*(PyTypeObject *) PyCurses_API[0]) |
| 96 | #define PyCursesSetupTermCalled {if (! ((int (*)(void))PyCurses_API[1]) () ) return NULL;} |
| 97 | #define PyCursesInitialised {if (! ((int (*)(void))PyCurses_API[2]) () ) return NULL;} |
| 98 | #define PyCursesInitialisedColor {if (! ((int (*)(void))PyCurses_API[3]) () ) return NULL;} |
| 99 | |
| 100 | #define import_curses() \ |
Larry Hastings | 402b73f | 2010-03-25 00:54:54 +0000 | [diff] [blame] | 101 | PyCurses_API = (void **)PyCapsule_Import(PyCurses_CAPSULE_NAME, 1); |
| 102 | |
Andrew M. Kuchling | 0c7a0bd | 2000-12-22 21:51:10 +0000 | [diff] [blame] | 103 | #endif |
| 104 | |
| 105 | /* general error messages */ |
| 106 | static char *catchall_ERR = "curses function returned ERR"; |
| 107 | static char *catchall_NULL = "curses function returned NULL"; |
| 108 | |
Andrew M. Kuchling | 0c7a0bd | 2000-12-22 21:51:10 +0000 | [diff] [blame] | 109 | /* Function Prototype Macros - They are ugly but very, very useful. ;-) |
| 110 | |
| 111 | X - function name |
| 112 | TYPE - parameter Type |
| 113 | ERGSTR - format string for construction of the return value |
| 114 | PARSESTR - format string for argument parsing |
| 115 | */ |
| 116 | |
| 117 | #define NoArgNoReturnFunction(X) \ |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 118 | static PyObject *PyCurses_ ## X (PyObject *self) \ |
Andrew M. Kuchling | 0c7a0bd | 2000-12-22 21:51:10 +0000 | [diff] [blame] | 119 | { \ |
| 120 | PyCursesInitialised \ |
Andrew M. Kuchling | 0c7a0bd | 2000-12-22 21:51:10 +0000 | [diff] [blame] | 121 | return PyCursesCheckERR(X(), # X); } |
| 122 | |
| 123 | #define NoArgOrFlagNoReturnFunction(X) \ |
| 124 | static PyObject *PyCurses_ ## X (PyObject *self, PyObject *args) \ |
| 125 | { \ |
| 126 | int flag = 0; \ |
| 127 | PyCursesInitialised \ |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 128 | switch(PyTuple_Size(args)) { \ |
Andrew M. Kuchling | 0c7a0bd | 2000-12-22 21:51:10 +0000 | [diff] [blame] | 129 | case 0: \ |
| 130 | return PyCursesCheckERR(X(), # X); \ |
| 131 | case 1: \ |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 132 | 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] | 133 | if (flag) return PyCursesCheckERR(X(), # X); \ |
| 134 | else return PyCursesCheckERR(no ## X (), # X); \ |
| 135 | default: \ |
| 136 | PyErr_SetString(PyExc_TypeError, # X " requires 0 or 1 arguments"); \ |
| 137 | return NULL; } } |
| 138 | |
| 139 | #define NoArgReturnIntFunction(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 | return PyInt_FromLong((long) X()); } |
| 144 | |
| 145 | |
| 146 | #define NoArgReturnStringFunction(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 \ |
Gregory P. Smith | dd96db6 | 2008-06-09 04:58:54 +0000 | [diff] [blame] | 150 | return PyString_FromString(X()); } |
Andrew M. Kuchling | 0c7a0bd | 2000-12-22 21:51:10 +0000 | [diff] [blame] | 151 | |
| 152 | #define NoArgTrueFalseFunction(X) \ |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 153 | static PyObject *PyCurses_ ## X (PyObject *self) \ |
Andrew M. Kuchling | 0c7a0bd | 2000-12-22 21:51:10 +0000 | [diff] [blame] | 154 | { \ |
| 155 | PyCursesInitialised \ |
Andrew M. Kuchling | 0c7a0bd | 2000-12-22 21:51:10 +0000 | [diff] [blame] | 156 | if (X () == FALSE) { \ |
| 157 | Py_INCREF(Py_False); \ |
| 158 | return Py_False; \ |
| 159 | } \ |
| 160 | Py_INCREF(Py_True); \ |
| 161 | return Py_True; } |
| 162 | |
| 163 | #define NoArgNoReturnVoidFunction(X) \ |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 164 | static PyObject *PyCurses_ ## X (PyObject *self) \ |
Andrew M. Kuchling | 0c7a0bd | 2000-12-22 21:51:10 +0000 | [diff] [blame] | 165 | { \ |
| 166 | PyCursesInitialised \ |
Andrew M. Kuchling | 0c7a0bd | 2000-12-22 21:51:10 +0000 | [diff] [blame] | 167 | X(); \ |
| 168 | Py_INCREF(Py_None); \ |
| 169 | return Py_None; } |
| 170 | |
| 171 | #ifdef __cplusplus |
| 172 | } |
| 173 | #endif |
| 174 | |
| 175 | #endif /* !defined(Py_CURSES_H) */ |
| 176 | |
| 177 | |