summaryrefslogtreecommitdiffstats
path: root/Include/py_curses.h
diff options
context:
space:
mode:
Diffstat (limited to 'Include/py_curses.h')
-rw-r--r--Include/py_curses.h101
1 files changed, 89 insertions, 12 deletions
diff --git a/Include/py_curses.h b/Include/py_curses.h
index 2702b37..eb77e35 100644
--- a/Include/py_curses.h
+++ b/Include/py_curses.h
@@ -12,15 +12,31 @@
#endif
#endif /* __APPLE__ */
-/* On FreeBSD, [n]curses.h and stdlib.h/wchar.h use different guards
- against multiple definition of wchar_t and wint_t. */
-#if defined(__FreeBSD__) && defined(_XOPEN_SOURCE_EXTENDED)
-# ifndef __wchar_t
-# define __wchar_t
-# endif
-# ifndef __wint_t
-# define __wint_t
-# endif
+#ifdef __FreeBSD__
+/*
+** On FreeBSD, [n]curses.h and stdlib.h/wchar.h use different guards
+** against multiple definition of wchar_t and wint_t.
+*/
+#ifdef _XOPEN_SOURCE_EXTENDED
+#ifndef __FreeBSD_version
+#include <osreldate.h>
+#endif
+#if __FreeBSD_version >= 500000
+#ifndef __wchar_t
+#define __wchar_t
+#endif
+#ifndef __wint_t
+#define __wint_t
+#endif
+#else
+#ifndef _WCHAR_T
+#define _WCHAR_T
+#endif
+#ifndef _WINT_T
+#define _WINT_T
+#endif
+#endif
+#endif
#endif
#if !defined(HAVE_CURSES_IS_PAD) && defined(WINDOW_HAS_FLAGS)
@@ -61,7 +77,6 @@ extern "C" {
typedef struct {
PyObject_HEAD
WINDOW *win;
- char *encoding;
} PyCursesWindowObject;
#define PyCursesWindow_Check(v) (Py_TYPE(v) == &PyCursesWindow_Type)
@@ -88,8 +103,70 @@ static void **PyCurses_API;
#endif
/* general error messages */
-static const char catchall_ERR[] = "curses function returned ERR";
-static const char catchall_NULL[] = "curses function returned NULL";
+static char *catchall_ERR = "curses function returned ERR";
+static char *catchall_NULL = "curses function returned NULL";
+
+/* Function Prototype Macros - They are ugly but very, very useful. ;-)
+
+ X - function name
+ TYPE - parameter Type
+ ERGSTR - format string for construction of the return value
+ PARSESTR - format string for argument parsing
+ */
+
+#define NoArgNoReturnFunction(X) \
+static PyObject *PyCurses_ ## X (PyObject *self) \
+{ \
+ PyCursesInitialised \
+ return PyCursesCheckERR(X(), # X); }
+
+#define NoArgOrFlagNoReturnFunction(X) \
+static PyObject *PyCurses_ ## X (PyObject *self, PyObject *args) \
+{ \
+ int flag = 0; \
+ PyCursesInitialised \
+ switch(PyTuple_Size(args)) { \
+ case 0: \
+ return PyCursesCheckERR(X(), # X); \
+ case 1: \
+ if (!PyArg_ParseTuple(args, "i;True(1) or False(0)", &flag)) return NULL; \
+ if (flag) return PyCursesCheckERR(X(), # X); \
+ else return PyCursesCheckERR(no ## X (), # X); \
+ default: \
+ PyErr_SetString(PyExc_TypeError, # X " requires 0 or 1 arguments"); \
+ return NULL; } }
+
+#define NoArgReturnIntFunction(X) \
+static PyObject *PyCurses_ ## X (PyObject *self) \
+{ \
+ PyCursesInitialised \
+ return PyInt_FromLong((long) X()); }
+
+
+#define NoArgReturnStringFunction(X) \
+static PyObject *PyCurses_ ## X (PyObject *self) \
+{ \
+ PyCursesInitialised \
+ return PyString_FromString(X()); }
+
+#define NoArgTrueFalseFunction(X) \
+static PyObject *PyCurses_ ## X (PyObject *self) \
+{ \
+ PyCursesInitialised \
+ if (X () == FALSE) { \
+ Py_INCREF(Py_False); \
+ return Py_False; \
+ } \
+ Py_INCREF(Py_True); \
+ return Py_True; }
+
+#define NoArgNoReturnVoidFunction(X) \
+static PyObject *PyCurses_ ## X (PyObject *self) \
+{ \
+ PyCursesInitialised \
+ X(); \
+ Py_INCREF(Py_None); \
+ return Py_None; }
#ifdef __cplusplus
}