blob: 9a89c50e7eb76303428c19d24caf52d7cf8f9520 [file] [log] [blame]
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +00001
2#ifndef Py_CURSES_H
3#define Py_CURSES_H
4
5#ifdef HAVE_NCURSES_H
Jack Jansen26897bf2002-11-22 16:12:57 +00006#ifdef __APPLE__
7/*
8** On Mac OS X 10.2 [n]curses.h and stdlib.h use different guards
9** against multiple definition of wchar_t.
10*/
11#ifdef _BSD_WCHAR_T_DEFINED_
12#define _WCHAR_T
13#endif
14#endif
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +000015#include <ncurses.h>
16#else
17#include <curses.h>
Martin v. Löwis69532332001-10-13 09:12:41 +000018#ifdef HAVE_TERM_H
19/* for tigetstr, which is not declared in SysV curses */
20#include <term.h>
21#endif
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +000022#endif
23
Martin v. Löwiseb9b1032001-10-24 17:10:49 +000024#ifdef HAVE_NCURSES_H
25/* configure was checking <curses.h>, but we will
26 use <ncurses.h>, which has all these features. */
27#ifndef WINDOW_HAS_FLAGS
28#define WINDOW_HAS_FLAGS 1
29#endif
30#ifndef MVWDELCH_IS_EXPRESSION
31#define MVWDELCH_IS_EXPRESSION 1
32#endif
33#endif
34
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +000035#ifdef __cplusplus
36extern "C" {
37#endif
38
39#define PyCurses_API_pointers 4
40
41/* Type declarations */
42
43typedef struct {
44 PyObject_HEAD
45 WINDOW *win;
46} PyCursesWindowObject;
47
48#define PyCursesWindow_Check(v) ((v)->ob_type == &PyCursesWindow_Type)
49
50#ifdef CURSES_MODULE
51/* This section is used when compiling _cursesmodule.c */
52
53#else
54/* This section is used in modules that use the _cursesmodule API */
55
56static void **PyCurses_API;
57
58#define PyCursesWindow_Type (*(PyTypeObject *) PyCurses_API[0])
59#define PyCursesSetupTermCalled {if (! ((int (*)(void))PyCurses_API[1]) () ) return NULL;}
60#define PyCursesInitialised {if (! ((int (*)(void))PyCurses_API[2]) () ) return NULL;}
61#define PyCursesInitialisedColor {if (! ((int (*)(void))PyCurses_API[3]) () ) return NULL;}
62
63#define import_curses() \
64{ \
65 PyObject *module = PyImport_ImportModule("_curses"); \
66 if (module != NULL) { \
67 PyObject *module_dict = PyModule_GetDict(module); \
68 PyObject *c_api_object = PyDict_GetItemString(module_dict, "_C_API"); \
69 if (PyCObject_Check(c_api_object)) { \
70 PyCurses_API = (void **)PyCObject_AsVoidPtr(c_api_object); \
71 } \
72 } \
73}
74#endif
75
76/* general error messages */
77static char *catchall_ERR = "curses function returned ERR";
78static char *catchall_NULL = "curses function returned NULL";
79
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +000080/* Function Prototype Macros - They are ugly but very, very useful. ;-)
81
82 X - function name
83 TYPE - parameter Type
84 ERGSTR - format string for construction of the return value
85 PARSESTR - format string for argument parsing
86 */
87
88#define NoArgNoReturnFunction(X) \
Martin v. Löwisc0e16712002-01-17 23:08:27 +000089static PyObject *PyCurses_ ## X (PyObject *self) \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +000090{ \
91 PyCursesInitialised \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +000092 return PyCursesCheckERR(X(), # X); }
93
94#define NoArgOrFlagNoReturnFunction(X) \
95static PyObject *PyCurses_ ## X (PyObject *self, PyObject *args) \
96{ \
97 int flag = 0; \
98 PyCursesInitialised \
Martin v. Löwisc0e16712002-01-17 23:08:27 +000099 switch(PyTuple_Size(args)) { \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000100 case 0: \
101 return PyCursesCheckERR(X(), # X); \
102 case 1: \
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000103 if (!PyArg_ParseTuple(args, "i;True(1) or False(0)", &flag)) return NULL; \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000104 if (flag) return PyCursesCheckERR(X(), # X); \
105 else return PyCursesCheckERR(no ## X (), # X); \
106 default: \
107 PyErr_SetString(PyExc_TypeError, # X " requires 0 or 1 arguments"); \
108 return NULL; } }
109
110#define NoArgReturnIntFunction(X) \
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000111static PyObject *PyCurses_ ## X (PyObject *self) \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000112{ \
113 PyCursesInitialised \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000114 return PyInt_FromLong((long) X()); }
115
116
117#define NoArgReturnStringFunction(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 PyString_FromString(X()); }
122
123#define NoArgTrueFalseFunction(X) \
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000124static PyObject *PyCurses_ ## X (PyObject *self) \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000125{ \
126 PyCursesInitialised \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000127 if (X () == FALSE) { \
128 Py_INCREF(Py_False); \
129 return Py_False; \
130 } \
131 Py_INCREF(Py_True); \
132 return Py_True; }
133
134#define NoArgNoReturnVoidFunction(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 X(); \
139 Py_INCREF(Py_None); \
140 return Py_None; }
141
142#ifdef __cplusplus
143}
144#endif
145
146#endif /* !defined(Py_CURSES_H) */
147
148