#!/bin/sh# $Id: gen-dir-node,v 1.1 2004/10/28 18:14:11 zooey Exp $# Generate the top-level Info node, given a directory of Info files# and (optionally) a skeleton file. The output will be suitable for a# top-level dir file. The skeleton file contains info topic names in the# order they should appear in the output. There are three special# lines that alter the behavior: a line consisting of just "--" causes# the next line to be echoed verbatim to the output. A line# containing just "%%" causes all the remaining filenames (wildcards# allowed) in the rest of the file to be ignored. A line containing# just "!!" exits the script when reached (unless preceded by a line# containing just "--"). Once the script reaches the end of the# skeleton file, it goes through the remaining files in the directory# in order, putting their entries at the end. The script will use the# ENTRY information in each info file if it exists. Otherwise it will# make a minimal entry.# sent by Jeffrey Osier <jeffrey@cygnus.com>, who thinks it came from# zoo@winternet.com (david d `zoo' zuhn)# modified 7 April 1995 by Joe Harrington <jh@tecate.gsfc.nasa.gov> to# take special flagsINFODIR=$1if [ $# = 2 ] ; thenSKELETON=$2elseSKELETON=/dev/nullfiskip=if [ $# -gt 2 ] ; thenecho usage: $0 info-directory [ skeleton-file ] 1>&2exit 1elsetruefiif [ ! -d ${INFODIR} ] ; thenecho "$0: first argument must specify a directory"exit 1fi### output the dir headerecho "-*- Text -*-"echo "This file was generated automatically by $0."echo "This version was generated on `date`"echo "by `whoami`@`hostname` for `(cd ${INFODIR}; pwd)`"cat << mooblerThis is the file .../info/dir, which contains the topmost node of theInfo hierarchy. The first time you invoke Info you start offlooking at that node, which is (dir)Top.File: dir Node: Top This is the top of the INFO treeThis (the Directory node) gives a menu of major topics.Typing "d" returns here, "q" exits, "?" lists all INFO commands, "h"gives a primer for first-timers, "mTexinfo<Return>" visits Texinfo topic,etc.Or click mouse button 2 on a menu item or cross reference to select it.--- PLEASE ADD DOCUMENTATION TO THIS TREE. (See INFO topic first.) ---* Menu: The list of major topics begins on the next line.moobler### go through the list of files in the skeleton. If an info file### exists, grab the ENTRY information from it. If an entry exists### use it, otherwise create a minimal dir entry.###### Then remove that file from the list of existing files. If any### additional files remain (ones that don't have a skeleton entry),### then generate entries for those in the same way, putting the info for### those at the end....infofiles=`(cd ${INFODIR}; ls | egrep -v '\-|^dir$|^dir\.info$|^dir\.orig$')`# echoing gets clobbered by backquotes; we do it the hard way...lines=`wc $SKELETON | awk '{print $1}'`line=1while [ $lines -ge $line ] ; do# Read one line from the file. This is so that we can echo lines with# whitespace and quoted characters in them.fileline=`awk NR==$line $SKELETON`# flag fancy featuresif [ ! -z "$echoline" ] ; then # echo lineecho "$fileline"fileline=echoline=elif [ "${fileline}" = "--" ] ; then # should we echo the next line?echoline=1elif [ "${fileline}" = "%%" ] ; then # eliminate remaining files from dir?skip=1elif [ "${fileline}" = "!!" ] ; then # quit nowexit 0fi# handle files if they existfor file in $fileline"" ; do # expand wildcards ("" handles blank lines)fname=if [ -z "$echoline" -a ! -z "$file" ] ; then# Find the file to operate upon. Check both possible names.infoname=`echo $file | sed 's/\.info$//'`noext=ext=if [ -f ${INFODIR}/$infoname ] ; thennoext=$infonamefiif [ -f ${INFODIR}/${infoname}.info ] ; thenext=${infoname}.infofi# If it exists with both names take what was said in the file.if [ ! -z "$ext" -a ! -z "$noext" ]; thenfname=$filewarn="### Warning: $ext and $noext both exist! Using ${file}. ###"elif [ ! \( -z "$ext" -a -z "$noext" \) ]; then# just take the name if it exists only oncefname=${noext}${ext}fi# if we found something and aren't skipping, do the entryif [ ! -z "$fname" ] ; thenif [ -z "$skip" ] ; thenif [ ! -z "$warn" ] ; then # issue any warningecho $warnwarn=fientry=`sed -e '1,/START-INFO-DIR-ENTRY/d' \-e '/END-INFO-DIR-ENTRY/,$d' ${INFODIR}/$fname`if [ ! -z "${entry}" ] ; thenecho "${entry}"elseecho "* ${infoname}: (${fname})."fifi# remove the name from the directory listinginfofiles=`echo ${infofiles} | sed -e "s/ ${fname} / /" \-e "s/^${fname} //" \-e "s/ ${fname}$//"`fifidoneline=`expr $line + 1`doneif [ -z "${infofiles}" ] ; thenexit 0elseechofifor file in ${infofiles}; docase $file in*.gz) zcat=zcat; file=`echo $file|sed 's/\.gz$//'`; gz=.gz;;*) zcat=cat; gz=;;esacinfoname=`echo $file | sed 's/\.info$//'`entry=`$zcat ${INFODIR}/${file}$gz \|sed -e '1,/START-INFO-DIR-ENTRY/d' \-e '/END-INFO-DIR-ENTRY/,$d'`if [ ! -z "${entry}" ] ; thenecho "${entry}"elseecho "* ${infoname}: (${file})."fidone