[PHP-CVS] cvs: php-src /ext/spl spl_directory.c spl_directory.h

2009-07-07 Thread Ilia Alshanetsky
iliaa   Wed Jul  8 03:09:59 2009 UTC

  Modified files:  
/php-src/ext/splspl_directory.c spl_directory.h 
  Log:
  
  MFB: Fixed bug #48788 (RecursiveDirectoryIterator doesn't descend into
  symlinked
  directories). 
  
http://cvs.php.net/viewvc.cgi/php-src/ext/spl/spl_directory.c?r1=1.185r2=1.186diff_format=u
Index: php-src/ext/spl/spl_directory.c
diff -u php-src/ext/spl/spl_directory.c:1.185 
php-src/ext/spl/spl_directory.c:1.186
--- php-src/ext/spl/spl_directory.c:1.185   Sat Jul  4 20:28:15 2009
+++ php-src/ext/spl/spl_directory.c Wed Jul  8 03:09:58 2009
@@ -16,7 +16,7 @@
+--+
  */
 
-/* $Id: spl_directory.c,v 1.185 2009/07/04 20:28:15 felipe Exp $ */
+/* $Id: spl_directory.c,v 1.186 2009/07/08 03:09:58 iliaa Exp $ */
 
 #ifdef HAVE_CONFIG_H
 # include config.h
