2005-01-28 Martin Schwidefsky <schwidefsky@de.ibm.com>
[glibc.git] / manual / libc-texinfo.sh
blob79ac9773ee1c1f2705ec24c09cd0eccc725c324e
1 #! /bin/sh
3 # Create libc.texinfo from the chapter files.
5 trap "rm -f *.$$; exit 1" 1 2 15
7 exec 3>incl.$$ 4>smenu.$$ 5>lmenu.$$
9 build_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
21 collect_nodes () {
22 egrep '^(@c )?@node.*Top' "$@" /dev/null | cut -d, -f-2 |
23 sed 's/@c //; s/, /:/; s/:@node /:/; s/ /_/g; s/:/ /g' |
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 $AWK -f tsort.awk | sed 's/_/ /g'
31 # Emit "@set ADD-ON" for each add-on contributing a manual chapter.
32 for addon in $2; do
33 addon=`basename $addon .texi`
34 echo >&3 "@set $addon"
35 done
37 collect_nodes $1 | build_menu
39 if [ -n "$2" ]; then
41 { echo; echo 'Add-ons'; echo; } >&4
43 egrep '^(@c )?@node.*Top' `echo $2 /dev/null | tr ' ' '\n' | sort` |
44 cut -d, -f1 | sed 's/@c //;s/@node //' | build_menu
48 { echo; echo 'Appendices'; echo; } >&4
50 collect_nodes $3 | build_menu
52 exec 3>&- 4>&- 5>&-
54 mv -f incl.$$ chapters.texi
57 echo '@menu'
58 $AWK -F: '
59 /^\*/ {
60 printf("%-32s", $1 "::");
61 x = split($3, word, " ");
62 hpos = 34;
63 for (i = 1; i <= x; i++) {
64 hpos += length(word[i]) + 1;
65 if (hpos > 78) {
66 printf("\n%34s", "");
67 hpos = 35 + length(word[i]);
69 printf(" %s", word[i]);
71 print ".";
74 !/^\*/ { print; }
75 ' smenu.$$
76 cat <<EOF
77 * Free Manuals:: Free Software Needs Free Documentation.
78 * Copying:: The GNU Lesser General Public License says
79 how you can copy and share the GNU C Library.
80 * Documentation License:: This manual is under the GNU Free
81 Documentation License.
83 Indices
85 * Concept Index:: Index of concepts and names.
86 * Type Index:: Index of types and type qualifiers.
87 * Function Index:: Index of functions and function-like macros.
88 * Variable Index:: Index of variables and variable-like macros.
89 * File Index:: Index of programs and files.
91 --- The Detailed Node Listing ---
92 EOF
93 cat lmenu.$$
94 echo '@end menu'; } >top-menu.texi.$$
95 mv -f top-menu.texi.$$ top-menu.texi
97 rm -f *.$$