| 1 |
#!/usr/bin/perl -w |
| 2 |
|
| 3 |
$TOCHEADER=" TABLE OF CONTENTS"; |
| 4 |
|
| 5 |
open(O, ">FAQ.html"); |
| 6 |
|
| 7 |
|
| 8 |
# Load FAQ into memory |
| 9 |
while(<>) { |
| 10 |
push (@faqfile, $_); |
| 11 |
} |
| 12 |
my $current_line = 0; |
| 13 |
my $version; |
| 14 |
|
| 15 |
# Skip header up to table of contents |
| 16 |
while($current_line <= $#faqfile) { |
| 17 |
$_ = $faqfile[$current_line]; |
| 18 |
$current_line++; |
| 19 |
|
| 20 |
if (/Net-SNMP Version: (.*)/) { |
| 21 |
$version = $1; |
| 22 |
} |
| 23 |
|
| 24 |
last if (/$TOCHEADER/); |
| 25 |
} |
| 26 |
|
| 27 |
print O '<p class="SectionTitle"> |
| 28 |
FAQ |
| 29 |
</p> |
| 30 |
FAQ Maintainer: Dave Shield<br/> |
| 31 |
Email: <a href="mailto:[email protected]">[email protected]</a><br/> |
| 32 |
'; |
| 33 |
print O "Version: $version<br/>\n"; |
| 34 |
print O '<hr/> |
| 35 |
<h2>Table of Contents</h2> |
| 36 |
'; |
| 37 |
|
| 38 |
# Create table of contents |
| 39 |
while($current_line <= $#faqfile) { |
| 40 |
$_ = $faqfile[$current_line]; |
| 41 |
|
| 42 |
#Skip blank lines |
| 43 |
if (/^\s*$/) { |
| 44 |
$current_line++; |
| 45 |
last; |
| 46 |
} |
| 47 |
|
| 48 |
chomp(); |
| 49 |
|
| 50 |
# Remove white space at start of line |
| 51 |
$_ =~ s/^ *//; |
| 52 |
|
| 53 |
$x = $_; |
| 54 |
|
| 55 |
# Remove white space at start of line |
| 56 |
$x =~ s/^ *//g; |
| 57 |
|
| 58 |
# Replace all non alpha characters with _ |
| 59 |
$x =~ s/[^a-zA-Z]/_/g; |
| 60 |
|
| 61 |
# Save cleaned up line |
| 62 |
$xlate{$_} = $x; |
| 63 |
|
| 64 |
if ( /&/ ) { $_ =~ s/&/&/g; } |
| 65 |
if ( /</ ) { $_ =~ s/</</g; } |
| 66 |
if ( />/ ) { $_ =~ s/>/>/g; } |
| 67 |
if (/^[ A-Z]+$/) { |
| 68 |
# Section header (eg: GENERAL) |
| 69 |
print O "</ul><b>$_</b><ul>\n"; |
| 70 |
} else { |
| 71 |
# Question / answer - create link to it |
| 72 |
if ($faqfile[$current_line+1] =~ /^ */) { |
| 73 |
|
| 74 |
# Continuation of the question. |
| 75 |
$current_line++; |
| 76 |
my $part2 = $faqfile[$current_line]; |
| 77 |
|
| 78 |
# Remove white space at start of line |
| 79 |
$part2 =~ s/^ *//; |
| 80 |
|
| 81 |
print O "<li> <a href=\"#$x\">$_ $part2</a></li>\n"; |
| 82 |
} |
| 83 |
else { |
| 84 |
print O "<li> <a href=\"#$x\">$_</a></li>\n"; |
| 85 |
} |
| 86 |
} |
| 87 |
$current_line++; |
| 88 |
} |
| 89 |
|
| 90 |
print O "</ul><hr/><pre>\n"; |
| 91 |
|
| 92 |
# Print contents with targets defined |
| 93 |
while($current_line <= $#faqfile) { |
| 94 |
$_ = $faqfile[$current_line]; |
| 95 |
$current_line++; |
| 96 |
|
| 97 |
chomp(); |
| 98 |
|
| 99 |
$y = $_; |
| 100 |
|
| 101 |
if (defined($xlate{$y})) { |
| 102 |
print O "<a name=\"$xlate{$y}\"></a>\n"; |
| 103 |
} |
| 104 |
if ( /&/ ) { $_ =~ s/&/&/g; } |
| 105 |
if ( /</ ) { $_ =~ s/</</g; } |
| 106 |
if ( />/ ) { $_ =~ s/>/>/g; } |
| 107 |
print O "$_\n"; |
| 108 |
} |
| 109 |
|
| 110 |
print O ' |
| 111 |
</pre> |
| 112 |
'; |
| 113 |
|