File: FAQ2HTML

package info (click to toggle)
net-snmp 5.2.3-7etch4
  • links: PTS
  • area: main
  • in suites: etch
  • size: 24,452 kB
  • ctags: 16,045
  • sloc: ansic: 175,930; perl: 11,814; sh: 11,230; makefile: 5,375; pascal: 62
file content (105 lines) | stat: -rwxr-xr-x 2,152 bytes parent folder | download | duplicates (2)
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
#!/usr/bin/perl -w

$TOCHEADER=" TABLE OF CONTENTS";

open(O, ">FAQ.html");

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/>
<hr/>
<h2>Table of Contents</h2>
';

# Load FAQ into memory
while(<>) {
  push (@faqfile, $_);
}
my $current_line = 0;

# Skip header up to table of contents
while($current_line <= $#faqfile) {
    $_ = $faqfile[$current_line];
    $current_line++;

    last if (/$TOCHEADER/);
}

# 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/&/&amp;/g; }
    if ( /</ ) { $_ =~ s/</&lt;/g; }
    if ( />/ ) { $_ =~ s/>/&gt;/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/&/&amp;/g; }
    if ( /</ ) { $_ =~ s/</&lt;/g; }
    if ( />/ ) { $_ =~ s/>/&gt;/g; }
    print O "$_\n";
}

print O '
</pre>
';