diff options
| author | Mitja Felicijan <mitja.felicijan@gmail.com> | 2023-11-09 23:19:53 +0100 |
|---|---|---|
| committer | Mitja Felicijan <mitja.felicijan@gmail.com> | 2023-11-09 23:19:53 +0100 |
| commit | 1566b6faa8534118c3566188181367cd0868468f (patch) | |
| tree | 1de8d4b369efb5e592685a31088f798a6b63ffa1 /examples/dte/filetype.h | |
| parent | 349991bf6efe473ab9a5cbdae0a8114d72b997e3 (diff) | |
| download | crep-1566b6faa8534118c3566188181367cd0868468f.tar.gz | |
Added partial matching and introduced threads
Diffstat (limited to 'examples/dte/filetype.h')
| -rw-r--r-- | examples/dte/filetype.h | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/examples/dte/filetype.h b/examples/dte/filetype.h new file mode 100644 index 0000000..cec4d85 --- /dev/null +++ b/examples/dte/filetype.h @@ -0,0 +1,35 @@ +#ifndef FILETYPE_H +#define FILETYPE_H + +#include <stdbool.h> +#include <string.h> +#include "util/macros.h" +#include "util/ptr-array.h" +#include "util/string-view.h" +#include "util/string.h" + +// Note: the order of these values changes the order of iteration +// in find_ft() +typedef enum { + FT_INTERPRETER, + FT_BASENAME, + FT_CONTENT, + FT_EXTENSION, + FT_FILENAME, +} FileDetectionType; + +PURE +static inline bool is_valid_filetype_name(const char *name) +{ + size_t n = strcspn(name, " \t/"); + return n > 0 && n < 64 && name[n] == '\0' && name[0] != '-'; +} + +bool add_filetype(PointerArray *filetypes, const char *name, const char *str, FileDetectionType type) NONNULL_ARGS WARN_UNUSED_RESULT; +bool is_ft(const PointerArray *filetypes, const char *name); +const char *find_ft(const PointerArray *filetypes, const char *filename, StringView line); +void collect_ft(const PointerArray *filetypes, PointerArray *a, const char *prefix); +String dump_filetypes(const PointerArray *filetypes); +void free_filetypes(PointerArray *filetypes); + +#endif |
