3 # groffer - display groff files
5 # Source file position: <groff-source>/contrib/groffer/groffer.sh
7 # Copyright (C) 2001,2002,2003,2004,2005
8 # Free Software Foundation, Inc.
9 # Written by Bernd Warken
11 # This file is part of groff version @VERSION@ (eventually 1.19.2).
13 # groff is free software; you can redistribute it and/or modify it
14 # under the terms of the GNU General Public License as published by
15 # the Free Software Foundation; either version 2, or (at your option)
18 # groff is distributed in the hope that it will be useful, but WITHOUT
19 # ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
20 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public
21 # License for more details.
23 # You should have received a copy of the GNU General Public License
24 # along with groff; see the files COPYING and LICENSE in the top
25 # directory of the groff source. If not, write to the Free Software
26 # Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301, USA.
28 _PROGRAM_NAME
='groffer';
29 _PROGRAM_VERSION
='0.9.20';
30 _LAST_UPDATE
='30 July 2005';
33 ########################################################################
34 # Determine the shell under which to run this script from the command
35 # line arguments or $GROFF_OPT; if none is specified, just go on with
38 if test _
"${_GROFFER_RUN}"_
= __
;
40 # only reached during the first run of the script
42 export _GROFFER_RUN
; # counter for the runs of groffer
46 export _PROGRAM_VERSION
;
49 export GROFFER_OPT
; # option environment for groffer
50 export _GROFFER_SH
; # file name of this shell script
51 export _OUTPUT_FILE_NAME
; # output generated, see main_set_res..()
53 export _CONF_FILES
; # configuration files
54 _CONF_FILES
="/etc/groff/groffer.conf ${HOME}/.groff/groffer.conf";
59 # was: _GROFFER_SH="@BINDIR@/${_PROGRAM_NAME}";
62 echo "The ${_PROGRAM_NAME} script should be started directly." >&2
70 _NULL_DEV
="/dev/null";
80 _res
="$(unset _foo 2>&1)";
81 if unset _foo
>${_NULL_DEV} 2>&1 && \
82 test _
"${_res}"_
= __
&& test _
"${_foo}"_
= __
85 eval "${_UNSET}" _res
;
91 ###########################
92 # _get_opt_shell ("$@")
94 # Determine whether `--shell' was specified in $GROFF_OPT or in $*;
95 # if so, echo its argument.
97 # Output: the shell name if it was specified
101 case " ${GROFFER_OPT} $*" in
102 *\
--shell\
*|
*\
--shell=*)
104 eval set x
"${GROFFER_OPT}" '"$@"';
118 # delete up to first `=' character
119 _sh
="$(echo x"$1" | sed -e '
136 ###########################
137 # _test_on_shell (<name>)
139 # Test whether <name> is a shell program of Bourne type (POSIX sh).
143 if test "$#" -le 0 ||
test _
"$1"_
= __
;
147 # do not quote $1 to allow arguments
148 test _
"$(eval $1 -c "'"'s
=ok
; echo $s'"'" 2>${_NULL_DEV})"_
= _ok_
;
152 ###########################
153 # do the shell determination from command line and $GROFFER_OPT
154 _shell
="$(_get_opt_shell "$@
")";
155 if test _
"${_shell}"_
= __
;
157 # none found, so look at the `--shell' lines in configuration files
159 # for f in $_CONF_FILES
160 for f
in $
(eval set x
${_CONF_FILES}; shift; echo "$@")
164 _all
="$(cat "$f" | sed -n -e 's/^--shell[= ] *\([^ ]*\)$/\1/p')"
166 for s
in $
(eval set x
${_all}; shift; echo "$@")
177 export _GROFFER2_SH
; # file name of the script that follows up
178 _GROFFER2_SH
='@libdir@/groff/groffer/groffer2.sh';
180 # restart the script with the last found $_shell, if it is a shell
181 if _test_on_shell
"${_shell}";
183 _GROFFER_RUN
='second';
184 # do not quote $_shell to allow arguments
185 eval exec ${_shell} "'${_GROFFER2_SH}'" '"$@"';
189 _GROFFER_RUN
='second';
190 eval ${_UNSET} _shell
;
191 eval exec "'${_GROFFER2_SH}'" '"$@"';
193 fi; # end of first run
195 if test _
"${_GROFFER_RUN}"_
!= _second_
;
197 echo "$_GROFFER_RUN should be 'second' here." >&2
201 eval ${_UNSET} _GROFFER_RUN