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

Last change on this file since 3113 was 3113, checked in by nico, 12 years ago
  • Add php binding for 15 new functions
  • Add new sample program "examples/drivers.php"
File size: 39.6 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_180, NULL)
48        PHP_FE(caca_rotate_left, NULL)
49        PHP_FE(caca_rotate_right, NULL)
50        PHP_FE(caca_stretch_left, NULL)
51        PHP_FE(caca_stretch_right, NULL)
52        PHP_FE(caca_get_attr, NULL)
53        PHP_FE(caca_set_attr, NULL)
54        PHP_FE(caca_put_attr, NULL)
55        PHP_FE(caca_set_color_ansi, NULL)
56        PHP_FE(caca_set_color_argb, NULL)
57        PHP_FE(caca_attr_to_ansi, NULL)
58        PHP_FE(caca_attr_to_ansi_fg, NULL)
59        PHP_FE(caca_attr_to_ansi_bg, NULL)
60        PHP_FE(caca_attr_to_rgb12_fg, NULL)
61        PHP_FE(caca_attr_to_rgb12_bg, NULL)
62        PHP_FE(caca_attr_to_argb64, NULL)
63        PHP_FE(caca_utf8_to_utf32, NULL)
64        PHP_FE(caca_utf32_to_utf8, NULL)
65        PHP_FE(caca_utf32_to_cp437, NULL)
66        PHP_FE(caca_cp437_to_utf32, NULL)
67        PHP_FE(caca_utf32_to_ascii, NULL)
68        PHP_FE(caca_utf32_is_fullwidth, NULL)
69        PHP_FE(caca_draw_line, NULL)
70        PHP_FE(caca_draw_polyline, NULL)
71        PHP_FE(caca_draw_thin_line, NULL)
72        PHP_FE(caca_draw_thin_polyline, NULL)
73        PHP_FE(caca_draw_circle, NULL)
74        PHP_FE(caca_draw_ellipse, NULL)
75        PHP_FE(caca_draw_thin_ellipse, NULL)
76        PHP_FE(caca_fill_ellipse, NULL)
77        PHP_FE(caca_draw_box, NULL)
78        PHP_FE(caca_draw_thin_box, NULL)
79        PHP_FE(caca_draw_cp437_box, NULL)
80        PHP_FE(caca_fill_box, NULL)
81        PHP_FE(caca_draw_triangle, NULL)
82        PHP_FE(caca_draw_thin_triangle, NULL)
83        PHP_FE(caca_fill_triangle, NULL)
84        PHP_FE(caca_get_frame_count, NULL)
85        PHP_FE(caca_set_frame, NULL)
86        PHP_FE(caca_set_frame_name, NULL)
87        PHP_FE(caca_create_frame, NULL)
88        PHP_FE(caca_free_frame, NULL)
89        PHP_FE(caca_set_dither_palette, NULL)
90        PHP_FE(caca_set_dither_brightness, NULL)
91        PHP_FE(caca_get_dither_brightness, NULL)
92        PHP_FE(caca_set_dither_gamma, NULL)
93        PHP_FE(caca_get_dither_gamma, NULL)
94        PHP_FE(caca_set_dither_contrast, NULL)
95        PHP_FE(caca_get_dither_contrast, NULL)
96        PHP_FE(caca_set_dither_antialias, NULL)
97        PHP_FE(caca_get_dither_antialias_list, NULL)
98        PHP_FE(caca_get_dither_antialias, NULL)
99        PHP_FE(caca_set_dither_color, NULL)
100        PHP_FE(caca_get_dither_color_list, NULL)
101        PHP_FE(caca_get_dither_color, NULL)
102        PHP_FE(caca_set_dither_charset, NULL)
103        PHP_FE(caca_get_dither_charset_list, NULL)
104        PHP_FE(caca_get_dither_charset, NULL)
105        PHP_FE(caca_set_dither_algorithm, NULL)
106        PHP_FE(caca_get_dither_algorithm_list, NULL)
107        PHP_FE(caca_get_dither_algorithm, NULL)
108        PHP_FE(caca_dither_bitmap, NULL)
109        PHP_FE(caca_get_font_list, NULL)
110        PHP_FE(caca_get_font_width, NULL)
111        PHP_FE(caca_get_font_height, NULL)
112        PHP_FE(caca_render_canvas, NULL)
113        PHP_FE(caca_canvas_set_figfont, NULL)
114        PHP_FE(caca_put_figchar, NULL)
115        PHP_FE(caca_flush_figlet, NULL)
116        PHP_FE(caca_file_close, NULL)
117        PHP_FE(caca_file_tell, NULL)
118        PHP_FE(caca_file_read, NULL)
119        PHP_FE(caca_file_write, NULL)
120        PHP_FE(caca_file_gets, NULL)
121        PHP_FE(caca_file_eof, NULL)
122        PHP_FE(caca_import_string, NULL)
123        PHP_FE(caca_import_file, NULL)
124        PHP_FE(caca_get_import_list, NULL)
125        PHP_FE(caca_export_string, NULL)
126        PHP_FE(caca_get_export_list, NULL)
127        PHP_FE(caca_create_display, NULL)
128        PHP_FE(caca_create_display_with_driver, NULL)
129        PHP_FE(caca_get_display_driver_list, NULL)
130        PHP_FE(caca_get_display_driver, NULL)
131        PHP_FE(caca_set_display_driver, NULL)
132        PHP_FE(caca_get_canvas, NULL)
133        PHP_FE(caca_refresh_display, NULL)
134        PHP_FE(caca_set_display_time, NULL)
135        PHP_FE(caca_get_display_time, NULL)
136        PHP_FE(caca_get_display_width, NULL)
137        PHP_FE(caca_get_display_height, NULL)
138        PHP_FE(caca_set_display_title, NULL)
139        PHP_FE(caca_set_mouse, NULL)
140        PHP_FE(caca_set_cursor, NULL)
141        PHP_FE(caca_get_event, NULL)
142        PHP_FE(caca_get_mouse_x, NULL)
143        PHP_FE(caca_get_mouse_y, NULL)
144        PHP_FE(caca_get_event_type, NULL)
145        PHP_FE(caca_get_event_key_ch, NULL)
146        PHP_FE(caca_get_event_mouse_button, NULL)
147        PHP_FE(caca_get_event_mouse_x, NULL)
148        PHP_FE(caca_get_event_mouse_y, NULL)
149        PHP_FE(caca_get_event_resize_width, NULL)
150        PHP_FE(caca_get_event_resize_height, NULL)
151
152        {NULL, NULL, NULL}
153};
154
155zend_module_entry caca_module_entry = {
156#if ZEND_MODULE_API_NO >= 20010901
157        STANDARD_MODULE_HEADER,
158#endif
159        PHP_CACA_EXTNAME,
160        caca_functions,
161        PHP_MINIT(caca),
162        NULL,
163        NULL,
164        NULL,
165        PHP_MINFO(caca),
166#if ZEND_MODULE_API_NO >= 20010901
167        PHP_CACA_VERSION,
168#endif
169        STANDARD_MODULE_PROPERTIES
170};
171
172#ifdef COMPILE_DL_CACA
173ZEND_GET_MODULE(caca)
174#endif
175
176PHP_MINFO_FUNCTION(caca) {
177        php_info_print_table_start();
178        php_info_print_table_row(2, "Caca library version", caca_get_version());
179        php_info_print_table_end();
180}
181
182//-------- Caca's ressources destructors -----------//
183
184static void php_caca_canvas_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) {
185        caca_free_canvas(rsrc->ptr);
186}
187
188static void php_caca_dither_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) {
189        caca_free_dither(rsrc->ptr);
190}
191
192static void php_caca_font_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) {
193        caca_free_font(rsrc->ptr);
194}
195
196static void php_caca_file_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) {
197}
198
199static void php_caca_display_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) {
200        caca_free_display(rsrc->ptr);
201}
202
203static void php_caca_event_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) {
204        efree((caca_event_t *) rsrc->ptr);
205}
206
207//-------- Initialization ---------//
208
209PHP_MINIT_FUNCTION(caca) {
210
211        le_caca_canvas = zend_register_list_destructors_ex(php_caca_canvas_dtor, NULL, PHP_CACA_CANVAS_RES_NAME, module_number);
212        le_caca_dither = zend_register_list_destructors_ex(php_caca_dither_dtor, NULL, PHP_CACA_DITHER_RES_NAME, module_number);
213        le_caca_font = zend_register_list_destructors_ex(php_caca_font_dtor, NULL, PHP_CACA_FONT_RES_NAME, module_number);
214        le_caca_file = zend_register_list_destructors_ex(php_caca_file_dtor, NULL, PHP_CACA_FILE_RES_NAME, module_number);
215        le_caca_display = zend_register_list_destructors_ex(php_caca_display_dtor, NULL, PHP_CACA_DISPLAY_RES_NAME, module_number);
216        le_caca_event = zend_register_list_destructors_ex(php_caca_event_dtor, NULL, PHP_CACA_EVENT_RES_NAME, module_number);
217       
218        REGISTER_LONG_CONSTANT("CACA_BLACK", CACA_BLACK, CONST_CS | CONST_PERSISTENT);
219        REGISTER_LONG_CONSTANT("CACA_BLUE", CACA_BLUE, CONST_CS | CONST_PERSISTENT);
220        REGISTER_LONG_CONSTANT("CACA_GREEN", CACA_GREEN, CONST_CS | CONST_PERSISTENT);
221        REGISTER_LONG_CONSTANT("CACA_CYAN", CACA_CYAN, CONST_CS | CONST_PERSISTENT);
222        REGISTER_LONG_CONSTANT("CACA_RED", CACA_RED, CONST_CS | CONST_PERSISTENT);
223        REGISTER_LONG_CONSTANT("CACA_MAGENTA", CACA_MAGENTA, CONST_CS | CONST_PERSISTENT);
224        REGISTER_LONG_CONSTANT("CACA_BROWN", CACA_BROWN, CONST_CS | CONST_PERSISTENT);
225        REGISTER_LONG_CONSTANT("CACA_LIGHTGRAY", CACA_LIGHTGRAY, CONST_CS | CONST_PERSISTENT);
226        REGISTER_LONG_CONSTANT("CACA_DARKGRAY", CACA_DARKGRAY, CONST_CS | CONST_PERSISTENT);
227        REGISTER_LONG_CONSTANT("CACA_LIGHTBLUE", CACA_LIGHTBLUE, CONST_CS | CONST_PERSISTENT);
228        REGISTER_LONG_CONSTANT("CACA_LIGHTGREEN", CACA_LIGHTGREEN, CONST_CS | CONST_PERSISTENT);
229        REGISTER_LONG_CONSTANT("CACA_LIGHTCYAN", CACA_LIGHTCYAN, CONST_CS | CONST_PERSISTENT);
230        REGISTER_LONG_CONSTANT("CACA_LIGHTRED", CACA_LIGHTRED, CONST_CS | CONST_PERSISTENT);
231        REGISTER_LONG_CONSTANT("CACA_LIGHTMAGENTA", CACA_LIGHTMAGENTA, CONST_CS | CONST_PERSISTENT);
232        REGISTER_LONG_CONSTANT("CACA_YELLOW", CACA_YELLOW, CONST_CS | CONST_PERSISTENT);
233        REGISTER_LONG_CONSTANT("CACA_WHITE", CACA_WHITE, CONST_CS | CONST_PERSISTENT);
234        REGISTER_LONG_CONSTANT("CACA_DEFAULT", CACA_DEFAULT, CONST_CS | CONST_PERSISTENT);
235        REGISTER_LONG_CONSTANT("CACA_TRANSPARENT", CACA_TRANSPARENT, CONST_CS | CONST_PERSISTENT);
236        REGISTER_LONG_CONSTANT("CACA_BOLD", CACA_BOLD, CONST_CS | CONST_PERSISTENT);
237        REGISTER_LONG_CONSTANT("CACA_ITALICS", CACA_ITALICS, CONST_CS | CONST_PERSISTENT);
238        REGISTER_LONG_CONSTANT("CACA_UNDERLINE", CACA_UNDERLINE, CONST_CS | CONST_PERSISTENT);
239        REGISTER_LONG_CONSTANT("CACA_BLINK", CACA_BLINK, CONST_CS | CONST_PERSISTENT);
240
241        REGISTER_LONG_CONSTANT("CACA_EVENT_NONE", CACA_EVENT_NONE, CONST_CS | CONST_PERSISTENT);
242        REGISTER_LONG_CONSTANT("CACA_EVENT_KEY_PRESS", CACA_EVENT_KEY_PRESS, CONST_CS | CONST_PERSISTENT);
243        REGISTER_LONG_CONSTANT("CACA_EVENT_KEY_RELEASE", CACA_EVENT_KEY_RELEASE, CONST_CS | CONST_PERSISTENT);
244        REGISTER_LONG_CONSTANT("CACA_EVENT_MOUSE_PRESS", CACA_EVENT_MOUSE_PRESS, CONST_CS | CONST_PERSISTENT);
245        REGISTER_LONG_CONSTANT("CACA_EVENT_MOUSE_RELEASE", CACA_EVENT_MOUSE_RELEASE, CONST_CS | CONST_PERSISTENT);
246        REGISTER_LONG_CONSTANT("CACA_EVENT_MOUSE_MOTION", CACA_EVENT_MOUSE_MOTION, CONST_CS | CONST_PERSISTENT);
247        REGISTER_LONG_CONSTANT("CACA_EVENT_RESIZE", CACA_EVENT_RESIZE, CONST_CS | CONST_PERSISTENT);
248        REGISTER_LONG_CONSTANT("CACA_EVENT_QUIT", CACA_EVENT_QUIT, CONST_CS | CONST_PERSISTENT);
249        REGISTER_LONG_CONSTANT("CACA_EVENT_ANY", CACA_EVENT_ANY, CONST_CS | CONST_PERSISTENT);
250
251        REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_A", CACA_KEY_CTRL_A, CONST_CS | CONST_PERSISTENT);
252        REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_B", CACA_KEY_CTRL_B, CONST_CS | CONST_PERSISTENT);
253        REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_C", CACA_KEY_CTRL_C, CONST_CS | CONST_PERSISTENT);
254        REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_D", CACA_KEY_CTRL_D, CONST_CS | CONST_PERSISTENT);
255        REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_E", CACA_KEY_CTRL_E, CONST_CS | CONST_PERSISTENT);
256        REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_F", CACA_KEY_CTRL_F, CONST_CS | CONST_PERSISTENT);
257        REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_G", CACA_KEY_CTRL_G, CONST_CS | CONST_PERSISTENT);
258        REGISTER_LONG_CONSTANT("CACA_KEY_BACKSPACE", CACA_KEY_BACKSPACE, CONST_CS | CONST_PERSISTENT);
259        REGISTER_LONG_CONSTANT("CACA_KEY_TAB", CACA_KEY_TAB, CONST_CS | CONST_PERSISTENT);
260        REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_J", CACA_KEY_CTRL_J, CONST_CS | CONST_PERSISTENT);
261        REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_K", CACA_KEY_CTRL_K, CONST_CS | CONST_PERSISTENT);
262        REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_L", CACA_KEY_CTRL_L, CONST_CS | CONST_PERSISTENT);
263        REGISTER_LONG_CONSTANT("CACA_KEY_RETURN", CACA_KEY_RETURN, CONST_CS | CONST_PERSISTENT);
264        REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_N", CACA_KEY_CTRL_N, CONST_CS | CONST_PERSISTENT);
265        REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_O", CACA_KEY_CTRL_O, CONST_CS | CONST_PERSISTENT);
266        REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_P", CACA_KEY_CTRL_P, CONST_CS | CONST_PERSISTENT);
267        REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_Q", CACA_KEY_CTRL_Q, CONST_CS | CONST_PERSISTENT);
268        REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_R", CACA_KEY_CTRL_R, CONST_CS | CONST_PERSISTENT);
269        REGISTER_LONG_CONSTANT("CACA_KEY_PAUSE", CACA_KEY_PAUSE, CONST_CS | CONST_PERSISTENT);
270        REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_T", CACA_KEY_CTRL_T, CONST_CS | CONST_PERSISTENT);
271        REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_U", CACA_KEY_CTRL_U, CONST_CS | CONST_PERSISTENT);
272        REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_V", CACA_KEY_CTRL_V, CONST_CS | CONST_PERSISTENT);
273        REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_W", CACA_KEY_CTRL_W, CONST_CS | CONST_PERSISTENT);
274        REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_X", CACA_KEY_CTRL_X, CONST_CS | CONST_PERSISTENT);
275        REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_Y", CACA_KEY_CTRL_Y, CONST_CS | CONST_PERSISTENT);
276        REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_Z", CACA_KEY_CTRL_Z, CONST_CS | CONST_PERSISTENT);
277        REGISTER_LONG_CONSTANT("CACA_KEY_ESCAPE", CACA_KEY_ESCAPE, CONST_CS | CONST_PERSISTENT);
278        REGISTER_LONG_CONSTANT("CACA_KEY_DELETE", CACA_KEY_DELETE, CONST_CS | CONST_PERSISTENT);
279        REGISTER_LONG_CONSTANT("CACA_KEY_UP", CACA_KEY_UP, CONST_CS | CONST_PERSISTENT);
280        REGISTER_LONG_CONSTANT("CACA_KEY_DOWN", CACA_KEY_DOWN, CONST_CS | CONST_PERSISTENT);
281        REGISTER_LONG_CONSTANT("CACA_KEY_LEFT", CACA_KEY_LEFT, CONST_CS | CONST_PERSISTENT);
282        REGISTER_LONG_CONSTANT("CACA_KEY_RIGHT", CACA_KEY_RIGHT, CONST_CS | CONST_PERSISTENT);
283        REGISTER_LONG_CONSTANT("CACA_KEY_INSERT", CACA_KEY_INSERT, CONST_CS | CONST_PERSISTENT);
284        REGISTER_LONG_CONSTANT("CACA_KEY_HOME", CACA_KEY_HOME, CONST_CS | CONST_PERSISTENT);
285        REGISTER_LONG_CONSTANT("CACA_KEY_END", CACA_KEY_END, CONST_CS | CONST_PERSISTENT);
286        REGISTER_LONG_CONSTANT("CACA_KEY_PAGEUP", CACA_KEY_PAGEUP, CONST_CS | CONST_PERSISTENT);
287        REGISTER_LONG_CONSTANT("CACA_KEY_PAGEDOWN", CACA_KEY_PAGEDOWN, CONST_CS | CONST_PERSISTENT);
288        REGISTER_LONG_CONSTANT("CACA_KEY_F1", CACA_KEY_F1, CONST_CS | CONST_PERSISTENT);
289        REGISTER_LONG_CONSTANT("CACA_KEY_F2", CACA_KEY_F2, CONST_CS | CONST_PERSISTENT);
290        REGISTER_LONG_CONSTANT("CACA_KEY_F3", CACA_KEY_F3, CONST_CS | CONST_PERSISTENT);
291        REGISTER_LONG_CONSTANT("CACA_KEY_F4", CACA_KEY_F4, CONST_CS | CONST_PERSISTENT);
292        REGISTER_LONG_CONSTANT("CACA_KEY_F5", CACA_KEY_F5, CONST_CS | CONST_PERSISTENT);
293        REGISTER_LONG_CONSTANT("CACA_KEY_F6", CACA_KEY_F6, CONST_CS | CONST_PERSISTENT);
294        REGISTER_LONG_CONSTANT("CACA_KEY_F7", CACA_KEY_F7, CONST_CS | CONST_PERSISTENT);
295        REGISTER_LONG_CONSTANT("CACA_KEY_F8", CACA_KEY_F8, CONST_CS | CONST_PERSISTENT);
296        REGISTER_LONG_CONSTANT("CACA_KEY_F9", CACA_KEY_F9, CONST_CS | CONST_PERSISTENT);
297        REGISTER_LONG_CONSTANT("CACA_KEY_F10", CACA_KEY_F10, CONST_CS | CONST_PERSISTENT);
298        REGISTER_LONG_CONSTANT("CACA_KEY_F11", CACA_KEY_F11, CONST_CS | CONST_PERSISTENT);
299        REGISTER_LONG_CONSTANT("CACA_KEY_F12", CACA_KEY_F12, CONST_CS | CONST_PERSISTENT);
300        REGISTER_LONG_CONSTANT("CACA_KEY_F13", CACA_KEY_F13, CONST_CS | CONST_PERSISTENT);
301        REGISTER_LONG_CONSTANT("CACA_KEY_F14", CACA_KEY_F14, CONST_CS | CONST_PERSISTENT);
302        REGISTER_LONG_CONSTANT("CACA_KEY_F15", CACA_KEY_F15, CONST_CS | CONST_PERSISTENT);
303
304        return SUCCESS;
305}
306
307//---------- Some usefull macros ---------------//
308
309#define FETCH_CANVAS(canvas) \
310        zval *_zval; \
311        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) { \
312                RETURN_FALSE; \
313        } \
314        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
315
316#define FETCH_DISPLAY(display) \
317        zval *_zval; \
318        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) { \
319                RETURN_FALSE; \
320        } \
321        ZEND_FETCH_RESOURCE(display, caca_display_t*, &_zval, -1, PHP_CACA_DISPLAY_RES_NAME, le_caca_display);
322
323#define FETCH_EVENT(event) \
324        zval *_zval; \
325        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) { \
326                RETURN_FALSE; \
327        } \
328        ZEND_FETCH_RESOURCE(event, caca_event_t*, &_zval, -1, PHP_CACA_EVENT_RES_NAME, le_caca_event);
329
330#define FETCH_LONG(l) \
331        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &l) == FAILURE) { \
332                RETURN_FALSE; \
333        }
334
335#define RETURN_CHAR(c) \
336        char *str = emalloc(2); \
337        str[0] = c; \
338        str[1] = '\0'; \
339        RETURN_STRING(str, 0);
340
341#define RETURN_SUCCESS(i) \
342        RETURN_BOOL((i) == 0);
343
344//------- PHP Binding's specific functions ----------//
345
346PHP_FUNCTION(caca_create_event) {
347        caca_event_t *event;
348        event = emalloc(sizeof(caca_event_t));
349        ZEND_REGISTER_RESOURCE(return_value, event, le_caca_event);
350}
351
352//------- Caca's functions ----------------//
353
354PHP_FUNCTION(caca_create_canvas) {
355        long width, height = 0;
356        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &width, &height) == FAILURE) {
357                RETURN_FALSE;
358        }
359        caca_canvas_t *canvas = caca_create_canvas(width, height);
360        if (!canvas) {
361                RETURN_FALSE;
362        }
363        ZEND_REGISTER_RESOURCE(return_value, canvas, le_caca_canvas);
364}
365
366PHP_FUNCTION(caca_manage_canvas) {
367}
368
369PHP_FUNCTION(caca_unmanage_canvas) {
370}
371
372PHP_FUNCTION(caca_set_canvas_size) {
373        zval *_zval;
374        long width, height = 0;
375        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &_zval, &width, &height) == FAILURE) {
376                RETURN_FALSE;
377        }
378        caca_canvas_t *canvas;
379        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
380        RETURN_SUCCESS(caca_set_canvas_size(canvas, width, height));
381}
382
383PHP_FUNCTION(caca_get_canvas_width) {
384        caca_canvas_t *canvas;
385        FETCH_CANVAS(canvas);
386        RETURN_LONG(caca_get_canvas_width(canvas));
387}
388
389PHP_FUNCTION(caca_get_canvas_height) {
390        caca_canvas_t *canvas;
391        FETCH_CANVAS(canvas);
392        RETURN_LONG(caca_get_canvas_height(canvas));
393}
394
395PHP_FUNCTION(caca_get_canvas_chars) {
396        caca_canvas_t *canvas;
397        FETCH_CANVAS(canvas);
398        RETURN_STRING((char *) caca_get_canvas_chars(canvas), 1); //TODO: check that return \0 terminated string
399}
400
401PHP_FUNCTION(caca_get_canvas_attrs) {
402        caca_canvas_t *canvas;
403        FETCH_CANVAS(canvas);
404        RETURN_STRING((char *) caca_get_canvas_attrs(canvas), 1); //TODO: check that return \0 terminated string
405}
406
407PHP_FUNCTION(caca_rand) {
408        long min, max = 0;
409        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &min, &max) == FAILURE) {
410                RETURN_FALSE;
411        }
412        RETURN_LONG(caca_rand(min, max));
413}
414
415PHP_FUNCTION(caca_get_version) {
416        RETURN_STRING((char *) caca_get_version(), 1);
417}
418
419PHP_FUNCTION(caca_gotoxy) {
420        zval *_zval;
421        long x, y = 0;
422        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &_zval, &x, &y) == FAILURE) {
423                RETURN_FALSE;
424        }
425        caca_canvas_t *canvas;
426        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
427        RETURN_SUCCESS(caca_gotoxy(canvas, x, y));
428}
429
430PHP_FUNCTION(caca_get_cursor_x) {
431        caca_canvas_t *canvas;
432        FETCH_CANVAS(canvas);
433        RETURN_LONG(caca_get_cursor_x(canvas));
434}
435
436PHP_FUNCTION(caca_get_cursor_y) {
437        caca_canvas_t *canvas;
438        FETCH_CANVAS(canvas);
439        RETURN_LONG(caca_get_cursor_y(canvas));
440}
441
442PHP_FUNCTION(caca_put_char) {
443        zval *_zval;
444        char *str;
445        long str_len, x, y = 0;
446        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlls", &_zval, &x, &y, &str, &str_len) == FAILURE) {
447                RETURN_FALSE;
448        }
449        caca_canvas_t *canvas;
450        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
451        if (str_len != 1) {
452                RETURN_FALSE;
453        }
454        RETURN_SUCCESS(caca_put_char(canvas, x, y, str[0]));
455}
456
457PHP_FUNCTION(caca_get_char) {
458        zval *_zval;
459        long x, y = 0;
460        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &_zval, &x, &y) == FAILURE) {
461                RETURN_FALSE;
462        }
463        caca_canvas_t *canvas;
464        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
465        RETURN_CHAR(caca_get_char(canvas, x, y));
466}
467
468PHP_FUNCTION(caca_put_str) {
469        zval *_zval;
470        char *str;
471        long x, y, str_len = 0;
472        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlls", &_zval, &x, &y, &str, &str_len) == FAILURE) {
473                RETURN_FALSE;
474        }
475        caca_canvas_t *canvas;
476        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
477        RETURN_SUCCESS(caca_put_str(canvas, x, y, str));
478}
479
480PHP_FUNCTION(caca_clear_canvas) {
481        caca_canvas_t *canvas;
482        FETCH_CANVAS(canvas);
483        RETURN_LONG(caca_clear_canvas(canvas));
484}
485
486PHP_FUNCTION(caca_set_canvas_handle) {
487        zval *_zval;
488        long x, y = 0;
489        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &_zval, &x, &y) == FAILURE) {
490                RETURN_FALSE;
491        }
492        caca_canvas_t *canvas;
493        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
494        RETURN_SUCCESS(caca_set_canvas_handle(canvas, x, y));
495}
496
497PHP_FUNCTION(caca_get_canvas_handle_x) {
498        caca_canvas_t *canvas;
499        FETCH_CANVAS(canvas);
500        RETURN_LONG(caca_get_canvas_handle_x(canvas));
501}
502
503PHP_FUNCTION(caca_get_canvas_handle_y) {
504        caca_canvas_t *canvas;
505        FETCH_CANVAS(canvas);
506        RETURN_LONG(caca_get_canvas_handle_y(canvas));
507}
508
509PHP_FUNCTION(caca_blit) {
510        zval *_zval1, *_zval2, *_zval3 = NULL;
511        long x, y = 0;
512        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllr|r", &_zval1, &x, &y, &_zval2, &_zval3) == FAILURE) {
513                RETURN_FALSE;
514        }
515        caca_canvas_t *dst, *src, *mask = NULL;
516        ZEND_FETCH_RESOURCE(dst, caca_canvas_t*, &_zval1, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
517        ZEND_FETCH_RESOURCE(src, caca_canvas_t*, &_zval2, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
518        if (_zval3) {
519                ZEND_FETCH_RESOURCE(mask, caca_canvas_t*, &_zval3, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
520        }
521        RETURN_SUCCESS(caca_blit(dst, x, y, src, NULL));
522}
523
524PHP_FUNCTION(caca_set_canvas_boundaries) {
525        zval *_zval;
526        long x, y, width, height = 0;
527        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllll", &_zval, &x, &y, &width, &height) == FAILURE) {
528                RETURN_FALSE;
529        }
530        caca_canvas_t *canvas;
531        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
532        RETURN_SUCCESS(caca_set_canvas_boundaries(canvas, x, y, width, height));
533}
534
535PHP_FUNCTION(caca_invert) {
536        caca_canvas_t *canvas;
537        FETCH_CANVAS(canvas);
538        RETURN_SUCCESS(caca_invert(canvas));
539}
540
541PHP_FUNCTION(caca_flip) {
542        caca_canvas_t *canvas;
543        FETCH_CANVAS(canvas);
544        RETURN_SUCCESS(caca_flip(canvas));
545}
546
547PHP_FUNCTION(caca_flop) {
548        caca_canvas_t *canvas;
549        FETCH_CANVAS(canvas);
550        RETURN_SUCCESS(caca_flop(canvas));
551}
552
553PHP_FUNCTION(caca_rotate_180) {
554        caca_canvas_t *canvas;
555        FETCH_CANVAS(canvas);
556        RETURN_SUCCESS(caca_rotate_180(canvas));
557}
558
559PHP_FUNCTION(caca_rotate_left) {
560        caca_canvas_t *canvas;
561        FETCH_CANVAS(canvas);
562        RETURN_SUCCESS(caca_rotate_left(canvas));
563}
564
565PHP_FUNCTION(caca_rotate_right) {
566        caca_canvas_t *canvas;
567        FETCH_CANVAS(canvas);
568        RETURN_SUCCESS(caca_rotate_right(canvas));
569}
570
571PHP_FUNCTION(caca_stretch_left) {
572        caca_canvas_t *canvas;
573        FETCH_CANVAS(canvas);
574        RETURN_SUCCESS(caca_stretch_left(canvas));
575}
576
577PHP_FUNCTION(caca_stretch_right) {
578        caca_canvas_t *canvas;
579        FETCH_CANVAS(canvas);
580        RETURN_SUCCESS(caca_stretch_right(canvas));
581}
582
583PHP_FUNCTION(caca_get_attr) {
584        zval *_zval;
585        long x, y = 0;
586        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &_zval, &x, &y) == FAILURE) {
587                RETURN_FALSE;
588        }
589        caca_canvas_t *canvas;
590        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
591        RETURN_LONG(caca_get_attr(canvas, x, y));
592}
593
594PHP_FUNCTION(caca_set_attr) {
595        zval *_zval;
596        long attr = 0;
597        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &_zval, &attr) == FAILURE) {
598                RETURN_FALSE;
599        }
600        caca_canvas_t *canvas;
601        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
602        RETURN_SUCCESS(caca_set_attr(canvas, attr));
603}
604
605PHP_FUNCTION(caca_put_attr) {
606        zval *_zval;
607        long x, y, attr = 0;
608        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlll", &_zval, &x, &y, &attr) == FAILURE) {
609                RETURN_FALSE;
610        }
611        caca_canvas_t *canvas;
612        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
613        RETURN_SUCCESS(caca_put_attr(canvas, x, y, attr));
614}
615
616PHP_FUNCTION(caca_set_color_ansi) {
617        zval *_zval;
618        long foreground, background = 0;
619        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &_zval, &foreground, &background) == FAILURE) {
620                RETURN_FALSE;
621        }
622        caca_canvas_t *canvas;
623        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
624        RETURN_SUCCESS(caca_set_color_ansi(canvas, foreground, background));
625}
626
627PHP_FUNCTION(caca_set_color_argb) {
628        zval *_zval;
629        long foreground, background = 0;
630        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &_zval, &foreground, &background) == FAILURE) {
631                RETURN_FALSE;
632        }
633        caca_canvas_t *canvas;
634        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
635        RETURN_SUCCESS(caca_set_color_argb(canvas, foreground, background));
636}
637
638PHP_FUNCTION(caca_attr_to_ansi) {
639        long l;
640        FETCH_LONG(l);
641        RETURN_LONG(caca_attr_to_ansi(l));
642}
643
644PHP_FUNCTION(caca_attr_to_ansi_fg) {
645        long l;
646        FETCH_LONG(l);
647        RETURN_LONG(caca_attr_to_ansi_fg(l));
648}
649
650PHP_FUNCTION(caca_attr_to_ansi_bg) {
651        long l;
652        FETCH_LONG(l);
653        RETURN_LONG(caca_attr_to_ansi_bg(l));
654}
655
656PHP_FUNCTION(caca_attr_to_rgb12_fg) {
657        long l;
658        FETCH_LONG(l);
659        RETURN_LONG(caca_attr_to_rgb12_fg(l));
660}
661
662PHP_FUNCTION(caca_attr_to_rgb12_bg) {
663        long l;
664        FETCH_LONG(l);
665        RETURN_LONG(caca_attr_to_rgb12_bg(l));
666}
667
668PHP_FUNCTION(caca_attr_to_argb64) {
669}
670
671PHP_FUNCTION(caca_utf8_to_utf32) {
672}
673
674PHP_FUNCTION(caca_utf32_to_utf8) {
675}
676
677PHP_FUNCTION(caca_utf32_to_cp437) {
678}
679
680PHP_FUNCTION(caca_cp437_to_utf32) {
681}
682
683PHP_FUNCTION(caca_utf32_to_ascii) {
684}
685
686PHP_FUNCTION(caca_utf32_is_fullwidth) {
687}
688
689PHP_FUNCTION(caca_draw_line) {
690        zval *_zval;
691        char *str;
692        long str_len, xa, ya, xb, yb = 0;
693        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlllls", &_zval, &xa, &ya, &xb, &yb, &str, &str_len) == FAILURE) {
694                RETURN_FALSE;
695        }
696        caca_canvas_t *canvas;
697        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
698        if (str_len != 1) {
699                RETURN_FALSE;
700        }
701        RETURN_SUCCESS(caca_draw_line(canvas, xa, ya, xb, yb, str[0]));
702}
703
704PHP_FUNCTION(caca_draw_polyline) {
705}
706
707PHP_FUNCTION(caca_draw_thin_line) {
708        zval *_zval;
709        long xa, ya, xb, yb = 0;
710        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllll", &_zval, &xa, &ya, &xb, &yb) == FAILURE) {
711                RETURN_FALSE;
712        }
713        caca_canvas_t *canvas;
714        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
715        RETURN_SUCCESS(caca_draw_thin_line(canvas, xa, ya, xb, yb));
716}
717
718PHP_FUNCTION(caca_draw_thin_polyline) {
719}
720
721PHP_FUNCTION(caca_draw_circle) {
722        zval *_zval;
723        char *str;
724        long str_len, x, y, r = 0;
725        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllls", &_zval, &x, &y, &r, &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_SUCCESS(caca_draw_circle(canvas, x, y, r, str[0]));
734}
735
736PHP_FUNCTION(caca_draw_ellipse) {
737        zval *_zval;
738        char *str;
739        long str_len, xa, ya, xb, yb = 0;
740        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlllls", &_zval, &xa, &ya, &xb, &yb, &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_SUCCESS(caca_draw_ellipse(canvas, xa, ya, xb, yb, str[0]));
749}
750
751PHP_FUNCTION(caca_draw_thin_ellipse) {
752        zval *_zval;
753        long xa, ya, xb, yb = 0;
754        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllll", &_zval, &xa, &ya, &xb, &yb) == 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_SUCCESS(caca_draw_thin_ellipse(canvas, xa, ya, xb, yb));
760}
761
762PHP_FUNCTION(caca_fill_ellipse) {
763        zval *_zval;
764        char *str;
765        long str_len, xa, ya, xb, yb = 0;
766        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlllls", &_zval, &xa, &ya, &xb, &yb, &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_SUCCESS(caca_fill_ellipse(canvas, xa, ya, xb, yb, str[0]));
775}
776
777PHP_FUNCTION(caca_draw_box) {
778        zval *_zval;
779        char *str;
780        long str_len, xa, ya, xb, yb = 0;
781        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlllls", &_zval, &xa, &ya, &xb, &yb, &str, &str_len) == FAILURE) {
782                RETURN_FALSE;
783        }
784        caca_canvas_t *canvas;
785        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
786        if (str_len != 1) {
787                RETURN_FALSE;
788        }
789        RETURN_SUCCESS(caca_draw_box(canvas, xa, ya, xb, yb, str[0]));
790}
791
792PHP_FUNCTION(caca_draw_thin_box) {
793        zval *_zval;
794        long xa, ya, xb, yb = 0;
795        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllll", &_zval, &xa, &ya, &xb, &yb) == FAILURE) {
796                RETURN_FALSE;
797        }
798        caca_canvas_t *canvas;
799        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
800        RETURN_SUCCESS(caca_draw_thin_box(canvas, xa, ya, xb, yb));
801}
802
803PHP_FUNCTION(caca_draw_cp437_box) {
804        zval *_zval;
805        long xa, ya, xb, yb = 0;
806        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllll", &_zval, &xa, &ya, &xb, &yb) == FAILURE) {
807                RETURN_FALSE;
808        }
809        caca_canvas_t *canvas;
810        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
811        RETURN_SUCCESS(caca_draw_cp437_box(canvas, xa, ya, xb, yb));
812}
813
814PHP_FUNCTION(caca_fill_box) {
815        zval *_zval;
816        char *str;
817        long str_len, xa, ya, xb, yb = 0;
818        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlllls", &_zval, &xa, &ya, &xb, &yb, &str, &str_len) == FAILURE) {
819                RETURN_FALSE;
820        }
821        caca_canvas_t *canvas;
822        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
823        if (str_len != 1) {
824                RETURN_FALSE;
825        }
826        RETURN_SUCCESS(caca_fill_box(canvas, xa, ya, xb, yb, str[0]));
827}
828
829PHP_FUNCTION(caca_draw_triangle) {
830        zval *_zval;
831        char *str;
832        long str_len, xa, ya, xb, yb, xc, yc = 0;
833        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlllllls", &_zval, &xa, &ya, &xb, &yb, &xc, &yc, &str, &str_len) == FAILURE) {
834                RETURN_FALSE;
835        }
836        caca_canvas_t *canvas;
837        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
838        if (str_len != 1) {
839                RETURN_FALSE;
840        }
841        RETURN_SUCCESS(caca_draw_triangle(canvas, xa, ya, xb, yb, xc, yc, str[0]));
842}
843
844PHP_FUNCTION(caca_draw_thin_triangle) {
845        zval *_zval;
846        long xa, ya, xb, yb, xc, yc = 0;
847        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllllll", &_zval, &xa, &ya, &xb, &yb, &xc, &yc) == FAILURE) {
848                RETURN_FALSE;
849        }
850        caca_canvas_t *canvas;
851        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
852        RETURN_SUCCESS(caca_draw_thin_triangle(canvas, xa, ya, xb, yb, xc, yc));
853}
854
855PHP_FUNCTION(caca_fill_triangle) {
856        zval *_zval;
857        char *str;
858        long str_len, xa, ya, xb, yb, xc, yc = 0;
859        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlllllls", &_zval, &xa, &ya, &xb, &yb, &xc, &yc, &str, &str_len) == FAILURE) {
860                RETURN_FALSE;
861        }
862        caca_canvas_t *canvas;
863        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
864        if (str_len != 1) {
865                RETURN_FALSE;
866        }
867        RETURN_SUCCESS(caca_fill_triangle(canvas, xa, ya, xb, yb, xc, yc, str[0]));
868}
869
870PHP_FUNCTION(caca_get_frame_count) {
871        zval *_zval;
872        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) {
873                RETURN_FALSE;
874        }
875        caca_canvas_t *canvas;
876        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
877        RETURN_LONG(caca_get_canvas_count(canvas));
878}
879
880PHP_FUNCTION(caca_set_frame) {
881        zval *_zval;
882        long id;
883        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &_zval, &id) == FAILURE) {
884                RETURN_FALSE;
885        }
886        caca_canvas_t *canvas;
887        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
888        RETURN_SUCCESS(caca_set_frame(canvas, id));
889}
890
891PHP_FUNCTION(caca_set_frame_name) {
892        zval *_zval;
893        char *str;
894        long str_len;
895        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &_zval, &str, &str_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        RETURN_SUCCESS(caca_set_frame_name(canvas, str));
901}
902
903PHP_FUNCTION(caca_create_frame) {
904        zval *_zval;
905        long id;
906        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &_zval, &id) == FAILURE) {
907                RETURN_FALSE;
908        }
909        caca_canvas_t *canvas;
910        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
911        RETURN_SUCCESS(caca_create_frame(canvas, id));
912}
913
914PHP_FUNCTION(caca_free_frame) {
915        zval *_zval;
916        long id;
917        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &_zval, &id) == FAILURE) {
918                RETURN_FALSE;
919        }
920        caca_canvas_t *canvas;
921        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
922        RETURN_SUCCESS(caca_free_frame(canvas, id));
923}
924
925PHP_FUNCTION(caca_set_dither_palette) {
926}
927
928PHP_FUNCTION(caca_set_dither_brightness) {
929}
930
931PHP_FUNCTION(caca_get_dither_brightness) {
932}
933
934PHP_FUNCTION(caca_set_dither_gamma) {
935}
936
937PHP_FUNCTION(caca_get_dither_gamma) {
938}
939
940PHP_FUNCTION(caca_set_dither_contrast) {
941}
942
943PHP_FUNCTION(caca_get_dither_contrast) {
944}
945
946PHP_FUNCTION(caca_set_dither_antialias) {
947}
948
949PHP_FUNCTION(caca_get_dither_antialias_list) {
950}
951
952PHP_FUNCTION(caca_get_dither_antialias) {
953}
954
955PHP_FUNCTION(caca_set_dither_color) {
956}
957
958PHP_FUNCTION(caca_get_dither_color_list) {
959}
960
961PHP_FUNCTION(caca_get_dither_color) {
962}
963
964PHP_FUNCTION(caca_set_dither_charset) {
965}
966
967PHP_FUNCTION(caca_get_dither_charset_list) {
968}
969
970PHP_FUNCTION(caca_get_dither_charset) {
971}
972
973PHP_FUNCTION(caca_set_dither_algorithm) {
974}
975
976PHP_FUNCTION(caca_get_dither_algorithm_list) {
977}
978
979PHP_FUNCTION(caca_get_dither_algorithm) {
980}
981
982PHP_FUNCTION(caca_dither_bitmap) {
983}
984
985PHP_FUNCTION(caca_get_font_list) {
986}
987
988PHP_FUNCTION(caca_get_font_width) {
989}
990
991PHP_FUNCTION(caca_get_font_height) {
992}
993
994PHP_FUNCTION(caca_render_canvas) {
995}
996
997PHP_FUNCTION(caca_canvas_set_figfont) {
998}
999
1000PHP_FUNCTION(caca_put_figchar) {
1001}
1002
1003PHP_FUNCTION(caca_flush_figlet) {
1004}
1005
1006PHP_FUNCTION(caca_file_close) {
1007}
1008
1009PHP_FUNCTION(caca_file_tell) {
1010}
1011
1012PHP_FUNCTION(caca_file_read) {
1013}
1014
1015PHP_FUNCTION(caca_file_write) {
1016}
1017
1018PHP_FUNCTION(caca_file_gets) {
1019}
1020
1021PHP_FUNCTION(caca_file_eof) {
1022}
1023
1024PHP_FUNCTION(caca_import_string) {
1025        zval *_zval;
1026        char *src, *type;
1027        long src_len, type_len = 0;
1028        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss", &_zval, &src, &src_len, &type, &type_len) == FAILURE) {
1029                RETURN_FALSE;
1030        }
1031        caca_canvas_t *canvas;
1032        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
1033
1034        RETURN_LONG(caca_import_memory(canvas, src, src_len, type));
1035}
1036
1037PHP_FUNCTION(caca_import_file) {
1038}
1039
1040PHP_FUNCTION(caca_get_import_list) {
1041}
1042
1043PHP_FUNCTION(caca_export_string) {
1044        zval *_zval;
1045        char *type;
1046        long type_len;
1047        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &_zval, &type, &type_len) == FAILURE) {
1048                RETURN_FALSE;
1049        }
1050        caca_canvas_t *canvas;
1051        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
1052
1053        void *buffer;
1054        size_t len;
1055        buffer = caca_export_memory(canvas, type, &len);
1056        return_value->type = IS_STRING;
1057        return_value->value.str.len = len;
1058        return_value->value.str.val = emalloc(len);
1059        memcpy(return_value->value.str.val, buffer, len);
1060        free(buffer);
1061}
1062
1063PHP_FUNCTION(caca_get_export_list) {
1064}
1065
1066PHP_FUNCTION(caca_create_display) {
1067        caca_canvas_t *canvas;
1068        FETCH_CANVAS(canvas);
1069
1070        caca_display_t *display = caca_create_display(canvas);
1071        ZEND_REGISTER_RESOURCE(return_value, display, le_caca_display);
1072}
1073
1074PHP_FUNCTION(caca_create_display_with_driver) {
1075        zval *_zval;
1076        char *str;
1077        long str_len = 0;
1078        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &_zval, &str, &str_len) == FAILURE) {
1079                RETURN_FALSE;
1080        }
1081        caca_canvas_t *canvas;
1082        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
1083
1084        caca_display_t *display = caca_create_display_with_driver(canvas, str);
1085        if (!display) {
1086                RETURN_FALSE;
1087        }
1088        ZEND_REGISTER_RESOURCE(return_value, display, le_caca_display);
1089}
1090
1091PHP_FUNCTION(caca_get_display_driver_list) {
1092        char const * const *list = caca_get_display_driver_list();
1093        int i;
1094        array_init(return_value);       
1095        for(i = 0; list[i]; i += 2)
1096                add_assoc_string(return_value, (char*) list[i], (char*) list[i + 1], 1);
1097}
1098
1099PHP_FUNCTION(caca_get_display_driver) {
1100        zval *_zval;
1101        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) {
1102                RETURN_FALSE;
1103        }
1104        caca_display_t *display;
1105        ZEND_FETCH_RESOURCE(display, caca_display_t*, &_zval, -1, PHP_CACA_DISPLAY_RES_NAME, le_caca_display);
1106        RETURN_STRING((char *) caca_get_display_driver(display), 1);
1107}
1108
1109PHP_FUNCTION(caca_set_display_driver) {
1110        zval *_zval;
1111        char *str;
1112        long str_len;
1113        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &_zval, &str, &str_len) == FAILURE) {
1114                RETURN_FALSE;
1115        }
1116        caca_display_t *display;
1117        ZEND_FETCH_RESOURCE(display, caca_display_t*, &_zval, -1, PHP_CACA_DISPLAY_RES_NAME, le_caca_display);
1118        RETURN_SUCESS(caca_set_display_driver(display, str));
1119}
1120
1121PHP_FUNCTION(caca_get_canvas) {
1122        zval *_zval;
1123        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) {
1124                RETURN_FALSE;
1125        }
1126        caca_display_t *display;
1127        ZEND_FETCH_RESOURCE(display, caca_display_t*, &_zval, -1, PHP_CACA_DISPLAY_RES_NAME, le_caca_display);
1128        caca_canvas_t *canvas = caca_get_canvas(display);
1129        ZEND_REGISTER_RESOURCE(return_value, canvas, le_caca_canvas);
1130}
1131
1132PHP_FUNCTION(caca_refresh_display) {
1133        caca_display_t *display;
1134        FETCH_DISPLAY(display);
1135        RETURN_SUCCESS(caca_refresh_display(display));
1136}
1137
1138PHP_FUNCTION(caca_set_display_time) {
1139        zval *_zval;
1140        long value = 0;
1141        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &_zval, &value) == FAILURE) {
1142                RETURN_FALSE;
1143        }
1144        caca_display_t *display;
1145        ZEND_FETCH_RESOURCE(display, caca_display_t*, &_zval, -1, PHP_CACA_DISPLAY_RES_NAME, le_caca_display);
1146        RETURN_SUCCESS(caca_set_display_time(display, value));
1147}
1148
1149PHP_FUNCTION(caca_get_display_time) {
1150        caca_display_t *display;
1151        FETCH_DISPLAY(display);
1152        RETURN_LONG(caca_get_display_time(display)); //TODO: check return value
1153}
1154
1155PHP_FUNCTION(caca_get_display_width) {
1156        caca_display_t *display;
1157        FETCH_DISPLAY(display);
1158        RETURN_LONG(caca_get_display_width(display));
1159}
1160
1161PHP_FUNCTION(caca_get_display_height) {
1162        caca_display_t *display;
1163        FETCH_DISPLAY(display);
1164        RETURN_LONG(caca_get_display_height(display));
1165}
1166
1167PHP_FUNCTION(caca_set_display_title) {
1168        zval *_zval;
1169        char *str;
1170        long str_len = 0;
1171        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &_zval, &str, &str_len) == FAILURE) {
1172                RETURN_FALSE;
1173        }
1174        caca_display_t *display;
1175        ZEND_FETCH_RESOURCE(display, caca_display_t*, &_zval, -1, PHP_CACA_DISPLAY_RES_NAME, le_caca_display);
1176        RETURN_SUCCESS(caca_set_display(display, str));
1177}
1178
1179PHP_FUNCTION(caca_set_mouse) {
1180        zval *_zval;
1181        long value = 0;
1182        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &_zval, &value) == FAILURE) {
1183                RETURN_FALSE;
1184        }
1185        caca_display_t *display;
1186        ZEND_FETCH_RESOURCE(display, caca_display_t*, &_zval, -1, PHP_CACA_DISPLAY_RES_NAME, le_caca_display);
1187        RETURN_SUCCESS(caca_set_mouse(display, value));
1188}
1189
1190PHP_FUNCTION(caca_set_cursor) {
1191        zval *_zval;
1192        long value = 0;
1193        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &_zval, &value) == FAILURE) {
1194                RETURN_FALSE;
1195        }
1196        caca_display_t *display;
1197        ZEND_FETCH_RESOURCE(display, caca_display_t*, &_zval, -1, PHP_CACA_DISPLAY_RES_NAME, le_caca_display);
1198        RETURN_SUCCESS(caca_set_cursor(display, value));
1199}
1200
1201PHP_FUNCTION(caca_get_event) {
1202        zval *_zval1, *_zval2 = NULL;
1203        long g, aa = 0;
1204        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl|rl", &_zval1, &g, &_zval2, &aa) == FAILURE) {
1205                RETURN_FALSE;
1206        }
1207        caca_display_t *display;
1208        ZEND_FETCH_RESOURCE(display, caca_display_t*, &_zval1, -1, PHP_CACA_DISPLAY_RES_NAME, le_caca_display);
1209
1210        caca_event_t *event = NULL;
1211        if (_zval2) {
1212                ZEND_FETCH_RESOURCE(event, caca_event_t*, &_zval2, -1, PHP_CACA_EVENT_RES_NAME, le_caca_event);
1213        }
1214        RETURN_LONG(caca_get_event(display, g, event, aa));
1215}
1216
1217PHP_FUNCTION(caca_get_mouse_x) {
1218        caca_display_t *display;
1219        FETCH_DISPLAY(display);
1220        RETURN_LONG(caca_get_mouse_x(display));
1221}
1222
1223PHP_FUNCTION(caca_get_mouse_y) {
1224        caca_display_t *display;
1225        FETCH_DISPLAY(display);
1226        RETURN_LONG(caca_get_mouse_y(display));
1227}
1228
1229PHP_FUNCTION(caca_get_event_type) {
1230        caca_event_t *event;
1231        FETCH_EVENT(event);
1232        RETURN_LONG(caca_get_event_type(event));
1233}
1234
1235PHP_FUNCTION(caca_get_event_key_ch) {
1236        caca_event_t *event;
1237        FETCH_EVENT(event);
1238        RETURN_LONG(caca_get_event_key_ch(event));
1239}
1240
1241PHP_FUNCTION(caca_get_event_mouse_button) {
1242        caca_event_t *event;
1243        FETCH_EVENT(event);
1244        RETURN_LONG(caca_get_event_mouse_button(event));
1245}
1246
1247PHP_FUNCTION(caca_get_event_mouse_x) {
1248        caca_event_t *event;
1249        FETCH_EVENT(event);
1250        RETURN_LONG(caca_get_event_mouse_x(event));
1251}
1252
1253PHP_FUNCTION(caca_get_event_mouse_y) {
1254        caca_event_t *event;
1255        FETCH_EVENT(event);
1256        RETURN_LONG(caca_get_event_mouse_y(event));
1257}
1258
1259PHP_FUNCTION(caca_get_event_resize_width) {
1260        caca_event_t *event;
1261        FETCH_EVENT(event);
1262        RETURN_LONG(caca_get_event_resize_width(event));
1263}
1264
1265PHP_FUNCTION(caca_get_event_resize_height) {
1266        caca_event_t *event;
1267        FETCH_EVENT(event);
1268        RETURN_LONG(caca_get_event_resize_height(event));
1269}
1270
Note: See TracBrowser for help on using the repository browser.