From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from gnu.wildebeest.org (wildebeest.demon.nl [212.238.236.112]) by sourceware.org (Postfix) with ESMTPS id 70B49385701F for ; Thu, 29 Apr 2021 20:48:34 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 70B49385701F Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=klomp.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=mark@klomp.org Received: from tarox.wildebeest.org (tarox.wildebeest.org [172.31.17.39]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by gnu.wildebeest.org (Postfix) with ESMTPSA id 34AFC300075F; Thu, 29 Apr 2021 22:48:31 +0200 (CEST) Received: by tarox.wildebeest.org (Postfix, from userid 1000) id D2088413CB92; Thu, 29 Apr 2021 22:48:31 +0200 (CEST) From: Mark Wielaard To: debugedit@sourceware.org Cc: Mark Wielaard Subject: [PATCH] sepdebugcrcfix: Add --version, --help and man page. Date: Thu, 29 Apr 2021 22:48:25 +0200 Message-Id: <20210429204825.19783-1-mark@klomp.org> X-Mailer: git-send-email 2.18.4 X-Spam-Status: No, score=-11.0 required=5.0 tests=BAYES_00, GIT_PATCH_0, JMQ_SPF_NEUTRAL, KAM_DMARC_STATUS, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: debugedit@sourceware.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: debugedit development mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Thu, 29 Apr 2021 20:48:37 -0000 Add --version and --help support to sepdebugcrcfix. Use this to generate a manual page using help2man. * .gitignore: Add sepdebugcrcfix.1 * Makefile.am (dist_man_MANS): Add sepdebugcrcfix.1 (sepdebugcrcfix.1): New make rule. * tools/sepdebugcrcfix.c (version): New static functions. (help): Likewise. (main): Call version or help depending on argc and argv. Signed-off-by: Mark Wielaard --- .gitignore | 1 + Makefile.am | 8 +++++++- tools/sepdebugcrcfix.c | 31 ++++++++++++++++++++++++++++++- 3 files changed, 38 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 55d4bfc..d41ec64 100644 --- a/.gitignore +++ b/.gitignore @@ -29,6 +29,7 @@ missing debugedit debugedit.1 sepdebugcrcfix +sepdebugcrcfix.1 atconfig atlocal diff --git a/Makefile.am b/Makefile.am index 5042785..de7c51d 100644 --- a/Makefile.am +++ b/Makefile.am @@ -39,7 +39,7 @@ sepdebugcrcfix_CFLAGS = @LIBELF_CFLAGS@ $(AM_CFLAGS) sepdebugcrcfix_LDADD = @LIBELF_LIBS@ # Manual pages are generated for dist -dist_man_MANS = debugedit.1 +dist_man_MANS = debugedit.1 sepdebugcrcfix.1 debugedit.1: tools/debugedit.c $(top_srcdir)/configure.ac $(MAKE) $(AM_MAKEFLAGS) debugedit$(EXEEXT) @@ -47,6 +47,12 @@ debugedit.1: tools/debugedit.c $(top_srcdir)/configure.ac --name='debug source path manipulation tool' \ ./debugedit$(EXEEXT) +sepdebugcrcfix.1: tools/sepdebugcrcfix.c $(top_srcdir)/configure.ac + $(MAKE) $(AM_MAKEFLAGS) sepdebugcrcfix$(EXEEXT) + $(HELP2MAN) -N --output=$@ \ + --name='fixes CRC for separate .debug files' \ + ./sepdebugcrcfix$(EXEEXT) + noinst_HEADERS= tools/ansidecl.h \ tools/hashtab.h \ tools/md5.h \ diff --git a/tools/sepdebugcrcfix.c b/tools/sepdebugcrcfix.c index 72b3f30..20800ba 100644 --- a/tools/sepdebugcrcfix.c +++ b/tools/sepdebugcrcfix.c @@ -300,11 +300,40 @@ process (Elf *elf, int fd, const char *fname) return false; } +static void +version (void) +{ + printf("sepdebugcrcfix %s\n", VERSION); + exit(EXIT_SUCCESS); +} + +static const char *helpText = + "Usage: %s DEBUG_DIR FILEs\n" \ + "Fixes CRC in .debug files under DEBUG_DIR for the given FILEs\n" \ + "\n" \ + "DEBUG_DIR is usually \"usr/lib/debug\".\n" \ + "FILEs should have relative paths.\n" \ + "The relative paths will be used to find the corresponding .debug\n" \ + "files under DEBUGDIR\n"; + +static void +help (const char *progname, bool error) +{ + FILE *f = error ? stderr : stdout; + fprintf (f, helpText, progname); + exit (error ? EXIT_FAILURE : EXIT_SUCCESS); +} + int main (int argc, char **argv) { + if (argc == 2 && strcmp (argv[1], "--version") == 0) + version (); + if (argc == 2 && strcmp (argv[1], "--help") == 0) + help (argv[0], false); if (argc < 2) - error (1, 0, _("usr/lib/debug [...]")); + help (argv[0], true); + usr_lib_debug = argv[1]; if (elf_version (EV_CURRENT) == EV_NONE) error (1, 0, _("error initializing libelf: %s"), elf_errmsg (-1)); -- 2.18.4