3 # Update an older edition of What's Cooking with the latest data.
5 # Usage: UWC [ old [ new ] ]
7 # Giving no parameter is the same as giving a single "-" to the command.
9 # The command reads the old edition of (annotated) "What's Cooking"
10 # message from "old", and "new". If "old" is "-", it is read from
11 # the standard input. If "new" is not specified, WC script is run
12 # and its output is used.
14 # An annotated "What's Cooking" message can have group header (a line
15 # that has the group name enclosed in "[" and "]"), and annotatation
16 # paragraphs after each topic's commit list, in addition to the bare
19 # The group headers, topics in each group and their order in the group,
20 # and annotation to topics are preserved from the "old" message. The
21 # list of commits in each topic is replaced with the one taken from the
22 # "new" message. Any topic in "new" that did not exist in "old" appear
23 # in "New Topics" group. Also, topics that do not appear in the "new"
24 # message are marked with <<deleted>>, topics whose commit list are
25 # different from "old" are marked with <<updated from...>>>.
27 # Typically the maintainer would place the What's Cooking message
28 # previously sent in a buffer in Emacs, and filter the buffer contents
29 # with this script, to prepare an up-to-date message.
31 sub parse_whats_cooking
{
35 my %wc = ("group list" => [], "topic hash" => {});
37 my $skipping_comment = 0;
46 if (/^Here are the topics that have been/) {
56 if ($skipping_comment) {
58 $skipping_comment = 0;
63 if (!$skipping_comment && /^<</) {
64 $skipping_comment = 1;
70 push @
{$wc{"group list"}}, $group;
76 if (!defined $group) {
77 if (/^\* (\S+) (\(.*\) \d+ commits?)$/) {
80 push @
{$wc{"group list"}}, $group;
88 if (/^\* (\S+) (\(.*\) \d+ commits?)$/) {
95 $wc{"topic hash"}{$topic->{"topic"}} = $topic;
96 push @
{$wc{" $group"}}, $topic;
100 if (/^ [-+.?*] / || /^ \S/) {
101 $topic->{"names"} .= $_;
104 $topic->{"text"} .= $_;
111 $wc{"head text"} = $head;
112 for $topic (values %{$wc{"topic hash"}}) {
113 for ($topic->{"text"}) {
121 sub print_whats_cooking
{
124 print $wc->{"head text"}, "\n";
126 for my $group (@
{$wc->{"group list"}}) {
127 print "\n", "-" x
64, "\n";
129 for my $topic (@
{$wc->{" $group"}}) {
130 print "\n", $topic->{"head"};
131 print $topic->{"names"};
132 if ($topic->{"text"} ne '') {
133 print "\n", $topic->{"text"}, "\n";
140 my ($wc, $topic) = @_;
141 $topic->{"status"} = "deleted";
144 sub merge_whats_cooking
{
145 my ($old_wc, $new_wc) = @_;
148 for $group (@
{$old_wc->{"group list"}}) {
149 for my $topic (@
{$old_wc->{" $group"}}) {
150 my $name = $topic->{"topic"};
151 my $newtopic = delete $new_wc->{"topic hash"}{$name};
153 if (!defined $newtopic) {
154 $topic->{"text"} = ("<<deleted\n" .
159 $topic->{"names"} = "";
162 if (($newtopic->{"names"} ne $topic->{"names"}) ||
163 ($newtopic->{"head"} ne $topic->{"head"})) {
164 my $text = ("<<updated from\n" .
166 $topic->{"names"} . ">>");
168 if ($topic->{"text"} ne '') {
169 $text .= "\n\n" . $topic->{"text"};
175 $topic->{"text"} = $text;
176 $topic->{"names"} = $newtopic->{"names"};
177 $topic->{"head"} = $newtopic->{"head"};
182 if (%{$new_wc->{"topic hash"}}) {
183 $group = "New Topics";
184 if (!exists $old_wc->{" $group"}) {
185 unshift @
{$old_wc->{"group list"}}, $group;
186 $old_wc->{" $group"} = [];
188 for my $topic (values %{$new_wc->{"topic hash"}}) {
189 my $name = $topic->{"topic"};
190 $old_wc->{"topic hash"}{$name} = $topic;
191 push @
{$old_wc->{" $group"}}, $topic;
192 $topic->{"text"} = $topic->{"text"};
200 if (@ARGV != 2 && @ARGV != 1) {
201 die "Usage: $0 old [new]\n";
204 my ($old_wc, $new_wc);
206 if ($ARGV[0] eq '-') {
211 $old_wc = parse_whats_cooking
(\
*FH
);
217 open FH
, "Meta/WC |";
219 $new_wc = parse_whats_cooking
(\
*FH
);
222 merge_whats_cooking
($old_wc, $new_wc);
223 print_whats_cooking
($old_wc);