Skip to content

Commit

Permalink
incase of --help, usage is valid output
Browse files Browse the repository at this point in the history
cathugger committed Apr 7, 2018

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
1 parent 2d9bea1 commit 0fe541b
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions main.c
Original file line number Diff line number Diff line change
@@ -395,9 +395,9 @@ static void *dofastwork(void *task)
return 0;
}

static void printhelp(const char *progname)
static void printhelp(FILE *out,const char *progname)
{
fprintf(stderr,
fprintf(out,
"Usage: %s filter [filter...] [options]\n"
" %s -f filterfile [options]\n"
"Options:\n"
@@ -418,10 +418,11 @@ static void printhelp(const char *progname)
"\t-S t - print statistics every specified ammount of seconds\n"
"\t-T - do not reset statistics counters when printing\n"
,progname,progname);
fflush(out);
exit(1);
}

void setworkdir(const char *wd)
static void setworkdir(const char *wd)
{
free(workdir);
size_t l = strlen(wd);
@@ -478,7 +479,7 @@ int main(int argc,char **argv)

const char *progname = argv[0];
if (argc <= 1)
printhelp(progname);
printhelp(stderr,progname);
argc--, argv++;

while (argc--) {
@@ -497,7 +498,7 @@ int main(int argc,char **argv)
if (!*arg)
ignoreargs = 1;
else if (!strcmp(arg, "help"))
printhelp(progname);
printhelp(stdout,progname);
else {
fprintf(stderr, "unrecognised argument: --%s\n", arg);
exit(1);
@@ -510,7 +511,7 @@ int main(int argc,char **argv)
continue;
}
else if (*arg == 'h')
printhelp(progname);
printhelp(stdout,progname);
else if (*arg == 'f') {
if (argc--)
loadfilterfile(*argv++);

0 comments on commit 0fe541b

Please sign in to comment.