incase of --help, usage is valid output

This commit is contained in:
cathugger 2018-04-07 11:59:30 +00:00
parent 2d9bea188f
commit 0fe541b5fb

13
main.c
View file

@ -395,9 +395,9 @@ end:
return 0; 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" "Usage: %s filter [filter...] [options]\n"
" %s -f filterfile [options]\n" " %s -f filterfile [options]\n"
"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-S t - print statistics every specified ammount of seconds\n"
"\t-T - do not reset statistics counters when printing\n" "\t-T - do not reset statistics counters when printing\n"
,progname,progname); ,progname,progname);
fflush(out);
exit(1); exit(1);
} }
void setworkdir(const char *wd) static void setworkdir(const char *wd)
{ {
free(workdir); free(workdir);
size_t l = strlen(wd); size_t l = strlen(wd);
@ -478,7 +479,7 @@ int main(int argc,char **argv)
const char *progname = argv[0]; const char *progname = argv[0];
if (argc <= 1) if (argc <= 1)
printhelp(progname); printhelp(stderr,progname);
argc--, argv++; argc--, argv++;
while (argc--) { while (argc--) {
@ -497,7 +498,7 @@ int main(int argc,char **argv)
if (!*arg) if (!*arg)
ignoreargs = 1; ignoreargs = 1;
else if (!strcmp(arg, "help")) else if (!strcmp(arg, "help"))
printhelp(progname); printhelp(stdout,progname);
else { else {
fprintf(stderr, "unrecognised argument: --%s\n", arg); fprintf(stderr, "unrecognised argument: --%s\n", arg);
exit(1); exit(1);
@ -510,7 +511,7 @@ int main(int argc,char **argv)
continue; continue;
} }
else if (*arg == 'h') else if (*arg == 'h')
printhelp(progname); printhelp(stdout,progname);
else if (*arg == 'f') { else if (*arg == 'f') {
if (argc--) if (argc--)
loadfilterfile(*argv++); loadfilterfile(*argv++);