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 <filip.valgimigli@unimore.it>
Signed-off-by: Filip Valgimigli <filip.valgimigli@unimore.it>
  • Loading branch information
GGZ8 and delta512 committed May 14, 2024
1 parent 185c14f commit 23648c8
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions canplayer.c
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,9 @@ static void print_usage(char *prg)
fprintf(stderr, " -x (disable local "
"loopback of sent CAN frames)\n");
fprintf(stderr, " -v (verbose: print "
"sent CAN frames)\n\n");
"sent CAN frames)\n");
fprintf(stderr, " -h (show "
"this help message)\n\n");
fprintf(stderr, "Interface assignment:\n");
fprintf(stderr, " 0..n assignments like <write-if>=<log-if>\n\n");
fprintf(stderr, " e.g. vcan2=can0 (send frames received from can0 on "
Expand Down Expand Up @@ -279,7 +281,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 +336,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 23648c8

Please sign in to comment.