-
Notifications
You must be signed in to change notification settings - Fork 709
/
Copy pathmkchain
77 lines (65 loc) · 2.03 KB
/
mkchain
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
#!/usr/local/bin/perl
#
# Insert Next, ToC, Prev, and other links.
#
# The given configuration file contains ordering and
# numbering information
#
# Bert Bos <bert@w3.org>
# $Id: mkchain,v 2.4 2006-10-09 18:55:52 ihickson Exp $
use Getopt::Std;
use lib 'bin';
use utils;
my $PROG = substr($0, rindex($0, "/") + 1);
my $USAGE = "Usage: $PROG [-r real-name] [-c configfile] [file [output]]\n";
getopts('r:c:') or die $USAGE;
if ($#ARGV >= 0) {$input = $ARGV[0]; shift;} else {$input = '-';}
if ($#ARGV >= 0) {$output = $ARGV[0]; shift;} else {$output = '-';}
if ($#ARGV >= 0) {die $USAGE;}
my $name = defined $opt_r ? $opt_r : $input;
my $configfile = defined $opt_c ? $opt_c : 'Project.cfg';
# Read configuratio and find info about current file
read_config($configfile);
defined $lookup{$name} or die "$PROG: $name not found in config file\n";
$chapno = $lookup{$name};
# Insert the links after the </TITLE> tag. (There better be one!)
open(IN, $input) or die "$PROG: cannot read file $input\n";
open(OUT, ">$output") or die "$PROG: cannot write to file $output\n";
my $done = 0;
while (<IN>) {
/<\/title[^>]*>/io and do {
print OUT $`;
print OUT $&;
for ($i = 0; $i <= $#stylesheet; $i++) {
print OUT "\n<link rel=\"stylesheet\" href=\"$stylesheet[$i]\"";
if ($styletype[$i] ne '') {print OUT " type=\"$styletype[$i]\"";}
print OUT ">";
}
if ($chapno > 0) {
print OUT "\n<link rel=\"prev\" href=\"$chapter[$chapno-1]\">";
}
if ($chapno < $#chapter) {
print OUT "\n<link rel=\"next\" href=\"$chapter[$chapno+1]\">";
}
if ($contents ne '') {
print OUT "\n<link rel=\"contents\" href=\"$contents\">";
}
for ($i = 0; $i <= $#links; $i++) {
print OUT "\n<link rel=\"$relations[$i]\" href=\"$links[$i]\"";
if ($tonavbar[$i] ne '') {print OUT " title=\"$tonavbar[$i]\"";}
print OUT ">";
}
print OUT $';
$done = 1;
last;
};
print OUT;
}
# Copy the rest of the file
while (<IN>) {
print OUT;
}
if (! $done) {die "$PROG: $input had no <TITLE>; no links inserted\n";}
# Finalize
close(IN);
close(OUT);