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