gbranden pushed a commit to branch master
in repository groff.
commit 59cfa88d8e7d8b11adbb03a7f58cff912a657500
Author: G. Branden Robinson <[email protected]>
AuthorDate: Sat Aug 2 08:24:00 2025 -0500
[gpinyin]: Revise usage and version messages.
* contrib/gpinyin/gpinyin.pl: Rename scalar `version` to
`gpinyin_version`. Add scalar `groff_version`, and make its value
robust to use of the program directly from the source tree or in built
form, copying a technique from groff's `chem` contributed component.
Stop accepting abbreviated forms of `--help` and `--version` options,
apart from `-h` and `-v`. Developers have over the decades come to
repent of this old, terrible idea, because it prevents them from
adding an option name that is a leading substring of another without
changing the semantics of existing command lines. Bump minor
component of `gpinyin_version` accordingly.
(usage, version): Reuse subroutines from grog(1), updating usage
message appropriately and formatting version report per GNU Coding
Standards.
NEWS: Report CLI change.
Also revise comment header to stop stating that this contributed
component is "part of groff"; it is not. See the "LICENSES" file in the
groff source distribution (or at the top of its Git repository).
Contributed components are not necessarily distributed under the GNU
GPLv3, and this one is not--it uses GNU GPLv2 per its author's wishes.
Also add a copyright notice for myself. I've never executed copyright
assignment paperwork with the FSF, so my changes to gpinyin since 2022
can't be under the FSF's copyright.
N.B., I don't actually know whether Bernd Warken or anyone else
performed such assignment, either. Nobody automatically hands you that
information when you become a GNU maintainer (or tells you where you can
look for it). So the notice (and others) might require further
revision.
---
NEWS | 6 ++--
contrib/gpinyin/gpinyin.pl | 84 +++++++++++++++++++++++++++++-----------------
2 files changed, 56 insertions(+), 34 deletions(-)
diff --git a/NEWS b/NEWS
index 5411af872..4112482ee 100644
--- a/NEWS
+++ b/NEWS
@@ -759,9 +759,9 @@ Utilities
Miscellaneous
-------------
-* The contributed program gperl no longer accepts abbreviated forms of
- the long options `--help` and `--version`. The respective synonymous
- short options `-h` and `-v` remain.
+* The contributed programs gperl and gpinyin no longer accept
+ abbreviated forms of the long options `--help` and `--version`. The
+ respective synonymous short options `-h` and `-v` remain.
* Font description files now support a variant of the "charset"
directive: "charset-range" works like the existing "charset"
diff --git a/contrib/gpinyin/gpinyin.pl b/contrib/gpinyin/gpinyin.pl
index daef1074c..7ccee66c1 100755
--- a/contrib/gpinyin/gpinyin.pl
+++ b/contrib/gpinyin/gpinyin.pl
@@ -1,26 +1,25 @@
#!/usr/bin/env perl
-# gpinyin - European-like Chinese writing 'pinyin' into 'groff'
-
+# gpinyin - use Hanyu Pinyin romanization of Chinese in groff(1) input
+#
# Copyright (C) 2014-2020 Free Software Foundation, Inc.
-
+# 2022-2025 G. Branden Robinson
+#
# Written by Bernd Warken <[email protected]>.
-
-my $version = '1.0.5';
-my $groff_version = '(groff @VERSION@) '; # with trailing space
-
-# This file is part of 'gpinyin', which is part of 'groff'.
-
-# 'groff' is free software; you can redistribute it and/or modify it
+# Enhanced by: G. Branden Robinson <[email protected]>
+#
+# This file is part of 'gpinyin'.
+#
+# 'gpinyin' is free software; you can redistribute it and/or modify it
# under the terms of the GNU General Public License as published by
# the Free Software Foundation, either version 2 of the License, or
# (at your option) any later version.
-
-# 'groff' is distributed in the hope that it will be useful, but
+#
+# 'gpinyin' is distributed in the hope that it will be useful, but
# WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
# General Public License for more details.
-
+#
# You can find a copy of the GNU General Public License in the internet
# at <http://www.gnu.org/licenses/gpl-2.0.html>.
@@ -48,6 +47,18 @@ use Cwd;
# $Bin is the directory where this script is located
use FindBin;
+my $gpinyin_version = '1.1.0';
+my $groff_version = '(groff @VERSION@) '; # with trailing space
+
+my $is_in_source_tree;
+{
+ $is_in_source_tree = 1 if '@VERSION@' eq '@' . 'VERSION' . '@';
+}
+
+if (!$is_in_source_tree) {
+ $groff_version = '@VERSION@';
+}
+
########################################################################
# system variables and exported variables
@@ -55,11 +66,6 @@ use FindBin;
$\ = "\n"; # final part for print command
-{
- my $at = '@';
- $groff_version = '' if '@VERSION@' eq "${at}VERSION${at}";
-}
-
########################################################################
# All Pinyin syllables from wikipedia
########################################################################
@@ -280,6 +286,32 @@ my %tones4_glyphs =
# subs
########################################################################
+(undef, undef, my $program_name) = File::Spec->splitpath($0);
+
+sub usage {
+ my $stream = *STDOUT;
+ my $had_error = shift;
+ $stream = *STDERR if $had_error;
+ my $gpinyin = $program_name;
+ print $stream "usage: $gpinyin [file ...]\n" .
+ "usage: $gpinyin {-v | --version}\n" .
+ "usage: $gpinyin {-h | --help}\n";
+ unless ($had_error) {
+ # Omit some newlines due to `$\` voodoo.
+ print $stream "" .
+"Filter GNU troff(1) input, facilitating use of Hanyu Pinyin on\n" .
+"lines between '.pinyin start' and '.pinyin stop'. See the\n" .
+"gpinyin(1) manual page.";
+ }
+ exit $had_error;
+}
+
+sub version {
+ # Omit newline due to `$\` voodoo.
+ print "$program_name (groff $groff_version) $gpinyin_version";
+ exit 0;
+}
+
# Pinyin consists of syllables with a final number to be translated
# into an accent. Such numbered syllables are combined into words.
# Such words can have a final punctuation. A line is a collection of
@@ -617,19 +649,9 @@ sub finish_pinyin_mode {
# options
########################################################################
-foreach (@ARGV) {
- if ( /^(-h|--h|--he|--hel|--help)$/ ) {
- print q(Usage for the 'gpinyin' program:);
- print 'gpinyin [-] [--] [filespec...] normal file name arguments';
- print 'gpinyin [-h|--help] gives usage information';
- print 'gpinyin [-v|--version] displays the version number';
- print q(This program is a 'groff' preprocessor that handles ) .
- q(pinyin parts in 'roff' files.);
- exit;
- } elsif (/^(-v|--v|--ve|--ver|--vers|--versi|--versio|--version)$/) {
- print "gpinyin ${groff_version}version $version";
- exit;
- }
+foreach my $arg (@ARGV) {
+ usage(0) if ($arg eq '-h' || $arg eq '--help');
+ version() if ($arg eq '-v' || $arg eq '--version');
}
_______________________________________________
groff-commit mailing list
[email protected]
https://lists.gnu.org/mailman/listinfo/groff-commit