home *** CD-ROM | disk | FTP | other *** search
/ Dream 52 / Amiga_Dream_52.iso / OS2 / gnuinfo.zip / util / gen-dir-node < prev    next >
Text File  |  1997-05-22  |  6KB  |  182 lines

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