408.4.87
by Arnold D. Robbins
New file in helpers. |
1 |
#! /usr/local/bin2/gawk -f
|
2 |
||
3 |
# do.outline --- produce an outline of a texinfo document
|
|
4 |
||
5 |
BEGIN { |
|
6 |
# manifest constants
|
|
7 |
TRUE = 1 |
|
8 |
FALSE = 0 |
|
9 |
||
10 |
# Levels at which different nodes can be
|
|
11 |
Level["@top"] = 0 |
|
12 |
Level["@appendix"] = 1 |
|
13 |
Level["@chapter"] = 1 |
|
14 |
Level["@majorheading"] = 1 |
|
15 |
Level["@unnumbered"] = 1 |
|
16 |
Level["@preface"] = 1 |
|
17 |
Level["@appendixsec"] = 2 |
|
18 |
Level["@heading"] = 2 |
|
19 |
Level["@section"] = 2 |
|
20 |
Level["@unnumberedsec"] = 2 |
|
21 |
Level["@unnumberedsubsec"] = 3 |
|
22 |
Level["@appendixsubsec"] = 3 |
|
23 |
Level["@subheading"] = 3 |
|
24 |
Level["@subsection"] = 3 |
|
25 |
Level["@appendixsubsubsec"] = 4 |
|
26 |
Level["@subsubheading"] = 4 |
|
27 |
Level["@subsubsection"] = 4 |
|
28 |
Level["@unnumberedsubsubsec"] = 4 |
|
29 |
||
30 |
ah = bh = ch = 0 |
|
31 |
||
32 |
appendix = 0 |
|
33 |
}
|
|
34 |
||
35 |
/^@ignore/ && Pass == 1, /^@end[ \t]+ignore/ && Pass == 1 { |
|
36 |
next
|
|
37 |
}
|
|
38 |
||
39 |
||
40 |
$1 in Level { |
|
41 |
# save type
|
|
42 |
type = $1 |
|
43 |
||
44 |
lev = Level[$1] |
|
45 |
||
46 |
if (lev == 1 && tolower($0) !~ /preface|foreword/) { |
|
47 |
if ($1 == "@appendix") { |
|
48 |
appendix = next_appendix(appendix) |
|
49 |
ah = appendix |
|
50 |
} else |
|
51 |
ah++ |
|
52 |
bh = ch = dh = 0 |
|
53 |
} else if (lev == 2) { |
|
54 |
bh++ |
|
55 |
ch = dh = 0 |
|
56 |
} else if (lev == 3) { |
|
57 |
ch++ |
|
58 |
dh = 0 |
|
59 |
} else if (lev == 4) |
|
60 |
dh++ |
|
61 |
||
62 |
Unnumbered = ($1 ~ /^@unnumbered/) |
|
63 |
||
64 |
$1 = "" |
|
65 |
$0 = preprocess($0) |
|
66 |
||
67 |
for (i = 1; i < lev; i++) |
|
68 |
printf "\t" |
|
69 |
||
70 |
if (! Unnumbered) { |
|
71 |
printf("%s.", ah) |
|
72 |
if (bh) |
|
73 |
printf("%d.", bh) |
|
74 |
if (ch) |
|
75 |
printf("%d.", ch) |
|
76 |
if (dh) |
|
77 |
printf("%d.", dh) |
|
78 |
}
|
|
79 |
||
80 |
printf("%s\n", $0) |
|
81 |
}
|
|
82 |
||
83 |
function preprocess(record) |
|
84 |
{
|
|
85 |
record = gensub(/@(code|command|samp|env)\{([^\}]+)\}/, "\\2", "g", record) |
|
86 |
record = gensub(/@dots\{\}/, "...", "g", record) |
|
87 |
||
88 |
return record |
|
89 |
}
|
|
90 |
||
91 |
function next_appendix(cur, ind, letters) |
|
92 |
{
|
|
93 |
if (cur == 0) |
|
94 |
return "A" # first time |
|
95 |
||
96 |
letters = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" |
|
97 |
ind = index(letters, cur) |
|
98 |
if (ind > 0 && ind <= 26) |
|
99 |
return substr(letters, ++ind, 1) |
|
100 |
||
101 |
return "Z" |
|
102 |
}
|