/
headers.pl
69 lines (47 loc) · 1.11 KB
/
headers.pl
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
#!/usr/bin/perl -w
use strict;
my $sect_level = 0;
my $sect_1_count = 1;
my $sect_2_count = 1;
#############
# FUNCTIONS #
#############
# set this to false at the beginning of each file
# to knock out the chapter header
my $do_print = 0;
my $filename;
my $anchor;
while (<>) {
if (/<?headings/) {
$filename = $_;
$filename =~ s/^.*<?headings \"//;
$filename =~ s/\".*$//;
chop $filename;
# print "opening \"$filename\"\n";
open(INPUT, $filename) or print "cant open $filename\n";
#search for subheadings
# set this to false at the beginning of each file
# to knock out the chapter header
$do_print = 0;
print " <orderedlist>\n";
while (<INPUT>) {
if (/<sect1>/) {
$do_print = 1;
} elsif (/<sect2>/) {
$do_print = 0;
} elsif (/<\/sect2>/) {
$do_print = 1;
} elsif (/<title id=/ && $do_print) {
$_ =~ s/.*<title id=\"//;
$anchor = $_;
$anchor =~ s/\"?>.*//;
chop $anchor;
print " <listitem> <ulink url=\"$filename#$anchor\"> $anchor </ulink> </listitem>\n";
}
}
close(INPUT);
print " </orderedlist>\n";
} else {
print "$_";
}
}