]> git.ipfire.org Git - thirdparty/glibc.git/blame - manual/libc-texinfo.sh
Limited tsort replacement.
[thirdparty/glibc.git] / manual / libc-texinfo.sh
CommitLineData
7a68c94a
UD
1#! /bin/sh
2
3# Create libc.texinfo from the chapter files.
4
07435eb4
UD
5trap "rm -f *.$$; exit 1" 1 2 15
6
7exec 3>incl.$$ 4>smenu.$$ 5>lmenu.$$
8
9build_menu () {
10 while IFS=: read file node; do
11 echo "@include $file" >&3
12 echo "* $node:: `sed -n 's/^@c %MENU% //p' $file`" >&4
13 $AWK 'BEGIN { do_menu = 0 }
14 /^@node / { sub(/^@node /, ""); sub(/,.*$/, ""); node = $0 }
15 /^@menu/ { printf "\n%s\n\n", node; do_menu = 1; next }
16 /^@end menu/ { do_menu = 0 }
17 do_menu { print }' $file >&5
18 done
19}
7a68c94a 20
07435eb4 21collect_nodes () {
34992338
UD
22 egrep '^(@c )?@node.*Top' "$@" /dev/null | cut -d, -f-2 |
23 sed 's/@c //; s/, /:/; s/:@node /:/; s/ /_/g; s/:/ /g' |
07435eb4
UD
24 $AWK '{ file[$2] = $1; nnode[$2] = $3 }
25 END { for (x in file)
26 if (file[x] != "")
27 print file[x] ":" x, file[nnode[x]] ":" nnode[x] }' |
28 tsort | sed 's/_/ /g; $d'
7a68c94a
UD
29}
30
07435eb4
UD
31collect_nodes $1 | build_menu
32
33if [ -n "$2" ]; then
34
35 { echo; echo 'Add-ons'; echo; } >&4
36
34992338
UD
37 egrep '^(@c )?@node.*Top' `echo $2 /dev/null | tr ' ' '\n' | sort` |
38 cut -d, -f1 | sed 's/@c //;s/@node //' | build_menu
07435eb4
UD
39
40fi
41
42{ echo; echo 'Appendices'; echo; } >&4
43
44collect_nodes $3 | build_menu
45
46exec 3>&- 4>&- 5>&-
7a68c94a
UD
47
48mv -f incl.$$ chapters.texi
49
07435eb4
UD
50{
51 echo '@menu'
52 $AWK -F: '
53 /^\*/ {
54 printf("%-32s", $1 "::");
55 x = split($3, word, " ");
56 hpos = 34;
57 for (i = 1; i <= x; i++) {
58 hpos += length(word[i]) + 1;
59 if (hpos > 78) {
60 printf("\n%34s", "");
61 hpos = 35 + length(word[i]);
62 }
63 printf(" %s", word[i]);
64 }
65 print ".";
66 }
67
68 !/^\*/ { print; }
69 ' smenu.$$
7a68c94a
UD
70 cat <<EOF
71* Copying:: The GNU Library General Public License says
72 how you can copy and share the GNU C Library.
73
74Indices
75
76* Concept Index:: Index of concepts and names.
77* Type Index:: Index of types and type qualifiers.
78* Function Index:: Index of functions and function-like macros.
79* Variable Index:: Index of variables and variable-like macros.
80* File Index:: Index of programs and files.
81
82 --- The Detailed Node Listing ---
83EOF
84 cat lmenu.$$
07435eb4 85 echo '@end menu'; } >top-menu.texi.$$
7a68c94a
UD
86mv -f top-menu.texi.$$ top-menu.texi
87
88rm -f *.$$