-
-
Notifications
You must be signed in to change notification settings - Fork 173
Expand file tree
/
Copy pathkeywords_create.cgi
More file actions
executable file
·210 lines (173 loc) · 5.21 KB
/
keywords_create.cgi
File metadata and controls
executable file
·210 lines (173 loc) · 5.21 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
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
#!/usr/bin/perl
#require 'globals_API.pl';
#require 'globals.pl';
# KEY 2.0b7+
# LITERAL2 - Constants (QUARTER_PI, CORNERS, etc.)
# KEYWORD1 - Java datatypes and keywords (void, int, boolean, etc.)
# KEYWORD2 - Fields [variables within a class]
# KEYWORD3 - Processing variables (width, height, focused, etc.)
# FUNCTION1 - Functions
# FUNCTION2 - Methods (functions inside a class)
$dir = "../content/api_en/";
#$path = "../../processing/build/shared/lib/";
$path = "../../processing/java/";
# Open base file and copy into array
open (BASE, "keywords_base.txt") || die "can't open keywords_base.txt: $!";
@baseinfo = <BASE>;
close(BASE);
chomp(@baseinfo);
foreach $bi (@baseinfo) {
push(@modfiles, $bi)
}
# Add a blank line to separate the data
push(@modfiles, "\n");
opendir(DIR, $dir) || die $!;
@tempfiles = readdir(DIR);
closedir(DIR);
foreach $temp (@tempfiles) {
if($temp =~ ".xml" && !($temp =~ "~")) {
get_data("$temp");
$tempname = strip_name($name);
# 29 Nov. Because the PDE can't differentiate between variables inside a class
# or the main Processing variables, we leave these out of the generated reference
if ($tempname ne "x" && $tempname ne "y" && $tempname ne "z" &&
$tempname ne "width" && $tempname ne "height" && $tempname ne "") {
push(@modfiles, strip_name($name) . "\t" . set_category() . "\t" . file_name_convert($temp));
}
}
}
open(KEYWORDS, ">$path/keywords.txt");
foreach $temp (@modfiles) {
# Add additional API to file
print KEYWORDS "$temp\n";
print "$temp\n";
}
close(KEYWORDS);
sub get_data
{
open (CAT, "$dir/$_[0]") || die "can't open $_[0]: $!";
@cat = "";
while (<CAT>) {
chomp;
push(@cat, $_);
#print "$_\n";
}
close CAT;
foreach $el (@cat) {
#$type_cat = "";
if(grep{/^<type>/} $el) {
$type_cat = $el;
$type_cat =~ s/<type>//;
$type_cat =~ s/<\/type>//;
}
if(grep{/^<name>/} $el) {
$name_cat = $el;
$name_cat =~ s/<name>//;
$name_cat =~ s/<\/name>//;
}
if(grep{/^<category>/} $el) {
$category = $el;
$category =~ s/<category>//;
$category =~ s/<\/category>//;
}
if(grep{/^<subcategory>/} $el) {
$type_subcat = $el;
$type_subcat =~ s/<subcategory>//;
$type_subcat =~ s/<\/subcategory>//;
}
}
$type = $type_cat;
$name = $name_cat;
$subcat = $type_subcat;
$cat = $category;
}
sub strip_name
{
local ($page) = @_[0];
# Exceptions for constants with PI
if($page =~ /PI/) {
$_ = $page;
$page =~ s/\(.*\)//g; # Remove all between parenthesis
$page =~ s/\s//g; # Remove the spaces
#print("$page\n");
}
$_ = $page;
if(!($page =~ s/\(\)//g)) # Truncate all functions
{
# Exception for the case of pixels[] and vpixels[]
if(/pixels\[\]/) {
$page =~ s/\[\]//g;
}
# Exception for the case of all operators
if(/\(.*\)/) {
#$page = $&;
$tp = $&; # Get the entire match
$page =~ s/$tp//g; # Remove the entire match
$page =~ s/\(//g; # Remove the left paren
$page =~ s/\)//g; # Remove the right paren
}
}
# Exception for the case of () (parenthesis)
if($page =~ /paren/) {
#$tp = $&; # Get the entire match
$page =~ s/\(.*\)/()/g; # Remove the entire match
}
$page =~ s/\s//g; # Remove the spaces
$page =~ s/\</\</g; # Replace <
$page =~ s/\>/\</g; # Replace >
$page =~ s/\&/\&/g; # Replace &
$page =~ s/\*\///g; # Replace */
return $page;
}
sub set_category
{
# Set the default
$category = "FUNCTION1";
#if ($name eq $subcat) {
# $category = "KEYWORD1";
#} elsif($subcat =~ s/method/method/i) {
# $category = "FUNCTION2";
#} elsif($subcat =~ s/field/field/i) {
# $category = "KEYWORD2";
#} elsif($cat =~ s/constants/constants/i) {
# $category = "LITERAL2";
#} elsif ($type eq "variable") {
# $category = "KEYWORD3";
#}
$lc_type = lc($type);
if ($subcat =~ s/method/method/i) {
$category = "FUNCTION2";
} elsif($name eq $subcat) {
$category = "KEYWORD5";
} elsif($subcat =~ s/field/field/i) {
$category = "KEYWORD2";
} elsif($type eq "p5function") {
$category = "FUNCTION4";
} elsif($type eq "variable") {
$category = "KEYWORD4";
} elsif(($lc_type eq "object") || ($lc_type eq "class")) {
$category = "KEYWORD5";
} elsif ($cat =~ s/constants/constants/i) {
$category = "LITERAL2";
}
return $category;
}
sub file_name_convert
{
local ($thisfile) = @_[0];
# Remove the "xml" from the files
$thisfile =~ s/\.xml//;
# Remove the "converts" from the xml files
$thisfile =~ s/convert//;
# Remove the "_var" from the xml files
$thisfile =~ s/_var//;
# Add an "_" if the reference is a function, structure, or method
# 27 NOV 2011, this no longer works do to changes in the XML structure
#if(($type =~ /function/i) || ($type =~ /structure/i) ||($type =~ /method/i)) {
# $thisfile = $thisfile . "_";
#}
if(($category =~ /FUNCTION1/i) || ($category =~ /FUNCTION2/i)) {
$thisfile = $thisfile . "_";
}
return $thisfile;
}