2 # Id: gen-dir-node,v 1.3 2004/04/11 17:56:47 karl Exp
3 # Generate the top-level Info node, given a directory of Info files
4 # and (optionally) a skeleton file. The output will be suitable for a
5 # top-level dir file. The skeleton file contains info topic names in the
6 # order they should appear in the output. There are three special
7 # lines that alter the behavior: a line consisting of just "--" causes
8 # the next line to be echoed verbatim to the output. A line
9 # containing just "%%" causes all the remaining filenames (wildcards
10 # allowed) in the rest of the file to be ignored. A line containing
11 # just "!!" exits the script when reached (unless preceded by a line
12 # containing just "--"). Once the script reaches the end of the
13 # skeleton file, it goes through the remaining files in the directory
14 # in order, putting their entries at the end. The script will use the
15 # ENTRY information in each info file if it exists. Otherwise it will
16 # make a minimal entry.
18 # sent by Jeffrey Osier <jeffrey@cygnus.com>, who thinks it came from
19 # zoo@winternet.com (david d `zoo' zuhn)
21 # modified 7 April 1995 by Joe Harrington <jh@tecate.gsfc.nasa.gov> to
33 if [ $# -gt 2 ] ; then
34 echo usage
: $0 info-directory
[ skeleton-file
] 1>&2
36 elif [ -z "${INFODIR}" ] ; then
37 INFODIR
="%%DEFAULT_INFO_DIR%%"
42 if [ ! -d ${INFODIR} ] ; then
43 echo "$0: first argument must specify a directory"
47 ### output the dir header
49 echo "This file was generated automatically by $0."
50 echo "This version was generated on `date`"
51 echo "by `whoami`@`hostname` for `(cd ${INFODIR}; pwd)`"
54 \Id: gen-dir-node,v 1.3 2004/04/11 17:56:47 karl Exp
55 This is the file .../info/dir, which contains the topmost node of the
56 Info hierarchy. The first time you invoke Info you start off
57 looking at that node, which is (dir)Top.
59 File: dir Node: Top This is the top of the INFO tree
61 This (the Directory node) gives a menu of major topics.
62 Typing "q" exits, "?" lists all Info commands, "d" returns here,
63 "h" gives a primer for first-timers,
64 "mEmacs<Return>" visits the Emacs topic, etc.
66 In Emacs, you can click mouse button 2 on a menu item or cross reference
69 * Menu: The list of major topics begins on the next line.
73 ### go through the list of files in the skeleton. If an info file
74 ### exists, grab the ENTRY information from it. If an entry exists
75 ### use it, otherwise create a minimal dir entry.
77 ### Then remove that file from the list of existing files. If any
78 ### additional files remain (ones that don't have a skeleton entry),
79 ### then generate entries for those in the same way, putting the info for
80 ### those at the end....
82 infofiles
=`(cd ${INFODIR}; /bin/ls | grep -v '\-[0-9]*$' | egrep -v '^dir$|^dir\.info$|^dir\.orig$')`
84 # echoing gets clobbered by backquotes; we do it the hard way...
85 lines
=`wc $SKELETON | awk '{print $1}'`
87 while [ $lines -ge $line ] ; do
88 # Read one line from the file. This is so that we can echo lines with
89 # whitespace and quoted characters in them.
90 fileline
=`awk NR==$line $SKELETON`
93 if [ ! -z "$echoline" ] ; then # echo line
97 elif [ "${fileline}" = "--" ] ; then # should we echo the next line?
99 elif [ "${fileline}" = "%%" ] ; then # eliminate remaining files from dir?
101 elif [ "${fileline}" = "!!" ] ; then # quit now
105 # handle files if they exist
106 for file in $fileline"" ; do # expand wildcards ("" handles blank lines)
110 if [ -z "$echoline" ] && [ ! -z "$file" ] ; then
111 # Find the file to operate upon. Check both possible names.
112 infoname
=`echo $file | sed 's/\.info$//'`
115 if [ -f ${INFODIR}/$infoname ] ; then
118 if [ -f ${INFODIR}/${infoname}.info
] ; then
122 # If it exists with both names take what was said in the file.
123 if [ ! -z "$ext" ] && [ ! -z "$noext" ]; then
125 warn
="### Warning: $ext and $noext both exist! Using ${file}. ###"
126 elif [ ! -z "${noext}${ext}" ]; then
127 # just take the name if it exists only once
131 # if we found something and aren't skipping, do the entry
132 if [ ! -z "$fname" ] ; then
133 if [ -z "$skip" ] ; then
135 if [ ! -z "$warn" ] ; then # issue any warning
140 entry
=`sed -e '1,/START-INFO-DIR-ENTRY/d' \
141 -e '/END-INFO-DIR-ENTRY/,$d' ${INFODIR}/$fname`
142 if [ ! -z "${entry}" ] ; then
145 echo "* ${infoname}: (${infoname})."
149 # remove the name from the directory listing
150 infofiles
=`echo "" ${infofiles} "" | sed -e "s/ ${fname} / /" -e "s/ / /g"`
158 line
=`expr $line + 1`
161 if [ -z "${infofiles}" ] ; then
163 elif [ $lines -gt 0 ]; then
167 # Sort remaining files by INFO-DIR-SECTION.
169 filesectdata
=`(cd ${INFODIR}; fgrep INFO-DIR-SECTION /dev/null ${infofiles} | \
170 fgrep -v 'INFO-DIR-SECTION Miscellaneous' | \
171 sort -t: -k2 -k1 | tr ' ' '_')`
172 for sectdata
in ${filesectdata}; do
173 file=`echo ${sectdata} | cut -d: -f1`
174 section
=`sed -n -e 's/^INFO-DIR-SECTION //p' ${INFODIR}/${file}`
175 infofiles
=`echo "" ${infofiles} "" | sed -e "s/ ${file} / /" -e "s/ / /g"`
177 if [ "${prevsect}" != "${section}" ] ; then
178 if [ ! -z "${prevsect}" ] ; then
182 prevsect
="${section}"
185 infoname
=`echo $file | sed 's/\.info$//'`
186 entry
=`sed -e '1,/START-INFO-DIR-ENTRY/d' \
187 -e '/END-INFO-DIR-ENTRY/,$d' ${INFODIR}/${file}`
188 if [ ! -z "${entry}" ] ; then
190 elif [ ! -d "${INFODIR}/${file}" ] ; then
191 echo "* ${infoname}: (${infoname})."
195 # Process miscellaneous files.
196 for file in ${infofiles}; do
197 if [ ! -z "${prevsect}" ] ; then
203 infoname
=`echo $file | sed 's/\.info$//'`
204 entry
=`sed -e '1,/START-INFO-DIR-ENTRY/d' \
205 -e '/END-INFO-DIR-ENTRY/,$d' ${INFODIR}/${file}`
207 if [ ! -z "${entry}" ] ; then
209 elif [ ! -d "${INFODIR}/${file}" ] ; then
210 echo "* ${infoname}: (${infoname})."