/usr/bin/dicodconfig is in dicod 2.4-1.
This file is owned by root:root, with mode 0o755.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 | #!/usr/bin/perl
# dicodconfig -- generate dicod configuration database section
# Copyright (C) 2009 أحمد المحمودي (Ahmed El-Mahmoudy)
# Based on dictdconfig Copyright (C) 1999-2000 Kirk Hilliard <kirk@debian.org>
#
# 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 gcide wn foldoc jargon vera devil elements easton hitchcock gazetteer );
my $db_dir = "/usr/share/dictd";
push @db_order, "$db_dir/";
push @db_order, "/usr/share/dico/";
my %token;
$token{'database_exit'} = "database_exit\n";
my $dblist_file = "/var/lib/dicod/dictorg-db.list";
my $prog_dir = "/usr/sbin";
my $prog_name = "dicodconfig";
my $conf_file = "/etc/dicod.conf";
my $order_file = "/etc/dicod/dicod.order";
my $alias_script = "/etc/dicod/dicodconfig.alias";
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 = <<EOT;
Usage: $prog_name [OPTIONS]
Generate dictd configuration database section for available dictionary
databases found in $db_dir/.
-w, --write write database section to $dblist_file
-l, --list list database section to standard out
-o, --order display dictionary database order information
-h, --help display this help and exit
-v, --version display version information and exit
EOT
my $version = "$prog_name 1.1\n";
my $output = <<EOT;
# Automatically generated file -- do not edit.
#
# This file was automatically generated by $prog_name. Any changes
# made directly to this file will be lost when $prog_name is run upon
# installation, removal, or upgrade of a dictionary database package.
#
# This file provides a complete database section which may be
# included from the dictd configuration file $conf_file
# with an ``include $dblist_file'' line. The order and
# presence of the dictionary database entries here may be modified
# via the optional $prog_name order override file $order_file.
# See $prog_name(8) for details.
#
# Older dictionary database packages did not automatically invoke
# $prog_dir/$prog_name upon installation and removal, so you may
# need to do so manually (after which, you should restart dictd).
EOT
my $order_file_found_comment = <<EOT;
# Optional order override file $order_file found.
# Ignoring default order.
EOT
my $order_file_not_found_comment = <<EOT;
# Optional order override file $order_file not found.
# Using default order.
EOT
my $none_found = <<EOT;
# No dictionary databases were found.
# This dummy entry allows dictd to start.
EOT
my $order_header = <<EOT;
Dictionary Database Order Summary [See also $prog_name(8).]
Dictionary database entries will be generated only for those databases
found via basename and directory entries in the default order (or the
order override file, if present), and they will be generated in the
order in which these entries appear. No more than one dictionary
database entry of any given name will be generated.
Entries without a leading / are relative to $db_dir/.
Entries without a trailing / are basenames.
A dictionary database entry is generated if <basename>.index
and <basename>.dict.dz or <basename>.dict are present.
Entries with a trailing / are directories.
A dictionary database entry is generated for each <name> where
<directory>/<name>.index and <directory>/<name>.dict.dz or
<directory>/<name>.dict are present.
Default Order:
EOT
my $order_file_found = <<EOT;
Optional order override file $order_file found.
Ignoring default order.
New Order:
EOT
my $order_file_not_found = <<EOT;
Optional order override file $order_file not found.
Using default order.
EOT
ParseCommandLine(@ARGV);
print $version if $opt_version;
print $help if $opt_help;
exit if $opt_help || $opt_version;
if ( ! $opt_write && ! $opt_list && ! $opt_order ) {
print "No action taken.\n";
exit;
}
if ( $opt_order) {
print $order_header;
for (@db_order) { print " $_\n"; }
print "\n";
}
if ( -f $order_file ) {
$output .= $order_file_found_comment;
if ( $opt_order ) { print $order_file_found }
open ORDER, "$order_file"
or die "Can't open existing file `$order_file' for read: $!\n";
undef @db_order;
while (<ORDER>) {
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 ( $token{$_} ) { $output .= $token{$_} }
elsif ( m#/$# ) { CheckDirectory( $_ ) }
else { CheckDatabase( $_ ) }
}
if ( ! keys %db_entered ) {
$output .= $none_found;
AddEntry( "dummy", "/dev/null", "/dev/null" );
}
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, $base_name, $indexfile, $suffixfile, $wordfile ) = @_;
$output .= "database {\n" .
" name \"$name\";\n" .
" handler \"dictorg database=$base_name\"\;\n" .
"}\n";
++$db_entered{ $name };
}
sub AliasName {
my ( $name ) = @_;
if ( -x $alias_script ) { $name = `echo $name | $alias_script` }
return $name;
}
sub CheckDatabase {
my ( $base_name ) = @_;
my $name;
my $datafile;
my $indexfile;
my $suffixfile;
my $wordfile;
if ( $base_name =~ m#.*/(.*)# ) { $name = $1 }
else { $name = $base_name }
$name = AliasName( $name );
$base_name = "$db_dir/$base_name" unless $base_name =~ m#^/#;
$datafile = "$base_name.dict.dz";
$datafile =~ s/\.dz$// unless -f $datafile;
$indexfile = "$base_name.index";
$suffixfile = "$base_name.suffix";
$wordfile = "$base_name.word";
$name =~ s/\n//;
if ( ! $db_entered{ $name } && -f $datafile && -f $indexfile ) {
undef $suffixfile unless -f $suffixfile;
undef $wordfile unless -f $wordfile;
AddEntry( $name, $base_name, $indexfile, $suffixfile, $wordfile );
}
}
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"; }
}
}
|