#! /usr/bin/perl -w
#
# -*- Perl -*-
# $Id:$
# Copyright (C) 2004 Tadamasa Teranishi,
#               2004 Namazu Project All rights reserved.
#     This is free software with ABSOLUTELY NO WARRANTY.
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the GNU General Public License as published by
#  the Free Software Foundation; either versions 2, 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
#
#  This file must be encoded in EUC-JP encoding
#
#
#  Some Code copy from Win32::OLE Example program.
#  Licence for these code is
#    You may distribute under the terms of either the GNU General Public
#    License or the Artistic License, as specified in the README(Win32::OLE) file.
#

use strict;
use Win32::OLE qw(in with);

my $InstallOnly = 0;
my $ReadOnly = 0;

# for Word application start only one time
my $word = undef;

END {
    $word->Quit() if defined $word;
    undef $word;
}

main();

sub main {
    unless (defined $word) {
	$word = Win32::OLE->new('Word.Application', 'Quit')
	    or die "Oops, cannot start Word." . Win32::OLE::LastError();
    }

    $Win32::OLE::Warn = 0;       # False
    $word->{Visible} = 0;        # False
    $word->{DisplayAlerts} = 0;  # False

    my $version = $word->{Version};
    print "Microsoft Word $version\n";

    my @convlist;
    my %name;
    my %ext;
    my %canopen;
    my %cansave;

    foreach my $conv (in $word->{FileConverters}) {
        my $class = lc $conv->{'ClassName'};
        push (@convlist, $class);
        $name{$class} = lc $conv->{'Name'};
        $ext{$class} = lc $conv->{'Extensions'};
        $canopen{$class} = lc $conv->{'CanOpen'};
        $cansave{$class} = lc $conv->{'CanSave'};
    }

    foreach my $conv (sort @convlist) {
        my $inst = '-';
        my $read = '-';
        my $write = '-';

        if (defined $name{$conv} && $name{$conv} ne '') {
            $inst = ' ';
        }
        if ($canopen{$conv} == 1) {
            $read = 'r';
        }
        if ($cansave{$conv} == 1) {
            $write = 'w';
        }

        if ($InstallOnly == 1 && $inst ne ' ') {
        } elsif ($ReadOnly == 1 && $read ne 'r') {
        } else {
            print "$inst$read$write $conv:$ext{$conv}\n";
        }
    }
}
