blob: 67b958c1463ac1e8803fac4a554c47d5a377a5dd [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 Storchakae0fc1af2017-10-31 16:12:35 +020010#ifdef _BSD_WCHAR_T_DEFINED_
Jack Jansen26897bf2002-11-22 16:12:57 +000011#define _WCHAR_T
12#endif
Mark Dickinson6b3f1ef2009-09-06 21:21:05 +000013
14/* the following define is necessary for OS X 10.6; without it, the
15 Apple-supplied ncurses.h sets NCURSES_OPAQUE to 1, and then Python
16 can't get at the WINDOW flags field. */
17#define NCURSES_OPAQUE 0
18#endif /* __APPLE__ */
Jack Jansend00c13a2003-02-28 12:51:18 +000019
Andrew MacIntyre1a901172003-06-11 12:26:08 +000020#ifdef __FreeBSD__
21/*
22** On FreeBSD, [n]curses.h and stdlib.h/wchar.h use different guards
23** against multiple definition of wchar_t and wint_t.
24*/
Serhiy Storchakae0fc1af2017-10-31 16:12:35 +020025#ifdef _XOPEN_SOURCE_EXTENDED
Andrew MacIntyree3454af2003-06-29 15:46:21 +000026#ifndef __FreeBSD_version
27#include <osreldate.h>
28#endif
29#if __FreeBSD_version >= 500000
30#ifndef __wchar_t
31#define __wchar_t
32#endif
33#ifndef __wint_t
34#define __wint_t
35#endif
36#else
Andrew MacIntyre1a901172003-06-11 12:26:08 +000037#ifndef _WCHAR_T
38#define _WCHAR_T
39#endif
40#ifndef _WINT_T
41#define _WINT_T
42#endif
43#endif
44#endif
Andrew MacIntyree3454af2003-06-29 15:46:21 +000045#endif
Andrew MacIntyre1a901172003-06-11 12:26:08 +000046
Jack Jansend00c13a2003-02-28 12:51:18 +000047#ifdef HAVE_NCURSES_H
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +000048#include <ncurses.h>
49#else
50#include <curses.h>
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +000051#endif
52
Martin v. Löwiseb9b1032001-10-24 17:10:49 +000053#ifdef HAVE_NCURSES_H
54/* configure was checking <curses.h>, but we will
55 use <ncurses.h>, which has all these features. */
56#ifndef WINDOW_HAS_FLAGS
57#define WINDOW_HAS_FLAGS 1
58#endif
59#ifndef MVWDELCH_IS_EXPRESSION
60#define MVWDELCH_IS_EXPRESSION 1
61#endif
62#endif
63
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +000064#ifdef __cplusplus
65extern "C" {
66#endif
67
68#define PyCurses_API_pointers 4
69
70/* Type declarations */
71
72typedef struct {
Serhiy Storchakae0fc1af2017-10-31 16:12:35 +020073 PyObject_HEAD
74 WINDOW *win;
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +000075} PyCursesWindowObject;
76
Serhiy Storchakae0fc1af2017-10-31 16:12:35 +020077#define PyCursesWindow_Check(v) (Py_TYPE(v) == &PyCursesWindow_Type)
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +000078
Larry Hastings402b73f2010-03-25 00:54:54 +000079#define PyCurses_CAPSULE_NAME "_curses._C_API"
80
81
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +000082#ifdef CURSES_MODULE
83/* This section is used when compiling _cursesmodule.c */
84
85#else
86/* This section is used in modules that use the _cursesmodule API */
87
88static void **PyCurses_API;
89
90#define PyCursesWindow_Type (*(PyTypeObject *) PyCurses_API[0])
91#define PyCursesSetupTermCalled {if (! ((int (*)(void))PyCurses_API[1]) () ) return NULL;}
92#define PyCursesInitialised {if (! ((int (*)(void))PyCurses_API[2]) () ) return NULL;}
93#define PyCursesInitialisedColor {if (! ((int (*)(void))PyCurses_API[3]) () ) return NULL;}
94
95#define import_curses() \
Larry Hastings402b73f2010-03-25 00:54:54 +000096 PyCurses_API = (void **)PyCapsule_Import(PyCurses_CAPSULE_NAME, 1);
97
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +000098#endif
99
100/* general error messages */
101static char *catchall_ERR = "curses function returned ERR";
102static char *catchall_NULL = "curses function returned NULL";
103
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000104/* Function Prototype Macros - They are ugly but very, very useful. ;-)
105
106 X - function name
107 TYPE - parameter Type
108 ERGSTR - format string for construction of the return value
109 PARSESTR - format string for argument parsing
110 */
111
112#define NoArgNoReturnFunction(X) \
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000113static PyObject *PyCurses_ ## X (PyObject *self) \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000114{ \
115 PyCursesInitialised \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000116 return PyCursesCheckERR(X(), # X); }
117
118#define NoArgOrFlagNoReturnFunction(X) \
119static PyObject *PyCurses_ ## X (PyObject *self, PyObject *args) \
120{ \
121 int flag = 0; \
122 PyCursesInitialised \
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000123 switch(PyTuple_Size(args)) { \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000124 case 0: \
125 return PyCursesCheckERR(X(), # X); \
126 case 1: \
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000127 if (!PyArg_ParseTuple(args, "i;True(1) or False(0)", &flag)) return NULL; \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000128 if (flag) return PyCursesCheckERR(X(), # X); \
129 else return PyCursesCheckERR(no ## X (), # X); \
130 default: \
131 PyErr_SetString(PyExc_TypeError, # X " requires 0 or 1 arguments"); \
132 return NULL; } }
133
134#define NoArgReturnIntFunction(X) \
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000135static PyObject *PyCurses_ ## X (PyObject *self) \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000136{ \
137 PyCursesInitialised \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000138 return PyInt_FromLong((long) X()); }
139
140
141#define NoArgReturnStringFunction(X) \
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000142static PyObject *PyCurses_ ## X (PyObject *self) \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000143{ \
144 PyCursesInitialised \
Gregory P. Smithdd96db62008-06-09 04:58:54 +0000145 return PyString_FromString(X()); }
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000146
147#define NoArgTrueFalseFunction(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 \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000151 if (X () == FALSE) { \
152 Py_INCREF(Py_False); \
153 return Py_False; \
154 } \
155 Py_INCREF(Py_True); \
156 return Py_True; }
157
158#define NoArgNoReturnVoidFunction(X) \
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000159static PyObject *PyCurses_ ## X (PyObject *self) \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000160{ \
161 PyCursesInitialised \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000162 X(); \
163 Py_INCREF(Py_None); \
164 return Py_None; }
165
166#ifdef __cplusplus
167}
168#endif
169
170#endif /* !defined(Py_CURSES_H) */
171
172