您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符
 
 
 
 
 
 

1451 行
47 KiB

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