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 `groffer', which is part of `groff' version
12 # @VERSION@. See $_GROFF_VERSION.
14 # `groff' is free software; you can redistribute it and/or modify it
15 # under the terms of the GNU General Public License as published by
16 # the Free Software Foundation; either version 2, or (at your option)
19 # `groff' is distributed in the hope that it will be useful, but
20 # WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
22 # General Public License for more details.
24 # You should have received a copy of the GNU General Public License
25 # along with `groff'; see the files COPYING and LICENSE in the top
26 # directory of the `groff' source. If not, write to the Free Software
27 # Foundation, 51 Franklin St - Fifth Floor, Boston, MA 02110-1301,
30 ########################################################################
32 _PROGRAM_VERSION
='0.9.22';
33 _LAST_UPDATE
='22 August 2005';
35 export _PROGRAM_VERSION
;
38 export GROFFER_OPT
; # option environment for groffer
40 export _CONF_FILE_ETC
; # configuration file in /etc
41 export _CONF_FILE_HOME
; # configuration file in $HOME
42 export _CONF_FILES
; # configuration files
43 _CONF_FILE_ETC
='/etc/groff/groffer.conf';
44 _CONF_FILE_HOME
="${HOME}/.groff/groffer.conf";
45 _CONF_FILES
="${_CONF_FILE_ETC} ${_CONF_FILE_HOME}";
60 _ERROR
='7'; # for syntax errors; no `-1' in `ash'
65 _GROFF_VERSION
='@VERSION@';
66 if test _@VERSION@_
= _
${_AT}VERSION
${_AT}_
68 _GROFF_VERSION
='1.19.2';
74 export _GROFFER_LIBDIR
;
75 if test _@BINDIR@_
= _
${_AT}BINDIR
${_AT}_
77 # script before `make'
83 _AT_BINDIR_AT
='@BINDIR@';
85 _AT_LIBDIR_AT
='@libdir@';
86 _GROFFER_LIBDIR
="${_AT_LIBDIR_AT}"'/groff/groffer';
89 export _GROFFER_SH
; # file name of this shell script
93 # was: _GROFFER_SH="${_AT_BINDIR_AT}/groffer";
96 echo 'The groffer script should be started directly.' >&2
101 export _GROFFER2_SH
; # file name of the script that follows up
102 _GROFFER2_SH
="${_GROFFER_LIBDIR}"/groffer2.sh
;
107 _NULL_DEV
="/dev/null";
113 # Test of the `$()' construct.
114 if test _
"$(echo "$
(echo 'test')")"_ \
117 echo 'The "$()" construct did not work.' >&2;
121 # Test of sed program
122 if test _
"$(echo red | sed -e 's/r/s/')"_
!= _sed_
124 echo 'The sed program did not work.' >&2;
129 ########################### configuration
131 # read and transform the configuration files, execute the arising commands
132 for f
in "${_CONF_FILE_HOME}" "${_CONF_FILE_ETC}"
136 o
=""; # $o means groffer option
137 # use "" quotes because of ksh and posh
138 eval "$(cat "$f" | sed -n -e '
140 /^['"${_SP}${_TAB}"']*#/d
141 # Delete leading and final space
142 s/^['"${_SP}${_TAB}"']*//
143 s/['"${_SP}${_TAB}"']*$//
144 # Print all shell commands
146 # Replace empty arguments
147 s/^\(-[^ ]*\)=$/o="${o} \1 '"${_SQ}${_SQ}"'"/p
148 # Replace division between option and argument by single space
149 s
/[='"${_SP}${_TAB}"']['"${_SP}${_TAB}"']*/'"${_SP}"'/
150 # Handle lines without spaces
151 s
/^\
(-[^
'"${_SP}"']*\
)$
/o
="${o} \1"/p
152 # Print options that have their argument encircled with single quotes
153 /^
-[^
]* '"${_SQ}"'.*'"${_SQ}"'$/s/^.*$/o="${o} &"/p
154 # Replace encircled double quotes by single quotes and print the result
155 s/^\(-[^ ]*\) "\(.*\)"$/o="${o} \1 '"${_SQ}"'\2'"${_SQ}"'"/p
156 # Encircle the remaining arguments with single quotes
157 s/^\(-[^ ]*\) \(.*\)$/o="${o} \1 '"${_SQ}"'\2'"${_SQ}"'"/p
159 if test _"${o}"_ != __
161 if test _"{GROFFER_OPT}"_ = __
165 GROFFER_OPT="${o} ${GROFFER_OPT}";
171 # integrate $GROFFER_OPT into the command line; it isn't needed any
more
172 if test _
"${GROFFER_OPT}"_
!= __
174 eval set x
"${GROFFER_OPT}" '"$@"';
180 ########################### Determine the shell
184 # use "``" instead of "$()" for using the case ")" construct
185 # do not use "" quotes because of ksh
189 # The command line arguments are taken over.
190 # Shifting herein does not have an effect outside.
193 *\ --sh*) # abbreviation for --shell
196 # determine all --shell arguments, store them in $x in reverse order
200 --shell|--sh|--she|--shel)
207 --shell=*|--sh=*|--she=*|--shel=*)
208 # delete up to first "=" character
209 s="$(echo x"$1" | sed -e 's/^x[^=]*=//')";
215 if test _"${x}"_ = __
224 # from all possible shells in $x determine the first being a shell
227 # "" quotes because of posh
236 # use the empty argument as the default shell
240 # test $i on being a shell program;
241 # use this kind of quoting for posh
242 if test _"$(eval "$i -c 'echo ok'" 2>${_NULL_DEV})"_ = _ok_ >&2
250 # if not being a shell go on searching
257 if test _"${s}"_ != __
267 ########################### test fast shells for automatic run
269 if test _
"${_SHELL}"_
= __
271 for s
in ksh ash dash pdksh zsh posh
273 if test _
"$(eval "$s -c 'echo ok'" 2>${_NULL_DEV})"_
= _ok_
>&2
282 ########################### start groffer2.sh
284 if test _
"${_SHELL}"_
= _empty_
289 if test _
"${_SHELL}"_
= __
291 # no shell found, so start groffer2.sh normally
292 eval exec "'${_GROFFER2_SH}'" '"$@"';
295 # start groffer2.sh with the found $_SHELL
296 # do not quote $_SHELL to allow arguments
297 eval exec "${_SHELL} '${_GROFFER2_SH}'" '"$@"';