libc-texinfo.sh 2.3 KB

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