source: josm/trunk/geticons.pl@ 5218

Last change on this file since 5218 was 4172, checked in by stoecker, 13 years ago

remove unused icons, make connection timouts configurable and increase them a bit to handle JOSM server delays

  • Property svn:executable set to *
File size: 5.0 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 "styles/standard/*.mapcss",
8 "data/*.xml",
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 "src/org/openstreetmap/josm/*/*/*/*/*/*.java"
15);
16
17my %icons;
18
19my $o = $/;
20
21for my $arg (@ARGV ? @ARGV : @default)
22{
23 for my $file (glob($arg))
24 {
25 open(FILE,"<",$file) or die "Could not open $file\n";
26 #print "Read file $file\n";
27 $/ = $file =~ /\.java$/ ? ";" : $o;
28 my $extends = "";
29 while(my $l = <FILE>)
30 {
31 if($l =~ /src\s*=\s*["'](.*?)["']/)
32 {
33 my $img = "styles/standard/$1";
34 $img = "styles/$1" if((!-f "images/$img") && -f "images/styles/$1");
35 $img = $1 if((!-f "images/$img") && -f "images/$1");
36 ++$icons{$img};
37 }
38 elsif($l =~ /icon\s*[:=]\s*["']([^+]+?)["']/)
39 {
40 ++$icons{$1};
41 }
42
43 if($l =~ /icon-image:\s*\"?(.*?)\"?\s*;/)
44 {
45 my $img = "styles/standard/$1";
46 $img = "styles/$1" if((!-f "images/$img") && -f "images/styles/$1");
47 $img = $1 if((!-f "images/$img") && -f "images/$1");
48 ++$icons{$img};
49 }
50 if($l =~ /ImageProvider\.get\(\"([^\"]*?)\"\)/)
51 {
52 my $i = $1;
53 $i .= ".png" if !($i =~ /\.png$/);
54 ++$icons{$i};
55 }
56 while($l =~ /\/\*\s*ICON\s*\*\/\s*\"(.*?)\"/g)
57 {
58 my $i = $1;
59 $i .= ".png" if !($i =~ /\.png$/);
60 ++$icons{$i};
61 }
62 while($l =~ /\/\*\s*ICON\((.*?)\)\s*\*\/\s*\"(.*?)\"/g)
63 {
64 my $i = "$1$2";
65 $i .= ".png" if !($i =~ /\.png$/);
66 ++$icons{$i};
67 }
68 if($l =~ /new\s+ImageLabel\(\"(.*?)\"/)
69 {
70 my $i = "statusline/$1";
71 $i .= ".png" if !($i =~ /\.png$/);
72 ++$icons{$i};
73 }
74 if($l =~ /createPreferenceTab\(\"(.*?)\"/)
75 {
76 my $i = "preferences/$1";
77 $i .= ".png" if !($i =~ /\.png$/);
78 ++$icons{$i};
79 }
80 if($l =~ /ImageProvider\.get\(\"(.*?)\",\s*\"(.*?)\"\s*\)/)
81 {
82 my $i = "$1/$2";
83 $i .= ".png" if !($i =~ /\.png$/);
84 ++$icons{$i};
85 }
86 if($l =~ /ImageProvider\.overlay\(.*?,\s*\"(.*?)\",/)
87 {
88 my $i = $1;
89 $i .= ".png" if !($i =~ /\.png$/);
90 ++$icons{$i};
91 }
92 if($l =~ /getCursor\(\"(.*?)\",\s*\"(.*?)\"/)
93 {
94 my $i = "cursor/modifier/$2";
95 $i .= ".png" if !($i =~ /\.png$/);
96 ++$icons{$i};
97 $i = "cursor/$1";
98 $i .= ".png" if !($i =~ /\.png$/);
99 ++$icons{$i};
100 }
101 if($l =~ /ImageProvider\.getCursor\(\"(.*?)\",\s*null\)/)
102 {
103 my $i = "cursor/$1";
104 $i .= ".png" if !($i =~ /\.png$/);
105 ++$icons{$i};
106 }
107 if($l =~ /SideButton*\(\s*(?:mark)?tr\s*\(\s*\".*?\"\s*\)\s*,\s*\"(.*?)\"/)
108 {
109 my $i = "dialogs/$1";
110 $i .= ".png" if !($i =~ /\.png$/);
111 ++$icons{$i};
112 }
113 if($l =~ /super\(\s*tr\(\".*?\"\),\s*\"(.*?)\"/s)
114 {
115 my $i = "$extends$1";
116 $i .= ".png" if !($i =~ /\.png$/);
117 ++$icons{$i};
118 }
119 if($l =~ /super\(\s*trc\(\".*?\",\s*\".*?\"\),\s*\"(.*?)\"/s)
120 {
121 my $i = "$extends$1";
122 $i .= ".png" if !($i =~ /\.png$/);
123 ++$icons{$i};
124 }
125 if($l =~ /audiotracericon\",\s*\"(.*?)\"/s)
126 {
127 my $i = "markers/$1";
128 $i .= ".png" if !($i =~ /\.png$/);
129 ++$icons{$i};
130 }
131 if($l =~ /\"(.*?)\",\s*parentLayer/s)
132 {
133 my $i = "markers/$1";
134 $i .= ".png" if !($i =~ /\.png$/);
135 ++$icons{$i};
136 }
137 if($l =~ /allowedtypes\s+=.*\{(.*)\}/s)
138 {
139 my $t = $1;
140 while($t =~ /\"(.*?)\"/g)
141 {
142 ++$icons{"Mf_$1.png"};
143 }
144 }
145 if($l =~ /MODES\s+=.*\{(.*)\}/s)
146 {
147 my $t = $1;
148 while($t =~ /\"(.*?)\"/g)
149 {
150 ++$icons{"dialogs/autoscale/$1.png"};
151 }
152 }
153 if($l =~ /enum\s+DeleteMode\s*\{(.*)/s)
154 {
155 my $t = $1;
156 while($t =~ /\"(.*?)\"/g)
157 {
158 ++$icons{"cursor/modifier/$1.png"};
159 }
160 }
161 if($l =~ /\.setButtonIcons.*\{(.*)\}/)
162 {
163 my $t = $1;
164 while($t =~ /\"(.*?)\"/g)
165 {
166 my $i = $1;
167 $i .= ".png" if !($i =~ /\.png$/);
168 ++$icons{$i};
169 }
170 }
171 if($l =~ /extends MapMode/)
172 {
173 $extends = "mapmode/";
174 }
175 if($l =~ /extends ToggleDialog/)
176 {
177 $extends = "dialogs/";
178 }
179 }
180 close FILE;
181 }
182}
183
184my %haveicons;
185
186for($i = 1; my @ifiles = glob("images".("/*" x $i).".png"); ++$i)
187{
188 for my $ifile (sort @ifiles)
189 {
190 $ifile =~ s/^images\///;
191 $haveicons{$ifile} = 1;
192 }
193}
194
195for my $img (sort keys %icons)
196{
197 print STDERR "File $img does not exist!\n" if(!-f "images/$img");
198 delete $haveicons{$img};
199}
200
201for my $img (sort keys %haveicons)
202{
203 print "$img\n";
204}
Note: See TracBrowser for help on using the repository browser.