groff-commit
[Top][All Lists]
Advanced

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

[groff] 03/21: [chem]: Refactor.


From: G. Branden Robinson
Subject: [groff] 03/21: [chem]: Refactor.
Date: Tue, 23 Aug 2022 14:18:40 -0400 (EDT)

gbranden pushed a commit to branch master
in repository groff.

commit 37fb9f15e35a0bc025d6b479d74c5345645e45c5
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Thu Aug 18 09:46:00 2022 -0500

    [chem]: Refactor.
    
    * contrib/chem/chem.pl: Refactor.
      - Rename scalars.
        Copyright -> copyright
        Program_Version -> chem_version
        Groff_Version -> groff_version
        Chem_Name -> chem
        before_make -> is_in_source_tree
      - Rename hash.
        at_at -> makevar
      - Drop unused hash member `$makevar{'BINDIR'}`.
      - Drop scalar `Groff_Version_Preset`, which apparently hadn't
        been updated since groff 1.20.  Instead, follow grog(1) and
        set the `groff_version` scalar to "DEVELOPMENT" if this is
        the version from the groff source tree.  Overwrite its value
        with that determined by make(1) if available.
      - Tighten usage and version messages; make the latter more
        conformant with the format recommended in the GNU Coding
        Standards.  Explicitly identify license as GNU GPLv2.
    
      (usage): Refer to "pic" with its command prefix if it is known
      to have one.  (If running "unbuilt", we have no way to know.)
---
 contrib/chem/ChangeLog |  23 ++++++++++
 contrib/chem/chem.pl   | 111 ++++++++++++++++++-------------------------------
 2 files changed, 64 insertions(+), 70 deletions(-)

