#!/bin/sh # @(#$Id: rcldoc,v 1.4 2005-10-20 15:42:29 dockes Exp $ (C) 2004 J.F.Dockes # Parts taken from Estraier: #================================================================ # Estraier: a personal full-text search system # Copyright (C) 2003-2004 Mikio Hirabayashi #================================================================ #================================================================ # rcldoc # Extract text from an msword file by executing either antiword # (or wvware maybe if we need it one day) # # The default is to use antiword, the code would need modifications to # work with wvWare # #================================================================ # set variables LANG=C ; export LANG LC_ALL=C ; export LC_ALL progname="rcldoc" decoder="antiword -i -1 -m UTF-8" # Not ready to use this for now (it outputs html, so the code below has to # be simplified.) #decoder="wvWare -1 -c UTF-8" # show help message if test $# -ne 1 -o "$1" = "--help" then printf 'Convert a word file to unformatted HTML text.\n' printf 'Usage: %s [infile]\n' "$progname" exit 1 fi infile="$1" iscmd() { cmd=$1 case $cmd in */*) if test -x $cmd ; then return 0; else return 1; fi ;; *) oldifs=$IFS; IFS=":"; set -- $PATH; IFS=$oldifs for d in $*;do test -x $d/$cmd && return 0;done return 1 ;; esac } checkcmds() { for cmd in $*;do if iscmd $cmd then a=1 else echo $cmd not found 1>&2 exit 1 fi done } checkcmds awk antiword iconv # check the input file existence if test ! -f "$infile" then printf '%s: %s: no such file\n' "$progname" "$infile" exit 1 fi # output the result $decoder "$infile" | awk ' BEGIN { printf("\n") printf("\n") printf("\n

"); esc = 1 } { if ($0 ~ /-$/) { sub(/-$/, "", $0) printf("%s", $0); } else if($0 == "\f") { printf("

\n
\n

") } else { if(esc > 0) { gsub(/&/, "\\&", $0) gsub(//, "\\>", $0) } print $0 } } END { printf("

\n"); }' | iconv -f UTF-8 -t UTF-8 -c -s # exit normally exit 0