From e274001bcfcd8be0c2996b9794a0a6b6a5d33a76 Mon Sep 17 00:00:00 2001 From: GZZ8 Date: Tue, 14 May 2024 11:27:31 +0200 Subject: [PATCH] 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 Signed-off-by: Filip Valgimigli --- canplayer.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/canplayer.c b/canplayer.c index eb9c569b..892deb73 100644 --- a/canplayer.c +++ b/canplayer.c @@ -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"); @@ -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; } }