new gcc snapshot
[dottout.git] / net-im / emesene / files / sys-devel / gcc / files / mkinfodir
bloba62840ee86eef3e7bcea2b63c51437d58917ff04
1 #!/bin/bash
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
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: 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.
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]*\.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}'`
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" -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$//'`
115 noext=
116 ext=
117 if [ -f ${INFODIR}/$infoname ] ; then
118 noext=$infoname
120 if [ -f ${INFODIR}/${infoname}.info ] ; then
121 ext=${infoname}.info
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
128 fname=$file
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
132 fname=${noext}${ext}
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
140 echo $warn
141 warn=
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' `
146 else
147 entry=`sed -e '1,/START-INFO-DIR-ENTRY/d' \
148 -e '/END-INFO-DIR-ENTRY/,$d' ${INFODIR}/$fname`
150 if [ ! -z "${entry}" ] ; then
151 echo "${entry}"
152 else
153 echo "* ${infoname}: (${infoname})."
157 # remove the name from the directory listing
158 infofiles=`echo "" ${infofiles} "" | sed -e "s/ ${fname} / /" -e "s/ / /g"`
164 done
166 line=`expr $line + 1`
167 done
169 if [ -z "${infofiles}" ] ; then
170 exit 0
171 elif [ $lines -gt 0 ]; then
172 echo
175 # Sort remaining files by INFO-DIR-SECTION.
176 prevsect=
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
187 echo ""
189 echo "${section}"
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' `
197 else
198 entry=`sed -e '1,/START-INFO-DIR-ENTRY/d' \
199 -e '/END-INFO-DIR-ENTRY/,$d' ${INFODIR}/$file`
201 if [ ! -z "${entry}" ] ; then
202 echo "${entry}"
203 elif [ ! -d "${INFODIR}/${file}" ] ; then
204 echo "* ${infoname}: (${infoname})."
206 done
208 # Process miscellaneous files.
209 for file in ${infofiles}; do
210 if [ ! -z "${prevsect}" ] ; then
211 echo ""
212 echo "Miscellaneous"
213 prevsect=""
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'`
221 else
222 entry=`sed -e '1,/START-INFO-DIR-ENTRY/d' \
223 -e '/END-INFO-DIR-ENTRY/,$d' ${INFODIR}/$file`
227 if [ ! -z "${entry}" ] ; then
228 echo "${entry}"
229 elif [ ! -d "${INFODIR}/${file}" ] ; then
230 echo "* ${infoname}: (${infoname})."
232 done