Added vfs_path_cmp() ans vfs_path_ncmp() functions
[midnight-commander.git] / lib / vfs / path.h
blob82629b81946daf346a2db67b0aaf5c97bfffc0e9
1 #ifndef MC__VFS_PATH_H
2 #define MC__VFS_PATH_H
4 /*** typedefs(not structures) and defined constants **********************************************/
6 #define VFS_PATH_URL_DELIMITER "://"
8 /*** enums ***************************************************************************************/
10 typedef enum
12 VPF_NONE = 0,
13 VPF_NO_CANON = 1 << 0,
14 VPF_USE_DEPRECATED_PARSER = 1 << 1
15 } vfs_path_flag_t;
17 /*** structures declarations (and typedefs of structures)*****************************************/
19 struct vfs_class;
20 struct vfs_url_struct;
22 typedef struct
24 GArray *path;
25 } vfs_path_t;
27 typedef struct
29 char *user;
30 char *password;
31 char *host;
32 gboolean ipv6;
33 int port;
34 char *path;
35 struct vfs_class *class;
36 char *encoding;
37 char *vfs_prefix;
39 struct
41 GIConv converter;
42 DIR *info;
43 } dir;
44 } vfs_path_element_t;
46 /*** global variables defined in .c file *********************************************************/
48 /*** declarations of public functions ************************************************************/
50 vfs_path_t *vfs_path_new (void);
51 vfs_path_t *vfs_path_clone (const vfs_path_t * vpath);
52 void vfs_path_remove_element_by_index (vfs_path_t * vpath, int element_index);
53 void vfs_path_free (vfs_path_t * path);
54 int vfs_path_elements_count (const vfs_path_t * path);
56 char *vfs_path_to_str (const vfs_path_t * path);
57 char *vfs_path_to_str_elements_count (const vfs_path_t * path, int elements_count);
58 vfs_path_t *vfs_path_from_str (const char *path_str);
59 vfs_path_t *vfs_path_from_str_flags (const char *path_str, vfs_path_flag_t flags);
60 vfs_path_t *vfs_path_build_filename (const char *first_element, ...);
61 vfs_path_t *vfs_path_append_new (const vfs_path_t * vpath, const char *first_element, ...);
62 vfs_path_t *vfs_path_append_vpath_new (const vfs_path_t * first_vpath, ...);
63 size_t vfs_path_tokens_count (const vfs_path_t *);
64 char *vfs_path_tokens_get (const vfs_path_t * vpath, ssize_t start_position, size_t length);
65 vfs_path_t *vfs_path_vtokens_get (const vfs_path_t * vpath, ssize_t start_position, size_t length);
67 vfs_path_element_t *vfs_path_get_by_index (const vfs_path_t * path, int element_index);
68 vfs_path_element_t *vfs_path_element_clone (const vfs_path_element_t * element);
69 void vfs_path_element_free (vfs_path_element_t * element);
71 struct vfs_class *vfs_prefix_to_class (const char *prefix);
73 gboolean vfs_path_element_need_cleanup_converter (const vfs_path_element_t * element);
75 char *vfs_path_serialize (const vfs_path_t * vpath, GError ** error);
76 vfs_path_t *vfs_path_deserialize (const char *data, GError ** error);
78 char *vfs_path_build_url_params_str (const vfs_path_element_t * element, gboolean keep_password);
79 int vfs_path_cmp (const vfs_path_t * vpath1, const vfs_path_t * vpath2);
80 int vfs_path_ncmp (const vfs_path_t * vpath1, const vfs_path_t * vpath2, size_t len);
82 /*** inline functions ****************************************************************************/
84 static inline gboolean
85 vfs_path_element_valid (const vfs_path_element_t * element)
87 return (element != NULL && element->class != NULL);
90 /* --------------------------------------------------------------------------------------------- */
92 static inline char *
93 vfs_path_get_last_path_str (const vfs_path_t * vpath)
95 const vfs_path_element_t *element;
96 if (vpath == NULL)
97 return NULL;
98 element = vfs_path_get_by_index (vpath, -1);
99 return (element != NULL) ? element->path : NULL;
102 /* --------------------------------------------------------------------------------------------- */
104 static inline struct vfs_class *
105 vfs_path_get_last_path_vfs (const vfs_path_t * vpath)
107 const vfs_path_element_t *element;
108 if (vpath == NULL)
109 return NULL;
110 element = vfs_path_get_by_index (vpath, -1);
111 return (element != NULL) ? element->class : NULL;
114 #endif