No empty .Rs/.Re
[netbsd-mini2440.git] / gnu / dist / texinfo / util / outline.gawk
blob329bb17529ae82c159cd8f68ac682d03f54f2504
1 #! /usr/local/bin/gawk -f
3 # texi.outline --- produce an outline from a texinfo source file
4 #
5 # Copyright (C) 1998 Arnold David Robbins (arnold@gnu.org)
6 #
7 # TEXI.OUTLINE is free software; you can redistribute it and/or modify
8 # it under the terms of the GNU General Public License as published by
9 # the Free Software Foundation; either version 2 of the License, or
10 # (at your option) any later version.
12 # TEXI.OUTLINE is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 # GNU General Public License for more details.
17 # You should have received a copy of the GNU General Public License
18 # along with this program; if not, write to the Free Software
19 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA
21 # NOTE:
22 # This program uses gensub(), which is specific to gawk.
23 # With some work (split, substr, etc), it could be made to work
24 # on other awks, but it's not worth the trouble for me.
26 BEGIN \
28 # Levels at which different nodes can be
29 Level["@top"] = 0
30 Level["@appendix"] = 1
31 Level["@chapter"] = 1
32 Level["@majorheading"] = 1
33 Level["@unnumbered"] = 1
34 Level["@appendixsec"] = 2
35 Level["@heading"] = 2
36 Level["@section"] = 2
37 Level["@unnumberedsec"] = 2
38 Level["@unnumberedsubsec"] = 3
39 Level["@appendixsubsec"] = 3
40 Level["@subheading"] = 3
41 Level["@subsection"] = 3
42 Level["@appendixsubsubsec"] = 4
43 Level["@subsubheading"] = 4
44 Level["@subsubsection"] = 4
45 Level["@unnumberedsubsubsec"] = 4
47 # insure that we were called correctly
48 if (ARGC != 2) {
49 printf("usage: %s texinfo-file\n", ARGV[0]) > "/dev/stderr"
50 exit 1
53 # init header counters
54 app_letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
55 app_h = 0
56 l1_h = l2_h = l3_h = l4_h = 0
59 # skip lines we're not interested in
60 /^[^@]/ || ! ($1 in Level) { next }
62 Level[$1] == 1 {
63 if ($1 !~ /^@unnumbered/ || $1 !~ /heading/)
64 l1_h++
65 l2_h = l3_h = l4_h = 0
66 Ntabs = 0
67 Number = makenumber($1)
68 Title = maketitle($0)
69 print_title()
72 Level[$1] == 2 {
73 l2_h++
74 l3_h = l4_h = 0
75 Ntabs = 1
76 Number = makenumber($1)
77 Title = maketitle($0)
78 print_title()
81 Level[$1] == 3 {
82 l3_h++
83 l4_h = 0
84 Ntabs = 2
85 Number = makenumber($1)
86 Title = maketitle($0)
87 print_title()
90 Level[$1] == 4 {
91 l4_h++
92 Ntabs = 3
93 Number = makenumber($1)
94 Title = maketitle($0)
95 print_title()
98 # maketitle --- extract title
100 function maketitle(str, text)
102 $1 = "" # clobber section keyword
103 text = $0
104 gsub(/^[ \t]*/, "", text)
105 text = gensub(/@[a-z]+{/, "", "g", text)
106 text = gensub(/([^@])}/, "\\1", "g", text)
107 return text
110 # print_title --- print the title
112 function print_title( i)
114 for (i = 1; i <= Ntabs; i++)
115 printf "\t"
116 printf("%s %s\n", Number, Title)
119 # makenumber --- construct a heading number from levels and section command
121 function makenumber(command, result, lev1)
123 result = ""
124 if (command ~ /^@appendix/) {
125 if (Level[command] == 1)
126 app_h++
128 lev1 = substr(app_letters, app_h, 1)
129 } else if (command ~ /^@unnumbered/ || command ~ /heading/) {
130 lev1 = "(unnumbered)"
131 } else
132 lev1 = l1_h ""
134 result = lev1 "."
135 if (l2_h > 0) {
136 result = result l2_h "."
137 if (l3_h > 0) {
138 result = result l3_h "."
139 if (l4_h > 0) {
140 result = result l4_h "."
144 return result