home *** CD-ROM | disk | FTP | other *** search
/ GEMini Atari / GEMini_Atari_CD-ROM_Walnut_Creek_December_1993.iso / zip / gnu / tinfo210.lzh / TINFO210 / TEXI2DVI < prev    next >
Text File  |  1991-09-27  |  3KB  |  123 lines

  1. #!/bin/sh
  2. #
  3. # texi2dvi - prepare Texinfo files for printing.  
  4. #
  5. # Copyright (C) 1990, 1991 Free Software Foundation.
  6. #
  7. # Roland McGrath <roland@gnu.ai.mit.edu>
  8. # Version 0.10
  9. # 24 Sep 91
  10. #
  11. # This program is free software; you can redistribute it and/or modify
  12. # it under the terms of the GNU General Public License as published by
  13. # the Free Software Foundation; either version 1, or (at your option)
  14. # any later version.
  15. #
  16. # This program is distributed in the hope that it will be useful,
  17. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  18. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  19. # GNU General Public License for more details.
  20. #
  21. # A copy of the GNU General Public License can be obtained from this
  22. # program's author (send electronic mail to roland@ai.mit.edu) or from
  23. # the Free Software Foundation, Inc., 675 Mass Ave, Cambridge, MA
  24. # 02139, USA.
  25.  
  26. if [ $# -eq 0 ]; then
  27.   echo "Usage: `basename $0` FILE ..." >&2
  28.   exit 1
  29. fi
  30.  
  31. TEXINDEX=${TEXINDEX-texindex}
  32. TEX=${TEXINFO-${TEX-tex}}
  33.  
  34. for file in $*; do
  35.   base="`basename $file .texinfo | \
  36.      sed -e 's/\.texi$//' -e 's/\.tex$//'`"
  37.  
  38.   # Find all existing index files corresponding to FILE.
  39.   idx_files="`echo ${base}.??`"
  40.   if [ "$idx_files" = "${base}.??" ]; then
  41.     idx_files=''
  42.   else
  43.     # Ignore files with two-letter extensions that don't look like index files.
  44.     oidx_files="$idx_files"
  45.     idx_files=''
  46.     for idx_file in $oidx_files; do
  47.       if [ "`sed -n '1s/^\(.\).*$/\1/p' $idx_file`" = \\ ]; then
  48.         # It starts with a backslash, so it's probably an index file.
  49.     idx_files="$idx_files $idx_file"
  50.       fi
  51.     done
  52.   fi
  53.  
  54.   for idx_file in $idx_files; do
  55.     # Save a copy of the old index file.
  56.     cp ${idx_file} ${idx_file}O
  57.   done
  58.  
  59.   if [ "$idx_files" != "" ]; then
  60.     # Run texindex on the index files.
  61.     ${TEXINDEX} $idx_files
  62.   fi
  63.  
  64.   # Run TeX on FILE.
  65.   if ${TEX} $file; then
  66.  
  67.     # Find all the index files that exist now,
  68.     # so we can see if there are any new ones.
  69.     new_idx_files="`echo ${base}.??`"
  70.     if [ "$new_idx_files" = "${base}.??" ]; then
  71.       new_idx_files=''
  72.     else
  73.       oidx_files="$idx_files"
  74.       new_idx_files=''
  75.       for idx_file in $oidx_files; do
  76.     if [ "`sed -n '1s/^\(.\).*$/\1/p' $idx_file`" = \\ ]; then
  77.       # It starts with a backslash, so it's probably an index file.
  78.       new_idx_files="$new_idx_files $idx_file"
  79.     fi
  80.       done
  81.     fi
  82.  
  83.     if [ "$new_idx_files" != "$idx_files" ]; then
  84.       # There are some new index files.
  85.       changed=yes
  86.       idx_files="$new_idx_files"
  87.     else
  88.       # Run through all the index files, comparing them to the old ones.
  89.       changed=no
  90.       for idx_file in $idx_files; do
  91.     # Compare the old and new index files.
  92.     cmp -s ${idx_file}O ${idx_file}
  93.     status=$?
  94.  
  95.     # Remove the old index file.
  96.     rm -f ${idx_file}O
  97.  
  98.     if [ $status -ne 0 ]; then
  99.       # The index file has changed.
  100.       changed=yes
  101.     fi
  102.       done    # for idx_file
  103.     fi
  104.  
  105.     if [ $changed = yes ]; then
  106.       # Some index file changed.  Run texindex and TeX again.
  107.  
  108.       # Run texindex on the index files.
  109.       if ${TEXINDEX} $idx_files; then
  110.     # Run TeX on FILE.
  111.     ${TEX} $file
  112.       fi
  113.     fi
  114.   else
  115.     # TeX failed.  Remove the copies of the index files.
  116.     for idx_file in $idx_files; do
  117.       rm ${idx_file}O
  118.     done
  119.   fi
  120.  
  121. done       # for file
  122.  
  123.