[PATCH 3/8] agetty: use long options

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

 



This patch will introducing --help and --version options, which
does not have short version. Reason to this is a that the -h was
already assigned.

Signed-off-by: Sami Kerola <kerolasa@xxxxxx>
---
 term-utils/agetty.c |   69 ++++++++++++++++++++++++++++++++++++++++++++++----
 1 files changed, 63 insertions(+), 6 deletions(-)

diff --git a/term-utils/agetty.c b/term-utils/agetty.c
index 91f9ee2..9eda573 100644
--- a/term-utils/agetty.c
+++ b/term-utils/agetty.c
@@ -215,7 +215,7 @@ char *get_logname P_((struct options *op, struct chardata *cp, struct termios *t
 void termio_final P_((struct options *op, struct termios *tp, struct chardata *cp));
 int caps_lock P_((char *s));
 int bcode P_((char *s));
-void usage P_((void));
+void usage P_((FILE *out));
 void error P_((const char *, ...));
 #undef P_
 
@@ -359,7 +359,33 @@ parse_args(argc, argv, op)
     extern int optind;			/* getopt */
     int     c;
 
-    while (isascii(c = getopt(argc, argv, "8cI:LH:f:hil:mst:wUn"))) {
+    static const enum
+    {
+	VERSION_OPTION = CHAR_MAX + 1,
+	HELP_OPTION
+    };
+    static const struct option longopts[] = {
+	{  "8bits",	     no_argument,	 0,  '8'  },
+	{  "noreset",	     no_argument,	 0,  'c'  },
+	{  "issue-file",     required_argument,  0,  'f'  },
+	{  "flow-control",   no_argument,	 0,  'h'  },
+	{  "host",	     required_argument,  0,  'H'  },
+	{  "noissue",	     no_argument,	 0,  'i'  },
+	{  "init-string",    required_argument,  0,  'I'  },
+	{  "login-program",  required_argument,  0,  'l'  },
+	{  "local-line",     no_argument,	 0,  'L'  },
+	{  "extract-baud",   no_argument,	 0,  'm'  },
+	{  "skip-login",     no_argument,	 0,  'n'  },
+	{  "keep-baud",      no_argument,	 0,  's'  },
+	{  "timeout",	     required_argument,  0,  't'  },
+	{  "detect-case",    no_argument,	 0,  'U'  },
+	{  "wait-cr",	     no_argument,	 0,  'w'  },
+	{  "version",	     no_argument,	 0,  VERSION_OPTION  },
+	{  "help",	     no_argument,	 0,  HELP_OPTION     },
+	{ NULL, 0, 0, 0 }
+    };
+
+    while ((c = getopt_long(argc, argv, "8cf:hH:iI:l:Lmnst:Uw", longopts, NULL)) != -1) {
 	switch (c) {
 	case 'c':
 	    op->flags |= F_KEEPCFLAGS;
@@ -442,8 +468,14 @@ parse_args(argc, argv, op)
 	case 'U':
 	    op->flags |= F_LCUC;
 	    break;
+        case VERSION_OPTION:
+            printf(_("%s from %s\n"), program_invocation_short_name,
+                                      PACKAGE_STRING);
+            exit(EXIT_SUCCESS);
+        case HELP_OPTION:
+            usage(stdout);
 	default:
-	    usage();
+	    usage(stderr);
 	}
     }
 	debug("after getopt loop\n");
@@ -1206,10 +1238,35 @@ bcode(s)
 
 /* usage - explain */
 
-void __attribute__((__noreturn__)) usage(void)
+void __attribute__((__noreturn__)) usage(FILE *out)
 {
-    fprintf(stderr, _("Usage: %s [-8hiLmsUw] [-l login_program] [-t timeout] [-I initstring] [-H login_host] baud_rate,... line [termtype]\nor\t[-hiLmw] [-l login_program] [-t timeout] [-I initstring] [-H login_host] line baud_rate,... [termtype]\n"), progname);
-    exit(EXIT_FAILURE);
+    fprintf(out, _(
+	"\nUsage:\n"
+	"    %s [options] line baud_rate,... [termtype]\n"
+	" or %s [options] baud_rate,... line [termtype]\n"),
+	program_invocation_short_name, program_invocation_short_name);
+
+    fprintf(out, _(
+	"\nOptions:\n"
+	" -8, --8bits                assume 8-bit tty\n"
+	" -c, --noreset              do not reset control mode\n"
+	" -f, --issue-file FILE      display issue file\n"
+	" -h, --flow-control         enable hardware flow control\n"
+	" -H, --host HOSTNAME        specify login host\n"
+	" -i, --noissue              do not display issue file\n"
+	" -I, --init-string STRING   set init string\n"
+	" -l, --login-program FILE   specify login program\n"
+	" -L, --local-line           force local line\n"
+	" -m, --extract-baud         extract baud rate during connect\n"
+	" -n, --skip-login           do not prompt for login\n"
+	" -s, --keep-baud            try to keep baud rate after break\n"
+	" -t, --timeout NUMBER       login process timeout\n"
+	" -U, --detect-case          detect uppercase terminal\n"
+	" -w, --wait-cr              wait carriage-return\n"
+	"     --version              output version information and exit\n"
+	"     --help                 display this help and exit\n\n"));
+
+    exit(out == stderr ? EXIT_FAILURE : EXIT_SUCCESS);
 }
 
 /* error - report errors to console or syslog; only understands %s and %m */
-- 
1.7.4.4

--
To unsubscribe from this list: send the line "unsubscribe util-linux" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at  http://vger.kernel.org/majordomo-info.html


[Index of Archives]     [Netdev]     [Ethernet Bridging]     [Linux Wireless]     [Kernel Newbies]     [Security]     [Linux for Hams]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux RAID]     [Linux Admin]     [Samba]

  Powered by Linux