summaryrefslogtreecommitdiffstats
path: root/man/fix-roff-punct
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:24:48 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-07 18:24:48 +0000
commitcca66b9ec4e494c1d919bff0f71a820d8afab1fa (patch)
tree146f39ded1c938019e1ed42d30923c2ac9e86789 /man/fix-roff-punct
parentInitial commit. (diff)
downloadinkscape-cca66b9ec4e494c1d919bff0f71a820d8afab1fa.tar.xz
inkscape-cca66b9ec4e494c1d919bff0f71a820d8afab1fa.zip
Adding upstream version 1.2.2.upstream/1.2.2upstream
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to '')
-rwxr-xr-xman/fix-roff-punct140
1 files changed, 140 insertions, 0 deletions
diff --git a/man/fix-roff-punct b/man/fix-roff-punct
new file mode 100755
index 0000000..0a11f2f
--- /dev/null
+++ b/man/fix-roff-punct
@@ -0,0 +1,140 @@
+#! /usr/bin/env perl
+use strict;
+use warnings;
+
+# fix-roff-punct: Fix up punctuation usage in automatically-generated
+# troff files (man pages).
+
+# Authors:
+# Peter Moulder <pmoulder@mail.csse.monash.edu.au>
+#
+# Copyright (C) 2004 Monash University
+#
+# Gnu GPL v2+:
+#
+# This program 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.
+#
+# This program 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 should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+
+
+# Background: Humans use a number of dash-like characters:
+#
+# - ASCII hyphen/minus needed for command-line options and other computer
+# input;
+# - hyphen (`one-to-one');
+# - en dash (`2000-2003');
+# - em dash -- like this. [Not currently handled.]
+#
+# Troff input spells them as \-, -, \[en], \[em] respectively. (See the
+# groff_char.7 man page for a full list of such punctuation characters.) If
+# you run `man' with your LC_CTYPE indicating a rich character set like unicode
+# (UTF-8 encoding), then it uses different output characters for each of the
+# above.
+#
+# In particular, if your man page source has plain `-' when giving an example
+# of a flag or command or other program input, then users won't be able to use
+# mouse copy&paste from the formatted man page.
+
+# This script is something of a hack: it is only big enough to handle a few man
+# pages of interest (produced by pod2man). You should manually check the
+# changes it makes.
+
+# Approach: we handle each line a word at a time, and typically make the same
+# hyphen-vs-ASCII decision throughout the word. We're a bit haphazard about
+# word-splitting, but it's hard to find an example of where we'd be hurt by
+# that, and by luck we would do the right thing for many gcc options like
+# `-fconstant-string-class=\fICLASS-NAME\fR' (where CLASS-NAME should use a
+# hyphen and the others should be ASCII hyphen-minus).
+#
+# Perl's /e (execute) flag for substitutions does just what we want
+# for preserving non-word bits while transforming "words".
+#
+# We don't currently handle special things like `apt-get' that look like
+# hyphenated english words but are actually program names. In general the
+# problem is AI complete, e.g. `apt-gettable' could be either hyphen (gettable
+# by apt) or ASCII hyphen-minus (able to be processed by the `apt-get'
+# program).
+#
+# We don't currently take hints from font choice. (E.g. text in CR font should
+# probably use ASCII hyphen-minus.)
+#
+# We currently only handle a couple troff requests and escapes (see groff.7).
+
+sub frob ($);
+
+my $yearRE = qr/(?:19[6-9]|20[013])[0-9]/;
+
+sub frob ($) {
+ my ($x) = @_;
+
+ # Consider splitting into two words.
+ if ($x =~ m{\A(.*?)(\\(?:[&/,~:d]|f[BRI]|s-?[0-9]+))(.*)\z}) {
+ my ($before, $s, $after) = ($1, $2, $3);
+ return frob($before) . $s . frob($after);
+ }
+
+ if ($x =~ m{\A(.*?)(\.+)\z}) {
+ my $d = $2;
+ return frob($1) . $d;
+ }
+
+ # `32-bit', `5-page'.
+ if ($x =~ m{\A[0-9]+-[a-z]+\z}) {
+ return $x;
+ }
+
+ # Year range: `(C) 1998-2003'.
+ if ($x =~ m{\A$yearRE\\?-$yearRE\z}) {
+ $x =~ s{\\?-}{\\[en]};
+ return $x;
+ }
+
+ # ISO date.
+ if ($x =~ m{\A$yearRE-[01][0-9]-[0-3][0-9]\z}) {
+ return $x;
+ }
+
+ # Things likely to be computer input.
+ if ($x =~ m{[0-9]|\.[a-zA-Z]|\A(?:[-/.]|\\-|\[.*\]\z)}) {
+ $x =~ s/\\?-/\\-/g;
+ return $x;
+ }
+
+ $x =~ s/\\?-/-/g;
+ return $x;
+}
+
+while(<>) {
+ if ($_ eq '.tr \(*W-|\(bv\*(Tr' . "\n") {
+ # Get rid of pod2man's "helpful" munging of pipe symbol.
+ next;
+ }
+
+ # Leave ASCII apostrophe unchanged (i.e. \[aq]) for examples.
+ if (/\A\\\& /) {
+ s/'/\\[aq]/g; # `\[aq]' = "ascii quote"
+ }
+
+ if (/\A\.IP /) {
+ s/\\?-/\\-/g;
+ s/\\s\\-1/\\s-1/g;
+ }
+ elsif (/\A\.IX /) {
+ s/\\?-/-/g;
+ }
+ elsif (!/\A\. *(?:\\"|ds|if|ie)/) {
+ # As an optimization, we process only words containing `-'.
+ s{([.@/\\[:alnum:]]*-[-.@/\\[:alnum:]]*)}{frob($1)}ge;
+ }
+ print;
+}