blob: 3ecf48fcdff74e8b0a9484a4bdc9443114691f25 [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
13#endif
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*/
20#ifdef _XOPEN_SOURCE_EXTENDED
21#ifndef _WCHAR_T
22#define _WCHAR_T
23#endif
24#ifndef _WINT_T
25#define _WINT_T
26#endif
27#endif
28#endif
29
Jack Jansend00c13a2003-02-28 12:51:18 +000030#ifdef HAVE_NCURSES_H
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +000031#include <ncurses.h>
32#else
33#include <curses.h>
Martin v. Löwis69532332001-10-13 09:12:41 +000034#ifdef HAVE_TERM_H
35/* for tigetstr, which is not declared in SysV curses */
36#include <term.h>
37#endif
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +000038#endif
39
Martin v. Löwiseb9b1032001-10-24 17:10:49 +000040#ifdef HAVE_NCURSES_H
41/* configure was checking <curses.h>, but we will
42 use <ncurses.h>, which has all these features. */
43#ifndef WINDOW_HAS_FLAGS
44#define WINDOW_HAS_FLAGS 1
45#endif
46#ifndef MVWDELCH_IS_EXPRESSION
47#define MVWDELCH_IS_EXPRESSION 1
48#endif
49#endif
50
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +000051#ifdef __cplusplus
52extern "C" {
53#endif
54
55#define PyCurses_API_pointers 4
56
57/* Type declarations */
58
59typedef struct {
60 PyObject_HEAD
61 WINDOW *win;
62} PyCursesWindowObject;
63
64#define PyCursesWindow_Check(v) ((v)->ob_type == &PyCursesWindow_Type)
65
66#ifdef CURSES_MODULE
67/* This section is used when compiling _cursesmodule.c */
68
69#else
70/* This section is used in modules that use the _cursesmodule API */
71
72static void **PyCurses_API;
73
74#define PyCursesWindow_Type (*(PyTypeObject *) PyCurses_API[0])
75#define PyCursesSetupTermCalled {if (! ((int (*)(void))PyCurses_API[1]) () ) return NULL;}
76#define PyCursesInitialised {if (! ((int (*)(void))PyCurses_API[2]) () ) return NULL;}
77#define PyCursesInitialisedColor {if (! ((int (*)(void))PyCurses_API[3]) () ) return NULL;}
78
79#define import_curses() \
80{ \
81 PyObject *module = PyImport_ImportModule("_curses"); \
82 if (module != NULL) { \
83 PyObject *module_dict = PyModule_GetDict(module); \
84 PyObject *c_api_object = PyDict_GetItemString(module_dict, "_C_API"); \
85 if (PyCObject_Check(c_api_object)) { \
86 PyCurses_API = (void **)PyCObject_AsVoidPtr(c_api_object); \
87 } \
88 } \
89}
90#endif
91
92/* general error messages */
93static char *catchall_ERR = "curses function returned ERR";
94static char *catchall_NULL = "curses function returned NULL";
95
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +000096/* Function Prototype Macros - They are ugly but very, very useful. ;-)
97
98 X - function name
99 TYPE - parameter Type
100 ERGSTR - format string for construction of the return value
101 PARSESTR - format string for argument parsing
102 */
103
104#define NoArgNoReturnFunction(X) \
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000105static PyObject *PyCurses_ ## X (PyObject *self) \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000106{ \
107 PyCursesInitialised \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000108 return PyCursesCheckERR(X(), # X); }
109
110#define NoArgOrFlagNoReturnFunction(X) \
111static PyObject *PyCurses_ ## X (PyObject *self, PyObject *args) \
112{ \
113 int flag = 0; \
114 PyCursesInitialised \
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000115 switch(PyTuple_Size(args)) { \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000116 case 0: \
117 return PyCursesCheckERR(X(), # X); \
118 case 1: \
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000119 if (!PyArg_ParseTuple(args, "i;True(1) or False(0)", &flag)) return NULL; \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000120 if (flag) return PyCursesCheckERR(X(), # X); \
121 else return PyCursesCheckERR(no ## X (), # X); \
122 default: \
123 PyErr_SetString(PyExc_TypeError, # X " requires 0 or 1 arguments"); \
124 return NULL; } }
125
126#define NoArgReturnIntFunction(X) \
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000127static PyObject *PyCurses_ ## X (PyObject *self) \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000128{ \
129 PyCursesInitialised \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000130 return PyInt_FromLong((long) X()); }
131
132
133#define NoArgReturnStringFunction(X) \
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000134static PyObject *PyCurses_ ## X (PyObject *self) \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000135{ \
136 PyCursesInitialised \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000137 return PyString_FromString(X()); }
138
139#define NoArgTrueFalseFunction(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 \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000143 if (X () == FALSE) { \
144 Py_INCREF(Py_False); \
145 return Py_False; \
146 } \
147 Py_INCREF(Py_True); \
148 return Py_True; }
149
150#define NoArgNoReturnVoidFunction(X) \
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000151static PyObject *PyCurses_ ## X (PyObject *self) \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000152{ \
153 PyCursesInitialised \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000154 X(); \
155 Py_INCREF(Py_None); \
156 return Py_None; }
157
158#ifdef __cplusplus
159}
160#endif
161
162#endif /* !defined(Py_CURSES_H) */
163
164