blob: 746ea6ea83cf14ad74f340eb25684e8ea5b9097e (
plain)
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
|
#!/usr/bin/perl -w
$TOCHEADER=" TABLE OF CONTENTS";
open(O, ">FAQ.html");
# Load FAQ into memory
while(<>) {
push (@faqfile, $_);
}
my $current_line = 0;
my $version;
# Skip header up to table of contents
while($current_line <= $#faqfile) {
$_ = $faqfile[$current_line];
$current_line++;
if (/net-snmp Version: (.*)/) {
$version = $1;
}
last if (/$TOCHEADER/);
}
print O '<p class="SectionTitle">
FAQ
</p>
FAQ Maintainer: Dave Shield<br/>
Email: <a href="mailto:net-snmp-coders@lists.sourceforge.net">net-snmp-coders@list.sourceforge.net</a><br/>
';
print O "Version: $version<br/>\n";
print O '<hr/>
<h2>Table of Contents</h2>
';
# Create table of contents
while($current_line <= $#faqfile) {
$_ = $faqfile[$current_line];
#Skip blank lines
if (/^\s*$/) {
$current_line++;
last;
}
chomp();
# Remove white space at start of line
$_ =~ s/^ *//;
$x = $_;
# Remove white space at start of line
$x =~ s/^ *//g;
# Replace all non alpha characters with _
$x =~ s/[^a-zA-Z]/_/g;
# Save cleaned up line
$xlate{$_} = $x;
if ( /&/ ) { $_ =~ s/&/&/g; }
if ( /</ ) { $_ =~ s/</</g; }
if ( />/ ) { $_ =~ s/>/>/g; }
if (/^[ A-Z]+$/) {
# Section header (eg: GENERAL)
print O "</ul><b>$_</b><ul>\n";
} else {
# Question / answer - create link to it
if ($faqfile[$current_line+1] =~ /^ */) {
# Continuation of the question.
$current_line++;
my $part2 = $faqfile[$current_line];
# Remove white space at start of line
$part2 =~ s/^ *//;
print O "<li> <a href=\"#$x\">$_ $part2</a></li>\n";
}
else {
print O "<li> <a href=\"#$x\">$_</a></li>\n";
}
}
$current_line++;
}
print O "</ul><hr/><pre>\n";
# Print contents with targets defined
while($current_line <= $#faqfile) {
$_ = $faqfile[$current_line];
$current_line++;
chomp();
$y = $_;
if (defined($xlate{$y})) {
print O "<a name=\"$xlate{$y}\"></a>\n";
}
if ( /&/ ) { $_ =~ s/&/&/g; }
if ( /</ ) { $_ =~ s/</</g; }
if ( />/ ) { $_ =~ s/>/>/g; }
print O "$_\n";
}
print O '
</pre>
';
|