source: josm/trunk/geticons.pl@ 7668

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

cleanup icons, mark undetected icons, set proper mimetype, delete unused icons, update geticons script

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