read from stdin if no domain argument
This commit is contained in:
parent
abc56bc6dd
commit
7cc3eed46b
27
tools/psl.c
27
tools/psl.c
|
@ -32,8 +32,10 @@
|
||||||
# include <config.h>
|
# include <config.h>
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#include <unistd.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
#include <ctype.h>
|
||||||
#include <libpsl.h>
|
#include <libpsl.h>
|
||||||
|
|
||||||
static void usage(int err, FILE* f)
|
static void usage(int err, FILE* f)
|
||||||
|
@ -135,10 +137,35 @@ int main(int argc, const char *const *argv)
|
||||||
exit(2);
|
exit(2);
|
||||||
}
|
}
|
||||||
if (arg >= argv + argc) {
|
if (arg >= argv + argc) {
|
||||||
|
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");
|
fprintf(stderr, "No domains given - aborting\n");
|
||||||
exit(3);
|
exit(3);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (mode == 1) {
|
if (mode == 1) {
|
||||||
for (; arg < argv + argc; arg++)
|
for (; arg < argv + argc; arg++)
|
||||||
|
|
Loading…
Reference in New Issue