fixed locale/charset support

This commit is contained in:
Tim Ruehsen 2014-06-18 12:28:22 +02:00
parent 935b44b3ea
commit a0a9e76261
1 changed files with 41 additions and 22 deletions

View File

@ -73,6 +73,10 @@ int main(int argc, const char *const *argv)
const char *const *arg, *psl_file = NULL, *cookie_domain = NULL;
psl_ctx_t *psl = (psl_ctx_t *) psl_builtin();
/* set current locale according to the environment variables */
#include <locale.h>
setlocale(LC_ALL, "");
for (arg = argv + 1; arg < argv + argc; arg++) {
if (!strncmp(*arg, "--", 2)) {
if (!strcmp(*arg, "--is-public-suffix"))
@ -137,9 +141,9 @@ int main(int argc, const char *const *argv)
exit(2);
}
if (arg >= argv + argc) {
if (isatty(STDIN_FILENO)) {
char buf[256], *domain;
char buf[256], *domain, *lower;
size_t len;
int rc;
// read URLs from STDIN
while (fgets(buf, sizeof(buf), stdin)) {
@ -148,22 +152,30 @@ int main(int argc, const char *const *argv)
for (len = strlen(domain); len && isspace(domain[len - 1]); len--); // skip trailing spaces
domain[len] = 0;
if (mode == 1)
printf("%s: %d\n", domain, psl_is_public_suffix(psl, domain));
if ((rc = psl_str_to_utf8lower(domain, NULL, NULL, &lower)) != 0)
fprintf(stderr, "%s: Failed to convert to lowercase UTF-8 (%d)\n", domain, rc);
else if (mode == 1)
printf("%s: %d (%s)\n", domain, psl_is_public_suffix(psl, lower), lower);
else if (mode == 2)
printf("%s: %s\n", domain, psl_unregistrable_domain(psl, domain));
printf("%s: %s\n", domain, psl_unregistrable_domain(psl, lower));
else if (mode == 3)
printf("%s: %s\n", domain, psl_registrable_domain(psl, domain));
else if (mode == 4)
printf("%s: %d\n", domain, psl_is_cookie_domain_acceptable(psl, domain, cookie_domain));
printf("%s: %s\n", domain, psl_registrable_domain(psl, lower));
else if (mode == 4) {
char *cookie_domain_lower;
if ((rc = psl_str_to_utf8lower(domain, NULL, NULL, &cookie_domain_lower)) != 0)
fprintf(stderr, "%s: Failed to convert cookie domain '%s' to lowercase UTF-8 (%d)\n", domain, cookie_domain, rc);
else
printf("%s: %d\n", domain, psl_is_cookie_domain_acceptable(psl, lower, cookie_domain));
free(cookie_domain_lower);
}
free(lower);
}
psl_free(psl);
exit(0);
} else {
fprintf(stderr, "No domains given - aborting\n");
exit(3);
}
}
}
@ -199,6 +211,13 @@ int main(int argc, const char *const *argv)
printf("builtin compile time: %ld (%s)\n", psl_builtin_compile_time(), time2str(psl_builtin_compile_time()));
printf("builtin file time: %ld (%s)\n", psl_builtin_file_time(), time2str(psl_builtin_file_time()));
printf("builtin SHA1 file hash: %s\n", psl_builtin_sha1sum());
#ifdef WITH_LIBICU
#include <unicode/uloc.h>
#include <unicode/ucnv.h>
printf("uloc_getDefault=%s\n", uloc_getDefault());
printf("ucnv_getDefaultName=%s\n", ucnv_getDefaultName());
#endif
} else
printf("No builtin PSL data available\n");
}