mirror of
https://github.com/pragma-/pbot.git
synced 2025-01-11 12:32:37 +01:00
Improve handling of -t for dict command
This commit is contained in:
parent
b23f025a12
commit
81abdbec29
@ -67,7 +67,7 @@ if (@ARGV > 0)
|
|||||||
}
|
}
|
||||||
=cut
|
=cut
|
||||||
} else {
|
} else {
|
||||||
print "Usage: dict [-d database] [-n start from definition number] [-t first letter of word class type (n]oun, v]erb, etc)] [-search <regex> for definitions matching <regex>] <word>\n";
|
print "Usage: dict [-d database] [-n start from definition number] [-t abbreviation of word class type (n]oun, v]erb, adv]erb, adj]ective, etc)] [-search <regex> for definitions matching <regex>] <word>\n";
|
||||||
exit 0;
|
exit 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -115,6 +115,8 @@ sub define_word
|
|||||||
$def_contains =~ s/\.\*/*/g;
|
$def_contains =~ s/\.\*/*/g;
|
||||||
$def_contains =~ s/\*/.*/g;
|
$def_contains =~ s/\*/.*/g;
|
||||||
|
|
||||||
|
my $defined = 0;
|
||||||
|
|
||||||
eval {
|
eval {
|
||||||
foreach my $type (keys %$defs) {
|
foreach my $type (keys %$defs) {
|
||||||
next if $type eq 'word';
|
next if $type eq 'word';
|
||||||
@ -126,6 +128,7 @@ sub define_word
|
|||||||
print "$comma" unless $number == 1;
|
print "$comma" unless $number == 1;
|
||||||
print "$number) $defs->{$type}{$number}";
|
print "$number) $defs->{$type}{$number}";
|
||||||
$comma = ",\n\n";
|
$comma = ",\n\n";
|
||||||
|
$defined = 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
@ -134,6 +137,23 @@ sub define_word
|
|||||||
print "Error in -t parameter. Use v, n, *, etc.\n";
|
print "Error in -t parameter. Use v, n, *, etc.\n";
|
||||||
exit 0;
|
exit 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (not $defined && $def_type ne '*') {
|
||||||
|
my $types = '';
|
||||||
|
$comma = '';
|
||||||
|
foreach my $type (sort keys %$defs) {
|
||||||
|
next if $type eq 'word';
|
||||||
|
$types .= "$comma$type";
|
||||||
|
$comma = ', ';
|
||||||
|
}
|
||||||
|
if (length $types) {
|
||||||
|
print "no `$def_type` definition found; available definitions: $types.\n";
|
||||||
|
} else {
|
||||||
|
print "no definition found.\n";
|
||||||
|
}
|
||||||
|
} elsif (not $defined) {
|
||||||
|
print "no definition found.\n";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -155,7 +175,7 @@ sub dict_hash {
|
|||||||
$line =~ s/\s+$//;
|
$line =~ s/\s+$//;
|
||||||
$line =~ s/\s+/ /g;
|
$line =~ s/\s+/ /g;
|
||||||
|
|
||||||
if($line =~ m/^([a-z]) (\d+): (.*)/i) {
|
if($line =~ m/^([a-z]+) (\d+): (.*)/i) {
|
||||||
($type, $number, $text) = ($1, $2, $3);
|
($type, $number, $text) = ($1, $2, $3);
|
||||||
}
|
}
|
||||||
elsif($line =~ m/^(\d+): (.*)/i) {
|
elsif($line =~ m/^(\d+): (.*)/i) {
|
||||||
@ -354,7 +374,7 @@ sub initialise
|
|||||||
=cut
|
=cut
|
||||||
|
|
||||||
if(not $config->args(\@ARGV)) {
|
if(not $config->args(\@ARGV)) {
|
||||||
print "Usage : dict [-d database] [-n start from definition number] [-t first letter of word class type (n]oun, v]erb, etc)] [-search <regex> for definitions matching <regex>] <word>\n";
|
print "Usage : dict [-d database] [-n start from definition number] [-t abbreviation of word class type (n]oun, v]erb, adv]erb, adj]ective, etc)] [-search <regex> for definitions matching <regex>] <word>\n";
|
||||||
exit;
|
exit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user