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