/* Ignore rules for the skill and @file walks (also Fossil globs, below).
* Gitignore-style patterns for skill discovery, as Pi's skills.ts feeds them
* to the `ignore` library: .gitignore, .ignore and .fdignore found while
* walking a skills folder, each pattern prefixed by its folder's path from
* the walk's root. Globs (* ? [a-z]), **, a trailing / (folders only), !
* negation, # comments and \ escapes; the last matching rule wins, and
* nothing under an ignored folder is reachable. */
#ifndef PIC_IGNORE_H
#define PIC_IGNORE_H
#include <stddef.h>
typedef struct {
char *pat;
int negated, dir_only, anchored;
int fossil; /* Fossil glob: SQLite GLOB, any match ignores, no negation */
size_t plen; /* fossil only: length of the literal folder prefix in pat */
} pic_ignore_rule;
typedef struct {
pic_ignore_rule *v;
size_t n, cap;
} pic_ignore;
/* Adds the lines of TEXT, each prefixed by PREFIX ("" or "sub/dir/").
* 0, or -1 when out of memory. */
int pic_ignore_add(pic_ignore *ig, const char *text, size_t len, const char *prefix);
/* Fossil's dialect (.fslignore, ignore-glob settings): patterns separated by
* commas and/or white space and/or newlines, "double quotes" holding spaces
* or commas. Each is a SQLite GLOB (sqlite3_strglob: '*' crosses '/') matched
* against the path relative to the folder PREFIX names; a trailing '/' makes
* it folders-only; a pattern naming a folder ignores what is under it. */
int pic_ignore_add_glob(pic_ignore *ig, const char *text, size_t len, const char *prefix);
/* The per-folder ignore files, in the order they are read; .fslignore is the
* Fossil dialect, the rest gitignore. pic_ignore_add_named picks by NAME. */
#define PIC_IGNORE_NAMES 5
extern const char *const pic_ignore_names[PIC_IGNORE_NAMES];
int pic_ignore_add_named(pic_ignore *ig, const char *name, const char *text, size_t len, const char *prefix);
/* Fossil's versioned settings, read at the walk root only (Fossil dialect). */
#define PIC_IGNORE_SETTINGS 2
extern const char *const pic_ignore_settings[PIC_IGNORE_SETTINGS];
/* Reads every ignore file in DIR (REL is DIR's path from the walk's root;
* ROOT also reads the settings files) through pic_input_read. 0, or -1 when out of memory. */
#define PIC_IGNORE_MAX (1024 * 1024)
int pic_ignore_load_dir(pic_ignore *ig, const char *dir, const char *rel, int root);
/* Forgets the rules added after the first N (leaving a folder). */
void pic_ignore_truncate(pic_ignore *ig, size_t n);
void pic_ignore_free(pic_ignore *ig);
/* 1 when REL (slash separated, relative to the walk's root) is ignored. */
int pic_ignore_ignored(const pic_ignore *ig, const char *rel, int isdir);
#endif