blob: 713a24fadc31f973e728afc6f7926e9b56981e77 [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
15#ifdef HAVE_NCURSES_H
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +000016#include <ncurses.h>
17#else
18#include <curses.h>
Martin v. Löwis69532332001-10-13 09:12:41 +000019#ifdef HAVE_TERM_H
20/* for tigetstr, which is not declared in SysV curses */
21#include <term.h>
22#endif
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +000023#endif
24
Martin v. Löwiseb9b1032001-10-24 17:10:49 +000025#ifdef HAVE_NCURSES_H
26/* configure was checking <curses.h>, but we will
27 use <ncurses.h>, which has all these features. */
28#ifndef WINDOW_HAS_FLAGS
29#define WINDOW_HAS_FLAGS 1
30#endif
31#ifndef MVWDELCH_IS_EXPRESSION
32#define MVWDELCH_IS_EXPRESSION 1
33#endif
34#endif
35
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +000036#ifdef __cplusplus
37extern "C" {
38#endif
39
40#define PyCurses_API_pointers 4
41
42/* Type declarations */
43
44typedef struct {
45 PyObject_HEAD
46 WINDOW *win;
47} PyCursesWindowObject;
48
49#define PyCursesWindow_Check(v) ((v)->ob_type == &PyCursesWindow_Type)
50
51#ifdef CURSES_MODULE
52/* This section is used when compiling _cursesmodule.c */
53
54#else
55/* This section is used in modules that use the _cursesmodule API */
56
57static void **PyCurses_API;
58
59#define PyCursesWindow_Type (*(PyTypeObject *) PyCurses_API[0])
60#define PyCursesSetupTermCalled {if (! ((int (*)(void))PyCurses_API[1]) () ) return NULL;}
61#define PyCursesInitialised {if (! ((int (*)(void))PyCurses_API[2]) () ) return NULL;}
62#define PyCursesInitialisedColor {if (! ((int (*)(void))PyCurses_API[3]) () ) return NULL;}
63
64#define import_curses() \
65{ \
66 PyObject *module = PyImport_ImportModule("_curses"); \
67 if (module != NULL) { \
68 PyObject *module_dict = PyModule_GetDict(module); \
69 PyObject *c_api_object = PyDict_GetItemString(module_dict, "_C_API"); \
70 if (PyCObject_Check(c_api_object)) { \
71 PyCurses_API = (void **)PyCObject_AsVoidPtr(c_api_object); \
72 } \
73 } \
74}
75#endif
76
77/* general error messages */
78static char *catchall_ERR = "curses function returned ERR";
79static char *catchall_NULL = "curses function returned NULL";
80
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +000081/* Function Prototype Macros - They are ugly but very, very useful. ;-)
82
83 X - function name
84 TYPE - parameter Type
85 ERGSTR - format string for construction of the return value
86 PARSESTR - format string for argument parsing
87 */
88
89#define NoArgNoReturnFunction(X) \
Martin v. Löwisc0e16712002-01-17 23:08:27 +000090static PyObject *PyCurses_ ## X (PyObject *self) \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +000091{ \
92 PyCursesInitialised \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +000093 return PyCursesCheckERR(X(), # X); }
94
95#define NoArgOrFlagNoReturnFunction(X) \
96static PyObject *PyCurses_ ## X (PyObject *self, PyObject *args) \
97{ \
98 int flag = 0; \
99 PyCursesInitialised \
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000100 switch(PyTuple_Size(args)) { \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000101 case 0: \
102 return PyCursesCheckERR(X(), # X); \
103 case 1: \
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000104 if (!PyArg_ParseTuple(args, "i;True(1) or False(0)", &flag)) return NULL; \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000105 if (flag) return PyCursesCheckERR(X(), # X); \
106 else return PyCursesCheckERR(no ## X (), # X); \
107 default: \
108 PyErr_SetString(PyExc_TypeError, # X " requires 0 or 1 arguments"); \
109 return NULL; } }
110
111#define NoArgReturnIntFunction(X) \
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000112static PyObject *PyCurses_ ## X (PyObject *self) \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000113{ \
114 PyCursesInitialised \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000115 return PyInt_FromLong((long) X()); }
116
117
118#define NoArgReturnStringFunction(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 PyString_FromString(X()); }
123
124#define NoArgTrueFalseFunction(X) \
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000125static PyObject *PyCurses_ ## X (PyObject *self) \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000126{ \
127 PyCursesInitialised \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000128 if (X () == FALSE) { \
129 Py_INCREF(Py_False); \
130 return Py_False; \
131 } \
132 Py_INCREF(Py_True); \
133 return Py_True; }
134
135#define NoArgNoReturnVoidFunction(X) \
Martin v. Löwisc0e16712002-01-17 23:08:27 +0000136static PyObject *PyCurses_ ## X (PyObject *self) \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000137{ \
138 PyCursesInitialised \
Andrew M. Kuchling0c7a0bd2000-12-22 21:51:10 +0000139 X(); \
140 Py_INCREF(Py_None); \
141 return Py_None; }
142
143#ifdef __cplusplus
144}
145#endif
146
147#endif /* !defined(Py_CURSES_H) */
148
149