From 9699dfce074fac80d8d622f02ea6d8bb2f55cf00 Mon Sep 17 00:00:00 2001 From: Marcus Nilsson Date: Wed, 21 Aug 2024 16:45:57 +0200 Subject: [PATCH 1/2] Issue #40: Close file when it's no longer needed --- src/tools/uchardet.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tools/uchardet.cpp b/src/tools/uchardet.cpp index 56eed7b..d5ff167 100644 --- a/src/tools/uchardet.cpp +++ b/src/tools/uchardet.cpp @@ -266,6 +266,7 @@ int main(int argc, char ** argv) printf("%s: ", filename); } detect(handle, f, show_lang, verbose); + fclose(f); } uchardet_delete(handle); From 06029ec3340cdf6bf9a6a537dafb3f39eda0560e Mon Sep 17 00:00:00 2001 From: Jehan Date: Fri, 8 Aug 2025 11:40:10 +0200 Subject: [PATCH 2/2] src: allow setting a default language in the CLI tool. The syntax of --weight stays the same with the addition that the language '*' means setting the default weight. For instance, if you are sure that your input is either French or English, you could run: > uchardet -l -w 'fr:1,en:1,*:0' (setting same weight to French and English, and everything else to 0) --- src/tools/uchardet.cpp | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/tools/uchardet.cpp b/src/tools/uchardet.cpp index d5ff167..3aa65da 100644 --- a/src/tools/uchardet.cpp +++ b/src/tools/uchardet.cpp @@ -190,7 +190,10 @@ int main(int argc, char ** argv) return 1; } *comma = '\0'; - uchardet_weigh_language(handle, lang_weight, strtof (comma + 1, NULL)); + if (strcmp (lang_weight, "*") == 0) + uchardet_set_default_weight(handle, strtof (comma + 1, NULL)); + else + uchardet_weigh_language(handle, lang_weight, strtof (comma + 1, NULL)); } while ((lang_weight = strtok_r (NULL, ",", &saveptr))); }