Counter Strike : Global Offensive Source Code
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

176 lines
4.1 KiB

  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
  12. #ifdef __FreeBSD__
  13. /*
  14. ** On FreeBSD, [n]curses.h and stdlib.h/wchar.h use different guards
  15. ** against multiple definition of wchar_t and wint_t.
  16. */
  17. #ifdef _XOPEN_SOURCE_EXTENDED
  18. #ifndef __FreeBSD_version
  19. #include <osreldate.h>
  20. #endif
  21. #if __FreeBSD_version >= 500000
  22. #ifndef __wchar_t
  23. #define __wchar_t
  24. #endif
  25. #ifndef __wint_t
  26. #define __wint_t
  27. #endif
  28. #else
  29. #ifndef _WCHAR_T
  30. #define _WCHAR_T
  31. #endif
  32. #ifndef _WINT_T
  33. #define _WINT_T
  34. #endif
  35. #endif
  36. #endif
  37. #endif
  38. #ifdef HAVE_NCURSES_H
  39. #include <ncurses.h>
  40. #else
  41. #include <curses.h>
  42. #ifdef HAVE_TERM_H
  43. /* for tigetstr, which is not declared in SysV curses */
  44. #include <term.h>
  45. #endif
  46. #endif
  47. #ifdef HAVE_NCURSES_H
  48. /* configure was checking <curses.h>, but we will
  49. use <ncurses.h>, which has all these features. */
  50. #ifndef WINDOW_HAS_FLAGS
  51. #define WINDOW_HAS_FLAGS 1
  52. #endif
  53. #ifndef MVWDELCH_IS_EXPRESSION
  54. #define MVWDELCH_IS_EXPRESSION 1
  55. #endif
  56. #endif
  57. #ifdef __cplusplus
  58. extern "C" {
  59. #endif
  60. #define PyCurses_API_pointers 4
  61. /* Type declarations */
  62. typedef struct {
  63. PyObject_HEAD
  64. WINDOW *win;
  65. } PyCursesWindowObject;
  66. #define PyCursesWindow_Check(v) ((v)->ob_type == &PyCursesWindow_Type)
  67. #ifdef CURSES_MODULE
  68. /* This section is used when compiling _cursesmodule.c */
  69. #else
  70. /* This section is used in modules that use the _cursesmodule API */
  71. static void **PyCurses_API;
  72. #define PyCursesWindow_Type (*(PyTypeObject *) PyCurses_API[0])
  73. #define PyCursesSetupTermCalled {if (! ((int (*)(void))PyCurses_API[1]) () ) return NULL;}
  74. #define PyCursesInitialised {if (! ((int (*)(void))PyCurses_API[2]) () ) return NULL;}
  75. #define PyCursesInitialisedColor {if (! ((int (*)(void))PyCurses_API[3]) () ) return NULL;}
  76. #define import_curses() \
  77. { \
  78. PyObject *module = PyImport_ImportModule("_curses"); \
  79. if (module != NULL) { \
  80. PyObject *module_dict = PyModule_GetDict(module); \
  81. PyObject *c_api_object = PyDict_GetItemString(module_dict, "_C_API"); \
  82. if (PyCObject_Check(c_api_object)) { \
  83. PyCurses_API = (void **)PyCObject_AsVoidPtr(c_api_object); \
  84. } \
  85. } \
  86. }
  87. #endif
  88. /* general error messages */
  89. static char *catchall_ERR = "curses function returned ERR";
  90. static char *catchall_NULL = "curses function returned NULL";
  91. /* Function Prototype Macros - They are ugly but very, very useful. ;-)
  92. X - function name
  93. TYPE - parameter Type
  94. ERGSTR - format string for construction of the return value
  95. PARSESTR - format string for argument parsing
  96. */
  97. #define NoArgNoReturnFunction(X) \
  98. static PyObject *PyCurses_ ## X (PyObject *self) \
  99. { \
  100. PyCursesInitialised \
  101. return PyCursesCheckERR(X(), # X); }
  102. #define NoArgOrFlagNoReturnFunction(X) \
  103. static PyObject *PyCurses_ ## X (PyObject *self, PyObject *args) \
  104. { \
  105. int flag = 0; \
  106. PyCursesInitialised \
  107. switch(PyTuple_Size(args)) { \
  108. case 0: \
  109. return PyCursesCheckERR(X(), # X); \
  110. case 1: \
  111. if (!PyArg_ParseTuple(args, "i;True(1) or False(0)", &flag)) return NULL; \
  112. if (flag) return PyCursesCheckERR(X(), # X); \
  113. else return PyCursesCheckERR(no ## X (), # X); \
  114. default: \
  115. PyErr_SetString(PyExc_TypeError, # X " requires 0 or 1 arguments"); \
  116. return NULL; } }
  117. #define NoArgReturnIntFunction(X) \
  118. static PyObject *PyCurses_ ## X (PyObject *self) \
  119. { \
  120. PyCursesInitialised \
  121. return PyInt_FromLong((long) X()); }
  122. #define NoArgReturnStringFunction(X) \
  123. static PyObject *PyCurses_ ## X (PyObject *self) \
  124. { \
  125. PyCursesInitialised \
  126. return PyString_FromString(X()); }
  127. #define NoArgTrueFalseFunction(X) \
  128. static PyObject *PyCurses_ ## X (PyObject *self) \
  129. { \
  130. PyCursesInitialised \
  131. if (X () == FALSE) { \
  132. Py_INCREF(Py_False); \
  133. return Py_False; \
  134. } \
  135. Py_INCREF(Py_True); \
  136. return Py_True; }
  137. #define NoArgNoReturnVoidFunction(X) \
  138. static PyObject *PyCurses_ ## X (PyObject *self) \
  139. { \
  140. PyCursesInitialised \
  141. X(); \
  142. Py_INCREF(Py_None); \
  143. return Py_None; }
  144. #ifdef __cplusplus
  145. }
  146. #endif
  147. #endif /* !defined(Py_CURSES_H) */