Changeset 3131 for libcaca/trunk/caca-php/php_caca.c
- Timestamp:
- Oct 28, 2008, 6:59:41 PM (15 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
libcaca/trunk/caca-php/php_caca.c
r3129 r3131 376 376 //------- PHP Binding's specific functions ----------// 377 377 378 //TODO: register new resources in caca_get_event and remove caca_create_event 378 379 PHP_FUNCTION(caca_create_event) { 379 380 caca_event_t *event; … … 425 426 caca_canvas_t *canvas; 426 427 FETCH_CANVAS(canvas); 427 RETURN_STRING((char *) caca_get_canvas_chars(canvas), 1); //TODO: check that return \0 terminated string 428 RETURN_STRING((char *) caca_get_canvas_chars(canvas), 1); 429 //TODO: check that return \0 terminated string 428 430 } 429 431 … … 431 433 caca_canvas_t *canvas; 432 434 FETCH_CANVAS(canvas); 433 RETURN_STRING((char *) caca_get_canvas_attrs(canvas), 1); //TODO: check that return \0 terminated string 435 RETURN_STRING((char *) caca_get_canvas_attrs(canvas), 1); 436 //TODO: check that return \0 terminated string 434 437 } 435 438 … … 732 735 733 736 PHP_FUNCTION(caca_draw_polyline) { 737 zval *zval_res, *zval_arr; 738 char *c; 739 long c_len; 740 741 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ras", &zval_res, &zval_arr, &c, &c_len) == FAILURE) { 742 RETURN_FALSE; 743 } 744 745 if (c_len != 1) { 746 RETURN_FALSE; 747 } 748 749 caca_canvas_t *canvas; 750 ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &zval_res, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas); 751 752 HashTable *arr_hash = Z_ARRVAL_P(zval_arr); 753 int lenmax = zend_hash_num_elements(arr_hash); 754 int *tbl_x, *tbl_y; 755 int tbl_count = 0; 756 tbl_x = malloc(sizeof(int) * lenmax); 757 tbl_y = malloc(sizeof(int) * lenmax); 758 759 HashPosition pos; 760 zval **pt, **x, **y; 761 for ( 762 zend_hash_internal_pointer_reset_ex(arr_hash, &pos); 763 zend_hash_get_current_data_ex(arr_hash, (void**) &pt, &pos) == SUCCESS; 764 zend_hash_move_forward_ex(arr_hash, &pos) 765 ) { 766 if ( 767 Z_TYPE_P(*pt) == IS_ARRAY 768 && (zend_hash_index_find(Z_ARRVAL_P(*pt), 0, (void**) &x) != FAILURE) 769 && (zend_hash_index_find(Z_ARRVAL_P(*pt), 1, (void**) &y) != FAILURE) 770 ) { 771 convert_to_long_ex(x); 772 convert_to_long_ex(y); 773 tbl_x[tbl_count] = Z_LVAL_PP(x); 774 tbl_y[tbl_count] = Z_LVAL_PP(y); 775 tbl_count++; 776 } 777 } 778 int res = caca_draw_polyline(canvas, tbl_x, tbl_y, tbl_count - 1, c[0]); 779 free(tbl_x); 780 free(tbl_y); 781 RETURN_SUCCESS(res); 734 782 } 735 783 … … 746 794 747 795 PHP_FUNCTION(caca_draw_thin_polyline) { 796 zval *zval_res, *zval_arr; 797 if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "ra", &zval_res, &zval_arr) == FAILURE) { 798 RETURN_FALSE; 799 } 800 801 caca_canvas_t *canvas; 802 ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &zval_res, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas); 803 804 HashTable *arr_hash = Z_ARRVAL_P(zval_arr); 805 int lenmax = zend_hash_num_elements(arr_hash); 806 int *tbl_x, *tbl_y; 807 int tbl_count = 0; 808 tbl_x = malloc(sizeof(int) * lenmax); 809 tbl_y = malloc(sizeof(int) * lenmax); 810 811 HashPosition pos; 812 zval **pt, **x, **y; 813 for ( 814 zend_hash_internal_pointer_reset_ex(arr_hash, &pos); 815 zend_hash_get_current_data_ex(arr_hash, (void**) &pt, &pos) == SUCCESS; 816 zend_hash_move_forward_ex(arr_hash, &pos) 817 ) { 818 if ( 819 Z_TYPE_P(*pt) == IS_ARRAY 820 && (zend_hash_index_find(Z_ARRVAL_P(*pt), 0, (void**) &x) != FAILURE) 821 && (zend_hash_index_find(Z_ARRVAL_P(*pt), 1, (void**) &y) != FAILURE) 822 ) { 823 convert_to_long_ex(x); 824 convert_to_long_ex(y); 825 tbl_x[tbl_count] = Z_LVAL_PP(x); 826 tbl_y[tbl_count] = Z_LVAL_PP(y); 827 tbl_count++; 828 } 829 } 830 int res = caca_draw_thin_polyline(canvas, tbl_x, tbl_y, tbl_count - 1); 831 free(tbl_x); 832 free(tbl_y); 833 RETURN_SUCCESS(res); 748 834 } 749 835 … … 1282 1368 ZEND_FETCH_RESOURCE(canvas, caca_canvas_t*, &_zval, -1, PHP_CACA_CANVAS_RES_NAME, le_caca_canvas); 1283 1369 1284 //TODO: get a string instead of a long 1285 caca_put_figchar(canvas, c); 1370 RETURN_SUCCESS(caca_put_figchar(canvas, c)); 1286 1371 } 1287 1372
Note: See TracChangeset
for help on using the changeset viewer.