groff-commit
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[groff] 09/39: [gropdf] Give program a usage message.


From: G. Branden Robinson
Subject: [groff] 09/39: [gropdf] Give program a usage message.
Date: Sat, 29 Oct 2022 14:59:56 -0400 (EDT)

gbranden pushed a commit to branch master
in repository groff.

commit 500f209b94b2fcb8f4bcacfceb17235b44413147
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Mon Oct 24 12:30:26 2022 -0500

    [gropdf] Give program a usage message.
    
    * src/devices/gropdf/gropdf.pl: Add new scalar `want_help` of Boolean
      sense.  Recognize new long option `--help`, attached to `$want_help`.
    
      (usage): New subroutine reports usage message.  If help was explicitly
      requested, summarize purpose of program and steer reader to man page.
---
 ChangeLog                    | 11 +++++++++++
 src/devices/gropdf/gropdf.pl | 31 ++++++++++++++++++++++++++++++-
 2 files changed, 41 insertions(+), 1 deletion(-)

diff --git a/ChangeLog b/ChangeLog
index f08e98a78..80bbe41b8 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,14 @@
+2022-10-24  G. Branden Robinson <g.branden.robinson@gmail.com>
+
+       [gropdf] Give program a usage message.
+
+       * src/devices/gropdf/gropdf.pl: Add new scalar `want_help` of
+       Boolean sense.  Recognize new long option `--help`, attached to
+       `$want_help`.
+       (usage): New subroutine reports usage message.  If help was
+       explicitly requested, summarize purpose of program and steer
+       reader to man page.
+
 2022-10-24  G. Branden Robinson <g.branden.robinson@gmail.com>
 
        * src/devices/xditview/xditview.c (Syntax): "#if 0" out
diff --git a/src/devices/gropdf/gropdf.pl b/src/devices/gropdf/gropdf.pl
index f7be222ab..c8700f255 100644
--- a/src/devices/gropdf/gropdf.pl
+++ b/src/devices/gropdf/gropdf.pl
@@ -203,20 +203,49 @@ end
 end
 EOF
 
+sub usage
+{
+    my $stream = *STDOUT;
+    my $had_error = shift;
+    $stream = *STDERR if $had_error;
+    print $stream
+"usage: $prog [-dels] [-F font-directory] [-I inclusion-directory]" .
+" [-p paper-format] [-u [cmap-file]] [-y foundry] [file ...]\n" .
+"usage: $prog {-v | --version}\n" .
+"usage: $prog --help\n";
+    if (!$had_error)
+    {
+       print $stream "\n" .
+"Translate the output of troff(1) into Portable Document Format.\n" .
+"See the gropdf(1) manual page.\n";
+    }
+    exit($had_error);
+}
+
 my $fd;
 my $frot;
 my $fpsz;
 my $embedall=0;
 my $debug=0;
+my $want_help=0;
 my $version=0;
 my $stats=0;
 my $unicodemap;
 my @idirs;
 
-GetOptions("F=s" => \$fd, 'I=s' => \@idirs, 'l' => \$frot, 'p=s' => \$fpsz, 
'd!' => \$debug, 'v' => \$version, 'version' => \$version, 'e' => \$embedall, 
'y=s' => \$Foundry, 's' => \$stats, 'u:s' => \$unicodemap);
+if (!GetOptions('F=s' => \$fd, 'I=s' => \@idirs, 'l' => \$frot,
+               'p=s' => \$fpsz, 'd!' => \$debug, 'help' => \$want_help,
+               'v' => \$version, 'version' => \$version,
+               'e' => \$embedall, 'y=s' => \$Foundry, 's' => \$stats,
+               'u:s' => \$unicodemap))
+{
+    &usage(1);
+}
 
 unshift(@idirs,'.');
 
+&usage(0) if ($want_help);
+
 if ($version)
 {
     print "GNU gropdf (groff) version $cfg{GROFF_VERSION}\n";



reply via email to

[Prev in Thread] Current Thread [Next in Thread]