groff-commit
[Top][All Lists]
Advanced

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

[groff] 13/39: [afmtodit]: Give program a usage message.


From: G. Branden Robinson
Subject: [groff] 13/39: [afmtodit]: 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 7b2845f8fde5deeb10a225160f6b843894dadf5b
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Mon Oct 24 12:59:48 2022 -0500

    [afmtodit]: Give program a usage message.
    
    * src/utils/afmtodit/afmtodit.pl: Add new scalar `want_help` of Boolean
      sense.  Recognize new long option `--help`, attached to `$want_help`.
      Stop stripping off directory name components from program name when
      emitting diagnostics.  No other groff program does this (well, gropdf
      did until recently), and it might save users some confusion if they're
      working with multiple copies of afmtodit.
    
      (usage): New subroutine reports usage message.  If help was explicitly
      requested, summarize purpose of program and steer reader to man page.
    
    Also drop old-style Emacs file-local variable setting.
---
 ChangeLog                      | 15 +++++++++++++++
 src/utils/afmtodit/afmtodit.pl | 30 +++++++++++++++++++++++-------
 2 files changed, 38 insertions(+), 7 deletions(-)

diff --git a/ChangeLog b/ChangeLog
index 3970ef1c9..bb2841928 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,18 @@
+2022-10-24  G. Branden Robinson <g.branden.robinson@gmail.com>
+
+       [afmtodit]: Give program a usage message.
+
+       * src/utils/afmtodit/afmtodit.pl: Add new scalar `want_help` of
+       Boolean sense.  Recognize new long option `--help`, attached to
+       `$want_help`.  Stop stripping off directory name components from
+       program name when emitting diagnostics.  No other groff program
+       does this (well, gropdf did until recently), and it might save
+       users some confusion if they're working with multiple copies of
+       afmtodit.
+       (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>
 
        [afmtodit]: Migrate expansion of Perl interpreter in shebang.
diff --git a/src/utils/afmtodit/afmtodit.pl b/src/utils/afmtodit/afmtodit.pl
index 9156ee59f..b8183a249 100644
--- a/src/utils/afmtodit/afmtodit.pl
+++ b/src/utils/afmtodit/afmtodit.pl
@@ -1,5 +1,4 @@
 #!@PERL@
-# -*- Perl -*-
 # Copyright (C) 1989-2020 Free Software Foundation, Inc.
 #      Written by James Clark (jjc@jclark.com)
 #
@@ -24,16 +23,15 @@ use strict;
 @afmtodit.tables@
 
 my $prog = $0;
-$prog =~ s@.*/@@;
-
 my $groff_sys_fontdir = "@FONTDIR@";
+my $want_help;
 
 our ($opt_a, $opt_c, $opt_d, $opt_e, $opt_f, $opt_i, $opt_k,
      $opt_m, $opt_n, $opt_o, $opt_s, $opt_v, $opt_x);
 
 use Getopt::Long qw(:config gnu_getopt);
 GetOptions( "a=s", "c", "d=s", "e=s", "f=s", "i=s", "k", "m", "n",
-  "o=s", "s", "v", "x", "version" => \$opt_v
+  "o=s", "s", "v", "x", "version" => \$opt_v, "help" => \$want_help
 );
 
 my $afmtodit_version = "GNU afmtodit (groff) version @VERSION@";
@@ -43,12 +41,30 @@ if ($opt_v) {
     exit 0;
 }
 
-if ($#ARGV != 2) {
-    die "usage: $prog [-ckmnsx] [-a slant]" .
+sub usage {
+    my $stream = *STDOUT;
+    my $had_error = shift;
+    $stream = *STDERR if $had_error;
+    print $stream "usage: $prog [-ckmnsx] [-a slant]" .
        " [-d device-description-file] [-e encoding-file]" .
        " [-f internal-name] [-i italic-correction-factor]" .
        " [-o output-file] afm-file map-file font-description-file\n" .
-       "usage: $prog -v\n";
+       "usage: $prog {-v | --version}\n" .
+       "usage: $prog --help\n";
+    unless ($had_error) {
+       print $stream "\n" .
+"Adapt an Adobe Font Metric file, afm-file, for use with the 'ps'\n" .
+"and 'pdf' output devices of groff(1).  See the afmtodit(1) manual " .
+"page.\n";
+    }
+    exit($had_error);
+}
+
+&usage(0) if ($want_help);
+
+if ($#ARGV != 2) {
+    print STDERR "$prog: usage error: insufficient arguments\n";
+    &usage(1);
 }
 
 my $afm = $ARGV[0];



reply via email to

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