struct / union in initializer, RFE #901.
[sdcc.git] / sdcc / support / scripts / gen_known_bugs.pl
blob9c19cf878141722e6f46a4adf111cefa6f5e2f6b
1 # gen_known_bugs.pl - generate knownbugs.html
3 # Copyright (c) 2007-2013 Borut Razem
5 # This file is part of sdcc.
7 # This software is provided 'as-is', without any express or implied
8 # warranty. In no event will the authors be held liable for any damages
9 # arising from the use of this software.
11 # Permission is granted to anyone to use this software for any purpose,
12 # including commercial applications, and to alter it and redistribute it
13 # freely, subject to the following restrictions:
15 # 1. The origin of this software must not be misrepresented; you must not
16 # claim that you wrote the original software. If you use this software
17 # in a product, an acknowledgment in the product documentation would be
18 # appreciated but is not required.
19 # 2. Altered source versions must be plainly marked as such, and must not be
20 # misrepresented as being the original software.
21 # 3. This notice may not be removed or altered from any source distribution.
23 # Borut Razem
24 # borut.razem@siol.net
26 use strict;
27 use warnings;
29 use LWP::Simple;
30 use HTML::TreeBuilder;
33 # trim function to remove whitespace from the start and end of the string
34 sub trim($)
36 my $string = shift;
37 $string =~ s/^\s+//;
38 $string =~ s/\s+$//;
39 return $string;
43 my @headerList = ('#', 'Summary', 'Owner', 'Creator', 'Created', 'Priority');
44 my $nFields = $#headerList + 1; # Number of colums is number of header fields + 1 for "Select Columns" icon
46 # check if the line is a correct header
47 sub is_header($)
49 my ($line) = @_;
51 if (ref($line)) {
52 my @headers = $line->look_down('_tag', 'th');
53 foreach my $header (@headerList) {
54 my $found = 0;
55 foreach (@headers) {
56 my $content = trim($_->as_text());
57 if ($content =~ /\Q$header\E/i) {
58 $found = 1;
59 last;
62 if (!$found) {
63 return 0;
66 return 1;
68 return 0;
72 # check if the line has correct number of fields
73 sub has_all_fields($)
75 my ($line) = @_;
77 my @len = $line->look_down('_tag', 'td');
78 return $#len == $nFields;
81 # convert to ISO date
82 sub date_to_iso($)
84 my %months = (
85 'Jan', '01',
86 'Feb', '02',
87 'Mar', '03',
88 'Apr', '04',
89 'May', '05',
90 'Jun', '06',
91 'Jul', '07',
92 'Aug', '08',
93 'Sep', '09',
94 'Oct', '10',
95 'Nov', '11',
96 'Dec', '12'
99 my ($date) = @_; #Mon Mar 14, 2011 10:42 AM UTC
100 my (undef, $month, $day, $year) = split(' ' , $date);
101 $day =~ s/^(\d+),$/$1/;
102 return $year . '-' . $months{$month} . '-' . sprintf('%02d', $day);
105 # process a line
106 sub process_line($)
108 my ($line) = @_;
110 my $i = 0;
111 foreach ($line->look_down('_tag', 'td')) {
112 if (!defined($headerList[$i])) {
113 # don't print columns which are not in the header list
114 $_->delete();
116 elsif ($headerList[$i] eq 'Summary') {
117 # convert relative to absolute href in the 'Summary' field
118 foreach ($_->look_down('_tag', 'a')) {
119 my $attr = $_->attr('href');
120 if (defined($attr)) {
121 $_->attr('href', 'https://sourceforge.net' . $attr);
125 elsif ($headerList[$i] eq 'Owner' || $headerList[$i] eq 'Creator') {
126 $_->normalize_content();
128 elsif ($headerList[$i] eq 'Created') {
129 my $date = $_->look_down('_tag', 'span')->attr('title');
130 $_->delete_content();
131 $_->push_content(date_to_iso($date));
133 elsif ($headerList[$i] eq 'Priority') {
134 my @content = $_->content_list();
135 my $v = 0;
136 $v = $content[0] if (0 == $#content);
137 $_->{'_parent'}->{'class'} = 'p' . $v;
139 ++$i;
141 $line->delete_ignorable_whitespace();
145 # process the HTML page
146 sub process_page($)
148 my ($html) = @_;
150 # create HTML tree from the page
151 my $tree = HTML::TreeBuilder->new();
152 $tree->parse($html);
154 # find table with the required header
155 my $lines = 0;
156 foreach my $table ($tree->look_down('_tag', 'table')) {
157 my $thead = $table->look_down('_tag', 'thead');
158 if (is_header($thead)) {
159 my $tbody = $table->look_down('_tag', 'tbody');
160 my @lines = $tbody->content_list();
162 # process the lines in table
163 # if they have required number of fields
164 foreach my $line (@lines) {
165 if (ref($line) && has_all_fields($line)) {
166 # process a line
167 process_line($line);
168 # and print it
169 print($line->as_HTML(undef, ' '));
170 ++$lines;
176 $tree->delete;
178 return $lines;
182 # print HTML header
183 sub print_header($)
185 my ($version) = @_;
187 print <<EOF;
188 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
189 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
190 <html xmlns="http://www.w3.org/1999/xhtml" lang="en">
191 <!--
192 This file is generated automagicaly by gen_known_bugs.pl script.
194 <head>
195 <meta http-equiv="content-type" content="text/html; charset=utf-8" />
196 <title>SourceForge.net: Known Bugs</title>
197 <style type="text/css">
198 .p1 {background-color: #9ff;}
199 .p2 {background-color: #cff;}
200 .p3 {background-color: #9fc;}
201 .p4 {background-color: #cfc;}
202 .p5 {background-color: #cf9;}
203 .p6 {background-color: #ffc;}
204 .p7 {background-color: #ff9;}
205 .p8 {background-color: #fc9;}
206 .p9 {background-color: #fcc; color: #300;}
207 </style>
208 </head>
209 <body>
210 <h2>Small Device C Compiler - Release $version Known Bug List</h2>
211 <ul>
212 <li><a href="http://sdcc.sourceforge.net">Home&nbsp;Page</a></li>
213 <li class="selected"><a href="http://sourceforge.net/p/sdcc/bugs/">Current Bugs</a></li>
214 </ul>
215 <table width="100%" border="0" cellspacing="2" cellpadding="3">
216 <tr bgcolor="#ffffff">
219 foreach my $header (@headerList) {
220 # don't print Status and Resolution columns
221 if ($header ne 'Status' && $header ne 'Resolution') {
222 print(' <td align="center"><font color="#000000"><b>' . $header . "</b></font></td>\n");
225 print(" </tr>\n");
229 # print HTML footer
230 sub print_footer($)
232 my ($lines) = @_;
234 print <<EOF;
235 </table>
236 <p><b>Priority Colors:</b></p>
237 <table border="0">
238 <tr>
239 <td class="p1">1</td>
240 <td class="p2">2</td>
241 <td class="p3">3</td>
242 <td class="p4">4</td>
243 <td class="p5">5</td>
244 <td class="p6">6</td>
245 <td class="p7">7</td>
246 <td class="p8">8</td>
247 <td class="p9">9</td>
248 </tr>
249 </table>
250 </body>
251 <p><b>Number of open bugs: $lines</b></p>
252 </html>
257 # main procedure
259 my $url = "http://sourceforge.net/p/sdcc/bugs/?limit=%d&page=%d&sort=ticket_num+desc&q=%%7B%%22status%%22%%3A+%%7B%%22%%24nin%%22%%3A+%%5B%%22closed-invalid%%22%%2C+%%22closed-later%%22%%2C+%%22closed-accepted%%22%%2C+%%22closed-duplicate%%22%%2C+%%22closed-out-of-date%%22%%2C+%%22closed-fixed%%22%%2C+%%22closed-rejected%%22%%2C+%%22closed-remind%%22%%2C+%%22closed-works-for-me%%22%%2C+%%22closed%%22%%2C+%%22closed-wont-fix%%22%%2C+%%22closed-postponed%%22%%5D%%7D%%7D&columns-0.name=ticket_num&columns-0.sort_name=ticket_num&columns-0.label=Ticket+Number&columns-0.active=on&columns-1.name=summary&columns-1.sort_name=summary&columns-1.label=Summary&columns-1.active=on&columns-2.name=_milestone&columns-2.sort_name=custom_fields._milestone&columns-2.label=Milestone&columns-3.name=status&columns-3.sort_name=status&columns-3.label=Status&columns-4.name=assigned_to&columns-4.sort_name=assigned_to_username&columns-4.label=Owner&columns-4.active=on&columns-5.name=reported_by&columns-5.sort_name=reported_by&columns-5.label=Creator&columns-5.active=on&columns-6.name=created_date&columns-6.sort_name=created_date&columns-6.label=Created&columns-6.active=on&columns-7.name=mod_date&columns-7.sort_name=mod_date&columns-7.label=Updated&columns-8.name=labels&columns-8.sort_name=labels&columns-8.label=Labels&columns-9.name=_priority&columns-9.sort_name=_priority&columns-9.label=Priority&columns-9.active=on";
261 if ($#ARGV != 0) {
262 printf("Usage: gen_known_bugs.pl <version>\n");
263 exit(1);
266 my $limit = 100;
268 # get the SDCC version number from command line
269 my $version = $ARGV[0];
271 # print HTML header
272 print_header($version);
274 # get pages from SF bug tracker
275 # and process them
276 my $page = 0;
277 my $lines;
278 while (my $linesRead = process_page(get(sprintf($url, $limit, $page)))) {
279 $lines += $linesRead;
280 ++$page;
283 # print HTML footer
284 print_footer($lines);
286 exit(0);