blob: f2c08f6413a8635d85728d40301c40dccc83c0cc [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*/
10#ifdef _BSD_WCHAR_T_DEFINED_
11#define _WCHAR_T
12#endif
Mark Dickinson5ea7d642009-09-06 21:24:55 +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*/
25#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>
Martin v. Löwis69532332001-10-13 09:12:41 +000051#ifdef HAVE_TERM_H
52/* for tigetstr, which is not declared in SysV curses */
53#include <term.h>
54#endif
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +000055#endif
56
Martin v. Löwiseb9b1032001-10-24 17:10:49 +000057#ifdef HAVE_NCURSES_H
58/* configure was checking <curses.h>, but we will
59 use <ncurses.h>, which has all these features. */
60#ifndef WINDOW_HAS_FLAGS
61#define WINDOW_HAS_FLAGS 1
62#endif
63#ifndef MVWDELCH_IS_EXPRESSION
64#define MVWDELCH_IS_EXPRESSION 1
65#endif
66#endif
67
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +000068#ifdef __cplusplus
69extern "C" {
70#endif
71
72#define PyCurses_API_pointers 4
73
74/* Type declarations */
75
76typedef struct {
77 PyObject_HEAD
78 WINDOW *win;
Victor Stinner0fdfceb2011-11-25 22:10:02 +010079 char *encoding;
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +000080} PyCursesWindowObject;
81
Christian Heimes90aa7642007-12-19 02:45:37 +000082#define PyCursesWindow_Check(v) (Py_TYPE(v) == &PyCursesWindow_Type)
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +000083
Benjamin Petersonb173f782009-05-05 22:31:58 +000084#define PyCurses_CAPSULE_NAME "_curses._C_API"
85
86
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +000087#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
93static 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() \
Benjamin Petersonb173f782009-05-05 22:31:58 +0000101 PyCurses_API = (void **)PyCapsule_Import(PyCurses_CAPSULE_NAME, 1);
102
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000103#endif
104
105/* general error messages */
106static char *catchall_ERR = "curses function returned ERR";
107static char *catchall_NULL = "curses function returned NULL";
108
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000109/* 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öwisc0e16712002-01-17 23:08:27 +0000118static PyObject *PyCurses_ ## X (PyObject *self) \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000119{ \
120 PyCursesInitialised \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000121 return PyCursesCheckERR(X(), # X); }
122
123#define NoArgOrFlagNoReturnFunction(X) \
124static PyObject *PyCurses_ ## X (PyObject *self, PyObject *args) \
125{ \
126 int flag = 0; \
127 PyCursesInitialised \
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000128 switch(PyTuple_Size(args)) { \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000129 case 0: \
130 return PyCursesCheckERR(X(), # X); \
131 case 1: \
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000132 if (!PyArg_ParseTuple(args, "i;True(1) or False(0)", &flag)) return NULL; \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000133 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öwisc0e16712002-01-17 23:08:27 +0000140static PyObject *PyCurses_ ## X (PyObject *self) \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000141{ \
142 PyCursesInitialised \
Christian Heimes217cfd12007-12-02 14:31:20 +0000143 return PyLong_FromLong((long) X()); }
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000144
145
146#define NoArgReturnStringFunction(X) \
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000147static PyObject *PyCurses_ ## X (PyObject *self) \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000148{ \
149 PyCursesInitialised \
Christian Heimes72b710a2008-05-26 13:28:38 +0000150 return PyBytes_FromString(X()); }
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000151
152#define NoArgTrueFalseFunction(X) \
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000153static PyObject *PyCurses_ ## X (PyObject *self) \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000154{ \
155 PyCursesInitialised \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000156 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öwisc0e16712002-01-17 23:08:27 +0000164static PyObject *PyCurses_ ## X (PyObject *self) \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000165{ \
166 PyCursesInitialised \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000167 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