source: libcaca/trunk/caca-php/php_caca.c @ 3109

Last change on this file since 3109 was 3109, checked in by nico, 11 years ago
  • Add php binding for 4 new functions
  • Add "full" demo to "examples/demo.php"
File size: 34.0 KB
Line 
1/*
2 *  php-caca      Php binding for Libcaca
3 *  Copyright (c) 2008 Vion Nicolas <nico@picapo.net>
4 *
5 *
6 *  This library is free software. It comes without any warranty, to
7 *  the extent permitted by applicable law. You can redistribute it
8 *  and/or modify it under the terms of the Do What The Fuck You Want
9 *  To Public License, Version 2, as published by Sam Hocevar. See
10 *  http://sam.zoy.org/wtfpl/COPYING for more details.
11 */
12
13#ifdef HAVE_CONFIG_H
14#include "config.h"
15#endif
16
17#include "php.h"
18#include "php_caca.h"
19
20static function_entry caca_functions[] = {
21        PHP_FE(caca_create_event, NULL)
22        PHP_FE(caca_create_canvas, NULL)
23        PHP_FE(caca_manage_canvas, NULL)
24        PHP_FE(caca_unmanage_canvas, NULL)
25        PHP_FE(caca_set_canvas_size, NULL)
26        PHP_FE(caca_get_canvas_width, NULL)
27        PHP_FE(caca_get_canvas_height, NULL)
28        PHP_FE(caca_get_canvas_chars, NULL)
29        PHP_FE(caca_get_canvas_attrs, NULL)
30        PHP_FE(caca_rand, NULL)
31        PHP_FE(caca_get_version, NULL)
32        PHP_FE(caca_gotoxy, NULL)
33        PHP_FE(caca_get_cursor_x, NULL)
34        PHP_FE(caca_get_cursor_y, NULL)
35        PHP_FE(caca_put_char, NULL)
36        PHP_FE(caca_get_char, NULL)
37        PHP_FE(caca_put_str, NULL)
38        PHP_FE(caca_clear_canvas, NULL)
39        PHP_FE(caca_set_canvas_handle, NULL)
40        PHP_FE(caca_get_canvas_handle_x, NULL)
41        PHP_FE(caca_get_canvas_handle_y, NULL)
42        PHP_FE(caca_blit, NULL)
43        PHP_FE(caca_set_canvas_boundaries, NULL)
44        PHP_FE(caca_invert, NULL)
45        PHP_FE(caca_flip, NULL)
46        PHP_FE(caca_flop, NULL)
47        PHP_FE(caca_rotate_left, NULL)
48        PHP_FE(caca_rotate_right, NULL)
49        PHP_FE(caca_stretch_left, NULL)
50        PHP_FE(caca_stretch_right, NULL)
51        PHP_FE(caca_get_attr, NULL)
52        PHP_FE(caca_set_attr, NULL)
53        PHP_FE(caca_put_attr, NULL)
54        PHP_FE(caca_set_color_ansi, NULL)
55        PHP_FE(caca_set_color_argb, NULL)
56        PHP_FE(caca_attr_to_ansi, NULL)
57        PHP_FE(caca_attr_to_ansi_fg, NULL)
58        PHP_FE(caca_attr_to_ansi_bg, NULL)
59        PHP_FE(caca_draw_line, NULL)
60        PHP_FE(caca_draw_polyline, NULL)
61        PHP_FE(caca_draw_thin_line, NULL)
62        PHP_FE(caca_draw_thin_polyline, NULL)
63        PHP_FE(caca_draw_circle, NULL)
64        PHP_FE(caca_draw_ellipse, NULL)
65        PHP_FE(caca_draw_thin_ellipse, NULL)
66        PHP_FE(caca_fill_ellipse, NULL)
67        PHP_FE(caca_draw_box, NULL)
68        PHP_FE(caca_draw_thin_box, NULL)
69        PHP_FE(caca_draw_cp437_box, NULL)
70        PHP_FE(caca_fill_box, NULL)
71        PHP_FE(caca_draw_triangle, NULL)
72        PHP_FE(caca_draw_thin_triangle, NULL)
73        PHP_FE(caca_fill_triangle, NULL)
74        PHP_FE(caca_get_frame_count, NULL)
75        PHP_FE(caca_set_frame, NULL)
76        PHP_FE(caca_set_frame_name, NULL)
77        PHP_FE(caca_create_frame, NULL)
78        PHP_FE(caca_free_frame, NULL)
79        PHP_FE(caca_set_dither_palette, NULL)
80        PHP_FE(caca_set_dither_brightness, NULL)
81        PHP_FE(caca_get_dither_brightness, NULL)
82        PHP_FE(caca_set_dither_gamma, NULL)
83        PHP_FE(caca_get_dither_gamma, NULL)
84        PHP_FE(caca_set_dither_contrast, NULL)
85        PHP_FE(caca_get_dither_contrast, NULL)
86        PHP_FE(caca_set_dither_antialias, NULL)
87        PHP_FE(caca_get_dither_antialias_list, NULL)
88        PHP_FE(caca_get_dither_antialias, NULL)
89        PHP_FE(caca_set_dither_color, NULL)
90        PHP_FE(caca_get_dither_color_list, NULL)
91        PHP_FE(caca_get_dither_color, NULL)
92        PHP_FE(caca_set_dither_charset, NULL)
93        PHP_FE(caca_get_dither_charset_list, NULL)
94        PHP_FE(caca_get_dither_charset, NULL)
95        PHP_FE(caca_set_dither_algorithm, NULL)
96        PHP_FE(caca_get_dither_algorithm_list, NULL)
97        PHP_FE(caca_get_dither_algorithm, NULL)
98        PHP_FE(caca_dither_bitmap, NULL)
99        PHP_FE(caca_get_font_list, NULL)
100        PHP_FE(caca_get_font_width, NULL)
101        PHP_FE(caca_get_font_height, NULL)
102        PHP_FE(caca_render_canvas, NULL)
103        PHP_FE(caca_canvas_set_figfont, NULL)
104        PHP_FE(caca_put_figchar, NULL)
105        PHP_FE(caca_flush_figlet, NULL)
106        PHP_FE(caca_file_close, NULL)
107        PHP_FE(caca_file_tell, NULL)
108        PHP_FE(caca_file_read, NULL)
109        PHP_FE(caca_file_write, NULL)
110        PHP_FE(caca_file_gets, NULL)
111        PHP_FE(caca_file_eof, NULL)
112        PHP_FE(caca_import_memory, NULL)
113        PHP_FE(caca_import_file, NULL)
114        PHP_FE(caca_get_import_list, NULL)
115        PHP_FE(caca_get_export_list, NULL)
116        PHP_FE(caca_create_display, NULL)
117        PHP_FE(caca_create_display_with_driver, NULL)
118        PHP_FE(caca_get_display_driver_list, NULL)
119        PHP_FE(caca_get_display_driver, NULL)
120        PHP_FE(caca_set_display_driver, NULL)
121        PHP_FE(caca_get_canvas, NULL)
122        PHP_FE(caca_refresh_display, NULL)
123        PHP_FE(caca_set_display_time, NULL)
124        PHP_FE(caca_get_display_time, NULL)
125        PHP_FE(caca_get_display_width, NULL)
126        PHP_FE(caca_get_display_height, NULL)
127        PHP_FE(caca_set_display_title, NULL)
128        PHP_FE(caca_set_mouse, NULL)
129        PHP_FE(caca_set_cursor, NULL)
130        PHP_FE(caca_get_event, NULL)
131        PHP_FE(caca_get_mouse_x, NULL)
132        PHP_FE(caca_get_mouse_y, NULL)
133        PHP_FE(caca_get_event_type, NULL)
134        PHP_FE(caca_get_event_key_ch, NULL)
135        PHP_FE(caca_get_event_mouse_button, NULL)
136        PHP_FE(caca_get_event_mouse_x, NULL)
137        PHP_FE(caca_get_event_mouse_y, NULL)
138        PHP_FE(caca_get_event_resize_width, NULL)
139        PHP_FE(caca_get_event_resize_height, NULL)
140
141        {NULL, NULL, NULL}
142};
143
144zend_module_entry caca_module_entry = {
145#if ZEND_MODULE_API_NO >= 20010901
146        STANDARD_MODULE_HEADER,
147#endif
148        PHP_CACA_EXTNAME,
149        caca_functions,
150        PHP_MINIT(caca),
151        NULL,
152        NULL,
153        NULL,
154        PHP_MINFO(caca),
155#if ZEND_MODULE_API_NO >= 20010901
156        PHP_CACA_VERSION,
157#endif
158        STANDARD_MODULE_PROPERTIES
159};
160
161#ifdef COMPILE_DL_CACA
162ZEND_GET_MODULE(caca)
163#endif
164
165PHP_MINFO_FUNCTION(caca) {
166        php_info_print_table_start();
167        php_info_print_table_row(2, "Caca library version", caca_get_version());
168        php_info_print_table_end();
169}
170
171//-------- Caca's ressources destructors -----------//
172
173static void php_caca_canvas_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) {
174        caca_free_canvas(rsrc->ptr);
175}
176
177static void php_caca_dither_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) {
178        caca_free_dither(rsrc->ptr);
179}
180
181static void php_caca_font_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) {
182        caca_free_font(rsrc->ptr);
183}
184
185static void php_caca_file_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) {
186}
187
188static void php_caca_display_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) {
189        caca_free_display(rsrc->ptr);
190}
191
192static void php_caca_event_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) {
193        efree((caca_event_t *) rsrc->ptr);
194}
195
196//-------- Initialization ---------//
197
198PHP_MINIT_FUNCTION(caca) {
199
200        le_caca_canvas = zend_register_list_destructors_ex(php_caca_canvas_dtor, NULL, PHP_CACA_CANVAS_RES_NAME, module_number);
201        le_caca_dither = zend_register_list_destructors_ex(php_caca_dither_dtor, NULL, PHP_CACA_DITHER_RES_NAME, module_number);
202        le_caca_font = zend_register_list_destructors_ex(php_caca_font_dtor, NULL, PHP_CACA_FONT_RES_NAME, module_number);
203        le_caca_file = zend_register_list_destructors_ex(php_caca_file_dtor, NULL, PHP_CACA_FILE_RES_NAME, module_number);
204        le_caca_display = zend_register_list_destructors_ex(php_caca_display_dtor, NULL, PHP_CACA_DISPLAY_RES_NAME, module_number);
205        le_caca_event = zend_register_list_destructors_ex(php_caca_event_dtor, NULL, PHP_CACA_EVENT_RES_NAME, module_number);
206       
207        REGISTER_LONG_CONSTANT("CACA_BLACK", CACA_BLACK, CONST_CS | CONST_PERSISTENT);
208        REGISTER_LONG_CONSTANT("CACA_BLUE", CACA_BLUE, CONST_CS | CONST_PERSISTENT);
209        REGISTER_LONG_CONSTANT("CACA_GREEN", CACA_GREEN, CONST_CS | CONST_PERSISTENT);
210        REGISTER_LONG_CONSTANT("CACA_CYAN", CACA_CYAN, CONST_CS | CONST_PERSISTENT);
211        REGISTER_LONG_CONSTANT("CACA_RED", CACA_RED, CONST_CS | CONST_PERSISTENT);
212        REGISTER_LONG_CONSTANT("CACA_MAGENTA", CACA_MAGENTA, CONST_CS | CONST_PERSISTENT);
213        REGISTER_LONG_CONSTANT("CACA_BROWN", CACA_BROWN, CONST_CS | CONST_PERSISTENT);
214        REGISTER_LONG_CONSTANT("CACA_LIGHTGRAY", CACA_LIGHTGRAY, CONST_CS | CONST_PERSISTENT);
215        REGISTER_LONG_CONSTANT("CACA_DARKGRAY", CACA_DARKGRAY, CONST_CS | CONST_PERSISTENT);
216        REGISTER_LONG_CONSTANT("CACA_LIGHTBLUE", CACA_LIGHTBLUE, CONST_CS | CONST_PERSISTENT);
217        REGISTER_LONG_CONSTANT("CACA_LIGHTGREEN", CACA_LIGHTGREEN, CONST_CS | CONST_PERSISTENT);
218        REGISTER_LONG_CONSTANT("CACA_LIGHTCYAN", CACA_LIGHTCYAN, CONST_CS | CONST_PERSISTENT);
219        REGISTER_LONG_CONSTANT("CACA_LIGHTRED", CACA_LIGHTRED, CONST_CS | CONST_PERSISTENT);
220        REGISTER_LONG_CONSTANT("CACA_LIGHTMAGENTA", CACA_LIGHTMAGENTA, CONST_CS | CONST_PERSISTENT);
221        REGISTER_LONG_CONSTANT("CACA_YELLOW", CACA_YELLOW, CONST_CS | CONST_PERSISTENT);
222        REGISTER_LONG_CONSTANT("CACA_WHITE", CACA_WHITE, CONST_CS | CONST_PERSISTENT);
223        REGISTER_LONG_CONSTANT("CACA_DEFAULT", CACA_DEFAULT, CONST_CS | CONST_PERSISTENT);
224        REGISTER_LONG_CONSTANT("CACA_TRANSPARENT", CACA_TRANSPARENT, CONST_CS | CONST_PERSISTENT);
225        REGISTER_LONG_CONSTANT("CACA_BOLD", CACA_BOLD, CONST_CS | CONST_PERSISTENT);
226        REGISTER_LONG_CONSTANT("CACA_ITALICS", CACA_ITALICS, CONST_CS | CONST_PERSISTENT);
227        REGISTER_LONG_CONSTANT("CACA_UNDERLINE", CACA_UNDERLINE, CONST_CS | CONST_PERSISTENT);
228        REGISTER_LONG_CONSTANT("CACA_BLINK", CACA_BLINK, CONST_CS | CONST_PERSISTENT);
229
230        REGISTER_LONG_CONSTANT("CACA_EVENT_NONE", CACA_EVENT_NONE, CONST_CS | CONST_PERSISTENT);
231        REGISTER_LONG_CONSTANT("CACA_EVENT_KEY_PRESS", CACA_EVENT_KEY_PRESS, CONST_CS | CONST_PERSISTENT);
232        REGISTER_LONG_CONSTANT("CACA_EVENT_KEY_RELEASE", CACA_EVENT_KEY_RELEASE, CONST_CS | CONST_PERSISTENT);
233        REGISTER_LONG_CONSTANT("CACA_EVENT_MOUSE_PRESS", CACA_EVENT_MOUSE_PRESS, CONST_CS | CONST_PERSISTENT);
234        REGISTER_LONG_CONSTANT("CACA_EVENT_MOUSE_RELEASE", CACA_EVENT_MOUSE_RELEASE, CONST_CS | CONST_PERSISTENT);
235        REGISTER_LONG_CONSTANT("CACA_EVENT_MOUSE_MOTION", CACA_EVENT_MOUSE_MOTION, CONST_CS | CONST_PERSISTENT);
236        REGISTER_LONG_CONSTANT("CACA_EVENT_RESIZE", CACA_EVENT_RESIZE, CONST_CS | CONST_PERSISTENT);
237        REGISTER_LONG_CONSTANT("CACA_EVENT_QUIT", CACA_EVENT_QUIT, CONST_CS | CONST_PERSISTENT);
238        REGISTER_LONG_CONSTANT("CACA_EVENT_ANY", CACA_EVENT_ANY, CONST_CS | CONST_PERSISTENT);
239
240        REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_A", CACA_KEY_CTRL_A, CONST_CS | CONST_PERSISTENT);
241        REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_B", CACA_KEY_CTRL_B, CONST_CS | CONST_PERSISTENT);
242        REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_C", CACA_KEY_CTRL_C, CONST_CS | CONST_PERSISTENT);
243        REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_D", CACA_KEY_CTRL_D, CONST_CS | CONST_PERSISTENT);
244        REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_E", CACA_KEY_CTRL_E, CONST_CS | CONST_PERSISTENT);
245        REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_F", CACA_KEY_CTRL_F, CONST_CS | CONST_PERSISTENT);
246        REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_G", CACA_KEY_CTRL_G, CONST_CS | CONST_PERSISTENT);
247        REGISTER_LONG_CONSTANT("CACA_KEY_BACKSPACE", CACA_KEY_BACKSPACE, CONST_CS | CONST_PERSISTENT);
248        REGISTER_LONG_CONSTANT("CACA_KEY_TAB", CACA_KEY_TAB, CONST_CS | CONST_PERSISTENT);
249        REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_J", CACA_KEY_CTRL_J, CONST_CS | CONST_PERSISTENT);
250        REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_K", CACA_KEY_CTRL_K, CONST_CS | CONST_PERSISTENT);
251        REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_L", CACA_KEY_CTRL_L, CONST_CS | CONST_PERSISTENT);
252        REGISTER_LONG_CONSTANT("CACA_KEY_RETURN", CACA_KEY_RETURN, CONST_CS | CONST_PERSISTENT);
253        REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_N", CACA_KEY_CTRL_N, CONST_CS | CONST_PERSISTENT);
254        REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_O", CACA_KEY_CTRL_O, CONST_CS | CONST_PERSISTENT);
255        REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_P", CACA_KEY_CTRL_P, CONST_CS | CONST_PERSISTENT);
256        REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_Q", CACA_KEY_CTRL_Q, CONST_CS | CONST_PERSISTENT);
257        REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_R", CACA_KEY_CTRL_R, CONST_CS | CONST_PERSISTENT);
258        REGISTER_LONG_CONSTANT("CACA_KEY_PAUSE", CACA_KEY_PAUSE, CONST_CS | CONST_PERSISTENT);
259        REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_T", CACA_KEY_CTRL_T, CONST_CS | CONST_PERSISTENT);
260        REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_U", CACA_KEY_CTRL_U, CONST_CS | CONST_PERSISTENT);
261        REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_V", CACA_KEY_CTRL_V, CONST_CS | CONST_PERSISTENT);
262        REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_W", CACA_KEY_CTRL_W, CONST_CS | CONST_PERSISTENT);
263        REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_X", CACA_KEY_CTRL_X, CONST_CS | CONST_PERSISTENT);
264        REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_Y", CACA_KEY_CTRL_Y, CONST_CS | CONST_PERSISTENT);
265        REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_Z", CACA_KEY_CTRL_Z, CONST_CS | CONST_PERSISTENT);
266        REGISTER_LONG_CONSTANT("CACA_KEY_ESCAPE", CACA_KEY_ESCAPE, CONST_CS | CONST_PERSISTENT);
267        REGISTER_LONG_CONSTANT("CACA_KEY_DELETE", CACA_KEY_DELETE, CONST_CS | CONST_PERSISTENT);
268        REGISTER_LONG_CONSTANT("CACA_KEY_UP", CACA_KEY_UP, CONST_CS | CONST_PERSISTENT);
269        REGISTER_LONG_CONSTANT("CACA_KEY_DOWN", CACA_KEY_DOWN, CONST_CS | CONST_PERSISTENT);
270        REGISTER_LONG_CONSTANT("CACA_KEY_LEFT", CACA_KEY_LEFT, CONST_CS | CONST_PERSISTENT);
271        REGISTER_LONG_CONSTANT("CACA_KEY_RIGHT", CACA_KEY_RIGHT, CONST_CS | CONST_PERSISTENT);
272        REGISTER_LONG_CONSTANT("CACA_KEY_INSERT", CACA_KEY_INSERT, CONST_CS | CONST_PERSISTENT);
273        REGISTER_LONG_CONSTANT("CACA_KEY_HOME", CACA_KEY_HOME, CONST_CS | CONST_PERSISTENT);
274        REGISTER_LONG_CONSTANT("CACA_KEY_END", CACA_KEY_END, CONST_CS | CONST_PERSISTENT);
275        REGISTER_LONG_CONSTANT("CACA_KEY_PAGEUP", CACA_KEY_PAGEUP, CONST_CS | CONST_PERSISTENT);
276        REGISTER_LONG_CONSTANT("CACA_KEY_PAGEDOWN", CACA_KEY_PAGEDOWN, CONST_CS | CONST_PERSISTENT);
277        REGISTER_LONG_CONSTANT("CACA_KEY_F1", CACA_KEY_F1, CONST_CS | CONST_PERSISTENT);
278        REGISTER_LONG_CONSTANT("CACA_KEY_F2", CACA_KEY_F2, CONST_CS | CONST_PERSISTENT);
279        REGISTER_LONG_CONSTANT("CACA_KEY_F3", CACA_KEY_F3, CONST_CS | CONST_PERSISTENT);
280        REGISTER_LONG_CONSTANT("CACA_KEY_F4", CACA_KEY_F4, CONST_CS | CONST_PERSISTENT);
281        REGISTER_LONG_CONSTANT("CACA_KEY_F5", CACA_KEY_F5, CONST_CS | CONST_PERSISTENT);
282        REGISTER_LONG_CONSTANT("CACA_KEY_F6", CACA_KEY_F6, CONST_CS | CONST_PERSISTENT);
283        REGISTER_LONG_CONSTANT("CACA_KEY_F7", CACA_KEY_F7, CONST_CS | CONST_PERSISTENT);
284        REGISTER_LONG_CONSTANT("CACA_KEY_F8", CACA_KEY_F8, CONST_CS | CONST_PERSISTENT);
285        REGISTER_LONG_CONSTANT("CACA_KEY_F9", CACA_KEY_F9, CONST_CS | CONST_PERSISTENT);
286        REGISTER_LONG_CONSTANT("CACA_KEY_F10", CACA_KEY_F10, CONST_CS | CONST_PERSISTENT);
287        REGISTER_LONG_CONSTANT("CACA_KEY_F11", CACA_KEY_F11, CONST_CS | CONST_PERSISTENT);
288        REGISTER_LONG_CONSTANT("CACA_KEY_F12", CACA_KEY_F12, CONST_CS | CONST_PERSISTENT);
289        REGISTER_LONG_CONSTANT("CACA_KEY_F13", CACA_KEY_F13, CONST_CS | CONST_PERSISTENT);
290        REGISTER_LONG_CONSTANT("CACA_KEY_F14", CACA_KEY_F14, CONST_CS | CONST_PERSISTENT);
291        REGISTER_LONG_CONSTANT("CACA_KEY_F15", CACA_KEY_F15, CONST_CS | CONST_PERSISTENT);
292
293        return SUCCESS;
294}
295
296//---------- Some usefull macros ---------------//
297
298#define FETCH_CANVAS(canvas) \
299        zval *_zval; \
300        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) { \
301                RETURN_FALSE; \
302        } \
303        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
304
305#define FETCH_DISPLAY(display) \
306        zval *_zval; \
307        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) { \
308                RETURN_FALSE; \
309        } \
310        ZEND_FETCH_RESOURCE(display, caca_display_t*, &_zval, -1, PHP_CACA_DISPLAY_RES_NAME, le_caca_display);
311
312#define FETCH_EVENT(event) \
313        zval *_zval; \
314        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) { \
315                RETURN_FALSE; \
316        } \
317        ZEND_FETCH_RESOURCE(event, caca_event_t*, &_zval, -1, PHP_CACA_EVENT_RES_NAME, le_caca_event);
318
319#define RETURN_CHAR(c) \
320        char *str = emalloc(2); \
321        str[0] = c; \
322        str[1] = '\0'; \
323        RETURN_STRING(str, 0);
324
325//------- PHP Binding's specific functions ----------//
326
327PHP_FUNCTION(caca_create_event) {
328        caca_event_t *event;
329        event = emalloc(sizeof(caca_event_t));
330        ZEND_REGISTER_RESOURCE(return_value, event, le_caca_event);
331}
332
333//------- Caca's functions ----------------//
334
335PHP_FUNCTION(caca_create_canvas) {
336        long width, height = 0;
337        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &width, &height) == FAILURE) {
338                RETURN_FALSE;
339        }
340        caca_canvas_t *canvas = caca_create_canvas(width, height);
341        if (!canvas) {
342                RETURN_FALSE;
343        }
344        ZEND_REGISTER_RESOURCE(return_value, canvas, le_caca_canvas);
345}
346
347PHP_FUNCTION(caca_manage_canvas) {
348}
349
350PHP_FUNCTION(caca_unmanage_canvas) {
351}
352
353PHP_FUNCTION(caca_set_canvas_size) {
354        zval *_zval;
355        long width, height = 0;
356        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &_zval, &width, &height) == FAILURE) {
357                RETURN_FALSE;
358        }
359        caca_canvas_t *canvas;
360        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
361        RETURN_BOOL(caca_set_canvas_size(canvas, width, height) == 0);
362}
363
364PHP_FUNCTION(caca_get_canvas_width) {
365        caca_canvas_t *canvas;
366        FETCH_CANVAS(canvas);
367        RETURN_LONG(caca_get_canvas_width(canvas));
368}
369
370PHP_FUNCTION(caca_get_canvas_height) {
371        caca_canvas_t *canvas;
372        FETCH_CANVAS(canvas);
373        RETURN_LONG(caca_get_canvas_height(canvas));
374}
375
376PHP_FUNCTION(caca_get_canvas_chars) {
377        caca_canvas_t *canvas;
378        FETCH_CANVAS(canvas);
379        RETURN_STRING(estrdup(caca_get_canvas_chars(canvas)), 0); //TODO: check that return \0 terminated string
380}
381
382PHP_FUNCTION(caca_get_canvas_attrs) {
383        caca_canvas_t *canvas;
384        FETCH_CANVAS(canvas);
385        RETURN_STRING(estrdup(caca_get_canvas_attrs(canvas)), 0); //TODO: check that return \0 terminated string
386}
387
388PHP_FUNCTION(caca_rand) {
389        long min, max = 0;
390        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &min, &max) == FAILURE) {
391                RETURN_FALSE;
392        }
393        RETURN_LONG(caca_rand(min, max));
394}
395
396PHP_FUNCTION(caca_get_version) {
397        RETURN_STRING(estrdup(caca_get_version()), 0);
398}
399
400PHP_FUNCTION(caca_gotoxy) {
401        zval *_zval;
402        long x, y = 0;
403        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &_zval, &x, &y) == FAILURE) {
404                RETURN_FALSE;
405        }
406        caca_canvas_t *canvas;
407        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
408        RETURN_BOOL(caca_gotoxy(canvas, x, y) == 0);
409}
410
411PHP_FUNCTION(caca_get_cursor_x) {
412        caca_canvas_t *canvas;
413        FETCH_CANVAS(canvas);
414        RETURN_LONG(caca_get_cursor_x(canvas));
415}
416
417PHP_FUNCTION(caca_get_cursor_y) {
418        caca_canvas_t *canvas;
419        FETCH_CANVAS(canvas);
420        RETURN_LONG(caca_get_cursor_y(canvas));
421}
422
423PHP_FUNCTION(caca_put_char) {
424        zval *_zval;
425        char *str;
426        long str_len, x, y = 0;
427        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlls", &_zval, &x, &y, &str, &str_len) == FAILURE) {
428                RETURN_FALSE;
429        }
430        caca_canvas_t *canvas;
431        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
432        if (str_len != 1) {
433                RETURN_FALSE;
434        }
435        RETURN_BOOL(caca_put_char(canvas, x, y, str[0]) == 0);
436}
437
438PHP_FUNCTION(caca_get_char) {
439        zval *_zval;
440        long x, y = 0;
441        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &_zval, &x, &y) == FAILURE) {
442                RETURN_FALSE;
443        }
444        caca_canvas_t *canvas;
445        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
446        RETURN_CHAR(caca_get_char(canvas, x, y));
447}
448
449PHP_FUNCTION(caca_put_str) {
450        zval *_zval;
451        char *str;
452        long x, y, str_len = 0;
453        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlls", &_zval, &x, &y, &str, &str_len) == FAILURE) {
454                RETURN_FALSE;
455        }
456        caca_canvas_t *canvas;
457        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
458        RETURN_BOOL(caca_put_str(canvas, x, y, str) == 0);
459}
460
461PHP_FUNCTION(caca_clear_canvas) {
462        caca_canvas_t *canvas;
463        FETCH_CANVAS(canvas);
464        RETURN_LONG(caca_clear_canvas(canvas));
465}
466
467PHP_FUNCTION(caca_set_canvas_handle) {
468        zval *_zval;
469        long x, y = 0;
470        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &_zval, &x, &y) == FAILURE) {
471                RETURN_FALSE;
472        }
473        caca_canvas_t *canvas;
474        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
475        RETURN_BOOL(caca_set_canvas_handle(canvas, x, y) == 0);
476}
477
478PHP_FUNCTION(caca_get_canvas_handle_x) {
479        caca_canvas_t *canvas;
480        FETCH_CANVAS(canvas);
481        RETURN_LONG(caca_get_canvas_handle_x(canvas));
482}
483
484PHP_FUNCTION(caca_get_canvas_handle_y) {
485        caca_canvas_t *canvas;
486        FETCH_CANVAS(canvas);
487        RETURN_LONG(caca_get_canvas_handle_y(canvas));
488}
489
490PHP_FUNCTION(caca_blit) {
491        zval *_zval1, *_zval2, *_zval3 = NULL;
492        long x, y = 0;
493        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllr|r", &_zval1, &x, &y, &_zval2, &_zval3) == FAILURE) {
494                RETURN_FALSE;
495        }
496        caca_canvas_t *dst, *src, *mask = NULL;
497        ZEND_FETCH_RESOURCE(dst, caca_canvas_t*, &_zval1, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
498        ZEND_FETCH_RESOURCE(src, caca_canvas_t*, &_zval2, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
499        if (_zval3) {
500                ZEND_FETCH_RESOURCE(mask, caca_canvas_t*, &_zval3, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
501        }
502        RETURN_BOOL(caca_blit(dst, x, y, src, NULL) == 0);
503}
504
505PHP_FUNCTION(caca_set_canvas_boundaries) {
506        zval *_zval;
507        long x, y, width, height = 0;
508        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllll", &_zval, &x, &y, &width, &height) == FAILURE) {
509                RETURN_FALSE;
510        }
511        caca_canvas_t *canvas;
512        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
513        RETURN_BOOL(caca_set_canvas_boundaries(canvas, x, y, width, height) == 0);
514}
515
516PHP_FUNCTION(caca_invert) {
517        caca_canvas_t *canvas;
518        FETCH_CANVAS(canvas);
519        RETURN_BOOL(caca_invert(canvas) == 0);
520}
521
522PHP_FUNCTION(caca_flip) {
523        caca_canvas_t *canvas;
524        FETCH_CANVAS(canvas);
525        RETURN_BOOL(caca_flip(canvas) == 0);
526}
527
528PHP_FUNCTION(caca_flop) {
529        caca_canvas_t *canvas;
530        FETCH_CANVAS(canvas);
531        RETURN_BOOL(caca_flop(canvas) == 0);
532}
533
534PHP_FUNCTION(caca_rotate_180) {
535        caca_canvas_t *canvas;
536        FETCH_CANVAS(canvas);
537        RETURN_BOOL(caca_rotate_180(canvas) == 0);
538}
539
540PHP_FUNCTION(caca_rotate_left) {
541        caca_canvas_t *canvas;
542        FETCH_CANVAS(canvas);
543        RETURN_BOOL(caca_rotate_left(canvas) == 0);
544}
545
546PHP_FUNCTION(caca_rotate_right) {
547        caca_canvas_t *canvas;
548        FETCH_CANVAS(canvas);
549        RETURN_BOOL(caca_rotate_right(canvas) == 0);
550}
551
552PHP_FUNCTION(caca_stretch_left) {
553        caca_canvas_t *canvas;
554        FETCH_CANVAS(canvas);
555        RETURN_BOOL(caca_stretch_left(canvas) == 0);
556}
557
558PHP_FUNCTION(caca_stretch_right) {
559        caca_canvas_t *canvas;
560        FETCH_CANVAS(canvas);
561        RETURN_BOOL(caca_stretch_right(canvas) == 0);
562}
563
564PHP_FUNCTION(caca_get_attr) {
565}
566
567PHP_FUNCTION(caca_set_attr) {
568}
569
570PHP_FUNCTION(caca_put_attr) {
571}
572
573PHP_FUNCTION(caca_set_color_ansi) {
574        zval *_zval;
575        long foreground, background = 0;
576        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &_zval, &foreground, &background) == FAILURE) {
577                RETURN_FALSE;
578        }
579        caca_canvas_t *canvas;
580        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
581        RETURN_BOOL(caca_set_color_ansi(canvas, foreground, background) == 0);
582}
583
584PHP_FUNCTION(caca_set_color_argb) {
585}
586
587PHP_FUNCTION(caca_attr_to_ansi) {
588}
589
590PHP_FUNCTION(caca_attr_to_ansi_fg) {
591}
592
593PHP_FUNCTION(caca_attr_to_ansi_bg) {
594}
595
596PHP_FUNCTION(caca_draw_line) {
597        zval *_zval;
598        char *str;
599        long str_len, xa, ya, xb, yb = 0;
600        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlllls", &_zval, &xa, &ya, &xb, &yb, &str, &str_len) == FAILURE) {
601                RETURN_FALSE;
602        }
603        caca_canvas_t *canvas;
604        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
605        if (str_len != 1) {
606                RETURN_FALSE;
607        }
608        RETURN_BOOL(caca_draw_line(canvas, xa, ya, xb, yb, str[0]) == 0);
609}
610
611PHP_FUNCTION(caca_draw_polyline) {
612}
613
614PHP_FUNCTION(caca_draw_thin_line) {
615        zval *_zval;
616        long xa, ya, xb, yb = 0;
617        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllll", &_zval, &xa, &ya, &xb, &yb) == FAILURE) {
618                RETURN_FALSE;
619        }
620        caca_canvas_t *canvas;
621        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
622        RETURN_BOOL(caca_draw_thin_line(canvas, xa, ya, xb, yb) == 0);
623}
624
625PHP_FUNCTION(caca_draw_thin_polyline) {
626}
627
628PHP_FUNCTION(caca_draw_circle) {
629        zval *_zval;
630        char *str;
631        long str_len, x, y, r = 0;
632        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllls", &_zval, &x, &y, &r, &str, &str_len) == FAILURE) {
633                RETURN_FALSE;
634        }
635        caca_canvas_t *canvas;
636        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
637        if (str_len != 1) {
638                RETURN_FALSE;
639        }
640        RETURN_BOOL(caca_draw_circle(canvas, x, y, r, str[0]) == 0);
641}
642
643PHP_FUNCTION(caca_draw_ellipse) {
644        zval *_zval;
645        char *str;
646        long str_len, xa, ya, xb, yb = 0;
647        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlllls", &_zval, &xa, &ya, &xb, &yb, &str, &str_len) == FAILURE) {
648                RETURN_FALSE;
649        }
650        caca_canvas_t *canvas;
651        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
652        if (str_len != 1) {
653                RETURN_FALSE;
654        }
655        RETURN_BOOL(caca_draw_ellipse(canvas, xa, ya, xb, yb, str[0]) == 0);
656}
657
658PHP_FUNCTION(caca_draw_thin_ellipse) {
659        zval *_zval;
660        long xa, ya, xb, yb = 0;
661        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllll", &_zval, &xa, &ya, &xb, &yb) == FAILURE) {
662                RETURN_FALSE;
663        }
664        caca_canvas_t *canvas;
665        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
666        RETURN_BOOL(caca_draw_thin_ellipse(canvas, xa, ya, xb, yb) == 0);
667}
668
669PHP_FUNCTION(caca_fill_ellipse) {
670        zval *_zval;
671        char *str;
672        long str_len, xa, ya, xb, yb = 0;
673        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlllls", &_zval, &xa, &ya, &xb, &yb, &str, &str_len) == FAILURE) {
674                RETURN_FALSE;
675        }
676        caca_canvas_t *canvas;
677        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
678        if (str_len != 1) {
679                RETURN_FALSE;
680        }
681        RETURN_BOOL(caca_fill_ellipse(canvas, xa, ya, xb, yb, str[0]) == 0);
682}
683
684PHP_FUNCTION(caca_draw_box) {
685        zval *_zval;
686        char *str;
687        long str_len, xa, ya, xb, yb = 0;
688        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlllls", &_zval, &xa, &ya, &xb, &yb, &str, &str_len) == FAILURE) {
689                RETURN_FALSE;
690        }
691        caca_canvas_t *canvas;
692        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
693        if (str_len != 1) {
694                RETURN_FALSE;
695        }
696        RETURN_BOOL(caca_draw_box(canvas, xa, ya, xb, yb, str[0]) == 0);
697}
698
699PHP_FUNCTION(caca_draw_thin_box) {
700        zval *_zval;
701        long xa, ya, xb, yb = 0;
702        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllll", &_zval, &xa, &ya, &xb, &yb) == FAILURE) {
703                RETURN_FALSE;
704        }
705        caca_canvas_t *canvas;
706        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
707        RETURN_BOOL(caca_draw_thin_box(canvas, xa, ya, xb, yb) == 0);
708}
709
710PHP_FUNCTION(caca_draw_cp437_box) {
711        zval *_zval;
712        long xa, ya, xb, yb = 0;
713        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllll", &_zval, &xa, &ya, &xb, &yb) == FAILURE) {
714                RETURN_FALSE;
715        }
716        caca_canvas_t *canvas;
717        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
718        RETURN_BOOL(caca_draw_cp437_box(canvas, xa, ya, xb, yb) == 0);
719}
720
721PHP_FUNCTION(caca_fill_box) {
722        zval *_zval;
723        char *str;
724        long str_len, xa, ya, xb, yb = 0;
725        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlllls", &_zval, &xa, &ya, &xb, &yb, &str, &str_len) == FAILURE) {
726                RETURN_FALSE;
727        }
728        caca_canvas_t *canvas;
729        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
730        if (str_len != 1) {
731                RETURN_FALSE;
732        }
733        RETURN_BOOL(caca_fill_box(canvas, xa, ya, xb, yb, str[0]) == 0);
734}
735
736PHP_FUNCTION(caca_draw_triangle) {
737        zval *_zval;
738        char *str;
739        long str_len, xa, ya, xb, yb, xc, yc = 0;
740        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlllllls", &_zval, &xa, &ya, &xb, &yb, &xc, &yc, &str, &str_len) == FAILURE) {
741                RETURN_FALSE;
742        }
743        caca_canvas_t *canvas;
744        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
745        if (str_len != 1) {
746                RETURN_FALSE;
747        }
748        RETURN_BOOL(caca_draw_triangle(canvas, xa, ya, xb, yb, xc, yc, str[0]) == 0);
749}
750
751PHP_FUNCTION(caca_draw_thin_triangle) {
752        zval *_zval;
753        long xa, ya, xb, yb, xc, yc = 0;
754        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllllll", &_zval, &xa, &ya, &xb, &yb, &xc, &yc) == FAILURE) {
755                RETURN_FALSE;
756        }
757        caca_canvas_t *canvas;
758        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
759        RETURN_BOOL(caca_draw_thin_triangle(canvas, xa, ya, xb, yb, xc, yc) == 0);
760}
761
762PHP_FUNCTION(caca_fill_triangle) {
763        zval *_zval;
764        char *str;
765        long str_len, xa, ya, xb, yb, xc, yc = 0;
766        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlllllls", &_zval, &xa, &ya, &xb, &yb, &xc, &yc, &str, &str_len) == FAILURE) {
767                RETURN_FALSE;
768        }
769        caca_canvas_t *canvas;
770        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
771        if (str_len != 1) {
772                RETURN_FALSE;
773        }
774        RETURN_BOOL(caca_fill_triangle(canvas, xa, ya, xb, yb, xc, yc, str[0]) == 0);
775}
776
777PHP_FUNCTION(caca_get_frame_count) {
778}
779
780PHP_FUNCTION(caca_set_frame) {
781}
782
783PHP_FUNCTION(caca_set_frame_name) {
784}
785
786PHP_FUNCTION(caca_create_frame) {
787}
788
789PHP_FUNCTION(caca_free_frame) {
790}
791
792PHP_FUNCTION(caca_set_dither_palette) {
793}
794
795PHP_FUNCTION(caca_set_dither_brightness) {
796}
797
798PHP_FUNCTION(caca_get_dither_brightness) {
799}
800
801PHP_FUNCTION(caca_set_dither_gamma) {
802}
803
804PHP_FUNCTION(caca_get_dither_gamma) {
805}
806
807PHP_FUNCTION(caca_set_dither_contrast) {
808}
809
810PHP_FUNCTION(caca_get_dither_contrast) {
811}
812
813PHP_FUNCTION(caca_set_dither_antialias) {
814}
815
816PHP_FUNCTION(caca_get_dither_antialias_list) {
817}
818
819PHP_FUNCTION(caca_get_dither_antialias) {
820}
821
822PHP_FUNCTION(caca_set_dither_color) {
823}
824
825PHP_FUNCTION(caca_get_dither_color_list) {
826}
827
828PHP_FUNCTION(caca_get_dither_color) {
829}
830
831PHP_FUNCTION(caca_set_dither_charset) {
832}
833
834PHP_FUNCTION(caca_get_dither_charset_list) {
835}
836
837PHP_FUNCTION(caca_get_dither_charset) {
838}
839
840PHP_FUNCTION(caca_set_dither_algorithm) {
841}
842
843PHP_FUNCTION(caca_get_dither_algorithm_list) {
844}
845
846PHP_FUNCTION(caca_get_dither_algorithm) {
847}
848
849PHP_FUNCTION(caca_dither_bitmap) {
850}
851
852PHP_FUNCTION(caca_get_font_list) {
853}
854
855PHP_FUNCTION(caca_get_font_width) {
856}
857
858PHP_FUNCTION(caca_get_font_height) {
859}
860
861PHP_FUNCTION(caca_render_canvas) {
862}
863
864PHP_FUNCTION(caca_canvas_set_figfont) {
865}
866
867PHP_FUNCTION(caca_put_figchar) {
868}
869
870PHP_FUNCTION(caca_flush_figlet) {
871}
872
873PHP_FUNCTION(caca_file_close) {
874}
875
876PHP_FUNCTION(caca_file_tell) {
877}
878
879PHP_FUNCTION(caca_file_read) {
880}
881
882PHP_FUNCTION(caca_file_write) {
883}
884
885PHP_FUNCTION(caca_file_gets) {
886}
887
888PHP_FUNCTION(caca_file_eof) {
889}
890
891PHP_FUNCTION(caca_import_memory) {
892        zval *_zval;
893        char *src, *type;
894        long src_len, type_len = 0;
895        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss", &_zval, &src, &src_len, &type, &type_len) == FAILURE) {
896                RETURN_FALSE;
897        }
898        caca_canvas_t *canvas;
899        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
900
901        RETURN_LONG(caca_import_memory(canvas, src, src_len, type));
902}
903
904PHP_FUNCTION(caca_import_file) {
905}
906
907PHP_FUNCTION(caca_get_import_list) {
908}
909
910PHP_FUNCTION(caca_get_export_list) {
911}
912
913PHP_FUNCTION(caca_create_display) {
914        caca_canvas_t *canvas;
915        FETCH_CANVAS(canvas);
916
917        caca_display_t *display = caca_create_display(canvas);
918        ZEND_REGISTER_RESOURCE(return_value, display, le_caca_display);
919}
920
921PHP_FUNCTION(caca_create_display_with_driver) {
922        zval *_zval;
923        char *str;
924        long str_len = 0;
925        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &_zval, &str, &str_len) == FAILURE) {
926                RETURN_FALSE;
927        }
928        caca_canvas_t *canvas;
929        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
930
931        caca_display_t *display = caca_create_display_with_driver(canvas, str);
932        if (!display) {
933                RETURN_FALSE;
934        }
935        ZEND_REGISTER_RESOURCE(return_value, display, le_caca_display);
936}
937
938PHP_FUNCTION(caca_get_display_driver_list) {
939}
940
941PHP_FUNCTION(caca_get_display_driver) {
942}
943
944PHP_FUNCTION(caca_set_display_driver) {
945}
946
947PHP_FUNCTION(caca_get_canvas) {
948}
949
950PHP_FUNCTION(caca_refresh_display) {
951        caca_display_t *display;
952        FETCH_DISPLAY(display);
953        RETURN_BOOL(caca_refresh_display(display) == 0);
954}
955
956PHP_FUNCTION(caca_set_display_time) {
957        zval *_zval;
958        long value = 0;
959        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &_zval, &value) == FAILURE) {
960                RETURN_FALSE;
961        }
962        caca_display_t *display;
963        ZEND_FETCH_RESOURCE(display, caca_display_t*, &_zval, -1, PHP_CACA_DISPLAY_RES_NAME, le_caca_display);
964        RETURN_BOOL(caca_set_display_time(display, value) == 0);
965}
966
967PHP_FUNCTION(caca_get_display_time) {
968        caca_display_t *display;
969        FETCH_DISPLAY(display);
970        RETURN_LONG(caca_get_display_time(display)); //TODO: check return value
971}
972
973PHP_FUNCTION(caca_get_display_width) {
974        caca_display_t *display;
975        FETCH_DISPLAY(display);
976        RETURN_LONG(caca_get_display_width(display));
977}
978
979PHP_FUNCTION(caca_get_display_height) {
980        caca_display_t *display;
981        FETCH_DISPLAY(display);
982        RETURN_LONG(caca_get_display_height(display));
983}
984
985PHP_FUNCTION(caca_set_display_title) {
986        zval *_zval;
987        char *str;
988        long str_len = 0;
989        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &_zval, &str, &str_len) == FAILURE) {
990                RETURN_FALSE;
991        }
992        caca_display_t *display;
993        ZEND_FETCH_RESOURCE(display, caca_display_t*, &_zval, -1, PHP_CACA_DISPLAY_RES_NAME, le_caca_display);
994        RETURN_BOOL(caca_set_display(display, str) == 0);
995}
996
997PHP_FUNCTION(caca_set_mouse) {
998        zval *_zval;
999        long value = 0;
1000        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &_zval, &value) == FAILURE) {
1001                RETURN_FALSE;
1002        }
1003        caca_display_t *display;
1004        ZEND_FETCH_RESOURCE(display, caca_display_t*, &_zval, -1, PHP_CACA_DISPLAY_RES_NAME, le_caca_display);
1005        RETURN_BOOL(caca_set_mouse(display, value) == 0);
1006}
1007
1008PHP_FUNCTION(caca_set_cursor) {
1009        zval *_zval;
1010        long value = 0;
1011        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &_zval, &value) == FAILURE) {
1012                RETURN_FALSE;
1013        }
1014        caca_display_t *display;
1015        ZEND_FETCH_RESOURCE(display, caca_display_t*, &_zval, -1, PHP_CACA_DISPLAY_RES_NAME, le_caca_display);
1016        RETURN_BOOL(caca_set_cursor(display, value) == 0);
1017}
1018
1019PHP_FUNCTION(caca_get_event) {
1020        zval *_zval1, *_zval2 = NULL;
1021        long g, aa = 0;
1022        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl|rl", &_zval1, &g, &_zval2, &aa) == FAILURE) {
1023                RETURN_FALSE;
1024        }
1025        caca_display_t *display;
1026        ZEND_FETCH_RESOURCE(display, caca_display_t*, &_zval1, -1, PHP_CACA_DISPLAY_RES_NAME, le_caca_display);
1027
1028        caca_event_t *event = NULL;
1029        if (_zval2) {
1030                ZEND_FETCH_RESOURCE(event, caca_event_t*, &_zval2, -1, PHP_CACA_EVENT_RES_NAME, le_caca_event);
1031        }
1032        RETURN_LONG(caca_get_event(display, g, event, aa));
1033}
1034
1035PHP_FUNCTION(caca_get_mouse_x) {
1036        caca_display_t *display;
1037        FETCH_DISPLAY(display);
1038        RETURN_LONG(caca_get_mouse_x(display));
1039}
1040
1041PHP_FUNCTION(caca_get_mouse_y) {
1042        caca_display_t *display;
1043        FETCH_DISPLAY(display);
1044        RETURN_LONG(caca_get_mouse_y(display));
1045}
1046
1047PHP_FUNCTION(caca_get_event_type) {
1048        caca_event_t *event;
1049        FETCH_EVENT(event);
1050        RETURN_LONG(caca_get_event_type(event));
1051}
1052
1053PHP_FUNCTION(caca_get_event_key_ch) {
1054        caca_event_t *event;
1055        FETCH_EVENT(event);
1056        RETURN_LONG(caca_get_event_key_ch(event));
1057}
1058
1059PHP_FUNCTION(caca_get_event_mouse_button) {
1060        caca_event_t *event;
1061        FETCH_EVENT(event);
1062        RETURN_LONG(caca_get_event_mouse_button(event));
1063}
1064
1065PHP_FUNCTION(caca_get_event_mouse_x) {
1066        caca_event_t *event;
1067        FETCH_EVENT(event);
1068        RETURN_LONG(caca_get_event_mouse_x(event));
1069}
1070
1071PHP_FUNCTION(caca_get_event_mouse_y) {
1072        caca_event_t *event;
1073        FETCH_EVENT(event);
1074        RETURN_LONG(caca_get_event_mouse_y(event));
1075}
1076
1077PHP_FUNCTION(caca_get_event_resize_width) {
1078        caca_event_t *event;
1079        FETCH_EVENT(event);
1080        RETURN_LONG(caca_get_event_resize_width(event));
1081}
1082
1083PHP_FUNCTION(caca_get_event_resize_height) {
1084        caca_event_t *event;
1085        FETCH_EVENT(event);
1086        RETURN_LONG(caca_get_event_resize_height(event));
1087}
1088
Note: See TracBrowser for help on using the repository browser.