#!/usr/bin/perl -w
#
# Registration with hunspell dictionary

use strict;

my $class = "hunspell";
my $program = "installdeb-$class";
my $debug;

# =======================================================
# Main part
# =======================================================

use Text::Wrap;
$Text::Wrap::columns = 72;

use Debian::Debhelper::Dh_Lib;
use Debian::DictionariesCommon q(:all);
use Devel::DictionariesCommon q(:all);

if ( "$class" eq "wordlist" or "$class" eq "ispell" ){
  init( options => { 'write-elanguages'  => \$dh{WRITE_ELANGUAGES},
		     'no-elanguages'     => \$dh{DISABLE_ELANGUAGES},
		     'no-pre-post'       => \$dh{DISABLE_PREPOST},
		     'no-installdebconf' => \$dh{NO_INSTALLDEBCONF}
		   });
} elsif ( $class eq "aspell" ){
  init(options => { 'aspell-simple' => \$dh{ASPELL_SIMPLE} });
} else {
  init();
}

if ( $dh{NOSCRIPTS} ){
  $dh{DISABLE_PREPOST}++;
  $dh{NO_INSTALLDEBCONF}++;
};

delete $dh{WRITE_ELANGUAGES} if ( $dh{DISABLE_ELANGUAGES} );

foreach my $package (@{$dh{DOPACKAGES}}) {
  my $lib_dir       = tmpdir($package) . getlibdir($class);
  my $usr_lib_dir   = tmpdir($package) . "/usr/lib/$class";
  my $var_lib_dir   = tmpdir($package) . "/var/lib/$class";
  my $usr_share_dir = tmpdir($package) . "/usr/share/$class";
  my %options       = ('class'         => $class,
		       'program'       => $program,
		       'package'       => $package,
		       'lib_dir'       => $lib_dir,
		       'usr_lib_dir'   => $usr_lib_dir,
		       'var_lib_dir'   => $var_lib_dir,
		       'usr_share_dir' => $usr_share_dir
		      );

  # "cdbs" snippets call installdeb-* scripts unconditionally in
  # case there is something for them.
  # Do not trigger an error if not found, just exit.
  my $dicts = dico_process_infofile(\%options)
    or exit;

  #

  # Install debhelper and debhelper-like auto-scripts
  unless ( $dh{NOSCRIPTS} or $dh{DISABLE_PREPOST}) {
    if ( $class ne "wordlist" ){
      my %hash_extension   = ("ispell" => "hash", "aspell" => "rws");
      my $autocompat_info  = dico_process_autocompat($dicts,\%options);

      #

      if ( %{$autocompat_info->{'auto-compat'}} ){
	verbose_print("$program info:");
	if ( defined  $autocompat_info->{'auto-contents'}
	     && %{$autocompat_info->{'auto-contents'}} ){
	  verbose_print(" auto-contents: \"",join(', ',sort keys %{$autocompat_info->{'auto-contents'}}),"\"");
	}
	verbose_print(" auto-compat: \"",join(', ',sort keys %{$autocompat_info->{'auto-compat'}}),"\"");
	verbose_print(" auto-hash: \"",  join(', ',sort keys %{$autocompat_info->{'auto-hash'}}), "\"");
      }

      # Install autocompat autoscripts
      if ( %{$autocompat_info->{'auto-compat'}} ){
	dico_install_autocompat($autocompat_info,\%options);
      }
    }

    # Install normal autoscripts
    autoscript ($package, "postinst", "postinst-$class",
		"s/#PACKAGE#/$package/");
    autoscript ($package, "postrm", "postrm-$class",
		"s/#PACKAGE#/$package/");

    # Populate substvars $class:Depends
    dico_populate_substvars(\%options);
  }
  ## -- No debconf handling needed for aspell or hunspell --
}


__END__

=head1 NAME

B<installdeb-hunspell> - debhelper-like utility for
maintainers of  Debian packages

=head1 SYNOPSIS

 installdeb-hunspell [debhelper options] 

=head1 DESCRIPTION

B<installdeb-hunspell> is a debhelper like program that is
responsible for installing appropriate debhelper snippets in
a  package,
according to the Debian Spell Dictionaries and Tools Policy.

For more details, see
 /usr/share/doc/dictionaries-common-dev/dsdt-policy.txt.gz

The actions executed by B<installdeb-hunspell> are the
following:

=over

=item * Maintainer Scripts

B<installdeb-hunspell> installs the necessary
scraps of code in the F<postinst> and F<postrm> scripts.

=item * Language info file

B<installdeb-hunspell> also checks a file containing
 information, called
F<debian/info-hunspell> or
F<debian/package.info-hunspell>.  If this file is
successfully parsed, it is installed in the
F</var/lib/dictionaries-common/hunspell> directory.

=item * Debconf files

As opposed to B<installdeb-ispell> and B<installdeb-wordlist>, neither B<installdeb-aspell>
nor B<installdeb-hunspell> do anything related to debconf files, since both aspell and
hunspell rely on the environment variable C<LANG> for default dictionary selection
instead of using symlinks set after a debconf question on dictionary
installation. For that reason if you need to add debconf stuff with debhelper
to your aspell or hunspell dictionary package do it in the usual way and call
dh_installdebconf(1) as for any other package.


=back

=head1 OPTIONS

The usual dephelper(1) options are accepted. 

=head1 NOTES

This program is not part of debhelper, although it is intended to be used
in hunspell dictionary packages using debhelper in its
building.

=head1 SEE ALSO

debhelper(1)

This program is part of the dictionaries-common-dev package. It is
intended to be used by maintainers of
hunspell dictionary
packages for Debian. See the documentation
under /usr/share/doc/dictionaries-common-dev.

=head1 AUTHORS

Rafael Laboissiere, Agustin Martin

=cut

# Local Variables:
#  mode: perl
#  mode: flyspell-prog
#  ispell-local-dictionary: "american"
# End:

#  LocalWords:  aspell ispell wordlist debconf debhelper Debian config postrm
#  LocalWords:  debian elanguages installdeb dephelper installdebconf Elanguage
#  LocalWords:  Laboissiere
