From f2d4efbe8a7d51123b806e623835ddb6ccbc2f3a Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Wed, 24 Feb 2021 00:24:02 -0500 Subject: [PATCH] Improve usage messages a bit. --- src/cdecl99.c | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/src/cdecl99.c b/src/cdecl99.c index bebdfff..5941009 100644 --- a/src/cdecl99.c +++ b/src/cdecl99.c @@ -1,6 +1,6 @@ /* * Command line utility for making sense of C declarations. - * Copyright © 2011-2012, 2020 Nick Bowler + * Copyright © 2011-2012, 2020-2021 Nick Bowler * * This program is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by @@ -92,7 +92,7 @@ static void print_version(void) } puts(PACKAGE_STRING); - printf("Copyright %s 2020 Nick Bowler.\n", copysign); + printf("Copyright %s 2021 Nick Bowler.\n", copysign); puts("License GPLv3+: GNU GPL version 3 or any later version."); puts("This is free software: you are free to change and redistribute it."); puts("There is NO WARRANTY, to the extent permitted by law."); @@ -103,6 +103,9 @@ static void print_version(void) static void print_usage(FILE *f) { fprintf(f, "Usage: %s [options]\n", progname); + if (f != stdout) + fprintf(f, _("Try %s --help for more information.\n"), + progname); } /* @@ -237,7 +240,7 @@ retry: tmp = realloc(buf, rc + 1); if (!tmp) { - fprintf(stderr, "failed to allocate memory\n"); + fprintf(stderr, "%s\n", _("failed to allocate memory")); return NULL; } @@ -514,7 +517,7 @@ int main(int argc, char **argv) { bool show_intro = true, interactive = true, execute = false; const char *filename = NULL; - int opt, rc; + int i, opt, rc; if (argc > 0) progname = argv[0]; @@ -550,6 +553,17 @@ int main(int argc, char **argv) } } + if (optind < argc) { + fprintf(stderr, _("%s: excess command-line arguments:"), + progname); + for (i = optind; i < argc; i++) { + fprintf(stderr, " %s", argv[i]); + } + fprintf(stderr, "\n"); + print_usage(stderr); + return EXIT_FAILURE; + } + /* --filename and --execute imply --batch. */ if (filename || execute) interactive = false; -- 2.43.0