summaryrefslogtreecommitdiff
path: root/config.c
diff options
context:
space:
mode:
authorpommicket <pommicket@gmail.com>2023-01-02 14:10:38 -0500
committerpommicket <pommicket@gmail.com>2023-01-02 14:10:38 -0500
commitf791aa01fad7e81223808584212c6a1a4c80ca07 (patch)
treef93d53a62035cdad7f16b97fb28c83c7acfaf14f /config.c
parentc0d0117a963cf8e4dfb28b919087d8a8ecbbca6e (diff)
finish restructuring
Diffstat (limited to 'config.c')
-rw-r--r--config.c25
1 files changed, 25 insertions, 0 deletions
diff --git a/config.c b/config.c
index bc02e5c..4582f3b 100644
--- a/config.c
+++ b/config.c
@@ -170,6 +170,31 @@ static void context_copy(SettingsContext *dest, const SettingsContext *src) {
dest->path = str_dup(src->path);
}
+// score is higher if context is closer match.
+long context_score(const char *path, Language lang, const SettingsContext *context) {
+ long score = 0;
+
+ if (context->language) {
+ if (lang == context->language) {
+ score += 10000;
+ } else {
+ // dont use this. it's language-specific and for the wrong language.
+ return INT_MIN;
+ }
+ }
+
+ if (context->path) {
+ if (path && str_has_path_prefix(path, context->path)) {
+ score += (long)strlen(context->path);
+ } else {
+ // dont use this. it's path-specific and for the wrong path.
+ return INT_MIN;
+ }
+ }
+
+ return score;
+}
+
/* does being in the context of `parent` imply you are in the context of `child`? */
static bool context_is_parent(const SettingsContext *parent, const SettingsContext *child) {
if (child->language == 0 && parent->language != 0)