This repository has been archived by the owner on Apr 27, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 22
/
wiki_builtins.pl
executable file
·184 lines (145 loc) · 4.01 KB
/
wiki_builtins.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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/usr/bin/perl
# Usage: builtins_wiki.pl > builtins.txt
# a list of seed URLs
my %urls = (
"http://wiki.secondlife.com/wiki/Category:LSL_Functions" => "",
"http://wiki.secondlife.com/wiki/Category:LSL_Events" => "",
"http://wiki.secondlife.com/wiki/Category:LSL_Constants" => ""
);
sub do_function($) {
my $signature = shift(@_);
$signature =~ s/^[ ]*//g;
$signature =~ s/^function //g;
my @x = split / /, $signature;
if ($x[0] ne lc($x[0])) {
$signature = "void $signature";
}
$functions{"$signature\n"} = 1;
print STDERR "#F# $signature\n";
}
sub do_constant($) {
my $signature = shift(@_);
$signature =~ s/^[ ]*//g;
$signature = "const $signature";
$constants{"$signature\n"} = 1;
print STDERR "#C# $signature\n";
}
sub do_event($) {
my $signature = shift(@_);
$signature =~ s/^[ ]*//g;
$signature =~ s/^event void /event /g;
$events{"$signature\n"} = 1;
print STDERR "#E# $signature\n";
}
sub parse_signature($) {
my $signature = shift(@_);
# generic cleanup
$signature =~ s/\/\/.*//g; # remove comments
$signature =~ s/;.*//g; # remove semicolons
$signature =~ s/^\s*//g; # leading whitespace
$signature =~ s/\s*$//g; # trailing whitespace
if ($signature =~ /^event /) {
do_event($signature);
}
elsif ($signature =~ /^function /) {
do_function($signature);
}
elsif (length($signature)) {
do_constant($signature);
}
}
sub do_signature($) {
my $signature = shift(@_);
#print STDERR "|||$signature|||";
# common HTML escapes
$signature =~ s/</</g;
$signature =~ s/>/>/g;
$signature =~ s/"/"/g;
$signature =~ s/&/&/g;
# stupid stuff, errors in wiki templates?
$signature =~ s/<span[^>]*>//g;
$signature =~ s/<.span>//g;
foreach my $sig (split /\n/, $signature) {
parse_signature($sig);
}
}
# try each one gather new ones and try them too.
my $counter = 0;
my $changed = 1;
sub queue($) {
my $url = shift(@_);
if ($url =~ /^\//) {
$url = "http://wiki.secondlife.com$url";
}
$url =~ s/\&/\&/g;
# stay on site
if (!($url =~ /wiki.secondlife.com/)) {
return;
}
if (!defined($urls{$url})) {
$urls{$url} = "";
$changed = 1;
}
}
while ($changed) {
$changed = 0;
foreach $key (keys(%urls)) {
if (length($urls{$key}) == 0) {
$changed = 1;
$counter++;
@keylist = keys(%urls);
push @keylist, ""; # kludge to bump up keylist counter
print STDERR "$counter/$#keylist $key\n";
open FILE, "wget \"$key\" -O - 2>/dev/null |";
$urls{$key} = join("", <FILE>);
close FILE;
# look for a "next 200" link
$tmp = $urls{$key};
$tmp =~ s/<a href=\"([^"]*)\"[^>]*>next 200/queue($1)/gem;
# look for links in lists
$tmp = $urls{$key};
$tmp =~ s/<li><a href=\"([^"]*)\"/queue($1)/gem;
# look for functions, constants, and events
$tmp = $urls{$key};
$tmp =~ s/lsl-signature[^>]*>([^<]*)/do_signature($1)/gem;
$tmp =~ s/<[^>]*>//g;
$tmp =~ s/</</g;
$tmp =~ s/>/>/g;
$tmp =~ s/"/"/g;
# free up some memory
$urls{$key} = "*COMPLETE*";
}
}
}
sub byname {
$ta = $a;
$tb = $b;
$ta =~ s/^const //g;
$ta =~ s/^event //g;
$ta =~ s/^function //g;
$ta =~ s/^integer //g;
$ta =~ s/^float //g;
$ta =~ s/^string //g;
$ta =~ s/^vector //g;
$ta =~ s/^void //g;
$ta =~ s/^rotation //g;
$ta =~ s/^quaternion //g;
$ta =~ s/^list //g;
$ta =~ s/^key //g;
$tb =~ s/^const //g;
$tb =~ s/^event //g;
$tb =~ s/^function //g;
$tb =~ s/^integer //g;
$tb =~ s/^float //g;
$tb =~ s/^string //g;
$tb =~ s/^vector //g;
$tb =~ s/^void //g;
$tb =~ s/^rotation //g;
$tb =~ s/^quaternion //g;
$tb =~ s/^list //g;
$tb =~ s/^key //g;
$ta cmp $tb;
}
print sort byname keys(%functions);
print sort byname keys(%constants);
print sort byname keys(%events);