my $progname=$0; $progname = $& if $progname =~ m,[^/]+$,;
my %PREFIX; # used to search for prefix numbers
my %ISOCODE; # used to search for iso codes
my %LANGUAGE; # used to search for language names
#======================================================================= # initialisation code - stuff the DATA into the CODES hash #=======================================================================
sub init {
#======================================================================= # usage - error message #=======================================================================
sub usage {
my $errmsg = shift;
my $errcode = shift;
print STDERR "$progname: $errmsg\n"if $errmsg;
print STDERR "$progname: Converts between prefix codes, iso codes and langnames\n";
print STDERR " Usage: $progname (-i|-l|-p|-h) |all\n";
print STDERR " -i : convert prefix to iso code (ex: 03 -> pt)\n";
print STDERR " -l : convert iso code to language name (ex: pt -> portuguese)\n";
print STDERR " -p : convert iso code to prefix (ex: pt -> 03)\n";
print STDERR " the code can either be an iso code, a prefix or even a language name\n";
print STDERR " The special code \"all\" asks for all possible values.\n\n";
print STDERR " -h : print this help\n";
exit $errcode;
}
#======================================================================= # main - #=======================================================================
init();
usage ("no operation specified on command line",1) if (!$LanguageMap);
usage ("no language code specified on command line",1) if (!($LanguageCode = shift));
if ($LanguageCode =~ (m/^all$/)) { # Asked for all codes
my $old=""; foreach my $key (sort values %$LanguageMap) { if ($key ne $old) {
print "$key ";
$old=$key;
}
}
print "\n";
exit 0;
}
usage ("no mapping found for $LanguageCode\n",1) if (!($LanguageMap->{$LanguageCode}));
print $LanguageMap->{$LanguageCode}, "\n";
1;
# keep third column names here with openoffice-dir/share/*/<long lang name>/