wiki.pl: Port some fixes from upstream
[Orgmuse.git] / merge-list
blobc471c42e04749f7209c1d1147ba315789ca37666
1 #!/usr/bin/perl -w
2 # merge-list -- merge BannedContent from two wikis
3 # Copyright (C) 2004 Alex Schroeder <alex@emacswiki.org>
5 # This program is free software; you can redistribute it and/or modify
6 # it under the terms of the GNU General Public License as published by
7 # the Free Software Foundation; either version 2 of the License, or
8 # (at your option) any later version.
10 # This program is distributed in the hope that it will be useful,
11 # but WITHOUT ANY WARRANTY; without even the implied warranty of
12 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 # GNU General Public License for more details.
15 # You should have received a copy of the GNU General Public License
16 # along with this program; if not, write to the
17 # Free Software Foundation, Inc.
18 # 59 Temple Place, Suite 330
19 # Boston, MA 02111-1307 USA
21 # $Id: merge-list,v 1.2 2004/07/09 06:40:56 as Exp $</p>'
23 use strict;
24 use LWP::UserAgent;
26 sub GetRaw {
27 my $uri = shift;
28 my $ua = LWP::UserAgent->new;
29 my $request = HTTP::Request->new('GET', $uri);
30 my $response = $ua->request($request);
31 return $response->content;
34 sub Main {
35 my ($source, $target, $forgiven) = map {GetRaw($_)} @ARGV;
36 my (%source, %target);
37 map {$source{$_} = 1} grep(/^[ \t]/, split(/\n/, $source));
38 map {$target{$_} = 1} grep(/^[ \t]/, split(/\n/, $target));
39 # remove all the links that are forgiven...
40 foreach $_ (grep(/^[ \t]/, split(/\n/, $forgiven))) {
41 delete $source{$_};
42 delete $target{$_};
44 # merge the source lines to the target lines
45 foreach $_ (keys %source) {
46 $target{$_} = 1;
48 # now produce an updated pages from all the normal lines plus the
49 # new target lines.
50 my @page = grep(/^[^ \t]|$/, split(/\n/, $target));
51 push(@page, "") unless $page[$#page] eq ''; # add empty line if required
52 push(@page, sort(keys %target));
53 print join("\n", @page);
56 if ($#ARGV != 2) {
57 die "Usage: $0 source-url target-url forgiven-url\n";
60 Main();