Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

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