]> git.donarmstrong.com Git - bin.git/blobdiff - anamang
* add tex-only optino
[bin.git] / anamang
diff --git a/anamang b/anamang
index 54cd32b98a916284f94f11347d5dca9c58b86d62..aa7a006a87bf29562390f3baa6ed4bfc9fa74db1 100755 (executable)
--- a/anamang
+++ b/anamang
@@ -119,13 +119,12 @@ if (not @words) {
     exit 1;
 }
 
-my $database = update_and_load_database($options{database_dir},$options{wordlist});
-
 # letter order
 my @l_o = ('a'..'z');
 my %l_o;
 @l_o{@l_o} = (0 .. 25);
 
+my $database = update_and_load_database($options{database_dir},$options{wordlist});
 
 # run through and use the database
 
@@ -144,21 +143,22 @@ if ($options{acrostic}) {
            print STDERR "Only showing 200 of the " . @allowable_words . " possible words\n";
            @allowable_words = @allowable_words[0..199];
        }
-       while ((@allowable_words == 0 or $options{multiword}) and
-              (@allowable_words < 200 or $options{show_all})
-             ) {
-           # try for multiple word solutions, start with the longest
-           # words possible
-
-           # try to split the number of known letters in half, and
-           # start increasing and decreasing in both directions
-
-           # don't attempt to split each part into bits unless there
-           # are no solutions
-
-           # avoid searching for words when we only have a length and
-           # no position information
-       }
+       # multiword currently not enabled
+       # while ((@allowable_words == 0 or $options{multiword}) and
+       #        (@allowable_words < 200 or $options{show_all})
+       #       ) {
+       #     # try for multiple word solutions, start with the longest
+       #     # words possible
+       # 
+       #     # try to split the number of known letters in half, and
+       #     # start increasing and decreasing in both directions
+       # 
+       #     # don't attempt to split each part into bits unless there
+       #     # are no solutions
+       # 
+       #     # avoid searching for words when we only have a length and
+       #     # no position information
+       # }
        print map {$_,qq(\n)} sort @allowable_words;
     }
 }
@@ -235,6 +235,7 @@ sub find_allowable_words {
 sub update_and_load_database {
     my ($dir,$wordlist) = @_;
     # check to see if the wordlist is newer than our database
+    my @dbs = qw(length position substitution rotation anagram);
     my $update_required = 0;
     my $wordlist_time = 1;
     if (! -r $wordlist) {
@@ -242,7 +243,7 @@ sub update_and_load_database {
     }
     my $wordlist_stat = stat($wordlist);
     $wordlist_time = max($wordlist_time,$wordlist_stat->mtime);
-    for my $db (qw(length position)) {
+    for my $db (@dbs) {
        if (! -e "$dir/db_${db}") {
            $update_required = 1;
        }
@@ -256,7 +257,7 @@ sub update_and_load_database {
        if (not -d "$dir") {
            mkdir($dir) or die "Unable to create directory $dir: $!";
        }
-       for my $db (qw(length position substitution rotation anagram)) {
+       for my $db (@dbs) {
            $database->{$db} = {};
            $disk_db->{$db} = {};
            tie %{$disk_db->{$db}}, MLDBM => "$dir/db_${db}",
@@ -270,10 +271,12 @@ sub update_and_load_database {
            chomp;
            next unless length $_;
            my $word = lc($_);
+           $word =~ s/[^a-z]//;
+           next unless length $_;
            next if exists $seen_words{$word};
            $seen_words{$word} = 1;
            if ((keys %seen_words) % 100 == 0) {
-               print STDERR "Handled ".(keys %seen_words) . "words, on $word\n";
+               print STDERR "Handled ".(keys %seen_words) . " words, on $word\n";
            }
            my @l = split //, $word;
            my $l = length($word);
@@ -316,6 +319,9 @@ sub update_and_load_database {
            # in it, hello becomes axeeh, giddy acxxs
            my $fl = $l[0];
            my $index = $l_o{$fl};
+           if (not defined $index or grep {not exists $l_o{$_}} @l) {
+               print STDERR "Problem with some letters in '$word'\n";
+           }
            $mapped_word = join('',map {$l_o[($l_o{$_} - $index + 26) % 26]} @l);
            $temp = $database->{rotation}{$mapped_word};
            $temp = [] if not defined $temp;
@@ -337,7 +343,7 @@ sub update_and_load_database {
        }
     }
     else {
-       for my $db (qw(length position)) {
+       for my $db (@dbs) {
            $database->{$db} = {};
            tie %{$database->{$db}}, MLDBM => "$dir/db_${db}",
                O_RDONLY, 0666