Re: [PHP-DEV] Re: [PHP-CVS] cvs: php4 /ext/standard file.c
On Mon, 10 Feb 2003, Markus Fischer wrote: On Sun, Feb 09, 2003 at 08:05:14PM -, Ilia Alshanetsky wrote : iliaa Sun Feb 9 15:05:14 2003 EDT Modified files: /php4/ext/standard file.c Log: Added feature request #14097 (option allowing file() command not to include line endings in it's output. As well as another option, which allows blank lines to be excluded from the output). Can we change this to not have two more optional parameters but re-use the existing one? We could turn the existing one into a flags parameter: 1 - use include path 2 - include new line 4 - skip_blank_lines This would not break BC and we don't need multiple optional parameters. +1 on that. Derick -- - Derick Rethans http://derickrethans.nl/ PHP Magazine - PHP Magazine for Professionals http://php-mag.net/ - -- PHP Development Mailing List http://www.php.net/ To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] Re: [PHP-CVS] cvs: php4 /ext/standard file.c
On Mon, 10 Feb 2003, Ilia A. wrote: We could turn the existing one into a flags parameter: 1 - use include path 2 - include new line 4 - skip_blank_lines This would not break BC and we don't need multiple optional parameters. Do we want to create constants for each option or simply accept integer values? constants please :) Derick -- - Derick Rethans http://derickrethans.nl/ PHP Magazine - PHP Magazine for Professionals http://php-mag.net/ - -- PHP Development Mailing List http://www.php.net/ To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] Re: [PHP-CVS] cvs: php4 /ext/standard file.c
Attached is the proposed solution. Ilia Index: ext/standard/file.c === RCS file: /repository/php4/ext/standard/file.c,v retrieving revision 1.299 diff -u -3 -p -r1.299 file.c --- ext/standard/file.c 9 Feb 2003 20:43:05 - 1.299 +++ ext/standard/file.c 10 Feb 2003 15:46:19 - @@ -180,6 +180,10 @@ PHP_MINIT_FUNCTION(file) REGISTER_LONG_CONSTANT(STREAM_NOTIFY_SEVERITY_INFO, PHP_STREAM_NOTIFY_SEVERITY_INFO, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT(STREAM_NOTIFY_SEVERITY_WARN, PHP_STREAM_NOTIFY_SEVERITY_WARN, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT(STREAM_NOTIFY_SEVERITY_ERR, PHP_STREAM_NOTIFY_SEVERITY_ERR, CONST_CS | CONST_PERSISTENT); + + REGISTER_LONG_CONSTANT(STREAM_USE_INCLUDE_PATH, 1, CONST_CS | +CONST_PERSISTENT); + REGISTER_LONG_CONSTANT(STREAM_IGNORE_NEW_LINES, 2, CONST_CS | +CONST_PERSISTENT); + REGISTER_LONG_CONSTANT(STREAM_SKIP_EMPTY_LINES, 4, CONST_CS | +CONST_PERSISTENT); #ifdef HAVE_FNMATCH REGISTER_LONG_CONSTANT(FNM_NOESCAPE, FNM_NOESCAPE, CONST_CS | CONST_PERSISTENT); @@ -444,7 +448,7 @@ PHP_FUNCTION(file_get_contents) } /* }}} */ -/* {{{ proto array file(string filename [, bool use_include_path [, bool include_new_line [, bool skip_blank_lines]]]) +/* {{{ proto array file(string filename [, int flags]) Read entire file into an array */ #define PHP_FILE_BUF_SIZE 80 @@ -457,20 +461,26 @@ PHP_FUNCTION(file) register int i = 0; int target_len, len; char eol_marker = '\n'; - zend_bool use_include_path = 0; - zend_bool include_new_line = 1; - zend_bool skip_blank_lines = 0; + long flags = 0; + zend_bool use_include_path; + zend_bool include_new_line; + zend_bool skip_blank_lines; php_stream *stream; /* Parse arguments */ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, s|bbb, - filename, filename_len, use_include_path, include_new_line, skip_blank_lines) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, s|l, filename, +filename_len, flags) == FAILURE) { return; } + if (flags 0 || flags 7) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, '%d' flag is not +supported., flags); + RETURN_FALSE; + } + + use_include_path = flags 1; + include_new_line = flags 2; + skip_blank_lines = flags 4; - stream = php_stream_open_wrapper(filename, rb, - (use_include_path ? USE_PATH : 0) | ENFORCE_SAFE_MODE | REPORT_ERRORS, - NULL); + stream = php_stream_open_wrapper(filename, rb, (use_include_path ? USE_PATH +: 0) | ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL); if (!stream) { RETURN_FALSE; } -- PHP Development Mailing List http://www.php.net/ To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] Re: [PHP-CVS] cvs: php4 /ext/standard file.c
Hey Ilia, Lets also have either an enum or some real #define'd constants for the values used in the C code. eg: REGISTER_LONG_CONSTANT() and the code that checks for a number should both be using a symbolic constant rather than a hard-coded number. --Wez. On Mon, 10 Feb 2003, Ilia A. wrote: Attached is the proposed solution. Ilia -- PHP Development Mailing List http://www.php.net/ To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] Re: [PHP-CVS] cvs: php4 /ext/standard file.c
Here is the final revision of the patch. Ilia Index: ext/standard/file.c === RCS file: /repository/php4/ext/standard/file.c,v retrieving revision 1.300 diff -u -3 -p -r1.300 file.c --- ext/standard/file.c 9 Feb 2003 23:11:23 - 1.300 +++ ext/standard/file.c 10 Feb 2003 20:39:47 - @@ -180,6 +180,10 @@ PHP_MINIT_FUNCTION(file) REGISTER_LONG_CONSTANT(STREAM_NOTIFY_SEVERITY_INFO, PHP_STREAM_NOTIFY_SEVERITY_INFO, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT(STREAM_NOTIFY_SEVERITY_WARN, PHP_STREAM_NOTIFY_SEVERITY_WARN, CONST_CS | CONST_PERSISTENT); REGISTER_LONG_CONSTANT(STREAM_NOTIFY_SEVERITY_ERR, PHP_STREAM_NOTIFY_SEVERITY_ERR, CONST_CS | CONST_PERSISTENT); + + REGISTER_LONG_CONSTANT(FILE_USE_INCLUDE_PATH, PHP_FILE_USE_INCLUDE_PATH, +CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT(FILE_IGNORE_NEW_LINES, PHP_FILE_IGNORE_NEW_LINES, +CONST_CS | CONST_PERSISTENT); + REGISTER_LONG_CONSTANT(FILE_SKIP_EMPTY_LINES, PHP_FILE_SKIP_EMPTY_LINES, +CONST_CS | CONST_PERSISTENT); #ifdef HAVE_FNMATCH REGISTER_LONG_CONSTANT(FNM_NOESCAPE, FNM_NOESCAPE, CONST_CS | CONST_PERSISTENT); @@ -444,7 +448,7 @@ PHP_FUNCTION(file_get_contents) } /* }}} */ -/* {{{ proto array file(string filename [, bool use_include_path [, bool include_new_line [, bool skip_blank_lines]]]) +/* {{{ proto array file(string filename [, int flags]) Read entire file into an array */ #define PHP_FILE_BUF_SIZE 80 @@ -457,20 +461,26 @@ PHP_FUNCTION(file) register int i = 0; int target_len, len; char eol_marker = '\n'; - zend_bool use_include_path = 0; - zend_bool include_new_line = 1; - zend_bool skip_blank_lines = 0; + long flags = 0; + zend_bool use_include_path; + zend_bool include_new_line; + zend_bool skip_blank_lines; php_stream *stream; /* Parse arguments */ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, s|bbb, - filename, filename_len, use_include_path, include_new_line, skip_blank_lines) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, s|l, filename, +filename_len, flags) == FAILURE) { return; } + if (flags 0 || flags 7) { + php_error_docref(NULL TSRMLS_CC, E_WARNING, '%d' flag is not +supported., flags); + RETURN_FALSE; + } + + use_include_path = flags PHP_FILE_USE_INCLUDE_PATH; + include_new_line = !(flags PHP_FILE_IGNORE_NEW_LINES); + skip_blank_lines = flags PHP_FILE_SKIP_EMPTY_LINES; - stream = php_stream_open_wrapper(filename, rb, - (use_include_path ? USE_PATH : 0) | ENFORCE_SAFE_MODE | REPORT_ERRORS, - NULL); + stream = php_stream_open_wrapper(filename, rb, (use_include_path ? USE_PATH +: 0) | ENFORCE_SAFE_MODE | REPORT_ERRORS, NULL); if (!stream) { RETURN_FALSE; } Index: ext/standard/file.h === RCS file: /repository/php4/ext/standard/file.h,v retrieving revision 1.74 diff -u -3 -p -r1.74 file.h --- ext/standard/file.h 9 Feb 2003 20:43:05 - 1.74 +++ ext/standard/file.h 10 Feb 2003 20:39:47 - @@ -87,6 +87,10 @@ PHPAPI int php_copy_file(char *src, char #define META_DEF_BUFSIZE 8192 +#define PHP_FILE_USE_INCLUDE_PATH 1 +#define PHP_FILE_IGNORE_NEW_LINES 2 +#define PHP_FILE_SKIP_EMPTY_LINES 4 + typedef enum _php_meta_tags_token { TOK_EOF = 0, TOK_OPENTAG, -- PHP Development Mailing List http://www.php.net/ To unsubscribe, visit: http://www.php.net/unsub.php
Re: [PHP-DEV] Re: [PHP-CVS] cvs: php4 /ext/standard file.c
On Fri, 18 May 2001, Andi Gutmans wrote: I was just about to do an automatic merge of this fix to the PHP_4_0_6 branch when I saw that the merge will also merge the stat() update which creates associative keys too (cvs update -j 1.159 file.c after an update -r PHP_4_0_6). Any objections to me merging that one too? I think it would be good to have it in 4.0.6. If people mind I can just merge this one by hand. You might want to wait for another bug-fix. If a client interrupts a download, PHPWRITE() won't return, so that we have no chance of unmapping the file. Can someone remind me whether RSHUTDOWN functions are called after php_handle_aborted_connection()? - Sascha Experience IRCG http://schumann.cx/http://schumann.cx/ircg -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DEV] Re: [PHP-CVS] cvs: php4 /ext/standard file.c
I am all for that, but don't forget filestat.c and the macro in php_filestat.h. Thanks, Jason - Original Message - From: Andi Gutmans [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Friday, May 18, 2001 3:08 PM Subject: [PHP-DEV] Re: [PHP-CVS] cvs: php4 /ext/standard file.c I was just about to do an automatic merge of this fix to the PHP_4_0_6 branch when I saw that the merge will also merge the stat() update which creates associative keys too (cvs update -j 1.159 file.c after an update -r PHP_4_0_6). Any objections to me merging that one too? I think it would be good to have it in 4.0.6. If people mind I can just merge this one by hand. Andi At 05:48 PM 5/18/2001 +, Sascha Schumann wrote: sas Fri May 18 10:48:43 2001 EDT Modified files: /php4/ext/standard file.c Log: Files should be shared among processes. Index: php4/ext/standard/file.c diff -u php4/ext/standard/file.c:1.158 php4/ext/standard/file.c:1.159 --- php4/ext/standard/file.c:1.158 Sat May 12 14:48:39 2001 +++ php4/ext/standard/file.cFri May 18 10:48:43 2001 @@ -21,7 +21,7 @@ +--+ */ -/* $Id: file.c,v 1.158 2001/05/12 21:48:39 wez Exp $ */ +/* $Id: file.c,v 1.159 2001/05/18 17:48:43 sas Exp $ */ /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */ @@ -1546,7 +1546,7 @@ if (sbuf.st_size sizeof(buf)) { off = ftell(fp); len = sbuf.st_size - off; - p = mmap(0, len, PROT_READ, MAP_PRIVATE, fd, off); + p = mmap(0, len, PROT_READ, MAP_SHARED, fd, off); if (p != (void *) MAP_FAILED) { PHPWRITE(p, len); munmap(p, len); -- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED] -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DEV] Re: [PHP-CVS] cvs: php4 /ext/standard file.c
At 05:00 PM 5/18/2001 -0500, Jason Greene wrote: I am all for that, but don't forget filestat.c and the macro in php_filestat.h. Hmm, that's making me think twice now. Maybe we should just merge Sascha's fixes. Andi -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: [PHP-DEV] Re: [PHP-CVS] cvs: php4 /ext/standard file.c
At 12:04 AM 5/19/2001 +0200, Sascha Schumann wrote: On Fri, 18 May 2001, Andi Gutmans wrote: I was just about to do an automatic merge of this fix to the PHP_4_0_6 branch when I saw that the merge will also merge the stat() update which creates associative keys too (cvs update -j 1.159 file.c after an update -r PHP_4_0_6). Any objections to me merging that one too? I think it would be good to have it in 4.0.6. If people mind I can just merge this one by hand. You might want to wait for another bug-fix. If a client interrupts a download, PHPWRITE() won't return, so that we have no chance of unmapping the file. Can someone remind me whether RSHUTDOWN functions are called after php_handle_aborted_connection()? Yeah. It's supposed to be called. Andi -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]
Re: Re: [PHP-DEV] Re: [PHP-CVS] cvs: php4 /ext/standard file.c
I agree, though it would be nice to release this soon, however, it is not worth risking the RP. -Jason From: Andi Gutmans [EMAIL PROTECTED] Date: 2001/05/18 Fri PM 06:26:49 CDT To: Jason Greene [EMAIL PROTECTED],[EMAIL PROTECTED] Subject: Re: [PHP-DEV] Re: [PHP-CVS] cvs: php4 /ext/standard file.c At 05:00 PM 5/18/2001 -0500, Jason Greene wrote: I am all for that, but don't forget filestat.c and the macro in php_filestat.h. Hmm, that's making me think twice now. Maybe we should just merge Sascha's fixes. Andi -- PHP Development Mailing List http://www.php.net/ To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] To contact the list administrators, e-mail: [EMAIL PROTECTED]