option to use catdvi

This commit is contained in:
dockes 2006-02-03 11:47:47 +00:00
parent 87216c22f5
commit d788625849

View File

@ -1,10 +1,28 @@
#!/bin/sh #!/bin/sh
# @(#$Id: rcldvi,v 1.1 2006-02-03 10:53:34 dockes Exp $ (C) 2004 J.F.Dockes # @(#$Id: rcldvi,v 1.2 2006-02-03 11:47:47 dockes Exp $ (C) 2006 J.F.Dockes
#================================================================
# rcldvi # This program is free software; you can redistribute it and/or modify
# Extract text from a dvi file by executing dvitops and rclps # it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
# #
#================================================================ # This program 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 this program; if not, write to the
# Free Software Foundation, Inc.,
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# rcldvi
# Extract text from a dvi file by either executing dvitops and rclps
# or using catdvi. dvitops has given better results during tests, and is
# chosen first if available, but the dvitops/rclps combination is much
# slower than catdvi
# Show help message # Show help message
if test $# -ne 1 -o "$1" = "--help" if test $# -ne 1 -o "$1" = "--help"
@ -14,8 +32,6 @@ then
exit 1 exit 1
fi fi
decoder=dvips
# Find rclps. Note: this only works because we are always executed with a # Find rclps. Note: this only works because we are always executed with a
# full path # full path
infile="$1" infile="$1"
@ -33,19 +49,19 @@ iscmd()
return 1 ;; return 1 ;;
esac esac
} }
checkcmds()
{ decoder=""
for cmd in $*;do if iscmd dvips -a iscmd pstotext ; then
if iscmd $cmd decoder=dvips
then else
a=1 decoder=catdvi
else fi
echo $cmd not found 1>&2
exit 1 if test X$decoder = X ; then
fi echo "$progname: did not find either catdvi or dvips." 1>&2
done exit 1
} fi
checkcmds $decoder
# check the input file existence # check the input file existence
if test ! -f "$infile" if test ! -f "$infile"
@ -54,5 +70,40 @@ then
exit 1 exit 1
fi fi
# output the result if test X$decoder = Xdvips ; then
$decoder -f < "$infile" 2> /dev/null | $rclps - $decoder -f < "$infile" 2> /dev/null | $rclps -
exit $?
fi
$decoder "$infile" |
awk '
BEGIN {
printf("<html><head><title></title>\n")
printf("<meta http-equiv=\"Content-Type\" content=\"text/html;charset=UTF-8\">\n")
printf("</head>\n<body><p>");
cont = ""
}
{
$0 = cont $0
cont = ""
if ($0 == "\f") {
print "</p>\n<hr>\n<p>"
next
} else if ($0 ~ /-$/) {
match($0, "[ \t][^ \t]+$")
line = substr($0, 0, RSTART)
cont = substr($0, RSTART, RLENGTH)
$0 = line
gsub("-", "", cont)
}
gsub(/&/, "\\&amp;", $0)
gsub(/</, "\\&lt;", $0)
gsub(/>/, "\\&gt;", $0)
print $0 "<br>"
}
END {
print "</p></body></html>"
}'