commit a2a917d168df847c44df0fb265f7eaf811a48d9c
parent 8d5ba0f61391a8ac1edf46302ac798e0f89f102d
Author: Drew DeVault <sir@cmpwn.com>
Date: Sun, 7 Mar 2021 14:34:12 -0500
hare::module: import tags_compat & update eligible
Diffstat:
1 file changed, 20 insertions(+), 2 deletions(-)
diff --git a/hare/module/scan.ha b/hare/module/scan.ha
@@ -125,8 +125,7 @@ fn eligible(ctx: *context, name: path::path) bool = {
t: []tag => t,
};
defer tags_free(tags);
- // TODO: Check tag compatibility
- return true;
+ return tags_compat(ctx.tags, tags);
};
fn type_for_ext(name: path::path) (filetype | void) = {
@@ -218,3 +217,22 @@ export fn tags_free(tags: []tag) void = {
};
free(tags);
};
+
+// Compares two tag sets and tells you if they are compatible.
+export fn tags_compat(have: []tag, want: []tag) bool = {
+ // XXX: O(n²), lame
+ for (let i = 0z; i < len(want); i += 1) {
+ let present = false;
+ for (let j = 0z; j < len(have); j += 1) {
+ if (have[j].name == want[i].name) {
+ present = true;
+ break;
+ };
+ };
+ switch (want[i].mode) {
+ tag_mode::INCLUSIVE => if (!present) return false,
+ tag_mode::EXCLUSIVE => if (present) return false,
+ };
+ };
+ return true;
+};