From 0f365ac0521b25246f793ce13a97ce8ebb077b9e Mon Sep 17 00:00:00 2001 From: Ulrich Drepper Date: Fri, 11 Feb 2000 20:38:31 +0000 Subject: [PATCH] Suppress messages if first character of optstring is a colon. --- posix/getopt.c | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/posix/getopt.c b/posix/getopt.c index dfff5212498..efd822358f8 100644 --- a/posix/getopt.c +++ b/posix/getopt.c @@ -3,7 +3,7 @@ "Keep this file name-space clean" means, talk to drepper@gnu.org before changing it! - Copyright (C) 1987, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 2000 + Copyright (C) 1987, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99 Free Software Foundation, Inc. The GNU C Library is free software; you can redistribute it and/or @@ -517,12 +517,6 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only) int *longind; int long_only; { - /* POSIX.2 requires that messages are not only suppressed if `opterr' is - zero but also if the first character of the `optstring' is a colon. */ - int print_errors = opterr; - if (optstring[0] == ':') - print_errors = 0; - optarg = NULL; if (optind == 0 || !__getopt_initialized) @@ -679,7 +673,7 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only) if (ambig && !exact) { - if (print_errors) + if (opterr) fprintf (stderr, _("%s: option `%s' is ambiguous\n"), argv[0], argv[optind]); nextchar += strlen (nextchar); @@ -700,7 +694,7 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only) optarg = nameend + 1; else { - if (print_errors) + if (opterr) { if (argv[optind - 1][1] == '-') /* --option */ @@ -726,7 +720,7 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only) optarg = argv[optind++]; else { - if (print_errors) + if (opterr) fprintf (stderr, _("%s: option `%s' requires an argument\n"), argv[0], argv[optind - 1]); @@ -753,7 +747,7 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only) if (!long_only || argv[optind][1] == '-' || my_index (optstring, *nextchar) == NULL) { - if (print_errors) + if (opterr) { if (argv[optind][1] == '-') /* --option */ @@ -783,7 +777,7 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only) if (temp == NULL || c == ':') { - if (print_errors) + if (opterr) { if (posixly_correct) /* 1003.2 specifies the format of this message. */ @@ -817,7 +811,7 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only) } else if (optind == argc) { - if (print_errors) + if (opterr) { /* 1003.2 specifies the format of this message. */ fprintf (stderr, _("%s: option requires an argument -- %c\n"), @@ -866,7 +860,7 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only) } if (ambig && !exact) { - if (print_errors) + if (opterr) fprintf (stderr, _("%s: option `-W %s' is ambiguous\n"), argv[0], argv[optind]); nextchar += strlen (nextchar); @@ -884,7 +878,7 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only) optarg = nameend + 1; else { - if (print_errors) + if (opterr) fprintf (stderr, _("\ %s: option `-W %s' doesn't allow an argument\n"), argv[0], pfound->name); @@ -899,7 +893,7 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only) optarg = argv[optind++]; else { - if (print_errors) + if (opterr) fprintf (stderr, _("%s: option `%s' requires an argument\n"), argv[0], argv[optind - 1]); @@ -946,7 +940,7 @@ _getopt_internal (argc, argv, optstring, longopts, longind, long_only) } else if (optind == argc) { - if (print_errors) + if (opterr) { /* 1003.2 specifies the format of this message. */ fprintf (stderr, -- 2.47.2