summaryrefslogtreecommitdiff
path: root/src/stty.c
diff options
context:
space:
mode:
authorJim Meyering <jim@meyering.net>1994-02-16 23:36:41 +0000
committerJim Meyering <jim@meyering.net>1994-02-16 23:36:41 +0000
commit695581bf6503a2c9ac0a56f0ecebc4a99f7f8b47 (patch)
treeb022a7ba3b98c6fb0ecb690e02c1122a795e82d9 /src/stty.c
parent4923c48619ce3c83f5141b579ecd59fbd13353bc (diff)
downloadcoreutils-695581bf6503a2c9ac0a56f0ecebc4a99f7f8b47.tar.xz
* stty.c (main): Use getopt only to recognize long options.
Hand code the loop to detect -a, -g, -ag and -ga. Using getopt to detect the short options loses (because we have to ignore unrecognized options and we are allowing GNU getopt to permute) because e.g. `-tabs' is interpreted as a group of options, one of which is `-a'. Before, running `stty -tabs echo' gave this error: stty: when specifying an output style, modes may not be set Reported by Arne H. Juul.
Diffstat (limited to 'src/stty.c')
-rw-r--r--src/stty.c44
1 files changed, 36 insertions, 8 deletions
diff --git a/src/stty.c b/src/stty.c
index b094f8bce..1b9b9242d 100644
--- a/src/stty.c
+++ b/src/stty.c
@@ -641,21 +641,16 @@ main (argc, argv)
parse_long_options (argc, argv, usage);
- /* Assume we'll be setting modes rather than displaying them.
- But if either of -a or -g is specified, set this to zero. */
-
output_type = changed;
verbose_output = 0;
recoverable_output = 0;
+ /* Recognize the long options only. */
opterr = 0;
- while ((optc = getopt_long (argc, argv, "ag", longopts, (int *) 0)) != EOF)
+ while ((optc = getopt_long (argc, argv, "", longopts, (int *) 0)) != EOF)
{
switch (optc)
{
- case 0:
- break;
-
case 'a':
verbose_output = 1;
output_type = all;
@@ -671,6 +666,39 @@ main (argc, argv)
}
}
+ /* Recognize short options and combinations: -a, -g, -ag, and -ga.
+ They need not precede non-options. We cannot use GNU getopt because
+ it would treat -tabs and -ixany as uses of the -a option. */
+ for (k = optind; k < argc; k++)
+ {
+ if (argv[k][0] == '-')
+ {
+ if (argv[k][1] == 'a'
+ && argv[k][2] == '\0')
+ {
+ ++optind;
+ verbose_output = 1;
+ }
+ else if (argv[k][1] == 'g'
+ && argv[k][2] == '\0')
+ {
+ ++optind;
+ recoverable_output = 1;
+ }
+ else if ((argv[k][1] == 'g'
+ && argv[k][2] == 'a'
+ && argv[k][3] == '\0')
+ || (argv[k][1] == 'a'
+ && argv[k][2] == 'g'
+ && argv[k][3] == '\0'))
+ {
+ ++optind;
+ verbose_output = 1;
+ recoverable_output = 1;
+ }
+ }
+ }
+
/* Specifying both -a and -g gets an error. */
if (verbose_output && recoverable_output)
error (2, 0,
@@ -678,7 +706,7 @@ main (argc, argv)
\tmutually exclusive");
/* Specifying any other arguments with -a or -g gets an error. */
- if (argc > 2 && (verbose_output || recoverable_output))
+ if (argc - optind > 0 && (verbose_output || recoverable_output))
error (2, 0, "when specifying an output style, modes may not be set");
/* Initialize to all zeroes so there is no risk memcmp will report a