2 # $Id: mkinfodir,v 1.1 2001/09/01 07:56:19 drobbins 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: mkinfodir,v 1.1 2001/09/01 07:56:19 drobbins 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]*\.gz$' | 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" -a ! -z "$file" ] ; then
112 # Find the file to operate upon. Check both possible names.
113 infoname
=`echo $file | sed 's/\.gz$//'`
114 infoname
=`echo $infoname | sed 's/\.info$//'`
117 if [ -f ${INFODIR}/$infoname ] ; then
120 if [ -f ${INFODIR}/${infoname}.info
] ; then
123 if [ -f ${INFODIR}/${infoname}.info.gz
] ; then
124 ext
=${infoname}.info.gz
126 # If it exists with both names take what was said in the file.
127 if [ ! -z "$ext" -a ! -z "$noext" ]; then
129 warn
="### Warning: $ext and $noext both exist! Using ${file}. ###"
130 elif [ ! \
( -z "$ext" -a -z "$noext" \
) ]; then
131 # just take the name if it exists only once
135 # if we found something and aren't skipping, do the entry
136 if [ ! -z "$fname" ] ; then
137 if [ -z "$skip" ] ; then
139 if [ ! -z "$warn" ] ; then # issue any warning
143 if [ "${fname##*.}" = "gz" ] ; then
144 entry
=`zcat ${INFODIR}/${fname} | sed -e '1,/START-INFO-DIR-ENTRY/d' \
145 -e '/END-INFO-DIR-ENTRY/,$d' `
147 entry
=`sed -e '1,/START-INFO-DIR-ENTRY/d' \
148 -e '/END-INFO-DIR-ENTRY/,$d' ${INFODIR}/$fname`
150 if [ ! -z "${entry}" ] ; then
153 echo "* ${infoname}: (${infoname})."
157 # remove the name from the directory listing
158 infofiles
=`echo "" ${infofiles} "" | sed -e "s/ ${fname} / /" -e "s/ / /g"`
166 line
=`expr $line + 1`
169 if [ -z "${infofiles}" ] ; then
171 elif [ $lines -gt 0 ]; then
175 # Sort remaining files by INFO-DIR-SECTION.
177 filesectdata
=`(cd ${INFODIR}; fgrep INFO-DIR-SECTION /dev/null ${infofiles} | \
178 fgrep -v 'INFO-DIR-SECTION Miscellaneous' | \
179 sort -t: -k2 -k1 | tr ' ' '_')`
180 for sectdata
in ${filesectdata}; do
181 file=`echo ${sectdata} | cut -d: -f1`
182 section
=`sed -n -e 's/^INFO-DIR-SECTION //p' ${INFODIR}/${file}`
183 infofiles
=`echo "" ${infofiles} "" | sed -e "s/ ${file} / /" -e "s/ / /g"`
185 if [ "${prevsect}" != "${section}" ] ; then
186 if [ ! -z "${prevsect}" ] ; then
190 prevsect
="${section}"
192 infoname
=`echo $file | sed 's/\.gz$//'`
193 infoname
=`echo $infoname | sed 's/\.info$//'`
194 if [ "${file##*.}" = "gz" ] ; then
195 entry
=`zcat ${INFODIR}/$file | sed -e '1,/START-INFO-DIR-ENTRY/d' \
196 -e '/END-INFO-DIR-ENTRY/,$d' `
198 entry
=`sed -e '1,/START-INFO-DIR-ENTRY/d' \
199 -e '/END-INFO-DIR-ENTRY/,$d' ${INFODIR}/$file`
201 if [ ! -z "${entry}" ] ; then
203 elif [ ! -d "${INFODIR}/${file}" ] ; then
204 echo "* ${infoname}: (${infoname})."
208 # Process miscellaneous files.
209 for file in ${infofiles}; do
210 if [ ! -z "${prevsect}" ] ; then
216 infoname
=`echo $file | sed 's/\.gz$//'`
217 infoname
=`echo $infoname | sed 's/\.info$//'`
218 if [ "${file##*.}" = "gz" ] ; then
219 entry
=`zcat ${INFODIR}/${file} | sed -e '1,/START-INFO-DIR-ENTRY/d' \
220 -e '/END-INFO-DIR-ENTRY/,$d'`
222 entry
=`sed -e '1,/START-INFO-DIR-ENTRY/d' \
223 -e '/END-INFO-DIR-ENTRY/,$d' ${INFODIR}/$file`
227 if [ ! -z "${entry}" ] ; then
229 elif [ ! -d "${INFODIR}/${file}" ] ; then
230 echo "* ${infoname}: (${infoname})."