Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/gettext From William Orr:



details:   https://anonhg.NetBSD.org/src/rev/436f95971f0a
branches:  trunk
changeset: 809466:436f95971f0a
user:      christos <christos%NetBSD.org@localhost>
date:      Sun Jul 12 11:40:52 2015 +0000

description:
>From William Orr:
- add long options
- print usage on invalid command line args

diffstat:

 usr.bin/gettext/gettext.c |  24 ++++++++++++++++++------
 1 files changed, 18 insertions(+), 6 deletions(-)

diffs (72 lines):

diff -r 7dc4d3897548 -r 436f95971f0a usr.bin/gettext/gettext.c
--- a/usr.bin/gettext/gettext.c Sun Jul 12 11:27:52 2015 +0000
+++ b/usr.bin/gettext/gettext.c Sun Jul 12 11:40:52 2015 +0000
@@ -1,4 +1,4 @@
-/*     $NetBSD: gettext.c,v 1.2 2015/06/03 23:15:22 enami Exp $        */
+/*     $NetBSD: gettext.c,v 1.3 2015/07/12 11:40:52 christos Exp $     */
 
 /*-
  * Copyright (c) 2015 William Orr <will%worrbase.com@localhost>
@@ -26,7 +26,7 @@
  * SUCH DAMAGE.
  */
 #include <sys/cdefs.h>
-__RCSID("$NetBSD: gettext.c,v 1.2 2015/06/03 23:15:22 enami Exp $");
+__RCSID("$NetBSD: gettext.c,v 1.3 2015/07/12 11:40:52 christos Exp $");
 
 #include <err.h>
 #include <errno.h>
@@ -39,12 +39,20 @@
 #include <string.h>
 #include <util.h>
 
+static struct option longopts[] = {
+       { "help",       no_argument,        NULL,   'h' },
+       { "domain",     required_argument,  NULL,   'd' },
+       { NULL,         0,                  NULL,   '\0' },
+};
+
 static __dead void
 usage(int exit_status)
 {
 
        fprintf(stderr, "Usage: %s [-ehn] [[<textdomain>] <msgid>]\n",
            getprogname());
+       fprintf(stderr, "Usage: %s [-ehn] -d <textdomain> <msgid>\n",
+           getprogname());
        fprintf(stderr, "Usage: %s -s [<msgid>]...\n", getprogname());
        exit(exit_status);
 }
@@ -140,7 +148,8 @@
        setlocale(LC_ALL, "");
        setprogname(argv[0]);
 
-       while ((ch = getopt(argc, argv, "d:EehnsV")) != -1) {
+       while ((ch = getopt_long(argc, argv, "d:eEhnsV", longopts, NULL)) != -1)
+       {
                switch (ch) {
                case 'd':
                        msgdomain = estrdup(optarg);
@@ -173,7 +182,8 @@
 
        if (argc == 0) {
                free(msgdomain);
-               errx(EXIT_FAILURE, "missing msgid");
+               warnx("missing msgid");
+               usage(EXIT_FAILURE);
        }
 
        /* msgdomain can be passed as optional arg iff -s is not passed */
@@ -184,8 +194,10 @@
 
                        argc -= 1;
                        argv += 1;
-               } else if (argc > 2)
-                       errx(EXIT_FAILURE, "too many arguments");
+               } else if (argc > 2) {
+                       warnx("too many arguments");
+                       usage(EXIT_FAILURE);
+               }
        }
 
        /* msgdomain can be passed as env var */



Home | Main Index | Thread Index | Old Index