blob: dfb0b5f5d4fef1672aeb04790e9cfc6d1f3818eb (
plain) (
blame)
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
|
#ifndef CLEANPATH_CLEANPATH_H
#define CLEANPATH_CLEANPATH_H
// Define some platform detection shortcuts
#define OS_DARWIN 0
#define OS_WINDOWS 0
#define OS_LINUX 0
#define OS_SUPPORTED 0
#if defined(__APPLE__) && defined(__MACH__)
# undef OS_DARWIN
# define OS_DARWIN 1
# undef OS_SUPPORTED
# define OS_SUPPORTED 1
#elif defined(_WIN32)
# undef OS_WINDOWS
# define OS_WINDOWS 1
# undef OS_SUPPORTED
# define OS_SUPPORTED 1
#elif defined(__linux) || defined(__linux__)
# undef OS_LINUX
# define OS_LINUX 1
# undef OS_SUPPORTED
# define OS_SUPPORTED 1
#endif
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#define CLEANPATH_VERSION "1.0.0"
#define CLEANPATH_FILTER_NONE -1
#define CLEANPATH_FILTER_EXACT 0
#define CLEANPATH_FILTER_LOOSE 1
#define CLEANPATH_FILTER_REGEX 2
#define CLEANPATH_PART_MAX 1024
#define CLEANPATH_VAR "PATH"
#define CLEANPATH_SEP ":"
#define CLEANPATH_MSG_NOT_IMPLEMENTED "[not implemented]"
#define CLEANPATH_MSG_NOT_SUPPORTED "[not supported]"
#define CLEANPATH_MSG_NO_REGEX ""
#define CLEANPATH_MSG_NO_DEFAULT_PATH ""
#if OS_WINDOWS
#undef CLEANPATH_SEP
#define CLEANPATH_SEP ";"
#undef CLEANPATH_MSG_NO_REGEX
#define CLEANPATH_MSG_NO_REGEX CLEANPATH_MSG_NOT_IMPLEMENTED
#endif
#if !OS_SUPPORTED
#undef CLEANPATH_MSG_NO_DEFAULT_PATH
#define CLEANPATH_MSG_NO_DEFAULT_PATH CLEANPATH_MSG_NOT_SUPPORTED
#endif
struct CleanPath {
char *data; // Pointer to the path string
size_t data_len; // Length of the path string
char *sep; // Pointer to the separator used to split the data string
char *part[CLEANPATH_PART_MAX]; // Array of pointers to path elements
size_t part_nelem; // Total number of elements in part array
};
// Prototypes
struct CleanPath *cleanpath_init(const char *path, const char *sep);
void cleanpath_filter(struct CleanPath *path, unsigned mode, const char *pattern);
char *cleanpath_read(struct CleanPath *path);
void cleanpath_free(struct CleanPath *path);
#endif //CLEANPATH_CLEANPATH_H
|