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). Index: php4/ext/standard/file.c diff -u php4/ext/standard/file.c:1.296 php4/ext/standard/file.c:1.297 --- php4/ext/standard/file.c:1.296 Tue Jan 21 09:53:17 2003 +++ php4/ext/standard/file.c Sun Feb 9 15:05:13 2003 @@ -21,7 +21,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: file.c,v 1.296 2003/01/21 14:53:17 iliaa Exp $ */ +/* $Id: file.c,v 1.297 2003/02/09 20:05:13 iliaa Exp $ */ /* Synced with php 3.0 revision 1.218 1999-06-16 [ssb] */ @@ -458,11 +458,13 @@ 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; php_stream *stream; /* Parse arguments */ - if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|b", - &filename, &filename_len, &use_include_path) == FAILURE) { + if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s|bbb", + &filename, &filename_len, &use_include_path, +&include_new_line, &skip_blank_lines) == FAILURE) { return; } @@ -488,19 +490,39 @@ if (stream->flags & PHP_STREAM_FLAG_EOL_MAC) { eol_marker = '\r'; } - - do { - p++; - parse_eol: - if (PG(magic_quotes_runtime)) { - /* s is in target_buf which is freed at the end of the function */ - slashed = php_addslashes(s, (p-s), &len, 0 TSRMLS_CC); - add_index_stringl(return_value, i++, slashed, len, 0); - } else { - add_index_stringl(return_value, i++, estrndup(s, p-s), p-s, 0); - } - s = p; - } while ((p = memchr(p, eol_marker, (e-p)))); + + /* for performance reasons the code is duplicated, so that the if +(include_new_line) + * will not need to be done for every single line in the file. + */ + if (include_new_line) { + do { + p++; + parse_eol: + if (PG(magic_quotes_runtime)) { + /* s is in target_buf which is freed at the +end of the function */ + slashed = php_addslashes(s, (p-s), &len, 0 +TSRMLS_CC); + add_index_stringl(return_value, i++, slashed, +len, 0); + } else { + add_index_stringl(return_value, i++, +estrndup(s, p-s), p-s, 0); + } + s = p; + } while ((p = memchr(p, eol_marker, (e-p)))); + } else { + do { + if (skip_blank_lines && !(p-s)) { + s = ++p; + continue; + } + if (PG(magic_quotes_runtime)) { + /* s is in target_buf which is freed at the +end of the function */ + slashed = php_addslashes(s, (p-s), &len, 0 +TSRMLS_CC); + add_index_stringl(return_value, i++, slashed, +len, 0); + } else { + add_index_stringl(return_value, i++, +estrndup(s, p-s), p-s, 0); + } + s = ++p; + } while ((p = memchr(p, eol_marker, (e-p)))); + } /* handle any left overs of files without new lines */ if (s != e) {
-- PHP CVS Mailing List (http://www.php.net/) To unsubscribe, visit: http://www.php.net/unsub.php