summaryrefslogtreecommitdiffstats
path: root/src/filemanager/dir.h
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 17:44:12 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-04 17:44:12 +0000
commit8ccb487c21368a7fdc8c7c72315325bf0aa06147 (patch)
treeb2056fae01d325924508a41731edfbd4c3cddd23 /src/filemanager/dir.h
parentInitial commit. (diff)
downloadmc-8ccb487c21368a7fdc8c7c72315325bf0aa06147.tar.xz
mc-8ccb487c21368a7fdc8c7c72315325bf0aa06147.zip
Adding upstream version 3:4.8.29.upstream/3%4.8.29upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/filemanager/dir.h')
-rw-r--r--src/filemanager/dir.h115
1 files changed, 115 insertions, 0 deletions
diff --git a/src/filemanager/dir.h b/src/filemanager/dir.h
new file mode 100644
index 0000000..f6a65ee
--- /dev/null
+++ b/src/filemanager/dir.h
@@ -0,0 +1,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 */