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

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