From 797c9847e8b7ddf6dd0bb39d21bdda4c8f20ca07 Mon Sep 17 00:00:00 2001 From: Nick Bowler Date: Wed, 23 Feb 2022 20:55:25 -0500 Subject: [PATCH] Use help formatting routines from dxcommon. As we now have shared code to format the options lists in dxcommon, make use of that to reduce the amount of code unique to this package. --- Makefile.am | 12 +++++---- common | 2 +- src/main.c | 70 ++++------------------------------------------------- 3 files changed, 13 insertions(+), 71 deletions(-) diff --git a/Makefile.am b/Makefile.am index 6422661..3932dcb 100644 --- a/Makefile.am +++ b/Makefile.am @@ -1,4 +1,4 @@ -# Copyright © 2019-2021 Nick Bowler +# Copyright © 2019-2022 Nick Bowler # # Based on original work Copyright © 1999-2013 Jiri (George) Lebl. # @@ -10,7 +10,7 @@ ACLOCAL_AMFLAGS = -I m4 -I common/m4 AM_CPPFLAGS = -I$(top_builddir)/src -I$(top_srcdir)/src \ -I$(top_builddir)/lib -I$(top_srcdir)/lib \ - -DPKGDATADIR=\"$(pkgdatadir)\" + -I$(DX_BASEDIR)/src -DPKGDATADIR=\"$(pkgdatadir)\" AM_CFLAGS = $(LIBGLIB_CFLAGS) AM_YFLAGS = -d -t @@ -38,12 +38,14 @@ EXTRA_PROGRAMS = parser-rdeps parser_rdeps_SOURCES = src/main.c src/lexer.c $(parser_rdeps_OBJECTS): src/parse.h -noinst_HEADERS = src/main.h src/treefuncs.h src/out.h src/util.h src/checks.h +noinst_HEADERS = src/main.h src/treefuncs.h src/out.h src/util.h src/checks.h \ + common/src/help.h gob2_SOURCES = src/main.c src/main.h src/treefuncs.c src/out.c src/util.c \ - src/checks.c src/parse.y src/lexer.c src/lexer.h src/options.h + src/checks.c src/parse.y src/lexer.c src/lexer.h src/options.h \ + common/src/help.c gob2_LDADD = $(LIBGLIB_LIBS) libgnu.a -$(gob2_OBJECTS): src/treefuncs.h src/options.h $(gnulib_headers) +$(gob2_OBJECTS): $(gnulib_headers) src/treefuncs.h src/options.h man_MANS = doc/gob2.1 EXTRA_DIST += doc/makehtml.pl diff --git a/common b/common index aa6ab45..03a2675 160000 --- a/common +++ b/common @@ -1 +1 @@ -Subproject commit aa6ab453c6ff523a4d8538554c068117f2de3aca +Subproject commit 03a26752c80546ac8cf8fc81807bb5a153786599 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'); -- 2.43.2