-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmaplint.pl
More file actions
160 lines (123 loc) · 2.93 KB
/
Copy pathmaplint.pl
File metadata and controls
160 lines (123 loc) · 2.93 KB
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
160
#!/usr/bin/perl -w
# Load up modules
use strict;
# Check to make sure that a room file actually is valid
my %rooms = ();
my $state = 0; # Indicator of the current state of the parser
my $counter = 0;
my $roominfo = undef;
my $roomname = "";
my $roomtext = "";
my $exits = [];
my @errors = ();
# Statistical
my $totalrooms = 0;
my $bytesize = 0;
# Parse through the room files and seperate it out into rooms, and links
# to rooms...
&credits();
print "Processing the rooms file:";
while (<>) {
chomp;
my $line = $_; # Get a real variable to work with
$bytesize+=length($line);
$counter++;
if ($state == 0) { # Expect a #, start of a new room
if ($line =~ /^#$/) {
print ".";
$state = 1;
$roominfo = {}; # build a new anonymous array
$roomtext = "";
$exits = [];
next;
}
push @errors,"File format error on line $counter of $ARGV.";
last;
}
if ($state == 1) { # Room name
$roomname = "main.$line";
if ($line =~ /^#$/) {
push @errors,"Bogus room name \"#\" at $counter of $ARGV.";
next;
}
if (exists $rooms{$roomname}) {
push @errors,"Duplicate room warning on line $counter of $ARGV. The Original at line ".$rooms{$roomname}->{line}.".\n";
}
$rooms{$roomname}=$roominfo;
$rooms{$roomname}->{name}=$roomname;
$rooms{$roomname}->{line}=$counter;
$state=2;
next;
}
if ($state == 2) { # where message
$rooms{$roomname}->{where}=$line;
$state=3;
next;
}
if ($state == 3) {
$rooms{$roomname}->{entermsg}=$line;
$state = 4;
next;
}
if ($state == 4) {
if ($line =~ /^#$/) {
$state = 5;
$rooms{$roomname}->{text}=$roomtext;
next;
}
$roomtext.=$line;
next;
}
if ($state == 5) {
if ($line =~ /^end$/) {
$state = 6;
$rooms{$roomname}->{exits}=$exits;
next;
}
push @$exits,$line;
next;
}
if ($state == 6) {
if ($line =~ /^end$/) {
$state = 0;
$totalrooms++;
next;
}
}
}
# Next level of postprocessing
for my $each_room (sort keys %rooms) {
my @exits = @{$rooms{$each_room}->{exits}};
push (@errors, "Orphan room $each_room") if (scalar @exits == 0);
for my $test_room (@exits) {
push (@errors, "Bogus room link $test_room in $each_room") unless (exists $rooms{$test_room});
}
}
# Display information about the rooms
print "\n\n";
print join "\n",@errors;
print "\n\n";
statistics();
# Subroutines
sub credits {
print "\nMaplint (C) 2001 Gary Coulbourne (bear\@bears.org)\n";
print " Playground+ rooms file linting program\n";
print "This program is licensed under the terms of the GPL\n";
print " --=* *=--\n\n";
}
sub statistics {
print "\n";
print "Statistics\n";
print "----------\n";
print "Total number of lines : $counter\n";
print "Total number of characters : $bytesize\n";
print "Total number of rooms : $totalrooms\n";
print "\n";
}
sub xml_header {
print "<?xml?>\n";
print "<sets>\n";
}
sub xml_footer {
print "</sets>\n";
}