py_curses.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. #ifndef Py_CURSES_H
  2. #define Py_CURSES_H
  3. #ifdef __APPLE__
  4. /*
  5. ** On Mac OS X 10.2 [n]curses.h and stdlib.h use different guards
  6. ** against multiple definition of wchar_t.
  7. */
  8. #ifdef _BSD_WCHAR_T_DEFINED_
  9. #define _WCHAR_T
  10. #endif
  11. #endif /* __APPLE__ */
  12. /* On FreeBSD, [n]curses.h and stdlib.h/wchar.h use different guards
  13. against multiple definition of wchar_t and wint_t. */
  14. #if defined(__FreeBSD__) && defined(_XOPEN_SOURCE_EXTENDED)
  15. # ifndef __wchar_t
  16. # define __wchar_t
  17. # endif
  18. # ifndef __wint_t
  19. # define __wint_t
  20. # endif
  21. #endif
  22. #if !defined(HAVE_CURSES_IS_PAD) && defined(WINDOW_HAS_FLAGS)
  23. /* The following definition is necessary for ncurses 5.7; without it,
  24. some of [n]curses.h set NCURSES_OPAQUE to 1, and then Python
  25. can't get at the WINDOW flags field. */
  26. #define NCURSES_OPAQUE 0
  27. #endif
  28. #ifdef HAVE_NCURSES_H
  29. #include <ncurses.h>
  30. #else
  31. #include <curses.h>
  32. #endif
  33. #ifdef HAVE_NCURSES_H
  34. /* configure was checking <curses.h>, but we will
  35. use <ncurses.h>, which has some or all these features. */
  36. #if !defined(WINDOW_HAS_FLAGS) && !(NCURSES_OPAQUE+0)
  37. #define WINDOW_HAS_FLAGS 1
  38. #endif
  39. #if !defined(HAVE_CURSES_IS_PAD) && NCURSES_VERSION_PATCH+0 >= 20090906
  40. #define HAVE_CURSES_IS_PAD 1
  41. #endif
  42. #ifndef MVWDELCH_IS_EXPRESSION
  43. #define MVWDELCH_IS_EXPRESSION 1
  44. #endif
  45. #endif
  46. #ifdef __cplusplus
  47. extern "C" {
  48. #endif
  49. #define PyCurses_API_pointers 4
  50. /* Type declarations */
  51. typedef struct {
  52. PyObject_HEAD
  53. WINDOW *win;
  54. char *encoding;
  55. } PyCursesWindowObject;
  56. #define PyCursesWindow_Check(v) (Py_TYPE(v) == &PyCursesWindow_Type)
  57. #define PyCurses_CAPSULE_NAME "_curses._C_API"
  58. #ifdef CURSES_MODULE
  59. /* This section is used when compiling _cursesmodule.c */
  60. #else
  61. /* This section is used in modules that use the _cursesmodule API */
  62. static void **PyCurses_API;
  63. #define PyCursesWindow_Type (*(PyTypeObject *) PyCurses_API[0])
  64. #define PyCursesSetupTermCalled {if (! ((int (*)(void))PyCurses_API[1]) () ) return NULL;}
  65. #define PyCursesInitialised {if (! ((int (*)(void))PyCurses_API[2]) () ) return NULL;}
  66. #define PyCursesInitialisedColor {if (! ((int (*)(void))PyCurses_API[3]) () ) return NULL;}
  67. #define import_curses() \
  68. PyCurses_API = (void **)PyCapsule_Import(PyCurses_CAPSULE_NAME, 1);
  69. #endif
  70. /* general error messages */
  71. static const char catchall_ERR[] = "curses function returned ERR";
  72. static const char catchall_NULL[] = "curses function returned NULL";
  73. #ifdef __cplusplus
  74. }
  75. #endif
  76. #endif /* !defined(Py_CURSES_H) */