#!/usr/bin/perl # dictdconfig -- generate dictd configuration database section # Copyright (C) 1999-2000 Kirk Hilliard # # This is free software, published under version 2 or (at your option) # any later version of the GNU General Public License. You should # have received a copy of the GNU General Public License with your # Debian GNU/Linux system as /usr/share/common-licenses/GPL. my @db_order = qw( web1913 wn foldoc jargon vera elements easton hitchcock gazetteer ); my $db_dir = "/usr/share/dictd"; push @db_order, "$db_dir/"; my $dblist_file = "/var/lib/dictd/db.list"; my $prog_dir = "/usr/sbin"; my $prog_name = "dictdconfig"; my $conf_file = "/etc/dictd.conf"; my $order_file = "/etc/dictd.order"; my %db_entered; my ( $opt_write, $opt_list, $opt_order, $opt_help, $opt_version); my %opt_matrix = ( '-w' => \$opt_write, '--write' => \$opt_write, '-l' => \$opt_list, '--list' => \$opt_list, '-o' => \$opt_order, '--order' => \$opt_order, '-h' => \$opt_help, '--help' => \$opt_help, '-v' => \$opt_version, '--version' => \$opt_version ); my $help = <.index and .dict.dz or .dict are present. Entries with a trailing / are directories. A dictionary database entry is generated for each where /.index and /.dict.dz or /.dict are present. Default Order: EOT my $order_file_found = <) { chomp; s/#.*//; push @db_order, split; } if ( $opt_order ) { for (@db_order) { print " $_\n"; } print "\n"; } } else { $output .= $order_file_not_found_comment; if ( $opt_order) { print $order_file_not_found } } for (@db_order) { if ( m#/$# ) { CheckDirectory( $_ ) } else { CheckDatabase( $_ ) } } if ( ! keys %db_entered ) { $output .= $none_found; AddEntry( "dummy", "/dev/zero", "/dev/zero" ); } if ( $opt_list ) { print $output } if ( $opt_write ) { open DBLIST, ">$dblist_file" or die "Can't write to file $dblist_file: $!\n"; print DBLIST $output; close DBLIST; } exit 0; sub AddEntry { my ( $name, $datafile, $indexfile ) = @_; $output .= "database $name {\n" . " data $datafile\n" . " index $indexfile\n" . "}\n"; ++$db_entered{ $name }; } sub CheckDatabase { my ( $base_name ) = @_; my $name; my $datafile; my $indexfile; if ( $base_name =~ m#.*/(.*)# ) { $name = $1 } else { $name = $base_name } if ( $base_name =~ m#^/# ) { $datafile = $indexfile = $base_name } else { $datafile = $indexfile = "$db_dir/$base_name" } $datafile .= ".dict.dz"; $datafile =~ s/\.dz$// unless -f $datafile; $indexfile .= ".index"; if ( ! $db_entered{ $name } && -f $datafile && -f $indexfile ) { AddEntry( $name, $datafile, $indexfile ); } } sub CheckDirectory { my ( $dir ) = @_; $dir = "$db_dir/$dir" unless $dir =~ m#^/#; opendir DIR, $dir; for (readdir DIR) { if ( /(^.*)\.index$/ ) { CheckDatabase( "$dir$1" ) } } closedir DIR; } sub ParseCommandLine { my $ref; for (@_) { if ( $ref = $opt_matrix{$_} ) { ++$$ref; } elsif ( /^-([^-].*)/ ) { for ( split //, $1 ) { if ( $ref = $opt_matrix{"-$_"} ) { ++$$ref; } else { die "$prog_name: unrecognized option `-$_'.\n" . "Try `$0 --help' for more information.\n"; } } } else { die "$prog_name: unrecognized option `$_'.\n" . "Try `$0 --help' for more information.\n"; } } }