|
| 1 | +#!/usr/bin/perl |
| 2 | +#require 'globals_API.pl'; |
| 3 | +#require 'globals.pl'; |
| 4 | + |
| 5 | + |
| 6 | +# CURRENT BUGS |
| 7 | +# Making a line with \t\tblank |
| 8 | +# fixed: [] array access symbols are not appearing |
| 9 | +# ??? there are overlaps when methods are included (blend() and image.blend()) |
| 10 | + |
| 11 | + |
| 12 | +#$dir = "API"; |
| 13 | +$dir = "../content/api_en/"; |
| 14 | +# This path is for the configuration on Casey's local machine |
| 15 | +$path = "../../processing/build/shared/lib/"; |
| 16 | + |
| 17 | +# Open base file and copy into array |
| 18 | +open (BASE, "keywords_base.txt") || die "can't open keywords_base.txt: $!"; |
| 19 | +@baseinfo = <BASE>; |
| 20 | +close(BASE); |
| 21 | +chomp(@baseinfo); |
| 22 | + |
| 23 | +foreach $bi (@baseinfo) { |
| 24 | + push(@modfiles, $bi) |
| 25 | +} |
| 26 | + |
| 27 | +# Add a blank line to separate the data |
| 28 | +push(@modfiles, "\n"); |
| 29 | + |
| 30 | +opendir(DIR, $dir) || die $!; |
| 31 | +@tempfiles = readdir(DIR); |
| 32 | +closedir(DIR); |
| 33 | + |
| 34 | +foreach $temp (@tempfiles) { |
| 35 | + if($temp =~ ".xml" && !($temp =~ "~")) { |
| 36 | + get_data("$temp"); |
| 37 | + if(strip_name($name) ne "") { |
| 38 | + push(@modfiles, strip_name($name) . "\t" . set_category() . "\t" . file_name_convert($temp)); |
| 39 | + } |
| 40 | + } |
| 41 | + } |
| 42 | + |
| 43 | + |
| 44 | +open(KEYWORDS, ">$path/keywords.txt"); |
| 45 | + |
| 46 | +foreach $temp (@modfiles) { |
| 47 | + # Add additional API to file |
| 48 | + print KEYWORDS "$temp\n"; |
| 49 | + print "$temp\n"; |
| 50 | +} |
| 51 | + |
| 52 | +close(KEYWORDS); |
| 53 | + |
| 54 | + |
| 55 | + |
| 56 | + |
| 57 | + |
| 58 | +sub get_data |
| 59 | +{ |
| 60 | + open (CAT, "$dir/$_[0]") || die "can't open $_[0]: $!"; |
| 61 | + @cat = ""; |
| 62 | + while (<CAT>) { |
| 63 | + chomp; |
| 64 | + push(@cat, $_); |
| 65 | + #print "$_\n"; |
| 66 | + } |
| 67 | + close CAT; |
| 68 | + foreach $el (@cat) { |
| 69 | + if(grep{/^<type>/} $el) { |
| 70 | + $type_cat = $el; |
| 71 | + $type_cat =~ s/<type>//; |
| 72 | + $type_cat =~ s/<\/type>//; |
| 73 | + } |
| 74 | + if(grep{/^<name>/} $el) { |
| 75 | + $name_cat = $el; |
| 76 | + $name_cat =~ s/<name>//; |
| 77 | + $name_cat =~ s/<\/name>//; |
| 78 | + } |
| 79 | + } |
| 80 | + $type = $type_cat; |
| 81 | + $name = $name_cat; |
| 82 | +} |
| 83 | + |
| 84 | +sub strip_name |
| 85 | +{ |
| 86 | + local ($page) = @_[0]; |
| 87 | + |
| 88 | + # Exceptions for constants with PI |
| 89 | + if($page =~ /PI/) { |
| 90 | + $_ = $page; |
| 91 | + $page =~ s/\(.*\)//g; # Remove all between parenthesis |
| 92 | + $page =~ s/\s//g; # Remove the spaces |
| 93 | + #print("$page\n"); |
| 94 | + } |
| 95 | + |
| 96 | + $_ = $page; |
| 97 | + if(!($page =~ s/\(\)//g)) # Truncate all functions |
| 98 | + { |
| 99 | + # Exception for the case of pixels[] and vpixels[] |
| 100 | + if(/pixels\[\]/) { |
| 101 | + $page =~ s/\[\]//g; |
| 102 | + } |
| 103 | + |
| 104 | + # Exception for the case of all operators |
| 105 | + if(/\(.*\)/) { |
| 106 | + #$page = $&; |
| 107 | + $tp = $&; # Get the entire match |
| 108 | + $page =~ s/$tp//g; # Remove the entire match |
| 109 | + $page =~ s/\(//g; # Remove the left paren |
| 110 | + $page =~ s/\)//g; # Remove the right paren |
| 111 | + } |
| 112 | + } |
| 113 | + |
| 114 | + # Exception for the case of () (parenthesis) |
| 115 | + if($page =~ /paren/) { |
| 116 | + #$tp = $&; # Get the entire match |
| 117 | + $page =~ s/\(.*\)/()/g; # Remove the entire match |
| 118 | + } |
| 119 | + |
| 120 | + $page =~ s/\s//g; # Remove the spaces |
| 121 | + $page =~ s/\</\</g; # Replace < |
| 122 | + $page =~ s/\>/\</g; # Replace > |
| 123 | + $page =~ s/\&/\&/g; # Replace & |
| 124 | + $page =~ s/\*\///g; # Replace */ |
| 125 | + |
| 126 | + |
| 127 | + return $page; |
| 128 | +} |
| 129 | + |
| 130 | +sub set_category |
| 131 | +{ |
| 132 | + if($type =~ s/constant/constant/i) { |
| 133 | + $category = "LITERAL1"; |
| 134 | + } elsif ($type =~ s/variable/variable/i || $type =~ s/field/field/i ) { |
| 135 | + $category = "LITERAL2"; |
| 136 | + } elsif ($type =~ s/datatype/datatype/i || $type =~ s/structure/structure/i || |
| 137 | + $type =~ s/keyword/keyword/i || $type =~ s/object/object/i ) { |
| 138 | + $category = "KEYWORD1"; |
| 139 | + } elsif ($type =~ s/function/method/i || $type =~ s/method/method/i ) { |
| 140 | + $category = "KEYWORD2"; |
| 141 | + } else { |
| 142 | + $category = ""; |
| 143 | + } |
| 144 | + |
| 145 | + if($type =~ s/processing//i) { |
| 146 | + $category = "KEYWORD3"; |
| 147 | + } |
| 148 | + |
| 149 | + return $category; |
| 150 | +} |
| 151 | + |
| 152 | +sub file_name_convert |
| 153 | +{ |
| 154 | + local ($thisfile) = @_[0]; |
| 155 | + |
| 156 | + # Remove the "xml" from the files |
| 157 | + $thisfile =~ s/\.xml//; |
| 158 | + |
| 159 | + # Remove the "converts" from the xml files |
| 160 | + $thisfile =~ s/convert//; |
| 161 | + |
| 162 | + # Remove the "_var" from the xml files |
| 163 | + $thisfile =~ s/_var//; |
| 164 | + if(($type =~ /function/i) || ($type =~ /structure/i) ||($type =~ /method/i)) { |
| 165 | + $thisfile = $thisfile . "_"; |
| 166 | + } |
| 167 | + |
| 168 | + return $thisfile; |
| 169 | +} |
0 commit comments