X-Git-Url: https://git.draconx.ca/gitweb/gob-dx.git/blobdiff_plain/7200c42b4183887f9952871909446352a984170a..797c9847e8b7ddf6dd0bb39d21bdda4c8f20ca07:/src/main.c diff --git a/src/main.c b/src/main.c index 8e6c04e..0e6c55c 100644 --- a/src/main.c +++ b/src/main.c @@ -2,7 +2,7 @@ * Copyright (C) 1999,2000 the Free Software Foundation. * Copyright (C) 2000 Eazel, Inc. * Copyright (C) 2001-2011 George (Jiri) Lebl - * Copyright © 2019-2021 Nick Bowler + * Copyright © 2019-2022 Nick Bowler * * Author: George (Jiri) Lebl * @@ -39,6 +39,7 @@ #include "out.h" #include "util.h" #include "checks.h" +#include "help.h" #include "main.h" @@ -4535,13 +4536,11 @@ generate_outfiles(void) static void print_version(void) { printf("%s (%s) %s\n", PACKAGE_NAME, PACKAGE_TARNAME, PACKAGE_VERSION); - putchar('\n'); puts("Copyright (C) 2013 George (Jiri) Lebl et al."); - puts("Copyright (C) 2020 Nick Bowler"); - puts("License GPLv2+: GNU GPL version 2 or later ."); + puts("Copyright (C) 2022 Nick Bowler"); + puts("License GPLv2+: GNU GPL version 2 or any later version"); puts("This is free software: you are free to change and redistribute it."); puts("There is NO WARRANTY, to the extent permitted by law."); - } static void print_usage(FILE *f) @@ -4553,46 +4552,6 @@ static void print_usage(FILE *f) } } -/* - * Given a long option, return the corresponding short option character, - * or 0 if there is no such character. - */ -static char lopt_to_sopt(const char *sopts, const struct option *opt) -{ - int val = opt->val; - const char *c; - - if (val <= 0 || val > CHAR_MAX) - return 0; - - if (val == ':' || val == '+' || val == '-') - return 0; - - c = strchr(sopts, opt->val); - if (c) - return *c; - return 0; -} - -/* - * Print a string, with each line indented by i spaces. The first line - * will be indented by w fewer spaces (to account for the cursor being in - * some other column). - */ -static void print_block(const char *s, int i, int w) -{ - for (; *s; w = 0) { - const char *nl = strchr(s, '\n'); - int n = (nl ? nl-s : -1); - - printf("%*s%.*s\n", i-w, "", n, s); - if (!nl) - break; - - s = nl+1; - } -} - static void print_help(void) { const struct option *opt; @@ -4605,8 +4564,6 @@ static void print_help(void) puts("\nOptions:"); for (opt = lopts; opt->name; opt++) { struct lopt_help help; - char sopt; - int w; /* Don't display obsolete options that don't do anything */ if (!opt->flag && !opt->val) @@ -4615,24 +4572,7 @@ static void print_help(void) if (!lopt_get_help(opt, &help)) continue; - if ((sopt = lopt_to_sopt(sopts, opt))) { - w = printf(opt->has_arg == 0 ? " -%c, --%s" - : opt->has_arg == 1 ? " -%c, --%s=%s" - : " -%c, --%s[=%s]", - sopt, opt->name, help.arg); - } else { - w = printf(opt->has_arg == 0 ? " --%s" - : opt->has_arg == 1 ? " --%s=%s" - : " --%s[=%s]", - opt->name, help.arg); - } - - if (w < 0 || w > 18) { - putchar('\n'); - w = 0; - } - - print_block(help.desc, 20, w); + help_print_option(opt, help.arg, help.desc, 20); } putchar('\n');