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