#!/usr/bin/perl
# Convert Winword doc files to html
# Usage: doc2html searchdir
# All changed files in searchdir and subdirectories
#  are converted to ./html/*.htm
# Pirmin Kalberer <kalberer@spin.ch>, 8.5.98

require "find.pl";

$searchdir = @ARGV[0];

# Traverse desired filesystems

$File::Find::dont_use_nlink = 1; # Needed for (smb)mounted NT-drive
&find($searchdir);

exit;

sub wanted {
    /^.*\.doc$/i &&
    ($htmlname = $_) && ($htmlname =~ s/.doc/.htm/i) &&
    (($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$docmtime,$ctime) = stat($name)) &&
    (!(($dev,$ino,$mode,$nlink,$uid,$gid,$rdev,$size,$atime,$htmlmtime,$ctime) = stat("$dir/html/$htmlname")) ||
    $docmtime > $htmlmtime) &&
    print("$name -> html/$htmlname\n") &&
    (-e "$dir/html" || mkdir html,777) &&
    system("export LC_CTYPE=; lhalw --to_stdout '$name' 2>/dev/null | /usr/local/bin/txt2html.pl --shortline 999 >'$dir/html/$htmlname'") == 0;
#    system("lhalw --override --dest_base html '$name'") == 0;
#    system("catdoc '$name' >'$dir/html/$htmlname'") == 0;
}
