-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathwikiformat.pl
More file actions
65 lines (53 loc) · 1.48 KB
/
wikiformat.pl
File metadata and controls
65 lines (53 loc) · 1.48 KB
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
#!/usr/bin/perl -w
use strict;
use warnings;
use JSON::XS;
use File::Slurp::Unicode;
my $datafile = shift || "data.json";
my $wikifile = shift || "wikidata.txt";
my $data = {};
if (-f $datafile) {
$data = decode_json(read_file($datafile));
}
my $wikidata = {};
if (-f $wikifile) {
$wikidata = read_wiki($wikifile);
}
print <<EOF;
= RFC List =
Every RFC is the work of someone who felt enough pain from the
lack of something that they would make the effort to write the
document. These problems need to be solved somehow - maybe
inherently in a different protocol, maybe explicitly.
||||||'''RFC List'''||
||RFC||Problem Solved||Plan for new Protocol||
EOF
foreach my $num (sort { $a <=> $b } keys %$data) {
my $url = "http://tools.ietf.org/html/rfc$num";
my $title = $data->{$num};
my $desc = $wikidata->{$num}{desc} || '';
my $res = $wikidata->{$num}{res} || '';
print "||[[$url|RFC $num]] $title||$desc||$res||\n";
}
print "\n";
print "(auto-generated from the list stored at " .
"[[http://github.com/brong/New-Mail-Protocol/|Github]])\n";
exit 0;
sub read_wiki {
my $file = shift;
my %data;
if (open(FH, "<$file")) {
while (<FH>) {
my @bits = split /[|]{2}/, $_;
my $id = $bits[1];
next unless $id;
next unless $id =~ m/RFC (\d+)/;
$data{$1} = {
desc => $bits[2],
res => $bits[3],
};
};
close(FH);
}
return \%data;
}