]> git.draconx.ca Git - cdecl99.git/commitdiff
Improve usage messages a bit.
authorNick Bowler <nbowler@draconx.ca>
Wed, 24 Feb 2021 05:24:02 +0000 (00:24 -0500)
committerNick Bowler <nbowler@draconx.ca>
Wed, 3 Mar 2021 01:23:58 +0000 (20:23 -0500)
src/cdecl99.c

index bebdfffa43de00ee166bfcbee9b13e9ee70e9015..5941009eb7df8401e897b13ebe3795872872cbb5 100644 (file)
@@ -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;