Skip to content

Commit

Permalink
Refactor the help/usage message for canplayer
Browse files Browse the repository at this point in the history
Limit the error return value only to unknown options.
If the utility is invoked with the help option '-h',
display the usage message and exit successfully.

Co-authored-by: Filip Valgimigli <[email protected]>
Signed-off-by: Filip Valgimigli <[email protected]>
  • Loading branch information
GGZ8 and delta512 committed May 14, 2024
1 parent 185c14f commit e274001
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions canplayer.c
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ int main(int argc, char **argv)
char *fret;
unsigned long long sec, usec;

while ((opt = getopt(argc, argv, "I:l:tin:g:s:xv?")) != -1) {
while ((opt = getopt(argc, argv, "I:l:tin:g:s:xvh")) != -1) {
switch (opt) {
case 'I':
infile = fopen(optarg, "r");
Expand Down Expand Up @@ -334,10 +334,14 @@ int main(int argc, char **argv)
verbose++;
break;

case '?':
case 'h':
print_usage(basename(argv[0]));
exit(EXIT_SUCCESS);
break;

default:
print_usage(basename(argv[0]));
return 1;
exit(EXIT_FAILURE);
break;
}
}
Expand Down

0 comments on commit e274001

Please sign in to comment.