From 7cc3eed46bc948abb62f2909312899b6f234fdf6 Mon Sep 17 00:00:00 2001 From: Tim Ruehsen Date: Sun, 15 Jun 2014 22:32:18 +0200 Subject: [PATCH] read from stdin if no domain argument --- tools/psl.c | 31 +++++++++++++++++++++++++++++-- 1 file changed, 29 insertions(+), 2 deletions(-) diff --git a/tools/psl.c b/tools/psl.c index 3764599..ff28285 100644 --- a/tools/psl.c +++ b/tools/psl.c @@ -32,8 +32,10 @@ # include #endif +#include #include #include +#include #include static void usage(int err, FILE* f) @@ -135,8 +137,33 @@ int main(int argc, const char *const *argv) exit(2); } if (arg >= argv + argc) { - fprintf(stderr, "No domains given - aborting\n"); - exit(3); + if (isatty(STDIN_FILENO)) { + char buf[256], *domain; + size_t len; + + // read URLs from STDIN + while (fgets(buf, sizeof(buf), stdin)) { + for (domain = buf; isspace(*domain); domain++); // skip leading spaces + if (*domain == '#' || !*domain) continue; // skip empty lines and comments + 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)); + else if (mode == 2) + printf("%s: %s\n", domain, psl_unregistrable_domain(psl, domain)); + 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)); + } + + psl_free(psl); + exit(0); + } else { + fprintf(stderr, "No domains given - aborting\n"); + exit(3); + } } }