1 #! /usr/local/bin/gawk -f
3 # texi.outline --- produce an outline from a texinfo source file
5 # Copyright (C) 1998 Arnold David Robbins (arnold@gnu.org)
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
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.
28 # Levels at which different nodes can be
30 Level
["@appendix"] =
1
32 Level
["@majorheading"] =
1
33 Level
["@unnumbered"] =
1
34 Level
["@appendixsec"] =
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
49 printf("usage: %s texinfo-file\n", ARGV[0]) > "/dev/stderr"
53 # init header counters
54 app_letters =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
56 l1_h = l2_h = l3_h = l4_h =
0
59 # skip lines we're not interested in
60 /^
[^@
]/ || !
($
1 in Level
) { next }
63 if ($
1 !~
/^@unnumbered
/ || $
1 !~
/heading
/)
65 l2_h = l3_h = l4_h =
0
67 Number = makenumber
($
1)
76 Number = makenumber
($
1)
85 Number = makenumber
($
1)
93 Number = makenumber
($
1)
98 # maketitle --- extract title
100 function maketitle
(str
, text
)
102 $
1 =
"" # clobber section keyword
104 gsub(/^
[ \t]*/, "", text
)
105 text = gensub
(/@
[a
-z
]+{/, "", "g", text
)
106 text = gensub
(/([^@
])}/, "\\1", "g", text
)
110 # print_title --- print the title
112 function print_title
( i
)
114 for (i =
1; i
<= Ntabs
; i
++)
116 printf("%s %s\n", Number
, Title
)
119 # makenumber --- construct a heading number from levels and section command
121 function makenumber
(command
, result
, lev1
)
124 if (command ~
/^@appendix
/) {
125 if (Level
[command
] ==
1)
128 lev1 =
substr(app_letters
, app_h
, 1)
129 } else if (command ~
/^@unnumbered
/ || command ~
/heading
/) {
130 lev1 =
"(unnumbered)"
136 result = result l2_h
"."
138 result = result l3_h
"."
140 result = result l4_h
"."