-
Notifications
You must be signed in to change notification settings - Fork 2
/
mk-back
executable file
·54 lines (51 loc) · 1.5 KB
/
mk-back
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
#!/usr/bin/perl
#
# Usage mk-back <file>
#
# Use to create a references section in a back file w/ oxtradoc.
#
# Substitutes any line on the form:
# ietf-ref[:<alias>]:RFCXXXX
# ietf-ref[:<alias>]:I-D.xxx...
# w3c-ref[:<alias>]:W3C.xxx...
# with the corresponding xml2rfc XML reference element.
my $host = "xml2rfc.tools.ietf.org";
my $path = "public/rfc";
my $filename = shift @ARGV;
open(my $fh, $filename);
while ( $line = $fh->getline() ) {
my $file = "";
my $alias = "";
my $name = "";
if ( $line =~ /ietf-ref(:(.*))?:RFC(.*)/ ) {
$alias = $2;
$name = $3;
$file = "bibxml/reference.RFC." . $name . ".xml";
} elsif ( $line =~ /ietf-ref(:(.*))?:(I-D.*)/ ) {
$alias = $2;
$name = $3;
$file = "bibxml3/reference." . $name . ".xml";
} elsif ( $line =~ /w3c-ref(:(.*))?:(.*)/ ) {
$alias = $2;
$name = $3;
$file = "bibxml4/reference." . $name . ".xml";
}
if ( $file eq "" ) {
print $line;
} else {
my $url = "https://" . $host . "/" . $path . "/" . $file;
my $res = `curl -L -f -s $url \\
| xmllint --format - \\
| grep -v '\?xml'`;
if ($? != 0) {
print STDERR "Failed to get " . $url . "\n";
exit(1);
}
if ( $alias ne "") {
my $anchor1 = "anchor=\"" . $name . "\"";
my $anchor2 = "anchor=\"" . $alias . "\"";
$res =~ s/$anchor1/$anchor2/;
}
print $res;
}
}