source: josm/trunk/geticons.pl@ 2841

Last change on this file since 2841 was 2811, checked in by stoecker, 14 years ago

fixed image recognition script

  • Property svn:executable set to *
File size: 3.9 KB
Line 
1#! /usr/bin/perl -w
2# short tool to find out all used icons and allows deleting unused icons
3# when building release files
4
5my @default = (
6 "styles/standard/*.xml",
7 "presets/*.xml",
8 "src/org/openstreetmap/josm/*.java",
9 "src/org/openstreetmap/josm/*/*.java",
10 "src/org/openstreetmap/josm/*/*/*.java",
11 "src/org/openstreetmap/josm/*/*/*/*.java",
12 "src/org/openstreetmap/josm/*/*/*/*/*.java",
13 "src/org/openstreetmap/josm/*/*/*/*/*/*.java"
14);
15
16my %icons;
17
18my $o = $/;
19
20for my $arg (@ARGV ? @ARGV : @default)
21{
22 for my $file (glob($arg))
23 {
24 open(FILE,"<",$file) or die "Could not open $file\n";
25 #print "Read file $file\n";
26 $/ = $file =~ /\.java$/ ? ";" : $o;
27 my $extends = "";
28 while(my $l = <FILE>)
29 {
30 if($l =~ /src\s*=\s*["'](.*?)["']/)
31 {
32 ++$icons{"styles/standard/$1"};
33 }
34 elsif($l =~ /icon\s*=\s*["'](.*?)["']/)
35 {
36 ++$icons{$1};
37 }
38
39 if($l =~ /ImageProvider\.get\(\"([^\"]*?)\"\)/)
40 {
41 my $i = $1;
42 $i .= ".png" if !($i =~ /\.png$/);
43 ++$icons{$i};
44 }
45 if($l =~ /new\s+ImageLabel\(\"(.*?)\"/)
46 {
47 my $i = "statusline/$1";
48 $i .= ".png" if !($i =~ /\.png$/);
49 ++$icons{$i};
50 }
51 if($l =~ /createPreferenceTab\(\"(.*?)\"/)
52 {
53 my $i = "preferences/$1";
54 $i .= ".png" if !($i =~ /\.png$/);
55 ++$icons{$i};
56 }
57 if($l =~ /ImageProvider\.get\(\"(.*?)\",\s*\"(.*?)\"\s*\)/)
58 {
59 my $i = "$1/$2";
60 $i .= ".png" if !($i =~ /\.png$/);
61 ++$icons{$i};
62 }
63 if($l =~ /ImageProvider\.overlay\(.*?,\s*\"(.*?)\",/)
64 {
65 my $i = $1;
66 $i .= ".png" if !($i =~ /\.png$/);
67 ++$icons{$i};
68 }
69 if($l =~ /getCursor\(\"(.*?)\",\s*\"(.*?)\"/)
70 {
71 my $i = "cursor/modifier/$2";
72 $i .= ".png" if !($i =~ /\.png$/);
73 ++$icons{$i};
74 $i = "cursor/$1";
75 $i .= ".png" if !($i =~ /\.png$/);
76 ++$icons{$i};
77 }
78 if($l =~ /ImageProvider\.getCursor\(\"(.*?)\",\s*null\)/)
79 {
80 my $i = "cursor/$1";
81 $i .= ".png" if !($i =~ /\.png$/);
82 ++$icons{$i};
83 }
84 if($l =~ /super\(\s*tr\(\".*?\"\),\s*\"(.*?)\"/s)
85 {
86 my $i = "$extends$1";
87 $i .= ".png" if !($i =~ /\.png$/);
88 ++$icons{$i};
89 }
90 if($l =~ /audiotracericon\",\s*\"(.*?)\"/s)
91 {
92 my $i = "markers/$1";
93 $i .= ".png" if !($i =~ /\.png$/);
94 ++$icons{$i};
95 }
96 if($l =~ /\"(.*?)\",\s*parentLayer/s)
97 {
98 my $i = "markers/$1";
99 $i .= ".png" if !($i =~ /\.png$/);
100 ++$icons{$i};
101 }
102 if($l =~ /allowedtypes\s+=.*\{(.*)\}/s)
103 {
104 my $t = $1;
105 while($t =~ /\"(.*?)\"/g)
106 {
107 ++$icons{"Mf_$1.png"};
108 }
109 }
110 if($l =~ /MODES\s+=.*\{(.*)\}/s)
111 {
112 my $t = $1;
113 while($t =~ /\"(.*?)\"/g)
114 {
115 ++$icons{"dialogs/autoscale/$1.png"};
116 }
117 }
118 if($l =~ /enum\s+DeleteMode\s*\{(.*)/s)
119 {
120 my $t = $1;
121 while($t =~ /\"(.*?)\"/g)
122 {
123 ++$icons{"cursor/modifier/$1.png"};
124 }
125 }
126 if($l =~ /\.setButtonIcons.*\{(.*)\}/)
127 {
128 my $t = $1;
129 while($t =~ /\"(.*?)\"/g)
130 {
131 my $i = $1;
132 $i .= ".png" if !($i =~ /\.png$/);
133 ++$icons{$i};
134 }
135 }
136 if($l =~ /extends MapMode/)
137 {
138 $extends = "mapmode/";
139 }
140 if($l =~ /extends ToggleDialog/)
141 {
142 $extends = "dialogs/";
143 }
144 }
145 close FILE;
146 }
147}
148
149my %haveicons;
150
151for($i = 0; my @ifiles = glob("images".("/*" x $i).".png"); ++$i)
152{
153 for my $ifile (sort @ifiles)
154 {
155 $ifile =~ s/^images\///;
156 $haveicons{$ifile} = 1;
157 }
158}
159
160for my $img (sort keys %icons)
161{
162 print STDERR "File $img does not exist!\n" if(!-f "images/$img");
163 delete $haveicons{$img};
164}
165
166for my $img (sort keys %haveicons)
167{
168 print "$img\n";
169}
Note: See TracBrowser for help on using the repository browser.