-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnud.pl
159 lines (145 loc) · 3.79 KB
/
nud.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
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
#######################################
#nud.pl
#sorts the nudge file "say"s by the order they appear in the table
#
#
use warnings;
use strict;
#functions below here
my $sizeMatters = 1;
my %full;
my %outs;
nudgesort("roiling");
nudgesort("shuffling");
sub nudgesort {
%full = ();
%outs = ();
my $inNudge = 0;
my $nudgeEnded = 0;
my $idx = 0;
my $veryEnd = 0;
my @bigAry;
my @prefix;
my $lastString;
my $fileName =
"c:/Program Files (x86)/Inform 7/Inform7/Extensions/Andrew Schultz/$_[0] nudges.i7x";
my $tempFile =
"c:/Program Files (x86)/Inform 7/Inform7/Extensions/Andrew Schultz/temp.i7x";
open( A, "$fileName" ) || die("$fileName not available.");
open( B, ">$tempFile" );
my $a;
while ( $a = <A> ) {
if ( ( $a =~ /ends here\.$/ )
|| ( $a =~ /^section support/ )
|| ($veryEnd) )
{
$veryEnd = 1;
$lastString .= $a;
next;
}
if ( $a =~ /^section/ ) { <A>; next; }
if ( $nudgeEnded == 0 ) { print B $a; }
else {
my $header = $a;
chomp($header);
$header =~ s/:.*//g;
if ( $header =~ / of \(/ ) { $header =~ s/ of \(.*/ of/g; }
if ( !$outs{$header} ) { print "$header doesn't match with table.\n"; }
else {
#print "Got $outs{$header}\n";
}
while ( ( $b = <A> ) =~ /[a-z]/ ) { $a .= $b; }
$full{$header} = "$a\n";
#print "$header -> $a";
next;
}
if ( $a =~ /^table of [a-z]+ nudges/i ) {
$inNudge = 1;
$a = <A>;
print B $a;
next;
}
if ( $a =~ /^book text details/ ) {
$nudgeEnded = 1;
$a = <A>;
print B $a;
next;
}
if ($inNudge) {
if ( $a !~ /[a-z]/ ) { $inNudge = 0; next; }
chomp($a);
my @ary = split( /\t/, $a );
if ( $#ary < 6 ) { print "@ary too few args\n"; next; }
my $quo = $ary[6];
$quo =~ s/\[if [^\]]*\]//g;
$quo =~ s/\[else .*\]//g;
$quo =~ s/\[unless .*\]//g;
$quo =~ s/\[else\]//g;
$quo =~ s/\[end if\]//g;
$quo =~ s/\[one of\]//g;
$quo =~ s/\[or\]//g;
$quo =~ s/\[stopping\]//g;
$quo =~ s/^\"//g;
$quo =~ s/\".*//g;
if ( $quo =~ /\[/ ) {
$quo =~ s/.*\[(.*)\].*/$1/g;
$quo = "to say $quo";
if ( $quo =~ / of / ) {
$quo =~ s/ of .*/ of/g; #print "OF: $quo\n";
}
if ( !$outs{$quo} ) {
$idx++;
$outs{$quo} = $idx;
@bigAry[$idx] = $quo;
}
#print "$quo => $idx\n";
}
my $rul = $ary[5];
if ( $rul =~ /[a-z]/ ) {
$rul = "this is the $rul";
if ( !$outs{$rul} ) {
$idx++;
$outs{$rul} = $idx;
@bigAry[$idx] = $rul;
}
}
if ( $#ary >= 7 ) {
my $chap = $ary[7];
$chap =~ s/[\[\]]//g;
chomp($chap);
$chap = "section $chap\n\n";
@prefix[$idx] = "$chap";
}
}
}
for my $q ( 1 .. $idx ) {
if ( !defined( $full{ $bigAry[$q] } ) ) {
print "WARNING $bigAry[$q] may be defined elsehwere\n";
}
else {
if ( defined( $prefix[$q] ) ) { print B "$prefix[$q]"; }
print B $full{ $bigAry[$q] };
}
#print "after\n";
}
print B $lastString;
close(B);
close(A);
print "$sizeMatters " . ( -s $tempFile ) . " " . ( -s $fileName );
if ( ( !$sizeMatters ) || ( -s "$tempFile" == -s "$fileName" ) ) {
my $cmd = "copy \"$tempFile\" \"$fileName\"";
$cmd =~ s/\//\\/g;
print "Copying back to $fileName...\n$cmd\n";
#`$cmd`;
$cmd = "erase \"$tempFile\"";
$cmd =~ s/\//\\/g;
print "Erasing $tempFile...\n$cmd\n";
#`$cmd`;
}
else {
print "Didn't copy $tempFile to $fileName file over--file size difference("
. ( -s "$tempFile" ) . " vs "
. ( -s "$fileName" ) . ").\n";
`wm "$tempFile" "$fileName"`;
}
}