Annotation of /trunk/mage/usr/lib/mage/mkinfodir
Parent Directory | Revision Log
Revision 43 -
(hide annotations)
(download)
Mon Jan 10 01:59:03 2005 UTC (19 years, 8 months ago) by niro
File size: 7338 byte(s)
Mon Jan 10 01:59:03 2005 UTC (19 years, 8 months ago) by niro
File size: 7338 byte(s)
updated revision tags
1 | niro | 24 | #!/bin/bash |
2 | niro | 43 | # $Id: mkinfodir,v 1.4 2005-01-10 01:58:55 niro Exp $ |
3 | niro | 24 | # 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 | niro | 43 | # version: 0.3.6-r11 |
25 | niro | 24 | |
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 | ### output the dir header | ||
50 | echo "-*- Text -*-" | ||
51 | echo "This file was generated automatically by $0." | ||
52 | echo "This version was generated on `date`" | ||
53 | echo "by `whoami`@`hostname` for `(cd ${INFODIR}; pwd)`" | ||
54 | |||
55 | cat << moobler | ||
56 | niro | 43 | \$Id: mkinfodir,v 1.4 2005-01-10 01:58:55 niro Exp $ |
57 | niro | 24 | This is the file .../info/dir, which contains the topmost node of the |
58 | Info hierarchy. The first time you invoke Info you start off | ||
59 | looking at that node, which is (dir)Top. | ||
60 | |||
61 | File: dir Node: Top This is the top of the INFO tree | ||
62 | |||
63 | This (the Directory node) gives a menu of major topics. | ||
64 | Typing "q" exits, "?" lists all Info commands, "d" returns here, | ||
65 | "h" gives a primer for first-timers, | ||
66 | "mEmacs<Return>" visits the Emacs topic, etc. | ||
67 | |||
68 | In Emacs, you can click mouse button 2 on a menu item or cross reference | ||
69 | to select it. | ||
70 | |||
71 | * Menu: The list of major topics begins on the next line. | ||
72 | |||
73 | moobler | ||
74 | |||
75 | ### go through the list of files in the skeleton. If an info file | ||
76 | ### exists, grab the ENTRY information from it. If an entry exists | ||
77 | ### use it, otherwise create a minimal dir entry. | ||
78 | ### | ||
79 | ### Then remove that file from the list of existing files. If any | ||
80 | ### additional files remain (ones that don't have a skeleton entry), | ||
81 | ### then generate entries for those in the same way, putting the info for | ||
82 | ### those at the end.... | ||
83 | |||
84 | infofiles=`(cd ${INFODIR}; /bin/ls | grep -v '\-[0-9]*\.gz$' | grep -v '\-[0-9]*$' | egrep -v '^dir$|^dir\.info$|^dir\.orig$')` | ||
85 | |||
86 | # echoing gets clobbered by backquotes; we do it the hard way... | ||
87 | lines=`wc $SKELETON | awk '{print $1}'` | ||
88 | line=1 | ||
89 | while [ $lines -ge $line ] ; do | ||
90 | # Read one line from the file. This is so that we can echo lines with | ||
91 | # whitespace and quoted characters in them. | ||
92 | fileline=`awk NR==$line $SKELETON` | ||
93 | |||
94 | # flag fancy features | ||
95 | if [ ! -z "$echoline" ] ; then # echo line | ||
96 | echo "$fileline" | ||
97 | fileline= | ||
98 | echoline= | ||
99 | elif [ "${fileline}" = "--" ] ; then # should we echo the next line? | ||
100 | echoline=1 | ||
101 | elif [ "${fileline}" = "%%" ] ; then # eliminate remaining files from dir? | ||
102 | skip=1 | ||
103 | elif [ "${fileline}" = "!!" ] ; then # quit now | ||
104 | exit 0 | ||
105 | fi | ||
106 | |||
107 | # handle files if they exist | ||
108 | for file in $fileline"" ; do # expand wildcards ("" handles blank lines) | ||
109 | |||
110 | fname= | ||
111 | |||
112 | if [ -z "$echoline" -a ! -z "$file" ] ; then | ||
113 | |||
114 | # Find the file to operate upon. Check both possible names. | ||
115 | infoname=`echo $file | sed 's/\.gz$//'` | ||
116 | infoname=`echo $infoname | sed 's/\.info$//'` | ||
117 | noext= | ||
118 | ext= | ||
119 | if [ -f ${INFODIR}/$infoname ] ; then | ||
120 | noext=$infoname | ||
121 | fi | ||
122 | if [ -f ${INFODIR}/${infoname}.info ] ; then | ||
123 | ext=${infoname}.info | ||
124 | fi | ||
125 | if [ -f ${INFODIR}/${infoname}.info.gz ] ; then | ||
126 | ext=${infoname}.info.gz | ||
127 | fi | ||
128 | # If it exists with both names take what was said in the file. | ||
129 | if [ ! -z "$ext" -a ! -z "$noext" ]; then | ||
130 | fname=$file | ||
131 | warn="### Warning: $ext and $noext both exist! Using ${file}. ###" | ||
132 | elif [ ! \( -z "$ext" -a -z "$noext" \) ]; then | ||
133 | # just take the name if it exists only once | ||
134 | fname=${noext}${ext} | ||
135 | fi | ||
136 | |||
137 | # if we found something and aren't skipping, do the entry | ||
138 | if [ ! -z "$fname" ] ; then | ||
139 | if [ -z "$skip" ] ; then | ||
140 | |||
141 | if [ ! -z "$warn" ] ; then # issue any warning | ||
142 | echo $warn | ||
143 | warn= | ||
144 | fi | ||
145 | if [ "${fname##*.}" = "gz" ] ; then | ||
146 | entry=`zcat ${INFODIR}/${fname} | sed -e '1,/START-INFO-DIR-ENTRY/d' \ | ||
147 | -e '/END-INFO-DIR-ENTRY/,$d' ` | ||
148 | else | ||
149 | entry=`sed -e '1,/START-INFO-DIR-ENTRY/d' \ | ||
150 | -e '/END-INFO-DIR-ENTRY/,$d' ${INFODIR}/$fname` | ||
151 | fi | ||
152 | if [ ! -z "${entry}" ] ; then | ||
153 | echo "${entry}" | ||
154 | else | ||
155 | echo "* ${infoname}: (${infoname})." | ||
156 | fi | ||
157 | fi | ||
158 | |||
159 | # remove the name from the directory listing | ||
160 | infofiles=`echo "" ${infofiles} "" | sed -e "s/ ${fname} / /" -e "s/ / /g"` | ||
161 | |||
162 | fi | ||
163 | |||
164 | fi | ||
165 | |||
166 | done | ||
167 | |||
168 | line=`expr $line + 1` | ||
169 | done | ||
170 | |||
171 | if [ -z "${infofiles}" ] ; then | ||
172 | exit 0 | ||
173 | elif [ $lines -gt 0 ]; then | ||
174 | echo | ||
175 | fi | ||
176 | |||
177 | # Sort remaining files by INFO-DIR-SECTION. | ||
178 | prevsect= | ||
179 | filesectdata=`(cd ${INFODIR}; fgrep INFO-DIR-SECTION /dev/null ${infofiles} | \ | ||
180 | fgrep -v 'INFO-DIR-SECTION Miscellaneous' | \ | ||
181 | sort -t: -k2 -k1 | tr ' ' '_')` | ||
182 | for sectdata in ${filesectdata}; do | ||
183 | file=`echo ${sectdata} | cut -d: -f1` | ||
184 | section=`sed -n -e 's/^INFO-DIR-SECTION //p' ${INFODIR}/${file}` | ||
185 | infofiles=`echo "" ${infofiles} "" | sed -e "s/ ${file} / /" -e "s/ / /g"` | ||
186 | |||
187 | if [ "${prevsect}" != "${section}" ] ; then | ||
188 | if [ ! -z "${prevsect}" ] ; then | ||
189 | echo "" | ||
190 | fi | ||
191 | echo "${section}" | ||
192 | prevsect="${section}" | ||
193 | fi | ||
194 | infoname=`echo $file | sed 's/\.gz$//'` | ||
195 | infoname=`echo $infoname | sed 's/\.info$//'` | ||
196 | if [ "${file##*.}" = "gz" ] ; then | ||
197 | entry=`zcat ${INFODIR}/$file | sed -e '1,/START-INFO-DIR-ENTRY/d' \ | ||
198 | -e '/END-INFO-DIR-ENTRY/,$d' ` | ||
199 | else | ||
200 | entry=`sed -e '1,/START-INFO-DIR-ENTRY/d' \ | ||
201 | -e '/END-INFO-DIR-ENTRY/,$d' ${INFODIR}/$file` | ||
202 | fi | ||
203 | if [ ! -z "${entry}" ] ; then | ||
204 | echo "${entry}" | ||
205 | elif [ ! -d "${INFODIR}/${file}" ] ; then | ||
206 | echo "* ${infoname}: (${infoname})." | ||
207 | fi | ||
208 | done | ||
209 | |||
210 | # Process miscellaneous files. | ||
211 | for file in ${infofiles}; do | ||
212 | if [ ! -z "${prevsect}" ] ; then | ||
213 | echo "" | ||
214 | echo "Miscellaneous" | ||
215 | prevsect="" | ||
216 | fi | ||
217 | |||
218 | infoname=`echo $file | sed 's/\.gz$//'` | ||
219 | infoname=`echo $infoname | sed 's/\.info$//'` | ||
220 | if [ "${file##*.}" = "gz" ] ; then | ||
221 | entry=`zcat ${INFODIR}/${file} | sed -e '1,/START-INFO-DIR-ENTRY/d' \ | ||
222 | -e '/END-INFO-DIR-ENTRY/,$d'` | ||
223 | else | ||
224 | entry=`sed -e '1,/START-INFO-DIR-ENTRY/d' \ | ||
225 | -e '/END-INFO-DIR-ENTRY/,$d' ${INFODIR}/$file` | ||
226 | fi | ||
227 | |||
228 | |||
229 | if [ ! -z "${entry}" ] ; then | ||
230 | echo "${entry}" | ||
231 | elif [ ! -d "${INFODIR}/${file}" ] ; then | ||
232 | echo "* ${infoname}: (${infoname})." | ||
233 | fi | ||
234 | done | ||
235 |
Properties
Name | Value |
---|---|
svn:executable | * |