* 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
*
#include "out.h"
#include "util.h"
#include "checks.h"
+#include "help.h"
#include "main.h"
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 <https://gnu.org/licenses/gpl.html>.");
+ 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)
}
}
-/*
- * 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;
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)
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');