No empty .Rs/.Re
[netbsd-mini2440.git] / gnu / dist / texinfo / util / gen-dir-node
blob88e0b2d19ac208acdcc9569e7a45235d2322b00c
1 #!/bin/sh
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
22 # take special flags
24 INFODIR=$1
25 if [ $# = 2 ] ; then
26 SKELETON=$2
27 else
28 SKELETON=/dev/null
31 skip=
33 if [ $# -gt 2 ] ; then
34 echo usage: $0 info-directory [ skeleton-file ] 1>&2
35 exit 1
36 elif [ -z "${INFODIR}" ] ; then
37 INFODIR="%%DEFAULT_INFO_DIR%%"
38 else
39 true
42 if [ ! -d ${INFODIR} ] ; then
43 echo "$0: first argument must specify a directory"
44 exit 1
47 ### output the dir header
48 echo "-*- Text -*-"
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)`"
53 cat << moobler
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.
58 \x1f
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
67 to select it.
69 * Menu: The list of major topics begins on the next line.
71 moobler
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.
76 ###
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}'`
86 line=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`
92 # flag fancy features
93 if [ ! -z "$echoline" ] ; then # echo line
94 echo "$fileline"
95 fileline=
96 echoline=
97 elif [ "${fileline}" = "--" ] ; then # should we echo the next line?
98 echoline=1
99 elif [ "${fileline}" = "%%" ] ; then # eliminate remaining files from dir?
100 skip=1
101 elif [ "${fileline}" = "!!" ] ; then # quit now
102 exit 0
105 # handle files if they exist
106 for file in $fileline"" ; do # expand wildcards ("" handles blank lines)
108 fname=
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$//'`
113 noext=
114 ext=
115 if [ -f ${INFODIR}/$infoname ] ; then
116 noext=$infoname
118 if [ -f ${INFODIR}/${infoname}.info ] ; then
119 ext=${infoname}.info
122 # If it exists with both names take what was said in the file.
123 if [ ! -z "$ext" ] && [ ! -z "$noext" ]; then
124 fname=$file
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
128 fname=${noext}${ext}
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
136 echo $warn
137 warn=
140 entry=`sed -e '1,/START-INFO-DIR-ENTRY/d' \
141 -e '/END-INFO-DIR-ENTRY/,$d' ${INFODIR}/$fname`
142 if [ ! -z "${entry}" ] ; then
143 echo "${entry}"
144 else
145 echo "* ${infoname}: (${infoname})."
149 # remove the name from the directory listing
150 infofiles=`echo "" ${infofiles} "" | sed -e "s/ ${fname} / /" -e "s/ / /g"`
156 done
158 line=`expr $line + 1`
159 done
161 if [ -z "${infofiles}" ] ; then
162 exit 0
163 elif [ $lines -gt 0 ]; then
164 echo
167 # Sort remaining files by INFO-DIR-SECTION.
168 prevsect=
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
179 echo ""
181 echo "${section}"
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
189 echo "${entry}"
190 elif [ ! -d "${INFODIR}/${file}" ] ; then
191 echo "* ${infoname}: (${infoname})."
193 done
195 # Process miscellaneous files.
196 for file in ${infofiles}; do
197 if [ ! -z "${prevsect}" ] ; then
198 echo ""
199 echo "Miscellaneous"
200 prevsect=""
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
208 echo "${entry}"
209 elif [ ! -d "${INFODIR}/${file}" ] ; then
210 echo "* ${infoname}: (${infoname})."
212 done