2 # grog -- guess options for groff command
3 # Like doctype in Kernighan & Pike, Unix Programming Environment, pp 306-8.
5 # Source file position: <groff-source>/src/roff/grog/grog.sh
6 # Installed position: <prefix>/bin/grog
8 # Copyright (C) 1993, 2006, 2009 Free Software Foundation, Inc.
9 # Written by James Clark, maintained by Werner Lemberg.
10 # Rewritten by and put under GPL Bernd Warken.
12 # This file is part of `grog', which is part of `groff'.
14 # `groff' is free software; you can redistribute it and/or modify it
15 # under the terms of the GNU General Public License (GPL) as published
16 # by the Free Software Foundation, either version 3 of the License, or
17 # (at your option) any later version.
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 this program. If not, see <http://www.gnu.org/licenses/>.
27 ########################################################################
28 Last_Update='5 Jan 2009'
29 ########################################################################
44 if test _"${double_minus}"_ = _1_
47 if test -f "${arg}" && test -r "${arg}"
51 eval filespec="'${filespec} '"'\"'"'${arg}'"'\"'
54 eval filespec="'${filespec} ${arg}'"
58 echo "grog: ${arg} is not a readable file.">&2
68 if test _"${was_minus}"_ = _0_
71 filespec="${filespec} -"
77 -v|--v|--ve|--ver|--vers|--versi|--versio|--version)
79 "Shell version of GNU grog of $Last_Update in groff version @VERSION@";
82 -h|--h|--he|--hel|--help)
85 usage: grog [option]... [--] [filespec]...
87 "filespec" is either the name of an existing, readable file or "-" for
88 standard input. If no "filespec" is specified, standard input is
89 assumed automatically.
91 "option" is either a "groff" option or one of these:
94 -h --help print this uasge message and exit
95 -v --version print version information and exit
97 "groff" options are appended to the output, "-m" options are checked.
103 if test _"$nr"_ = _0_
108 echo "grog: several -m* options are not allowed." >&2
117 if test -f "${arg}" && test -r "${arg}"
121 eval filespec="'${filespec} '"'\"'"'${arg}'"'\"'
124 eval filespec="'${filespec} ${arg}'"
128 echo "grog: ${arg} is not a readable file.">&2
133 if test _"${filespec}"_ = __ && test _"${had_filespec}"_ = _0_
137 if test _"${filespec}"_ = __
141 if test "${double_minus}" = 1
143 eval files="'-- ${filespec}'"
145 eval files="'${filespec}'"
147 files=`echo $files|sed s/\"/\'/g`
150 eval sed "'s/[ ]*$//'" '--' "${filespec}" \
151 | sed 's/^[ ]*begin[ ][ ]*chem$/.cstart/' \
152 | sed 's/^[.'"'"'][ ]*/./' \
154 "^\.(\[|\])|cstart|((P|PS|[PLI]P|[pnil]p|sh|Dd|Tp|Dp|De|Cx|Cl|Oo|.* Oo|Oc|.* Oc|NH|TL|TS|TE|EQ|TH|SH|so|\[|R1|GS|G1|PH|SA)$sp)" \
155 | sed '/^\.so/s/^.*$/.SO_START\
160 '^\.(cstart|P|PS|[PLI]P|[pnil]p|sh|Dd|Tp|Dp|De|Cx|Cl|Oo|.* Oo|Oc|.* Oc|NH|TL|TS|TE|EQ|TH|TL|NH|SH|\[|\]|R1|GS|G1|PH|SA|SO_START|SO_END)' \
162 /^\.SO_START$/ { so = 1 }
163 /^\.SO_END$/ { so = 0 }
164 /^\.cstart$/ { chem++ }
165 /^\.TS/ { tbl++; in_tbl = 1; if (so > 0) soelim++; }
166 /^\.TE/ { in_tbl = 0 }
167 /^\.PS([ 0-9.<].*)?$/ { pic++; if (so > 0) soelim++ }
168 /^\.EQ/ { eqn++; if (so > 0) soelim++ }
169 /^\.R1/ { refer++; if (so > 0) soelim++ }
170 /^\.\[/ {refer_start++; if (so > 0) soelim++ }
171 /^\.\]/ {refer_end++; if (so > 0) soelim++ }
172 /^\.GS/ { grn++; if (so > 0) soelim++ }
173 /^\.G1/ { grap++; pic++; if (so > 0) soelim++ }
174 /^\.TH/ { if (in_tbl != 1) TH++ }
181 /^\.(PH|SA)/ { mm++ }
182 /^\.([pnil]p|sh)/ { me++ }
184 /^\.(Tp|Dp|De|Cx|Cl)/ { mdoc_old++ }
185 /^\.(O[oc]|.* O[oc]( |$))/ {
187 gsub(/\"[^\"]*\"/, "")
202 /^\.(PRINTSTYLE|START)/ { mom++ }
206 printf "chem %s | ", files
211 refer = refer || (refer_start && refer_end)
212 if (pic > 0 || tbl > 0 || grn > 0 || grap > 0 || eqn > 0 || refer > 0) {
214 if (soelim > 0) printf "s"
215 if (refer > 0) printf "R"
216 if (grn > 0) printf "g"
217 if (grap > 0) printf "G"
218 if (pic > 0) printf "p"
219 if (tbl > 0) printf "t"
220 if (eqn > 0) printf "e"
229 mnr++; m = "-me"; printf " -me"
232 if (SH > 0 && TH > 0) {
233 mnr++; m = "-man"; printf " -man"; is_man = 1
237 mnr++; m = "-mom"; printf " -mom"; is_mom = 1
240 if ( mm > 0 || (P > 0 && is_man == 0) ) {
241 mnr++; m = "-mm"; printf " -mm"; is_mm = 1
244 if ( NH > 0 || (TL > 0 && is_mm == 0) || (ILP > 0 && is_man == 0) ||
245 (PP > 0 && is_mom == 0 && is_man == 0) ) {
246 # .TL also occurs in -mm, .IP and .LP also occur in -man
247 # .PP also occurs in -mom and -man
248 mnr++; m = "-ms"; printf " -ms"
253 if (mdoc_old > 0 || Oo > 0) {
254 m = "-mdoc-old"; printf " -mdoc-old"
257 m = "-mdoc"; printf " -mdoc"
273 if (mopt != "" && m != mopt)
274 printf "grog: wrong option %s\n", mopt | "cat 1>&2"
277 err = "grog: error: there are several -m* arguments"
278 printf "%s\n", err | "cat 1>&2"
281 }' "opts=$opts" "mopt=$mopt" "files=$files" -