Back to index

php5  5.3.10
spl_directory.h
Go to the documentation of this file.
00001 /*
00002    +----------------------------------------------------------------------+
00003    | PHP Version 5                                                        |
00004    +----------------------------------------------------------------------+
00005    | Copyright (c) 1997-2012 The PHP Group                                |
00006    +----------------------------------------------------------------------+
00007    | This source file is subject to version 3.01 of the PHP license,      |
00008    | that is bundled with this package in the file LICENSE, and is        |
00009    | available through the world-wide-web at the following url:           |
00010    | http://www.php.net/license/3_01.txt                                  |
00011    | If you did not receive a copy of the PHP license and are unable to   |
00012    | obtain it through the world-wide-web, please send a note to          |
00013    | license@php.net so we can mail you a copy immediately.               |
00014    +----------------------------------------------------------------------+
00015    | Authors: Marcus Boerger <helly@php.net>                              |
00016    +----------------------------------------------------------------------+
00017  */
00018 
00019 /* $Id: spl_directory.h 321634 2012-01-01 13:15:04Z felipe $ */
00020 
00021 #ifndef SPL_DIRECTORY_H
00022 #define SPL_DIRECTORY_H
00023 
00024 #include "php.h"
00025 #include "php_spl.h"
00026 
00027 extern PHPAPI zend_class_entry *spl_ce_SplFileInfo;
00028 extern PHPAPI zend_class_entry *spl_ce_DirectoryIterator;
00029 extern PHPAPI zend_class_entry *spl_ce_FilesystemIterator;
00030 extern PHPAPI zend_class_entry *spl_ce_RecursiveDirectoryIterator;
00031 extern PHPAPI zend_class_entry *spl_ce_GlobIterator;
00032 extern PHPAPI zend_class_entry *spl_ce_SplFileObject;
00033 extern PHPAPI zend_class_entry *spl_ce_SplTempFileObject;
00034 
00035 PHP_MINIT_FUNCTION(spl_directory);
00036 
00037 typedef enum {
00038        SPL_FS_INFO, /* must be 0 */
00039        SPL_FS_DIR,
00040        SPL_FS_FILE
00041 } SPL_FS_OBJ_TYPE;
00042 
00043 typedef struct _spl_filesystem_object  spl_filesystem_object;
00044 
00045 typedef void (*spl_foreign_dtor_t)(spl_filesystem_object *object TSRMLS_DC);
00046 typedef void (*spl_foreign_clone_t)(spl_filesystem_object *src, spl_filesystem_object *dst TSRMLS_DC);
00047 
00048 PHPAPI char* spl_filesystem_object_get_path(spl_filesystem_object *intern, int *len TSRMLS_DC);
00049 
00050 typedef struct _spl_other_handler {
00051        spl_foreign_dtor_t     dtor;
00052        spl_foreign_clone_t    clone;
00053 } spl_other_handler;
00054 
00055 /* define an overloaded iterator structure */
00056 typedef struct {
00057        zend_object_iterator  intern;
00058        zval                  *current;
00059        spl_filesystem_object *object;
00060 } spl_filesystem_iterator;
00061 
00062 struct _spl_filesystem_object {
00063        zend_object        std;
00064        void               *oth;
00065        spl_other_handler  *oth_handler;
00066        char               *_path;
00067        int                _path_len;
00068        char               *orig_path;
00069        char               *file_name;
00070        int                file_name_len;
00071        SPL_FS_OBJ_TYPE    type;
00072        long               flags;
00073        zend_class_entry   *file_class;
00074        zend_class_entry   *info_class;
00075        union {
00076               struct {
00077                      php_stream         *dirp;
00078                      php_stream_dirent  entry;
00079                      char               *sub_path;
00080                      int                sub_path_len;
00081                      int                index;
00082                      int                is_recursive;
00083                      zend_function      *func_rewind;
00084                      zend_function      *func_next;
00085                      zend_function      *func_valid;
00086               } dir;
00087               struct {
00088                      php_stream         *stream;
00089                      php_stream_context *context;
00090                      zval               *zcontext;
00091                      char               *open_mode;
00092                      int                open_mode_len;
00093                      zval               *current_zval;
00094                      char               *current_line;
00095                      size_t             current_line_len;
00096                      size_t             max_line_len;
00097                      long               current_line_num;
00098                      zval               zresource;
00099                      zend_function      *func_getCurr;
00100                      char               delimiter;
00101                      char               enclosure;
00102                      char               escape;
00103               } file;
00104        } u;
00105        spl_filesystem_iterator    it;
00106 };
00107 
00108 static inline spl_filesystem_iterator* spl_filesystem_object_to_iterator(spl_filesystem_object *obj)
00109 {
00110        return &obj->it;
00111 }
00112 
00113 static inline spl_filesystem_object* spl_filesystem_iterator_to_object(spl_filesystem_iterator *it)
00114 {
00115        return (spl_filesystem_object*)((char*)it - XtOffsetOf(spl_filesystem_object, it));
00116 }
00117 
00118 #define SPL_FILE_OBJECT_DROP_NEW_LINE      0x00000001 /* drop new lines */
00119 #define SPL_FILE_OBJECT_READ_AHEAD         0x00000002 /* read on rewind/next */
00120 #define SPL_FILE_OBJECT_SKIP_EMPTY         0x00000004 /* skip empty lines */
00121 #define SPL_FILE_OBJECT_READ_CSV           0x00000008 /* read via fgetcsv */
00122 #define SPL_FILE_OBJECT_MASK               0x0000000F /* read via fgetcsv */
00123 
00124 #define SPL_FILE_DIR_CURRENT_AS_FILEINFO   0x00000000 /* make RecursiveDirectoryTree::current() return SplFileInfo */
00125 #define SPL_FILE_DIR_CURRENT_AS_SELF       0x00000010 /* make RecursiveDirectoryTree::current() return getSelf() */
00126 #define SPL_FILE_DIR_CURRENT_AS_PATHNAME   0x00000020 /* make RecursiveDirectoryTree::current() return getPathname() */
00127 #define SPL_FILE_DIR_CURRENT_MODE_MASK     0x000000F0 /* mask RecursiveDirectoryTree::current() */
00128 #define SPL_FILE_DIR_CURRENT(intern,mode)  ((intern->flags&SPL_FILE_DIR_CURRENT_MODE_MASK)==mode)
00129 
00130 #define SPL_FILE_DIR_KEY_AS_PATHNAME       0x00000000 /* make RecursiveDirectoryTree::key() return getPathname() */
00131 #define SPL_FILE_DIR_KEY_AS_FILENAME       0x00000100 /* make RecursiveDirectoryTree::key() return getFilename() */
00132 #define SPL_FILE_DIR_FOLLOW_SYMLINKS       0x00000200 /* make RecursiveDirectoryTree::hasChildren() follow symlinks */
00133 #define SPL_FILE_DIR_KEY_MODE_MASK         0x00000F00 /* mask RecursiveDirectoryTree::key() */
00134 #define SPL_FILE_DIR_KEY(intern,mode)      ((intern->flags&SPL_FILE_DIR_KEY_MODE_MASK)==mode)
00135 
00136 #define SPL_FILE_DIR_SKIPDOTS              0x00001000 /* Tells whether it should skip dots or not */
00137 #define SPL_FILE_DIR_UNIXPATHS             0x00002000 /* Whether to unixify path separators */
00138 #define SPL_FILE_DIR_OTHERS_MASK           0x00003000 /* mask used for get/setFlags */
00139 
00140 #endif /* SPL_DIRECTORY_H */
00141 
00142 /*
00143  * Local Variables:
00144  * c-basic-offset: 4
00145  * tab-width: 4
00146  * End:
00147  * vim600: fdm=marker
00148  * vim: noet sw=4 ts=4
00149  */