Skip to content

Commit

Permalink
Accept no argument along with - for stdin
Browse files Browse the repository at this point in the history
  • Loading branch information
wwalexander committed Mar 6, 2018
1 parent 736be43 commit 8fa6fa1
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
7 changes: 5 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ Usage

hostsblock [filterlist]

If the filterlist argument is `-`, hostsblock will read from stdin. For example,
If the filterlist argument is `-` or omitted, hostsblock will read from stdin.
For example,

curl -s https://www.fanboy.co.nz/r/fanboy-ultimate.txt | hostsblock -

Expand All @@ -33,4 +34,6 @@ list, read the hosts file entries from it with hostsblock, and concatenate the
original hosts file with the ad-blocking entries to create the actual hosts
file:

curl -s https://www.fanboy.co.nz/r/fanboy-ultimate.txt | hostsblock - | cat /etc/hosts~ - > /etc/hosts
curl -s https://www.fanboy.co.nz/r/fanboy-ultimate.txt |
hostsblock |
cat /etc/hosts~ - > /etc/hosts
6 changes: 3 additions & 3 deletions hostsblock.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,12 +114,12 @@ int main(int argc, char **argv)
char rule[MAX_DOMAIN_RULE_LENGTH];
char domain[MAX_DOMAIN_LENGTH] = { 0 };

if (argc != 2) {
if (argc > 2) {
fprintf(stderr, "usage: %s [filterlist]\n", argv[0]);
return 1;
}

if (!strncmp(argv[1], "-", 2)) list = stdin;
if (argc < 2 || !strncmp(argv[1], "-", 2)) list = stdin;
else list = fopen(argv[1], "r");

if (list == NULL) {
Expand Down

0 comments on commit 8fa6fa1

Please sign in to comment.