source: josm/trunk/geticons.pl@ 9489

Last change on this file since 9489 was 7736, checked in by stoecker, 10 years ago

exclude some recently removed icons from distribution

  • Property svn:executable set to *
File size: 4.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 next if $l =~ /NO-ICON/;
32 if($l =~ /icon\s*[:=]\s*["']([^+]+?)["']/)
33 {
34 ++$icons{$1};
35 }
36
37 if(($l =~ /(?:icon-image|repeat-image|fill-image)\s*:\s*(\"?(.*?)\"?)\s*;/) && ($1 ne "none"))
38 {
39 my $val = $2;
40 my $img = "styles/standard/$val";
41 $img = "styles/$val" if((!-f "images/$img") && -f "images/styles/$val");
42 $img = $val if((!-f "images/$img") && -f "images/$val");
43 ++$icons{$img};
44 }
45 if($l =~ /ImageProvider(?:\.get)?\(\"([^\"]*?)\"\)/)
46 {
47 my $i = $1;
48 $i = "styles/standard/$i" if $i eq "misc/no_icon.png";
49 ++$icons{$i};
50 }
51 while($l =~ /\/\*\s*ICON\s*\*\/\s*\"(.*?)\"/g)
52 {
53 my $i = $1;
54 ++$icons{$i};
55 }
56 while($l =~ /\/\*\s*ICON\((.*?)\)\s*\*\/\s*\"(.*?)\"/g)
57 {
58 my $i = "$1$2";
59 ++$icons{$i};
60 }
61 if($l =~ /new\s+ImageLabel\(\"(.*?)\"/)
62 {
63 my $i = "statusline/$1";
64 ++$icons{$i};
65 }
66 if($l =~ /createPreferenceTab\(\"(.*?)\"/)
67 {
68 my $i = "preferences/$1";
69 ++$icons{$i};
70 }
71 if($l =~ /ImageProvider\.get\(\"(.*?)\",\s*\"(.*?)\"\s*\)/)
72 {
73 my $i = "$1/$2";
74 ++$icons{$i};
75 }
76 if($l =~ /ImageProvider\.overlay\(.*?,\s*\"(.*?)\",/)
77 {
78 my $i = $1;
79 ++$icons{$i};
80 }
81 if($l =~ /getCursor\(\"(.*?)\",\s*\"(.*?)\"/)
82 {
83 my $i = "cursor/modifier/$2";
84 ++$icons{$i};
85 $i = "cursor/$1";
86 ++$icons{$i};
87 }
88 if($l =~ /ImageProvider\.getCursor\(\"(.*?)\",\s*null\)/)
89 {
90 my $i = "cursor/$1";
91 ++$icons{$i};
92 }
93 if($l =~ /SideButton*\(\s*(?:mark)?tr\s*\(\s*\".*?\"\s*\)\s*,\s*\"(.*?)\"/)
94 {
95 my $i = "dialogs/$1";
96 ++$icons{$i};
97 }
98 if($l =~ /super\(\s*tr\(\".*?\"\),\s*\"(.*?)\"/s)
99 {
100 my $i = "$extends$1";
101 ++$icons{$i};
102 }
103 if($l =~ /super\(\s*trc\(\".*?\",\s*\".*?\"\),\s*\"(.*?)\"/s)
104 {
105 my $i = "$extends$1";
106 ++$icons{$i};
107 }
108 if($l =~ /audiotracericon\",\s*\"(.*?)\"/s)
109 {
110 my $i = "markers/$1";
111 ++$icons{$i};
112 }
113 if($l =~ /\"(.*?)\",\s*parentLayer/s)
114 {
115 my $i = "markers/$1";
116 ++$icons{$i};
117 }
118 if($l =~ /\.setButtonIcons.*\{(.*)\}/)
119 {
120 my $t = $1;
121 while($t =~ /\"(.*?)\"/g)
122 {
123 my $i = $1;
124 ++$icons{$i};
125 }
126 }
127 if($l =~ /extends MapMode/)
128 {
129 $extends = "mapmode/";
130 }
131 elsif($l =~ /extends ToggleDialog/)
132 {
133 $extends = "dialogs/";
134 }
135 }
136 close FILE;
137 }
138}
139
140my %haveicons;
141
142for($i = 1; my @ifiles = (glob("images".("/*" x $i).".png"), glob("images".("/*" x $i).".svg")); ++$i)
143{
144 for my $ifile (sort @ifiles)
145 {
146 $ifile =~ s/^images\///;
147 $haveicons{$ifile} = 1;
148 }
149}
150
151for my $img (sort keys %icons)
152{
153 if($img =~ /\.(png|svg)/)
154 {
155 print STDERR "File $img does not exist!\n" if(!-f "images/$img");
156 delete $haveicons{$img};
157 }
158 else
159 {
160 print STDERR "File $img(.svg|.png) does not exist!\n" if(!-f "images/$img.png" && !-f "images/$img.svg");
161 delete $haveicons{"$img.svg"};
162 delete $haveicons{"$img.png"};
163 }
164}
165
166for my $img (sort keys %haveicons)
167{
168 print "$img\n";
169}
Note: See TracBrowser for help on using the repository browser.