From 6a16bdb808b02977cc99f84b4adae420f99019d2 Mon Sep 17 00:00:00 2001 From: Kurtis Rader Date: Thu, 3 Mar 2016 15:36:17 -0800 Subject: assume getopt/getopt_long is available There is no longer a good reason to detect whether or not getopt_long() is available. All UNIX implementations we're likely to run on have it. And if we ever find one that doesn't the right thing to do is not fallback to getopt() but to include the getopt_long() source in our package like we do with the pcre2 library. Since it's licensed under LGPL we can legally do so if it becomes necessary. This partially addresses issue #2790. --- src/fish_indent.cpp | 47 ++++++++++++++++++++--------------------------- 1 file changed, 20 insertions(+), 27 deletions(-) (limited to 'src/fish_indent.cpp') diff --git a/src/fish_indent.cpp b/src/fish_indent.cpp index 60ed2334..037d9b77 100644 --- a/src/fish_indent.cpp +++ b/src/fish_indent.cpp @@ -21,13 +21,11 @@ Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA #include "config.h" +#include #include #include #include #include -#ifdef HAVE_GETOPT_H -#include -#endif #include #include #include @@ -297,40 +295,34 @@ int main(int argc, char *argv[]) output_type_ansi, output_type_html } output_type = output_type_plain_text; - - /* Whether to indent (true) or just reformat to one job per line (false) */ bool do_indent = true; - while (1) + const char *short_opts = "+hvi"; + const struct option long_opts[] = + { + { "no-indent", no_argument, NULL, 'i' }, + { "help", no_argument, NULL, 'h' }, + { "version", no_argument, NULL, 'v' }, + { "html", no_argument, NULL, 1 }, + { "ansi", no_argument, NULL, 2 }, + { NULL, 0, NULL, 0 } + }; + + int opt; + while ((opt = getopt_long(argc, argv, short_opts, long_opts, NULL)) != -1) { - const struct option long_options[] = - { - { "no-indent", no_argument, 0, 'i' }, - { "help", no_argument, 0, 'h' }, - { "version", no_argument, 0, 'v' }, - { "html", no_argument, 0, 1 }, - { "ansi", no_argument, 0, 2 }, - { 0, 0, 0, 0 } - }; - - int opt_index = 0; - int opt = getopt_long(argc, argv, "hvi", long_options, &opt_index); - if (opt == -1) - break; - switch (opt) { case 0: { - break; + fwprintf(stderr, _(L"getopt_long() unexpectedly returned zero\n")); + exit_without_destructors(127); } case 'h': { print_help("fish_indent", 1); - exit(0); - assert(0 && "Unreachable code reached"); - break; + exit_without_destructors(0); } case 'v': @@ -359,9 +351,10 @@ int main(int argc, char *argv[]) break; } - case '?': + default: { - exit(1); + // We assume getopt_long() has already emitted a diagnostic msg. + exit_without_destructors(1); } } } -- cgit v1.2.3