gen-dir-node 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  1. #!/bin/sh
  2. # Generate the top-level Info node, given a directory of Info files
  3. # and (optionally) a skeleton file. The output will be suitable for a
  4. # top-level dir file. The skeleton file contains info topic names in the
  5. # order they should appear in the output. There are three special
  6. # lines that alter the behavior: a line consisting of just "--" causes
  7. # the next line to be echoed verbatim to the output. A line
  8. # containing just "%%" causes all the remaining filenames (wildcards
  9. # allowed) in the rest of the file to be ignored. A line containing
  10. # just "!!" exits the script when reached (unless preceded by a line
  11. # containing just "--"). Once the script reaches the end of the
  12. # skeleton file, it goes through the remaining files in the directory
  13. # in order, putting their entries at the end. The script will use the
  14. # ENTRY information in each info file if it exists. Otherwise it will
  15. # make a minimal entry.
  16. # sent by Jeffrey Osier <jeffrey@cygnus.com>, who thinks it came from
  17. # zoo@winternet.com (david d `zoo' zuhn)
  18. # modified 7 April 1995 by Joe Harrington <jh@tecate.gsfc.nasa.gov> to
  19. # take special flags
  20. INFODIR=$1
  21. if [ $# = 2 ] ; then
  22. SKELETON=$2
  23. else
  24. SKELETON=/dev/null
  25. fi
  26. skip=
  27. if [ $# -gt 2 ] ; then
  28. echo usage: $0 info-directory [ skeleton-file ] 1>&2
  29. exit 1
  30. elif [ -z "${INFODIR}" ] ; then
  31. INFODIR="%%DEFAULT_INFO_DIR%%"
  32. else
  33. true
  34. fi
  35. if [ ! -d ${INFODIR} ] ; then
  36. echo "$0: first argument must specify a directory"
  37. exit 1
  38. fi
  39. ### output the dir header
  40. echo "-*- Text -*-"
  41. echo "This file was generated automatically by $0."
  42. echo "This version was generated on `date`"
  43. echo "by `whoami`@`hostname` for `(cd ${INFODIR}; pwd)`"
  44. cat << moobler
  45. \$Id: gen-dir-node,v 1.1 2013-01-02 01:00:25 karl Exp $
  46. This is the file .../info/dir, which contains the topmost node of the
  47. Info hierarchy. The first time you invoke Info you start off
  48. looking at that node, which is (dir)Top.
  49. 
  50. File: dir Node: Top This is the top of the INFO tree
  51. This (the Directory node) gives a menu of major topics.
  52. Typing "q" exits, "?" lists all Info commands, "d" returns here,
  53. "h" gives a primer for first-timers,
  54. "mEmacs<Return>" visits the Emacs topic, etc.
  55. In Emacs, you can click mouse button 2 on a menu item or cross reference
  56. to select it.
  57. * Menu: The list of major topics begins on the next line.
  58. moobler
  59. ### go through the list of files in the skeleton. If an info file
  60. ### exists, grab the ENTRY information from it. If an entry exists
  61. ### use it, otherwise create a minimal dir entry.
  62. ###
  63. ### Then remove that file from the list of existing files. If any
  64. ### additional files remain (ones that don't have a skeleton entry),
  65. ### then generate entries for those in the same way, putting the info for
  66. ### those at the end....
  67. infofiles=`(cd ${INFODIR}; /bin/ls | grep -v '\-[0-9]*$' | egrep -v '^dir$|^dir\.info$|^dir\.orig$')`
  68. # echoing gets clobbered by backquotes; we do it the hard way...
  69. lines=`wc $SKELETON | awk '{print $1}'`
  70. line=1
  71. while [ $lines -ge $line ] ; do
  72. # Read one line from the file. This is so that we can echo lines with
  73. # whitespace and quoted characters in them.
  74. fileline=`awk NR==$line $SKELETON`
  75. # flag fancy features
  76. if [ ! -z "$echoline" ] ; then # echo line
  77. echo "$fileline"
  78. fileline=
  79. echoline=
  80. elif [ "${fileline}" = "--" ] ; then # should we echo the next line?
  81. echoline=1
  82. elif [ "${fileline}" = "%%" ] ; then # eliminate remaining files from dir?
  83. skip=1
  84. elif [ "${fileline}" = "!!" ] ; then # quit now
  85. exit 0
  86. fi
  87. # handle files if they exist
  88. for file in $fileline"" ; do # expand wildcards ("" handles blank lines)
  89. fname=
  90. if [ -z "$echoline" ] && [ ! -z "$file" ] ; then
  91. # Find the file to operate upon. Check both possible names.
  92. infoname=`echo $file | sed 's/\.info$//'`
  93. noext=
  94. ext=
  95. if [ -f ${INFODIR}/$infoname ] ; then
  96. noext=$infoname
  97. fi
  98. if [ -f ${INFODIR}/${infoname}.info ] ; then
  99. ext=${infoname}.info
  100. fi
  101. # If it exists with both names take what was said in the file.
  102. if [ ! -z "$ext" ] && [ ! -z "$noext" ]; then
  103. fname=$file
  104. warn="### Warning: $ext and $noext both exist! Using ${file}. ###"
  105. elif [ ! -z "${noext}${ext}" ]; then
  106. # just take the name if it exists only once
  107. fname=${noext}${ext}
  108. fi
  109. # if we found something and aren't skipping, do the entry
  110. if [ ! -z "$fname" ] ; then
  111. if [ -z "$skip" ] ; then
  112. if [ ! -z "$warn" ] ; then # issue any warning
  113. echo $warn
  114. warn=
  115. fi
  116. entry=`sed -e '1,/START-INFO-DIR-ENTRY/d' \
  117. -e '/END-INFO-DIR-ENTRY/,$d' ${INFODIR}/$fname`
  118. if [ ! -z "${entry}" ] ; then
  119. echo "${entry}"
  120. else
  121. echo "* ${infoname}: (${infoname})."
  122. fi
  123. fi
  124. # remove the name from the directory listing
  125. infofiles=`echo "" ${infofiles} "" | sed -e "s/ ${fname} / /" -e "s/ / /g"`
  126. fi
  127. fi
  128. done
  129. line=`expr $line + 1`
  130. done
  131. if [ -z "${infofiles}" ] ; then
  132. exit 0
  133. elif [ $lines -gt 0 ]; then
  134. echo
  135. fi
  136. # Sort remaining files by INFO-DIR-SECTION.
  137. prevsect=
  138. filesectdata=`(cd ${INFODIR}; fgrep INFO-DIR-SECTION /dev/null ${infofiles} | \
  139. fgrep -v 'INFO-DIR-SECTION Miscellaneous' | \
  140. sort -t: -k2 -k1 | tr ' ' '_')`
  141. for sectdata in ${filesectdata}; do
  142. file=`echo ${sectdata} | cut -d: -f1`
  143. section=`sed -n -e 's/^INFO-DIR-SECTION //p' ${INFODIR}/${file}`
  144. infofiles=`echo "" ${infofiles} "" | sed -e "s/ ${file} / /" -e "s/ / /g"`
  145. if [ "${prevsect}" != "${section}" ] ; then
  146. if [ ! -z "${prevsect}" ] ; then
  147. echo ""
  148. fi
  149. echo "${section}"
  150. prevsect="${section}"
  151. fi
  152. infoname=`echo $file | sed 's/\.info$//'`
  153. entry=`sed -e '1,/START-INFO-DIR-ENTRY/d' \
  154. -e '/END-INFO-DIR-ENTRY/,$d' ${INFODIR}/${file}`
  155. if [ ! -z "${entry}" ] ; then
  156. echo "${entry}"
  157. elif [ ! -d "${INFODIR}/${file}" ] ; then
  158. echo "* ${infoname}: (${infoname})."
  159. fi
  160. done
  161. # Process miscellaneous files.
  162. for file in ${infofiles}; do
  163. if [ ! -z "${prevsect}" ] ; then
  164. echo ""
  165. echo "Miscellaneous"
  166. prevsect=""
  167. fi
  168. infoname=`echo $file | sed 's/\.info$//'`
  169. entry=`sed -e '1,/START-INFO-DIR-ENTRY/d' \
  170. -e '/END-INFO-DIR-ENTRY/,$d' ${INFODIR}/${file}`
  171. if [ ! -z "${entry}" ] ; then
  172. echo "${entry}"
  173. elif [ ! -d "${INFODIR}/${file}" ] ; then
  174. echo "* ${infoname}: (${infoname})."
  175. fi
  176. done