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.

182 lines
5.3 KiB

25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
25 years ago
  1. /*
  2. +----------------------------------------------------------------------+
  3. | PHP version 4.0 |
  4. +----------------------------------------------------------------------+
  5. | Copyright (c) 1997, 1998, 1999, 2000, 2001 The PHP Group |
  6. +----------------------------------------------------------------------+
  7. | This source file is subject to version 2.02 of the PHP license, |
  8. | that is bundled with this package in the file LICENSE, and is |
  9. | available at through the world-wide-web at |
  10. | http://www.php.net/license/2_02.txt. |
  11. | If you did not receive a copy of the PHP license and are unable to |
  12. | obtain it through the world-wide-web, please send a note to |
  13. | license@php.net so we can mail you a copy immediately. |
  14. +----------------------------------------------------------------------+
  15. | Authors: Hartmut Holzgraefe <hartmut@six.de> |
  16. | |
  17. +----------------------------------------------------------------------+
  18. */
  19. #ifdef HAVE_CONFIG_H
  20. #include "config.h"
  21. #endif
  22. #include "php.h"
  23. #include "php_ini.h"
  24. #include "php_ncurses.h"
  25. #include "ext/standard/info.h"
  26. /* If you declare any globals in php_ncurses.h uncomment this:
  27. ZEND_DECLARE_MODULE_GLOBALS(ncurses)
  28. */
  29. /* True global resources - no need for thread safety here */
  30. int le_ncurses;
  31. static void ncurses_destruct(zend_rsrc_list_entry *rsrc TSRMLS_DC)
  32. {
  33. WINDOW **pwin = (WINDOW **)rsrc->ptr;
  34. delwin(*pwin);
  35. efree(pwin);
  36. }
  37. /* {{{ ncurses_module_entry
  38. */
  39. zend_module_entry ncurses_module_entry = {
  40. STANDARD_MODULE_HEADER,
  41. "ncurses",
  42. ncurses_functions,
  43. PHP_MINIT(ncurses),
  44. PHP_MSHUTDOWN(ncurses),
  45. PHP_RINIT(ncurses), /* Replace with NULL if there's nothing to do at request start */
  46. PHP_RSHUTDOWN(ncurses), /* Replace with NULL if there's nothing to do at request end */
  47. PHP_MINFO(ncurses),
  48. NO_VERSION_YET,
  49. STANDARD_MODULE_PROPERTIES
  50. };
  51. /* }}} */
  52. #ifdef COMPILE_DL_NCURSES
  53. ZEND_GET_MODULE(ncurses)
  54. #endif
  55. /* {{{ PHP_INI
  56. */
  57. /* Remove comments and fill if you need to have entries in php.ini
  58. PHP_INI_BEGIN()
  59. STD_PHP_INI_ENTRY("ncurses.value", "42", PHP_INI_ALL, OnUpdateInt, global_value, zend_ncurses_globals, ncurses_globals)
  60. STD_PHP_INI_ENTRY("ncurses.string", "foobar", PHP_INI_ALL, OnUpdateString, global_string, zend_ncurses_globals, ncurses_globals)
  61. PHP_INI_END()
  62. */
  63. /* }}} */
  64. #define PHP_NCURSES_CONST(x) REGISTER_LONG_CONSTANT("NCURSES_"#x, x, CONST_CS | CONST_PERSISTENT)
  65. /* {{{ PHP_MINIT_FUNCTION
  66. */
  67. PHP_MINIT_FUNCTION(ncurses)
  68. {
  69. /* color constants */
  70. PHP_NCURSES_CONST(COLOR_BLACK);
  71. PHP_NCURSES_CONST(COLOR_RED);
  72. PHP_NCURSES_CONST(COLOR_GREEN);
  73. PHP_NCURSES_CONST(COLOR_YELLOW);
  74. PHP_NCURSES_CONST(COLOR_BLUE);
  75. PHP_NCURSES_CONST(COLOR_MAGENTA);
  76. PHP_NCURSES_CONST(COLOR_CYAN);
  77. PHP_NCURSES_CONST(COLOR_WHITE);
  78. /* keyboard constants */
  79. PHP_NCURSES_CONST(KEY_DOWN);
  80. PHP_NCURSES_CONST(KEY_UP);
  81. PHP_NCURSES_CONST(KEY_LEFT);
  82. PHP_NCURSES_CONST(KEY_RIGHT);
  83. PHP_NCURSES_CONST(KEY_BACKSPACE);
  84. le_ncurses = zend_register_list_destructors_ex(ncurses_destruct, NULL, "ncurses_handle", module_number);
  85. return SUCCESS;
  86. }
  87. /* }}} */
  88. /* {{{ PHP_MSHUTDOWN_FUNCTION
  89. */
  90. PHP_MSHUTDOWN_FUNCTION(ncurses)
  91. {
  92. return SUCCESS;
  93. }
  94. /* }}} */
  95. /* Remove if there's nothing to do at request start */
  96. /* {{{ PHP_RINIT_FUNCTION
  97. */
  98. PHP_RINIT_FUNCTION(ncurses)
  99. {
  100. return SUCCESS;
  101. }
  102. /* }}} */
  103. /* Remove if there's nothing to do at request end */
  104. /* {{{ PHP_RSHUTDOWN_FUNCTION
  105. */
  106. PHP_RSHUTDOWN_FUNCTION(ncurses)
  107. {
  108. return SUCCESS;
  109. }
  110. /* }}} */
  111. /* {{{ PHP_MINFO_FUNCTION
  112. */
  113. PHP_MINFO_FUNCTION(ncurses)
  114. {
  115. php_info_print_table_start();
  116. php_info_print_table_header(2, "ncurses support", "enabled");
  117. php_info_print_table_end();
  118. /* Remove comments if you have entries in php.ini
  119. DISPLAY_INI_ENTRIES();
  120. */
  121. }
  122. /* }}} */
  123. /* Remove the following function when you have succesfully modified config.m4
  124. so that your module can be compiled into PHP, it exists only for testing
  125. purposes. */
  126. /* Every user-visible function in PHP should document itself in the source */
  127. /* {{{ proto string confirm_ncurses_compiled(string arg)
  128. Return a string to confirm that the module is compiled in */
  129. PHP_FUNCTION(confirm_ncurses_compiled)
  130. {
  131. zval **arg;
  132. int len;
  133. char string[256];
  134. if (ZEND_NUM_ARGS() != 1 || zend_get_parameters_ex(1, &arg) == FAILURE) {
  135. WRONG_PARAM_COUNT;
  136. }
  137. convert_to_string_ex(arg);
  138. len = sprintf(string, "Congratulations! You have successfully modified ext/%.78s/config.m4. Module %.78s is now compiled into PHP.", "ncurses", Z_STRVAL_PP(arg));
  139. RETURN_STRINGL(string, len, 1);
  140. }
  141. /* }}} */
  142. /* The previous line is meant for vim and emacs, so it can correctly fold and
  143. unfold functions in source code. See the corresponding marks just before
  144. function definition, where the functions purpose is also documented. Please
  145. follow this convention for the convenience of others editing your code.
  146. */
  147. /*
  148. * Local variables:
  149. * tab-width: 4
  150. * c-basic-offset: 4
  151. * End:
  152. * vim600: sw=4 ts=4 fdm=marker
  153. * vim<600: sw=4 ts=4
  154. */