1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
|
/** \file dir.h
* \brief Header: directory routines
*/
#ifndef MC__DIR_H
#define MC__DIR_H
#include <sys/stat.h>
#include "lib/global.h"
#include "lib/search.h"
#include "lib/util.h"
#include "lib/vfs/vfs.h"
/*** typedefs(not structures) and defined constants **********************************************/
#define DIR_LIST_MIN_SIZE 128
#define DIR_LIST_RESIZE_STEP 128
typedef enum
{
DIR_OPEN = 0,
DIR_READ,
DIR_CLOSE
} dir_list_cb_state_t;
/* selection flags */
typedef enum
{
SELECT_FILES_ONLY = 1 << 0,
SELECT_MATCH_CASE = 1 << 1,
SELECT_SHELL_PATTERNS = 1 << 2
} select_flags_t;
#define FILE_FILTER_DEFAULT_FLAGS (SELECT_FILES_ONLY | SELECT_MATCH_CASE | SELECT_SHELL_PATTERNS)
/* dir_list callback */
typedef void (*dir_list_cb_fn) (dir_list_cb_state_t state, void *data);
/*** enums ***************************************************************************************/
/*** structures declarations (and typedefs of structures)*****************************************/
/**
* A structure to represent directory content
*/
typedef struct
{
file_entry_t *list; /**< list of file_entry_t objects */
int size; /**< number of allocated elements in list (capacity) */
int len; /**< number of used elements in list */
dir_list_cb_fn callback; /**< callback to visualize of directory read */
} dir_list;
/**
* A structure to represent sort options for directory content
*/
typedef struct dir_sort_options_struct
{
gboolean reverse; /**< sort is reverse */
gboolean case_sensitive; /**< sort is case sensitive */
gboolean exec_first; /**< executables are at top of list */
} dir_sort_options_t;
/* filter */
typedef struct
{
char *value;
mc_search_t *handler;
select_flags_t flags;
} file_filter_t;
/*** global variables defined in .c file *********************************************************/
/*** declarations of public functions ************************************************************/
gboolean dir_list_grow (dir_list * list, int delta);
gboolean dir_list_append (dir_list * list, const char *fname, const struct stat *st,
gboolean link_to_dir, gboolean stale_link);
gboolean dir_list_load (dir_list * list, const vfs_path_t * vpath, GCompareFunc sort,
const dir_sort_options_t * sort_op, const file_filter_t * filter);
gboolean dir_list_reload (dir_list * list, const vfs_path_t * vpath, GCompareFunc sort,
const dir_sort_options_t * sort_op, const file_filter_t * filter);
void dir_list_sort (dir_list * list, GCompareFunc sort, const dir_sort_options_t * sort_op);
gboolean dir_list_init (dir_list * list);
void dir_list_clean (dir_list * list);
void dir_list_free_list (dir_list * list);
gboolean handle_path (const char *path, struct stat *buf1, gboolean * link_to_dir,
gboolean * stale_link);
/* Sorting functions */
int unsorted (file_entry_t * a, file_entry_t * b);
int sort_name (file_entry_t * a, file_entry_t * b);
int sort_vers (file_entry_t * a, file_entry_t * b);
int sort_ext (file_entry_t * a, file_entry_t * b);
int sort_time (file_entry_t * a, file_entry_t * b);
int sort_atime (file_entry_t * a, file_entry_t * b);
int sort_ctime (file_entry_t * a, file_entry_t * b);
int sort_size (file_entry_t * a, file_entry_t * b);
int sort_inode (file_entry_t * a, file_entry_t * b);
gboolean if_link_is_exe (const vfs_path_t * full_name, const file_entry_t * file);
void file_filter_clear (file_filter_t * filter);
/*** inline functions ****************************************************************************/
static inline gboolean
link_isdir (const file_entry_t * file)
{
return (gboolean) file->f.link_to_dir;
}
#endif /* MC__DIR_H */
|