-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathanin.pl
99 lines (83 loc) · 2.37 KB
/
anin.pl
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
############################################
#anin.pl
#checks for anagrams
#
#largely superseded by gq.bat/gr.bat/gq.pl
use strict;
use warnings;
my @matches = split(/,/, @ARGV[0]);
my $found = 0;
my @files = ( "c:/games/inform/roiling.inform/source/story.ni", "c:/games/inform/shuffling.inform/source/story.ni",
"c:/Program Files (x86)/Inform 7/Inform7/Extensions/Andrew Schultz/Roiling Random Text.i7x",
"c:/Program Files (x86)/Inform 7/Inform7/Extensions/Andrew Schultz/Shuffling Random Text.i7x",
"c:/Program Files (x86)/Inform 7/Inform7/Extensions/Andrew Schultz/Roiling Nudges.i7x",
"c:/Program Files (x86)/Inform 7/Inform7/Extensions/Andrew Schultz/Shuffling Nudges.i7x" );
my $match;
my $curFile;
my $localFound;
for $match (@matches)
{
for $curFile (@files)
{
$localFound = 0;
pokeSource($curFile, $match);
}
}
if (!$found) { print "$match doesn't have any matches!\n"; }
sub pokeSource
{
open(A, "$_[0]") || die ("No $_[0]");
while ($a = <A>)
{
if ($a !~ /[a-z]/i) { next; }
chomp($a);
if (lineMatch($_[1], $a)) { print "$a\n"; }
}
close(A);
}
##################################
#arg 0 = string to match
#arg 1 = the line
sub lineMatch
{
my $tempLine = lc($_[1]); $tempLine =~ s/^[^a-z]+//gi;
my @b = split(/[^a-z']+/i, $tempLine);
my $ss = lc($_[0]);
my $searchLength = length($ss);
my $startIndex = 0;
my $endIndex = 0;
my $stringInLine = @b[0];
my $ll;
while (($startIndex <= $#b) && ($endIndex <= $#b))
{
$ll = length($stringInLine);
#print "$stringInLine($ll) vs $ss($searchLength)\n";
if ($ll < $searchLength)
{
#print "Adding to end\n";
$endIndex++; $stringInLine .= @b[$endIndex]; next;
}
if ($ll > $searchLength)
{
my $blen = length(@b[$startIndex]);
#print "Zapping $blen from start\n";
$stringInLine = substr($stringInLine, $blen, length($stringInLine) - $blen); $startIndex++; next;
}
if (checkAna($ss, $stringInLine))
{
if (!$localFound) { print "$curFile finds: =================\n"; $localFound = 1; }
$found = 1;
print "$ss ($startIndex, $endIndex) ";
print join(" ", @b[$startIndex..$endIndex]);
print " matches line $.======\n$_[1]\n";
}
$endIndex++; $stringInLine .= @b[$endIndex];
}
}
sub checkAna
{
my $x1 = join("", sort(split(//, $_[0])));
my $x2 = join("", sort(split(//, $_[1])));
if ($x1 ne $x2) { return 0; }
return 1;
}