1 : /*
2 : +----------------------------------------------------------------------+
3 : | PHP Version 5 |
4 : +----------------------------------------------------------------------+
5 : | Copyright (c) 1997-2009 The PHP Group |
6 : +----------------------------------------------------------------------+
7 : | This source file is subject to version 3.01 of the PHP license, |
8 : | that is bundled with this package in the file LICENSE, and is |
9 : | available through the world-wide-web at the following url: |
10 : | http://www.php.net/license/3_01.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 : | Author: Hartmut Holzgraefe <hholzgra@php.net> |
16 : +----------------------------------------------------------------------+
17 : */
18 :
19 : #ifdef HAVE_CONFIG_H
20 : #include "config.h"
21 : #endif
22 :
23 : #include "php.h"
24 : #include "php_ini.h"
25 : #include "php_ncurses.h"
26 : #include "ext/standard/info.h"
27 :
28 : ZEND_DECLARE_MODULE_GLOBALS(ncurses)
29 :
30 : /* True global resources - no need for thread safety here */
31 : int le_ncurses_windows;
32 : #if HAVE_NCURSES_PANEL
33 : int le_ncurses_panels;
34 : #endif
35 :
36 : static void ncurses_destruct_window(zend_rsrc_list_entry *rsrc TSRMLS_DC)
37 0 : {
38 0 : WINDOW **pwin = (WINDOW **)rsrc->ptr;
39 :
40 0 : delwin(*pwin);
41 0 : efree(pwin);
42 0 : }
43 :
44 : #if HAVE_NCURSES_PANEL
45 : static void ncurses_destruct_panel(zend_rsrc_list_entry *rsrc TSRMLS_DC)
46 0 : {
47 0 : PANEL **ppanel = (PANEL **)rsrc->ptr;
48 :
49 0 : del_panel(*ppanel);
50 0 : efree(ppanel);
51 0 : }
52 : #endif
53 :
54 : /* {{{ ncurses_module_entry
55 : */
56 : zend_module_entry ncurses_module_entry = {
57 : STANDARD_MODULE_HEADER,
58 : "ncurses",
59 : ncurses_functions,
60 : PHP_MINIT(ncurses),
61 : PHP_MSHUTDOWN(ncurses),
62 : NULL,
63 : NULL,
64 : PHP_MINFO(ncurses),
65 : NO_VERSION_YET,
66 : STANDARD_MODULE_PROPERTIES
67 : };
68 : /* }}} */
69 :
70 : #ifdef COMPILE_DL_NCURSES
71 : ZEND_GET_MODULE(ncurses)
72 : #endif
73 :
74 : #define PHP_NCURSES_CONST(x) REGISTER_LONG_CONSTANT("NCURSES_"#x, x, CONST_CS | CONST_PERSISTENT)
75 : #define PHP_NCURSES_FKEY_CONST(x) REGISTER_LONG_CONSTANT("NCURSES_KEY_F"#x, KEY_F0 + x, CONST_CS | CONST_PERSISTENT)
76 :
77 : static void php_ncurses_init_globals(zend_ncurses_globals *ncurses_globals)
78 13565 : {
79 13565 : memset(ncurses_globals, 0, sizeof(*ncurses_globals));
80 13565 : }
81 :
82 : /* {{{ PHP_MINIT_FUNCTION
83 : */
84 : PHP_MINIT_FUNCTION(ncurses)
85 13565 : {
86 : /* color constants */
87 13565 : PHP_NCURSES_CONST(COLOR_BLACK);
88 13565 : PHP_NCURSES_CONST(COLOR_RED);
89 13565 : PHP_NCURSES_CONST(COLOR_GREEN);
90 13565 : PHP_NCURSES_CONST(COLOR_YELLOW);
91 13565 : PHP_NCURSES_CONST(COLOR_BLUE);
92 13565 : PHP_NCURSES_CONST(COLOR_MAGENTA);
93 13565 : PHP_NCURSES_CONST(COLOR_CYAN);
94 13565 : PHP_NCURSES_CONST(COLOR_WHITE);
95 :
96 : /* keyboard constants */
97 13565 : PHP_NCURSES_CONST(KEY_DOWN);
98 13565 : PHP_NCURSES_CONST(KEY_UP);
99 13565 : PHP_NCURSES_CONST(KEY_LEFT);
100 13565 : PHP_NCURSES_CONST(KEY_RIGHT);
101 13565 : PHP_NCURSES_CONST(KEY_HOME);
102 13565 : PHP_NCURSES_CONST(KEY_END);
103 13565 : PHP_NCURSES_CONST(KEY_BACKSPACE);
104 13565 : PHP_NCURSES_CONST(KEY_MOUSE);
105 13565 : PHP_NCURSES_CONST(KEY_F0);
106 :
107 : /* TODO:this macro sux, we have 65 function key,
108 : so we need a little loop */
109 13565 : PHP_NCURSES_FKEY_CONST(1);
110 13565 : PHP_NCURSES_FKEY_CONST(2);
111 13565 : PHP_NCURSES_FKEY_CONST(3);
112 13565 : PHP_NCURSES_FKEY_CONST(4);
113 13565 : PHP_NCURSES_FKEY_CONST(5);
114 13565 : PHP_NCURSES_FKEY_CONST(6);
115 13565 : PHP_NCURSES_FKEY_CONST(7);
116 13565 : PHP_NCURSES_FKEY_CONST(8);
117 13565 : PHP_NCURSES_FKEY_CONST(9);
118 13565 : PHP_NCURSES_FKEY_CONST(10);
119 13565 : PHP_NCURSES_FKEY_CONST(11);
120 13565 : PHP_NCURSES_FKEY_CONST(12);
121 :
122 13565 : PHP_NCURSES_CONST(KEY_DL);
123 13565 : PHP_NCURSES_CONST(KEY_IL);
124 13565 : PHP_NCURSES_CONST(KEY_DC);
125 13565 : PHP_NCURSES_CONST(KEY_IC);
126 13565 : PHP_NCURSES_CONST(KEY_EIC);
127 13565 : PHP_NCURSES_CONST(KEY_CLEAR);
128 13565 : PHP_NCURSES_CONST(KEY_EOS);
129 13565 : PHP_NCURSES_CONST(KEY_EOL);
130 13565 : PHP_NCURSES_CONST(KEY_SF);
131 13565 : PHP_NCURSES_CONST(KEY_SR);
132 13565 : PHP_NCURSES_CONST(KEY_NPAGE);
133 13565 : PHP_NCURSES_CONST(KEY_PPAGE);
134 13565 : PHP_NCURSES_CONST(KEY_STAB);
135 13565 : PHP_NCURSES_CONST(KEY_CTAB);
136 13565 : PHP_NCURSES_CONST(KEY_CATAB);
137 13565 : PHP_NCURSES_CONST(KEY_ENTER);
138 13565 : PHP_NCURSES_CONST(KEY_SRESET);
139 13565 : PHP_NCURSES_CONST(KEY_RESET);
140 13565 : PHP_NCURSES_CONST(KEY_PRINT);
141 13565 : PHP_NCURSES_CONST(KEY_LL);
142 13565 : PHP_NCURSES_CONST(KEY_A1);
143 13565 : PHP_NCURSES_CONST(KEY_A3);
144 13565 : PHP_NCURSES_CONST(KEY_B2);
145 13565 : PHP_NCURSES_CONST(KEY_C1);
146 13565 : PHP_NCURSES_CONST(KEY_C3);
147 13565 : PHP_NCURSES_CONST(KEY_BTAB);
148 13565 : PHP_NCURSES_CONST(KEY_BEG);
149 13565 : PHP_NCURSES_CONST(KEY_CANCEL);
150 13565 : PHP_NCURSES_CONST(KEY_CLOSE);
151 13565 : PHP_NCURSES_CONST(KEY_COMMAND);
152 13565 : PHP_NCURSES_CONST(KEY_COPY);
153 13565 : PHP_NCURSES_CONST(KEY_CREATE);
154 13565 : PHP_NCURSES_CONST(KEY_EXIT);
155 13565 : PHP_NCURSES_CONST(KEY_FIND);
156 13565 : PHP_NCURSES_CONST(KEY_HELP);
157 13565 : PHP_NCURSES_CONST(KEY_MARK);
158 13565 : PHP_NCURSES_CONST(KEY_MESSAGE);
159 13565 : PHP_NCURSES_CONST(KEY_MOVE);
160 13565 : PHP_NCURSES_CONST(KEY_NEXT);
161 13565 : PHP_NCURSES_CONST(KEY_OPEN);
162 13565 : PHP_NCURSES_CONST(KEY_OPTIONS);
163 13565 : PHP_NCURSES_CONST(KEY_PREVIOUS);
164 13565 : PHP_NCURSES_CONST(KEY_REDO);
165 13565 : PHP_NCURSES_CONST(KEY_REFERENCE);
166 13565 : PHP_NCURSES_CONST(KEY_REFRESH);
167 13565 : PHP_NCURSES_CONST(KEY_REPLACE);
168 13565 : PHP_NCURSES_CONST(KEY_RESTART);
169 13565 : PHP_NCURSES_CONST(KEY_RESUME);
170 13565 : PHP_NCURSES_CONST(KEY_SAVE);
171 13565 : PHP_NCURSES_CONST(KEY_SBEG);
172 13565 : PHP_NCURSES_CONST(KEY_SCANCEL);
173 13565 : PHP_NCURSES_CONST(KEY_SCOMMAND);
174 13565 : PHP_NCURSES_CONST(KEY_SCOPY);
175 13565 : PHP_NCURSES_CONST(KEY_SCREATE);
176 13565 : PHP_NCURSES_CONST(KEY_SDC);
177 13565 : PHP_NCURSES_CONST(KEY_SDL);
178 13565 : PHP_NCURSES_CONST(KEY_SELECT);
179 13565 : PHP_NCURSES_CONST(KEY_SEND);
180 13565 : PHP_NCURSES_CONST(KEY_SEOL);
181 13565 : PHP_NCURSES_CONST(KEY_SEXIT);
182 13565 : PHP_NCURSES_CONST(KEY_SFIND);
183 13565 : PHP_NCURSES_CONST(KEY_SHELP);
184 13565 : PHP_NCURSES_CONST(KEY_SHOME);
185 13565 : PHP_NCURSES_CONST(KEY_SIC);
186 13565 : PHP_NCURSES_CONST(KEY_SLEFT);
187 13565 : PHP_NCURSES_CONST(KEY_SMESSAGE);
188 13565 : PHP_NCURSES_CONST(KEY_SMOVE);
189 13565 : PHP_NCURSES_CONST(KEY_SNEXT);
190 13565 : PHP_NCURSES_CONST(KEY_SOPTIONS);
191 13565 : PHP_NCURSES_CONST(KEY_SPREVIOUS);
192 13565 : PHP_NCURSES_CONST(KEY_SPRINT);
193 13565 : PHP_NCURSES_CONST(KEY_SREDO);
194 13565 : PHP_NCURSES_CONST(KEY_SREPLACE);
195 13565 : PHP_NCURSES_CONST(KEY_SRIGHT);
196 13565 : PHP_NCURSES_CONST(KEY_SRSUME);
197 13565 : PHP_NCURSES_CONST(KEY_SSAVE);
198 13565 : PHP_NCURSES_CONST(KEY_SSUSPEND);
199 13565 : PHP_NCURSES_CONST(KEY_SUNDO);
200 13565 : PHP_NCURSES_CONST(KEY_SUSPEND);
201 13565 : PHP_NCURSES_CONST(KEY_UNDO);
202 13565 : PHP_NCURSES_CONST(KEY_RESIZE);
203 :
204 : /* screen attribute constants */
205 13565 : PHP_NCURSES_CONST(A_NORMAL);
206 13565 : PHP_NCURSES_CONST(A_STANDOUT);
207 13565 : PHP_NCURSES_CONST(A_UNDERLINE);
208 13565 : PHP_NCURSES_CONST(A_REVERSE);
209 13565 : PHP_NCURSES_CONST(A_BLINK);
210 13565 : PHP_NCURSES_CONST(A_DIM);
211 13565 : PHP_NCURSES_CONST(A_BOLD);
212 13565 : PHP_NCURSES_CONST(A_PROTECT);
213 13565 : PHP_NCURSES_CONST(A_INVIS);
214 13565 : PHP_NCURSES_CONST(A_ALTCHARSET);
215 13565 : PHP_NCURSES_CONST(A_CHARTEXT);
216 :
217 : /* mouse constants */
218 13565 : PHP_NCURSES_CONST(BUTTON1_PRESSED);
219 13565 : PHP_NCURSES_CONST(BUTTON1_RELEASED);
220 13565 : PHP_NCURSES_CONST(BUTTON1_CLICKED);
221 13565 : PHP_NCURSES_CONST(BUTTON1_DOUBLE_CLICKED);
222 13565 : PHP_NCURSES_CONST(BUTTON1_TRIPLE_CLICKED);
223 13565 : PHP_NCURSES_CONST(BUTTON2_PRESSED);
224 13565 : PHP_NCURSES_CONST(BUTTON2_RELEASED);
225 13565 : PHP_NCURSES_CONST(BUTTON2_CLICKED);
226 13565 : PHP_NCURSES_CONST(BUTTON2_DOUBLE_CLICKED);
227 13565 : PHP_NCURSES_CONST(BUTTON2_TRIPLE_CLICKED);
228 13565 : PHP_NCURSES_CONST(BUTTON3_PRESSED);
229 13565 : PHP_NCURSES_CONST(BUTTON3_RELEASED);
230 13565 : PHP_NCURSES_CONST(BUTTON3_CLICKED);
231 13565 : PHP_NCURSES_CONST(BUTTON3_DOUBLE_CLICKED);
232 13565 : PHP_NCURSES_CONST(BUTTON3_TRIPLE_CLICKED);
233 13565 : PHP_NCURSES_CONST(BUTTON4_PRESSED);
234 13565 : PHP_NCURSES_CONST(BUTTON4_RELEASED);
235 13565 : PHP_NCURSES_CONST(BUTTON4_CLICKED);
236 13565 : PHP_NCURSES_CONST(BUTTON4_DOUBLE_CLICKED);
237 13565 : PHP_NCURSES_CONST(BUTTON4_TRIPLE_CLICKED);
238 13565 : PHP_NCURSES_CONST(BUTTON_SHIFT);
239 13565 : PHP_NCURSES_CONST(BUTTON_CTRL);
240 13565 : PHP_NCURSES_CONST(BUTTON_ALT);
241 13565 : PHP_NCURSES_CONST(ALL_MOUSE_EVENTS);
242 13565 : PHP_NCURSES_CONST(REPORT_MOUSE_POSITION);
243 :
244 13565 : ZEND_INIT_MODULE_GLOBALS(ncurses, php_ncurses_init_globals, NULL);
245 :
246 13565 : le_ncurses_windows = zend_register_list_destructors_ex(ncurses_destruct_window, NULL, "ncurses_window", module_number);
247 : #if HAVE_NCURSES_PANEL
248 13565 : le_ncurses_panels = zend_register_list_destructors_ex(ncurses_destruct_panel, NULL, "ncurses_panel", module_number);
249 : #endif
250 :
251 13565 : return SUCCESS;
252 : }
253 : /* }}} */
254 :
255 : /* {{{ PHP_MSHUTDOWN_FUNCTION
256 : */
257 : PHP_MSHUTDOWN_FUNCTION(ncurses)
258 13597 : {
259 13597 : if (NCURSES_G(registered_constants)) {
260 0 : endwin();
261 : }
262 :
263 13597 : return SUCCESS;
264 : }
265 : /* }}} */
266 :
267 : /* {{{ PHP_MINFO_FUNCTION
268 : */
269 : PHP_MINFO_FUNCTION(ncurses)
270 6 : {
271 6 : php_info_print_table_start();
272 6 : php_info_print_table_header(2, "ncurses support", "enabled");
273 6 : php_info_print_table_row(2, "ncurses library version", NCURSES_VERSION);
274 : #ifdef HAVE_NCURSES_COLOR_SET
275 6 : php_info_print_table_row(2, "color support", "yes");
276 : #else
277 : php_info_print_table_row(2, "color support", "no");
278 : #endif
279 6 : php_info_print_table_end();
280 6 : }
281 : /* }}} */
282 :
283 : /* Remove the following function when you have succesfully modified config.m4
284 : so that your module can be compiled into PHP, it exists only for testing
285 : purposes. */
286 :
287 :
288 :
289 : /*
290 : * Local variables:
291 : * tab-width: 4
292 : * c-basic-offset: 4
293 : * End:
294 : * vim600: sw=4 ts=4 fdm=marker
295 : * vim<600: sw=4 ts=4
296 : */
|