]> git.ipfire.org Git - thirdparty/strongswan.git/blob - doc/utils/contents.awk
- import of strongswan-2.7.0
[thirdparty/strongswan.git] / doc / utils / contents.awk
1 # table-of-contents extractor
2 # Copyright (C) 1999 Sandy Harris.
3 #
4 # This program is free software; you can redistribute it and/or modify it
5 # under the terms of the GNU General Public License as published by the
6 # Free Software Foundation; either version 2 of the License, or (at your
7 # option) any later version. See <http://www.fsf.org/copyleft/gpl.txt>.
8 #
9 # This program is distributed in the hope that it will be useful, but
10 # WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
11 # or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
12 # for more details.
13 #
14 # RCSID $Id: contents.awk,v 1.1 2004/03/15 20:35:24 as Exp $
15 BEGIN {
16 # initialise indent counter
17 indent = 0
18 # define variables for section breaks
19 b0 = "==================================================="
20 b1 = "---------------------------------------------------"
21 b2 = "\t------------------------------------------"
22 # TURN OFF HTML formatting
23 print "<html>"
24 print "<body>"
25 print "<pre>"
26 # print a header
27 blurb()
28 print "Section headings printed, indentation shows structure"
29 }
30 # start of new file
31 FNR == 1 {
32 print b0
33 print "HTML file: " "<a href=\"" FILENAME "\">" FILENAME "</a>"
34 print b1
35 }
36 # print header lines
37 # actual printing is done by tagged() function
38 # which adds tag if last line was <a name=...>
39 $0 ~/<h1>/ {
40 text = $0
41 tabs = ""
42 gsub(/.*<h1>/, "", text)
43 gsub(/<\/h1>/, "", text)
44 tagged( text )
45 }
46 $0 ~/<h2>/ {
47 text = $0
48 tabs = "\t"
49 gsub(/.*<h2>/, "", text)
50 gsub(/<\/h2>/, "", text)
51 tagged(text)
52 }
53 $0 ~/<h3>/ {
54 text = $0
55 tabs = "\t\t"
56 gsub(/.*<h3>/, "", text)
57 gsub(/<\/h3>/, "", text)
58 tagged(text)
59 }
60 $0 ~/<h4>/ {
61 text = $0
62 tabs = "\t\t\t"
63 gsub(/.*<h4>/, "", text)
64 gsub(/<\/h4>/, "", text)
65 tagged( text )
66 }
67 # if current line is not header
68 # and we have stored tag from <a name=..> line
69 # make link to that tag
70 $0 !~ /<h[1-4]/ {
71 if( length(name) )
72 print "[ <a href=\"" FILENAME "#" name "\">" name "</a>" " ]"
73 name = ""
74 }
75 # for <a name=whatever> lines
76 # save name in a variable
77 # not printed until we see next line
78 $0 ~ /<a name=.*>/ {
79 name = $0
80 # strip anything before or after name tag
81 gsub(/.*<a name=/, "", name)
82 gsub(/>.*/, "", name)
83 # strip quotes off name
84 gsub(/^"/, "", name)
85 gsub(/"$/, "", name)
86 }
87 END {
88 print b0
89 blurb()
90 print "Docs & script by Sandy Harris"
91 print "</pre>"
92 print "</body>"
93 print "</html>"
94 }
95
96 function tagged(text) { # print header with tag if available
97 if( length(name) ) # > 0 if previous line was a name
98 print tabs "<a href=\"" FILENAME "#" name "\">" text "</a>"
99 else
100 print tabs text
101 name = ""
102 }
103
104 function blurb() {
105 print "Linux FreeSWAN HTML documents"
106 print "Automatically generated Table of Contents"
107 print "Bug reports to the mailing list: linux-ipsec@clinet.fi"
108 print "<p>"
109 }