[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Groff] grog Using groff.
From: |
Werner LEMBERG |
Subject: |
Re: [Groff] grog Using groff. |
Date: |
Mon, 17 Mar 2003 15:56:13 +0100 (CET) |
Ralph, attached is the version of grog.sh which I intend to include
into groff. There were some problems:
. Running with -d I get the following warnings (from my GNU awk
3.1.0):
awk: /tmp/grog.sh.21103.awk2:153:
warning: escape sequence `\.' treated as plain `.'
awk: /tmp/grog.sh.21103.awk2:158:
warning: escape sequence `\[' treated as plain `['
awk: /tmp/grog.sh.21103.awk2:159:
warning: escape sequence `\]' treated as plain `]'
Can you fix this?
. Doing `grog webpage.ms' I got `groff -mm webpage.ms'. Reason is
that webpage.ms uses `LI' which is defined in www.tmac. I've thus
removed the pattern which contains `LI'.
. Another problem are these two lines:
/^\.\[~/ : refer_start
/^\.\]~/ : refer_end
This is not correct. The space after `.[' and `.]' is already part
of the argument and *not* used as an argument separator -- with
other words, the following must work even if not in compatibility
mode:
See reference
.[ (
blablabla
.]).
I'm not sure how to handle this optimally so I haven't modified the
code.
. It is probably a good idea to allow e.g. `.cstart' and `.cstart '
also. I suggest to ignore trailing spaces. What do you think?
Werner
#! /bin/sh
# grog -- guess options for groff command.
# Inspired by `doctype' in Kernighan & Pike, Unix Programming Environment,
# pp 306-8.
# Copyright (C) 1989-2000, 2003 Free Software Foundation, Inc.
# Written by James Clark (address@hidden)
# Rewritten by Ralph Corderoy (address@hidden)
#
# This file is part of groff.
#
# groff 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, or (at your option) any later
# version.
#
# groff 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 groff; see the file COPYING. If not, write to the Free Software
# Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
progname=`basename $0`
t=/tmp/$progname.$$
address@hidden@soelim
soelim=soelim
opts=
debug=0
endmac="([\t\x20]|$)"
sp=$endmac
for arg
do
case "$arg" in
--)
shift
break
;;
-C)
sp=
opts="$opts -C"
shift
;;
-v|--version)
echo 'GNU grog (groff) version @VERSION@'
exit 0
;;
--help)
cat <<EOF
usage: $progname [options...] [files...]
where options are:
-v print version and exit.
-h provide this help.
-C enable compatibility mode, including placing -C in output.
-* any other options are prefixed to the output.
a file of \`-' means standard input. if no files are given standard
input is read.
EOF
exit 0
;;
-d)
debug=1
shift
;;
-)
break
;;
-*)
opts="$opts $arg"
shift
;;
*)
break
;;
esac
done
pat='
/^\.SO_START$/ : soelim
/^\.TS~/ : tbl
/^\.PS([0-9 .<].*)?$/ : pic
/^\.EQ~/ : eqn
/^\.R1~/ : refer
/^\.\[~/ : refer_start
/^\.\]~/ : refer_end
/^\.GS~/ : grn
/^\.G1~/ : grap
/^\.IS~/ : ideal
/^\.cstart$/ : chem
/^\.begin dformat$/ : dformat
/^\.G3$/ : g3
/^\.ALD~~/ : macromom
/^\.DOCTYPE~~/ : macromom
/^\.FAMILY~~/ : macromom
/^\.FAM~~/ : macromom
/^\.FT~~/ : macromom
/^\.LL~~/ : macromom
/^\.LS~~/ : macromom
/^\.NEWPAGE~~/ : macromom
/^\.PAGE~~/ : macromom
/^\.PAPER~~/ : macromom
/^\.PRINTSTYLE~~/ : macromom
/^\.PT_SIZE~~/ : macromom
/^\.T_MARGIN~~/ : macromom
/^\.P$~/ : macromm
/^\.PH~/ : macromm
/^\.SA~/ : macromm
/^\.H~/ : macromm
/^\.MULB~~/ : macromm
/^\.NCOL~~/ : macromm
/^\.pp~/ : macrome
/^\.np~/ : macrome
/^\.ip~/ : macrome
/^\.lp~/ : macrome
/^\.sh~/ : macrome
/^\.SH~/ : dotSH
/^\.TH~/ : dotTH
/^\.PP~/ : macroms
/^\.LP~/ : macroms
/^\.IP~/ : macroms
/^\.XP~/ : macroms
/^\.Dd~/ : macromdoc
/^\.Tp~/ : macromdoc_old
/^\.Dp~/ : macromdoc_old
/^\.De~/ : macromdoc_old
/^\.Cx~/ : macromdoc_old
/^\.Cl~/ : macromdoc_old
'
rule='
010 : soelim : $ : .-s
020 : tbl : $ : .-t
030 : pic : $ : .-p
040 : eqn : $ : .-e
050 : refer || refer_start && refer_end : $ : .-R
060 : grn : $ : .-g
070 : grap : $ : .-G
080 : chem : ^ : chem |.
081 : chem : $ : .-p
090 : ideal : ^ : ideal |.
091 : ideal : $ : .-p
100 : dformat : ^ : dformat |.
101 : dformat : $ : .-p
110 : g3 : ^ : g3 |.
111 : g3 : $ : .-p
120 : macromom : $ : .-mom
120 : macrome : $ : .-me
120 : dotSH && dotTH : $ : .-man
120 : macromm : $ : .-mm
120 : dotSH || macroms : $ : .-ms
120 : macromdoc && macromdoc_old : $ : .-mdoc-old
120 : macromdoc : $ : .-mdoc
'
cat <<EOF |
BEGIN {
debug = $debug
i = 0
$pat
numpat = i
i = 0
$rule
numrule = i
print "BEGIN { o = \"groff\" }"
}
END {
for (i = 0; i < numpat; i++) {
print re[i], "{", counter[i] "++"
if (debug) {
print "p" i "++"
}
print "next }"
}
print "END {"
if (debug) {
for (i = 0; i < numpat; i++) {
print "print \"" re[i] "\", p" i, "+ 0"
}
print "print \"\""
for (i = 0; i < numpat; i++) {
if (counter[i] in dup) {
continue
}
dup[counter[i]] = 1
print "print \"" counter[i] "\", " counter[i], "+ 0"
}
print "print \"\""
}
for (i = 0; i < numrule; i++) {
if (set[i] == last) {
print "else"
}
last = set[i]
print "if (" rule[i] ") { sub(/" place[i] "/, \"" opt[i] "\", o)"
if (debug) {
print "print \"" rule[i], "implies", opt[i] "\""
}
print "}"
}
if (debug) {
print "print \"\""
}
print "cmd = \"\""
print "pipeline = index(o, \"|\")"
print "if (pipeline && length(files)) cmd = \"cat \" files \" | \""
print "cmd = cmd o"
print "if (length(opts)) cmd = cmd \" \" opts"
print "if (!pipeline && length(files)) cmd = cmd \" \" files"
print "gsub(/ +/, \" \", cmd)"
print "print cmd"
print "}"
}
EOF
awk '
BEGIN {
FS = " : "
}
NF == 2 {
gsub(/~~/, "'"$endmac"'", $1)
gsub(/~/, "'"$sp"'", $1)
gsub(/[\\"]/, "\\\\&", $1)
$0 = "re[i] = \"" $1 "\"; counter[i] = \"" $2 "\"; i++"
}
NF == 4 {
s = "set[i] = \"" $1 "\";"
s = s " rule[i] = \"" $2 "\";"
s = s " place[i] = \"" $3 "\";"
gsub(/\./, " ", $4)
s = s " opt[i] = \"" $4 "\";"
s = s " i++"
$0 = s
}
1
' >$t.awk1
awk -f $t.awk1 </dev/null >$t.awk2
sed '
/^\./!d
/^\.so /s/^.*$/.SO_START\
&/
' "$@" |
$soelim |
awk -f $t.awk2 opts="$opts" files="$*"
rm $t.awk1 $t.awk2
# end of grog.sh
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- Re: [Groff] grog Using groff.,
Werner LEMBERG <=