aboutsummaryrefslogtreecommitdiff
path: root/src/Main.c
diff options
context:
space:
mode:
authorfrosty <frostinator33@airmail.cc>2026-10-03 13:30:21 -0400
committerfrosty <frostinator33@airmail.cc>2026-10-03 13:30:21 -0400
commit65500761a632d22057d3b3e709b91dde168e125b (patch)
tree0ff30abf8de4120e5ed8db296688e0d85b65736b /src/Main.c
parentcb716af752fb0b46aa8f78d3cbd5189a09642f39 (diff)
feat: add --exclude/--include
Diffstat (limited to 'src/Main.c')
-rw-r--r--src/Main.c19
1 files changed, 18 insertions, 1 deletions
diff --git a/src/Main.c b/src/Main.c
index b7c77f1..0acadf1 100644
--- a/src/Main.c
+++ b/src/Main.c
@@ -6,6 +6,13 @@
#include <libxml/parser.h>
#include <stdio.h>
#include <stdlib.h>
+#include <string.h>
+
+static const char *base_name(const char *path) {
+ const char *slash = strrchr(path, '/');
+
+ return slash == NULL ? path : slash + 1;
+}
static int run(int argc, char **argv) {
CliOptions options;
@@ -16,6 +23,7 @@ static int run(int argc, char **argv) {
parse_result = cli_parse(argc, argv, &options);
if (parse_result != CLI_PARSE_OK) {
+ cli_free_options(&options);
return parse_result == CLI_PARSE_ERROR ? EXIT_FAILURE : EXIT_SUCCESS;
}
@@ -26,6 +34,7 @@ static int run(int argc, char **argv) {
automatic_output = path_make_default_output(options.input_path);
if (automatic_output == NULL) {
logger_error("unable to allocate output path");
+ cli_free_options(&options);
return EXIT_FAILURE;
}
output_path = automatic_output;
@@ -33,12 +42,20 @@ static int run(int argc, char **argv) {
if (options.input_type == INPUT_TYPE_DIRECTORY) {
result = process_directory(options.input_path, output_path,
- options.overwrite_output);
+ options.overwrite_output, &options.patterns);
+ } else if (pattern_list_resolve(
+ &options.patterns, base_name(options.input_path), 0,
+ pattern_list_default_kind(&options.patterns)) ==
+ PATTERN_EXCLUDE) {
+ logger_error("input file is excluded by the active patterns: %s",
+ options.input_path);
+ result = -1;
} else {
result = process_file(options.input_path, output_path);
}
free(automatic_output);
+ cli_free_options(&options);
return result == 0 ? EXIT_SUCCESS : EXIT_FAILURE;
}