1#!/bin/sh 2# $Id: gen-dir-node,v 1.6 2016/09/02 11:50:48 tb 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 24INFODIR=$1 25if [ $# = 2 ] ; then 26 SKELETON=$2 27else 28 SKELETON=/dev/null 29fi 30 31skip= 32 33if [ $# -gt 2 ] ; then 34 echo usage: $0 info-directory [ skeleton-file ] 1>&2 35 exit 1 36elif [ -z "${INFODIR}" ] ; then 37 INFODIR="%%DEFAULT_INFO_DIR%%" 38else 39 true 40fi 41 42if [ ! -d ${INFODIR} ] ; then 43 echo "$0: first argument must specify a directory" 44 exit 1 45fi 46 47### output the dir header 48echo "-*- Text -*-" 49echo "This file was generated automatically by $0." 50 51cat << moobler 52\$Id: gen-dir-node,v 1.6 2016/09/02 11:50:48 tb Exp $ 53This is the file .../info/dir, which contains the topmost node of the 54Info hierarchy. The first time you invoke Info you start off 55looking at that node, which is (dir)Top. 56 57File: dir Node: Top This is the top of the INFO tree 58 59 This (the Directory node) gives a menu of major topics. 60 Typing "q" exits, "?" lists all Info commands, "d" returns here, 61 "h" gives a primer for first-timers, 62 "mEmacs<Return>" visits the Emacs topic, etc. 63 64 In Emacs, you can click mouse button 2 on a menu item or cross reference 65 to select it. 66 67* Menu: The list of major topics begins on the next line. 68 69moobler 70 71### go through the list of files in the skeleton. If an info file 72### exists, grab the ENTRY information from it. If an entry exists 73### use it, otherwise create a minimal dir entry. 74### 75### Then remove that file from the list of existing files. If any 76### additional files remain (ones that don't have a skeleton entry), 77### then generate entries for those in the same way, putting the info for 78### those at the end.... 79 80infofiles=`(cd ${INFODIR}; /bin/ls | grep -v '\-[0-9]*$' | egrep -v '^dir$|^dir\.info$|^dir\.orig$')` 81 82# echoing gets clobbered by backquotes; we do it the hard way... 83lines=`wc $SKELETON | awk '{print $1}'` 84line=1 85while [ $lines -ge $line ] ; do 86 # Read one line from the file. This is so that we can echo lines with 87 # whitespace and quoted characters in them. 88 fileline=`awk NR==$line $SKELETON` 89 90 # flag fancy features 91 if [ ! -z "$echoline" ] ; then # echo line 92 echo "$fileline" 93 fileline= 94 echoline= 95 elif [ "${fileline}" = "--" ] ; then # should we echo the next line? 96 echoline=1 97 elif [ "${fileline}" = "%%" ] ; then # eliminate remaining files from dir? 98 skip=1 99 elif [ "${fileline}" = "!!" ] ; then # quit now 100 exit 0 101 fi 102 103 # handle files if they exist 104 for file in $fileline"" ; do # expand wildcards ("" handles blank lines) 105 106 fname= 107 108 if [ -z "$echoline" ] && [ ! -z "$file" ] ; then 109 # Find the file to operate upon. Check both possible names. 110 infoname=`echo $file | sed 's/\.info$//'` 111 noext= 112 ext= 113 if [ -f ${INFODIR}/$infoname ] ; then 114 noext=$infoname 115 fi 116 if [ -f ${INFODIR}/${infoname}.info ] ; then 117 ext=${infoname}.info 118 fi 119 120 # If it exists with both names take what was said in the file. 121 if [ ! -z "$ext" ] && [ ! -z "$noext" ]; then 122 fname=$file 123 warn="### Warning: $ext and $noext both exist! Using ${file}. ###" 124 elif [ ! -z "${noext}${ext}" ]; then 125 # just take the name if it exists only once 126 fname=${noext}${ext} 127 fi 128 129 # if we found something and aren't skipping, do the entry 130 if [ ! -z "$fname" ] ; then 131 if [ -z "$skip" ] ; then 132 133 if [ ! -z "$warn" ] ; then # issue any warning 134 echo $warn 135 warn= 136 fi 137 138 entry=`sed -e '1,/START-INFO-DIR-ENTRY/d' \ 139 -e '/END-INFO-DIR-ENTRY/,$d' ${INFODIR}/$fname` 140 if [ ! -z "${entry}" ] ; then 141 echo "${entry}" 142 else 143 echo "* ${infoname}: (${infoname})." 144 fi 145 fi 146 147 # remove the name from the directory listing 148 infofiles=`echo "" ${infofiles} "" | sed -e "s/ ${fname} / /" -e "s/ / /g"` 149 150 fi 151 152 fi 153 154 done 155 156 line=`expr $line + 1` 157done 158 159if [ -z "${infofiles}" ] ; then 160 exit 0 161elif [ $lines -gt 0 ]; then 162 echo 163fi 164 165# Sort remaining files by INFO-DIR-SECTION. 166prevsect= 167filesectdata=`(cd ${INFODIR}; \ 168 fgrep -a INFO-DIR-SECTION /dev/null ${infofiles} | \ 169 fgrep -v 'INFO-DIR-SECTION Miscellaneous' | \ 170 sort -t: -k2 -k1 | tr ' ' '_')` 171for sectdata in ${filesectdata}; do 172 file=`echo ${sectdata} | cut -d: -f1` 173 section=`sed -n -e 's/^INFO-DIR-SECTION //p' ${INFODIR}/${file}` 174 infofiles=`echo "" ${infofiles} "" | sed -e "s/ ${file} / /" -e "s/ / /g"` 175 176 if [ "${prevsect}" != "${section}" ] ; then 177 if [ ! -z "${prevsect}" ] ; then 178 echo "" 179 fi 180 echo "${section}" 181 prevsect="${section}" 182 fi 183 184 infoname=`echo $file | sed 's/\.info$//'` 185 entry=`sed -e '1,/START-INFO-DIR-ENTRY/d' \ 186 -e '/END-INFO-DIR-ENTRY/,$d' ${INFODIR}/${file}` 187 if [ ! -z "${entry}" ] ; then 188 echo "${entry}" 189 elif [ ! -d "${INFODIR}/${file}" ] ; then 190 echo "* ${infoname}: (${infoname})." 191 fi 192done 193 194# Process miscellaneous files. 195for file in ${infofiles}; do 196 if [ ! -z "${prevsect}" ] ; then 197 echo "" 198 echo "Miscellaneous" 199 prevsect="" 200 fi 201 202 infoname=`echo $file | sed 's/\.info$//'` 203 entry=`sed -e '1,/START-INFO-DIR-ENTRY/d' \ 204 -e '/END-INFO-DIR-ENTRY/,$d' ${INFODIR}/${file}` 205 206 if [ ! -z "${entry}" ] ; then 207 echo "${entry}" 208 elif [ ! -d "${INFODIR}/${file}" ] ; then 209 echo "* ${infoname}: (${infoname})." 210 fi 211done 212