-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathaq.pl
109 lines (97 loc) · 2.51 KB
/
aq.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
###################################################################
#
#aq.pl
#
#deletes specific lines, usually gotten from a run of tsh
#
use strict;
use warnings;
my @temp = ();
my @lines = ();
my $game = "roiling";
##################variables
my $count = 0;
my $curLine = 0;
my $inString = "";
my $itemDeleted = 0;
##################options
my $deleteBracket = 0;
my $sortAuto = 0;
while ($count <= $#ARGV)
{
$a = $ARGV[$count];
if ($a =~ /^[0-9]/)
{
@temp = split(/,/, $a);
@lines = (@lines, @temp);
}
if ($a =~ /-s/) { $game = "shuffling"; }
if ($a =~ /-a/) { $sortAuto = 1; }
if ($a =~ /-d/) { $deleteBracket = 1; }
if ($a =~ /-x/) { $inString = "x"; }
$count++;
}
if ($#lines == -1) { print ("Nothing done.\n"); exit; }
my $lastLine = 0;
for (0..$#lines)
{
my $temp = $lines[$_]; $temp =~ s/d//g;
if (($temp < $lastLine) && (!$sortAuto)) { die("Out of numerical order at item " . ($_+1) . " or $lines[$_]. Use -a to sort."); }
$lastLine = $temp;
}
if ($sortAuto) { @lines = reverse(sort(@lines)); }
doLines();
if ($itemDeleted)
{
print "Re-running nightly since you deleted something\n";
`c:/writing/dict/nitely.pl -t ana`;
}
sub doLines
{
my $fileString = "c:/Program Files (x86)/Inform 7/Inform7/Extensions/Andrew Schultz/$game Random Text.i7x";
$fileString =~ s/\//\\/g;
print "Do lines " . join(",", @lines) . "\n";
open(A, "$fileString") || die ("No $fileString");
open(B, ">$fileString.bak");
binmode(B);
$curLine = $lines[0]; $curLine =~ s/[a-z]//g;
while ($a = <A>)
{
chomp($a);
if ($. == $curLine) { processLine(); } else { print B "$a\n"; }
}
close(A);
close(B);
if (! -f "$fileString.bak") { die; }
if (! -f "$fileString") { die; }
if (((-s "$fileString.bak") < (-s "$fileString")) && (!$deleteBracket) && (!$itemDeleted)) { die ("Oops, data got deleted.\n"); }
my $cmd = "xcopy /y /q \"$fileString.bak\" \"$fileString\"";
print "Copying over...\n$cmd\n";
my $output = `$cmd`;
print "$output";
}
sub processLine
{
if ($lines[0] =~ /d/) { print "Deleting line $..\n"; $itemDeleted = 1; return; }
if ($deleteBracket)
{
if ($a !~ / ?\[\]/) { print "Oops, no \[\].\n"; }
else
{ $a =~ s/ ?\[\]//i; }
print B "$a\n";
shift(@lines);
$curLine = $lines[0]; $curLine =~ s/[a-z]//g;
}
else
{
if ($a =~ / \[$inString\]/) { print "$lines[0] $a already commented\n"; print B "$a\n"; }
else
{
#print "$a \[$inString\]\n";
print B "$a \[$inString\]\n";
}
shift(@lines);
$curLine = $lines[0]; $curLine =~ s/[a-z]//g;
#print "@lines\n";
}
}