1*29619d2aSchristos#!/bin/sh 2*29619d2aSchristos#fix-info-dir (GNU texinfo) 3*29619d2aSchristosVERSION=1.1 4*29619d2aSchristos#Copyright (C) 1998, 2003 Free Software Foundation, Inc. 5*29619d2aSchristos#fix-info-dir comes with NO WARRANTY, to the extent permitted by law. 6*29619d2aSchristos#You may redistribute copies of fix-info-dir 7*29619d2aSchristos#under the terms of the GNU General Public License. 8*29619d2aSchristos#For more information about these matters, see the files named COPYING." 9*29619d2aSchristos#fix-info-dir was derived from update-info and gen-dir-node 10*29619d2aSchristos# The skeleton file contains info topic names in the 11*29619d2aSchristos# order they should appear in the output. There are three special 12*29619d2aSchristos# lines that alter the behavior: a line consisting of just "--" causes 13*29619d2aSchristos# the next line to be echoed verbatim to the output. A line 14*29619d2aSchristos# containing just "%%" causes all the remaining filenames (wildcards 15*29619d2aSchristos# allowed) in the rest of the file to be ignored. A line containing 16*29619d2aSchristos# just "!!" exits the script when reached (unless preceded by a line 17*29619d2aSchristos# containing just "--"). 18*29619d2aSchristos#Author: Richard L. Hawes, rhawes@dmapub.dma.org. 19*29619d2aSchristos 20*29619d2aSchristos# ###SECTION 1### Constants 21*29619d2aSchristosset -h 2>/dev/null 22*29619d2aSchristos# ENVIRONMENT 23*29619d2aSchristosif test -z "$TMPDIR"; then 24*29619d2aSchristos TMPDIR="/usr/tmp" 25*29619d2aSchristosfi 26*29619d2aSchristosif test -z "$LINENO"; then 27*29619d2aSchristos LINENO="0" 28*29619d2aSchristosfi 29*29619d2aSchristos 30*29619d2aSchristosMENU_BEGIN='^\*\([ ]\)\{1,\}Menu:' 31*29619d2aSchristosMENU_ITEM='^\* ([^ ]).*:([ ])+\(' 32*29619d2aSchristosMENU_FILTER1='s/^\*\([ ]\)\{1,\}/* /' 33*29619d2aSchristosMENU_FILTER2='s/\([ ]\)\{1,\}$//g' 34*29619d2aSchristos 35*29619d2aSchristosTMP_FILE1="${TMPDIR}/fx${$}.info" 36*29619d2aSchristosTMP_FILE2="${TMPDIR}/fy${$}.info" 37*29619d2aSchristosTMP_FILE_LIST="$TMP_FILE1 $TMP_FILE2" 38*29619d2aSchristos 39*29619d2aSchristosTRY_HELP_MSG="Try --help for more information" 40*29619d2aSchristos 41*29619d2aSchristos# ###SECTION 100### main program 42*29619d2aSchristos#variables set by options 43*29619d2aSchristosCREATE_NODE="" 44*29619d2aSchristosDEBUG=":" 45*29619d2aSchristosMODE="" 46*29619d2aSchristos# 47*29619d2aSchristosTotal="0" 48*29619d2aSchristosChanged="" 49*29619d2aSchristos 50*29619d2aSchristoswhile test "$*"; do 51*29619d2aSchristos case "$1" in 52*29619d2aSchristos -c|--create) CREATE_NODE="y";; 53*29619d2aSchristos --debug) set -eux; DEBUG="set>&2";; 54*29619d2aSchristos -d|--delete) MODE="Detect_Invalid";; 55*29619d2aSchristos +d);; 56*29619d2aSchristos --version) 57*29619d2aSchristoscat<<VersionEOF 58*29619d2aSchristosfix-info-dir (GNU Texinfo) $VERSION 59*29619d2aSchristosCopyright (C) 1998 Free Software Foundation, Inc. 60*29619d2aSchristosfix-info-dir comes with NO WARRANTY, to the extent permitted by law. 61*29619d2aSchristosYou may redistribute copies of fix-info-dir 62*29619d2aSchristosunder the terms of the GNU General Public License. 63*29619d2aSchristosFor more information about these matters, see the files named COPYING. 64*29619d2aSchristosAuthor: Richard L. Hawes 65*29619d2aSchristosVersionEOF 66*29619d2aSchristos exit;; 67*29619d2aSchristos 68*29619d2aSchristos --help) 69*29619d2aSchristoscat<<HelpEndOfFile 70*29619d2aSchristosUsage: fix-info-dir [OPTION]... [INFO_DIR/[DIR_FILE]] [SKELETON] 71*29619d2aSchristos 72*29619d2aSchristosIt detects and inserts missing menu items into the info dir file. 73*29619d2aSchristosThe info dir must be the current directory. 74*29619d2aSchristos 75*29619d2aSchristosOptions: 76*29619d2aSchristos-c, --create create a new info node 77*29619d2aSchristos-d, --delete delete invalid menu items (ignore missing menu items) 78*29619d2aSchristos --debug print debug information to standard error path 79*29619d2aSchristos --help print this help message and exit 80*29619d2aSchristos --version print current version and exit 81*29619d2aSchristosBackup of the info node has a '.old' suffix added. This is a shell script. 82*29619d2aSchristosEnvironment Variables: TMPDIR 83*29619d2aSchristosEmail bug reports to bug-texinfo@gnu.org. 84*29619d2aSchristosHelpEndOfFile 85*29619d2aSchristos exit;; 86*29619d2aSchristos 87*29619d2aSchristos [-+]*) echo "$0:$LINENO: \"$1\" is not a valid option">&2 88*29619d2aSchristos echo "$TRY_HELP_MSG">&2 89*29619d2aSchristos exit 2;; 90*29619d2aSchristos *) break;; 91*29619d2aSchristos esac 92*29619d2aSchristos shift 93*29619d2aSchristosdone 94*29619d2aSchristos 95*29619d2aSchristosORIGINAL_DIR=`pwd` 96*29619d2aSchristos 97*29619d2aSchristosif test "$#" -gt "0"; then 98*29619d2aSchristos INFO_DIR="$1" 99*29619d2aSchristos shift 100*29619d2aSchristoselse 101*29619d2aSchristos INFO_DIR=$DEFAULT_INFO_DIR 102*29619d2aSchristosfi 103*29619d2aSchristos 104*29619d2aSchristosif test ! -d "${INFO_DIR}"; then 105*29619d2aSchristos DIR_FILE=`basename ${INFO_DIR}`; 106*29619d2aSchristos INFO_DIR=`dirname ${INFO_DIR}`; 107*29619d2aSchristoselse 108*29619d2aSchristos DIR_FILE="dir" 109*29619d2aSchristosfi 110*29619d2aSchristos 111*29619d2aSchristoscd "$INFO_DIR"||exit 112*29619d2aSchristos 113*29619d2aSchristos 114*29619d2aSchristosif test "$CREATE_NODE"; then 115*29619d2aSchristos if test "$#" -gt "0"; then 116*29619d2aSchristos if test `expr $1 : /` = '1'; then 117*29619d2aSchristos SKELETON="$1" 118*29619d2aSchristos else 119*29619d2aSchristos SKELETON="$ORIGINAL_DIR/$1" 120*29619d2aSchristos fi 121*29619d2aSchristos if test ! -r "$SKELETON" && test -f "$SKELETON"; then 122*29619d2aSchristos echo "$0:$LINENO: $SKELETON is not readable">&2 123*29619d2aSchristos exit 2 124*29619d2aSchristos fi 125*29619d2aSchristos shift 126*29619d2aSchristos else 127*29619d2aSchristos SKELETON=/dev/null 128*29619d2aSchristos 129*29619d2aSchristos fi 130*29619d2aSchristoselse 131*29619d2aSchristos if test ! -f "$DIR_FILE"; then 132*29619d2aSchristos echo "$0:$LINENO: $DIR_FILE is irregular or nonexistant">&2 133*29619d2aSchristos exit 2 134*29619d2aSchristos elif test ! -r "$DIR_FILE"; then 135*29619d2aSchristos echo "$0:$LINENO: $DIR_FILE is not readable">&2 136*29619d2aSchristos exit 2 137*29619d2aSchristos elif test ! -w "$DIR_FILE"; then 138*29619d2aSchristos echo "$0:$LINENO: $DIR_FILE is not writeable">&2 139*29619d2aSchristos exit 2 140*29619d2aSchristos fi 141*29619d2aSchristosfi 142*29619d2aSchristos 143*29619d2aSchristosif test "$#" -gt "0"; then 144*29619d2aSchristos echo "$0:$LINENO: Too many parameters">&2 145*29619d2aSchristos echo "$TRY_HELP_MSG">&2 146*29619d2aSchristos exit 2 147*29619d2aSchristosfi 148*29619d2aSchristos 149*29619d2aSchristosif test -f "$DIR_FILE"; then 150*29619d2aSchristos cp "$DIR_FILE" "$DIR_FILE.old" 151*29619d2aSchristos echo "Backed up $DIR_FILE to $DIR_FILE.old." 152*29619d2aSchristosfi 153*29619d2aSchristos 154*29619d2aSchristosif test "$CREATE_NODE"; then 155*29619d2aSchristos if test "$MODE"; then 156*29619d2aSchristos echo "$0:$LINENO: ERROR: Illogical option combination: -d -c">&2 157*29619d2aSchristos echo "$TRY_HELP_MSG">&2 158*29619d2aSchristos exit 2 159*29619d2aSchristos fi 160*29619d2aSchristos echo "Creating new Info Node: `pwd`/$DIR_FILE" 161*29619d2aSchristos Changed="y" 162*29619d2aSchristos 163*29619d2aSchristos{ 164*29619d2aSchristos 165*29619d2aSchristos ### output the dir header 166*29619d2aSchristos echo "-*- Text -*-" 167*29619d2aSchristos echo "This file was generated automatically by $0." 168*29619d2aSchristos echo "This version was generated on `date`" 169*29619d2aSchristos echo "by `whoami`@`hostname` for `pwd`" 170*29619d2aSchristos 171*29619d2aSchristos cat<<DIR_FILE_END_OF_FILE 172*29619d2aSchristosThis is the file .../info/$DIR_FILE, which contains the topmost node of the 173*29619d2aSchristosInfo hierarchy. The first time you invoke Info you start off 174*29619d2aSchristoslooking at that node, which is ($DIR_FILE)Top. 175*29619d2aSchristos 176*29619d2aSchristos 177*29619d2aSchristosFile: $DIR_FILE Node: Top This is the top of the INFO tree 178*29619d2aSchristos 179*29619d2aSchristos This (the Directory node) gives a menu of major topics. 180*29619d2aSchristos Typing "q" exits, "?" lists all Info commands, "d" returns here, 181*29619d2aSchristos "h" gives a primer for first-timers, 182*29619d2aSchristos "mEmacs<Return>" visits the Emacs topic, etc. 183*29619d2aSchristos 184*29619d2aSchristos In Emacs, you can click mouse button 2 on a menu item or cross reference 185*29619d2aSchristos to select it. 186*29619d2aSchristos 187*29619d2aSchristos* Menu: The list of major topics begins on the next line. 188*29619d2aSchristos 189*29619d2aSchristosDIR_FILE_END_OF_FILE 190*29619d2aSchristos 191*29619d2aSchristos### go through the list of files in the skeleton. If an info file 192*29619d2aSchristos### exists, grab the ENTRY information from it. If an entry exists 193*29619d2aSchristos### use it, otherwise create a minimal $DIR_FILE entry. 194*29619d2aSchristos 195*29619d2aSchristos # Read one line from the file. This is so that we can echo lines with 196*29619d2aSchristos # whitespace and quoted characters in them. 197*29619d2aSchristos while read fileline; do 198*29619d2aSchristos # flag fancy features 199*29619d2aSchristos if test ! -z "$echoline"; then # echo line 200*29619d2aSchristos echo "$fileline" 201*29619d2aSchristos echoline="" 202*29619d2aSchristos continue 203*29619d2aSchristos elif test "${fileline}" = "--"; then 204*29619d2aSchristos # echo the next line 205*29619d2aSchristos echoline="1" 206*29619d2aSchristos continue 207*29619d2aSchristos elif test "${fileline}" = "%%"; then 208*29619d2aSchristos # skip remaining files listed in skeleton file 209*29619d2aSchristos skip="1" 210*29619d2aSchristos continue 211*29619d2aSchristos elif test "${fileline}" = "!!"; then 212*29619d2aSchristos # quit now 213*29619d2aSchristos break 214*29619d2aSchristos fi 215*29619d2aSchristos 216*29619d2aSchristos # handle files if they exist 217*29619d2aSchristos for file in $fileline""; do 218*29619d2aSchristos fname= 219*29619d2aSchristos if test -z "$file"; then 220*29619d2aSchristos break 221*29619d2aSchristos fi 222*29619d2aSchristos # Find the file to operate upon. 223*29619d2aSchristos if test -r "$file"; then 224*29619d2aSchristos fname="$file" 225*29619d2aSchristos elif test -r "${file}.info"; then 226*29619d2aSchristos fname="${file}.info" 227*29619d2aSchristos elif test -r "${file}.gz"; then 228*29619d2aSchristos fname="${file}.gz" 229*29619d2aSchristos elif test -r "${file}.info.gz"; then 230*29619d2aSchristos fname="${file}.info.gz" 231*29619d2aSchristos else 232*29619d2aSchristos echo "$0:$LINENO: can't find info file for ${file}?">&2 233*29619d2aSchristos continue 234*29619d2aSchristos fi 235*29619d2aSchristos 236*29619d2aSchristos # if we found something and aren't skipping, do the entry 237*29619d2aSchristos if test "$skip"; then 238*29619d2aSchristos continue 239*29619d2aSchristos fi 240*29619d2aSchristos 241*29619d2aSchristos infoname=`echo $file|sed -e 's/.info$//'` 242*29619d2aSchristos entry=`zcat -f $fname|\ 243*29619d2aSchristos sed -e '1,/START-INFO-DIR-ENTRY/d'\ 244*29619d2aSchristos -e '/END-INFO-DIR-ENTRY/,$d'` 245*29619d2aSchristos if [ ! -z "${entry}" ]; then 246*29619d2aSchristos echo "${entry}" 247*29619d2aSchristos else 248*29619d2aSchristos echo "* ${infoname}: (${infoname})." 249*29619d2aSchristos fi 250*29619d2aSchristos Total=`expr "$Total" + "1"` 251*29619d2aSchristos done 252*29619d2aSchristos done 253*29619d2aSchristos}>$DIR_FILE<$SKELETON 254*29619d2aSchristosfi 255*29619d2aSchristos 256*29619d2aSchristostrap ' eval "$DEBUG"; rm -f $TMP_FILE_LIST; exit ' 0 257*29619d2aSchristostrap ' rm -f $TMP_FILE_LIST 258*29619d2aSchristos exit ' 1 259*29619d2aSchristostrap ' rm -f $TMP_FILE_LIST 260*29619d2aSchristos echo "$0:$LINENO: received INT signal.">&2 261*29619d2aSchristos exit ' 2 262*29619d2aSchristostrap ' rm -f $TMP_FILE_LIST 263*29619d2aSchristos echo "$0:$LINENO: received QUIT signal.">&2 264*29619d2aSchristos exit ' 3 265*29619d2aSchristos 266*29619d2aSchristossed -e "1,/$MENU_BEGIN/d" -e "$MENU_FILTER1" -e "$MENU_FILTER2"<$DIR_FILE\ 267*29619d2aSchristos|sed -n -e '/\* /{ 268*29619d2aSchristoss/).*$//g 269*29619d2aSchristoss/\.gz$// 270*29619d2aSchristoss/\.info$// 271*29619d2aSchristoss/^.*(//p 272*29619d2aSchristos}'|sort -u>$TMP_FILE1 273*29619d2aSchristosls -F|sed -e '/\/$/d' -e '/[-.][0-9]/d'\ 274*29619d2aSchristos -e "/^$DIR_FILE\$/d" -e "/^$DIR_FILE.old\$/d"\ 275*29619d2aSchristos -e 's/[*@]$//' -e 's/\.gz$//' -e 's/\.info$//'|sort>$TMP_FILE2 276*29619d2aSchristos 277*29619d2aSchristosif test -z "$MODE"; then 278*29619d2aSchristos #Detect Missing 279*29619d2aSchristos DONE_MSG="total menu item(s) were inserted into `pwd`/$DIR_FILE" 280*29619d2aSchristos for Info_Name in `comm -13 $TMP_FILE1 $TMP_FILE2`; do 281*29619d2aSchristos if test -r "$Info_Name"; then 282*29619d2aSchristos Info_File="$Info_Name" 283*29619d2aSchristos elif test -r "${Info_Name}.info"; then 284*29619d2aSchristos Info_File="${Info_Name}.info" 285*29619d2aSchristos elif test -r "${Info_Name}.gz"; then 286*29619d2aSchristos Info_File="${Info_Name}.gz" 287*29619d2aSchristos elif test -r "${Info_Name}.info.gz"; then 288*29619d2aSchristos Info_File="${Info_Name}.info.gz" 289*29619d2aSchristos else 290*29619d2aSchristos echo "$0:$LINENO: can't find info file for ${Info_Name}?">&2 291*29619d2aSchristos continue 292*29619d2aSchristos fi 293*29619d2aSchristos Changed="y" 294*29619d2aSchristos if install-info $Info_File $DIR_FILE; then 295*29619d2aSchristos Total=`expr "$Total" + "1"` 296*29619d2aSchristos fi 297*29619d2aSchristos done 298*29619d2aSchristoselse 299*29619d2aSchristos # Detect Invalid 300*29619d2aSchristos DONE_MSG="total invalid menu item(s) were removed from `pwd`/$DIR_FILE" 301*29619d2aSchristos for Info_Name in `comm -23 $TMP_FILE1 $TMP_FILE2`; do 302*29619d2aSchristos Changed="y" 303*29619d2aSchristos if install-info --remove $Info_Name $DIR_FILE; then 304*29619d2aSchristos Total=`expr "$Total" + "1"` 305*29619d2aSchristos fi 306*29619d2aSchristos done 307*29619d2aSchristosfi 308*29619d2aSchristos 309*29619d2aSchristos# print summary 310*29619d2aSchristosif test "$Changed"; then 311*29619d2aSchristos echo "$Total $DONE_MSG" 312*29619d2aSchristoselse 313*29619d2aSchristos echo "Nothing to do" 314*29619d2aSchristosfi 315*29619d2aSchristosrm -f $TMP_FILE_LIST 316*29619d2aSchristoseval "$DEBUG" 317*29619d2aSchristosexit 0 318