2 #fix-info-dir (GNU texinfo)
4 #Copyright (C) 1998, 2003 Free Software Foundation, Inc.
5 #fix-info-dir comes with NO WARRANTY, to the extent permitted by law.
6 #You may redistribute copies of fix-info-dir
7 #under the terms of the GNU General Public License.
8 #For more information about these matters, see the files named COPYING."
9 #fix-info-dir was derived from update-info and gen-dir-node
10 # The skeleton file contains info topic names in the
11 # order they should appear in the output. There are three special
12 # lines that alter the behavior: a line consisting of just "--" causes
13 # the next line to be echoed verbatim to the output. A line
14 # containing just "%%" causes all the remaining filenames (wildcards
15 # allowed) in the rest of the file to be ignored. A line containing
16 # just "!!" exits the script when reached (unless preceded by a line
17 # containing just "--").
18 #Author: Richard L. Hawes, rhawes@dmapub.dma.org.
20 # ###SECTION 1### Constants
23 if test -z "$TMPDIR"; then
26 if test -z "$LINENO"; then
30 MENU_BEGIN
='^\*\([ ]\)\{1,\}Menu:'
31 MENU_ITEM
='^\* ([^ ]).*:([ ])+\('
32 MENU_FILTER1
='s/^\*\([ ]\)\{1,\}/* /'
33 MENU_FILTER2
='s/\([ ]\)\{1,\}$//g'
35 TMP_FILE1
="${TMPDIR}/fx${$}.info"
36 TMP_FILE2
="${TMPDIR}/fy${$}.info"
37 TMP_FILE_LIST
="$TMP_FILE1 $TMP_FILE2"
39 TRY_HELP_MSG
="Try --help for more information"
41 # ###SECTION 100### main program
42 #variables set by options
52 -c|
--create) CREATE_NODE
="y";;
53 --debug) set -eux; DEBUG
="set>&2";;
54 -d|
--delete) MODE
="Detect_Invalid";;
58 fix-info-dir (GNU Texinfo) $VERSION
59 Copyright (C) 1998 Free Software Foundation, Inc.
60 fix-info-dir comes with NO WARRANTY, to the extent permitted by law.
61 You may redistribute copies of fix-info-dir
62 under the terms of the GNU General Public License.
63 For more information about these matters, see the files named COPYING.
64 Author: Richard L. Hawes
70 Usage: fix-info-dir [OPTION]... [INFO_DIR/[DIR_FILE]] [SKELETON]
72 It detects and inserts missing menu items into the info dir file.
73 The info dir must be the current directory.
76 -c, --create create a new info node
77 -d, --delete delete invalid menu items (ignore missing menu items)
78 --debug print debug information to standard error path
79 --help print this help message and exit
80 --version print current version and exit
81 Backup of the info node has a '.old' suffix added. This is a shell script.
82 Environment Variables: TMPDIR
83 Email bug reports to bug-texinfo@gnu.org.
87 [-+]*) echo "$0:$LINENO: \"$1\" is not a valid option">&2
88 echo "$TRY_HELP_MSG">&2
97 if test "$#" -gt "0"; then
101 INFO_DIR
=$DEFAULT_INFO_DIR
104 if test ! -d "${INFO_DIR}"; then
105 DIR_FILE
=`basename ${INFO_DIR}`;
106 INFO_DIR
=`dirname ${INFO_DIR}`;
114 if test "$CREATE_NODE"; then
115 if test "$#" -gt "0"; then
116 if test `expr $1 : /` = '1'; then
119 SKELETON
="$ORIGINAL_DIR/$1"
121 if test ! -r "$SKELETON" && test -f "$SKELETON"; then
122 echo "$0:$LINENO: $SKELETON is not readable">&2
131 if test ! -f "$DIR_FILE"; then
132 echo "$0:$LINENO: $DIR_FILE is irregular or nonexistant">&2
134 elif test ! -r "$DIR_FILE"; then
135 echo "$0:$LINENO: $DIR_FILE is not readable">&2
137 elif test ! -w "$DIR_FILE"; then
138 echo "$0:$LINENO: $DIR_FILE is not writeable">&2
143 if test "$#" -gt "0"; then
144 echo "$0:$LINENO: Too many parameters">&2
145 echo "$TRY_HELP_MSG">&2
149 if test -f "$DIR_FILE"; then
150 cp "$DIR_FILE" "$DIR_FILE.old"
151 echo "Backed up $DIR_FILE to $DIR_FILE.old."
154 if test "$CREATE_NODE"; then
155 if test "$MODE"; then
156 echo "$0:$LINENO: ERROR: Illogical option combination: -d -c">&2
157 echo "$TRY_HELP_MSG">&2
160 echo "Creating new Info Node: `pwd`/$DIR_FILE"
165 ### output the dir header
167 echo "This file was generated automatically by $0."
168 echo "This version was generated on `date`"
169 echo "by `whoami`@`hostname` for `pwd`"
171 cat<<DIR_FILE_END_OF_FILE
172 This is the file .../info/$DIR_FILE, which contains the topmost node of the
173 Info hierarchy. The first time you invoke Info you start off
174 looking at that node, which is ($DIR_FILE)Top.
177 File: $DIR_FILE Node: Top This is the top of the INFO tree
179 This (the Directory node) gives a menu of major topics.
180 Typing "q" exits, "?" lists all Info commands, "d" returns here,
181 "h" gives a primer for first-timers,
182 "mEmacs<Return>" visits the Emacs topic, etc.
184 In Emacs, you can click mouse button 2 on a menu item or cross reference
187 * Menu: The list of major topics begins on the next line.
191 ### go through the list of files in the skeleton. If an info file
192 ### exists, grab the ENTRY information from it. If an entry exists
193 ### use it, otherwise create a minimal $DIR_FILE entry.
195 # Read one line from the file. This is so that we can echo lines with
196 # whitespace and quoted characters in them.
197 while read fileline
; do
198 # flag fancy features
199 if test ! -z "$echoline"; then # echo line
203 elif test "${fileline}" = "--"; then
207 elif test "${fileline}" = "%%"; then
208 # skip remaining files listed in skeleton file
211 elif test "${fileline}" = "!!"; then
216 # handle files if they exist
217 for file in $fileline""; do
219 if test -z "$file"; then
222 # Find the file to operate upon.
223 if test -r "$file"; then
225 elif test -r "${file}.info"; then
227 elif test -r "${file}.gz"; then
229 elif test -r "${file}.info.gz"; then
230 fname
="${file}.info.gz"
232 echo "$0:$LINENO: can't find info file for ${file}?">&2
236 # if we found something and aren't skipping, do the entry
237 if test "$skip"; then
241 infoname
=`echo $file|sed -e 's/.info$//'`
242 entry
=`zcat -f $fname|\
243 sed -e '1,/START-INFO-DIR-ENTRY/d'\
244 -e '/END-INFO-DIR-ENTRY/,$d'`
245 if [ ! -z "${entry}" ]; then
248 echo "* ${infoname}: (${infoname})."
250 Total
=`expr "$Total" + "1"`
253 }>$DIR_FILE<$SKELETON
256 trap ' eval "$DEBUG"; rm -f $TMP_FILE_LIST; exit ' 0
257 trap ' rm -f $TMP_FILE_LIST
259 trap ' rm -f $TMP_FILE_LIST
260 echo "$0:$LINENO: received INT signal.">&2
262 trap ' rm -f $TMP_FILE_LIST
263 echo "$0:$LINENO: received QUIT signal.">&2
266 sed -e "1,/$MENU_BEGIN/d" -e "$MENU_FILTER1" -e "$MENU_FILTER2"<$DIR_FILE\
272 }'|
sort -u>$TMP_FILE1
273 ls -F|
sed -e '/\/$/d' -e '/[-.][0-9]/d'\
274 -e "/^$DIR_FILE\$/d" -e "/^$DIR_FILE.old\$/d"\
275 -e 's/[*@]$//' -e 's/\.gz$//' -e 's/\.info$//'|
sort>$TMP_FILE2
277 if test -z "$MODE"; then
279 DONE_MSG
="total menu item(s) were inserted into `pwd`/$DIR_FILE"
280 for Info_Name
in `comm -13 $TMP_FILE1 $TMP_FILE2`; do
281 if test -r "$Info_Name"; then
282 Info_File
="$Info_Name"
283 elif test -r "${Info_Name}.info"; then
284 Info_File
="${Info_Name}.info"
285 elif test -r "${Info_Name}.gz"; then
286 Info_File
="${Info_Name}.gz"
287 elif test -r "${Info_Name}.info.gz"; then
288 Info_File
="${Info_Name}.info.gz"
290 echo "$0:$LINENO: can't find info file for ${Info_Name}?">&2
294 if install-info
$Info_File $DIR_FILE; then
295 Total
=`expr "$Total" + "1"`
300 DONE_MSG
="total invalid menu item(s) were removed from `pwd`/$DIR_FILE"
301 for Info_Name
in `comm -23 $TMP_FILE1 $TMP_FILE2`; do
303 if install-info
--remove $Info_Name $DIR_FILE; then
304 Total
=`expr "$Total" + "1"`
310 if test "$Changed"; then
311 echo "$Total $DONE_MSG"