PageRenderTime 73ms CodeModel.GetById 46ms RepoModel.GetById 1ms app.codeStats 0ms

/openswan/doc/utils/contents.awk

https://bitbucket.org/thelearninglabs/uclinux-distro-tll-public
AWK | 109 lines | 77 code | 2 blank | 30 comment | 0 complexity | cc97314e906e753a023a63231890517e MD5 | raw file
Possible License(s): LGPL-2.1, BSD-3-Clause, MPL-2.0-no-copyleft-exception, LGPL-3.0, Unlicense, GPL-2.0, GPL-3.0, CC-BY-SA-3.0, AGPL-1.0, ISC, MIT, 0BSD, LGPL-2.0
  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 2001/01/29 01:18:07 sandy 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. function tagged(text) { # print header with tag if available
  96. if( length(name) ) # > 0 if previous line was a name
  97. print tabs "<a href=\"" FILENAME "#" name "\">" text "</a>"
  98. else
  99. print tabs text
  100. name = ""
  101. }
  102. function blurb() {
  103. print "Linux FreeSWAN HTML documents"
  104. print "Automatically generated Table of Contents"
  105. print "Bug reports to the mailing list: linux-ipsec@clinet.fi"
  106. print "<p>"
  107. }