ftwin 0.8.10
ft_ignore.h
Go to the documentation of this file.
1
6/*
7 * Copyright (C) 2025 François Pesce : francois.pesce (at) gmail (dot) com
8 *
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 */
21
22#ifndef FT_IGNORE_H
23#define FT_IGNORE_H
24
25#include <apr_pools.h>
26#include <apr_tables.h>
27#include <pcre.h>
28
29/* Flags for ignore patterns */
30#define FT_IGNORE_NEGATE 0x01 /* Starts with '!' */
31#define FT_IGNORE_DIR_ONLY 0x02 /* Ends with '/' */
32
36typedef struct
37{
38 pcre *regex;
39 const char *pattern_str;
40 unsigned int flags;
42
50typedef struct ft_ignore_context_t
51{
53 apr_array_header_t *patterns;
54 const char *base_dir;
55 apr_size_t base_dir_len;
56 apr_pool_t *pool;
58
68
78
86apr_status_t ft_ignore_load_file(ft_ignore_context_t * ctx, const char *filepath);
87
97apr_status_t ft_ignore_add_pattern_str(ft_ignore_context_t * ctx, const char *pattern_str);
98
110ft_ignore_match_result_t ft_ignore_match(ft_ignore_context_t * ctx, const char *fullpath, int is_dir);
111
112#endif /* FT_IGNORE_H */
apr_status_t ft_ignore_add_pattern_str(ft_ignore_context_t *ctx, const char *pattern_str)
Adds a single pattern string to a context.
Definition ft_ignore.c:197
ft_ignore_context_t * ft_ignore_context_create(apr_pool_t *pool, ft_ignore_context_t *parent, const char *base_dir)
Creates a new ignore context.
Definition ft_ignore.c:184
apr_status_t ft_ignore_load_file(ft_ignore_context_t *ctx, const char *filepath)
Loads and parses an ignore file (like .gitignore) into a context.
Definition ft_ignore.c:239
ft_ignore_match_result_t
Result codes for an ignore match operation.
Definition ft_ignore.h:63
@ FT_IGNORE_MATCH_NONE
The path is not matched by any pattern.
Definition ft_ignore.h:64
@ FT_IGNORE_MATCH_WHITELISTED
The path is matched by a negation (whitelist) pattern.
Definition ft_ignore.h:66
@ FT_IGNORE_MATCH_IGNORED
The path is matched by an ignore pattern.
Definition ft_ignore.h:65
ft_ignore_match_result_t ft_ignore_match(ft_ignore_context_t *ctx, const char *fullpath, int is_dir)
Checks if a given path should be ignored based on the hierarchical context.
Definition ft_ignore.c:268
Represents the ignore rules for a specific directory and its descendants.
Definition ft_ignore.h:51
apr_array_header_t * patterns
Array of ft_ignore_pattern_t pointers defined at this level.
Definition ft_ignore.h:53
const char * base_dir
The absolute path to the directory this context is anchored to.
Definition ft_ignore.h:54
struct ft_ignore_context_t * parent
Pointer to the parent directory's context, or NULL if root.
Definition ft_ignore.h:52
apr_size_t base_dir_len
The length of the base directory path.
Definition ft_ignore.h:55
apr_pool_t * pool
The memory pool used for allocations within this context.
Definition ft_ignore.h:56
Represents a single compiled ignore pattern.
Definition ft_ignore.h:37
unsigned int flags
Flags for the pattern (e.g., FT_IGNORE_NEGATE).
Definition ft_ignore.h:40
const char * pattern_str
The original, uncompiled pattern string for debugging.
Definition ft_ignore.h:39
pcre * regex
The compiled PCRE pattern.
Definition ft_ignore.h:38