diff --git a/contrib/chem/ChangeLog b/contrib/chem/ChangeLog
index 3472ee572..ad40944e5 100644
--- a/contrib/chem/ChangeLog
+++ b/contrib/chem/ChangeLog
@@ -1,3 +1,26 @@
+2022-08-18  G. Branden Robinson <g.branden.robinson@gmail.com>
+
+       * chem.pl: Refactor.
+         - Rename scalars.
+           Copyright -> copyright
+           Program_Version -> chem_version
+           Groff_Version -> groff_version
+           Chem_Name -> chem
+           before_make -> is_in_source_tree
+         - Rename hash.
+           at_at -> makevar
+         - Drop unused hash member `$makevar{'BINDIR'}`.
+         - Drop scalar `Groff_Version_Preset`, which apparently hadn't
+           been updated since groff 1.20.  Instead, follow grog(1) and
+           set the `groff_version` scalar to "DEVELOPMENT" if this is
+           the version from the groff source tree.  Overwrite its value
+           with that determined by make(1) if available.
+         - Tighten usage and version messages; make the latter more
+           conformant with the format recommended in the GNU Coding
+           Standards.  Explicitly identify license as GNU GPLv2.
+         (usage): Refer to "pic" with its command prefix if it is known
+         to have one.  (If running "unbuilt", we have no way to know.)
+
 2022-08-18  G. Branden Robinson <g.branden.robinson@gmail.com>
 
        * chem.pl: Stop copying "pic.tmac" (fallback troff macro
diff --git a/contrib/chem/chem.pl b/contrib/chem/chem.pl
index fb4aa279d..6e65fe939 100755
--- a/contrib/chem/chem.pl
+++ b/contrib/chem/chem.pl
@@ -2,7 +2,8 @@
 
 # chem - a groff preprocessor for producing chemical structure diagrams
 
-my $Copyright = 'Copyright (C) 2006-2014 Free Software Foundation, Inc.';
+my $copyright = 'Copyright (C) 2006-2014, 2022'
+                . ' Free Software Foundation, Inc.';
 # Written by Bernd Warken <groff-bernd.warken-72@web.de>.
 
 # This file is part of 'chem', which is part of 'groff'.
@@ -23,13 +24,9 @@ my $Copyright = 'Copyright (C) 2006-2014 Free Software 
Foundation, Inc.';
 # settings
 ########################################################################
 
-my $Program_Version = '1.0.6';
+my $chem_version = '1.0.6';
+my $groff_version = 'DEVELOPMENT';
 
-# this setting of the groff version is only used before make is run,
-# otherwise @VERSION@ will set it.
-my $Groff_Version_Preset='1.20preset';
-
-# test on Perl version
 require v5.6;
 
 
@@ -47,37 +44,27 @@ use File::Spec;
 # $Bin is the directory where this script is located
 use FindBin;
 
-my $Chem_Name;
-my $Groff_Version;
+my $chem;
 my $File_chem_pic;
 
-BEGIN {
-  {
-    my $before_make;           # script before run of 'make'
-    {
-      my $at = '@';
-      $before_make = 1 if '@VERSION@' eq "${at}VERSION${at}";
-    }
-
-    my %at_at;
+my $is_in_source_tree;
+{
+  $is_in_source_tree = 1 if '@VERSION@' eq '@' . 'VERSION' . '@';
+}
 
-    if ($before_make) {
-      my $chem_dir = $FindBin::Bin;
-      $at_at{'BINDIR'} = $chem_dir;
-      $at_at{'G'} = '';
-      $File_chem_pic = File::Spec->catfile($chem_dir, 'chem.pic');
-      $Groff_Version = '';
-      $Chem_Name = 'chem';
-    } else {
-      $Groff_Version = '@VERSION@';
-      $at_at{'BINDIR'} = '@BINDIR@';
-      $at_at{'G'} = '@g@';
-      $at_at{'PICDIR'} = '@PICDIR@';
-      $File_chem_pic =
-       File::Spec->catfile($at_at{'PICDIR'}, 'chem.pic');
-      $Chem_Name = $at_at{'G'} . 'chem';
-    }
-  }
+my %makevar;
+
+if ($is_in_source_tree) {
+  my $chem_dir = $FindBin::Bin;
+  $makevar{'G'} = '';
+  $File_chem_pic = File::Spec->catfile($chem_dir, 'chem.pic');
+  $chem = 'chem';
+} else {
+  $groff_version = '@VERSION@';
+  $makevar{'G'} = '@g@';
+  $makevar{'PICDIR'} = '@PICDIR@';
+  $File_chem_pic = File::Spec->catfile($makevar{'PICDIR'}, 'chem.pic');
+  $chem = $makevar{'G'} . 'chem';
 }
 
 
@@ -1207,54 +1194,38 @@ sub setparams {
 } # setparams()
 
 
-##########
-# usage()
-#
-# Print usage information for --help.
-#
 sub usage {
-  print "\n";
-  &version();
   print <<EOF;
+usage: $chem [file] ...
+usage: $chem { -h | --help | -v | --version }
 
-Usage: $Chem_Name [option]... [filespec]...
-
-$Chem_Name is a groff preprocessor for producing chemical structure
-diagrams.  The output suits to the pic preprocessor.
-
-"filespec" is one of
-  "filename"       name of a readable file
-  "-"              for standard input
-
-All available options are
-
--h --help         print this usage message.
--v --version      print version information.
+$chem is a groff preprocessor for producing chemical structure
+diagrams.  It produces input for the $makevar{'G'}pic preprocessor.  If
+no file operands are given, or if file is "-", the standard input stream
+is read.
 
+Options:
+ -h, --help     Display this message and exit.
+ -v, --version  Display version information and exit.
 EOF
-} # usage()
+}
 
 
-##########
-# version()
-#
-# Get version information from version.sh and print a text with this.
-#
 sub version {
-  $Groff_Version = $Groff_Version_Preset unless $Groff_Version;
   print <<EOF;
-$Chem_Name $Program_Version (Perl version)
-is part of groff version $Groff_Version.
-$Copyright
-GNU groff and chem come with ABSOLUTELY NO WARRANTY.
-You may redistribute copies of groff and its subprograms
-under the terms of the GNU General Public License.
+$chem (groff $groff_version) $chem_version
+$copyright
+License GPLv2: GNU GPL version 2
+<https://www.gnu.org/licenses/old-licenses/gpl-2.0.en.html>
+This is free software: you are free to change and redistribute it.
+There is NO WARRANTY, to the extent permitted by law.
 EOF
-} # version()
+}
 
 1;
+
 # Local Variables:
 # fill-column: 72
 # mode: CPerl
 # End:
-# vim: set autoindent textwidth=72:
+# vim: set cindent noexpandtab shiftwidth=2 softtabstop=2 textwidth=72:



reply via email to

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