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

Last change on this file since 3112 was 3112, checked in by nico, 12 years ago
  • Improve function caca_export_string
File size: 36.2 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 RETURN_CHAR(c) \
331        char *str = emalloc(2); \
332        str[0] = c; \
333        str[1] = '\0'; \
334        RETURN_STRING(str, 0);
335
336#define RETURN_SUCCESS(i) \
337        RETURN_BOOL((i) == 0);
338
339//------- PHP Binding's specific functions ----------//
340
341PHP_FUNCTION(caca_create_event) {
342        caca_event_t *event;
343        event = emalloc(sizeof(caca_event_t));
344        ZEND_REGISTER_RESOURCE(return_value, event, le_caca_event);
345}
346
347//------- Caca's functions ----------------//
348
349PHP_FUNCTION(caca_create_canvas) {
350        long width, height = 0;
351        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &width, &height) == FAILURE) {
352                RETURN_FALSE;
353        }
354        caca_canvas_t *canvas = caca_create_canvas(width, height);
355        if (!canvas) {
356                RETURN_FALSE;
357        }
358        ZEND_REGISTER_RESOURCE(return_value, canvas, le_caca_canvas);
359}
360
361PHP_FUNCTION(caca_manage_canvas) {
362}
363
364PHP_FUNCTION(caca_unmanage_canvas) {
365}
366
367PHP_FUNCTION(caca_set_canvas_size) {
368        zval *_zval;
369        long width, height = 0;
370        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &_zval, &width, &height) == FAILURE) {
371                RETURN_FALSE;
372        }
373        caca_canvas_t *canvas;
374        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
375        RETURN_SUCCESS(caca_set_canvas_size(canvas, width, height));
376}
377
378PHP_FUNCTION(caca_get_canvas_width) {
379        caca_canvas_t *canvas;
380        FETCH_CANVAS(canvas);
381        RETURN_LONG(caca_get_canvas_width(canvas));
382}
383
384PHP_FUNCTION(caca_get_canvas_height) {
385        caca_canvas_t *canvas;
386        FETCH_CANVAS(canvas);
387        RETURN_LONG(caca_get_canvas_height(canvas));
388}
389
390PHP_FUNCTION(caca_get_canvas_chars) {
391        caca_canvas_t *canvas;
392        FETCH_CANVAS(canvas);
393        RETURN_STRING(estrdup(caca_get_canvas_chars(canvas)), 0); //TODO: check that return \0 terminated string
394}
395
396PHP_FUNCTION(caca_get_canvas_attrs) {
397        caca_canvas_t *canvas;
398        FETCH_CANVAS(canvas);
399        RETURN_STRING(estrdup(caca_get_canvas_attrs(canvas)), 0); //TODO: check that return \0 terminated string
400}
401
402PHP_FUNCTION(caca_rand) {
403        long min, max = 0;
404        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &min, &max) == FAILURE) {
405                RETURN_FALSE;
406        }
407        RETURN_LONG(caca_rand(min, max));
408}
409
410PHP_FUNCTION(caca_get_version) {
411        RETURN_STRING(estrdup(caca_get_version()), 0);
412}
413
414PHP_FUNCTION(caca_gotoxy) {
415        zval *_zval;
416        long x, y = 0;
417        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &_zval, &x, &y) == FAILURE) {
418                RETURN_FALSE;
419        }
420        caca_canvas_t *canvas;
421        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
422        RETURN_SUCCESS(caca_gotoxy(canvas, x, y));
423}
424
425PHP_FUNCTION(caca_get_cursor_x) {
426        caca_canvas_t *canvas;
427        FETCH_CANVAS(canvas);
428        RETURN_LONG(caca_get_cursor_x(canvas));
429}
430
431PHP_FUNCTION(caca_get_cursor_y) {
432        caca_canvas_t *canvas;
433        FETCH_CANVAS(canvas);
434        RETURN_LONG(caca_get_cursor_y(canvas));
435}
436
437PHP_FUNCTION(caca_put_char) {
438        zval *_zval;
439        char *str;
440        long str_len, x, y = 0;
441        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlls", &_zval, &x, &y, &str, &str_len) == 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        if (str_len != 1) {
447                RETURN_FALSE;
448        }
449        RETURN_SUCCESS(caca_put_char(canvas, x, y, str[0]));
450}
451
452PHP_FUNCTION(caca_get_char) {
453        zval *_zval;
454        long x, y = 0;
455        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &_zval, &x, &y) == FAILURE) {
456                RETURN_FALSE;
457        }
458        caca_canvas_t *canvas;
459        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
460        RETURN_CHAR(caca_get_char(canvas, x, y));
461}
462
463PHP_FUNCTION(caca_put_str) {
464        zval *_zval;
465        char *str;
466        long x, y, str_len = 0;
467        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlls", &_zval, &x, &y, &str, &str_len) == FAILURE) {
468                RETURN_FALSE;
469        }
470        caca_canvas_t *canvas;
471        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
472        RETURN_SUCCESS(caca_put_str(canvas, x, y, str));
473}
474
475PHP_FUNCTION(caca_clear_canvas) {
476        caca_canvas_t *canvas;
477        FETCH_CANVAS(canvas);
478        RETURN_LONG(caca_clear_canvas(canvas));
479}
480
481PHP_FUNCTION(caca_set_canvas_handle) {
482        zval *_zval;
483        long x, y = 0;
484        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &_zval, &x, &y) == FAILURE) {
485                RETURN_FALSE;
486        }
487        caca_canvas_t *canvas;
488        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
489        RETURN_SUCCESS(caca_set_canvas_handle(canvas, x, y));
490}
491
492PHP_FUNCTION(caca_get_canvas_handle_x) {
493        caca_canvas_t *canvas;
494        FETCH_CANVAS(canvas);
495        RETURN_LONG(caca_get_canvas_handle_x(canvas));
496}
497
498PHP_FUNCTION(caca_get_canvas_handle_y) {
499        caca_canvas_t *canvas;
500        FETCH_CANVAS(canvas);
501        RETURN_LONG(caca_get_canvas_handle_y(canvas));
502}
503
504PHP_FUNCTION(caca_blit) {
505        zval *_zval1, *_zval2, *_zval3 = NULL;
506        long x, y = 0;
507        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllr|r", &_zval1, &x, &y, &_zval2, &_zval3) == FAILURE) {
508                RETURN_FALSE;
509        }
510        caca_canvas_t *dst, *src, *mask = NULL;
511        ZEND_FETCH_RESOURCE(dst, caca_canvas_t*, &_zval1, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
512        ZEND_FETCH_RESOURCE(src, caca_canvas_t*, &_zval2, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
513        if (_zval3) {
514                ZEND_FETCH_RESOURCE(mask, caca_canvas_t*, &_zval3, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
515        }
516        RETURN_SUCCESS(caca_blit(dst, x, y, src, NULL));
517}
518
519PHP_FUNCTION(caca_set_canvas_boundaries) {
520        zval *_zval;
521        long x, y, width, height = 0;
522        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllll", &_zval, &x, &y, &width, &height) == FAILURE) {
523                RETURN_FALSE;
524        }
525        caca_canvas_t *canvas;
526        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
527        RETURN_SUCCESS(caca_set_canvas_boundaries(canvas, x, y, width, height));
528}
529
530PHP_FUNCTION(caca_invert) {
531        caca_canvas_t *canvas;
532        FETCH_CANVAS(canvas);
533        RETURN_SUCCESS(caca_invert(canvas));
534}
535
536PHP_FUNCTION(caca_flip) {
537        caca_canvas_t *canvas;
538        FETCH_CANVAS(canvas);
539        RETURN_SUCCESS(caca_flip(canvas));
540}
541
542PHP_FUNCTION(caca_flop) {
543        caca_canvas_t *canvas;
544        FETCH_CANVAS(canvas);
545        RETURN_SUCCESS(caca_flop(canvas));
546}
547
548PHP_FUNCTION(caca_rotate_180) {
549        caca_canvas_t *canvas;
550        FETCH_CANVAS(canvas);
551        RETURN_SUCCESS(caca_rotate_180(canvas));
552}
553
554PHP_FUNCTION(caca_rotate_left) {
555        caca_canvas_t *canvas;
556        FETCH_CANVAS(canvas);
557        RETURN_SUCCESS(caca_rotate_left(canvas));
558}
559
560PHP_FUNCTION(caca_rotate_right) {
561        caca_canvas_t *canvas;
562        FETCH_CANVAS(canvas);
563        RETURN_SUCCESS(caca_rotate_right(canvas));
564}
565
566PHP_FUNCTION(caca_stretch_left) {
567        caca_canvas_t *canvas;
568        FETCH_CANVAS(canvas);
569        RETURN_SUCCESS(caca_stretch_left(canvas));
570}
571
572PHP_FUNCTION(caca_stretch_right) {
573        caca_canvas_t *canvas;
574        FETCH_CANVAS(canvas);
575        RETURN_SUCCESS(caca_stretch_right(canvas));
576}
577
578PHP_FUNCTION(caca_get_attr) {
579        zval *_zval;
580        long x, y = 0;
581        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &_zval, &x, &y) == FAILURE) {
582                RETURN_FALSE;
583        }
584        caca_canvas_t *canvas;
585        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
586        RETURN_LONG(caca_get_attr(canvas, x, y));
587}
588
589PHP_FUNCTION(caca_set_attr) {
590        zval *_zval;
591        long attr = 0;
592        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &_zval, &attr) == FAILURE) {
593                RETURN_FALSE;
594        }
595        caca_canvas_t *canvas;
596        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
597        RETURN_SUCCESS(caca_set_attr(canvas, attr));
598}
599
600PHP_FUNCTION(caca_put_attr) {
601        zval *_zval;
602        long x, y, attr = 0;
603        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlll", &_zval, &x, &y, &attr) == FAILURE) {
604                RETURN_FALSE;
605        }
606        caca_canvas_t *canvas;
607        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
608        RETURN_SUCCESS(caca_put_attr(canvas, x, y, attr));
609}
610
611PHP_FUNCTION(caca_set_color_ansi) {
612        zval *_zval;
613        long foreground, background = 0;
614        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &_zval, &foreground, &background) == FAILURE) {
615                RETURN_FALSE;
616        }
617        caca_canvas_t *canvas;
618        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
619        RETURN_SUCCESS(caca_set_color_ansi(canvas, foreground, background));
620}
621
622PHP_FUNCTION(caca_set_color_argb) {
623}
624
625PHP_FUNCTION(caca_attr_to_ansi) {
626}
627
628PHP_FUNCTION(caca_attr_to_ansi_fg) {
629}
630
631PHP_FUNCTION(caca_attr_to_ansi_bg) {
632}
633
634PHP_FUNCTION(caca_attr_to_rgb12_fg) {
635}
636
637PHP_FUNCTION(caca_attr_to_rgb12_bg) {
638}
639
640PHP_FUNCTION(caca_attr_to_argb64) {
641}
642
643PHP_FUNCTION(caca_utf8_to_utf32) {
644}
645
646PHP_FUNCTION(caca_utf32_to_utf8) {
647}
648
649PHP_FUNCTION(caca_utf32_to_cp437) {
650}
651
652PHP_FUNCTION(caca_cp437_to_utf32) {
653}
654
655PHP_FUNCTION(caca_utf32_to_ascii) {
656}
657
658PHP_FUNCTION(caca_utf32_is_fullwidth) {
659}
660
661PHP_FUNCTION(caca_draw_line) {
662        zval *_zval;
663        char *str;
664        long str_len, xa, ya, xb, yb = 0;
665        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlllls", &_zval, &xa, &ya, &xb, &yb, &str, &str_len) == FAILURE) {
666                RETURN_FALSE;
667        }
668        caca_canvas_t *canvas;
669        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
670        if (str_len != 1) {
671                RETURN_FALSE;
672        }
673        RETURN_SUCCESS(caca_draw_line(canvas, xa, ya, xb, yb, str[0]));
674}
675
676PHP_FUNCTION(caca_draw_polyline) {
677}
678
679PHP_FUNCTION(caca_draw_thin_line) {
680        zval *_zval;
681        long xa, ya, xb, yb = 0;
682        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllll", &_zval, &xa, &ya, &xb, &yb) == FAILURE) {
683                RETURN_FALSE;
684        }
685        caca_canvas_t *canvas;
686        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
687        RETURN_SUCCESS(caca_draw_thin_line(canvas, xa, ya, xb, yb));
688}
689
690PHP_FUNCTION(caca_draw_thin_polyline) {
691}
692
693PHP_FUNCTION(caca_draw_circle) {
694        zval *_zval;
695        char *str;
696        long str_len, x, y, r = 0;
697        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllls", &_zval, &x, &y, &r, &str, &str_len) == FAILURE) {
698                RETURN_FALSE;
699        }
700        caca_canvas_t *canvas;
701        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
702        if (str_len != 1) {
703                RETURN_FALSE;
704        }
705        RETURN_SUCCESS(caca_draw_circle(canvas, x, y, r, str[0]));
706}
707
708PHP_FUNCTION(caca_draw_ellipse) {
709        zval *_zval;
710        char *str;
711        long str_len, xa, ya, xb, yb = 0;
712        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlllls", &_zval, &xa, &ya, &xb, &yb, &str, &str_len) == FAILURE) {
713                RETURN_FALSE;
714        }
715        caca_canvas_t *canvas;
716        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
717        if (str_len != 1) {
718                RETURN_FALSE;
719        }
720        RETURN_SUCCESS(caca_draw_ellipse(canvas, xa, ya, xb, yb, str[0]));
721}
722
723PHP_FUNCTION(caca_draw_thin_ellipse) {
724        zval *_zval;
725        long xa, ya, xb, yb = 0;
726        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllll", &_zval, &xa, &ya, &xb, &yb) == FAILURE) {
727                RETURN_FALSE;
728        }
729        caca_canvas_t *canvas;
730        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
731        RETURN_SUCCESS(caca_draw_thin_ellipse(canvas, xa, ya, xb, yb));
732}
733
734PHP_FUNCTION(caca_fill_ellipse) {
735        zval *_zval;
736        char *str;
737        long str_len, xa, ya, xb, yb = 0;
738        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlllls", &_zval, &xa, &ya, &xb, &yb, &str, &str_len) == FAILURE) {
739                RETURN_FALSE;
740        }
741        caca_canvas_t *canvas;
742        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
743        if (str_len != 1) {
744                RETURN_FALSE;
745        }
746        RETURN_SUCCESS(caca_fill_ellipse(canvas, xa, ya, xb, yb, str[0]));
747}
748
749PHP_FUNCTION(caca_draw_box) {
750        zval *_zval;
751        char *str;
752        long str_len, xa, ya, xb, yb = 0;
753        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlllls", &_zval, &xa, &ya, &xb, &yb, &str, &str_len) == FAILURE) {
754                RETURN_FALSE;
755        }
756        caca_canvas_t *canvas;
757        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
758        if (str_len != 1) {
759                RETURN_FALSE;
760        }
761        RETURN_SUCCESS(caca_draw_box(canvas, xa, ya, xb, yb, str[0]));
762}
763
764PHP_FUNCTION(caca_draw_thin_box) {
765        zval *_zval;
766        long xa, ya, xb, yb = 0;
767        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllll", &_zval, &xa, &ya, &xb, &yb) == FAILURE) {
768                RETURN_FALSE;
769        }
770        caca_canvas_t *canvas;
771        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
772        RETURN_SUCCESS(caca_draw_thin_box(canvas, xa, ya, xb, yb));
773}
774
775PHP_FUNCTION(caca_draw_cp437_box) {
776        zval *_zval;
777        long xa, ya, xb, yb = 0;
778        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllll", &_zval, &xa, &ya, &xb, &yb) == FAILURE) {
779                RETURN_FALSE;
780        }
781        caca_canvas_t *canvas;
782        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
783        RETURN_SUCCESS(caca_draw_cp437_box(canvas, xa, ya, xb, yb));
784}
785
786PHP_FUNCTION(caca_fill_box) {
787        zval *_zval;
788        char *str;
789        long str_len, xa, ya, xb, yb = 0;
790        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlllls", &_zval, &xa, &ya, &xb, &yb, &str, &str_len) == FAILURE) {
791                RETURN_FALSE;
792        }
793        caca_canvas_t *canvas;
794        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
795        if (str_len != 1) {
796                RETURN_FALSE;
797        }
798        RETURN_SUCCESS(caca_fill_box(canvas, xa, ya, xb, yb, str[0]));
799}
800
801PHP_FUNCTION(caca_draw_triangle) {
802        zval *_zval;
803        char *str;
804        long str_len, xa, ya, xb, yb, xc, yc = 0;
805        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlllllls", &_zval, &xa, &ya, &xb, &yb, &xc, &yc, &str, &str_len) == FAILURE) {
806                RETURN_FALSE;
807        }
808        caca_canvas_t *canvas;
809        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
810        if (str_len != 1) {
811                RETURN_FALSE;
812        }
813        RETURN_SUCCESS(caca_draw_triangle(canvas, xa, ya, xb, yb, xc, yc, str[0]));
814}
815
816PHP_FUNCTION(caca_draw_thin_triangle) {
817        zval *_zval;
818        long xa, ya, xb, yb, xc, yc = 0;
819        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllllll", &_zval, &xa, &ya, &xb, &yb, &xc, &yc) == FAILURE) {
820                RETURN_FALSE;
821        }
822        caca_canvas_t *canvas;
823        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
824        RETURN_SUCCESS(caca_draw_thin_triangle(canvas, xa, ya, xb, yb, xc, yc));
825}
826
827PHP_FUNCTION(caca_fill_triangle) {
828        zval *_zval;
829        char *str;
830        long str_len, xa, ya, xb, yb, xc, yc = 0;
831        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlllllls", &_zval, &xa, &ya, &xb, &yb, &xc, &yc, &str, &str_len) == FAILURE) {
832                RETURN_FALSE;
833        }
834        caca_canvas_t *canvas;
835        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
836        if (str_len != 1) {
837                RETURN_FALSE;
838        }
839        RETURN_SUCCESS(caca_fill_triangle(canvas, xa, ya, xb, yb, xc, yc, str[0]));
840}
841
842PHP_FUNCTION(caca_get_frame_count) {
843}
844
845PHP_FUNCTION(caca_set_frame) {
846}
847
848PHP_FUNCTION(caca_set_frame_name) {
849}
850
851PHP_FUNCTION(caca_create_frame) {
852}
853
854PHP_FUNCTION(caca_free_frame) {
855}
856
857PHP_FUNCTION(caca_set_dither_palette) {
858}
859
860PHP_FUNCTION(caca_set_dither_brightness) {
861}
862
863PHP_FUNCTION(caca_get_dither_brightness) {
864}
865
866PHP_FUNCTION(caca_set_dither_gamma) {
867}
868
869PHP_FUNCTION(caca_get_dither_gamma) {
870}
871
872PHP_FUNCTION(caca_set_dither_contrast) {
873}
874
875PHP_FUNCTION(caca_get_dither_contrast) {
876}
877
878PHP_FUNCTION(caca_set_dither_antialias) {
879}
880
881PHP_FUNCTION(caca_get_dither_antialias_list) {
882}
883
884PHP_FUNCTION(caca_get_dither_antialias) {
885}
886
887PHP_FUNCTION(caca_set_dither_color) {
888}
889
890PHP_FUNCTION(caca_get_dither_color_list) {
891}
892
893PHP_FUNCTION(caca_get_dither_color) {
894}
895
896PHP_FUNCTION(caca_set_dither_charset) {
897}
898
899PHP_FUNCTION(caca_get_dither_charset_list) {
900}
901
902PHP_FUNCTION(caca_get_dither_charset) {
903}
904
905PHP_FUNCTION(caca_set_dither_algorithm) {
906}
907
908PHP_FUNCTION(caca_get_dither_algorithm_list) {
909}
910
911PHP_FUNCTION(caca_get_dither_algorithm) {
912}
913
914PHP_FUNCTION(caca_dither_bitmap) {
915}
916
917PHP_FUNCTION(caca_get_font_list) {
918}
919
920PHP_FUNCTION(caca_get_font_width) {
921}
922
923PHP_FUNCTION(caca_get_font_height) {
924}
925
926PHP_FUNCTION(caca_render_canvas) {
927}
928
929PHP_FUNCTION(caca_canvas_set_figfont) {
930}
931
932PHP_FUNCTION(caca_put_figchar) {
933}
934
935PHP_FUNCTION(caca_flush_figlet) {
936}
937
938PHP_FUNCTION(caca_file_close) {
939}
940
941PHP_FUNCTION(caca_file_tell) {
942}
943
944PHP_FUNCTION(caca_file_read) {
945}
946
947PHP_FUNCTION(caca_file_write) {
948}
949
950PHP_FUNCTION(caca_file_gets) {
951}
952
953PHP_FUNCTION(caca_file_eof) {
954}
955
956PHP_FUNCTION(caca_import_string) {
957        zval *_zval;
958        char *src, *type;
959        long src_len, type_len = 0;
960        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss", &_zval, &src, &src_len, &type, &type_len) == FAILURE) {
961                RETURN_FALSE;
962        }
963        caca_canvas_t *canvas;
964        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
965
966        RETURN_LONG(caca_import_memory(canvas, src, src_len, type));
967}
968
969PHP_FUNCTION(caca_import_file) {
970}
971
972PHP_FUNCTION(caca_get_import_list) {
973}
974
975PHP_FUNCTION(caca_export_string) {
976        zval *_zval;
977        char *type;
978        long type_len;
979        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &_zval, &type, &type_len) == FAILURE) {
980                RETURN_FALSE;
981        }
982        caca_canvas_t *canvas;
983        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
984
985        void *buffer;
986        size_t len;
987        buffer = caca_export_memory(canvas, type, &len);
988        return_value->type = IS_STRING;
989        return_value->value.str.len = len;
990        return_value->value.str.val = emalloc(len);
991        memcpy(return_value->value.str.val, buffer, len);
992        free(buffer);
993}
994
995PHP_FUNCTION(caca_get_export_list) {
996}
997
998PHP_FUNCTION(caca_create_display) {
999        caca_canvas_t *canvas;
1000        FETCH_CANVAS(canvas);
1001
1002        caca_display_t *display = caca_create_display(canvas);
1003        ZEND_REGISTER_RESOURCE(return_value, display, le_caca_display);
1004}
1005
1006PHP_FUNCTION(caca_create_display_with_driver) {
1007        zval *_zval;
1008        char *str;
1009        long str_len = 0;
1010        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &_zval, &str, &str_len) == FAILURE) {
1011                RETURN_FALSE;
1012        }
1013        caca_canvas_t *canvas;
1014        ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
1015
1016        caca_display_t *display = caca_create_display_with_driver(canvas, str);
1017        if (!display) {
1018                RETURN_FALSE;
1019        }
1020        ZEND_REGISTER_RESOURCE(return_value, display, le_caca_display);
1021}
1022
1023PHP_FUNCTION(caca_get_display_driver_list) {
1024}
1025
1026PHP_FUNCTION(caca_get_display_driver) {
1027}
1028
1029PHP_FUNCTION(caca_set_display_driver) {
1030}
1031
1032PHP_FUNCTION(caca_get_canvas) {
1033}
1034
1035PHP_FUNCTION(caca_refresh_display) {
1036        caca_display_t *display;
1037        FETCH_DISPLAY(display);
1038        RETURN_SUCCESS(caca_refresh_display(display));
1039}
1040
1041PHP_FUNCTION(caca_set_display_time) {
1042        zval *_zval;
1043        long value = 0;
1044        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &_zval, &value) == FAILURE) {
1045                RETURN_FALSE;
1046        }
1047        caca_display_t *display;
1048        ZEND_FETCH_RESOURCE(display, caca_display_t*, &_zval, -1, PHP_CACA_DISPLAY_RES_NAME, le_caca_display);
1049        RETURN_SUCCESS(caca_set_display_time(display, value));
1050}
1051
1052PHP_FUNCTION(caca_get_display_time) {
1053        caca_display_t *display;
1054        FETCH_DISPLAY(display);
1055        RETURN_LONG(caca_get_display_time(display)); //TODO: check return value
1056}
1057
1058PHP_FUNCTION(caca_get_display_width) {
1059        caca_display_t *display;
1060        FETCH_DISPLAY(display);
1061        RETURN_LONG(caca_get_display_width(display));
1062}
1063
1064PHP_FUNCTION(caca_get_display_height) {
1065        caca_display_t *display;
1066        FETCH_DISPLAY(display);
1067        RETURN_LONG(caca_get_display_height(display));
1068}
1069
1070PHP_FUNCTION(caca_set_display_title) {
1071        zval *_zval;
1072        char *str;
1073        long str_len = 0;
1074        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &_zval, &str, &str_len) == FAILURE) {
1075                RETURN_FALSE;
1076        }
1077        caca_display_t *display;
1078        ZEND_FETCH_RESOURCE(display, caca_display_t*, &_zval, -1, PHP_CACA_DISPLAY_RES_NAME, le_caca_display);
1079        RETURN_SUCCESS(caca_set_display(display, str));
1080}
1081
1082PHP_FUNCTION(caca_set_mouse) {
1083        zval *_zval;
1084        long value = 0;
1085        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &_zval, &value) == FAILURE) {
1086                RETURN_FALSE;
1087        }
1088        caca_display_t *display;
1089        ZEND_FETCH_RESOURCE(display, caca_display_t*, &_zval, -1, PHP_CACA_DISPLAY_RES_NAME, le_caca_display);
1090        RETURN_SUCCESS(caca_set_mouse(display, value));
1091}
1092
1093PHP_FUNCTION(caca_set_cursor) {
1094        zval *_zval;
1095        long value = 0;
1096        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &_zval, &value) == FAILURE) {
1097                RETURN_FALSE;
1098        }
1099        caca_display_t *display;
1100        ZEND_FETCH_RESOURCE(display, caca_display_t*, &_zval, -1, PHP_CACA_DISPLAY_RES_NAME, le_caca_display);
1101        RETURN_SUCCESS(caca_set_cursor(display, value));
1102}
1103
1104PHP_FUNCTION(caca_get_event) {
1105        zval *_zval1, *_zval2 = NULL;
1106        long g, aa = 0;
1107        if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl|rl", &_zval1, &g, &_zval2, &aa) == FAILURE) {
1108                RETURN_FALSE;
1109        }
1110        caca_display_t *display;
1111        ZEND_FETCH_RESOURCE(display, caca_display_t*, &_zval1, -1, PHP_CACA_DISPLAY_RES_NAME, le_caca_display);
1112
1113        caca_event_t *event = NULL;
1114        if (_zval2) {
1115                ZEND_FETCH_RESOURCE(event, caca_event_t*, &_zval2, -1, PHP_CACA_EVENT_RES_NAME, le_caca_event);
1116        }
1117        RETURN_LONG(caca_get_event(display, g, event, aa));
1118}
1119
1120PHP_FUNCTION(caca_get_mouse_x) {
1121        caca_display_t *display;
1122        FETCH_DISPLAY(display);
1123        RETURN_LONG(caca_get_mouse_x(display));
1124}
1125
1126PHP_FUNCTION(caca_get_mouse_y) {
1127        caca_display_t *display;
1128        FETCH_DISPLAY(display);
1129        RETURN_LONG(caca_get_mouse_y(display));
1130}
1131
1132PHP_FUNCTION(caca_get_event_type) {
1133        caca_event_t *event;
1134        FETCH_EVENT(event);
1135        RETURN_LONG(caca_get_event_type(event));
1136}
1137
1138PHP_FUNCTION(caca_get_event_key_ch) {
1139        caca_event_t *event;
1140        FETCH_EVENT(event);
1141        RETURN_LONG(caca_get_event_key_ch(event));
1142}
1143
1144PHP_FUNCTION(caca_get_event_mouse_button) {
1145        caca_event_t *event;
1146        FETCH_EVENT(event);
1147        RETURN_LONG(caca_get_event_mouse_button(event));
1148}
1149
1150PHP_FUNCTION(caca_get_event_mouse_x) {
1151        caca_event_t *event;
1152        FETCH_EVENT(event);
1153        RETURN_LONG(caca_get_event_mouse_x(event));
1154}
1155
1156PHP_FUNCTION(caca_get_event_mouse_y) {
1157        caca_event_t *event;
1158        FETCH_EVENT(event);
1159        RETURN_LONG(caca_get_event_mouse_y(event));
1160}
1161
1162PHP_FUNCTION(caca_get_event_resize_width) {
1163        caca_event_t *event;
1164        FETCH_EVENT(event);
1165        RETURN_LONG(caca_get_event_resize_width(event));
1166}
1167
1168PHP_FUNCTION(caca_get_event_resize_height) {
1169        caca_event_t *event;
1170        FETCH_EVENT(event);
1171        RETURN_LONG(caca_get_event_resize_height(event));
1172}
1173
Note: See TracBrowser for help on using the repository browser.