* support/scripts/gen_known_bugs.pl: cosmetic fix
[fw/sdcc] / support / scripts / gen_known_bugs.pl
1 # gen_known_bugs.pl - generate knownbugs.html\r
2 #\r
3 # Copyright (c) 2007 Borut Razem\r
4 #\r
5 # This file is part of sdcc.\r
6 #\r
7 #  This software is provided 'as-is', without any express or implied\r
8 #  warranty.  In no event will the authors be held liable for any damages\r
9 #  arising from the use of this software.\r
10 #\r
11 #  Permission is granted to anyone to use this software for any purpose,\r
12 #  including commercial applications, and to alter it and redistribute it\r
13 #  freely, subject to the following restrictions:\r
14 #\r
15 #  1. The origin of this software must not be misrepresented; you must not\r
16 #     claim that you wrote the original software. If you use this software\r
17 #     in a product, an acknowledgment in the product documentation would be\r
18 #     appreciated but is not required.\r
19 #  2. Altered source versions must be plainly marked as such, and must not be\r
20 #     misrepresented as being the original software.\r
21 #  3. This notice may not be removed or altered from any source distribution.\r
22 #\r
23 #  Borut Razem\r
24 #  borut.razem@siol.net\r
25 \r
26 use strict;\r
27 use warnings;\r
28 \r
29 use LWP::Simple;\r
30 use HTML::TreeBuilder;\r
31 \r
32 \r
33 my @headerList = ('Request ID', 'Summary', 'Open Date', 'Priority', 'Status', 'Assigned To', 'Submitted By');\r
34 my $version;\r
35 \r
36 \r
37 # check if the line is a correct header\r
38 sub is_header($)\r
39 {\r
40   my ($line) = @_;\r
41   \r
42   if (ref($line)) {\r
43     my $i = 0;\r
44     foreach ($line->look_down('_tag', 'td')) {\r
45       if ($_->as_text() ne $headerList[$i++]) {\r
46         return 0;\r
47       }\r
48     }\r
49     return 1;\r
50   }\r
51   else {\r
52     return 0;\r
53   }\r
54 }\r
55 \r
56 \r
57 # check if the line has correct number of fields\r
58 sub has_all_fields($)\r
59 {\r
60   my ($line) = @_;\r
61  \r
62   my @len = $line->look_down('_tag', 'td');\r
63   return $#len == $#headerList;\r
64 }\r
65 \r
66 \r
67 # process a line\r
68 sub process_line($)\r
69 {\r
70   my ($line) = @_;\r
71 \r
72   my $i = 0;\r
73   foreach ($line->look_down('_tag', 'td')) {\r
74     if ($i == 0) {\r
75       # remove nowrap attribute from 'Request ID' field\r
76       $_->attr('nowrap', undef);\r
77     }\r
78     elsif ($i == 1) {\r
79       # convert relative to absolute href in the 'Summary' field\r
80       foreach ($_->look_down('_tag', 'a')) {\r
81         my $attr = $_->attr('href');\r
82         if (defined($attr) && $attr =~ m!^/tracker/index.php?!) {\r
83           $_->attr('href', 'http://sourceforge.net' . $attr);\r
84         }\r
85       }\r
86     }\r
87     elsif ($i == 2) {\r
88       # remove text formatting from 'Open Date' field\r
89       my $text = $_->as_text();\r
90       $text =~ s/^\W*\**\W//;\r
91       $_->delete_content();\r
92       $_->push_content($text);\r
93     }\r
94     elsif ($i == 4) {\r
95       # remove the 'Status' field\r
96       $_->delete();\r
97     }\r
98     elsif ($i == 5 || $i == 6) {\r
99       # remove hrefs in 'Assigned To' and 'Submitted By' fields\r
100       foreach ($_->look_down('_tag', 'a')) {\r
101        $_->replace_with($_->as_text());\r
102       }\r
103     }\r
104     ++$i;\r
105   }\r
106   $line->delete_ignorable_whitespace();\r
107 }\r
108 \r
109 \r
110 # process the HTML page\r
111 sub process_page($)\r
112 {\r
113   my ($html) = @_;\r
114 \r
115   # create HTML tree from the page\r
116   my $tree = HTML::TreeBuilder->new();\r
117   $tree->parse($html);\r
118 \r
119   # find table with the required header\r
120   my $hasTable = 0;\r
121   foreach my $table ($tree->look_down('_tag', 'table')) {\r
122     my @lines = $table->content_list();\r
123     if (is_header($lines[0])) {\r
124       shift(@lines);  #remove the header\r
125 \r
126       # process the following lines in table\r
127       # if they have required number of fields\r
128       foreach my $line (@lines) {\r
129         if (ref($line) && has_all_fields($line)) {\r
130           # process a line\r
131           process_line($line);\r
132           # and print it\r
133           print($line->as_HTML(undef, '  '));\r
134           $hasTable = 1;\r
135         }\r
136       }\r
137     }\r
138   }\r
139 \r
140   $tree->delete;\r
141   \r
142   return $hasTable;\r
143 }\r
144 \r
145 \r
146 # print HTML header\r
147 sub print_header()\r
148 {\r
149   print <<EOF;\r
150 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"\r
151   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\r
152 <html xmlns="http://www.w3.org/1999/xhtml" lang="en">\r
153 <!--\r
154 This file is generated automagicaly by gen_known_bugs.pl script.\r
155 -->\r
156   <head>\r
157     <meta http-equiv="content-type" content="text/html; charset=utf-8" />\r
158     <title>SourceForge.net: Known Bugs</title>\r
159   </head>\r
160   <body>\r
161     <h2>Small Device C Compiler - Release $version Known Bug List</h2>\r
162     <ul>\r
163       <li><a href="http://sdcc.sourceforge.net" >Home&nbsp;Page</a></li>\r
164       <li class="selected"><a href="http://sourceforge.net/tracker/?group_id=599&amp;atid=100599" >Current Bugs</a></li>\r
165     </ul>\r
166     <table width="100%" border="0" cellspacing="2" cellpadding="3">\r
167       <tr bgcolor="#ffffff">\r
168         <td align="center"><font color="#000000"><b>Request ID</b></font></td>\r
169         <td align="center"><font color="#000000"><b>Summary</b></font></td>\r
170         <td align="center"><font color="#000000"><b>Open Date</b></font></td>\r
171         <td align="center"><font color="#000000"><b>Priority</b></font></td>\r
172         <td align="center"><font color="#000000"><b>Assigned To</b></font></td>\r
173         <td align="center"><font color="#000000"><b>Submitted By</b></font></td>\r
174       </tr>\r
175 EOF\r
176 }\r
177 \r
178 \r
179 # print HTML footer\r
180 sub print_footer()\r
181 {\r
182   print <<EOF;\r
183     </table>\r
184     <p><b>Priority Colors:</b></p>\r
185     <br />\r
186     <table border="0">\r
187       <tr>\r
188         <td bgcolor="#dadada">1</td>\r
189         <td bgcolor="#dad0d0">2</td>\r
190         <td bgcolor="#dacaca">3</td>\r
191         <td bgcolor="#dac0c0">4</td>\r
192         <td bgcolor="#dababa">5</td>\r
193         <td bgcolor="#dab0b0">6</td>\r
194         <td bgcolor="#daaaaa">7</td>\r
195         <td bgcolor="#da9090">8</td>\r
196         <td bgcolor="#da8a8a">9</td>\r
197       </tr>\r
198     </table>\r
199   </body>\r
200 </html>\r
201 EOF\r
202 }\r
203 \r
204 \r
205 # main procedure\r
206 {\r
207   my $url = "http://sourceforge.net/tracker/index.php?func=browse&group_id=599&atid=100599&set=custom&_assigned_to=0&_status=1&_category=100&_group=100&order=artifact_id&sort=DESC&offset=";\r
208 \r
209   if ($#ARGV != 0) {\r
210     printf("Usage: gen_known_bugs.pl <version>\n");\r
211     exit(1);\r
212   }\r
213 \r
214   # get the SDCC version number from command line\r
215   $version = $ARGV[0];\r
216 \r
217   # print HTML header\r
218   print_header();\r
219 \r
220   # get pages from SF bug tracker\r
221   for (my $i = 0; my $html = get($url . $i); $i += 50) {\r
222     # and process them\r
223     if (!process_page($html)) {\r
224       last;\r
225     }\r
226   }\r
227 \r
228   # print HTML footer\r
229   print_footer();\r
230 \r
231   exit(0);\r
232 }\r