Skip to content

Commit 23648c8

Browse files
GGZ8delta512
andcommitted
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>
1 parent 185c14f commit 23648c8

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

canplayer.c

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,9 @@ static void print_usage(char *prg)
116116
fprintf(stderr, " -x (disable local "
117117
"loopback of sent CAN frames)\n");
118118
fprintf(stderr, " -v (verbose: print "
119-
"sent CAN frames)\n\n");
119+
"sent CAN frames)\n");
120+
fprintf(stderr, " -h (show "
121+
"this help message)\n\n");
120122
fprintf(stderr, "Interface assignment:\n");
121123
fprintf(stderr, " 0..n assignments like <write-if>=<log-if>\n\n");
122124
fprintf(stderr, " e.g. vcan2=can0 (send frames received from can0 on "
@@ -279,7 +281,7 @@ int main(int argc, char **argv)
279281
char *fret;
280282
unsigned long long sec, usec;
281283

282-
while ((opt = getopt(argc, argv, "I:l:tin:g:s:xv?")) != -1) {
284+
while ((opt = getopt(argc, argv, "I:l:tin:g:s:xvh")) != -1) {
283285
switch (opt) {
284286
case 'I':
285287
infile = fopen(optarg, "r");
@@ -334,10 +336,14 @@ int main(int argc, char **argv)
334336
verbose++;
335337
break;
336338

337-
case '?':
339+
case 'h':
340+
print_usage(basename(argv[0]));
341+
exit(EXIT_SUCCESS);
342+
break;
343+
338344
default:
339345
print_usage(basename(argv[0]));
340-
return 1;
346+
exit(EXIT_FAILURE);
341347
break;
342348
}
343349
}

0 commit comments

Comments
 (0)