Debian Codegraph @

dist/extractnews

raw
1 #!/usr/bin/perl
2
3 use strict;
4 use Text::Wrap;
5 my %output;
6 my $text;
7 my %stash;
8
9 use Getopt::Long;
10
11 my %opts = (
12 c => 'CHANGES.new',
13 n => 'NEWS.new',
14 );
15
16 LocalGetOptions(\%opts,
17 ['s|start-regexp=s','A regexp to look for in files to start converting at'],
18 ['e|end-regexp=s','A regexp to look for in files to end converting at'],
19 "",
20 ['c|changes-file=s','A file to save CHANGES entries to'],
21 ['n|news-file=s','A file to save NEWS entries to'],
22 ['d|debug-line=s', 'Debugging output for lines matching STRING'],
23 "",
24 ['GUI:otherargs_text','Input files to parse'],
25 );
26
27 my $maybecontinue = 0;
28 my $lasttext = "";
29 my $lastfile;
30 my $lastcomponent;
31
32 foreach my $argv (@ARGV) {
33 open(I, $argv);
34 if ($opts{'s'}) {
35 while (<I>) {
36 last if (/$opts{'s'}/o);
37 }
38 }
39
40 while (<I>) {
41 my ($file, $component, $patbug, $nums, $text);
42
43 last if ($opts{'e'} && /$opts{e}/o);
44
45 print STDERR "here: $_" if ($opts{'d'} && /$opts{'d'}/o);
46
47 # don't use this:
48 # FILE: BUGS: 123,456: text
49 ($file, $patbug, $nums, $text) =
50 /(NEWS|CHANGES):\s*-*\s*\[*(BUG|PATCH)(?:ES|S|):*\s*([\d,\s*]*)\]*:*\s*-*\s*(.*)/;
51
52 print STDERR " 1:$file, $component, $patbug, $nums, $text\n" if ($opts{'d'} && /$opts{'d'}/o);
53
54 # or this:
55 # FILE: component - text
56 ($file, $component, $text) =
57 /(NEWS|CHANGES):\s*(\w+)\s*-+\s*(.*)/ if (!$file);
58
59 print STDERR " 2:$file, $component, $patbug, $nums, $text\n" if ($opts{'d'} && /$opts{'d'}/o);
60
61 # what you should use:
62 # FILE: component: BUGS: 123,456: text
63 #
64 # or
65 # FILE: component: PATCH: 123,456: from someone text
66 # FILE: component: PATCH: 123,456: from "someone long" text
67 ($file, $component, $patbug, $nums, $text) =
68 /(NEWS|CHANGES):\s*([^:]+):\s*-*\s*\[*(BUG|PATCH)(?:ES|S):*\s*([\d,\s*]*)\]*:*\s*-*\s*(?:from ["'][^"]+["']|from \w+|):*\s*(.*)/ if (!$file);
69
70 print STDERR " 3:$file, $component, $patbug, $nums, $text\n" if ($opts{'d'} && /$opts{'d'}/o);
71
72 # or at least:
73 # FILE: component: text
74 ($file, $component, $text) =
75 /(NEWS|CHANGES):\s*([^:]+):\s*-*\s*(.*)/ if (!$file);
76
77 print STDERR " 4:$file, $component, $patbug, $nums, $text\n" if ($opts{'d'} && /$opts{'d'}/o);
78
79 # component left out
80 # FILE: [BUGS: 123,456]: text
81 ($file, $patbug, $nums, $text) =
82 /(NEWS|CHANGES):\s*\[*(BUG|PATCH)*(?:ES|S|):*\s*([\d,\s*]*)\]*:*\s*-*\s*(.*)/ if (!$file);
83
84 print STDERR " 5:$file, $component, $patbug, $nums, $text\n" if ($opts{'d'} && /$opts{'d'}/o);
85
86 if ($opts{'d'} && /$opts{'d'}/o) {
87 my $bogus = 1; # breakable point
88 }
89
90 if (!$file && $maybecontinue) {
91 if (/^\s*(.+)$/) {
92 $text = $1;
93 $file = $lastfile;
94 $component = $lastcomponent;
95
96 # we're going to re-add these
97 pop @{$output{$opts{'c'}}{$component}};
98 pop @{$output{$opts{'n'}}{$component}} if ($file eq 'NEWS');
99 } else {
100 $maybecontinue = 0;
101 $lasttext = "";
102 next;
103 }
104 } elsif (!$file) {
105 next;
106 }
107
108 next if (exists($stash{$text}));
109 $stash{$text} = 1;
110
111 $component = "unspecified" if (!$component);
112 if ($patbug) {
113 $lasttext .= " [$patbug $nums]: $text";
114 } else {
115 $lasttext .= " $text";
116 }
117 $lasttext =~ s/^ //; # get rid of leading spaces
118 $lasttext =~ s/^([a-z])/uc($1)/e; # capitalize the first letter
119 $text = wrap(" - "," ","$lasttext") . "\n";
120
121 #
122 # Assist with displaying categories in a sensible order
123 # snmplib first
124 # snmpd/snmp{apps}
125 # various other
126 # O/S specific (relies on upper case)
127 #
128 $component =~ s/^snmplib/00snmplib/;
129 $component =~ s/^snmp/0snmp/;
130 $component =~ s/^agent/0snmpd/; # Merge "agent" into "snmpd"
131 $component =~ s/^([A-Z])/zz\1/;
132 print STDERR " t:$file, $component, $patbug, $nums, $text\n" if ($opts{'d'} && /$opts{'d'}/o);
133 push @{$output{$opts{'c'}}{$component}}, $text;
134 push @{$output{$opts{'n'}}{$component}}, $text if ($file eq 'NEWS');
135 $lastfile = $file;
136 $lastcomponent = $component;
137 $maybecontinue = 1;
138 }
139 }
140
141
142
143 # save the news and changes to appropriate files
144 foreach my $f ($opts{'c'}, $opts{'n'}) {
145 my $cat2;
146 open(O,">$f");
147 foreach my $cat (sort (keys(%{$output{$f}}))) {
148 ($cat2 = $cat) =~ s/^00?|^zz//;
149 print O " $cat2:\n";
150 print O sort @{$output{$f}{$cat}};
151 print O "\n";
152 }
153 close(O);
154 }
155
156 #######################################################################
157 # getopt long gui portability code
158 #
159 sub LocalGetOptions {
160 if (eval {require Getopt::GUI::Long;}) {
161 import Getopt::GUI::Long;
162 Getopt::GUI::Long::Configure(qw(display_help no_ignore_case));
163 return GetOptions(@_);
164 } else {
165 require Getopt::Long;
166 Getopt::Long::Configure(qw(auto_help no_ignore_case));
167 import Getopt::Long;
168 }
169 GetOptions(LocalOptionsMap(@_));
170 }
171
172 sub LocalOptionsMap {
173 my ($st, $cb, @opts) = ((ref($_[0]) eq 'HASH')
174 ? (1, 1, $_[0]) : (0, 2));
175 for (my $i = $st; $i <= $#_; $i += $cb) {
176 if ($_[$i]) {
177 next if (ref($_[$i]) eq 'ARRAY' && $_[$i][0] =~ /^GUI:/);
178 push @opts, ((ref($_[$i]) eq 'ARRAY') ? $_[$i][0] : $_[$i]);
179 push @opts, $_[$i+1] if ($cb == 2);
180 }
181 }
182 return @opts;
183 }