@@ -1364,7 +1364,7 @@
return;
}
spl_filesystem_object_get_file_name(intern TSRMLS_CC);
-   if (!allow_links) {
+   if (!allow_links  !(intern-flags  
SPL_FILE_DIR_FOLLOW_SYMLINKS)) {
php_u_stat(intern-file_name_type, intern-file_name, 
intern-file_name_len, FS_IS_LINK, FG(default_context), return_value TSRMLS_CC);
if (zend_is_true(return_value)) {
RETURN_FALSE;
@@ -2787,6 +2787,7 @@
REGISTER_SPL_CLASS_CONST_LONG(FilesystemIterator, CURRENT_AS_SELF,
 SPL_FILE_DIR_CURRENT_AS_SELF);
REGISTER_SPL_CLASS_CONST_LONG(FilesystemIterator, KEY_MODE_MASK,  
 SPL_FILE_DIR_KEY_MODE_MASK);
REGISTER_SPL_CLASS_CONST_LONG(FilesystemIterator, KEY_AS_PATHNAME,
 SPL_FILE_DIR_KEY_AS_PATHNAME);
+   REGISTER_SPL_CLASS_CONST_LONG(FilesystemIterator, FOLLOW_SYMLINKS,
 SPL_FILE_DIR_FOLLOW_SYMLINKS);
REGISTER_SPL_CLASS_CONST_LONG(FilesystemIterator, KEY_AS_FILENAME,
 SPL_FILE_DIR_KEY_AS_FILENAME);
REGISTER_SPL_CLASS_CONST_LONG(FilesystemIterator, 
NEW_CURRENT_AND_KEY, 
SPL_FILE_DIR_KEY_AS_FILENAME|SPL_FILE_DIR_CURRENT_AS_FILEINFO);
REGISTER_SPL_CLASS_CONST_LONG(FilesystemIterator, SKIP_DOTS,  
 SPL_FILE_DIR_SKIPDOTS);
http://cvs.php.net/viewvc.cgi/php-src/ext/spl/spl_directory.h?r1=1.49r2=1.50diff_format=u
Index: php-src/ext/spl/spl_directory.h
diff -u php-src/ext/spl/spl_directory.h:1.49 
php-src/ext/spl/spl_directory.h:1.50
--- php-src/ext/spl/spl_directory.h:1.49Thu Jun  4 14:46:08 2009
+++ php-src/ext/spl/spl_directory.h Wed Jul  8 03:09:58 2009
@@ -16,7 +16,7 @@
+--+
  */
 
-/* $Id: spl_directory.h,v 1.49 2009/06/04 14:46:08 colder Exp $ */
+/* $Id: spl_directory.h,v 1.50 2009/07/08 03:09:58 iliaa Exp $ */
 
 #ifndef SPL_DIRECTORY_H
 #define SPL_DIRECTORY_H
@@ -131,6 +131,7 @@
 
 #define SPL_FILE_DIR_KEY_AS_PATHNAME   0x /* make 
RecursiveDirectoryTree::key() return getPathname() */
 #define SPL_FILE_DIR_KEY_AS_FILENAME   0x0100 /* make 
RecursiveDirectoryTree::key() return getFilename() */
+#define SPL_FILE_DIR_FOLLOW_SYMLINKS   0x0200 /* make 
RecursiveDirectoryTree::hasChildren() follow symlinks */
 #define SPL_FILE_DIR_KEY_MODE_MASK 0x0F00 /* mask 
RecursiveDirectoryTree::key() */
 #define SPL_FILE_DIR_KEY(intern,mode)  
((intern-flagsSPL_FILE_DIR_KEY_MODE_MASK)==mode)
 



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-CVS] cvs: php-src /ext/spl spl_directory.c spl_directory.h

2009-06-04 Thread Etienne Kneuss
colder  Thu Jun  4 14:46:08 2009 UTC

  Modified files:  
/php-src/ext/splspl_directory.c spl_directory.h 
  Log:
  Include other flags as well
  
http://cvs.php.net/viewvc.cgi/php-src/ext/spl/spl_directory.c?r1=1.182r2=1.183diff_format=u
Index: php-src/ext/spl/spl_directory.c
diff -u php-src/ext/spl/spl_directory.c:1.182 
php-src/ext/spl/spl_directory.c:1.183
--- php-src/ext/spl/spl_directory.c:1.182   Mon May 25 14:32:14 2009
+++ php-src/ext/spl/spl_directory.c Thu Jun  4 14:46:08 2009
@@ -16,7 +16,7 @@
+--+
  */
 
-/* $Id: spl_directory.c,v 1.182 2009/05/25 14:32:14 felipe Exp $ */
+/* $Id: spl_directory.c,v 1.183 2009/06/04 14:46:08 colder Exp $ */
 
 #ifdef HAVE_CONFIG_H
 # include config.h
@@ -1334,7 +1334,7 @@
 {
spl_filesystem_object *intern = 
(spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
 
-   RETURN_LONG(intern-flags  (SPL_FILE_DIR_KEY_MODE_MASK | 
SPL_FILE_DIR_CURRENT_MODE_MASK));
+   RETURN_LONG(intern-flags  (SPL_FILE_DIR_KEY_MODE_MASK | 
SPL_FILE_DIR_CURRENT_MODE_MASK | SPL_FILE_DIR_OTHERS_MASK));
 } /* }}} */
 
 /* {{{ proto void FilesystemIterator::setFlags(long $flags) U
@@ -1346,8 +1346,8 @@
 
zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, l, flags);
 
-   intern-flags = 
~(SPL_FILE_DIR_KEY_MODE_MASK|SPL_FILE_DIR_CURRENT_MODE_MASK);
-   intern-flags |= 
((SPL_FILE_DIR_KEY_MODE_MASK|SPL_FILE_DIR_CURRENT_MODE_MASK)  flags);
+   intern-flags = 
~(SPL_FILE_DIR_KEY_MODE_MASK|SPL_FILE_DIR_CURRENT_MODE_MASK|SPL_FILE_DIR_OTHERS_MASK);
+   intern-flags |= 
((SPL_FILE_DIR_KEY_MODE_MASK|SPL_FILE_DIR_CURRENT_MODE_MASK|SPL_FILE_DIR_OTHERS_MASK)
  flags);
 } /* }}} */
 
 /* {{{ proto bool RecursiveDirectoryIterator::hasChildren([bool $allow_links = 
false]) U
http://cvs.php.net/viewvc.cgi/php-src/ext/spl/spl_directory.h?r1=1.48r2=1.49diff_format=u
Index: php-src/ext/spl/spl_directory.h
diff -u php-src/ext/spl/spl_directory.h:1.48 
php-src/ext/spl/spl_directory.h:1.49
--- php-src/ext/spl/spl_directory.h:1.48Tue Mar 10 23:39:38 2009
+++ php-src/ext/spl/spl_directory.h Thu Jun  4 14:46:08 2009
@@ -16,7 +16,7 @@
+--+
  */
 
-/* $Id: spl_directory.h,v 1.48 2009/03/10 23:39:38 helly Exp $ */
+/* $Id: spl_directory.h,v 1.49 2009/06/04 14:46:08 colder Exp $ */
 
 #ifndef SPL_DIRECTORY_H
 #define SPL_DIRECTORY_H
@@ -137,6 +137,7 @@
 
 #define SPL_FILE_DIR_SKIPDOTS  0x1000 /* Tells whether it 
should skip dots or not */
 #define SPL_FILE_DIR_UNIXPATHS 0x2000 /* Whether to unixify 
path separators */
+#define SPL_FILE_DIR_OTHERS_MASK   0x3000 /* mask used for 
get/setFlags */
 
 #endif /* SPL_DIRECTORY_H */
 



-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-CVS] cvs: php-src /ext/spl spl_directory.c spl_directory.h

2008-07-24 Thread Steph Fox
sfoxThu Jul 24 08:52:24 2008 UTC

  Modified files:  
/php-src/ext/splspl_directory.c spl_directory.h 
  Log:
  - Introduce SPL_FILE_DIR_UNIXPATHS.
  
http://cvs.php.net/viewvc.cgi/php-src/ext/spl/spl_directory.c?r1=1.161r2=1.162diff_format=u
Index: php-src/ext/spl/spl_directory.c
diff -u php-src/ext/spl/spl_directory.c:1.161 
php-src/ext/spl/spl_directory.c:1.162
--- php-src/ext/spl/spl_directory.c:1.161   Wed Jul 23 06:12:44 2008
+++ php-src/ext/spl/spl_directory.c Thu Jul 24 08:52:24 2008
@@ -16,7 +16,7 @@
+--+
  */
 
-/* $Id: spl_directory.c,v 1.161 2008/07/23 06:12:44 helly Exp $ */
+/* $Id: spl_directory.c,v 1.162 2008/07/24 08:52:24 sfox Exp $ */
 
 #ifdef HAVE_CONFIG_H
 # include config.h
@@ -185,6 +185,8 @@
 {
zstr path;
zend_uchar path_type;
+   char slash = intern-flags  SPL_FILE_DIR_UNIXPATHS ? '/' : 
DEFAULT_SLASH;
+
if (!intern-file_name.v) {
switch (intern-type) {
case SPL_FS_INFO:
@@ -195,7 +197,7 @@
path = spl_filesystem_object_get_path(intern, NULL, 
path_type TSRMLS_CC);
intern-file_name_len = zspprintf(path_type, 
intern-file_name, 0, %R%c%s,
  path_type, path,
- DEFAULT_SLASH, 
intern-u.dir.entry.d_name);
+ slash, 
intern-u.dir.entry.d_name);
intern-file_name_type = path_type;
break;
}
@@ -684,6 +686,10 @@
flags |= SPL_FILE_DIR_SKIPDOTS;
}
 
+   if (ctor_flags  SPL_FILE_DIR_UNIXPATHS) {
+   flags |= SPL_FILE_DIR_UNIXPATHS;
+   }
+
if (parsed == FAILURE) {
php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC);
return;
@@ -1372,6 +1378,7 @@
zval zpath, zflags;
spl_filesystem_object *intern = 
(spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
spl_filesystem_object *subdir;
+   char slash = intern-flags  SPL_FILE_DIR_UNIXPATHS ? '/' : 
DEFAULT_SLASH;

spl_filesystem_object_get_file_name(intern TSRMLS_CC);
 
@@ -1388,7 +1395,7 @@
if (subdir) {
if (intern-u.dir.sub_path.v  intern-u.dir.sub_path_len  1) 
{
subdir-u.dir.sub_path_type = 
intern-u.dir.sub_path_type;
-   subdir-u.dir.sub_path_len = 
zspprintf(intern-u.dir.sub_path_type, subdir-u.dir.sub_path, 0, %R%c%s, 
intern-u.dir.sub_path_type, intern-u.dir.sub_path, DEFAULT_SLASH, 
intern-u.dir.entry.d_name);
+   subdir-u.dir.sub_path_len = 
zspprintf(intern-u.dir.sub_path_type, subdir-u.dir.sub_path, 0, %R%c%s, 
intern-u.dir.sub_path_type, intern-u.dir.sub_path, slash, 
intern-u.dir.entry.d_name);
} else {
subdir-u.dir.sub_path_len = 
strlen(intern-u.dir.entry.d_name);
subdir-u.dir.sub_path_type = IS_STRING;
@@ -1422,9 +1429,10 @@
spl_filesystem_object *intern = 
(spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
zstr sub_name;
int sub_len;
+   char slash = intern-flags  SPL_FILE_DIR_UNIXPATHS ? '/' : 
DEFAULT_SLASH;
 
if (intern-u.dir.sub_path.v) {
-   sub_len = zspprintf(intern-u.dir.sub_path_type, sub_name, 0, 
%R%c%s, intern-u.dir.sub_path_type, intern-u.dir.sub_path, DEFAULT_SLASH, 
intern-u.dir.entry.d_name);
+   sub_len = zspprintf(intern-u.dir.sub_path_type, sub_name, 0, 
%R%c%s, intern-u.dir.sub_path_type, intern-u.dir.sub_path, slash, 
intern-u.dir.entry.d_name);
RETURN_ZSTRL(intern-u.dir.sub_path_type, sub_name, sub_len, 0);
} else {
RETURN_RT_STRING(intern-u.dir.entry.d_name, ZSTR_DUPLICATE);
@@ -2770,6 +2778,7 @@
REGISTER_SPL_CLASS_CONST_LONG(FilesystemIterator, KEY_AS_FILENAME,
 SPL_FILE_DIR_KEY_AS_FILENAME);
REGISTER_SPL_CLASS_CONST_LONG(FilesystemIterator, 
NEW_CURRENT_AND_KEY, 
SPL_FILE_DIR_KEY_AS_FILENAME|SPL_FILE_DIR_CURRENT_AS_FILEINFO);
REGISTER_SPL_CLASS_CONST_LONG(FilesystemIterator, SKIP_DOTS,  
 SPL_FILE_DIR_SKIPDOTS);
+   REGISTER_SPL_CLASS_CONST_LONG(FilesystemIterator, UNIX_PATHS, 
 SPL_FILE_DIR_UNIXPATHS);
 
spl_ce_FilesystemIterator-get_iterator = 
spl_filesystem_tree_get_iterator;
 
http://cvs.php.net/viewvc.cgi/php-src/ext/spl/spl_directory.h?r1=1.45r2=1.46diff_format=u
Index: php-src/ext/spl/spl_directory.h
diff -u php-src/ext/spl/spl_directory.h:1.45 
php-src/ext/spl/spl_directory.h:1.46
--- php-src/ext/spl/spl_directory.h:1.45Sat Jul 19 11:20:04 2008
+++ php-src/ext/spl/spl_directory.h Thu Jul 24 08:52:24 2008
@@ -16,7 +16,7 @@

[PHP-CVS] cvs: php-src /ext/spl spl_directory.c spl_directory.h /ext/spl/tests dit_006.phpt

2008-07-19 Thread Etienne Kneuss
colder  Sat Jul 19 11:20:05 2008 UTC

  Added files: 
/php-src/ext/spl/tests  dit_006.phpt 

  Modified files:  
/php-src/ext/splspl_directory.c spl_directory.h 
  Log:
  Implement DirectoryIterator::seek
  
http://cvs.php.net/viewvc.cgi/php-src/ext/spl/spl_directory.c?r1=1.159r2=1.160diff_format=u
Index: php-src/ext/spl/spl_directory.c
diff -u php-src/ext/spl/spl_directory.c:1.159 
php-src/ext/spl/spl_directory.c:1.160
--- php-src/ext/spl/spl_directory.c:1.159   Tue Jul  8 22:49:35 2008
+++ php-src/ext/spl/spl_directory.c Sat Jul 19 11:20:04 2008
@@ -16,7 +16,7 @@
+--+
  */
 
-/* $Id: spl_directory.c,v 1.159 2008/07/08 22:49:35 colder Exp $ */
+/* $Id: spl_directory.c,v 1.160 2008/07/19 11:20:04 colder Exp $ */
 
 #ifdef HAVE_CONFIG_H
 # include config.h
@@ -776,6 +776,44 @@
 }
 /* }}} */
 
+/* {{{ proto void DirectoryIterator::seek(int position)
+   Seek to the given position */
+SPL_METHOD(DirectoryIterator, seek)
+{
+   spl_filesystem_object *intern= 
(spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
+   zval  *retval= NULL;
+   long   pos;
+
+   if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, l, pos) == 
FAILURE) {
+   return;
+   }
+
+   if (intern-u.dir.index  pos) {
+   /* we first rewind */
+   zend_call_method_with_0_params(this_ptr, Z_OBJCE_P(getThis()), 
intern-u.dir.func_rewind, rewind, retval);
+   if (retval) {
+   zval_ptr_dtor(retval);
+   }
+   }
+
+   while (intern-u.dir.index  pos) {
+   int valid = 0;
+   zend_call_method_with_0_params(this_ptr, Z_OBJCE_P(getThis()), 
intern-u.dir.func_valid, valid, retval);
+   if (retval) {
+   valid = zend_is_true(retval);
+   zval_ptr_dtor(retval);
+   }
+   if (!valid) {
+   break;
+   }
+   zend_call_method_with_0_params(this_ptr, Z_OBJCE_P(getThis()), 
intern-u.dir.func_next, next, retval);
+   if (retval) {
+   zval_ptr_dtor(retval);
+   }
+   }
+} /* }}} */
+
+
 /* {{{ proto string DirectoryIterator::valid() U
Check whether dir contains more entries */
 SPL_METHOD(DirectoryIterator, valid)
@@ -1768,6 +1806,12 @@
ZEND_ARG_INFO(0, path)
 ZEND_END_ARG_INFO()
 
+static
+ZEND_BEGIN_ARG_INFO(arginfo_dir_it_seek, 0) 
+   ZEND_ARG_INFO(0, position)
+ZEND_END_ARG_INFO();
+
+
 /* the method table */
 /* each method can have its own parameters and visibility */
 static const zend_function_entry spl_DirectoryIterator_functions[] = {
@@ -1780,6 +1824,7 @@
SPL_ME(DirectoryIterator, key,   NULL, ZEND_ACC_PUBLIC)
SPL_ME(DirectoryIterator, current,   NULL, ZEND_ACC_PUBLIC)
SPL_ME(DirectoryIterator, next,  NULL, ZEND_ACC_PUBLIC)
+   SPL_ME(DirectoryIterator, seek,  arginfo_dir_it_seek, 
ZEND_ACC_PUBLIC)
SPL_MA(DirectoryIterator, __toString, DirectoryIterator, getFilename, 
NULL, ZEND_ACC_PUBLIC)
{NULL, NULL, NULL}
 };
@@ -2704,12 +2749,13 @@
 
REGISTER_SPL_STD_CLASS_EX(SplFileInfo, spl_filesystem_object_new, 
spl_SplFileInfo_functions);
memcpy(spl_filesystem_object_handlers, zend_get_std_object_handlers(), 
sizeof(zend_object_handlers));
-   spl_filesystem_object_handlers.clone_obj = spl_filesystem_object_clone;
-   spl_filesystem_object_handlers.cast_object = spl_filesystem_object_cast;
+   spl_filesystem_object_handlers.clone_obj  = 
spl_filesystem_object_clone;
+   spl_filesystem_object_handlers.cast_object= 
spl_filesystem_object_cast;
spl_filesystem_object_handlers.get_debug_info = 
spl_filesystem_object_get_debug_info;
 
REGISTER_SPL_SUB_CLASS_EX(DirectoryIterator, SplFileInfo, 
spl_filesystem_object_new, spl_DirectoryIterator_functions);
zend_class_implements(spl_ce_DirectoryIterator TSRMLS_CC, 1, 
zend_ce_iterator);
+   REGISTER_SPL_IMPLEMENTS(DirectoryIterator, SeekableIterator);
 
spl_ce_DirectoryIterator-get_iterator = 
spl_filesystem_dir_get_iterator;
 
http://cvs.php.net/viewvc.cgi/php-src/ext/spl/spl_directory.h?r1=1.44r2=1.45diff_format=u
Index: php-src/ext/spl/spl_directory.h
diff -u php-src/ext/spl/spl_directory.h:1.44 
php-src/ext/spl/spl_directory.h:1.45
--- php-src/ext/spl/spl_directory.h:1.44Tue May 20 21:46:13 2008
+++ php-src/ext/spl/spl_directory.h Sat Jul 19 11:20:04 2008
@@ -16,7 +16,7 @@
+--+
  */
 
-/* $Id: spl_directory.h,v 1.44 2008/05/20 21:46:13 colder Exp $ */
+/* $Id: spl_directory.h,v 1.45 2008/07/19 11:20:04 colder Exp $ */
 
 #ifndef SPL_DIRECTORY_H
 #define SPL_DIRECTORY_H
@@ -82,6 

[PHP-CVS] cvs: php-src /ext/spl spl_directory.c spl_directory.h /ext/spl/tests fileobject_004.phpt

2008-05-20 Thread Etienne Kneuss
colder  Tue May 20 21:46:14 2008 UTC

  Added files: 
/php-src/ext/spl/tests  fileobject_004.phpt 

  Modified files:  
/php-src/ext/splspl_directory.c spl_directory.h 
  Log:
  Fix path lookup when include_path is used
  
http://cvs.php.net/viewvc.cgi/php-src/ext/spl/spl_directory.c?r1=1.154r2=1.155diff_format=u
Index: php-src/ext/spl/spl_directory.c
diff -u php-src/ext/spl/spl_directory.c:1.154 
php-src/ext/spl/spl_directory.c:1.155
--- php-src/ext/spl/spl_directory.c:1.154   Fri May 16 13:22:02 2008
+++ php-src/ext/spl/spl_directory.c Tue May 20 21:46:13 2008
@@ -16,7 +16,7 @@
+--+
  */
 
-/* $Id: spl_directory.c,v 1.154 2008/05/16 13:22:02 colder Exp $ */
+/* $Id: spl_directory.c,v 1.155 2008/05/20 21:46:13 colder Exp $ */
 
 #ifdef HAVE_CONFIG_H
 # include config.h
@@ -109,6 +109,9 @@
if (intern-u.file.open_mode) {
efree(intern-u.file.open_mode);
}
+   if (intern-orig_path) {
+   efree(intern-orig_path);
+   }
}
spl_filesystem_file_free_line(intern TSRMLS_CC);
break;
@@ -277,6 +280,10 @@
intern-file_name_len--;
}
 
+   /* NOTE: Works as long as stream-orig_path is not unicode aware, might
+* break later. */
+   intern-orig_path = estrndup(intern-u.file.stream-orig_path, 
strlen(intern-u.file.stream-orig_path));
+
intern-file_name = ezstrndup(intern-file_name_type, 
intern-file_name, intern-file_name_len);
intern-u.file.open_mode = estrndup(intern-u.file.open_mode, 
intern-u.file.open_mode_len);
 
@@ -1082,10 +1089,14 @@
spl_filesystem_object_get_file_name(intern TSRMLS_CC);
}
 
-   if (intern-file_name_type == IS_UNICODE) {
-   php_stream_path_encode(NULL, filename, filename_len, 
intern-file_name.u, intern-file_name_len, REPORT_ERRORS, FG(default_context));
+   if (intern-orig_path) {
+   filename = intern-orig_path;
} else {
-   filename = intern-file_name.s;
+   if (intern-file_name_type == IS_UNICODE) {
+   php_stream_path_encode(NULL, filename, filename_len, 
intern-file_name.u, intern-file_name_len, REPORT_ERRORS, FG(default_context));
+   } else {
+   filename = intern-file_name.s;
+   }
}
 
if (filename  VCWD_REALPATH(filename, buff)) {
@@ -1994,6 +2005,8 @@
spl_filesystem_object *intern = 
(spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
zend_bool use_include_path = 0;
zstr p1, p2;
+   char *tmp_path;
+   int   tmp_path_len;
 
php_set_error_handling(EH_THROW, spl_ce_RuntimeException TSRMLS_CC);
 
@@ -2009,31 +2022,31 @@
}

if (spl_filesystem_file_open(intern, use_include_path, 0 TSRMLS_CC) == 
SUCCESS) {
-   if (intern-file_name_type == IS_UNICODE) {
-   p1.u = u_strrchr(intern-file_name.u, '/');
-   } else {
-   p1.s = strrchr(intern-file_name.s, '/');
+   tmp_path_len  = strlen(intern-u.file.stream-orig_path);
+
+   if (tmp_path_len  IS_SLASH_AT(IS_STRING, 
ZSTR(intern-u.file.stream-orig_path), tmp_path_len-1)) {
+   tmp_path_len--;
}
+
+   tmp_path = estrndup(intern-u.file.stream-orig_path, 
tmp_path_len);
+
+   p1.s = strrchr(tmp_path, '/');
 #if defined(PHP_WIN32) || defined(NETWARE)
-   if (intern-file_name_type == IS_UNICODE) {
-   p2.u = u_strrchr(intern-file_name.u, '\\');
-   } else {
-   p2.s = strrchr(intern-file_name.s, '\\');
-   }
+   p2.s = strrchr(tmp_path, '\\');
 #else
p2.v = 0;
 #endif
+
if (p1.v || p2.v) {
-   if (intern-file_name_type == IS_UNICODE) {
-   intern-_path_len = (p1.u  p2.u ? p1.u : p2.u) 
- intern-file_name.u;
-   } else {
-   intern-_path_len = (p1.s  p2.s ? p1.s : p2.s) 
- intern-file_name.s;
-   }
+   intern-_path_len = (p1.s  p2.s ? p1.s : p2.s) - 
tmp_path;
} else {
intern-_path_len = 0;
}
-   intern-_path_type = intern-file_name_type;
-   intern-_path = ezstrndup(intern-file_name_type, 
intern-file_name, intern-_path_len);
+
+   efree(tmp_path);
+
+   intern-_path  = 
ZSTR(estrndup(intern-u.file.stream-orig_path, intern-_path_len));
+   intern-_path_type = IS_STRING;
}
 

[PHP-CVS] cvs: php-src /ext/spl spl_directory.c spl_directory.h /ext/spl/tests dit_004.phpt dit_005.phpt

2008-05-16 Thread Etienne Kneuss
colder  Fri May 16 13:22:02 2008 UTC

  Added files: 
/php-src/ext/spl/tests  dit_004.phpt dit_005.phpt 

  Modified files:  
/php-src/ext/splspl_directory.c spl_directory.h 
  Log:
  Fix FilesystemIterator with ./..
  http://cvs.php.net/viewvc.cgi/php-src/ext/spl/spl_directory.c?r1=1.153r2=1.154diff_format=u
Index: php-src/ext/spl/spl_directory.c
diff -u php-src/ext/spl/spl_directory.c:1.153 
php-src/ext/spl/spl_directory.c:1.154
--- php-src/ext/spl/spl_directory.c:1.153   Thu May 15 17:22:03 2008
+++ php-src/ext/spl/spl_directory.c Fri May 16 13:22:02 2008
@@ -16,7 +16,7 @@
+--+
  */
 
-/* $Id: spl_directory.c,v 1.153 2008/05/15 17:22:03 colder Exp $ */
+/* $Id: spl_directory.c,v 1.154 2008/05/16 13:22:02 colder Exp $ */
 
 #ifdef HAVE_CONFIG_H
 # include config.h
@@ -212,11 +212,18 @@
 
 #define IS_SLASH_AT(type, zs, pos) (type == IS_UNICODE ? IS_U_SLASH(zs.u[pos]) 
: IS_SLASH(zs.s[pos]))
 
+static inline int spl_filesystem_is_dot(const char * d_name) /* {{{ */
+{
+   return !strcmp(d_name, .) || !strcmp(d_name, ..);
+}
+/* }}} */
+
 /* {{{ spl_filesystem_dir_open */
 /* open a directory resource */
 static void spl_filesystem_dir_open(spl_filesystem_object* intern, zend_uchar 
type, zstr path, int path_len TSRMLS_DC)
 {
int options = REPORT_ERRORS;
+   int skip_dots = intern-flags  SPL_FILE_DIR_SKIPDOTS;
 
 #if HELLY_0
if (php_stream_is(intern-u.dir.dirp, php_glob_stream_ops)) {
@@ -240,7 +247,9 @@
/* throw exception: should've been already happened */
intern-u.dir.entry.d_name[0] = '\0';
} else {
-   spl_filesystem_dir_read(intern TSRMLS_CC);
+   do {
+   spl_filesystem_dir_read(intern TSRMLS_CC);
+   } while (skip_dots  
spl_filesystem_is_dot(intern-u.dir.entry.d_name));
}
 }
 /* }}} */
@@ -299,13 +308,18 @@
spl_filesystem_object *intern;
spl_filesystem_object *source;
int index;
+   int skip_dots;
 
old_object = zend_objects_get_address(zobject TSRMLS_CC);
source = (spl_filesystem_object*)old_object;
 
+   skip_dots = source-flags  SPL_FILE_DIR_SKIPDOTS;
+
new_obj_val = spl_filesystem_object_new_ex(old_object-ce, intern 
TSRMLS_CC);
new_object = intern-std;
 
+   intern-flags = source-flags;
+
switch (source-type) {
case SPL_FS_INFO:
intern-_path_type = source-_path_type;
@@ -319,7 +333,9 @@
spl_filesystem_dir_open(intern, source-_path_type, 
source-_path, source-_path_len TSRMLS_CC);
/* read until we hit the position in which we were before */
for(index = 0; index  source-u.dir.index; ++index) {
-   spl_filesystem_dir_read(intern TSRMLS_CC);
+   do {
+   spl_filesystem_dir_read(intern TSRMLS_CC);
+   } while (skip_dots  
spl_filesystem_is_dot(intern-u.dir.entry.d_name));
}
intern-u.dir.index = index;
break;
@@ -330,7 +346,6 @@

intern-file_class = source-file_class;
intern-info_class = source-info_class;
-   intern-flags = source-flags;
intern-oth = source-oth;
intern-oth_handler = source-oth_handler;
 
@@ -514,12 +529,6 @@
return NULL;
 } /* }}} */
 
-static inline int spl_filesystem_is_dot(const char * d_name) /* {{{ */
-{
-   return !strcmp(d_name, .) || !strcmp(d_name, ..);
-}
-/* }}} */
-
 static int spl_filesystem_is_invalid_or_dot(const char * d_name) /* {{{ */
 {
return d_name[0] == '\0' || spl_filesystem_is_dot(d_name);
@@ -614,6 +623,11 @@
flags = 
SPL_FILE_DIR_KEY_AS_PATHNAME|SPL_FILE_DIR_CURRENT_AS_SELF;
parsed = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, t, 
path, len, path_type);
}
+
+   if (ctor_flags  SPL_FILE_DIR_SKIPDOTS) {
+   flags |= SPL_FILE_DIR_SKIPDOTS;
+   }
+
if (parsed == FAILURE) {
php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC);
return;
@@ -625,6 +639,8 @@
}
 
intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() 
TSRMLS_CC);
+   intern-flags = flags;
+
if ((ctor_flags  DIT_CTOR_GLOB)  (
(path_type == IS_STRING  strstr(path.s, glob://) != path.s) 
||
(path_type == IS_UNICODE  u_strstr(path.u, u_glob) != path.u)
@@ -637,7 +653,6 @@
}
 
intern-u.dir.is_recursive = instanceof_function(intern-std.ce, 
spl_ce_RecursiveDirectoryIterator TSRMLS_CC) ? 1 : 0;
-   intern-flags = flags;
 
php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC);
 }
@@ -692,9 +707,12 @@
 SPL_METHOD(DirectoryIterator, next)
 {
spl_filesystem_object *intern = 

[PHP-CVS] cvs: php-src /ext/spl spl_directory.c spl_directory.h

2008-02-04 Thread Marcus Boerger
helly   Mon Feb  4 19:33:03 2008 UTC

  Modified files:  
/php-src/ext/splspl_directory.c spl_directory.h 
  Log:
  - Really fix flag handling
  
http://cvs.php.net/viewvc.cgi/php-src/ext/spl/spl_directory.c?r1=1.146r2=1.147diff_format=u
Index: php-src/ext/spl/spl_directory.c
diff -u php-src/ext/spl/spl_directory.c:1.146 
php-src/ext/spl/spl_directory.c:1.147
--- php-src/ext/spl/spl_directory.c:1.146   Mon Feb  4 18:46:02 2008
+++ php-src/ext/spl/spl_directory.c Mon Feb  4 19:33:03 2008
@@ -16,7 +16,7 @@
+--+
  */
 
-/* $Id: spl_directory.c,v 1.146 2008/02/04 18:46:02 helly Exp $ */
+/* $Id: spl_directory.c,v 1.147 2008/02/04 19:33:03 helly Exp $ */
 
 #ifdef HAVE_CONFIG_H
 # include config.h
@@ -597,13 +597,15 @@
zstr path;
int parsed, len;
zend_uchar path_type;
-   long flags = 0;
+   long flags;

php_set_error_handling(EH_THROW, spl_ce_RuntimeException TSRMLS_CC);
 
if (ctor_flags  DIT_CTOR_FLAGS) {
+   flags = 0;
parsed = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, 
t|l, path, len, path_type, flags);
} else {
+   flags = 
SPL_FILE_DIR_KEY_AS_PATHNAME|SPL_FILE_DIR_CURRENT_AS_SELF;
parsed = zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, t, 
path, len, path_type);
}
if (parsed == FAILURE) {
@@ -837,7 +839,7 @@
 {
spl_filesystem_object *intern = 
(spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
 
-   if (intern-flags  SPL_FILE_DIR_KEY_AS_FILENAME) {
+   if (SPL_FILE_DIR_KEY(intern, SPL_FILE_DIR_KEY_AS_FILENAME)) {
RETURN_RT_STRING(intern-u.dir.entry.d_name, ZSTR_DUPLICATE);
} else {
spl_filesystem_object_get_file_name(intern TSRMLS_CC);
@@ -852,10 +854,10 @@
 {
spl_filesystem_object *intern = 
(spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
 
-   if (intern-flags  SPL_FILE_DIR_CURRENT_AS_PATHNAME) {
+   if (SPL_FILE_DIR_CURRENT(intern, SPL_FILE_DIR_CURRENT_AS_PATHNAME)) {
spl_filesystem_object_get_file_name(intern TSRMLS_CC);
RETURN_ZSTRL(intern-file_name_type, intern-file_name, 
intern-file_name_len, ZSTR_DUPLICATE);
-   } else if (intern-flags  SPL_FILE_DIR_CURRENT_AS_FILEINFO) {
+   } else if (SPL_FILE_DIR_CURRENT(intern, 
SPL_FILE_DIR_CURRENT_AS_FILEINFO)) {
spl_filesystem_object_get_file_name(intern TSRMLS_CC);
spl_filesystem_object_create_type(0, intern, SPL_FS_INFO, NULL, 
return_value TSRMLS_CC);
} else {
@@ -1460,14 +1462,14 @@
spl_filesystem_iterator *iterator = (spl_filesystem_iterator *)iter;
spl_filesystem_object   *object   = 
spl_filesystem_iterator_to_object(iterator);
 
-   if (object-flags  SPL_FILE_DIR_CURRENT_AS_PATHNAME) {
+   if (SPL_FILE_DIR_CURRENT(object, SPL_FILE_DIR_CURRENT_AS_PATHNAME)) {
if (!iterator-current) {
ALLOC_INIT_ZVAL(iterator-current);
spl_filesystem_object_get_file_name(object TSRMLS_CC);
ZVAL_ZSTRL(iterator-current, object-file_name_type, 
object-file_name, object-file_name_len, ZSTR_DUPLICATE);
}
*data = iterator-current;
-   } else if (object-flags  SPL_FILE_DIR_CURRENT_AS_FILEINFO) {
+   } else if (SPL_FILE_DIR_CURRENT(object, 
SPL_FILE_DIR_CURRENT_AS_FILEINFO)) {
if (!iterator-current) {
ALLOC_INIT_ZVAL(iterator-current);
spl_filesystem_object_get_file_name(object TSRMLS_CC);
@@ -1485,7 +1487,7 @@
 {
spl_filesystem_object *object = 
spl_filesystem_iterator_to_object((spl_filesystem_iterator *)iter);

-   if (object-flags  SPL_FILE_DIR_KEY_AS_FILENAME) {
+   if (SPL_FILE_DIR_KEY(object, SPL_FILE_DIR_KEY_AS_FILENAME)) {
*str_key_len = strlen(object-u.dir.entry.d_name) + 1;
str_key-s = estrndup(object-u.dir.entry.d_name, *str_key_len 
- 1);
return HASH_KEY_IS_STRING;
@@ -1898,11 +1900,11 @@
case IS_UNICODE:
return Z_STRLEN_P(intern-u.file.current_zval) == 0;
case IS_ARRAY:
-   if ((intern-flags  SPL_FILE_OBJECT_READ_CSV) 
+   if ((intern-flags  SPL_FILE_OBJECT_READ_CSV)
 
zend_hash_num_elements(Z_ARRVAL_P(intern-u.file.current_zval)) == 1) {
zval ** first = 
Z_ARRVAL_P(intern-u.file.current_zval)-pListHead-pData;

-   return (Z_TYPE_PP(first) == IS_STRING || 
Z_TYPE_PP(first) == IS_UNICODE) 
+   return (Z_TYPE_PP(first) == IS_STRING || 
Z_TYPE_PP(first) == IS_UNICODE)
   

[PHP-CVS] cvs: php-src /ext/spl spl_directory.c spl_directory.h

2008-02-02 Thread Marcus Boerger
helly   Sat Feb  2 22:53:05 2008 UTC

  Modified files:  
/php-src/ext/splspl_directory.c spl_directory.h 
  Log:
  - MFB glob handling
  - Add GlobIterator and FilesystemIterator
  # Commit to 5.3 for more
  
  http://cvs.php.net/viewvc.cgi/php-src/ext/spl/spl_directory.c?r1=1.142r2=1.143diff_format=u
Index: php-src/ext/spl/spl_directory.c
diff -u php-src/ext/spl/spl_directory.c:1.142 
php-src/ext/spl/spl_directory.c:1.143
--- php-src/ext/spl/spl_directory.c:1.142   Thu Jan 31 11:09:50 2008
+++ php-src/ext/spl/spl_directory.c Sat Feb  2 22:53:05 2008
@@ -16,7 +16,7 @@
+--+
  */
 
-/* $Id: spl_directory.c,v 1.142 2008/01/31 11:09:50 rrichards Exp $ */
+/* $Id: spl_directory.c,v 1.143 2008/02/02 22:53:05 helly Exp $ */
 
 #ifdef HAVE_CONFIG_H
 # include config.h
@@ -43,15 +43,6 @@
 
 #include ext/standard/basic_functions.h
 #include ext/standard/php_filestat.h
-#include ext/standard/php_link.h
-
-#ifdef HAVE_GLOB
-# ifndef PHP_WIN32
-#  include glob.h
-# else
-#  include win32/glob.h
-# endif
-#endif
 
 /* declare the class handlers */
 static zend_object_handlers spl_filesystem_object_handlers;
@@ -59,7 +50,9 @@
 /* decalre the class entry */
 PHPAPI zend_class_entry *spl_ce_SplFileInfo;
 PHPAPI zend_class_entry *spl_ce_DirectoryIterator;
+PHPAPI zend_class_entry *spl_ce_FilesystemIterator;
 PHPAPI zend_class_entry *spl_ce_RecursiveDirectoryIterator;
+PHPAPI zend_class_entry *spl_ce_GlobIterator;
 PHPAPI zend_class_entry *spl_ce_SplFileObject;
 PHPAPI zend_class_entry *spl_ce_SplTempFileObject;
 
@@ -197,64 +190,49 @@
break;
case SPL_FS_DIR:
path = spl_filesystem_object_get_path(intern, NULL, 
path_type TSRMLS_CC);
-   intern-file_name_len = zspprintf(path_type, 
intern-file_name, 0, %R%c%s, path_type, path, DEFAULT_SLASH, 
intern-u.dir.entry.d_name);
+   intern-file_name_len = zspprintf(path_type, 
intern-file_name, 0, %R%c%s,
+ path_type, path,
+ DEFAULT_SLASH, 
intern-u.dir.entry.d_name);
intern-file_name_type = path_type;
break;
}
}
 } /* }}} */
 
-#define IS_SLASH_AT(type, zs, pos) (type == IS_UNICODE ? IS_U_SLASH(zs.u[pos]) 
: IS_SLASH(zs.s[pos]))
-
 static int spl_filesystem_dir_read(spl_filesystem_object *intern TSRMLS_DC) /* 
{{{ */
 {
if (!intern-u.dir.dirp || !php_stream_readdir(intern-u.dir.dirp, 
intern-u.dir.entry)) {
intern-u.dir.entry.d_name[0] = '\0';
return 0;
} else {
-   if (intern-flags  SPL_FILE_DIR_GLOB_REFETCH_PATH) {
-   if (intern-_path.v) {
-   efree(intern-_path.v);
-   }
-   intern-_path.s = 
php_glob_stream_get_path(intern-u.dir.dirp, 1, intern-_path_len);
-   intern-_path_type = IS_STRING;
-   }
return 1;
}
 }
 /* }}} */
 
+#define IS_SLASH_AT(type, zs, pos) (type == IS_UNICODE ? IS_U_SLASH(zs.u[pos]) 
: IS_SLASH(zs.s[pos]))
+
 /* {{{ spl_filesystem_dir_open */
 /* open a directory resource */
 static void spl_filesystem_dir_open(spl_filesystem_object* intern, zend_uchar 
type, zstr path, int path_len TSRMLS_DC)
 {
-   int options = REPORT_ERRORS, flags;
-   
-   if (intern-flags  SPL_FILE_DIR_GLOB_USE) {
+   int options = REPORT_ERRORS;
+
+#if HELLY_0
+   if (php_stream_is(intern-u.dir.dirp, php_glob_stream_ops)) {
options |= STREAM_USE_GLOB_DIR_OPEN;
}
+#endif
 
intern-type = SPL_FS_DIR;
intern-_path_type= type;
intern-_path_len = path_len;
intern-u.dir.dirp = php_stream_u_opendir(type, path, path_len, 
options, NULL);
 
-   if (intern-u.dir.dirp  php_stream_is(intern-u.dir.dirp, 
php_glob_stream_ops)) {
-   intern-_path.s = php_glob_stream_get_path(intern-u.dir.dirp, 
1, intern-_path_len);
-   intern-_path_type = IS_STRING;
-   intern-flags |= SPL_FILE_DIR_GLOB_USE;
-   php_glob_stream_get_count(intern-u.dir.dirp, flags);
-   if (flags  GLOB_APPEND) {
-   intern-flags |= SPL_FILE_DIR_GLOB_REFETCH_PATH;
-   } else {
-   intern-flags = ~SPL_FILE_DIR_GLOB_REFETCH_PATH;
-   }
-   } else if (intern-_path_len  IS_SLASH_AT(type, path, 
intern-_path_len-1)) {
+   if (intern-_path_len  IS_SLASH_AT(type, path, intern-_path_len-1)) {
intern-_path = ezstrndup(type, path, --intern-_path_len);
-   intern-flags = 
~(SPL_FILE_DIR_GLOB_USE|SPL_FILE_DIR_GLOB_REFETCH_PATH);
} else {
intern-_path = ezstrndup(type, path, intern-_path_len);
- 

[PHP-CVS] cvs: php-src /ext/spl spl_directory.c spl_directory.h

2008-01-30 Thread Marcus Boerger
helly   Wed Jan 30 23:49:49 2008 UTC

  Modified files:  
/php-src/ext/splspl_directory.c spl_directory.h 
  Log:
  - MFB SplDirectoryIterator/glob:// stream integration
  
  http://cvs.php.net/viewvc.cgi/php-src/ext/spl/spl_directory.c?r1=1.140r2=1.141diff_format=u
Index: php-src/ext/spl/spl_directory.c
diff -u php-src/ext/spl/spl_directory.c:1.140 
php-src/ext/spl/spl_directory.c:1.141
--- php-src/ext/spl/spl_directory.c:1.140   Mon Dec 31 07:12:15 2007
+++ php-src/ext/spl/spl_directory.c Wed Jan 30 23:49:49 2008
@@ -16,7 +16,7 @@
+--+
  */
 
-/* $Id: spl_directory.c,v 1.140 2007/12/31 07:12:15 sebastian Exp $ */
+/* $Id: spl_directory.c,v 1.141 2008/01/30 23:49:49 helly Exp $ */
 
 #ifdef HAVE_CONFIG_H
 # include config.h
@@ -85,8 +85,8 @@

zend_object_std_dtor(intern-std TSRMLS_CC);

-   if (intern-path.v) {
-   efree(intern-path.v);
+   if (intern-_path.v) {
+   efree(intern-_path.v);
}
if (intern-file_name.v) {
efree(intern-file_name.v);
@@ -164,8 +164,31 @@
 }
 /* }}} */
 
+PHPAPI zstr spl_filesystem_object_get_path(spl_filesystem_object *intern, int 
*len, zend_uchar *type TSRMLS_DC) /* {{{ */
+{
+   if (intern-type == SPL_FS_DIR) {
+   if (php_stream_is(intern-u.dir.dirp ,php_glob_stream_ops)) {
+   if (type) {
+   *type = IS_STRING;
+   }
+   zstr ret;
+   ret.s = php_glob_stream_get_path(intern-u.dir.dirp, 0, 
len);
+   return ret;
+   }
+   }
+   if (len) {
+   *len = intern-_path_len;
+   }
+   if (type) {
+   *type = intern-_path_type;
+   }
+   return intern-_path;
+} /* }}} */
+
 static inline void spl_filesystem_object_get_file_name(spl_filesystem_object 
*intern TSRMLS_DC) /* {{{ */
 {
+   zstr path;
+   zend_uchar path_type;
if (!intern-file_name.v) {
switch (intern-type) {
case SPL_FS_INFO:
@@ -173,8 +196,9 @@
php_error_docref(NULL TSRMLS_CC, E_ERROR, Object not 
initialized);
break;
case SPL_FS_DIR:
-   intern-file_name_len = zspprintf(intern-path_type, 
intern-file_name, 0, %R%c%s, intern-path_type, intern-path, 
DEFAULT_SLASH, intern-u.dir.entry.d_name);
-   intern-file_name_type = intern-path_type;
+   path = spl_filesystem_object_get_path(intern, NULL, 
path_type TSRMLS_CC);
+   intern-file_name_len = zspprintf(path_type, 
intern-file_name, 0, %R%c%s, path_type, path, DEFAULT_SLASH, 
intern-u.dir.entry.d_name);
+   intern-file_name_type = path_type;
break;
}
}
@@ -189,10 +213,11 @@
return 0;
} else {
if (intern-flags  SPL_FILE_DIR_GLOB_REFETCH_PATH) {
-   if (intern-path.v) {
-   efree(intern-path.v);
+   if (intern-_path.v) {
+   efree(intern-_path.v);
}
-   intern-path.s = 
php_glob_stream_get_path(intern-u.dir.dirp, 1, intern-path_len);
+   intern-_path.s = 
php_glob_stream_get_path(intern-u.dir.dirp, 1, intern-_path_len);
+   intern-_path_type = IS_STRING;
}
return 1;
}
@@ -210,13 +235,13 @@
}
 
intern-type = SPL_FS_DIR;
-   intern-path_type= type;
-   intern-path_len = path_len;
+   intern-_path_type= type;
+   intern-_path_len = path_len;
intern-u.dir.dirp = php_stream_u_opendir(type, path, path_len, 
options, NULL);
 
if (intern-u.dir.dirp  php_stream_is(intern-u.dir.dirp, 
php_glob_stream_ops)) {
-   intern-path.s = php_glob_stream_get_path(intern-u.dir.dirp, 
1, intern-path_len);
-   intern-path_type = IS_STRING;
+   intern-_path.s = php_glob_stream_get_path(intern-u.dir.dirp, 
1, intern-_path_len);
+   intern-_path_type = IS_STRING;
intern-flags |= SPL_FILE_DIR_GLOB_USE;
php_glob_stream_get_count(intern-u.dir.dirp, flags);
if (flags  GLOB_APPEND) {
@@ -224,11 +249,11 @@
} else {
intern-flags = ~SPL_FILE_DIR_GLOB_REFETCH_PATH;
}
-   } else if (intern-path_len  IS_SLASH_AT(type, path, 
intern-path_len-1)) {
-   intern-path = ezstrndup(type, path, --intern-path_len);
+   } else if (intern-_path_len  IS_SLASH_AT(type, path, 
intern-_path_len-1)) {
+   intern-_path = ezstrndup(type, path, --intern-_path_len);
intern-flags = 

Re: [PHP-CVS] cvs: php-src /ext/spl spl_directory.c spl_directory.h /ext/standard file.c file.h /ext/standard/tests/file bug40501.csv bug40501.phpt fgetcsv_error.phpt

2007-10-03 Thread Marcus Boerger
Hello David,

  can you MFH this to 5.3.

marcus

Wednesday, October 3, 2007, 12:31:04 PM, you wrote:

 http://cvs.php.net/viewvc.cgi/php-src/ext/spl/spl_directory.c?r1=1.136r2=1.137diff_format=u
 Index: php-src/ext/spl/spl_directory.c
 diff -u php-src/ext/spl/spl_directory.c:1.136
 php-src/ext/spl/spl_directory.c:1.137
 --- php-src/ext/spl/spl_directory.c:1.136   Thu Sep 27 18:28:42 2007
 +++ php-src/ext/spl/spl_directory.c Wed Oct  3 10:31:03 2007
 @@ -16,7 +16,7 @@
 +--+
   */
  
 -/* $Id: spl_directory.c,v 1.136 2007/09/27 18:28:42 dmitry Exp $ */
 +/* $Id: spl_directory.c,v 1.137 2007/10/03 10:31:03 dsp Exp $ */
  
  #ifdef HAVE_CONFIG_H
  # include config.h
 @@ -1771,7 +1771,7 @@
 spl_filesystem_file_call(intern, func_ptr, pass_num_args, 
 return_value, arg2
 TSRMLS_CC); \
  }
  
 -static int spl_filesystem_file_read_csv(spl_filesystem_object *intern, char 
 delimiter, char
 enclosure, zval *return_value TSRMLS_DC) /* {{{ */
 +static int spl_filesystem_file_read_csv(spl_filesystem_object *intern, char 
 delimiter, char
 enclosure, char escape, zval *return_value TSRMLS_DC) /* {{{ */
  {
 int ret = SUCCESS;
 
 @@ -1788,7 +1788,7 @@
 }
 ALLOC_INIT_ZVAL(intern-u.file.current_zval);
  
 -   php_fgetcsv(intern-u.file.stream, delimiter, enclosure, 
 buf_len, buf,
 intern-u.file.current_zval TSRMLS_CC);
 +   php_fgetcsv(intern-u.file.stream, delimiter, enclosure, 
 escape, buf_len, buf,
 intern-u.file.current_zval TSRMLS_CC);
 if (return_value) {
 if (Z_TYPE_P(return_value) != IS_NULL) {
 zval_dtor(return_value);
 @@ -1814,7 +1814,7 @@
 return FAILURE;
 }
 if (intern-flags  SPL_FILE_OBJECT_READ_CSV) {
 -   return spl_filesystem_file_read_csv(intern, 
 intern-u.file.delimiter,
 intern-u.file.enclosure, NULL TSRMLS_CC);
 +   return spl_filesystem_file_read_csv(intern, 
 intern-u.file.delimiter,
 intern-u.file.enclosure, intern-u.file.escape, NULL TSRMLS_CC);
 } else {
 zend_call_method_with_0_params(this_ptr, 
 Z_OBJCE_P(getThis()),
 intern-u.file.func_getCurr, getCurrentLine, retval);
 }
 @@ -2149,13 +2149,20 @@
  SPL_METHOD(SplFileObject, fgetcsv)
  {
 spl_filesystem_object *intern =
 (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
 -   char delimiter = intern-u.file.delimiter, enclosure = 
 intern-u.file.enclosure;
 -   char *delim, *enclo;
 -   int d_len, e_len;
 +   char delimiter = intern-u.file.delimiter, enclosure = 
 intern-u.file.enclosure, escape
 = intern-u.file.escape;
 +   char *delim, *enclo, *esc;
 +   int d_len, e_len, esc_len;
 
 -   if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, |ss, delim, 
 d_len, enclo,
 e_len) == SUCCESS) {
 +   if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, |sss, delim, 
 d_len, enclo,
 e_len, esc, esc_len) == SUCCESS) {
 switch(ZEND_NUM_ARGS())
 {
 +   case 3:
 +   if (esc_len != 1) {
 +   php_error_docref(NULL TSRMLS_CC, 
 E_WARNING, escape
 must be a character);
 +   RETURN_FALSE;
 +   }
 +   escape = esc[0];
 +
 case 2:
 if (e_len != 1) {
 php_error_docref(NULL TSRMLS_CC, 
 E_WARNING, enclosure
 must be a character);
 @@ -2173,23 +2180,30 @@
 case 0:
 break;
 }
 -   spl_filesystem_file_read_csv(intern, delimiter, enclosure, 
 return_value
 TSRMLS_CC);
 +   spl_filesystem_file_read_csv(intern, delimiter, enclosure, 
 escape, return_value
 TSRMLS_CC);
 }
  }
  /* }}} */
  
 -/* {{{ proto void SplFileObject::setCsvControl([string delimiter = ',' [, 
 string enclosure =
 '']])
 +/* {{{ proto void SplFileObject::setCsvControl([string delimiter = ',' [, 
 string enclosure =
 '' [, string escape = '\\']]])
 Set the delimiter and enclosure character used in fgetcsv */
  SPL_METHOD(SplFileObject, setCsvControl)
  {
 spl_filesystem_object *intern =
 (spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
 -   char delimiter = ',', enclosure = '';
 -   char *delim, *enclo;
 -   int d_len, e_len;
 +   char delimiter = ',', enclosure = '', escape='\\';
 +   char *delim, *enclo, *esc;
 +   int d_len, e_len, esc_len;
 
 -   if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, |ss, delim, 
 d_len, enclo,
 e_len) == SUCCESS) {
 +   if 

[PHP-CVS] cvs: php-src /ext/spl spl_directory.c spl_directory.h

2007-03-03 Thread Marcus Boerger
helly   Sat Mar  3 21:41:56 2007 UTC

  Modified files:  
/php-src/ext/splspl_directory.c spl_directory.h 
  Log:
  - Add glob support for DirectoryIterator
  
http://cvs.php.net/viewvc.cgi/php-src/ext/spl/spl_directory.c?r1=1.124r2=1.125diff_format=u
Index: php-src/ext/spl/spl_directory.c
diff -u php-src/ext/spl/spl_directory.c:1.124 
php-src/ext/spl/spl_directory.c:1.125
--- php-src/ext/spl/spl_directory.c:1.124   Sat Mar  3 14:51:40 2007
+++ php-src/ext/spl/spl_directory.c Sat Mar  3 21:41:56 2007
@@ -16,7 +16,7 @@
+--+
  */
 
-/* $Id: spl_directory.c,v 1.124 2007/03/03 14:51:40 helly Exp $ */
+/* $Id: spl_directory.c,v 1.125 2007/03/03 21:41:56 helly Exp $ */
 
 #ifdef HAVE_CONFIG_H
 # include config.h
@@ -178,15 +178,27 @@
 /* open a directory resource */
 static void spl_filesystem_dir_open(spl_filesystem_object* intern, zend_uchar 
type, zstr path, int path_len TSRMLS_DC)
 {
+   int options = REPORT_ERRORS;
+   
+   if (intern-flags  SPL_FILE_DIR_USE_GLOB) {
+   options |= STREAM_USE_GLOB_DIR_OPEN;
+   }
+
intern-type = SPL_FS_DIR;
intern-path_type= type;
intern-path_len = path_len;
-   intern-u.dir.dirp = php_stream_u_opendir(type, path, path_len, 
REPORT_ERRORS, NULL);
+   intern-u.dir.dirp = php_stream_u_opendir(type, path, path_len, 
options, NULL);
 
-   if (intern-path_len  IS_SLASH_AT(type, path, intern-path_len-1)) {
+   if (php_stream_is(intern-u.dir.dirp, php_glob_stream_ops)) {
+   intern-path.s = php_glob_stream_get_path(intern-u.dir.dirp, 
1, intern-path_len);
+   intern-path_type = IS_STRING;
+   intern-flags |= SPL_FILE_DIR_USE_GLOB;
+   } else if (intern-path_len  IS_SLASH_AT(type, path, 
intern-path_len-1)) {
intern-path = ezstrndup(type, path, --intern-path_len);
+   intern-flags = ~SPL_FILE_DIR_USE_GLOB;
} else {
intern-path = ezstrndup(type, path, intern-path_len);
+   intern-flags = ~SPL_FILE_DIR_USE_GLOB;
}
intern-u.dir.index = 0;
 
@@ -518,7 +530,7 @@
 }
 /*  */
 
-/* {{{ proto void DirectoryIterator::__construct(string path) U
+/* {{{ proto void DirectoryIterator::__construct(string $path, [int $flags = 
0]) U
  Cronstructs a new dir iterator from a path. */
 SPL_METHOD(DirectoryIterator, __construct)
 {
@@ -526,10 +538,11 @@
zstr path;
int len;
zend_uchar path_type;
+   long flags = 0;

php_set_error_handling(EH_THROW, spl_ce_RuntimeException TSRMLS_CC);
 
-   if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, t, path, len, 
path_type) == FAILURE) {
+   if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, t|l, path, 
len, path_type, flags) == FAILURE) {
php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC);
return;
}
@@ -542,10 +555,10 @@
 
intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() 
TSRMLS_CC);
 
+   intern-flags = flags;
spl_filesystem_dir_open(intern, path_type, path, len TSRMLS_CC);
 
intern-u.dir.is_recursive = instanceof_function(intern-std.ce, 
spl_ce_RecursiveDirectoryIterator TSRMLS_CC) ? 1 : 0;
-   intern-flags = 0;
 
php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC);
 }
@@ -1077,9 +1090,9 @@
}
 
intern = (spl_filesystem_object*)zend_object_store_get_object(getThis() 
TSRMLS_CC);
-   spl_filesystem_dir_open(intern, path_type, path, path_len TSRMLS_CC);
intern-u.dir.is_recursive = instanceof_function(intern-std.ce, 
spl_ce_RecursiveDirectoryIterator TSRMLS_CC) ? 1 : 0;
intern-flags = flags;
+   spl_filesystem_dir_open(intern, path_type, path, path_len TSRMLS_CC);
 
php_set_error_handling(EH_NORMAL, NULL TSRMLS_CC);
 }
@@ -1151,17 +1164,32 @@
Returns an iterator for the current entry if it is a directory */
 SPL_METHOD(RecursiveDirectoryIterator, getChildren)
 {
-   zval zpath;
+   zval zpath, zflags;
spl_filesystem_object *intern = 
(spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
spl_filesystem_object *subdir;

spl_filesystem_object_get_file_name(intern TSRMLS_CC);
 
+   INIT_PZVAL(zflags);
+   ZVAL_LONG(zflags, intern-flags);
+
INIT_PZVAL(zpath);
-   ZVAL_ZSTRL(zpath, intern-file_name_type, intern-file_name, 
intern-file_name_len, 0);
+   if (intern-flags  SPL_FILE_DIR_USE_GLOB) {
+   Z_TYPE(zpath) = IS_STRING;
+   spprintf(Z_STRVAL(zpath), 0, %R%c%s,
+   intern-file_name_type, intern-file_name,
+   DEFAULT_SLASH,
+   php_glob_stream_get_pattern(intern-u.dir.dirp, 0, 
NULL));
+   } else {
+   ZVAL_ZSTRL(zpath, intern-file_name_type, intern-file_name, 
intern-file_name_len, 

[PHP-CVS] cvs: php-src /ext/spl spl_directory.c spl_directory.h

2007-03-03 Thread Marcus Boerger
helly   Sat Mar  3 23:41:43 2007 UTC

  Modified files:  
/php-src/ext/splspl_directory.c spl_directory.h 
  Log:
  - Glob might require us to refetch the path for every entry
  
http://cvs.php.net/viewvc.cgi/php-src/ext/spl/spl_directory.c?r1=1.126r2=1.127diff_format=u
Index: php-src/ext/spl/spl_directory.c
diff -u php-src/ext/spl/spl_directory.c:1.126 
php-src/ext/spl/spl_directory.c:1.127
--- php-src/ext/spl/spl_directory.c:1.126   Sat Mar  3 23:07:33 2007
+++ php-src/ext/spl/spl_directory.c Sat Mar  3 23:41:43 2007
@@ -16,7 +16,7 @@
+--+
  */
 
-/* $Id: spl_directory.c,v 1.126 2007/03/03 23:07:33 helly Exp $ */
+/* $Id: spl_directory.c,v 1.127 2007/03/03 23:41:43 helly Exp $ */
 
 #ifdef HAVE_CONFIG_H
 # include config.h
@@ -45,6 +45,14 @@
 #include ext/standard/php_filestat.h
 #include ext/standard/php_link.h
 
+#ifdef HAVE_GLOB
+# ifndef PHP_WIN32
+#  include glob.h
+# else
+#  include win32/glob.h
+# endif
+#endif
+
 /* declare the class handlers */
 static zend_object_handlers spl_filesystem_object_handlers;
 
@@ -174,11 +182,28 @@
 
 #define IS_SLASH_AT(type, zs, pos) (type == IS_UNICODE ? IS_U_SLASH(zs.u[pos]) 
: IS_SLASH(zs.s[pos]))
 
+static int spl_filesystem_dir_read(spl_filesystem_object *intern TSRMLS_DC) /* 
{{{ */
+{
+   if (!intern-u.dir.dirp || !php_stream_readdir(intern-u.dir.dirp, 
intern-u.dir.entry)) {
+   intern-u.dir.entry.d_name[0] = '\0';
+   return 0;
+   } else {
+   if (intern-flags  SPL_FILE_DIR_GLOB_REFETCH_PATH) {
+   if (intern-path.v) {
+   efree(intern-path.v);
+   }
+   intern-path.s = 
php_glob_stream_get_path(intern-u.dir.dirp, 1, intern-path_len);
+   }
+   return 1;
+   }
+}
+/* }}} */
+
 /* {{{ spl_filesystem_dir_open */
 /* open a directory resource */
 static void spl_filesystem_dir_open(spl_filesystem_object* intern, zend_uchar 
type, zstr path, int path_len TSRMLS_DC)
 {
-   int options = REPORT_ERRORS;
+   int options = REPORT_ERRORS, flags;

if (intern-flags  SPL_FILE_DIR_USE_GLOB) {
options |= STREAM_USE_GLOB_DIR_OPEN;
@@ -193,12 +218,18 @@
intern-path.s = php_glob_stream_get_path(intern-u.dir.dirp, 
1, intern-path_len);
intern-path_type = IS_STRING;
intern-flags |= SPL_FILE_DIR_USE_GLOB;
+   php_glob_stream_get_count(intern-u.dir.dirp, flags);
+   if (flags  GLOB_APPEND) {
+   intern-flags |= SPL_FILE_DIR_GLOB_REFETCH_PATH;
+   } else {
+   intern-flags = ~SPL_FILE_DIR_GLOB_REFETCH_PATH;
+   }
} else if (intern-path_len  IS_SLASH_AT(type, path, 
intern-path_len-1)) {
intern-path = ezstrndup(type, path, --intern-path_len);
-   intern-flags = ~SPL_FILE_DIR_USE_GLOB;
+   intern-flags = 
~(SPL_FILE_DIR_USE_GLOB|SPL_FILE_DIR_GLOB_REFETCH_PATH);
} else {
intern-path = ezstrndup(type, path, intern-path_len);
-   intern-flags = ~SPL_FILE_DIR_USE_GLOB;
+   intern-flags = 
~(SPL_FILE_DIR_USE_GLOB|SPL_FILE_DIR_GLOB_REFETCH_PATH);
}
intern-u.dir.index = 0;
 
@@ -206,9 +237,7 @@
/* throw exception: should've been already happened */
intern-u.dir.entry.d_name[0] = '\0';
} else {
-   if (!php_stream_readdir(intern-u.dir.dirp, 
intern-u.dir.entry)) {
-   intern-u.dir.entry.d_name[0] = '\0';
-   }
+   spl_filesystem_dir_read(intern TSRMLS_CC);
}
 }
 /* }}} */
@@ -574,9 +603,8 @@
if (intern-u.dir.dirp) {
php_stream_rewinddir(intern-u.dir.dirp);
}
-   if (!intern-u.dir.dirp || !php_stream_readdir(intern-u.dir.dirp, 
intern-u.dir.entry)) {
-   intern-u.dir.entry.d_name[0] = '\0';
-   }
+
+   spl_filesystem_dir_read(intern TSRMLS_CC);
 }
 /* }}} */
 
@@ -609,9 +637,7 @@
spl_filesystem_object *intern = 
(spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
 
intern-u.dir.index++;
-   if (!intern-u.dir.dirp || !php_stream_readdir(intern-u.dir.dirp, 
intern-u.dir.entry)) {
-   intern-u.dir.entry.d_name[0] = '\0';
-   }
+   spl_filesystem_dir_read(intern TSRMLS_CC);
if (intern-file_name.v) {
efree(intern-file_name.v);
intern-file_name = NULL_ZSTR;
@@ -636,7 +662,7 @@
spl_filesystem_object *intern = 
(spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
 
if (intern-flags  SPL_FILE_DIR_USE_GLOB) {
-   RETURN_LONG(php_glob_stream_get_count(intern-u.dir.dirp));
+   RETURN_LONG(php_glob_stream_get_count(intern-u.dir.dirp, 

[PHP-CVS] cvs: php-src /ext/spl spl_directory.c spl_directory.h

2007-03-03 Thread Marcus Boerger
helly   Sun Mar  4 00:23:07 2007 UTC

  Modified files:  
/php-src/ext/splspl_directory.c spl_directory.h 
  Log:
  - Fix a minor issue with glob support - forgot to set length of string 
  - Add ability to not use glob on subdirs
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/spl/spl_directory.c?r1=1.127r2=1.128diff_format=u
Index: php-src/ext/spl/spl_directory.c
diff -u php-src/ext/spl/spl_directory.c:1.127 
php-src/ext/spl/spl_directory.c:1.128
--- php-src/ext/spl/spl_directory.c:1.127   Sat Mar  3 23:41:43 2007
+++ php-src/ext/spl/spl_directory.c Sun Mar  4 00:23:07 2007
@@ -16,7 +16,7 @@
+--+
  */
 
-/* $Id: spl_directory.c,v 1.127 2007/03/03 23:41:43 helly Exp $ */
+/* $Id: spl_directory.c,v 1.128 2007/03/04 00:23:07 helly Exp $ */
 
 #ifdef HAVE_CONFIG_H
 # include config.h
@@ -1206,24 +1206,22 @@
spl_filesystem_object_get_file_name(intern TSRMLS_CC);
 
INIT_PZVAL(zflags);
-   ZVAL_LONG(zflags, intern-flags);
-
INIT_PZVAL(zpath);
-   if (intern-flags  SPL_FILE_DIR_USE_GLOB) {
+   if ((intern-flags  
(SPL_FILE_DIR_USE_GLOB|SPL_FILE_DIR_NO_GLOB_CHILD)) == SPL_FILE_DIR_USE_GLOB) {
+   ZVAL_LONG(zflags, intern-flags);
Z_TYPE(zpath) = IS_STRING;
-   spprintf(Z_STRVAL(zpath), 0, %R%c%s,
+   Z_STRLEN(zpath) = spprintf(Z_STRVAL(zpath), 0, %R%c%s,
intern-file_name_type, intern-file_name,
DEFAULT_SLASH,
php_glob_stream_get_pattern(intern-u.dir.dirp, 0, 
NULL));
} else {
-   ZVAL_ZSTRL(zpath, intern-file_name_type, intern-file_name, 
intern-file_name_len, 0);
+   ZVAL_LONG(zflags, intern-flags  ~SPL_FILE_DIR_USE_GLOB);
+   ZVAL_ZSTRL(zpath, intern-file_name_type, intern-file_name, 
intern-file_name_len, 1);
}
 
spl_instantiate_arg_ex2(spl_ce_RecursiveDirectoryIterator, 
return_value, 0, zpath, zflags TSRMLS_CC);
 
-   if (intern-flags  SPL_FILE_DIR_USE_GLOB) {
-   efree(Z_STRVAL(zpath));
-   }
+   zval_dtor(zpath);
 
subdir = 
(spl_filesystem_object*)zend_object_store_get_object(return_value TSRMLS_CC);
if (subdir) {
@@ -2509,7 +2507,8 @@
REGISTER_SPL_SUB_CLASS_EX(DirectoryIterator, SplFileInfo, 
spl_filesystem_object_new, spl_DirectoryIterator_functions);
zend_class_implements(spl_ce_DirectoryIterator TSRMLS_CC, 1, 
zend_ce_iterator);
 
-   REGISTER_SPL_CLASS_CONST_LONG(DirectoryIterator, USE_GLOB, 
SPL_FILE_DIR_USE_GLOB);
+   REGISTER_SPL_CLASS_CONST_LONG(DirectoryIterator, USE_GLOB,
SPL_FILE_DIR_USE_GLOB);
+   REGISTER_SPL_CLASS_CONST_LONG(DirectoryIterator, NO_GLOB_CHILD,   
SPL_FILE_DIR_NO_GLOB_CHILD);
 
spl_ce_DirectoryIterator-get_iterator = 
spl_filesystem_dir_get_iterator;
 
http://cvs.php.net/viewvc.cgi/php-src/ext/spl/spl_directory.h?r1=1.31r2=1.32diff_format=u
Index: php-src/ext/spl/spl_directory.h
diff -u php-src/ext/spl/spl_directory.h:1.31 
php-src/ext/spl/spl_directory.h:1.32
--- php-src/ext/spl/spl_directory.h:1.31Sat Mar  3 23:41:43 2007
+++ php-src/ext/spl/spl_directory.h Sun Mar  4 00:23:07 2007
@@ -16,7 +16,7 @@
+--+
  */
 
-/* $Id: spl_directory.h,v 1.31 2007/03/03 23:41:43 helly Exp $ */
+/* $Id: spl_directory.h,v 1.32 2007/03/04 00:23:07 helly Exp $ */
 
 #ifndef SPL_DIRECTORY_H
 #define SPL_DIRECTORY_H
@@ -122,6 +122,7 @@
 
 #define SPL_FILE_DIR_USE_GLOB  0x1000 /* use glob for open 
dir*/
 #define SPL_FILE_DIR_GLOB_REFETCH_PATH 0x2000 /* whether we need to 
refetch the path in glob mode */
+#define SPL_FILE_DIR_NO_GLOB_CHILD 0x4000 /* do not use glob on 
childs */
 
 #endif /* SPL_DIRECTORY_H */
 

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-CVS] cvs: php-src /ext/spl spl_directory.c spl_directory.h

2007-03-03 Thread Marcus Boerger
helly   Sun Mar  4 00:36:08 2007 UTC

  Modified files:  
/php-src/ext/splspl_directory.c spl_directory.h 
  Log:
  - Reverting glob on child logic makes globbing work better with the example
code
  
  
http://cvs.php.net/viewvc.cgi/php-src/ext/spl/spl_directory.c?r1=1.128r2=1.129diff_format=u
Index: php-src/ext/spl/spl_directory.c
diff -u php-src/ext/spl/spl_directory.c:1.128 
php-src/ext/spl/spl_directory.c:1.129
--- php-src/ext/spl/spl_directory.c:1.128   Sun Mar  4 00:23:07 2007
+++ php-src/ext/spl/spl_directory.c Sun Mar  4 00:36:08 2007
@@ -16,7 +16,7 @@
+--+
  */
 
-/* $Id: spl_directory.c,v 1.128 2007/03/04 00:23:07 helly Exp $ */
+/* $Id: spl_directory.c,v 1.129 2007/03/04 00:36:08 helly Exp $ */
 
 #ifdef HAVE_CONFIG_H
 # include config.h
@@ -1207,7 +1207,7 @@
 
INIT_PZVAL(zflags);
INIT_PZVAL(zpath);
-   if ((intern-flags  
(SPL_FILE_DIR_USE_GLOB|SPL_FILE_DIR_NO_GLOB_CHILD)) == SPL_FILE_DIR_USE_GLOB) {
+   if ((intern-flags  (SPL_FILE_DIR_USE_GLOB|SPL_FILE_DIR_CHILD_GLOB)) 
== (SPL_FILE_DIR_USE_GLOB|SPL_FILE_DIR_CHILD_GLOB)) {
ZVAL_LONG(zflags, intern-flags);
Z_TYPE(zpath) = IS_STRING;
Z_STRLEN(zpath) = spprintf(Z_STRVAL(zpath), 0, %R%c%s,
@@ -1215,7 +1215,7 @@
DEFAULT_SLASH,
php_glob_stream_get_pattern(intern-u.dir.dirp, 0, 
NULL));
} else {
-   ZVAL_LONG(zflags, intern-flags  ~SPL_FILE_DIR_USE_GLOB);
+   ZVAL_LONG(zflags, intern-flags  
~(SPL_FILE_DIR_USE_GLOB|SPL_FILE_DIR_CHILD_GLOB));
ZVAL_ZSTRL(zpath, intern-file_name_type, intern-file_name, 
intern-file_name_len, 1);
}
 
@@ -2508,7 +2508,7 @@
zend_class_implements(spl_ce_DirectoryIterator TSRMLS_CC, 1, 
zend_ce_iterator);
 
REGISTER_SPL_CLASS_CONST_LONG(DirectoryIterator, USE_GLOB,
SPL_FILE_DIR_USE_GLOB);
-   REGISTER_SPL_CLASS_CONST_LONG(DirectoryIterator, NO_GLOB_CHILD,   
SPL_FILE_DIR_NO_GLOB_CHILD);
+   REGISTER_SPL_CLASS_CONST_LONG(DirectoryIterator, CHILD_GLOB,  
SPL_FILE_DIR_CHILD_GLOB);
 
spl_ce_DirectoryIterator-get_iterator = 
spl_filesystem_dir_get_iterator;
 
http://cvs.php.net/viewvc.cgi/php-src/ext/spl/spl_directory.h?r1=1.32r2=1.33diff_format=u
Index: php-src/ext/spl/spl_directory.h
diff -u php-src/ext/spl/spl_directory.h:1.32 
php-src/ext/spl/spl_directory.h:1.33
--- php-src/ext/spl/spl_directory.h:1.32Sun Mar  4 00:23:07 2007
+++ php-src/ext/spl/spl_directory.h Sun Mar  4 00:36:08 2007
@@ -16,7 +16,7 @@
+--+
  */
 
-/* $Id: spl_directory.h,v 1.32 2007/03/04 00:23:07 helly Exp $ */
+/* $Id: spl_directory.h,v 1.33 2007/03/04 00:36:08 helly Exp $ */
 
 #ifndef SPL_DIRECTORY_H
 #define SPL_DIRECTORY_H
@@ -122,7 +122,7 @@
 
 #define SPL_FILE_DIR_USE_GLOB  0x1000 /* use glob for open 
dir*/
 #define SPL_FILE_DIR_GLOB_REFETCH_PATH 0x2000 /* whether we need to 
refetch the path in glob mode */
-#define SPL_FILE_DIR_NO_GLOB_CHILD 0x4000 /* do not use glob on 
childs */
+#define SPL_FILE_DIR_CHILD_GLOB0x4000 /* do use glob on childs 
*/
 
 #endif /* SPL_DIRECTORY_H */
 

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-CVS] cvs: php-src /ext/spl spl_directory.c spl_directory.h

2007-03-03 Thread Marcus Boerger
helly   Sun Mar  4 00:42:30 2007 UTC

  Modified files:  
/php-src/ext/splspl_directory.c spl_directory.h 
  Log:
  - And finally use prefix style names for consistency sake
  
http://cvs.php.net/viewvc.cgi/php-src/ext/spl/spl_directory.c?r1=1.129r2=1.130diff_format=u
Index: php-src/ext/spl/spl_directory.c
diff -u php-src/ext/spl/spl_directory.c:1.129 
php-src/ext/spl/spl_directory.c:1.130
--- php-src/ext/spl/spl_directory.c:1.129   Sun Mar  4 00:36:08 2007
+++ php-src/ext/spl/spl_directory.c Sun Mar  4 00:42:30 2007
@@ -16,7 +16,7 @@
+--+
  */
 
-/* $Id: spl_directory.c,v 1.129 2007/03/04 00:36:08 helly Exp $ */
+/* $Id: spl_directory.c,v 1.130 2007/03/04 00:42:30 helly Exp $ */
 
 #ifdef HAVE_CONFIG_H
 # include config.h
@@ -205,7 +205,7 @@
 {
int options = REPORT_ERRORS, flags;

-   if (intern-flags  SPL_FILE_DIR_USE_GLOB) {
+   if (intern-flags  SPL_FILE_DIR_GLOB_USE) {
options |= STREAM_USE_GLOB_DIR_OPEN;
}
 
@@ -217,7 +217,7 @@
if (intern-u.dir.dirp  php_stream_is(intern-u.dir.dirp, 
php_glob_stream_ops)) {
intern-path.s = php_glob_stream_get_path(intern-u.dir.dirp, 
1, intern-path_len);
intern-path_type = IS_STRING;
-   intern-flags |= SPL_FILE_DIR_USE_GLOB;
+   intern-flags |= SPL_FILE_DIR_GLOB_USE;
php_glob_stream_get_count(intern-u.dir.dirp, flags);
if (flags  GLOB_APPEND) {
intern-flags |= SPL_FILE_DIR_GLOB_REFETCH_PATH;
@@ -226,10 +226,10 @@
}
} else if (intern-path_len  IS_SLASH_AT(type, path, 
intern-path_len-1)) {
intern-path = ezstrndup(type, path, --intern-path_len);
-   intern-flags = 
~(SPL_FILE_DIR_USE_GLOB|SPL_FILE_DIR_GLOB_REFETCH_PATH);
+   intern-flags = 
~(SPL_FILE_DIR_GLOB_USE|SPL_FILE_DIR_GLOB_REFETCH_PATH);
} else {
intern-path = ezstrndup(type, path, intern-path_len);
-   intern-flags = 
~(SPL_FILE_DIR_USE_GLOB|SPL_FILE_DIR_GLOB_REFETCH_PATH);
+   intern-flags = 
~(SPL_FILE_DIR_GLOB_USE|SPL_FILE_DIR_GLOB_REFETCH_PATH);
}
intern-u.dir.index = 0;
 
@@ -661,7 +661,7 @@
 {
spl_filesystem_object *intern = 
(spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
 
-   if (intern-flags  SPL_FILE_DIR_USE_GLOB) {
+   if (intern-flags  SPL_FILE_DIR_GLOB_USE) {
RETURN_LONG(php_glob_stream_get_count(intern-u.dir.dirp, 
NULL));
}
zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, Unable 
to determine count unless USE_GLOG flag is in effect);
@@ -1207,7 +1207,7 @@
 
INIT_PZVAL(zflags);
INIT_PZVAL(zpath);
-   if ((intern-flags  (SPL_FILE_DIR_USE_GLOB|SPL_FILE_DIR_CHILD_GLOB)) 
== (SPL_FILE_DIR_USE_GLOB|SPL_FILE_DIR_CHILD_GLOB)) {
+   if ((intern-flags  (SPL_FILE_DIR_GLOB_USE|SPL_FILE_DIR_GLOB_CHILD)) 
== (SPL_FILE_DIR_GLOB_USE|SPL_FILE_DIR_GLOB_CHILD)) {
ZVAL_LONG(zflags, intern-flags);
Z_TYPE(zpath) = IS_STRING;
Z_STRLEN(zpath) = spprintf(Z_STRVAL(zpath), 0, %R%c%s,
@@ -1215,7 +1215,7 @@
DEFAULT_SLASH,
php_glob_stream_get_pattern(intern-u.dir.dirp, 0, 
NULL));
} else {
-   ZVAL_LONG(zflags, intern-flags  
~(SPL_FILE_DIR_USE_GLOB|SPL_FILE_DIR_CHILD_GLOB));
+   ZVAL_LONG(zflags, intern-flags  
~(SPL_FILE_DIR_GLOB_USE|SPL_FILE_DIR_GLOB_CHILD));
ZVAL_ZSTRL(zpath, intern-file_name_type, intern-file_name, 
intern-file_name_len, 1);
}
 
@@ -2507,8 +2507,8 @@
REGISTER_SPL_SUB_CLASS_EX(DirectoryIterator, SplFileInfo, 
spl_filesystem_object_new, spl_DirectoryIterator_functions);
zend_class_implements(spl_ce_DirectoryIterator TSRMLS_CC, 1, 
zend_ce_iterator);
 
-   REGISTER_SPL_CLASS_CONST_LONG(DirectoryIterator, USE_GLOB,
SPL_FILE_DIR_USE_GLOB);
-   REGISTER_SPL_CLASS_CONST_LONG(DirectoryIterator, CHILD_GLOB,  
SPL_FILE_DIR_CHILD_GLOB);
+   REGISTER_SPL_CLASS_CONST_LONG(DirectoryIterator, GLOB,
SPL_FILE_DIR_GLOB_USE);
+   REGISTER_SPL_CLASS_CONST_LONG(DirectoryIterator, GLOB_CHILD,  
SPL_FILE_DIR_GLOB_CHILD);
 
spl_ce_DirectoryIterator-get_iterator = 
spl_filesystem_dir_get_iterator;
 
http://cvs.php.net/viewvc.cgi/php-src/ext/spl/spl_directory.h?r1=1.33r2=1.34diff_format=u
Index: php-src/ext/spl/spl_directory.h
diff -u php-src/ext/spl/spl_directory.h:1.33 
php-src/ext/spl/spl_directory.h:1.34
--- php-src/ext/spl/spl_directory.h:1.33Sun Mar  4 00:36:08 2007
+++ php-src/ext/spl/spl_directory.h Sun Mar  4 00:42:30 2007
@@ -16,7 +16,7 @@
+--+
  */
 
-/* $Id: spl_directory.h,v 1.33 2007/03/04 00:36:08 helly 

Re: [PHP-CVS] cvs: php-src /ext/spl spl_directory.c spl_directory.h

2007-01-17 Thread Andrei Zmievski

+   if (intern-file_name.v) {
+   efree(intern-file_name.s);


Why not be consistent here and free intern-file_name.v?


-   if (!intern-file_name) {
+   if (!intern-file_name.s) {


I think it's clearer to check for intern-file_name.v, because  
otherwise it looks like you care only about .s part of the union.



+#if defined(PHP_WIN32) || defined(NETWARE)
+# define is_slash(c) (c == '/' || c == '\\')
+#else
+# define is_slash(c) (c == '/')
+#endif
+
+#define is_slash_at(type, zs, pos) (type == IS_UNICODE ? is_slash 
(zs.u[pos]) : is_slash(zs.s[pos]))


We already have these macros in tsrm_virtual_cwd.c (IS_SLASH,  
IS_U_SLASH, etc).


-Andrei


On Jan 16, 2007, at 3:52 PM, Marcus Boerger wrote:


helly   Tue Jan 16 23:52:14 2007 UTC

  Modified files:
/php-src/ext/splspl_directory.c spl_directory.h
  Log:
  - Steps towards unicode
helly-20070116235214.txt
--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


--
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-CVS] cvs: php-src /ext/spl spl_directory.c spl_directory.h

2007-01-16 Thread Marcus Boerger
helly   Tue Jan 16 23:52:14 2007 UTC

  Modified files:  
/php-src/ext/splspl_directory.c spl_directory.h 
  Log:
  - Steps towards unicode
  http://cvs.php.net/viewvc.cgi/php-src/ext/spl/spl_directory.c?r1=1.108r2=1.109diff_format=u
Index: php-src/ext/spl/spl_directory.c
diff -u php-src/ext/spl/spl_directory.c:1.108 
php-src/ext/spl/spl_directory.c:1.109
--- php-src/ext/spl/spl_directory.c:1.108   Mon Jan  1 09:29:29 2007
+++ php-src/ext/spl/spl_directory.c Tue Jan 16 23:52:14 2007
@@ -16,7 +16,7 @@
+--+
  */
 
-/* $Id: spl_directory.c,v 1.108 2007/01/01 09:29:29 sebastian Exp $ */
+/* $Id: spl_directory.c,v 1.109 2007/01/16 23:52:14 helly Exp $ */
 
 #ifdef HAVE_CONFIG_H
 # include config.h
@@ -76,11 +76,11 @@

zend_object_std_dtor(intern-std TSRMLS_CC);

-   if (intern-path) {
-   efree(intern-path);
+   if (intern-path.v) {
+   efree(intern-path.s);
}
-   if (intern-file_name) {
-   efree(intern-file_name);
+   if (intern-file_name.v) {
+   efree(intern-file_name.s);
}
switch(intern-type) {
case SPL_FS_INFO:
@@ -90,8 +90,8 @@
php_stream_close(intern-u.dir.dirp);
intern-u.dir.dirp = NULL;
}
-   if (intern-u.dir.sub_path) {
-   efree(intern-u.dir.sub_path);
+   if (intern-u.dir.sub_path.s) {
+   efree(intern-u.dir.sub_path.s);
}   
break;
case SPL_FS_FILE:
@@ -157,35 +157,45 @@
 
 static inline void spl_filesystem_object_get_file_name(spl_filesystem_object 
*intern TSRMLS_DC) /* {{{ */
 {
-   if (!intern-file_name) {
+   if (!intern-file_name.s) {
switch (intern-type) {
case SPL_FS_INFO:
case SPL_FS_FILE:
php_error_docref(NULL TSRMLS_CC, E_ERROR, Object not 
initialized);
break;
case SPL_FS_DIR:
-   intern-file_name_len = spprintf(intern-file_name, 0, 
%s%c%s, intern-path, DEFAULT_SLASH, intern-u.dir.entry.d_name);
+   if (intern-path_type == IS_UNICODE) {
+   intern-file_name_len = 
spprintf(intern-file_name.s, 0, %s%c%s, intern-path, DEFAULT_SLASH, 
intern-u.dir.entry.d_name);
+   } else {
+   intern-file_name_len = 
uspprintf(intern-file_name.s, 0, %r%c%s, intern-path, DEFAULT_SLASH, 
intern-u.dir.entry.d_name);
+   }
+   intern-file_name_type = intern-path_type;
break;
}
}
 } /* }}} */
 
+#if defined(PHP_WIN32) || defined(NETWARE)
+# define is_slash(c) (c == '/' || c == '\\')
+#else
+# define is_slash(c) (c == '/')
+#endif
+
+#define is_slash_at(type, zs, pos) (type == IS_UNICODE ? is_slash(zs.u[pos]) : 
is_slash(zs.s[pos]))
+
 /* {{{ spl_filesystem_dir_open */
 /* open a directory resource */
-static void spl_filesystem_dir_open(spl_filesystem_object* intern, char *path 
TSRMLS_DC)
+static void spl_filesystem_dir_open(spl_filesystem_object* intern, zend_uchar 
type, zstr path, int path_len TSRMLS_DC)
 {
intern-type = SPL_FS_DIR;
-   intern-path_len = strlen(path);
-   intern-u.dir.dirp = php_stream_opendir(path, REPORT_ERRORS, NULL);
+   intern-path_type= type;
+   intern-path_len = path_len;
+   intern-u.dir.dirp = php_stream_u_opendir(type, path, path_len, 
REPORT_ERRORS, NULL);
 
-   if (intern-path_len  (path[intern-path_len-1] == '/'
-#if defined(PHP_WIN32) || defined(NETWARE)
-   || path[intern-path_len-1] == '\\'
-#endif
-   )) {
-   intern-path = estrndup(path, --intern-path_len);
+   if (intern-path_len  is_slash_at(type, path, intern-path_len-1)) {
+   intern-path = ezstrndup(type, path, --intern-path_len);
} else {
-   intern-path = estrndup(path, intern-path_len);
+   intern-path = ezstrndup(type, path, intern-path_len);
}
intern-u.dir.index = 0;
 
@@ -204,13 +214,13 @@
 {
intern-type = SPL_FS_FILE;
intern-u.file.context = 
php_stream_context_from_zval(intern-u.file.zcontext, 0);
-   intern-u.file.stream = php_stream_open_wrapper_ex(intern-file_name, 
intern-u.file.open_mode, (use_include_path ? USE_PATH : 0) | REPORT_ERRORS, 
NULL, intern-u.file.context);
+   intern-u.file.stream = 
php_stream_u_open_wrapper(intern-file_name_type, intern-file_name, 
intern-file_name_len, intern-u.file.open_mode, (use_include_path ? USE_PATH : 
0) | REPORT_ERRORS, NULL, intern-u.file.context);
 
if (!intern-file_name_len || !intern-u.file.stream) {
if (!EG(exception)) {
-   

[PHP-CVS] cvs: php-src /ext/spl spl_directory.c spl_directory.h

2006-11-12 Thread Marcus Boerger
helly   Sun Nov 12 17:56:14 2006 UTC

  Modified files:  
/php-src/ext/splspl_directory.c spl_directory.h 
  Log:
  - Optimize SPL directory stuff by making iterator part of object
  http://cvs.php.net/viewvc.cgi/php-src/ext/spl/spl_directory.c?r1=1.104r2=1.105diff_format=u
Index: php-src/ext/spl/spl_directory.c
diff -u php-src/ext/spl/spl_directory.c:1.104 
php-src/ext/spl/spl_directory.c:1.105
--- php-src/ext/spl/spl_directory.c:1.104   Sun Nov 12 17:08:45 2006
+++ php-src/ext/spl/spl_directory.c Sun Nov 12 17:56:14 2006
@@ -16,7 +16,7 @@
+--+
  */
 
-/* $Id: spl_directory.c,v 1.104 2006/11/12 17:08:45 bjori Exp $ */
+/* $Id: spl_directory.c,v 1.105 2006/11/12 17:56:14 helly Exp $ */
 
 #ifdef HAVE_CONFIG_H
 # include config.h
@@ -88,6 +88,7 @@
case SPL_FS_DIR:
if (intern-u.dir.dirp) {
php_stream_close(intern-u.dir.dirp);
+   intern-u.dir.dirp = NULL;
}
if (intern-u.dir.sub_path) {
efree(intern-u.dir.sub_path);
@@ -977,13 +978,6 @@
 }
 /* }}} */
 
-/* define an overloaded iterator structure */
-typedef struct {
-   zend_object_iterator  intern;
-   zval  *current;
-   spl_filesystem_object *object;
-} spl_filesystem_dir_it;
-
 /* forward declarations to the iterator handlers */
 static void spl_filesystem_dir_it_dtor(zend_object_iterator *iter TSRMLS_DC);
 static int spl_filesystem_dir_it_valid(zend_object_iterator *iter TSRMLS_DC);
@@ -1005,20 +999,19 @@
 /* {{{ spl_ce_dir_get_iterator */
 zend_object_iterator *spl_filesystem_dir_get_iterator(zend_class_entry *ce, 
zval *object, int by_ref TSRMLS_DC)
 {
-   spl_filesystem_dir_it *iterator;
-   spl_filesystem_object *dir_object;
+   spl_filesystem_iterator *iterator;
+   spl_filesystem_object   *dir_object;
 
if (by_ref) {
zend_error(E_ERROR, An iterator cannot be used with foreach by 
reference);
}
-   iterator   = emalloc(sizeof(spl_filesystem_dir_it));
dir_object = 
(spl_filesystem_object*)zend_object_store_get_object(object TSRMLS_CC);
+   iterator   = spl_filesystem_object_to_iterator(dir_object);
 
-   object-refcount += 2;;
+   object-refcount += 2;
iterator-intern.data = (void*)object;
iterator-intern.funcs = spl_filesystem_dir_it_funcs;
iterator-current = object;
-   iterator-object = dir_object;

return (zend_object_iterator*)iterator;
 }
@@ -1027,20 +1020,18 @@
 /* {{{ spl_filesystem_dir_it_dtor */
 static void spl_filesystem_dir_it_dtor(zend_object_iterator *iter TSRMLS_DC)
 {
-   spl_filesystem_dir_it *iterator = (spl_filesystem_dir_it *)iter;
+   spl_filesystem_iterator *iterator = (spl_filesystem_iterator *)iter;
 
zval_ptr_dtor(iterator-current);
zval_ptr_dtor((zval**)iterator-intern.data);
-
-   efree(iterator);
+   iterator-intern.data = NULL; /* mark as unused */
 }
 /* }}} */

 /* {{{ spl_filesystem_dir_it_valid */
 static int spl_filesystem_dir_it_valid(zend_object_iterator *iter TSRMLS_DC)
 {
-   spl_filesystem_dir_it *iterator = (spl_filesystem_dir_it *)iter;
-   spl_filesystem_object *object   = iterator-object;
+   spl_filesystem_object *object = 
spl_filesystem_iterator_to_object((spl_filesystem_iterator *)iter);
 
return object-u.dir.entry.d_name[0] != '\0' ? SUCCESS : FAILURE;
 }
@@ -1050,7 +1041,7 @@
 /* {{{ spl_filesystem_dir_it_current_data */
 static void spl_filesystem_dir_it_current_data(zend_object_iterator *iter, 
zval ***data TSRMLS_DC)
 {
-   spl_filesystem_dir_it *iterator = (spl_filesystem_dir_it *)iter;
+   spl_filesystem_iterator *iterator = (spl_filesystem_iterator *)iter;

*data = iterator-current;
 }
@@ -1059,8 +1050,7 @@
 /* {{{ spl_filesystem_dir_it_current_key */
 static int spl_filesystem_dir_it_current_key(zend_object_iterator *iter, zstr 
*str_key, uint *str_key_len, ulong *int_key TSRMLS_DC)
 {
-   spl_filesystem_dir_it *iterator = (spl_filesystem_dir_it *)iter;
-   spl_filesystem_object *object   = iterator-object;
+   spl_filesystem_object *object = 
spl_filesystem_iterator_to_object((spl_filesystem_iterator *)iter);

*int_key = object-u.dir.index;
return HASH_KEY_IS_LONG;
@@ -1070,8 +1060,7 @@
 /* {{{ spl_filesystem_dir_it_move_forward */
 static void spl_filesystem_dir_it_move_forward(zend_object_iterator *iter 
TSRMLS_DC)
 {
-   spl_filesystem_dir_it *iterator = (spl_filesystem_dir_it *)iter;
-   spl_filesystem_object *object   = iterator-object;
+   spl_filesystem_object *object = 
spl_filesystem_iterator_to_object((spl_filesystem_iterator *)iter);

object-u.dir.index++;
if (!object-u.dir.dirp || !php_stream_readdir(object-u.dir.dirp, 
object-u.dir.entry)) {
@@ -1087,8 

[PHP-CVS] cvs: php-src /ext/spl spl_directory.c spl_directory.h

2006-03-09 Thread Marcus Boerger
helly   Thu Mar  9 23:03:08 2006 UTC

  Modified files:  
/php-src/ext/splspl_directory.c spl_directory.h 
  Log:
  - Add read ahead ability
  - Add skipping empty lines
  - Add ability to read lines as csv
  
  http://cvs.php.net/viewcvs.cgi/php-src/ext/spl/spl_directory.c?r1=1.84r2=1.85diff_format=u
Index: php-src/ext/spl/spl_directory.c
diff -u php-src/ext/spl/spl_directory.c:1.84 
php-src/ext/spl/spl_directory.c:1.85
--- php-src/ext/spl/spl_directory.c:1.84Wed Mar  8 20:30:12 2006
+++ php-src/ext/spl/spl_directory.c Thu Mar  9 23:03:08 2006
@@ -16,7 +16,7 @@
+--+
  */
 
-/* $Id: spl_directory.c,v 1.84 2006/03/08 20:30:12 helly Exp $ */
+/* $Id: spl_directory.c,v 1.85 2006/03/09 23:03:08 helly Exp $ */
 
 #ifdef HAVE_CONFIG_H
 # include config.h
@@ -1368,19 +1368,89 @@
return SUCCESS;
 } /* }}} */
 
-static int spl_filesystem_file_read_line(zval * this_ptr, 
spl_filesystem_object *intern, int silent TSRMLS_DC) /* {{{ */
+static int spl_filesystem_file_call(spl_filesystem_object *intern, 
zend_function *func_ptr, int pass_num_args, zval *return_value, zval *arg2 
TSRMLS_DC) /* {{{ */
+{
+   zend_fcall_info fci;
+   zend_fcall_info_cache fcic;
+   zval z_fname;
+   zval * zresource_ptr = intern-u.file.zresource, *retval;
+   int result;
+   int num_args = pass_num_args + (arg2 ? 2 : 1);
+
+   zval ***params = (zval***)safe_emalloc(num_args, sizeof(zval**), 0);
+
+   params[0] = zresource_ptr;
+   
+   if (arg2) {
+   params[1] = arg2;
+   }
+
+   zend_get_parameters_array_ex(pass_num_args, params+(arg2 ? 2 : 1));
+
+   ZVAL_STRING(z_fname, func_ptr-common.function_name.s, 0);
+
+   fci.size = sizeof(fci);
+   fci.function_table = EG(function_table);
+   fci.object_pp = NULL;
+   fci.function_name = z_fname;
+   fci.retval_ptr_ptr = retval;
+   fci.param_count = num_args;
+   fci.params = params;
+   fci.no_separation = 1;
+   fci.symbol_table = NULL;
+
+   fcic.initialized = 1;
+   fcic.function_handler = func_ptr;
+   fcic.calling_scope = NULL;
+   fcic.object_pp = NULL;
+
+   result = zend_call_function(fci, fcic TSRMLS_CC);
+   
+   ZVAL_ZVAL(return_value, retval, 1, 1);
+
+   efree(params);
+   return result;
+} /* }}} */
+
+#define FileFunctionCall(func_name, pass_num_args, arg2) \
+{ \
+   zend_function *func_ptr; \
+   zend_hash_find(EG(function_table), #func_name, sizeof(#func_name), 
(void **) func_ptr); \
+   spl_filesystem_file_call(intern, func_ptr, pass_num_args, return_value, 
arg2 TSRMLS_CC); \
+}
+
+static void spl_filesystem_file_read_csv(zval * this_ptr, 
spl_filesystem_object *intern, int pass_num_args, zval *return_value TSRMLS_DC) 
/* {{{ */
+{
+   zval *arg2 = NULL;
+   MAKE_STD_ZVAL(arg2);
+   ZVAL_LONG(arg2, intern-u.file.max_line_len);
+
+   spl_filesystem_file_free_line(intern TSRMLS_CC);
+
+   FileFunctionCall(fgetcsv, pass_num_args, arg2);
+
+   zval_ptr_dtor(arg2);
+}
+/* }}} */
+
+static int spl_filesystem_file_read_line_ex(zval * this_ptr, 
spl_filesystem_object *intern, int silent TSRMLS_DC) /* {{{ */
 {
zval *retval;
 
-   /* if overloaded call the function, otherwise do it directly */
-   if (intern-u.file.func_getCurr-common.scope != spl_ce_SplFileObject) {
+   /* 1) use fgetcsv? 2) overloaded call the function, 3) do it directly */
+   if (intern-flags  SPL_FILE_OBJECT_READ_CSV || 
intern-u.file.func_getCurr-common.scope != spl_ce_SplFileObject) {
if (php_stream_eof(intern-u.file.stream)) {
if (!silent) {

zend_throw_exception_ex(spl_ce_RuntimeException, 0 TSRMLS_CC, Cannot read from 
file %s, intern-file_name);
}
return FAILURE;
}
-   zend_call_method_with_0_params(getThis(), 
Z_OBJCE_P(getThis()), intern-u.file.func_getCurr, getCurrentLine, retval);
+   if (intern-flags  SPL_FILE_OBJECT_READ_CSV) {
+   MAKE_STD_ZVAL(retval);
+   spl_filesystem_file_read_csv(this_ptr, intern, 0, 
retval TSRMLS_CC);
+   } else {
+   zend_call_method_with_0_params(this_ptr, 
Z_OBJCE_P(getThis()), intern-u.file.func_getCurr, getCurrentLine, retval);
+   }
if (retval) {
if (intern-u.file.current_line || 
intern-u.file.current_zval) {
intern-u.file.current_line_num++;
@@ -1403,7 +1473,49 @@
}
 } /* }}} */
 
-static void spl_filesystem_file_rewind(spl_filesystem_object *intern 
TSRMLS_DC) /* {{{ */
+static int spl_filesystem_file_is_empty_line(spl_filesystem_object *intern 
TSRMLS_DC) /* {{{ */
+{
+   if (intern-u.file.current_line) {
+   return 

[PHP-CVS] cvs: php-src /ext/spl spl_directory.c spl_directory.h

2006-03-08 Thread Marcus Boerger
helly   Wed Mar  8 20:06:16 2006 UTC

  Modified files:  
/php-src/ext/splspl_directory.c spl_directory.h 
  Log:
  - Something that uses void* oth might want to deinitialize it in the dtor
  
http://cvs.php.net/viewcvs.cgi/php-src/ext/spl/spl_directory.c?r1=1.82r2=1.83diff_format=u
Index: php-src/ext/spl/spl_directory.c
diff -u php-src/ext/spl/spl_directory.c:1.82 
php-src/ext/spl/spl_directory.c:1.83
--- php-src/ext/spl/spl_directory.c:1.82Wed Mar  8 00:43:28 2006
+++ php-src/ext/spl/spl_directory.c Wed Mar  8 20:06:16 2006
@@ -16,7 +16,7 @@
+--+
  */
 
-/* $Id: spl_directory.c,v 1.82 2006/03/08 00:43:28 pajoye Exp $ */
+/* $Id: spl_directory.c,v 1.83 2006/03/08 20:06:16 helly Exp $ */
 
 #ifdef HAVE_CONFIG_H
 # include config.h
@@ -70,6 +70,9 @@
 {
spl_filesystem_object *intern = (spl_filesystem_object*)object;
 
+   if (intern-oth_dtor) {
+   intern-oth_dtor(intern TSRMLS_CC);
+   }
zend_hash_destroy(intern-std.properties);
FREE_HASHTABLE(intern-std.properties);
 
@@ -1330,7 +1333,6 @@
 {
char *buf;
size_t line_len;
-   int len;
long line_add = (intern-u.file.current_line || 
intern-u.file.current_zval) ? 1 : 0;
 
spl_filesystem_file_free_line(intern TSRMLS_CC);
@@ -1823,7 +1825,6 @@
spl_filesystem_object *intern = 
(spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
char *str;
int str_len;
-   int ret;
long length = 0;
 
if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, s|l, str, 
str_len, length) == FAILURE) {
http://cvs.php.net/viewcvs.cgi/php-src/ext/spl/spl_directory.h?r1=1.20r2=1.21diff_format=u
Index: php-src/ext/spl/spl_directory.h
diff -u php-src/ext/spl/spl_directory.h:1.20 
php-src/ext/spl/spl_directory.h:1.21
--- php-src/ext/spl/spl_directory.h:1.20Mon Feb 27 18:15:29 2006
+++ php-src/ext/spl/spl_directory.h Wed Mar  8 20:06:16 2006
@@ -16,7 +16,7 @@
+--+
  */
 
-/* $Id: spl_directory.h,v 1.20 2006/02/27 18:15:29 helly Exp $ */
+/* $Id: spl_directory.h,v 1.21 2006/03/08 20:06:16 helly Exp $ */
 
 #ifndef SPL_DIRECTORY_H
 #define SPL_DIRECTORY_H
@@ -38,9 +38,14 @@
SPL_FS_FILE,
 } SPL_FS_OBJ_TYPE;
 
-typedef struct _spl_filesystem_object {
+typedef struct _spl_filesystem_object  spl_filesystem_object;
+
+typedef void (*spl_foreign_dtor_t)(spl_filesystem_object *object TSRMLS_DC);
+
+struct _spl_filesystem_object {
zend_objectstd;
void   *oth;
+   spl_foreign_dtor_t oth_dtor;
char   *path;
intpath_len;
char   *file_name;
@@ -73,7 +78,7 @@
zend_function  *func_getCurr;
} file;
} u;
-} spl_filesystem_object;
+};
 
 #define SPL_FILE_OBJECT_DROP_NEW_LINE  0x0001 /* drop new lines */
 

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-CVS] cvs: php-src /ext/spl spl_directory.c spl_directory.h

2006-03-08 Thread Marcus Boerger
helly   Wed Mar  8 20:30:12 2006 UTC

  Modified files:  
/php-src/ext/splspl_directory.c spl_directory.h 
  Log:
  - Cloning might need special treatment as well
  
http://cvs.php.net/viewcvs.cgi/php-src/ext/spl/spl_directory.c?r1=1.83r2=1.84diff_format=u
Index: php-src/ext/spl/spl_directory.c
diff -u php-src/ext/spl/spl_directory.c:1.83 
php-src/ext/spl/spl_directory.c:1.84
--- php-src/ext/spl/spl_directory.c:1.83Wed Mar  8 20:06:16 2006
+++ php-src/ext/spl/spl_directory.c Wed Mar  8 20:30:12 2006
@@ -16,7 +16,7 @@
+--+
  */
 
-/* $Id: spl_directory.c,v 1.83 2006/03/08 20:06:16 helly Exp $ */
+/* $Id: spl_directory.c,v 1.84 2006/03/08 20:30:12 helly Exp $ */
 
 #ifdef HAVE_CONFIG_H
 # include config.h
@@ -70,8 +70,8 @@
 {
spl_filesystem_object *intern = (spl_filesystem_object*)object;
 
-   if (intern-oth_dtor) {
-   intern-oth_dtor(intern TSRMLS_CC);
+   if (intern-oth_handler  intern-oth_handler-dtor) {
+   intern-oth_handler-dtor(intern TSRMLS_CC);
}
zend_hash_destroy(intern-std.properties);
FREE_HASHTABLE(intern-std.properties);
@@ -133,7 +133,7 @@
intern = emalloc(sizeof(spl_filesystem_object));
memset(intern, 0, sizeof(spl_filesystem_object));
intern-std.ce = class_type;
-   /* intern-type = SPL_FS_INFO; done by set o */
+   /* intern-type = SPL_FS_INFO; done by set 0 */
intern-file_class = spl_ce_SplFileObject;
intern-info_class = spl_ce_SplFileInfo;
if (obj) *obj = intern;
@@ -273,9 +273,14 @@
intern-info_class = source-info_class;
intern-flags = source-flags;
intern-oth = source-oth;
+   intern-oth_handler = source-oth_handler;
 
zend_objects_clone_members(new_object, new_obj_val, old_object, handle 
TSRMLS_CC);
 
+   if (intern-oth_handler  intern-oth_handler-clone) {
+   intern-oth_handler-clone(source, intern TSRMLS_CC);
+   }
+
return new_obj_val;
 }
 /* }}} */
http://cvs.php.net/viewcvs.cgi/php-src/ext/spl/spl_directory.h?r1=1.21r2=1.22diff_format=u
Index: php-src/ext/spl/spl_directory.h
diff -u php-src/ext/spl/spl_directory.h:1.21 
php-src/ext/spl/spl_directory.h:1.22
--- php-src/ext/spl/spl_directory.h:1.21Wed Mar  8 20:06:16 2006
+++ php-src/ext/spl/spl_directory.h Wed Mar  8 20:30:12 2006
@@ -16,7 +16,7 @@
+--+
  */
 
-/* $Id: spl_directory.h,v 1.21 2006/03/08 20:06:16 helly Exp $ */
+/* $Id: spl_directory.h,v 1.22 2006/03/08 20:30:12 helly Exp $ */
 
 #ifndef SPL_DIRECTORY_H
 #define SPL_DIRECTORY_H
@@ -33,7 +33,7 @@
 PHP_MINIT_FUNCTION(spl_directory);
 
 typedef enum {
-   SPL_FS_INFO,
+   SPL_FS_INFO, /* must be 0 */
SPL_FS_DIR,
SPL_FS_FILE,
 } SPL_FS_OBJ_TYPE;
@@ -41,11 +41,17 @@
 typedef struct _spl_filesystem_object  spl_filesystem_object;
 
 typedef void (*spl_foreign_dtor_t)(spl_filesystem_object *object TSRMLS_DC);
+typedef void (*spl_foreign_clone_t)(spl_filesystem_object *src, 
spl_filesystem_object *dst TSRMLS_DC);
+
+typedef struct _spl_other_handler {
+   spl_foreign_dtor_t dtor;
+   spl_foreign_clone_tclone;
+} spl_other_handler;
 
 struct _spl_filesystem_object {
zend_objectstd;
void   *oth;
-   spl_foreign_dtor_t oth_dtor;
+   spl_other_handler  *oth_handler;
char   *path;
intpath_len;
char   *file_name;

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php



[PHP-CVS] cvs: php-src /ext/spl spl_directory.c spl_directory.h

2005-11-27 Thread Marcus Boerger
helly   Sun Nov 27 08:07:19 2005 EDT

  Modified files:  
/php-src/ext/splspl_directory.c spl_directory.h 
  Log:
  - Fix minor issues in RecursiveDirectoryIterator  provide new flag consts
  
  
http://cvs.php.net/diff.php/php-src/ext/spl/spl_directory.c?r1=1.56r2=1.57ty=u
Index: php-src/ext/spl/spl_directory.c
diff -u php-src/ext/spl/spl_directory.c:1.56 
php-src/ext/spl/spl_directory.c:1.57
--- php-src/ext/spl/spl_directory.c:1.56Sun Nov 27 07:13:42 2005
+++ php-src/ext/spl/spl_directory.c Sun Nov 27 08:07:18 2005
@@ -16,7 +16,7 @@
+--+
  */
 
-/* $Id: spl_directory.c,v 1.56 2005/11/27 12:13:42 helly Exp $ */
+/* $Id: spl_directory.c,v 1.57 2005/11/27 13:07:18 helly Exp $ */
 
 #ifdef HAVE_CONFIG_H
 # include config.h
@@ -334,7 +334,7 @@
 
switch (type) {
case SPL_FS_INFO:
-   return_value-value.obj = spl_filesystem_object_new_ex(ce ? ce 
: intern-info_class, intern TSRMLS_CC);
+   return_value-value.obj = spl_filesystem_object_new_ex(ce ? ce 
: source-info_class, intern TSRMLS_CC);
Z_TYPE_P(return_value) = IS_OBJECT;

spl_filesystem_object_get_file_name(source TSRMLS_CC);
@@ -342,7 +342,7 @@
intern-file_name_len = source-file_name_len;
break;
case SPL_FS_FILE:
-   return_value-value.obj = spl_filesystem_object_new_ex(ce ? ce 
: intern-file_class, intern TSRMLS_CC);
+   return_value-value.obj = spl_filesystem_object_new_ex(ce ? ce 
: source-file_class, intern TSRMLS_CC);
Z_TYPE_P(return_value) = IS_OBJECT;

spl_filesystem_object_get_file_name(source TSRMLS_CC);
@@ -549,11 +549,15 @@
 {
spl_filesystem_object *intern = 
(spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
 
-   if (intern-flags  SPL_FILE_DIR_CURRENT_AS_FILEINFO) {
+   if (intern-flags  SPL_FILE_DIR_CURRENT_AS_PATHNAME) {
+   spl_filesystem_object_get_file_name(intern TSRMLS_CC);
+   RETURN_STRINGL(intern-file_name, intern-file_name_len, 1);
+   } else if (intern-flags  SPL_FILE_DIR_CURRENT_AS_FILEINFO) {
spl_filesystem_object_get_file_name(intern TSRMLS_CC);
spl_filesystem_object_create_type(0, intern, SPL_FS_INFO, NULL, 
return_value TSRMLS_CC);
} else {
-   RETURN_STRING(intern-u.dir.entry.d_name, 1);
+   RETURN_ZVAL(getThis(), 1, 0);
+   /*RETURN_STRING(intern-u.dir.entry.d_name, 1);*/
}
 }
 /* }}} */
@@ -1031,7 +1035,14 @@
spl_filesystem_dir_it *iterator = (spl_filesystem_dir_it *)iter;
spl_filesystem_object *object   = iterator-object;
 
-   if (object-flags  SPL_FILE_DIR_CURRENT_AS_FILEINFO) {
+   if (object-flags  SPL_FILE_DIR_CURRENT_AS_PATHNAME) {
+   if (!iterator-current) {
+   ALLOC_INIT_ZVAL(iterator-current);
+   spl_filesystem_object_get_file_name(object TSRMLS_CC);
+   ZVAL_STRINGL(iterator-current, object-file_name, 
object-file_name_len, 1);
+   }
+   *data = iterator-current;
+   } else if (object-flags  SPL_FILE_DIR_CURRENT_AS_FILEINFO) {
if (!iterator-current) {
ALLOC_INIT_ZVAL(iterator-current);
spl_filesystem_object_get_file_name(object TSRMLS_CC);
@@ -1930,7 +1941,13 @@
 
REGISTER_SPL_SUB_CLASS_EX(RecursiveDirectoryIterator, 
DirectoryIterator, spl_filesystem_object_new, 
spl_RecursiveDirectoryIterator_functions);
REGISTER_SPL_IMPLEMENTS(RecursiveDirectoryIterator, RecursiveIterator);
+
+   REGISTER_SPL_CLASS_CONST_LONG(RecursiveDirectoryIterator, 
CURRENT_MODE_MASK,   SPL_FILE_DIR_CURRENT_MODE_MASK);
+   REGISTER_SPL_CLASS_CONST_LONG(RecursiveDirectoryIterator, 
CURRENT_AS_PATHNAME, SPL_FILE_DIR_CURRENT_AS_PATHNAME);
REGISTER_SPL_CLASS_CONST_LONG(RecursiveDirectoryIterator, 
CURRENT_AS_FILEINFO, SPL_FILE_DIR_CURRENT_AS_FILEINFO);
+   REGISTER_SPL_CLASS_CONST_LONG(RecursiveDirectoryIterator, 
CURRENT_AS_SELF, 0);
+   REGISTER_SPL_CLASS_CONST_LONG(RecursiveDirectoryIterator, 
KEY_MODE_MASK,   SPL_FILE_DIR_KEY_MODE_MASK);
+   REGISTER_SPL_CLASS_CONST_LONG(RecursiveDirectoryIterator, 
KEY_AS_PATHNAME, 0);
REGISTER_SPL_CLASS_CONST_LONG(RecursiveDirectoryIterator, 
KEY_AS_FILENAME, SPL_FILE_DIR_KEY_AS_FILENAME);
REGISTER_SPL_CLASS_CONST_LONG(RecursiveDirectoryIterator, 
NEW_CURRENT_AND_KEY, 
SPL_FILE_DIR_KEY_AS_FILENAME|SPL_FILE_DIR_CURRENT_AS_FILEINFO);
 
http://cvs.php.net/diff.php/php-src/ext/spl/spl_directory.h?r1=1.17r2=1.18ty=u
Index: php-src/ext/spl/spl_directory.h
diff -u php-src/ext/spl/spl_directory.h:1.17 
php-src/ext/spl/spl_directory.h:1.18
--- php-src/ext/spl/spl_directory.h:1.17Tue Nov  1 11:54:44 

[PHP-CVS] cvs: php-src /ext/spl spl_directory.c spl_directory.h

2005-11-01 Thread Marcus Boerger
helly   Tue Nov  1 11:54:45 2005 EDT

  Modified files:  
/php-src/ext/splspl_directory.c spl_directory.h 
  Log:
  - Allow to recive derived SplFileInfo/SplFileObject instances
  
  http://cvs.php.net/diff.php/php-src/ext/spl/spl_directory.c?r1=1.54r2=1.55ty=u
Index: php-src/ext/spl/spl_directory.c
diff -u php-src/ext/spl/spl_directory.c:1.54 
php-src/ext/spl/spl_directory.c:1.55
--- php-src/ext/spl/spl_directory.c:1.54Sat Oct 29 11:48:14 2005
+++ php-src/ext/spl/spl_directory.c Tue Nov  1 11:54:44 2005
@@ -16,7 +16,7 @@
+--+
  */
 
-/* $Id: spl_directory.c,v 1.54 2005/10/29 15:48:14 helly Exp $ */
+/* $Id: spl_directory.c,v 1.55 2005/11/01 16:54:44 helly Exp $ */
 
 #ifdef HAVE_CONFIG_H
 # include config.h
@@ -131,6 +131,8 @@
memset(intern, 0, sizeof(spl_filesystem_object));
intern-std.ce = class_type;
/* intern-type = SPL_FS_INFO; done by set o */
+   intern-file_class = U_CLASS_ENTRY(spl_ce_SplFileObject);
+   intern-info_class = U_CLASS_ENTRY(spl_ce_SplFileInfo);
if (obj) *obj = intern;
 
ALLOC_HASHTABLE(intern-std.properties);
@@ -259,6 +261,9 @@
php_error_docref(NULL TSRMLS_CC, E_ERROR, An object of class 
%v cannot be cloned, old_object-ce-name);
break;
}
+   
+   intern-file_class = source-file_class;
+   intern-info_class = source-info_class;
 
zend_objects_clone_members(new_object, new_obj_val, old_object, handle 
TSRMLS_CC);
 
@@ -283,7 +288,7 @@
intern-path = estrndup(path, intern-path_len);
 } /* }}} */
 
-static spl_filesystem_object * 
spl_filesystem_object_create_info(spl_filesystem_object *source, char 
*file_path, int file_path_len, int use_copy, zval *return_value TSRMLS_DC) /* 
{{{ */
+static spl_filesystem_object * 
spl_filesystem_object_create_info(spl_filesystem_object *source, char 
*file_path, int file_path_len, int use_copy, zend_class_entry *ce, zval 
*return_value TSRMLS_DC) /* {{{ */
 {
spl_filesystem_object *intern;

@@ -298,7 +303,7 @@
 
php_set_error_handling(EH_THROW, U_CLASS_ENTRY(spl_ce_RuntimeException) 
TSRMLS_CC);
 
-   return_value-value.obj = 
spl_filesystem_object_new_ex(spl_ce_SplFileInfo, intern TSRMLS_CC);
+   return_value-value.obj = spl_filesystem_object_new_ex(ce ? ce : 
intern-info_class, intern TSRMLS_CC);
Z_TYPE_P(return_value) = IS_OBJECT;
 
spl_filesystem_info_set_filename(intern, file_path, file_path_len, 
use_copy TSRMLS_CC);
@@ -308,7 +313,7 @@
return intern;
 } /* }}} */
 
-static spl_filesystem_object * spl_filesystem_object_create_type(int ht, 
spl_filesystem_object *source, int type, zval *return_value TSRMLS_DC) /* {{{ */
+static spl_filesystem_object * spl_filesystem_object_create_type(int ht, 
spl_filesystem_object *source, int type, zend_class_entry *ce, zval 
*return_value TSRMLS_DC) /* {{{ */
 {
spl_filesystem_object *intern;
zend_bool use_include_path = 0;
@@ -329,7 +334,7 @@
 
switch (type) {
case SPL_FS_INFO:
-   return_value-value.obj = 
spl_filesystem_object_new_ex(spl_ce_SplFileInfo, intern TSRMLS_CC);
+   return_value-value.obj = spl_filesystem_object_new_ex(ce ? ce 
: intern-info_class, intern TSRMLS_CC);
Z_TYPE_P(return_value) = IS_OBJECT;

spl_filesystem_object_get_file_name(source TSRMLS_CC);
@@ -337,7 +342,7 @@
intern-file_name_len = source-file_name_len;
break;
case SPL_FS_FILE:
-   return_value-value.obj = 
spl_filesystem_object_new_ex(spl_ce_SplFileObject, intern TSRMLS_CC);
+   return_value-value.obj = spl_filesystem_object_new_ex(ce ? ce 
: intern-file_class, intern TSRMLS_CC);
Z_TYPE_P(return_value) = IS_OBJECT;

spl_filesystem_object_get_file_name(source TSRMLS_CC);
@@ -546,7 +551,7 @@
 
if (intern-flags  SPL_FILE_DIR_CURRENT_AS_FILEINFO) {
spl_filesystem_object_get_file_name(intern TSRMLS_CC);
-   spl_filesystem_object_create_type(0, intern, SPL_FS_INFO, 
return_value TSRMLS_CC);
+   spl_filesystem_object_create_type(0, intern, SPL_FS_INFO, NULL, 
return_value TSRMLS_CC);
} else {
RETURN_STRING(intern-u.dir.entry.d_name, 1);
}
@@ -687,25 +692,63 @@
 {
spl_filesystem_object *intern = 
(spl_filesystem_object*)zend_object_store_get_object(getThis() TSRMLS_CC);
 
-   spl_filesystem_object_create_type(ht, intern, SPL_FS_FILE, return_value 
TSRMLS_CC);
+   spl_filesystem_object_create_type(ht, intern, SPL_FS_FILE, NULL, 
return_value TSRMLS_CC);
 }
 
-/* {{{ proto SplFileInfo SplFileInfo::getFileInfo()
+/* {{{ proto SplFileObject SplFileInfo::setFileClass([string class_name])
+   Class to use in openFile() */
+SPL_METHOD(SplFileInfo, setFileClass)
+{
+   

[PHP-CVS] cvs: php-src /ext/spl spl_directory.c spl_directory.h

2005-03-31 Thread Marcus Boerger
helly   Thu Mar 31 16:51:46 2005 EDT

  Modified files:  
/php-src/ext/splspl_directory.c spl_directory.h 
  Log:
  - Add RecursiveDirectoryIterator::getSubPath()
  
http://cvs.php.net/diff.php/php-src/ext/spl/spl_directory.c?r1=1.39r2=1.40ty=u
Index: php-src/ext/spl/spl_directory.c
diff -u php-src/ext/spl/spl_directory.c:1.39 
php-src/ext/spl/spl_directory.c:1.40
--- php-src/ext/spl/spl_directory.c:1.39Wed Mar  9 05:29:27 2005
+++ php-src/ext/spl/spl_directory.c Thu Mar 31 16:51:45 2005
@@ -16,7 +16,7 @@
+--+
  */
 
-/* $Id: spl_directory.c,v 1.39 2005/03/09 10:29:27 helly Exp $ */
+/* $Id: spl_directory.c,v 1.40 2005/03/31 21:51:45 helly Exp $ */
 
 #ifdef HAVE_CONFIG_H
 # include config.h
@@ -73,6 +73,9 @@
if (intern-path_name) {
efree(intern-path_name);
}
+   if (intern-sub_path) {
+   efree(intern-sub_path);
+   }
efree(object);
 }
 /* }}} */
@@ -540,6 +543,7 @@
 {
zval *object = getThis(), zpath;
spl_ce_dir_object *intern = 
(spl_ce_dir_object*)zend_object_store_get_object(object TSRMLS_CC);
+   spl_ce_dir_object *subdir;

spl_dir_get_path_name(intern);
 
@@ -547,6 +551,31 @@
ZVAL_STRINGL(zpath, intern-path_name, intern-path_name_len, 0);
 
spl_instantiate_arg_ex1(spl_ce_RecursiveDirectoryIterator, 
return_value, 0, zpath TSRMLS_CC);
+   
+   subdir = (spl_ce_dir_object*)zend_object_store_get_object(return_value 
TSRMLS_CC);
+   if (subdir) {
+   if (intern-sub_path  intern-sub_path[0]) {
+   subdir-sub_path_len = spprintf(subdir-sub_path, 0, 
%s/%s, intern-sub_path, intern-entry.d_name);
+   } else {
+   subdir-sub_path_len = strlen(intern-entry.d_name);
+   subdir-sub_path = estrndup(intern-entry.d_name, 
subdir-sub_path_len);
+   }
+   }
+}
+/* }}} */
+
+/* {{{ proto void RecursiveDirectoryIterator::rewind()
+   Get sub path */
+SPL_METHOD(RecursiveDirectoryIterator, getSubPath)
+{
+   zval *object = getThis();
+   spl_ce_dir_object *intern = 
(spl_ce_dir_object*)zend_object_store_get_object(object TSRMLS_CC);
+
+   if (intern-sub_path) {
+   RETURN_STRINGL(intern-sub_path, intern-sub_path_len, 1);
+   } else {
+   RETURN_STRINGL(, 0, 1);
+   }
 }
 /* }}} */
 
@@ -818,6 +847,7 @@
SPL_ME(RecursiveDirectoryIterator, key,   NULL, ZEND_ACC_PUBLIC)
SPL_ME(RecursiveDirectoryIterator, hasChildren,   NULL, ZEND_ACC_PUBLIC)
SPL_ME(RecursiveDirectoryIterator, getChildren,   NULL, ZEND_ACC_PUBLIC)
+   SPL_ME(RecursiveDirectoryIterator, getSubPath,NULL, ZEND_ACC_PUBLIC)
{NULL, NULL, NULL}
 };
 
http://cvs.php.net/diff.php/php-src/ext/spl/spl_directory.h?r1=1.8r2=1.9ty=u
Index: php-src/ext/spl/spl_directory.h
diff -u php-src/ext/spl/spl_directory.h:1.8 php-src/ext/spl/spl_directory.h:1.9
--- php-src/ext/spl/spl_directory.h:1.8 Sun Mar  6 19:40:57 2005
+++ php-src/ext/spl/spl_directory.h Thu Mar 31 16:51:46 2005
@@ -16,7 +16,7 @@
+--+
  */
 
-/* $Id: spl_directory.h,v 1.8 2005/03/07 00:40:57 helly Exp $ */
+/* $Id: spl_directory.h,v 1.9 2005/03/31 21:51:46 helly Exp $ */
 
 #ifndef SPL_DIRECTORY_H
 #define SPL_DIRECTORY_H
@@ -37,6 +37,8 @@
char  *path;
char  *path_name;
int   path_name_len;
+   char  *sub_path;
+   int   sub_path_len;
int   index;
 } spl_ce_dir_object;
 

-- 
PHP CVS Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php