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 | baac01e | 2017-10-31 13:56:44 +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 | 5ea7d64 | 2009-09-06 21:24:55 +0000 | [diff] [blame] | 13 | #endif /* __APPLE__ */ |
Jack Jansen | d00c13a | 2003-02-28 12:51:18 +0000 | [diff] [blame] | 14 | |
Victor Stinner | 13ff245 | 2018-01-22 18:32:50 +0100 | [diff] [blame] | 15 | /* On FreeBSD, [n]curses.h and stdlib.h/wchar.h use different guards |
| 16 | against multiple definition of wchar_t and wint_t. */ |
| 17 | #if defined(__FreeBSD__) && defined(_XOPEN_SOURCE_EXTENDED) |
| 18 | # ifndef __wchar_t |
| 19 | # define __wchar_t |
| 20 | # endif |
| 21 | # ifndef __wint_t |
| 22 | # define __wint_t |
| 23 | # endif |
Andrew MacIntyre | e3454af | 2003-06-29 15:46:21 +0000 | [diff] [blame] | 24 | #endif |
Andrew MacIntyre | 1a90117 | 2003-06-11 12:26:08 +0000 | [diff] [blame] | 25 | |
Masayuki Yamamoto | 8bc7d63 | 2017-11-01 21:05:26 +0900 | [diff] [blame] | 26 | #if !defined(HAVE_CURSES_IS_PAD) && defined(WINDOW_HAS_FLAGS) |
| 27 | /* The following definition is necessary for ncurses 5.7; without it, |
| 28 | some of [n]curses.h set NCURSES_OPAQUE to 1, and then Python |
| 29 | can't get at the WINDOW flags field. */ |
| 30 | #define NCURSES_OPAQUE 0 |
| 31 | #endif |
| 32 | |
Jack Jansen | d00c13a | 2003-02-28 12:51:18 +0000 | [diff] [blame] | 33 | #ifdef HAVE_NCURSES_H |
Andrew M. Kuchling | 0c7a0bd | 2000-12-22 21:51:10 +0000 | [diff] [blame] | 34 | #include <ncurses.h> |
| 35 | #else |
| 36 | #include <curses.h> |
Andrew M. Kuchling | 0c7a0bd | 2000-12-22 21:51:10 +0000 | [diff] [blame] | 37 | #endif |
| 38 | |
Martin v. Löwis | eb9b103 | 2001-10-24 17:10:49 +0000 | [diff] [blame] | 39 | #ifdef HAVE_NCURSES_H |
| 40 | /* configure was checking <curses.h>, but we will |
Masayuki Yamamoto | 8bc7d63 | 2017-11-01 21:05:26 +0900 | [diff] [blame] | 41 | use <ncurses.h>, which has some or all these features. */ |
| 42 | #if !defined(WINDOW_HAS_FLAGS) && !(NCURSES_OPAQUE+0) |
Martin v. Löwis | eb9b103 | 2001-10-24 17:10:49 +0000 | [diff] [blame] | 43 | #define WINDOW_HAS_FLAGS 1 |
| 44 | #endif |
Masayuki Yamamoto | 8bc7d63 | 2017-11-01 21:05:26 +0900 | [diff] [blame] | 45 | #if !defined(HAVE_CURSES_IS_PAD) && NCURSES_VERSION_PATCH+0 >= 20090906 |
| 46 | #define HAVE_CURSES_IS_PAD 1 |
| 47 | #endif |
Martin v. Löwis | eb9b103 | 2001-10-24 17:10:49 +0000 | [diff] [blame] | 48 | #ifndef MVWDELCH_IS_EXPRESSION |
| 49 | #define MVWDELCH_IS_EXPRESSION 1 |
| 50 | #endif |
| 51 | #endif |
| 52 | |
Andrew M. Kuchling | 0c7a0bd | 2000-12-22 21:51:10 +0000 | [diff] [blame] | 53 | #ifdef __cplusplus |
| 54 | extern "C" { |
| 55 | #endif |
| 56 | |
| 57 | #define PyCurses_API_pointers 4 |
| 58 | |
| 59 | /* Type declarations */ |
| 60 | |
| 61 | typedef struct { |
Serhiy Storchaka | baac01e | 2017-10-31 13:56:44 +0200 | [diff] [blame] | 62 | PyObject_HEAD |
| 63 | WINDOW *win; |
| 64 | char *encoding; |
Andrew M. Kuchling | 0c7a0bd | 2000-12-22 21:51:10 +0000 | [diff] [blame] | 65 | } PyCursesWindowObject; |
| 66 | |
Serhiy Storchaka | baac01e | 2017-10-31 13:56:44 +0200 | [diff] [blame] | 67 | #define PyCursesWindow_Check(v) (Py_TYPE(v) == &PyCursesWindow_Type) |
Andrew M. Kuchling | 0c7a0bd | 2000-12-22 21:51:10 +0000 | [diff] [blame] | 68 | |
Benjamin Peterson | b173f78 | 2009-05-05 22:31:58 +0000 | [diff] [blame] | 69 | #define PyCurses_CAPSULE_NAME "_curses._C_API" |
| 70 | |
| 71 | |
Andrew M. Kuchling | 0c7a0bd | 2000-12-22 21:51:10 +0000 | [diff] [blame] | 72 | #ifdef CURSES_MODULE |
| 73 | /* This section is used when compiling _cursesmodule.c */ |
| 74 | |
| 75 | #else |
| 76 | /* This section is used in modules that use the _cursesmodule API */ |
| 77 | |
| 78 | static void **PyCurses_API; |
| 79 | |
| 80 | #define PyCursesWindow_Type (*(PyTypeObject *) PyCurses_API[0]) |
| 81 | #define PyCursesSetupTermCalled {if (! ((int (*)(void))PyCurses_API[1]) () ) return NULL;} |
| 82 | #define PyCursesInitialised {if (! ((int (*)(void))PyCurses_API[2]) () ) return NULL;} |
| 83 | #define PyCursesInitialisedColor {if (! ((int (*)(void))PyCurses_API[3]) () ) return NULL;} |
| 84 | |
| 85 | #define import_curses() \ |
Benjamin Peterson | b173f78 | 2009-05-05 22:31:58 +0000 | [diff] [blame] | 86 | PyCurses_API = (void **)PyCapsule_Import(PyCurses_CAPSULE_NAME, 1); |
| 87 | |
Andrew M. Kuchling | 0c7a0bd | 2000-12-22 21:51:10 +0000 | [diff] [blame] | 88 | #endif |
| 89 | |
| 90 | /* general error messages */ |
Serhiy Storchaka | 2d06e84 | 2015-12-25 19:53:18 +0200 | [diff] [blame] | 91 | static const char catchall_ERR[] = "curses function returned ERR"; |
| 92 | static const char catchall_NULL[] = "curses function returned NULL"; |
Andrew M. Kuchling | 0c7a0bd | 2000-12-22 21:51:10 +0000 | [diff] [blame] | 93 | |
Andrew M. Kuchling | 0c7a0bd | 2000-12-22 21:51:10 +0000 | [diff] [blame] | 94 | /* Function Prototype Macros - They are ugly but very, very useful. ;-) |
| 95 | |
| 96 | X - function name |
| 97 | TYPE - parameter Type |
| 98 | ERGSTR - format string for construction of the return value |
| 99 | PARSESTR - format string for argument parsing |
| 100 | */ |
| 101 | |
| 102 | #define NoArgNoReturnFunction(X) \ |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 103 | static PyObject *PyCurses_ ## X (PyObject *self) \ |
Andrew M. Kuchling | 0c7a0bd | 2000-12-22 21:51:10 +0000 | [diff] [blame] | 104 | { \ |
| 105 | PyCursesInitialised \ |
Andrew M. Kuchling | 0c7a0bd | 2000-12-22 21:51:10 +0000 | [diff] [blame] | 106 | return PyCursesCheckERR(X(), # X); } |
| 107 | |
| 108 | #define NoArgOrFlagNoReturnFunction(X) \ |
| 109 | static PyObject *PyCurses_ ## X (PyObject *self, PyObject *args) \ |
| 110 | { \ |
| 111 | int flag = 0; \ |
| 112 | PyCursesInitialised \ |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 113 | switch(PyTuple_Size(args)) { \ |
Andrew M. Kuchling | 0c7a0bd | 2000-12-22 21:51:10 +0000 | [diff] [blame] | 114 | case 0: \ |
| 115 | return PyCursesCheckERR(X(), # X); \ |
| 116 | case 1: \ |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 117 | 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] | 118 | if (flag) return PyCursesCheckERR(X(), # X); \ |
| 119 | else return PyCursesCheckERR(no ## X (), # X); \ |
| 120 | default: \ |
| 121 | PyErr_SetString(PyExc_TypeError, # X " requires 0 or 1 arguments"); \ |
| 122 | return NULL; } } |
| 123 | |
| 124 | #define NoArgReturnIntFunction(X) \ |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 125 | static PyObject *PyCurses_ ## X (PyObject *self) \ |
Andrew M. Kuchling | 0c7a0bd | 2000-12-22 21:51:10 +0000 | [diff] [blame] | 126 | { \ |
| 127 | PyCursesInitialised \ |
Christian Heimes | 217cfd1 | 2007-12-02 14:31:20 +0000 | [diff] [blame] | 128 | return PyLong_FromLong((long) X()); } |
Andrew M. Kuchling | 0c7a0bd | 2000-12-22 21:51:10 +0000 | [diff] [blame] | 129 | |
| 130 | |
| 131 | #define NoArgReturnStringFunction(X) \ |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 132 | static PyObject *PyCurses_ ## X (PyObject *self) \ |
Andrew M. Kuchling | 0c7a0bd | 2000-12-22 21:51:10 +0000 | [diff] [blame] | 133 | { \ |
| 134 | PyCursesInitialised \ |
Christian Heimes | 72b710a | 2008-05-26 13:28:38 +0000 | [diff] [blame] | 135 | return PyBytes_FromString(X()); } |
Andrew M. Kuchling | 0c7a0bd | 2000-12-22 21:51:10 +0000 | [diff] [blame] | 136 | |
| 137 | #define NoArgTrueFalseFunction(X) \ |
Martin v. Löwis | c0e1671 | 2002-01-17 23:08:27 +0000 | [diff] [blame] | 138 | static PyObject *PyCurses_ ## X (PyObject *self) \ |
Andrew M. Kuchling | 0c7a0bd | 2000-12-22 21:51:10 +0000 | [diff] [blame] | 139 | { \ |
| 140 | PyCursesInitialised \ |
Andrew M. Kuchling | 0c7a0bd | 2000-12-22 21:51:10 +0000 | [diff] [blame] | 141 | if (X () == FALSE) { \ |
Serhiy Storchaka | d1302c0 | 2017-01-23 10:23:58 +0200 | [diff] [blame] | 142 | Py_RETURN_FALSE; \ |
Andrew M. Kuchling | 0c7a0bd | 2000-12-22 21:51:10 +0000 | [diff] [blame] | 143 | } \ |
Serhiy Storchaka | d1302c0 | 2017-01-23 10:23:58 +0200 | [diff] [blame] | 144 | Py_RETURN_TRUE; } |
Andrew M. Kuchling | 0c7a0bd | 2000-12-22 21:51:10 +0000 | [diff] [blame] | 145 | |
| 146 | #define NoArgNoReturnVoidFunction(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 | X(); \ |
Serhiy Storchaka | d1302c0 | 2017-01-23 10:23:58 +0200 | [diff] [blame] | 151 | Py_RETURN_NONE; } |
Andrew M. Kuchling | 0c7a0bd | 2000-12-22 21:51:10 +0000 | [diff] [blame] | 152 | |
| 153 | #ifdef __cplusplus |
| 154 | } |
| 155 | #endif |
| 156 | |
| 157 | #endif /* !defined(Py_CURSES_H) */ |
| 158 | |
| 159 | |