|
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484 |
- /*
- * php-caca Php binding for Libcaca
- * Copyright (c) 2008 Vion Nicolas <nico@picapo.net>
- *
- *
- * This library is free software. It comes without any warranty, to
- * the extent permitted by applicable law. You can redistribute it
- * and/or modify it under the terms of the Do What The Fuck You Want
- * To Public License, Version 2, as published by Sam Hocevar. See
- * http://sam.zoy.org/wtfpl/COPYING for more details.
- */
-
- #ifdef HAVE_CONFIG_H
- #include "config.h"
- #endif
-
- #include "php.h"
- #include "php_caca.h"
- #include <gd.h>
-
- static function_entry caca_functions[] = {
- PHP_FE(caca_create_event, NULL)
- PHP_FE(caca_create_canvas, NULL)
- PHP_FE(caca_manage_canvas, NULL)
- PHP_FE(caca_unmanage_canvas, NULL)
- PHP_FE(caca_set_canvas_size, NULL)
- PHP_FE(caca_get_canvas_width, NULL)
- PHP_FE(caca_get_canvas_height, NULL)
- PHP_FE(caca_get_canvas_chars, NULL)
- PHP_FE(caca_get_canvas_attrs, NULL)
- PHP_FE(caca_rand, NULL)
- PHP_FE(caca_get_version, NULL)
- PHP_FE(caca_gotoxy, NULL)
- PHP_FE(caca_get_cursor_x, NULL)
- PHP_FE(caca_get_cursor_y, NULL)
- PHP_FE(caca_put_char, NULL)
- PHP_FE(caca_get_char, NULL)
- PHP_FE(caca_put_str, NULL)
- PHP_FE(caca_clear_canvas, NULL)
- PHP_FE(caca_set_canvas_handle, NULL)
- PHP_FE(caca_get_canvas_handle_x, NULL)
- PHP_FE(caca_get_canvas_handle_y, NULL)
- PHP_FE(caca_blit, NULL)
- PHP_FE(caca_set_canvas_boundaries, NULL)
- PHP_FE(caca_invert, NULL)
- PHP_FE(caca_flip, NULL)
- PHP_FE(caca_flop, NULL)
- PHP_FE(caca_rotate_180, NULL)
- PHP_FE(caca_rotate_left, NULL)
- PHP_FE(caca_rotate_right, NULL)
- PHP_FE(caca_stretch_left, NULL)
- PHP_FE(caca_stretch_right, NULL)
- PHP_FE(caca_get_attr, NULL)
- PHP_FE(caca_set_attr, NULL)
- PHP_FE(caca_put_attr, NULL)
- PHP_FE(caca_set_color_ansi, NULL)
- PHP_FE(caca_set_color_argb, NULL)
- PHP_FE(caca_attr_to_ansi, NULL)
- PHP_FE(caca_attr_to_ansi_fg, NULL)
- PHP_FE(caca_attr_to_ansi_bg, NULL)
- PHP_FE(caca_attr_to_rgb12_fg, NULL)
- PHP_FE(caca_attr_to_rgb12_bg, NULL)
- PHP_FE(caca_attr_to_argb64, NULL)
- PHP_FE(caca_utf8_to_utf32, NULL)
- PHP_FE(caca_utf32_to_utf8, NULL)
- PHP_FE(caca_utf32_to_cp437, NULL)
- PHP_FE(caca_cp437_to_utf32, NULL)
- PHP_FE(caca_utf32_to_ascii, NULL)
- PHP_FE(caca_utf32_is_fullwidth, NULL)
- PHP_FE(caca_draw_line, NULL)
- PHP_FE(caca_draw_polyline, NULL)
- PHP_FE(caca_draw_thin_line, NULL)
- PHP_FE(caca_draw_thin_polyline, NULL)
- PHP_FE(caca_draw_circle, NULL)
- PHP_FE(caca_draw_ellipse, NULL)
- PHP_FE(caca_draw_thin_ellipse, NULL)
- PHP_FE(caca_fill_ellipse, NULL)
- PHP_FE(caca_draw_box, NULL)
- PHP_FE(caca_draw_thin_box, NULL)
- PHP_FE(caca_draw_cp437_box, NULL)
- PHP_FE(caca_fill_box, NULL)
- PHP_FE(caca_draw_triangle, NULL)
- PHP_FE(caca_draw_thin_triangle, NULL)
- PHP_FE(caca_fill_triangle, NULL)
- PHP_FE(caca_get_frame_count, NULL)
- PHP_FE(caca_set_frame, NULL)
- PHP_FE(caca_set_frame_name, NULL)
- PHP_FE(caca_create_frame, NULL)
- PHP_FE(caca_free_frame, NULL)
- PHP_FE(caca_create_dither, NULL)
- PHP_FE(caca_set_dither_palette, NULL)
- PHP_FE(caca_set_dither_brightness, NULL)
- PHP_FE(caca_get_dither_brightness, NULL)
- PHP_FE(caca_set_dither_gamma, NULL)
- PHP_FE(caca_get_dither_gamma, NULL)
- PHP_FE(caca_set_dither_contrast, NULL)
- PHP_FE(caca_get_dither_contrast, NULL)
- PHP_FE(caca_set_dither_antialias, NULL)
- PHP_FE(caca_get_dither_antialias_list, NULL)
- PHP_FE(caca_get_dither_antialias, NULL)
- PHP_FE(caca_set_dither_color, NULL)
- PHP_FE(caca_get_dither_color_list, NULL)
- PHP_FE(caca_get_dither_color, NULL)
- PHP_FE(caca_set_dither_charset, NULL)
- PHP_FE(caca_get_dither_charset_list, NULL)
- PHP_FE(caca_get_dither_charset, NULL)
- PHP_FE(caca_set_dither_algorithm, NULL)
- PHP_FE(caca_get_dither_algorithm_list, NULL)
- PHP_FE(caca_get_dither_algorithm, NULL)
- PHP_FE(caca_dither_bitmap_gd, NULL)
- PHP_FE(caca_get_font_list, NULL)
- PHP_FE(caca_get_font_width, NULL)
- PHP_FE(caca_get_font_height, NULL)
- PHP_FE(caca_render_canvas, NULL)
- PHP_FE(caca_canvas_set_figfont, NULL)
- PHP_FE(caca_put_figchar, NULL)
- PHP_FE(caca_flush_figlet, NULL)
- PHP_FE(caca_file_close, NULL)
- PHP_FE(caca_file_tell, NULL)
- PHP_FE(caca_file_read, NULL)
- PHP_FE(caca_file_write, NULL)
- PHP_FE(caca_file_gets, NULL)
- PHP_FE(caca_file_eof, NULL)
- PHP_FE(caca_import_string, NULL)
- PHP_FE(caca_import_file, NULL)
- PHP_FE(caca_get_import_list, NULL)
- PHP_FE(caca_export_string, NULL)
- PHP_FE(caca_get_export_list, NULL)
- PHP_FE(caca_create_display, NULL)
- PHP_FE(caca_create_display_with_driver, NULL)
- PHP_FE(caca_get_display_driver_list, NULL)
- PHP_FE(caca_get_display_driver, NULL)
- PHP_FE(caca_set_display_driver, NULL)
- PHP_FE(caca_get_canvas, NULL)
- PHP_FE(caca_refresh_display, NULL)
- PHP_FE(caca_set_display_time, NULL)
- PHP_FE(caca_get_display_time, NULL)
- PHP_FE(caca_get_display_width, NULL)
- PHP_FE(caca_get_display_height, NULL)
- PHP_FE(caca_set_display_title, NULL)
- PHP_FE(caca_set_mouse, NULL)
- PHP_FE(caca_set_cursor, NULL)
- PHP_FE(caca_get_event, NULL)
- PHP_FE(caca_get_mouse_x, NULL)
- PHP_FE(caca_get_mouse_y, NULL)
- PHP_FE(caca_get_event_type, NULL)
- PHP_FE(caca_get_event_key_ch, NULL)
- PHP_FE(caca_get_event_mouse_button, NULL)
- PHP_FE(caca_get_event_mouse_x, NULL)
- PHP_FE(caca_get_event_mouse_y, NULL)
- PHP_FE(caca_get_event_resize_width, NULL)
- PHP_FE(caca_get_event_resize_height, NULL)
-
- {NULL, NULL, NULL}
- };
-
- zend_module_entry caca_module_entry = {
- #if ZEND_MODULE_API_NO >= 20010901
- STANDARD_MODULE_HEADER,
- #endif
- PHP_CACA_EXTNAME,
- caca_functions,
- PHP_MINIT(caca),
- NULL,
- NULL,
- NULL,
- PHP_MINFO(caca),
- #if ZEND_MODULE_API_NO >= 20010901
- PHP_CACA_VERSION,
- #endif
- STANDARD_MODULE_PROPERTIES
- };
-
- #ifdef COMPILE_DL_CACA
- ZEND_GET_MODULE(caca)
- #endif
-
- PHP_MINFO_FUNCTION(caca) {
- php_info_print_table_start();
- php_info_print_table_row(2, "Caca library version", caca_get_version());
- php_info_print_table_end();
- }
-
- //-------- Caca's ressources destructors -----------//
-
- static void php_caca_canvas_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) {
- caca_free_canvas(rsrc->ptr);
- }
-
- static void php_caca_dither_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) {
- caca_free_dither(rsrc->ptr);
- }
-
- static void php_caca_font_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) {
- caca_free_font(rsrc->ptr);
- }
-
- static void php_caca_file_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) {
- }
-
- static void php_caca_display_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) {
- caca_free_display(rsrc->ptr);
- }
-
- static void php_caca_event_dtor(zend_rsrc_list_entry *rsrc TSRMLS_DC) {
- efree((caca_event_t *) rsrc->ptr);
- }
-
- //-------- Initialization ---------//
-
- PHP_MINIT_FUNCTION(caca) {
-
- le_caca_canvas = zend_register_list_destructors_ex(php_caca_canvas_dtor, NULL, PHP_CACA_CANVAS_RES_NAME, module_number);
- le_caca_dither = zend_register_list_destructors_ex(php_caca_dither_dtor, NULL, PHP_CACA_DITHER_RES_NAME, module_number);
- le_caca_font = zend_register_list_destructors_ex(php_caca_font_dtor, NULL, PHP_CACA_FONT_RES_NAME, module_number);
- le_caca_file = zend_register_list_destructors_ex(php_caca_file_dtor, NULL, PHP_CACA_FILE_RES_NAME, module_number);
- le_caca_display = zend_register_list_destructors_ex(php_caca_display_dtor, NULL, PHP_CACA_DISPLAY_RES_NAME, module_number);
- le_caca_event = zend_register_list_destructors_ex(php_caca_event_dtor, NULL, PHP_CACA_EVENT_RES_NAME, module_number);
-
- REGISTER_LONG_CONSTANT("CACA_BLACK", CACA_BLACK, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_BLUE", CACA_BLUE, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_GREEN", CACA_GREEN, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_CYAN", CACA_CYAN, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_RED", CACA_RED, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_MAGENTA", CACA_MAGENTA, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_BROWN", CACA_BROWN, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_LIGHTGRAY", CACA_LIGHTGRAY, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_DARKGRAY", CACA_DARKGRAY, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_LIGHTBLUE", CACA_LIGHTBLUE, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_LIGHTGREEN", CACA_LIGHTGREEN, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_LIGHTCYAN", CACA_LIGHTCYAN, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_LIGHTRED", CACA_LIGHTRED, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_LIGHTMAGENTA", CACA_LIGHTMAGENTA, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_YELLOW", CACA_YELLOW, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_WHITE", CACA_WHITE, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_DEFAULT", CACA_DEFAULT, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_TRANSPARENT", CACA_TRANSPARENT, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_BOLD", CACA_BOLD, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_ITALICS", CACA_ITALICS, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_UNDERLINE", CACA_UNDERLINE, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_BLINK", CACA_BLINK, CONST_CS | CONST_PERSISTENT);
-
- REGISTER_LONG_CONSTANT("CACA_EVENT_NONE", CACA_EVENT_NONE, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_EVENT_KEY_PRESS", CACA_EVENT_KEY_PRESS, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_EVENT_KEY_RELEASE", CACA_EVENT_KEY_RELEASE, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_EVENT_MOUSE_PRESS", CACA_EVENT_MOUSE_PRESS, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_EVENT_MOUSE_RELEASE", CACA_EVENT_MOUSE_RELEASE, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_EVENT_MOUSE_MOTION", CACA_EVENT_MOUSE_MOTION, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_EVENT_RESIZE", CACA_EVENT_RESIZE, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_EVENT_QUIT", CACA_EVENT_QUIT, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_EVENT_ANY", CACA_EVENT_ANY, CONST_CS | CONST_PERSISTENT);
-
- REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_A", CACA_KEY_CTRL_A, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_B", CACA_KEY_CTRL_B, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_C", CACA_KEY_CTRL_C, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_D", CACA_KEY_CTRL_D, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_E", CACA_KEY_CTRL_E, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_F", CACA_KEY_CTRL_F, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_G", CACA_KEY_CTRL_G, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_KEY_BACKSPACE", CACA_KEY_BACKSPACE, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_KEY_TAB", CACA_KEY_TAB, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_J", CACA_KEY_CTRL_J, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_K", CACA_KEY_CTRL_K, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_L", CACA_KEY_CTRL_L, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_KEY_RETURN", CACA_KEY_RETURN, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_N", CACA_KEY_CTRL_N, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_O", CACA_KEY_CTRL_O, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_P", CACA_KEY_CTRL_P, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_Q", CACA_KEY_CTRL_Q, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_R", CACA_KEY_CTRL_R, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_KEY_PAUSE", CACA_KEY_PAUSE, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_T", CACA_KEY_CTRL_T, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_U", CACA_KEY_CTRL_U, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_V", CACA_KEY_CTRL_V, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_W", CACA_KEY_CTRL_W, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_X", CACA_KEY_CTRL_X, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_Y", CACA_KEY_CTRL_Y, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_KEY_CTRL_Z", CACA_KEY_CTRL_Z, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_KEY_ESCAPE", CACA_KEY_ESCAPE, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_KEY_DELETE", CACA_KEY_DELETE, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_KEY_UP", CACA_KEY_UP, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_KEY_DOWN", CACA_KEY_DOWN, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_KEY_LEFT", CACA_KEY_LEFT, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_KEY_RIGHT", CACA_KEY_RIGHT, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_KEY_INSERT", CACA_KEY_INSERT, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_KEY_HOME", CACA_KEY_HOME, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_KEY_END", CACA_KEY_END, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_KEY_PAGEUP", CACA_KEY_PAGEUP, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_KEY_PAGEDOWN", CACA_KEY_PAGEDOWN, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_KEY_F1", CACA_KEY_F1, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_KEY_F2", CACA_KEY_F2, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_KEY_F3", CACA_KEY_F3, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_KEY_F4", CACA_KEY_F4, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_KEY_F5", CACA_KEY_F5, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_KEY_F6", CACA_KEY_F6, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_KEY_F7", CACA_KEY_F7, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_KEY_F8", CACA_KEY_F8, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_KEY_F9", CACA_KEY_F9, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_KEY_F10", CACA_KEY_F10, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_KEY_F11", CACA_KEY_F11, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_KEY_F12", CACA_KEY_F12, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_KEY_F13", CACA_KEY_F13, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_KEY_F14", CACA_KEY_F14, CONST_CS | CONST_PERSISTENT);
- REGISTER_LONG_CONSTANT("CACA_KEY_F15", CACA_KEY_F15, CONST_CS | CONST_PERSISTENT);
-
- return SUCCESS;
- }
-
- //---------- Some usefull macros ---------------//
-
- #define FETCH_CANVAS(canvas) \
- zval *_zval; \
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) { \
- RETURN_FALSE; \
- } \
- ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
-
- #define FETCH_DISPLAY(display) \
- zval *_zval; \
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) { \
- RETURN_FALSE; \
- } \
- ZEND_FETCH_RESOURCE(display, caca_display_t*, &_zval, -1, PHP_CACA_DISPLAY_RES_NAME, le_caca_display);
-
- #define FETCH_EVENT(event) \
- zval *_zval; \
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) { \
- RETURN_FALSE; \
- } \
- ZEND_FETCH_RESOURCE(event, caca_event_t*, &_zval, -1, PHP_CACA_EVENT_RES_NAME, le_caca_event);
-
- #define FETCH_LONG(l) \
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "l", &l) == FAILURE) { \
- RETURN_FALSE; \
- }
-
- #define RETURN_CHAR(c) \
- char *str = emalloc(2); \
- str[0] = c; \
- str[1] = '\0'; \
- RETURN_STRING(str, 0);
-
- #define RETURN_SUCCESS(i) \
- RETURN_BOOL((i) == 0);
-
- //------- Function that allows to fetch external php resources such as gd resouces
-
- void *fetch_external_resource(zval *_zval, char const *type_name) {
- int resource_id = _zval->value.lval;
- int resource_type;
- void *result = zend_list_find(resource_id, &resource_type);
- char *resource_type_name = zend_rsrc_list_get_rsrc_type(resource_id);
- return (strcmp(resource_type_name, type_name) == 0) ? result : NULL;
- }
-
- //------- PHP Binding's specific functions ----------//
-
- PHP_FUNCTION(caca_create_event) {
- caca_event_t *event;
- event = emalloc(sizeof(caca_event_t));
- ZEND_REGISTER_RESOURCE(return_value, event, le_caca_event);
- }
-
- //------- Caca's functions ----------------//
-
- PHP_FUNCTION(caca_create_canvas) {
- long width, height = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &width, &height) == FAILURE) {
- RETURN_FALSE;
- }
- caca_canvas_t *canvas = caca_create_canvas(width, height);
- if (!canvas) {
- RETURN_FALSE;
- }
- ZEND_REGISTER_RESOURCE(return_value, canvas, le_caca_canvas);
- }
-
- PHP_FUNCTION(caca_manage_canvas) {
- }
-
- PHP_FUNCTION(caca_unmanage_canvas) {
- }
-
- PHP_FUNCTION(caca_set_canvas_size) {
- zval *_zval;
- long width, height = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &_zval, &width, &height) == FAILURE) {
- RETURN_FALSE;
- }
- caca_canvas_t *canvas;
- ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
- RETURN_SUCCESS(caca_set_canvas_size(canvas, width, height));
- }
-
- PHP_FUNCTION(caca_get_canvas_width) {
- caca_canvas_t *canvas;
- FETCH_CANVAS(canvas);
- RETURN_LONG(caca_get_canvas_width(canvas));
- }
-
- PHP_FUNCTION(caca_get_canvas_height) {
- caca_canvas_t *canvas;
- FETCH_CANVAS(canvas);
- RETURN_LONG(caca_get_canvas_height(canvas));
- }
-
- PHP_FUNCTION(caca_get_canvas_chars) {
- caca_canvas_t *canvas;
- FETCH_CANVAS(canvas);
- RETURN_STRING((char *) caca_get_canvas_chars(canvas), 1); //TODO: check that return \0 terminated string
- }
-
- PHP_FUNCTION(caca_get_canvas_attrs) {
- caca_canvas_t *canvas;
- FETCH_CANVAS(canvas);
- RETURN_STRING((char *) caca_get_canvas_attrs(canvas), 1); //TODO: check that return \0 terminated string
- }
-
- PHP_FUNCTION(caca_rand) {
- long min, max = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ll", &min, &max) == FAILURE) {
- RETURN_FALSE;
- }
- RETURN_LONG(caca_rand(min, max));
- }
-
- PHP_FUNCTION(caca_get_version) {
- RETURN_STRING((char *) caca_get_version(), 1);
- }
-
- PHP_FUNCTION(caca_gotoxy) {
- zval *_zval;
- long x, y = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &_zval, &x, &y) == FAILURE) {
- RETURN_FALSE;
- }
- caca_canvas_t *canvas;
- ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
- RETURN_SUCCESS(caca_gotoxy(canvas, x, y));
- }
-
- PHP_FUNCTION(caca_get_cursor_x) {
- caca_canvas_t *canvas;
- FETCH_CANVAS(canvas);
- RETURN_LONG(caca_get_cursor_x(canvas));
- }
-
- PHP_FUNCTION(caca_get_cursor_y) {
- caca_canvas_t *canvas;
- FETCH_CANVAS(canvas);
- RETURN_LONG(caca_get_cursor_y(canvas));
- }
-
- PHP_FUNCTION(caca_put_char) {
- zval *_zval;
- char *str;
- long str_len, x, y = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlls", &_zval, &x, &y, &str, &str_len) == FAILURE) {
- RETURN_FALSE;
- }
- caca_canvas_t *canvas;
- ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
- if (str_len != 1) {
- RETURN_FALSE;
- }
- RETURN_SUCCESS(caca_put_char(canvas, x, y, str[0]));
- }
-
- PHP_FUNCTION(caca_get_char) {
- zval *_zval;
- long x, y = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &_zval, &x, &y) == FAILURE) {
- RETURN_FALSE;
- }
- caca_canvas_t *canvas;
- ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
- RETURN_CHAR(caca_get_char(canvas, x, y));
- }
-
- PHP_FUNCTION(caca_put_str) {
- zval *_zval;
- char *str;
- long x, y, str_len = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlls", &_zval, &x, &y, &str, &str_len) == FAILURE) {
- RETURN_FALSE;
- }
- caca_canvas_t *canvas;
- ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
- RETURN_SUCCESS(caca_put_str(canvas, x, y, str));
- }
-
- PHP_FUNCTION(caca_clear_canvas) {
- caca_canvas_t *canvas;
- FETCH_CANVAS(canvas);
- RETURN_LONG(caca_clear_canvas(canvas));
- }
-
- PHP_FUNCTION(caca_set_canvas_handle) {
- zval *_zval;
- long x, y = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &_zval, &x, &y) == FAILURE) {
- RETURN_FALSE;
- }
- caca_canvas_t *canvas;
- ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
- RETURN_SUCCESS(caca_set_canvas_handle(canvas, x, y));
- }
-
- PHP_FUNCTION(caca_get_canvas_handle_x) {
- caca_canvas_t *canvas;
- FETCH_CANVAS(canvas);
- RETURN_LONG(caca_get_canvas_handle_x(canvas));
- }
-
- PHP_FUNCTION(caca_get_canvas_handle_y) {
- caca_canvas_t *canvas;
- FETCH_CANVAS(canvas);
- RETURN_LONG(caca_get_canvas_handle_y(canvas));
- }
-
- PHP_FUNCTION(caca_blit) {
- zval *_zval1, *_zval2, *_zval3 = NULL;
- long x, y = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllr|r", &_zval1, &x, &y, &_zval2, &_zval3) == FAILURE) {
- RETURN_FALSE;
- }
- caca_canvas_t *dst, *src, *mask = NULL;
- ZEND_FETCH_RESOURCE(dst, caca_canvas_t*, &_zval1, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
- ZEND_FETCH_RESOURCE(src, caca_canvas_t*, &_zval2, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
- if (_zval3) {
- ZEND_FETCH_RESOURCE(mask, caca_canvas_t*, &_zval3, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
- }
- RETURN_SUCCESS(caca_blit(dst, x, y, src, NULL));
- }
-
- PHP_FUNCTION(caca_set_canvas_boundaries) {
- zval *_zval;
- long x, y, width, height = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllll", &_zval, &x, &y, &width, &height) == FAILURE) {
- RETURN_FALSE;
- }
- caca_canvas_t *canvas;
- ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
- RETURN_SUCCESS(caca_set_canvas_boundaries(canvas, x, y, width, height));
- }
-
- PHP_FUNCTION(caca_invert) {
- caca_canvas_t *canvas;
- FETCH_CANVAS(canvas);
- RETURN_SUCCESS(caca_invert(canvas));
- }
-
- PHP_FUNCTION(caca_flip) {
- caca_canvas_t *canvas;
- FETCH_CANVAS(canvas);
- RETURN_SUCCESS(caca_flip(canvas));
- }
-
- PHP_FUNCTION(caca_flop) {
- caca_canvas_t *canvas;
- FETCH_CANVAS(canvas);
- RETURN_SUCCESS(caca_flop(canvas));
- }
-
- PHP_FUNCTION(caca_rotate_180) {
- caca_canvas_t *canvas;
- FETCH_CANVAS(canvas);
- RETURN_SUCCESS(caca_rotate_180(canvas));
- }
-
- PHP_FUNCTION(caca_rotate_left) {
- caca_canvas_t *canvas;
- FETCH_CANVAS(canvas);
- RETURN_SUCCESS(caca_rotate_left(canvas));
- }
-
- PHP_FUNCTION(caca_rotate_right) {
- caca_canvas_t *canvas;
- FETCH_CANVAS(canvas);
- RETURN_SUCCESS(caca_rotate_right(canvas));
- }
-
- PHP_FUNCTION(caca_stretch_left) {
- caca_canvas_t *canvas;
- FETCH_CANVAS(canvas);
- RETURN_SUCCESS(caca_stretch_left(canvas));
- }
-
- PHP_FUNCTION(caca_stretch_right) {
- caca_canvas_t *canvas;
- FETCH_CANVAS(canvas);
- RETURN_SUCCESS(caca_stretch_right(canvas));
- }
-
- PHP_FUNCTION(caca_get_attr) {
- zval *_zval;
- long x, y = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &_zval, &x, &y) == FAILURE) {
- RETURN_FALSE;
- }
- caca_canvas_t *canvas;
- ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
- RETURN_LONG(caca_get_attr(canvas, x, y));
- }
-
- PHP_FUNCTION(caca_set_attr) {
- zval *_zval;
- long attr = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &_zval, &attr) == FAILURE) {
- RETURN_FALSE;
- }
- caca_canvas_t *canvas;
- ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
- RETURN_SUCCESS(caca_set_attr(canvas, attr));
- }
-
- PHP_FUNCTION(caca_put_attr) {
- zval *_zval;
- long x, y, attr = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlll", &_zval, &x, &y, &attr) == FAILURE) {
- RETURN_FALSE;
- }
- caca_canvas_t *canvas;
- ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
- RETURN_SUCCESS(caca_put_attr(canvas, x, y, attr));
- }
-
- PHP_FUNCTION(caca_set_color_ansi) {
- zval *_zval;
- long foreground, background = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &_zval, &foreground, &background) == FAILURE) {
- RETURN_FALSE;
- }
- caca_canvas_t *canvas;
- ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
- RETURN_SUCCESS(caca_set_color_ansi(canvas, foreground, background));
- }
-
- PHP_FUNCTION(caca_set_color_argb) {
- zval *_zval;
- long foreground, background = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rll", &_zval, &foreground, &background) == FAILURE) {
- RETURN_FALSE;
- }
- caca_canvas_t *canvas;
- ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
- RETURN_SUCCESS(caca_set_color_argb(canvas, foreground, background));
- }
-
- PHP_FUNCTION(caca_attr_to_ansi) {
- long l;
- FETCH_LONG(l);
- RETURN_LONG(caca_attr_to_ansi(l));
- }
-
- PHP_FUNCTION(caca_attr_to_ansi_fg) {
- long l;
- FETCH_LONG(l);
- RETURN_LONG(caca_attr_to_ansi_fg(l));
- }
-
- PHP_FUNCTION(caca_attr_to_ansi_bg) {
- long l;
- FETCH_LONG(l);
- RETURN_LONG(caca_attr_to_ansi_bg(l));
- }
-
- PHP_FUNCTION(caca_attr_to_rgb12_fg) {
- long l;
- FETCH_LONG(l);
- RETURN_LONG(caca_attr_to_rgb12_fg(l));
- }
-
- PHP_FUNCTION(caca_attr_to_rgb12_bg) {
- long l;
- FETCH_LONG(l);
- RETURN_LONG(caca_attr_to_rgb12_bg(l));
- }
-
- PHP_FUNCTION(caca_attr_to_argb64) {
- }
-
- PHP_FUNCTION(caca_utf8_to_utf32) {
- }
-
- PHP_FUNCTION(caca_utf32_to_utf8) {
- }
-
- PHP_FUNCTION(caca_utf32_to_cp437) {
- }
-
- PHP_FUNCTION(caca_cp437_to_utf32) {
- }
-
- PHP_FUNCTION(caca_utf32_to_ascii) {
- }
-
- PHP_FUNCTION(caca_utf32_is_fullwidth) {
- }
-
- PHP_FUNCTION(caca_draw_line) {
- zval *_zval;
- char *str;
- long str_len, xa, ya, xb, yb = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlllls", &_zval, &xa, &ya, &xb, &yb, &str, &str_len) == FAILURE) {
- RETURN_FALSE;
- }
- caca_canvas_t *canvas;
- ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
- if (str_len != 1) {
- RETURN_FALSE;
- }
- RETURN_SUCCESS(caca_draw_line(canvas, xa, ya, xb, yb, str[0]));
- }
-
- PHP_FUNCTION(caca_draw_polyline) {
- }
-
- PHP_FUNCTION(caca_draw_thin_line) {
- zval *_zval;
- long xa, ya, xb, yb = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllll", &_zval, &xa, &ya, &xb, &yb) == FAILURE) {
- RETURN_FALSE;
- }
- caca_canvas_t *canvas;
- ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
- RETURN_SUCCESS(caca_draw_thin_line(canvas, xa, ya, xb, yb));
- }
-
- PHP_FUNCTION(caca_draw_thin_polyline) {
- }
-
- PHP_FUNCTION(caca_draw_circle) {
- zval *_zval;
- char *str;
- long str_len, x, y, r = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllls", &_zval, &x, &y, &r, &str, &str_len) == FAILURE) {
- RETURN_FALSE;
- }
- caca_canvas_t *canvas;
- ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
- if (str_len != 1) {
- RETURN_FALSE;
- }
- RETURN_SUCCESS(caca_draw_circle(canvas, x, y, r, str[0]));
- }
-
- PHP_FUNCTION(caca_draw_ellipse) {
- zval *_zval;
- char *str;
- long str_len, xa, ya, xb, yb = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlllls", &_zval, &xa, &ya, &xb, &yb, &str, &str_len) == FAILURE) {
- RETURN_FALSE;
- }
- caca_canvas_t *canvas;
- ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
- if (str_len != 1) {
- RETURN_FALSE;
- }
- RETURN_SUCCESS(caca_draw_ellipse(canvas, xa, ya, xb, yb, str[0]));
- }
-
- PHP_FUNCTION(caca_draw_thin_ellipse) {
- zval *_zval;
- long xa, ya, xb, yb = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllll", &_zval, &xa, &ya, &xb, &yb) == FAILURE) {
- RETURN_FALSE;
- }
- caca_canvas_t *canvas;
- ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
- RETURN_SUCCESS(caca_draw_thin_ellipse(canvas, xa, ya, xb, yb));
- }
-
- PHP_FUNCTION(caca_fill_ellipse) {
- zval *_zval;
- char *str;
- long str_len, xa, ya, xb, yb = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlllls", &_zval, &xa, &ya, &xb, &yb, &str, &str_len) == FAILURE) {
- RETURN_FALSE;
- }
- caca_canvas_t *canvas;
- ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
- if (str_len != 1) {
- RETURN_FALSE;
- }
- RETURN_SUCCESS(caca_fill_ellipse(canvas, xa, ya, xb, yb, str[0]));
- }
-
- PHP_FUNCTION(caca_draw_box) {
- zval *_zval;
- char *str;
- long str_len, xa, ya, xb, yb = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlllls", &_zval, &xa, &ya, &xb, &yb, &str, &str_len) == FAILURE) {
- RETURN_FALSE;
- }
- caca_canvas_t *canvas;
- ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
- if (str_len != 1) {
- RETURN_FALSE;
- }
- RETURN_SUCCESS(caca_draw_box(canvas, xa, ya, xb, yb, str[0]));
- }
-
- PHP_FUNCTION(caca_draw_thin_box) {
- zval *_zval;
- long xa, ya, xb, yb = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllll", &_zval, &xa, &ya, &xb, &yb) == FAILURE) {
- RETURN_FALSE;
- }
- caca_canvas_t *canvas;
- ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
- RETURN_SUCCESS(caca_draw_thin_box(canvas, xa, ya, xb, yb));
- }
-
- PHP_FUNCTION(caca_draw_cp437_box) {
- zval *_zval;
- long xa, ya, xb, yb = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllll", &_zval, &xa, &ya, &xb, &yb) == FAILURE) {
- RETURN_FALSE;
- }
- caca_canvas_t *canvas;
- ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
- RETURN_SUCCESS(caca_draw_cp437_box(canvas, xa, ya, xb, yb));
- }
-
- PHP_FUNCTION(caca_fill_box) {
- zval *_zval;
- char *str;
- long str_len, xa, ya, xb, yb = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlllls", &_zval, &xa, &ya, &xb, &yb, &str, &str_len) == FAILURE) {
- RETURN_FALSE;
- }
- caca_canvas_t *canvas;
- ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
- if (str_len != 1) {
- RETURN_FALSE;
- }
- RETURN_SUCCESS(caca_fill_box(canvas, xa, ya, xb, yb, str[0]));
- }
-
- PHP_FUNCTION(caca_draw_triangle) {
- zval *_zval;
- char *str;
- long str_len, xa, ya, xb, yb, xc, yc = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlllllls", &_zval, &xa, &ya, &xb, &yb, &xc, &yc, &str, &str_len) == FAILURE) {
- RETURN_FALSE;
- }
- caca_canvas_t *canvas;
- ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
- if (str_len != 1) {
- RETURN_FALSE;
- }
- RETURN_SUCCESS(caca_draw_triangle(canvas, xa, ya, xb, yb, xc, yc, str[0]));
- }
-
- PHP_FUNCTION(caca_draw_thin_triangle) {
- zval *_zval;
- long xa, ya, xb, yb, xc, yc = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllllll", &_zval, &xa, &ya, &xb, &yb, &xc, &yc) == FAILURE) {
- RETURN_FALSE;
- }
- caca_canvas_t *canvas;
- ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
- RETURN_SUCCESS(caca_draw_thin_triangle(canvas, xa, ya, xb, yb, xc, yc));
- }
-
- PHP_FUNCTION(caca_fill_triangle) {
- zval *_zval;
- char *str;
- long str_len, xa, ya, xb, yb, xc, yc = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rlllllls", &_zval, &xa, &ya, &xb, &yb, &xc, &yc, &str, &str_len) == FAILURE) {
- RETURN_FALSE;
- }
- caca_canvas_t *canvas;
- ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
- if (str_len != 1) {
- RETURN_FALSE;
- }
- RETURN_SUCCESS(caca_fill_triangle(canvas, xa, ya, xb, yb, xc, yc, str[0]));
- }
-
- PHP_FUNCTION(caca_get_frame_count) {
- zval *_zval;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) {
- RETURN_FALSE;
- }
- caca_canvas_t *canvas;
- ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
- RETURN_LONG(caca_get_canvas_count(canvas));
- }
-
- PHP_FUNCTION(caca_set_frame) {
- zval *_zval;
- long id;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &_zval, &id) == FAILURE) {
- RETURN_FALSE;
- }
- caca_canvas_t *canvas;
- ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
- RETURN_SUCCESS(caca_set_frame(canvas, id));
- }
-
- PHP_FUNCTION(caca_set_frame_name) {
- zval *_zval;
- char *str;
- long str_len;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &_zval, &str, &str_len) == FAILURE) {
- RETURN_FALSE;
- }
- caca_canvas_t *canvas;
- ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
- RETURN_SUCCESS(caca_set_frame_name(canvas, str));
- }
-
- PHP_FUNCTION(caca_create_frame) {
- zval *_zval;
- long id;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &_zval, &id) == FAILURE) {
- RETURN_FALSE;
- }
- caca_canvas_t *canvas;
- ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
- RETURN_SUCCESS(caca_create_frame(canvas, id));
- }
-
- PHP_FUNCTION(caca_free_frame) {
- zval *_zval;
- long id;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &_zval, &id) == FAILURE) {
- RETURN_FALSE;
- }
- caca_canvas_t *canvas;
- ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
- RETURN_SUCCESS(caca_free_frame(canvas, id));
- }
-
- PHP_FUNCTION(caca_create_dither) {
- long bpp, w, h, pitch, rmask, gmask, bmask, amask = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "llllllll", &bpp, &w, &h, &pitch, &rmask, &gmask, &bmask, &amask) == FAILURE) {
- RETURN_FALSE;
- }
- caca_dither_t *dither = caca_create_dither(bpp, w, h, pitch, rmask, gmask, bmask, amask);
- ZEND_REGISTER_RESOURCE(return_value, dither, le_caca_dither);
- }
-
- PHP_FUNCTION(caca_set_dither_palette) {
- }
-
- PHP_FUNCTION(caca_set_dither_brightness) {
- zval *_zval;
- double value;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rd", &_zval, &value) == FAILURE) {
- RETURN_FALSE;
- }
- caca_dither_t *dither;
- ZEND_FETCH_RESOURCE(dither, caca_dither_t*, &_zval, -1, PHP_CACA_DITHER_RES_NAME, le_caca_dither);
- RETURN_SUCCESS(caca_set_dither_brightness(dither, value));
- }
-
- PHP_FUNCTION(caca_get_dither_brightness) {
- zval *_zval;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) {
- RETURN_FALSE;
- }
- caca_dither_t *dither;
- ZEND_FETCH_RESOURCE(dither, caca_dither_t*, &_zval, -1, PHP_CACA_DITHER_RES_NAME, le_caca_dither);
- RETURN_DOUBLE(caca_get_dither_brightness(dither));
- }
-
- PHP_FUNCTION(caca_set_dither_gamma) {
- zval *_zval;
- double value;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rd", &_zval, &value) == FAILURE) {
- RETURN_FALSE;
- }
- caca_dither_t *dither;
- ZEND_FETCH_RESOURCE(dither, caca_dither_t*, &_zval, -1, PHP_CACA_DITHER_RES_NAME, le_caca_dither);
- RETURN_SUCCESS(caca_set_dither_gamma(dither, value));
- }
-
- PHP_FUNCTION(caca_get_dither_gamma) {
- zval *_zval;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) {
- RETURN_FALSE;
- }
- caca_dither_t *dither;
- ZEND_FETCH_RESOURCE(dither, caca_dither_t*, &_zval, -1, PHP_CACA_DITHER_RES_NAME, le_caca_dither);
- RETURN_DOUBLE(caca_get_dither_gamma(dither));
- }
-
- PHP_FUNCTION(caca_set_dither_contrast) {
- zval *_zval;
- double value;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rd", &_zval, &value) == FAILURE) {
- RETURN_FALSE;
- }
- caca_dither_t *dither;
- ZEND_FETCH_RESOURCE(dither, caca_dither_t*, &_zval, -1, PHP_CACA_DITHER_RES_NAME, le_caca_dither);
- RETURN_SUCCESS(caca_set_dither_contrast(dither, value));
- }
-
- PHP_FUNCTION(caca_get_dither_contrast) {
- zval *_zval;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) {
- RETURN_FALSE;
- }
- caca_dither_t *dither;
- ZEND_FETCH_RESOURCE(dither, caca_dither_t*, &_zval, -1, PHP_CACA_DITHER_RES_NAME, le_caca_dither);
- RETURN_DOUBLE(caca_get_dither_contrast(dither));
- }
-
- PHP_FUNCTION(caca_set_dither_antialias) {
- zval *_zval;
- int str_len;
- char *str;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &_zval, &str, &str_len) == FAILURE) {
- RETURN_FALSE;
- }
- caca_dither_t *dither;
- ZEND_FETCH_RESOURCE(dither, caca_dither_t*, &_zval, -1, PHP_CACA_DITHER_RES_NAME, le_caca_dither);
- RETURN_SUCCESS(caca_set_dither_antialias(dither, str));
- }
-
- PHP_FUNCTION(caca_get_dither_antialias_list) {
- }
-
- PHP_FUNCTION(caca_get_dither_antialias) {
- zval *_zval;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) {
- RETURN_FALSE;
- }
- caca_dither_t *dither;
- ZEND_FETCH_RESOURCE(dither, caca_dither_t*, &_zval, -1, PHP_CACA_DITHER_RES_NAME, le_caca_dither);
- RETURN_STRING((char *) caca_get_dither_antialias(dither), 1);
- }
-
- PHP_FUNCTION(caca_set_dither_color) {
- zval *_zval;
- int str_len;
- char *str;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &_zval, &str, &str_len) == FAILURE) {
- RETURN_FALSE;
- }
- caca_dither_t *dither;
- ZEND_FETCH_RESOURCE(dither, caca_dither_t*, &_zval, -1, PHP_CACA_DITHER_RES_NAME, le_caca_dither);
- RETURN_SUCCESS(caca_set_dither_color(dither, str));
- }
-
- PHP_FUNCTION(caca_get_dither_color_list) {
- zval *_zval;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) {
- RETURN_FALSE;
- }
- caca_dither_t *dither;
- ZEND_FETCH_RESOURCE(dither, caca_dither_t*, &_zval, -1, PHP_CACA_DITHER_RES_NAME, le_caca_dither);
-
- char const * const *list = caca_get_dither_antialias_list(dither);
- int i;
- array_init(return_value);
- for(i = 0; list[i]; i += 2)
- add_assoc_string(return_value, (char*) list[i], (char*) list[i + 1], 1);
- }
-
- PHP_FUNCTION(caca_get_dither_color) {
- zval *_zval;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) {
- RETURN_FALSE;
- }
- caca_dither_t *dither;
- ZEND_FETCH_RESOURCE(dither, caca_dither_t*, &_zval, -1, PHP_CACA_DITHER_RES_NAME, le_caca_dither);
- RETURN_STRING((char *) caca_get_dither_color(dither), 1);
- }
-
- PHP_FUNCTION(caca_set_dither_charset) {
- zval *_zval;
- int str_len;
- char *str;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &_zval, &str, &str_len) == FAILURE) {
- RETURN_FALSE;
- }
- caca_dither_t *dither;
- ZEND_FETCH_RESOURCE(dither, caca_dither_t*, &_zval, -1, PHP_CACA_DITHER_RES_NAME, le_caca_dither);
- RETURN_SUCCESS(caca_set_dither_charset(dither, str));
- }
-
- PHP_FUNCTION(caca_get_dither_charset_list) {
- zval *_zval;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) {
- RETURN_FALSE;
- }
- caca_dither_t *dither;
- ZEND_FETCH_RESOURCE(dither, caca_dither_t*, &_zval, -1, PHP_CACA_DITHER_RES_NAME, le_caca_dither);
-
- char const * const *list = caca_get_dither_charset_list(dither);
- int i;
- array_init(return_value);
- for(i = 0; list[i]; i += 2)
- add_assoc_string(return_value, (char*) list[i], (char*) list[i + 1], 1);
- }
-
- PHP_FUNCTION(caca_get_dither_charset) {
- zval *_zval;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) {
- RETURN_FALSE;
- }
- caca_dither_t *dither;
- ZEND_FETCH_RESOURCE(dither, caca_dither_t*, &_zval, -1, PHP_CACA_DITHER_RES_NAME, le_caca_dither);
- RETURN_STRING((char *) caca_get_dither_charset(dither), 1);
- }
-
- PHP_FUNCTION(caca_set_dither_algorithm) {
- zval *_zval;
- int str_len;
- char *str;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &_zval, &str, &str_len) == FAILURE) {
- RETURN_FALSE;
- }
- caca_dither_t *dither;
- ZEND_FETCH_RESOURCE(dither, caca_dither_t*, &_zval, -1, PHP_CACA_DITHER_RES_NAME, le_caca_dither);
- RETURN_SUCCESS(caca_set_dither_algorithm(dither, str));
- }
-
- PHP_FUNCTION(caca_get_dither_algorithm_list) {
- zval *_zval;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) {
- RETURN_FALSE;
- }
- caca_dither_t *dither;
- ZEND_FETCH_RESOURCE(dither, caca_dither_t*, &_zval, -1, PHP_CACA_DITHER_RES_NAME, le_caca_dither);
-
- char const * const *list = caca_get_dither_algorithm_list(dither);
- int i;
- array_init(return_value);
- for(i = 0; list[i]; i += 2)
- add_assoc_string(return_value, (char*) list[i], (char*) list[i + 1], 1);
- }
-
- PHP_FUNCTION(caca_get_dither_algorithm) {
- zval *_zval;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) {
- RETURN_FALSE;
- }
- caca_dither_t *dither;
- ZEND_FETCH_RESOURCE(dither, caca_dither_t*, &_zval, -1, PHP_CACA_DITHER_RES_NAME, le_caca_dither);
- RETURN_STRING((char *) caca_get_dither_algorithm(dither), 1);
- }
-
- PHP_FUNCTION(caca_dither_bitmap_gd) {
- zval *_zval1, *_zval2, *_zval3;
- long x, y, w, h = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rllllrr", &_zval1, &x, &y, &w, &h, &_zval2, &_zval3) == FAILURE) {
- RETURN_FALSE;
- }
-
- caca_canvas_t *canvas;
- ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval1, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
- caca_dither_t *dither;
- ZEND_FETCH_RESOURCE(dither, caca_dither_t*, &_zval2, -1, PHP_CACA_DITHER_RES_NAME, le_caca_dither);
-
- gdImage *img = fetch_external_resource(_zval3, "gd");
- if (!img) {
- RETURN_FALSE;
- }
-
- printf("image size: %i x %i\n", img->sx, img->sy);
- if (img->trueColor) {
- printf("image is true color\n");
- RETURN_SUCCESS(caca_dither_bitmap(canvas, x, y, w, h, dither, (void *) *(img->tpixels)));
- }
- }
-
- PHP_FUNCTION(caca_get_font_list) {
- char const * const *list = caca_get_font_list();
- int i;
- array_init(return_value);
- for(i = 0; list[i]; i += 1)
- add_next_index_string(return_value, (char*) list[i], 1);
- }
-
- PHP_FUNCTION(caca_get_font_width) {
- zval *_zval;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) {
- RETURN_FALSE;
- }
- caca_font_t *font;
- ZEND_FETCH_RESOURCE(font, caca_font_t*, &_zval, -1, PHP_CACA_FONT_RES_NAME, le_caca_font);
- RETURN_LONG(caca_get_font_width(font));
- }
-
- PHP_FUNCTION(caca_get_font_height) {
- zval *_zval;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) {
- RETURN_FALSE;
- }
- caca_font_t *font;
- ZEND_FETCH_RESOURCE(font, caca_font_t*, &_zval, -1, PHP_CACA_FONT_RES_NAME, le_caca_font);
- RETURN_LONG(caca_get_font_height(font));
- }
-
- PHP_FUNCTION(caca_render_canvas) {
- }
-
- PHP_FUNCTION(caca_canvas_set_figfont) {
- }
-
- PHP_FUNCTION(caca_put_figchar) {
- }
-
- PHP_FUNCTION(caca_flush_figlet) {
- }
-
- PHP_FUNCTION(caca_file_close) {
- }
-
- PHP_FUNCTION(caca_file_tell) {
- }
-
- PHP_FUNCTION(caca_file_read) {
- }
-
- PHP_FUNCTION(caca_file_write) {
- }
-
- PHP_FUNCTION(caca_file_gets) {
- }
-
- PHP_FUNCTION(caca_file_eof) {
- }
-
- PHP_FUNCTION(caca_import_string) {
- zval *_zval;
- char *src, *type;
- long src_len, type_len = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rss", &_zval, &src, &src_len, &type, &type_len) == FAILURE) {
- RETURN_FALSE;
- }
- caca_canvas_t *canvas;
- ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
-
- RETURN_LONG(caca_import_memory(canvas, src, src_len, type));
- }
-
- PHP_FUNCTION(caca_import_file) {
- }
-
- PHP_FUNCTION(caca_get_import_list) {
- }
-
- PHP_FUNCTION(caca_export_string) {
- zval *_zval;
- char *type;
- long type_len;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &_zval, &type, &type_len) == FAILURE) {
- RETURN_FALSE;
- }
- caca_canvas_t *canvas;
- ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
-
- void *buffer;
- size_t len;
- buffer = caca_export_memory(canvas, type, &len);
- if (!buffer) {
- RETURN_FALSE;
- }
- return_value->type = IS_STRING;
- return_value->value.str.len = len;
- return_value->value.str.val = emalloc(len);
- memcpy(return_value->value.str.val, buffer, len);
- free(buffer);
- }
-
- PHP_FUNCTION(caca_get_export_list) {
- char const * const *list = caca_get_export_list();
- int i;
- array_init(return_value);
- for(i = 0; list[i]; i += 2)
- add_assoc_string(return_value, (char*) list[i], (char*) list[i + 1], 1);
- }
-
- PHP_FUNCTION(caca_create_display) {
- caca_canvas_t *canvas;
- FETCH_CANVAS(canvas);
-
- caca_display_t *display = caca_create_display(canvas);
- ZEND_REGISTER_RESOURCE(return_value, display, le_caca_display);
- }
-
- PHP_FUNCTION(caca_create_display_with_driver) {
- zval *_zval;
- char *str;
- long str_len = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &_zval, &str, &str_len) == FAILURE) {
- RETURN_FALSE;
- }
- caca_canvas_t *canvas;
- ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas);
-
- caca_display_t *display = caca_create_display_with_driver(canvas, str);
- if (!display) {
- RETURN_FALSE;
- }
- ZEND_REGISTER_RESOURCE(return_value, display, le_caca_display);
- }
-
- PHP_FUNCTION(caca_get_display_driver_list) {
- char const * const *list = caca_get_display_driver_list();
- int i;
- array_init(return_value);
- for(i = 0; list[i]; i += 2)
- add_assoc_string(return_value, (char*) list[i], (char*) list[i + 1], 1);
- }
-
- PHP_FUNCTION(caca_get_display_driver) {
- zval *_zval;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) {
- RETURN_FALSE;
- }
- caca_display_t *display;
- ZEND_FETCH_RESOURCE(display, caca_display_t*, &_zval, -1, PHP_CACA_DISPLAY_RES_NAME, le_caca_display);
- RETURN_STRING((char *) caca_get_display_driver(display), 1);
- }
-
- PHP_FUNCTION(caca_set_display_driver) {
- zval *_zval;
- char *str;
- long str_len;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &_zval, &str, &str_len) == FAILURE) {
- RETURN_FALSE;
- }
- caca_display_t *display;
- ZEND_FETCH_RESOURCE(display, caca_display_t*, &_zval, -1, PHP_CACA_DISPLAY_RES_NAME, le_caca_display);
- RETURN_SUCESS(caca_set_display_driver(display, str));
- }
-
- PHP_FUNCTION(caca_get_canvas) {
- zval *_zval;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "r", &_zval) == FAILURE) {
- RETURN_FALSE;
- }
- caca_display_t *display;
- ZEND_FETCH_RESOURCE(display, caca_display_t*, &_zval, -1, PHP_CACA_DISPLAY_RES_NAME, le_caca_display);
- caca_canvas_t *canvas = caca_get_canvas(display);
- ZEND_REGISTER_RESOURCE(return_value, canvas, le_caca_canvas);
- }
-
- PHP_FUNCTION(caca_refresh_display) {
- caca_display_t *display;
- FETCH_DISPLAY(display);
- RETURN_SUCCESS(caca_refresh_display(display));
- }
-
- PHP_FUNCTION(caca_set_display_time) {
- zval *_zval;
- long value = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &_zval, &value) == FAILURE) {
- RETURN_FALSE;
- }
- caca_display_t *display;
- ZEND_FETCH_RESOURCE(display, caca_display_t*, &_zval, -1, PHP_CACA_DISPLAY_RES_NAME, le_caca_display);
- RETURN_SUCCESS(caca_set_display_time(display, value));
- }
-
- PHP_FUNCTION(caca_get_display_time) {
- caca_display_t *display;
- FETCH_DISPLAY(display);
- RETURN_LONG(caca_get_display_time(display)); //TODO: check return value
- }
-
- PHP_FUNCTION(caca_get_display_width) {
- caca_display_t *display;
- FETCH_DISPLAY(display);
- RETURN_LONG(caca_get_display_width(display));
- }
-
- PHP_FUNCTION(caca_get_display_height) {
- caca_display_t *display;
- FETCH_DISPLAY(display);
- RETURN_LONG(caca_get_display_height(display));
- }
-
- PHP_FUNCTION(caca_set_display_title) {
- zval *_zval;
- char *str;
- long str_len = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rs", &_zval, &str, &str_len) == FAILURE) {
- RETURN_FALSE;
- }
- caca_display_t *display;
- ZEND_FETCH_RESOURCE(display, caca_display_t*, &_zval, -1, PHP_CACA_DISPLAY_RES_NAME, le_caca_display);
- RETURN_SUCCESS(caca_set_display(display, str));
- }
-
- PHP_FUNCTION(caca_set_mouse) {
- zval *_zval;
- long value = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &_zval, &value) == FAILURE) {
- RETURN_FALSE;
- }
- caca_display_t *display;
- ZEND_FETCH_RESOURCE(display, caca_display_t*, &_zval, -1, PHP_CACA_DISPLAY_RES_NAME, le_caca_display);
- RETURN_SUCCESS(caca_set_mouse(display, value));
- }
-
- PHP_FUNCTION(caca_set_cursor) {
- zval *_zval;
- long value = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl", &_zval, &value) == FAILURE) {
- RETURN_FALSE;
- }
- caca_display_t *display;
- ZEND_FETCH_RESOURCE(display, caca_display_t*, &_zval, -1, PHP_CACA_DISPLAY_RES_NAME, le_caca_display);
- RETURN_SUCCESS(caca_set_cursor(display, value));
- }
-
- PHP_FUNCTION(caca_get_event) {
- zval *_zval1, *_zval2 = NULL;
- long g, aa = 0;
- if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "rl|rl", &_zval1, &g, &_zval2, &aa) == FAILURE) {
- RETURN_FALSE;
- }
- caca_display_t *display;
- ZEND_FETCH_RESOURCE(display, caca_display_t*, &_zval1, -1, PHP_CACA_DISPLAY_RES_NAME, le_caca_display);
-
- caca_event_t *event = NULL;
- if (_zval2) {
- ZEND_FETCH_RESOURCE(event, caca_event_t*, &_zval2, -1, PHP_CACA_EVENT_RES_NAME, le_caca_event);
- }
- RETURN_LONG(caca_get_event(display, g, event, aa));
- }
-
- PHP_FUNCTION(caca_get_mouse_x) {
- caca_display_t *display;
- FETCH_DISPLAY(display);
- RETURN_LONG(caca_get_mouse_x(display));
- }
-
- PHP_FUNCTION(caca_get_mouse_y) {
- caca_display_t *display;
- FETCH_DISPLAY(display);
- RETURN_LONG(caca_get_mouse_y(display));
- }
-
- PHP_FUNCTION(caca_get_event_type) {
- caca_event_t *event;
- FETCH_EVENT(event);
- RETURN_LONG(caca_get_event_type(event));
- }
-
- PHP_FUNCTION(caca_get_event_key_ch) {
- caca_event_t *event;
- FETCH_EVENT(event);
- RETURN_LONG(caca_get_event_key_ch(event));
- }
-
- PHP_FUNCTION(caca_get_event_mouse_button) {
- caca_event_t *event;
- FETCH_EVENT(event);
- RETURN_LONG(caca_get_event_mouse_button(event));
- }
-
- PHP_FUNCTION(caca_get_event_mouse_x) {
- caca_event_t *event;
- FETCH_EVENT(event);
- RETURN_LONG(caca_get_event_mouse_x(event));
- }
-
- PHP_FUNCTION(caca_get_event_mouse_y) {
- caca_event_t *event;
- FETCH_EVENT(event);
- RETURN_LONG(caca_get_event_mouse_y(event));
- }
-
- PHP_FUNCTION(caca_get_event_resize_width) {
- caca_event_t *event;
- FETCH_EVENT(event);
- RETURN_LONG(caca_get_event_resize_width(event));
- }
-
- PHP_FUNCTION(caca_get_event_resize_height) {
- caca_event_t *event;
- FETCH_EVENT(event);
- RETURN_LONG(caca_get_event_resize_height(event));
- }
-
|