coan 4.2.4
|
00001 #ifndef FILE_TREE_H 00002 #define FILE_TREE_H 00003 /*************************************************************************** 00004 * Copyright (C) 2004, 2006 Symbian Software Ltd. * 00005 * All rights reserved. * 00006 * Copyright (C) 2007-2011 Mike Kinghan, imk@strudl.org * 00007 * All rights reserved. * 00008 * * 00009 * Contributed originally by Mike Kinghan, imk@strudl.org * 00010 * * 00011 * Redistribution and use in source and binary forms, with or without * 00012 * modification, are permitted provided that the following conditions * 00013 * are met: * 00014 * * 00015 * Redistributions of source code must retain the above copyright * 00016 * notice, this list of conditions and the following disclaimer. * 00017 * * 00018 * Redistributions in binary form must reproduce the above copyright * 00019 * notice, this list of conditions and the following disclaimer in the * 00020 * documentation and/or other materials provided with the distribution. * 00021 * * 00022 * Neither the name of Symbian Software Ltd. nor the names of its * 00023 * contributors may be used to endorse or promote products derived from * 00024 * this software without specific prior written permission. * 00025 * * 00026 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS * 00027 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT * 00028 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS * 00029 * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE * 00030 * COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, * 00031 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, * 00032 * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS * 00033 * OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED * 00034 * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,* 00035 * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF * 00036 * THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH * 00037 * DAMAGE. * 00038 * * 00039 **************************************************************************/ 00040 #include "bool.h" 00041 #include "memory.h" 00042 00050 00055 #define FT_LAST ((size_t)-1) 00056 00058 typedef enum { 00059 FT_ENTERING_TREE = -2, 00060 FT_ENTERING_DIR = -1, 00061 FT_AT_FILE = 0, 00062 FT_LEAVING_DIR = 1, 00063 FT_LEAVING_TREE = 2 00064 } file_tree_traverse_state_t; 00065 00069 enum file_tree_count_flags { 00070 FT_COUNT_FILES = 1, 00071 FT_COUNT_DIRS = 2, 00072 FT_COUNT_ALL = FT_COUNT_FILES | FT_COUNT_DIRS, 00073 FT_COUNT_CHILDREN = 4 00074 }; 00075 00077 typedef struct file_tree * file_tree_h; 00078 00080 typedef struct file_tree const * file_tree_const_h; 00081 00084 typedef struct { 00085 size_t files; 00086 size_t dirs; 00087 size_t children; 00089 } file_tree_count_t; 00090 00104 typedef void (*file_tree_callback_t)( file_tree_h ft, 00105 char const *name, 00106 file_tree_traverse_state_t context); 00107 00118 typedef bool (*file_filter_t)(char const *leafname); 00119 00120 00126 extern heap_str 00127 file_tree_name(file_tree_const_h ft); 00128 00134 extern file_tree_h 00135 file_tree_new(void); 00136 00138 extern file_tree_h 00139 file_tree_copy(file_tree_const_h src); 00140 00142 extern void 00143 file_tree_swap(file_tree_h lhs, file_tree_h rhs); 00144 00149 extern void 00150 file_tree_assign(file_tree_h dest, file_tree_const_h src); 00151 00156 extern bool 00157 file_tree_equal(file_tree_const_h lhs, file_tree_const_h rhs); 00158 00172 extern bool 00173 file_tree_set_filter(file_tree_h ft, file_filter_t filter); 00174 00175 00206 extern void 00207 file_tree_add( file_tree_h parent, 00208 char const *path, 00209 file_tree_callback_t callback); 00210 00211 00216 extern void 00217 file_tree_dispose(file_tree_h ft); 00218 00226 extern void 00227 file_tree_traverse( file_tree_h ft, 00228 file_tree_callback_t callback); 00229 00230 00233 extern bool 00234 file_tree_is_empty(file_tree_const_h ft); 00235 00248 extern size_t 00249 file_tree_count( file_tree_const_h ft, 00250 unsigned flags, 00251 file_tree_count_t * counter); 00252 00264 extern file_tree_const_h 00265 file_tree_child(file_tree_const_h ft, size_t which); 00266 00267 #ifdef DEBUG_FILE_TREE 00268 extern void 00269 file_tree_dump(file_tree_h ft); 00270 #endif 00271 00274 #endif /* EOF*/