cvs: php4 /ext/swf php_swf.h swf.c

From: Date: Tue, 15 Aug 2000 17:30:42 +0000
Subject: cvs: php4 /ext/swf php_swf.h swf.c
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-1192@lists.php.net to get a copy of this message
sterling Tue Aug 15 10:30:42 2000 EDT Modified files: /php4/ext/swf php_swf.h swf.c Log: @ Fix stdout support with the swf extension. (Sterling) Index: php4/ext/swf/php_swf.h diff -u php4/ext/swf/php_swf.h:1.8 php4/ext/swf/php_swf.h:1.9 --- php4/ext/swf/php_swf.h:1.8 Sun Jul 2 16:46:48 2000 +++ php4/ext/swf/php_swf.h Tue Aug 15 10:30:41 2000 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: php_swf.h,v 1.8 2000/07/02 23:46:48 sas Exp $ */ +/* $Id: php_swf.h,v 1.9 2000/08/15 17:30:41 sterling Exp $ */ #ifndef PHP_SWF_H #define PHP_SWF_H @@ -28,6 +28,7 @@ PHP_MINIT_FUNCTION(swf); PHP_MINFO_FUNCTION(swf); +PHP_RINIT_FUNCTION(swf); extern void php_swf_define(INTERNAL_FUNCTION_PARAMETERS, int opt); extern void php_swf_fill_bitmap(INTERNAL_FUNCTION_PARAMETERS, int opt); extern void php_swf_geo_same(INTERNAL_FUNCTION_PARAMETERS, int opt); @@ -98,6 +99,19 @@ PHP_FUNCTION(swf_translate); PHP_FUNCTION(swf_rotate); PHP_FUNCTION(swf_posround); + +typedef struct { + int use_file; + char *tmpfile_name; +} php_swf_globals; + +#ifdef ZTS +#define SWFG(v) (swf_globals->v) +#define SWFLS_FETCH() php_swf_globals *swf_globals = ts_resource(gd_swf_id) +#else +#define SWFG(v) (swf_globals.v) +#define SWFLS_FETCH() +#endif #else #define swf_module_ptr NULL Index: php4/ext/swf/swf.c diff -u php4/ext/swf/swf.c:1.20 php4/ext/swf/swf.c:1.21 --- php4/ext/swf/swf.c:1.20 Mon Jul 17 22:52:03 2000 +++ php4/ext/swf/swf.c Tue Aug 15 10:30:41 2000 @@ -16,7 +16,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: swf.c,v 1.20 2000/07/18 05:52:03 sterling Exp $ */ +/* $Id: swf.c,v 1.21 2000/08/15 17:30:41 sterling Exp $ */ #include "php.h" @@ -27,6 +27,13 @@ #include "ext/standard/info.h" #include "php_swf.h" +#ifdef ZTS +int swf_globals_id; +#else +php_swf_globals swf_globals; +#endif + + function_entry swf_functions[] = { PHP_FE(swf_openfile, NULL) PHP_FE(swf_closefile, NULL) @@ -103,8 +110,8 @@ swf_functions, PHP_MINIT(swf), NULL, + PHP_RINIT(swf), NULL, - NULL, PHP_MINFO(swf), STANDARD_MODULE_PROPERTIES }; @@ -145,15 +152,20 @@ REGISTER_LONG_CONSTANT("MenuExit", MenuExit, CONST_CS | CONST_PERSISTENT); return SUCCESS; } - +PHP_RINIT_FUNCTION(swf) +{ + SWFG(use_file) = 0; +} /* {{{ proto void swf_openfile(string name, double xsize, double ysize, double framerate, double r, double g, double b) Create a Shockwave Flash file given by name, with width xsize and height ysize at a frame rate of framerate and a background color specified by a red value of r, green value of g and a blue value of b */ PHP_FUNCTION(swf_openfile) { zval **name, **sizeX, **sizeY, **frameRate, **r, **g, **b; - char *na; + char *na, *tmpna; + SWFLS_FETCH(); + if (ZEND_NUM_ARGS() != 7 || zend_get_parameters_ex(7, &name, &sizeX, &sizeY, &frameRate, &r, &g, &b) == FAILURE) { WRONG_PARAM_COUNT; @@ -166,18 +178,31 @@ convert_to_double_ex(r); convert_to_double_ex(g); convert_to_double_ex(b); + + + tmpna = Z_STRVAL_PP(name); + + if (strcasecmp("php://stdout", tmpna) == 0) { + na = tempnam(NULL, "php_swf_stdout"); + unlink((const char *)na); - na = Z_STRVAL_PP(name); + SWFG(use_file) = 0; + } else { + na = tmpna; + SWFG(use_file) = 1; + } #ifdef VIRTUAL_DIR if (virtual_filepath(na, &na)) { return; } #endif - - swf_openfile((strcasecmp("php://stdout", na)==0) ? "STDOUT" : na, - (float)Z_DVAL_PP(sizeX), (float)Z_DVAL_PP(sizeY), - (float)Z_DVAL_PP(frameRate), (float)Z_DVAL_PP(r), (float)Z_DVAL_PP(g), (float)Z_DVAL_PP(b)); + if (!SWFG(use_file)) + SWFG(tmpfile_name) = na; + + swf_openfile(na,(float)Z_DVAL_PP(sizeX), (float)Z_DVAL_PP(sizeY), + (float)Z_DVAL_PP(frameRate), (float)Z_DVAL_PP(r), + (float)Z_DVAL_PP(g), (float)Z_DVAL_PP(b)); #ifdef VIRTUAL_DIR free(na); #endif @@ -188,7 +213,27 @@ Close a Shockwave flash file that was opened with swf_openfile */ PHP_FUNCTION(swf_closefile) { + SWFLS_FETCH(); + swf_closefile(); + + if (!SWFG(use_file)) { + FILE *f; + char buf[4096]; + int b; + + if ((f = fopen(SWFG(tmpfile_name), "r")) == NULL) { + php_error(E_WARNING, "Cannot create temporary file for stdout support with SWF"); + RETURN_NULL(); + } + + while ((b = fread(buf, 1, sizeof(buf), f)) > 0) + php_write(buf, b); + + fclose(f); + + unlink((const char *)SWFG(tmpfile_name)); + } } /* }}} */

« previous php.cvs (#1192) next »