[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[groff] 21/31: [nroff]: Refactor, mostly by relocation.
From: |
G. Branden Robinson |
Subject: |
[groff] 21/31: [nroff]: Refactor, mostly by relocation. |
Date: |
Sun, 25 Jul 2021 02:39:49 -0400 (EDT) |
gbranden pushed a commit to branch master
in repository groff.
commit 9f105c833bce17435241b369ee922e26af0837fe
Author: G. Branden Robinson <g.branden.robinson@gmail.com>
AuthorDate: Sun Jul 25 06:27:07 2021 +1000
[nroff]: Refactor, mostly by relocation.
* src/roff/nroff/nroff.sh: Refactor, mostly by relocation. Move locale
character set inference logic so that we only run it if we have to (no
`-T` option was given and `GROFF_TYPESETTER` was not set in the
environment). Initalize `T` variable as empty.
---
ChangeLog | 7 ++++
src/roff/nroff/nroff.sh | 101 ++++++++++++++++++++++++------------------------
2 files changed, 57 insertions(+), 51 deletions(-)
diff --git a/ChangeLog b/ChangeLog
index eb28086..9a371b7 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,12 @@
2021-07-23 G. Branden Robinson <g.branden.robinson@gmail.com>
+ * src/roff/nroff/nroff.sh: Refactor, mostly by relocation. Move
+ locale character set inference logic so that we only run it if
+ we have to (no `-T` option was given and `GROFF_TYPESETTER` was
+ not set in the environment). Initalize `T` variable as empty.
+
+2021-07-23 G. Branden Robinson <g.branden.robinson@gmail.com>
+
* src/roff/nroff/nroff.sh: Use Version 7 Unix sh-compatible form
of parameter expansion; per the GNU Autoconf manual[1], "[o]ld
BSD shells, including the Ultrix sh, don't accept the colon for
diff --git a/src/roff/nroff/nroff.sh b/src/roff/nroff/nroff.sh
index 6c8ae85..cb577fb 100644
--- a/src/roff/nroff/nroff.sh
+++ b/src/roff/nroff/nroff.sh
@@ -22,43 +22,7 @@
prog="$0"
-# Default device.
-
-# Check the GROFF_TYPESETTER environment variable.
-Tenv=$GROFF_TYPESETTER
-
-# Try the 'locale charmap' command first because it is most reliable.
-# On systems where it doesn't exist, look at the environment variables.
-case "`exec 2>/dev/null ; locale charmap`" in
- UTF-8)
- Tloc=utf8 ;;
- ISO-8859-1 | ISO-8859-15)
- Tloc=latin1 ;;
- IBM-1047)
- Tloc=cp1047 ;;
- *)
- case "${LC_ALL-${LC_CTYPE-${LANG}}}" in
- *.UTF-8)
- Tloc=utf8 ;;
- iso_8859_1 | *.ISO-8859-1 | *.ISO8859-1 | \
- iso_8859_15 | *.ISO-8859-15 | *.ISO8859-15)
- Tloc=latin1 ;;
- *.IBM-1047)
- Tloc=cp1047 ;;
- *)
- case "$LESSCHARSET" in
- utf-8)
- Tloc=utf8 ;;
- latin1)
- Tloc=latin1 ;;
- cp1047)
- Tloc=cp1047 ;;
- *)
- Tloc=ascii ;;
- esac ;;
- esac ;;
-esac
-
+T=
Topt=
opts=
dry_run=
@@ -130,23 +94,58 @@ then
exit 2
fi
-if [ -n "$Topt" ]
+# Determine the -T option. Was a valid one specified?
+case "$Topt" in
+ -Tascii | -Tlatin1 | -Tutf8 | -Tcp1047)
+ T=$Topt ;;
+esac
+
+# -T option absent or invalid; try environment.
+if [ -z "$T" ]
then
- T=$Topt
-else
- if [ -n "$Tenv" ]
- then
- T=-T$Tenv
- fi
+ Tenv=-T$GROFF_TYPESETTER
+ case "$Tenv" in
+ -Tascii | -Tlatin1 | -Tutf8 | -Tcp1047)
+ T=$Tenv ;;
+ esac
fi
-case $T in
- -Tascii | -Tlatin1 | -Tutf8 | -Tcp1047)
- ;;
- *)
- # ignore other devices and use locale fallback
- T=-T$Tloc ;;
-esac
+# Finally, infer a -T option from the locale. Try 'locale charmap'
+# first because it is the most reliable, then look at environment
+# variables.
+if [ -z "$T" ]
+then
+ case "`exec 2>/dev/null ; locale charmap`" in
+ UTF-8)
+ Tloc=utf8 ;;
+ ISO-8859-1 | ISO-8859-15)
+ Tloc=latin1 ;;
+ IBM-1047)
+ Tloc=cp1047 ;;
+ *)
+ case "${LC_ALL-${LC_CTYPE-${LANG}}}" in
+ *.UTF-8)
+ Tloc=utf8 ;;
+ iso_8859_1 | *.ISO-8859-1 | *.ISO8859-1 | \
+ iso_8859_15 | *.ISO-8859-15 | *.ISO8859-15)
+ Tloc=latin1 ;;
+ *.IBM-1047)
+ Tloc=cp1047 ;;
+ *)
+ case "$LESSCHARSET" in
+ utf-8)
+ Tloc=utf8 ;;
+ latin1)
+ Tloc=latin1 ;;
+ cp1047)
+ Tloc=cp1047 ;;
+ *)
+ Tloc=ascii ;;
+ esac ;;
+ esac ;;
+ esac
+ T=-T$Tloc
+fi
# Load nroff-style character definitions too.
opts="-mtty-char$opts"
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- [groff] 21/31: [nroff]: Refactor, mostly by relocation.,
G. Branden Robinson <=