blob: 597f419eaca9a8e15cd2d6a70ccc888ce57c5214 [file] [log] [blame]
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +00001
2#ifndef Py_CURSES_H
3#define Py_CURSES_H
4
Jack Jansen26897bf2002-11-22 16:12:57 +00005#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 Storchakabaac01e2017-10-31 13:56:44 +020010#ifdef _BSD_WCHAR_T_DEFINED_
Jack Jansen26897bf2002-11-22 16:12:57 +000011#define _WCHAR_T
12#endif
Mark Dickinson5ea7d642009-09-06 21:24:55 +000013#endif /* __APPLE__ */
Jack Jansend00c13a2003-02-28 12:51:18 +000014
Andrew MacIntyre1a901172003-06-11 12:26:08 +000015#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 Storchakabaac01e2017-10-31 13:56:44 +020020#ifdef _XOPEN_SOURCE_EXTENDED
Andrew MacIntyree3454af2003-06-29 15:46:21 +000021#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 MacIntyre1a901172003-06-11 12:26:08 +000032#ifndef _WCHAR_T
33#define _WCHAR_T
34#endif
35#ifndef _WINT_T
36#define _WINT_T
37#endif
38#endif
39#endif
Andrew MacIntyree3454af2003-06-29 15:46:21 +000040#endif
Andrew MacIntyre1a901172003-06-11 12:26:08 +000041
Masayuki Yamamoto8bc7d632017-11-01 21:05:26 +090042#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 Jansend00c13a2003-02-28 12:51:18 +000049#ifdef HAVE_NCURSES_H
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +000050#include <ncurses.h>
51#else
52#include <curses.h>
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +000053#endif
54
Martin v. Löwiseb9b1032001-10-24 17:10:49 +000055#ifdef HAVE_NCURSES_H
56/* configure was checking <curses.h>, but we will
Masayuki Yamamoto8bc7d632017-11-01 21:05:26 +090057 use <ncurses.h>, which has some or all these features. */
58#if !defined(WINDOW_HAS_FLAGS) && !(NCURSES_OPAQUE+0)
Martin v. Löwiseb9b1032001-10-24 17:10:49 +000059#define WINDOW_HAS_FLAGS 1
60#endif
Masayuki Yamamoto8bc7d632017-11-01 21:05:26 +090061#if !defined(HAVE_CURSES_IS_PAD) && NCURSES_VERSION_PATCH+0 >= 20090906
62#define HAVE_CURSES_IS_PAD 1
63#endif
Martin v. Löwiseb9b1032001-10-24 17:10:49 +000064#ifndef MVWDELCH_IS_EXPRESSION
65#define MVWDELCH_IS_EXPRESSION 1
66#endif
67#endif
68
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +000069#ifdef __cplusplus
70extern "C" {
71#endif
72
73#define PyCurses_API_pointers 4
74
75/* Type declarations */
76
77typedef struct {
Serhiy Storchakabaac01e2017-10-31 13:56:44 +020078 PyObject_HEAD
79 WINDOW *win;
80 char *encoding;
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +000081} PyCursesWindowObject;
82
Serhiy Storchakabaac01e2017-10-31 13:56:44 +020083#define PyCursesWindow_Check(v) (Py_TYPE(v) == &PyCursesWindow_Type)
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +000084
Benjamin Petersonb173f782009-05-05 22:31:58 +000085#define PyCurses_CAPSULE_NAME "_curses._C_API"
86
87
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +000088#ifdef CURSES_MODULE
89/* This section is used when compiling _cursesmodule.c */
90
91#else
92/* This section is used in modules that use the _cursesmodule API */
93
94static void **PyCurses_API;
95
96#define PyCursesWindow_Type (*(PyTypeObject *) PyCurses_API[0])
97#define PyCursesSetupTermCalled {if (! ((int (*)(void))PyCurses_API[1]) () ) return NULL;}
98#define PyCursesInitialised {if (! ((int (*)(void))PyCurses_API[2]) () ) return NULL;}
99#define PyCursesInitialisedColor {if (! ((int (*)(void))PyCurses_API[3]) () ) return NULL;}
100
101#define import_curses() \
Benjamin Petersonb173f782009-05-05 22:31:58 +0000102 PyCurses_API = (void **)PyCapsule_Import(PyCurses_CAPSULE_NAME, 1);
103
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000104#endif
105
106/* general error messages */
Serhiy Storchaka2d06e842015-12-25 19:53:18 +0200107static const char catchall_ERR[] = "curses function returned ERR";
108static const char catchall_NULL[] = "curses function returned NULL";
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000109
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000110/* Function Prototype Macros - They are ugly but very, very useful. ;-)
111
112 X - function name
113 TYPE - parameter Type
114 ERGSTR - format string for construction of the return value
115 PARSESTR - format string for argument parsing
116 */
117
118#define NoArgNoReturnFunction(X) \
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000119static PyObject *PyCurses_ ## X (PyObject *self) \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000120{ \
121 PyCursesInitialised \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000122 return PyCursesCheckERR(X(), # X); }
123
124#define NoArgOrFlagNoReturnFunction(X) \
125static PyObject *PyCurses_ ## X (PyObject *self, PyObject *args) \
126{ \
127 int flag = 0; \
128 PyCursesInitialised \
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000129 switch(PyTuple_Size(args)) { \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000130 case 0: \
131 return PyCursesCheckERR(X(), # X); \
132 case 1: \
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000133 if (!PyArg_ParseTuple(args, "i;True(1) or False(0)", &flag)) return NULL; \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000134 if (flag) return PyCursesCheckERR(X(), # X); \
135 else return PyCursesCheckERR(no ## X (), # X); \
136 default: \
137 PyErr_SetString(PyExc_TypeError, # X " requires 0 or 1 arguments"); \
138 return NULL; } }
139
140#define NoArgReturnIntFunction(X) \
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000141static PyObject *PyCurses_ ## X (PyObject *self) \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000142{ \
143 PyCursesInitialised \
Christian Heimes217cfd12007-12-02 14:31:20 +0000144 return PyLong_FromLong((long) X()); }
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000145
146
147#define NoArgReturnStringFunction(X) \
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000148static PyObject *PyCurses_ ## X (PyObject *self) \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000149{ \
150 PyCursesInitialised \
Christian Heimes72b710a2008-05-26 13:28:38 +0000151 return PyBytes_FromString(X()); }
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000152
153#define NoArgTrueFalseFunction(X) \
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000154static PyObject *PyCurses_ ## X (PyObject *self) \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000155{ \
156 PyCursesInitialised \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000157 if (X () == FALSE) { \
Serhiy Storchakad1302c02017-01-23 10:23:58 +0200158 Py_RETURN_FALSE; \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000159 } \
Serhiy Storchakad1302c02017-01-23 10:23:58 +0200160 Py_RETURN_TRUE; }
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000161
162#define NoArgNoReturnVoidFunction(X) \
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000163static PyObject *PyCurses_ ## X (PyObject *self) \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000164{ \
165 PyCursesInitialised \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000166 X(); \
Serhiy Storchakad1302c02017-01-23 10:23:58 +0200167 Py_RETURN_NONE; }
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000168
169#ifdef __cplusplus
170}
171#endif
172
173#endif /* !defined(Py_CURSES_H) */
174
175