Contents of /branches/mage-next/src/mkinfodir.in
Parent Directory | Revision Log
Revision 2916 -
(show annotations)
(download)
Mon Nov 30 13:51:05 2015 UTC (8 years, 5 months ago) by niro
File size: 7896 byte(s)
Mon Nov 30 13:51:05 2015 UTC (8 years, 5 months ago) by niro
File size: 7896 byte(s)
-added some sanity checks
1 | #!/bin/bash |
2 | # $Id: mkinfodir,v 1.7 2005-06-01 15:48:42 niro 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. |
17 | |
18 | # sent by Jeffrey Osier <jeffrey@cygnus.com>, who thinks it came from |
19 | # zoo@winternet.com (david d `zoo' zuhn) |
20 | |
21 | # modified 7 April 1995 by Joe Harrington <jh@tecate.gsfc.nasa.gov> to |
22 | # take special flags |
23 | |
24 | # $Id$ |
25 | |
26 | INFODIR=$1 |
27 | if [ $# = 2 ] ; then |
28 | SKELETON=$2 |
29 | else |
30 | SKELETON=/dev/null |
31 | fi |
32 | |
33 | skip= |
34 | |
35 | if [ $# -gt 2 ] ; then |
36 | echo usage: $0 info-directory [ skeleton-file ] 1>&2 |
37 | exit 1 |
38 | elif [ -z "${INFODIR}" ] ; then |
39 | INFODIR="%%DEFAULT_INFO_DIR%%" |
40 | else |
41 | true |
42 | fi |
43 | |
44 | if [ ! -d ${INFODIR} ] ; then |
45 | echo "$0: first argument must specify a directory" |
46 | exit 1 |
47 | fi |
48 | |
49 | # sanity checks |
50 | if [[ -x $(type -P date) ]] |
51 | then |
52 | _DATE="$(date)" |
53 | else |
54 | _DATE="unknown date" |
55 | fi |
56 | if [[ -x $(type -P whoami) ]] |
57 | then |
58 | _WHOAMI="$(whoami)" |
59 | else |
60 | if [[ -n ${USER} ]] |
61 | then |
62 | _WHOAMI="${USER}" |
63 | else |
64 | _WHOAMI="unknown user" |
65 | fi |
66 | fi |
67 | if [[ -x $(type -P hostname) ]] |
68 | then |
69 | _HOSTNAME="$(hostname)" |
70 | else |
71 | if [[ -n ${HOSTNAME} ]] |
72 | then |
73 | _HOSTNAME="${HOSTNAME}" |
74 | else |
75 | _HOSTNAME="unknown hostname" |
76 | fi |
77 | fi |
78 | if [[ -x $(type -P pwd) ]] |
79 | then |
80 | _PWD="$(cd ${INFODIR}; pwd)" |
81 | else |
82 | if [[ -n ${PWD} ]] |
83 | then |
84 | _PWD="$(cd ${INFODIR}; echo $PWD)" |
85 | else |
86 | _PWD="unknown directory" |
87 | fi |
88 | fi |
89 | |
90 | ### output the dir header |
91 | echo "-*- Text -*-" |
92 | echo "This file was generated automatically by $0." |
93 | echo "This version was generated on ${_DATE}" |
94 | echo "by ${_WHOAMI}@${_HOSTNAME} for ${_PWD}" |
95 | |
96 | cat << moobler |
97 | \$Id: mkinfodir,v 1.7 2005-06-01 15:48:42 niro Exp $ |
98 | This is the file .../info/dir, which contains the topmost node of the |
99 | Info hierarchy. The first time you invoke Info you start off |
100 | looking at that node, which is (dir)Top. |
101 | |
102 | File: dir Node: Top This is the top of the INFO tree |
103 | |
104 | This (the Directory node) gives a menu of major topics. |
105 | Typing "q" exits, "?" lists all Info commands, "d" returns here, |
106 | "h" gives a primer for first-timers, |
107 | "mEmacs<Return>" visits the Emacs topic, etc. |
108 | |
109 | In Emacs, you can click mouse button 2 on a menu item or cross reference |
110 | to select it. |
111 | |
112 | * Menu: The list of major topics begins on the next line. |
113 | |
114 | moobler |
115 | |
116 | ### go through the list of files in the skeleton. If an info file |
117 | ### exists, grab the ENTRY information from it. If an entry exists |
118 | ### use it, otherwise create a minimal dir entry. |
119 | ### |
120 | ### Then remove that file from the list of existing files. If any |
121 | ### additional files remain (ones that don't have a skeleton entry), |
122 | ### then generate entries for those in the same way, putting the info for |
123 | ### those at the end.... |
124 | |
125 | infofiles=`(cd ${INFODIR}; /bin/ls | grep -v '\-[0-9]*\.gz$' | grep -v '\-[0-9]*$' | egrep -v '^dir$|^dir\.info$|^dir\.orig$')` |
126 | |
127 | # echoing gets clobbered by backquotes; we do it the hard way... |
128 | lines=`wc $SKELETON | awk '{print $1}'` |
129 | line=1 |
130 | while [ $lines -ge $line ] ; do |
131 | # Read one line from the file. This is so that we can echo lines with |
132 | # whitespace and quoted characters in them. |
133 | fileline=`awk NR==$line $SKELETON` |
134 | |
135 | # flag fancy features |
136 | if [ ! -z "$echoline" ] ; then # echo line |
137 | echo "$fileline" |
138 | fileline= |
139 | echoline= |
140 | elif [ "${fileline}" = "--" ] ; then # should we echo the next line? |
141 | echoline=1 |
142 | elif [ "${fileline}" = "%%" ] ; then # eliminate remaining files from dir? |
143 | skip=1 |
144 | elif [ "${fileline}" = "!!" ] ; then # quit now |
145 | exit 0 |
146 | fi |
147 | |
148 | # handle files if they exist |
149 | for file in $fileline"" ; do # expand wildcards ("" handles blank lines) |
150 | |
151 | fname= |
152 | |
153 | if [ -z "$echoline" -a ! -z "$file" ] ; then |
154 | |
155 | # Find the file to operate upon. Check both possible names. |
156 | infoname=`echo $file | sed 's/\.gz$//'` |
157 | infoname=`echo $infoname | sed 's/\.info$//'` |
158 | noext= |
159 | ext= |
160 | if [ -f ${INFODIR}/$infoname ] ; then |
161 | noext=$infoname |
162 | fi |
163 | if [ -f ${INFODIR}/${infoname}.info ] ; then |
164 | ext=${infoname}.info |
165 | fi |
166 | if [ -f ${INFODIR}/${infoname}.info.gz ] ; then |
167 | ext=${infoname}.info.gz |
168 | fi |
169 | # If it exists with both names take what was said in the file. |
170 | if [ ! -z "$ext" -a ! -z "$noext" ]; then |
171 | fname=$file |
172 | warn="### Warning: $ext and $noext both exist! Using ${file}. ###" |
173 | elif [ ! \( -z "$ext" -a -z "$noext" \) ]; then |
174 | # just take the name if it exists only once |
175 | fname=${noext}${ext} |
176 | fi |
177 | |
178 | # if we found something and aren't skipping, do the entry |
179 | if [ ! -z "$fname" ] ; then |
180 | if [ -z "$skip" ] ; then |
181 | |
182 | if [ ! -z "$warn" ] ; then # issue any warning |
183 | echo $warn |
184 | warn= |
185 | fi |
186 | if [ "${fname##*.}" = "gz" ] ; then |
187 | entry=`zcat ${INFODIR}/${fname} | sed -e '1,/START-INFO-DIR-ENTRY/d' \ |
188 | -e '/END-INFO-DIR-ENTRY/,$d' ` |
189 | else |
190 | entry=`sed -e '1,/START-INFO-DIR-ENTRY/d' \ |
191 | -e '/END-INFO-DIR-ENTRY/,$d' ${INFODIR}/$fname` |
192 | fi |
193 | if [ ! -z "${entry}" ] ; then |
194 | echo "${entry}" |
195 | else |
196 | echo "* ${infoname}: (${infoname})." |
197 | fi |
198 | fi |
199 | |
200 | # remove the name from the directory listing |
201 | infofiles=`echo "" ${infofiles} "" | sed -e "s/ ${fname} / /" -e "s/ / /g"` |
202 | |
203 | fi |
204 | |
205 | fi |
206 | |
207 | done |
208 | |
209 | line=`expr $line + 1` |
210 | done |
211 | |
212 | if [ -z "${infofiles}" ] ; then |
213 | exit 0 |
214 | elif [ $lines -gt 0 ]; then |
215 | echo |
216 | fi |
217 | |
218 | # Sort remaining files by INFO-DIR-SECTION. |
219 | prevsect= |
220 | filesectdata=`(cd ${INFODIR}; fgrep INFO-DIR-SECTION /dev/null ${infofiles} | \ |
221 | fgrep -v 'INFO-DIR-SECTION Miscellaneous' | \ |
222 | sort -t: -k2 -k1 | tr ' ' '_')` |
223 | for sectdata in ${filesectdata}; do |
224 | file=`echo ${sectdata} | cut -d: -f1` |
225 | section=`sed -n -e 's/^INFO-DIR-SECTION //p' ${INFODIR}/${file}` |
226 | infofiles=`echo "" ${infofiles} "" | sed -e "s/ ${file} / /" -e "s/ / /g"` |
227 | |
228 | if [ "${prevsect}" != "${section}" ] ; then |
229 | if [ ! -z "${prevsect}" ] ; then |
230 | echo "" |
231 | fi |
232 | echo "${section}" |
233 | prevsect="${section}" |
234 | fi |
235 | infoname=`echo $file | sed 's/\.gz$//'` |
236 | infoname=`echo $infoname | sed 's/\.info$//'` |
237 | if [ "${file##*.}" = "gz" ] ; then |
238 | entry=`zcat ${INFODIR}/$file | sed -e '1,/START-INFO-DIR-ENTRY/d' \ |
239 | -e '/END-INFO-DIR-ENTRY/,$d' ` |
240 | else |
241 | entry=`sed -e '1,/START-INFO-DIR-ENTRY/d' \ |
242 | -e '/END-INFO-DIR-ENTRY/,$d' ${INFODIR}/$file` |
243 | fi |
244 | if [ ! -z "${entry}" ] ; then |
245 | echo "${entry}" |
246 | elif [ ! -d "${INFODIR}/${file}" ] ; then |
247 | echo "* ${infoname}: (${infoname})." |
248 | fi |
249 | done |
250 | |
251 | # Process miscellaneous files. |
252 | for file in ${infofiles}; do |
253 | if [ ! -z "${prevsect}" ] ; then |
254 | echo "" |
255 | echo "Miscellaneous" |
256 | prevsect="" |
257 | fi |
258 | |
259 | infoname=`echo $file | sed 's/\.gz$//'` |
260 | infoname=`echo $infoname | sed 's/\.info$//'` |
261 | if [ "${file##*.}" = "gz" ] ; then |
262 | entry=`zcat ${INFODIR}/${file} | sed -e '1,/START-INFO-DIR-ENTRY/d' \ |
263 | -e '/END-INFO-DIR-ENTRY/,$d'` |
264 | else |
265 | entry=`sed -e '1,/START-INFO-DIR-ENTRY/d' \ |
266 | -e '/END-INFO-DIR-ENTRY/,$d' ${INFODIR}/$file` |
267 | fi |
268 | |
269 | |
270 | if [ ! -z "${entry}" ] ; then |
271 | echo "${entry}" |
272 | elif [ ! -d "${INFODIR}/${file}" ] ; then |
273 | echo "* ${infoname}: (${infoname})." |
274 | fi |
275 | done |
276 |