Refactor the help/usage message for canplayer

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>
pull/522/head
GZZ8 2024-05-14 11:27:31 +02:00 committed by Filip Valgimigli
parent 185c14f464
commit 23648c8a31
No known key found for this signature in database
GPG Key ID: 6F47D53C051F9939
1 changed files with 10 additions and 4 deletions

View File

@ -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 "
@ -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");
@ -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;
}
}