From d34d28418ae4ba7cbdad979459f1e36eaa98b88c Mon Sep 17 00:00:00 2001 From: Jean-Francois Dockes Date: Sun, 6 Jul 2014 16:24:11 +0200 Subject: [PATCH] msword docs: avoid generating an error for files containing only a picture (empty antiword output) --- src/filters/rcldoc | 41 +++++++++++++++++++++++++---------------- 1 file changed, 25 insertions(+), 16 deletions(-) diff --git a/src/filters/rcldoc b/src/filters/rcldoc index 287188c8..0b132fa7 100755 --- a/src/filters/rcldoc +++ b/src/filters/rcldoc @@ -90,23 +90,30 @@ umask 77 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 # is an awk program -$decoder "$infile" | +(((($decoder "$infile"; echo $? >&3) | awk 'BEGIN'\ ' { cont = "" gotdata = 0 } { - if (!($0 ~ /^[ ]*$/)) { + if (!($0 ~ /^[ ]*$/) && gotdata == 0) { + print "" + print "" + print "\n\n

" gotdata = 1 - if (gotdata == 0) { - print "" - print "" - print "\n\n

" - } } $0 = cont $0 cont = "" @@ -124,17 +131,19 @@ awk 'BEGIN'\ print "


" next } - gsub(/&/, "\\&", $0) - gsub(//, "\\>", $0) - print $0 "
" + if (gotdata == 1) { + gsub(/&/, "\\&", $0) + gsub(//, "\\>", $0) + + print $0 "
" + } } END { - if (gotdata == 0) - exit(1) - print "

" -}' + if (gotdata == 1) + print "

" +}' >&4) 3>&1) | stdintoexitstatus) 4>&1 # Antiword rarely fails, we try to catch the most common reasons: