summaryrefslogtreecommitdiff
path: root/dist/extractnews
blob: 69e1f5bc370dee2ca4749abf3a01dc63cc57d18a (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#!/usr/bin/perl

use strict;
use Text::Wrap;
my %output;
my $text;
my %stash;

use Getopt::Long;

my %opts = (
	    c => 'CHANGES.new',
	    n => 'NEWS.new',
	   );

LocalGetOptions(\%opts,
		['s|start-regexp=s','A regexp to look for in files to start converting at'],
		['e|end-regexp=s','A regexp to look for in files to end converting at'],
		"",
		['c|changes-file=s','A file to save CHANGES entries to'],
		['n|news-file=s','A file to save NEWS entries to'],
		"",
		['GUI:otherargs_text','Input files to parse'],
	       );

foreach my $argv (@ARGV) {
    open(I, $argv);
    if ($opts{'s'}) {
	while (<I>) {
	    last if (/$opts{'s'}/o);
	}
    }

    while (<I>) {
	my ($file, $component, $patbug, $nums, $text);

	last if ($opts{'e'} && /$opts{e}/o);

	# don't use this:
	#   FILE: BUGS: 123,456: text
	($file, $patbug, $nums, $text) = 
	  /(NEWS|CHANGES):\s*-*\s*\[*(BUG|PATCH)(?:ES|S|):*\s*([\d,\s*]*)\]*:*\s*-*\s*(.*)/;

	# or this:
	#   FILE: component - text
	($file, $component, $text) = 
	  /(NEWS|CHANGES):\s*(\w+)\s*-+\s*(.*)/ if (!$file);

	# what you should use:
	#   FILE: component: text
	#      or
	#   FILE: component: BUGS: 123,456: text
	#
	#      or
	#   FILE: component: PATCH: 123,456: from someone text
	#   FILE: component: PATCH: 123,456: from "someone long" text
	($file, $component, $patbug, $nums, $text) = 
	  /(NEWS|CHANGES):\s*([^:]+):\s*-*\s*\[*(BUG|PATCH)*(?:ES|S|):*\s*([\d,\s*]*)\]*:*\s*-*\s*(?:from ["'][^"]+["']|from \w+|):*\s*(.*)/ if (!$file);

	# component left out
	# FILE: [BUGS: 123,456]: text
	($file, $patbug, $nums, $text) = 
	  /(NEWS|CHANGES):\s*\[*(BUG|PATCH)*(?:ES|S|):*\s*([\d,\s*]*)\]*:*\s*-*\s*(.*)/ if (!$file);
	
	next if (!$file);
	
	next if (exists($stash{$text}));
	$stash{$text} = 1;
	
	$component = "unspecified" if (!$component);
	if ($patbug) {
	    $text = wrap("      - ","        ","[$patbug $nums]: $text") . "\n";
	} else {
	    $text = wrap("      - ","        ","$text") . "\n";
	}
	
	#
	#  Assist with displaying categories in a sensible order
	#     snmplib first
	#     snmpd/snmp{apps}
	#     various other
	#     O/S specific  (relies on upper case)
	#
	$component =~ s/^snmplib/00snmplib/;
	$component =~ s/^snmp/0snmp/;
	$component =~ s/^agent/0snmpd/;		# Merge "agent" into "snmpd"
	$component =~ s/^([A-Z])/zz\1/;
	push @{$output{$opts{'c'}}{$component}}, $text;
	push @{$output{$opts{'n'}}{$component}}, $text if ($file eq 'NEWS');
    }
}



# save the news and changes to appropriate files
foreach my $f ($opts{'c'}, $opts{'n'}) {
    my $cat2;
    open(O,">$f");
    foreach my $cat (sort (keys(%{$output{$f}}))) {
	($cat2 = $cat) =~ s/^00?|^zz//;
	print O "    $cat2:\n";
	print O sort @{$output{$f}{$cat}};
	print O "\n";
    }
    close(O);
}

#######################################################################
# getopt long gui portability code
#
sub LocalGetOptions {
    if (eval {require Getopt::GUI::Long;}) {
	import Getopt::GUI::Long;
	Getopt::GUI::Long::Configure(qw(display_help no_ignore_case));
	return GetOptions(@_);
    } else {
	require Getopt::Long;
	Getopt::Long::Configure(qw(auto_help no_ignore_case));
	import Getopt::Long;
    }
    GetOptions(LocalOptionsMap(@_));
}

sub LocalOptionsMap {
    my ($st, $cb, @opts) = ((ref($_[0]) eq 'HASH')
			    ? (1, 1, $_[0]) : (0, 2));
    for (my $i = $st; $i <= $#_; $i += $cb) {
	if ($_[$i]) {
	    next if (ref($_[$i]) eq 'ARRAY' && $_[$i][0] =~ /^GUI:/);
	    push @opts, ((ref($_[$i]) eq 'ARRAY') ? $_[$i][0] : $_[$i]);
	    push @opts, $_[$i+1] if ($cb == 2);
	}
    }
    return @opts;
}