Imported Upstream version 2.9.0
[debian/cc1111] / support / scripts / gen_known_bugs.pl
1 # gen_known_bugs.pl - generate knownbugs.html\r
2 #\r
3 # Copyright (c) 2007 - 2008 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 \r
35 \r
36 # check if the line is a correct header\r
37 sub is_header($)\r
38 {\r
39   my ($line) = @_;\r
40   \r
41   if (ref($line)) {\r
42     my $i = 0;\r
43     foreach ($line->look_down('_tag', 'td')) {\r
44       if ($_->as_text() ne $headerList[$i++]) {\r
45         return 0;\r
46       }\r
47     }\r
48     return 1;\r
49   }\r
50   else {\r
51     return 0;\r
52   }\r
53 }\r
54 \r
55 \r
56 # check if the line has correct number of fields\r
57 sub has_all_fields($)\r
58 {\r
59   my ($line) = @_;\r
60  \r
61   my @len = $line->look_down('_tag', 'td');\r
62   return $#len == $#headerList;\r
63 }\r
64 \r
65 \r
66 # process a line\r
67 sub process_line($)\r
68 {\r
69   my ($line) = @_;\r
70 \r
71   my $i = 0;\r
72   foreach ($line->look_down('_tag', 'td')) {\r
73     if ($i == 0) {\r
74       # remove nowrap attribute from 'Request ID' field\r
75       $_->attr('nowrap', undef);\r
76     }\r
77     elsif ($i == 1) {\r
78       # convert relative to absolute href in the 'Summary' field\r
79       foreach ($_->look_down('_tag', 'a')) {\r
80         my $attr = $_->attr('href');\r
81         if (defined($attr) && $attr =~ m!^/tracker/index.php?!) {\r
82           $_->attr('href', 'http://sourceforge.net' . $attr);\r
83         }\r
84       }\r
85     }\r
86     elsif ($i == 2) {\r
87       # remove text formatting from 'Open Date' field\r
88       my $text = $_->as_text();\r
89       $text =~ s/^\W*\**\W//;\r
90       $_->delete_content();\r
91       $_->push_content($text);\r
92     }\r
93     elsif ($i == 4) {\r
94       # remove the 'Status' field\r
95       $_->delete();\r
96     }\r
97     elsif ($i == 5 || $i == 6) {\r
98       # remove hrefs in 'Assigned To' and 'Submitted By' fields\r
99       foreach ($_->look_down('_tag', 'a')) {\r
100        $_->replace_with($_->as_text());\r
101       }\r
102     }\r
103     ++$i;\r
104   }\r
105   $line->delete_ignorable_whitespace();\r
106 }\r
107 \r
108 \r
109 # process the HTML page\r
110 sub process_page($)\r
111 {\r
112   my ($html) = @_;\r
113 \r
114   # create HTML tree from the page\r
115   my $tree = HTML::TreeBuilder->new();\r
116   $tree->parse($html);\r
117 \r
118   # find table with the required header\r
119   my $lines = 0;\r
120   foreach my $table ($tree->look_down('_tag', 'table')) {\r
121     my @lines = $table->content_list();\r
122     if (is_header($lines[0])) {\r
123       shift(@lines);  #remove the header\r
124 \r
125       # process the following lines in table\r
126       # if they have required number of fields\r
127       foreach my $line (@lines) {\r
128         if (ref($line) && has_all_fields($line)) {\r
129           # process a line\r
130           process_line($line);\r
131           # and print it\r
132           print($line->as_HTML(undef, '  '));\r
133           ++$lines;\r
134         }\r
135       }\r
136     }\r
137   }\r
138 \r
139   $tree->delete;\r
140   \r
141   return $lines;\r
142 }\r
143 \r
144 \r
145 # print HTML header\r
146 sub print_header($)\r
147 {\r
148   my ($version) = @_;\r
149 \r
150   print <<EOF;\r
151 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"\r
152   "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">\r
153 <html xmlns="http://www.w3.org/1999/xhtml" lang="en">\r
154 <!--\r
155 This file is generated automagicaly by gen_known_bugs.pl script.\r
156 -->\r
157   <head>\r
158     <meta http-equiv="content-type" content="text/html; charset=utf-8" />\r
159     <title>SourceForge.net: Known Bugs</title>\r
160   </head>\r
161   <body>\r
162     <h2>Small Device C Compiler - Release $version Known Bug List</h2>\r
163     <ul>\r
164       <li><a href="http://sdcc.sourceforge.net" >Home&nbsp;Page</a></li>\r
165       <li class="selected"><a href="http://sourceforge.net/tracker/?group_id=599&amp;atid=100599" >Current Bugs</a></li>\r
166     </ul>\r
167     <table width="100%" border="0" cellspacing="2" cellpadding="3">\r
168       <tr bgcolor="#ffffff">\r
169         <td align="center"><font color="#000000"><b>Request ID</b></font></td>\r
170         <td align="center"><font color="#000000"><b>Summary</b></font></td>\r
171         <td align="center"><font color="#000000"><b>Open Date</b></font></td>\r
172         <td align="center"><font color="#000000"><b>Priority</b></font></td>\r
173         <td align="center"><font color="#000000"><b>Assigned To</b></font></td>\r
174         <td align="center"><font color="#000000"><b>Submitted By</b></font></td>\r
175       </tr>\r
176 EOF\r
177 }\r
178 \r
179 \r
180 # print HTML footer\r
181 sub print_footer($)\r
182 {\r
183   my ($lines) = @_;\r
184 \r
185   print <<EOF;\r
186     </table>\r
187     <p><b>Priority Colors:</b></p>\r
188     <table border="0">\r
189       <tr>\r
190         <td bgcolor="#dadada">1</td>\r
191         <td bgcolor="#dad0d0">2</td>\r
192         <td bgcolor="#dacaca">3</td>\r
193         <td bgcolor="#dac0c0">4</td>\r
194         <td bgcolor="#dababa">5</td>\r
195         <td bgcolor="#dab0b0">6</td>\r
196         <td bgcolor="#daaaaa">7</td>\r
197         <td bgcolor="#da9090">8</td>\r
198         <td bgcolor="#da8a8a">9</td>\r
199       </tr>\r
200     </table>\r
201   </body>\r
202 <p><b>Number of open bugs: $lines</b></p>\r
203 </html>\r
204 EOF\r
205 }\r
206 \r
207 \r
208 # main procedure\r
209 {\r
210   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
211 \r
212   if ($#ARGV != 0) {\r
213     printf("Usage: gen_known_bugs.pl <version>\n");\r
214     exit(1);\r
215   }\r
216 \r
217   # get the SDCC version number from command line\r
218   my $version = $ARGV[0];\r
219 \r
220   my $lines = 0;  # number of lines\r
221 \r
222   # print HTML header\r
223   print_header($version);\r
224 \r
225   # get pages from SF bug tracker\r
226   for (my $i = 0; my $html = get($url . $i); $i += 50) {\r
227     # and process them\r
228     last if (!(my $myLines = process_page($html)));\r
229     $lines += $myLines;\r
230   }\r
231 \r
232   # print HTML footer\r
233   print_footer($lines);\r
234 \r
235   exit(0);\r
236 }\r