-
Notifications
You must be signed in to change notification settings - Fork 118
/
Copy pathcamatch.h
63 lines (43 loc) · 1.74 KB
/
camatch.h
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
/* SPDX-License-Identifier: LGPL-2.1+ */
#ifndef foocamatchhfoo
#define foocamatchhfoo
#include <stdbool.h>
#include <stdio.h>
#include <sys/types.h>
typedef struct CaMatch CaMatch;
typedef enum CaMatchType {
CA_MATCH_POSITIVE,
CA_MATCH_NEGATIVE, /* Path is prefixed with an exclamation mark: reverses operation */
CA_MATCH_INNER, /* Item does not match anything, just exists to track children */
_CA_MATCH_TYPE_MAX,
_CA_MATCH_TYPE_INVALID = -1,
} CaMatchType;
struct CaMatch {
unsigned n_ref;
CaMatchType type;
bool anchored:1; /* Path starts with a slash (or contained them originall, though not at the end): only
* applies to the current directory, not any children */
bool directory_only:1; /* Path is suffixed with a slash: only matches directories */
CaMatch **children;
size_t n_children;
size_t n_allocated;
char name[];
};
int ca_match_new_from_file(int dir_fd, const char *filename, CaMatch **ret);
int ca_match_new_from_strings(char **path, CaMatch **ret);
CaMatch* ca_match_ref(CaMatch *match);
CaMatch* ca_match_unref(CaMatch *match);
static inline void ca_match_unrefp(CaMatch **match) {
if (match)
ca_match_unref(*match);
}
int ca_match_add_child(CaMatch *match, CaMatch *child);
int ca_match_merge(CaMatch **a, CaMatch *b);
int ca_match_normalize(CaMatch **match);
int ca_match_test(CaMatch *match, const char *name, bool is_directory, CaMatch **ret);
static inline size_t ca_match_children(CaMatch *match) {
return match ? match->n_children : 0;
}
void ca_match_dump(FILE *f, CaMatch *match, const char *prefix);
bool ca_match_equal(CaMatch *a, CaMatch *b);
#endif