msword docs: avoid generating an error for files containing only a picture (empty antiword output)

This commit is contained in:
Jean-Francois Dockes 2014-07-06 16:24:11 +02:00
parent 244c2ed468
commit d34d28418a

View file

@ -90,23 +90,30 @@ umask 77
checkcmds awk antiword iconv checkcmds awk antiword iconv
# output the result # We need to do some strange stuff to retrieve the status from antiword. Things
# would be simpler if we relied on using bash.
# Explanations:
#http://stackoverflow.com/questions/1221833/bash-pipe-output-and-capture-exit-status
stdintoexitstatus() {
read exitstatus
return $exitstatus
}
# The strange 'BEGIN' setup is to prevent 'file' from thinking this file # The strange 'BEGIN' setup is to prevent 'file' from thinking this file
# is an awk program # is an awk program
$decoder "$infile" | (((($decoder "$infile"; echo $? >&3) |
awk 'BEGIN'\ awk 'BEGIN'\
' { ' {
cont = "" cont = ""
gotdata = 0 gotdata = 0
} }
{ {
if (!($0 ~ /^[ ]*$/)) { if (!($0 ~ /^[ ]*$/) && gotdata == 0) {
gotdata = 1
if (gotdata == 0) {
print "<html><head><title></title>" print "<html><head><title></title>"
print "<meta http-equiv=\"Content-Type\" content=\"text/html;charset=UTF-8\">" print "<meta http-equiv=\"Content-Type\" content=\"text/html;charset=UTF-8\">"
print "</head>\n<body>\n<p>" print "</head>\n<body>\n<p>"
} gotdata = 1
} }
$0 = cont $0 $0 = cont $0
cont = "" cont = ""
@ -124,17 +131,19 @@ awk 'BEGIN'\
print "</p><hr><p>" print "</p><hr><p>"
next next
} }
if (gotdata == 1) {
gsub(/&/, "\\&amp;", $0) gsub(/&/, "\\&amp;", $0)
gsub(/</, "\\&lt;", $0) gsub(/</, "\\&lt;", $0)
gsub(/>/, "\\&gt;", $0) gsub(/>/, "\\&gt;", $0)
print $0 "<br>" print $0 "<br>"
} }
}
END { END {
if (gotdata == 0) if (gotdata == 1)
exit(1)
print "</p></body></html>" print "</p></body></html>"
}' }' >&4) 3>&1) | stdintoexitstatus) 4>&1
# Antiword rarely fails, we try to catch the most common reasons: # Antiword rarely fails, we try to catch the most common reasons: