home *** CD-ROM | disk | FTP | other *** search
/ BURKS 2 / BURKS_AUG97.ISO / SLAKWARE / AP5 / TEXINFO.TGZ / TEXINFO.tar / usr / bin / texi2dvi < prev    next >
Text File  |  1997-02-01  |  14KB  |  365 lines

  1. #! /bin/sh
  2. # texi2dvi --- smartly produce DVI files from texinfo sources
  3.  
  4. # Copyright (C) 1992, 93, 94, 95, 96 Free Software Foundation, Inc.
  5.  
  6. # $Id: texi2dvi,v 1.10 1996/10/04 18:21:55 karl Exp $
  7.  
  8. # This program is free software; you can redistribute it and/or modify
  9. # it under the terms of the GNU General Public License as published by
  10. # the Free Software Foundation; either version 2, or (at your option)
  11. # any later version.
  12. #
  13. # This program is distributed in the hope that it will be useful,
  14. # but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. # GNU General Public License for more details.
  17. #
  18. # You should have received a copy of the GNU General Public License
  19. # along with this program; if not, you can either send email to this
  20. # program's maintainer or write to: The Free Software Foundation,
  21. # Inc.; 59 Temple Place, Suite 330; Boston, MA 02111-1307, USA.
  22.  
  23. # Commentary:
  24.  
  25. # Author: Noah Friedman <friedman@prep.ai.mit.edu>
  26.  
  27. # Please send bug reports, etc. to bug-texinfo@prep.ai.mit.edu
  28. # If possible, please send a copy of the output of the script called with
  29. # the `--debug' option when making a bug report.
  30.  
  31. # In the interest of general portability, some common bourne shell
  32. # constructs were avoided because they weren't guaranteed to be available
  33. # in some earlier implementations.  I've tried to make this program as
  34. # portable as possible.  Welcome to unix, where the lowest common
  35. # denominator is rapidly diminishing.
  36. #
  37. # Among the more interesting lossages I noticed with some bourne shells
  38. # are:
  39. #     * No shell functions.
  40. #     * No `unset' builtin.
  41. #     * `shift' cannot take a numeric argument, and signals an error if
  42. #       there are no arguments to shift.
  43.  
  44. # Code:
  45.  
  46. # Name by which this script was invoked.
  47. progname=`echo "$0" | sed -e 's/[^\/]*\///g'`
  48.  
  49. # This string is expanded by rcs automatically when this file is checked out.
  50. rcs_revision='$Revision: 1.10 $'
  51. version=`set - $rcs_revision; echo $2`
  52.  
  53. # To prevent hairy quoting and escaping later.
  54. bq='`'
  55. eq="'"
  56.  
  57. usage="Usage: $0 [OPTION]... FILE...
  58. Run a Texinfo document through TeX.
  59.  
  60. Options:
  61. -D, --debug          Turn on shell debugging ($bq${bq}set -x$eq$eq).
  62. -t, --texinfo CMD    Insert CMD after @setfilename before running TeX.
  63. --verbose            Report on what is done.
  64. -h, --help           Display this help and exit.
  65. -v, --version        Display version information and exit.
  66.  
  67. The values of the TEX, TEXINDEX, and MAKEINFO environment variables are
  68. used to run those commands, if they are set.
  69.  
  70. Email bug reports to bug-texinfo@prep.ai.mit.edu.
  71. "
  72.  
  73. # Initialize variables.
  74. # Don't use `unset' since old bourne shells don't have this command.
  75. # Instead, assign them an empty value.
  76. # Some of these, like TEX and TEXINDEX, may be inherited from the environment.
  77. backup_extension=.bak # these files get deleted if all goes well.
  78. debug=
  79. orig_pwd="`pwd`"
  80. textra=
  81. verbose=false
  82. makeinfo="${MAKEINFO-makeinfo}"
  83. texindex="${TEXINDEX-texindex}"
  84. tex="${TEX-tex}"
  85.  
  86. # Save this so we can construct a new TEXINPUTS path for each file.
  87. TEXINPUTS_orig="$TEXINPUTS"
  88. export TEXINPUTS
  89.  
  90. # Parse command line arguments.
  91. # Make sure that all wildcarded options are long enough to be unambiguous.
  92. # It's a good idea to document the full long option name in each case.
  93. # Long options which take arguments will need a `*' appended to the
  94. # canonical name to match the value appended after the `=' character.
  95. while : ; do
  96.   case $# in 0) break ;; esac
  97.   case "$1" in
  98.     -D | --debug | --d* ) debug=t; shift ;;
  99.     -h | --help | --h* )   echo "$usage"; exit 0 ;;
  100.     # OK, we should do real option parsing here, but be lazy for now.
  101.     -t | --texinfo | --t*) shift; textra="$textra $1"; shift ;; 
  102.     -v | --vers* )
  103.       echo "$progname (Texinfo 3.9) $version"
  104.       echo "Copyright (C) 1996 Free Software Foundation, Inc.
  105. There is NO warranty.  You may redistribute this software
  106. under the terms of the GNU General Public License.
  107. For more information about these matters, see the files named COPYING."
  108.       exit 0 ;;
  109.     --verb* )            verbose=echo; shift ;;
  110.     -- )     # Stop option processing
  111.       shift
  112.       break
  113.      ;;
  114.     -* )
  115.       case "$1" in
  116.         --*=* ) arg=`echo "$1" | sed -e 's/=.*//'` ;;
  117.         * )     arg="$1" ;;
  118.       esac
  119.       exec 1>&2
  120.       echo "$progname: Unknown or ambiguous option $bq$arg$eq."
  121.       echo "$progname: Try $bq--help$eq for more information."
  122.       exit 1
  123.      ;;
  124.     * )
  125.       break
  126.      ;;
  127.    esac
  128. done
  129.  
  130. # See if there are any command line args left (which will be interpreted as
  131. # filename arguments).
  132. if test $# -eq 0; then
  133.   exec 1>&2
  134.   echo "$progname: At least one file name is required as an argument."
  135.   echo "$progname: Try $bq--help$eq for more information."
  136.   exit 2
  137. fi
  138.  
  139. test "$debug" = t && set -x
  140.  
  141. # Texify files
  142. for command_line_filename in ${1+"$@"} ; do
  143.   $verbose "Processing $command_line_filename ..."
  144.  
  145.   # See if file exists.  If it doesn't we're in trouble since, even
  146.   # though the user may be able to reenter a valid filename at the tex
  147.   # prompt (assuming they're attending the terminal), this script won't
  148.   # be able to find the right index files and so forth.
  149.   if test ! -r "${command_line_filename}" ; then
  150.     echo "$0: Could not read ${command_line_filename}." >&2
  151.     continue
  152.   fi
  153.  
  154.   # Roughly equivalent to `dirname ...`, but more portable
  155.   directory="`echo ${command_line_filename} | sed 's/\/[^\/]*$//'`"
  156.   filename_texi="`basename ${command_line_filename}`"
  157.   # Strip off the last extension part (probably .texinfo or .texi)
  158.   filename_noext="`echo ${filename_texi} | sed 's/\.[^.]*$//'`"
  159.  
  160.   # Use same basename since we want to generate aux files with the same
  161.   # basename as the manual.  Use extension .texi for the temp file so
  162.   # that TeX will ignore it.  Thus, we must use a subdirectory.
  163.   #
  164.   # Output the macro-expanded file to here.
  165.   tmp_dir=${TMPDIR-/tmp}/$$
  166.   filename_tmp=$tmp_dir/$filename_noext.texi
  167.   # Output the file with the user's extra commands to here.
  168.   filename_tmp2=$tmp_dir.2/$filename_noext.texi
  169.   mkdir $tmp_dir $tmp_dir.2
  170.  
  171.   # If directory and file are the same, then it's probably because there's
  172.   # no pathname component.  Set dirname to `.', the current directory.
  173.   if test "z${directory}" = "z${command_line_filename}" ; then
  174.      directory=.
  175.   fi
  176.  
  177.   # Source file might @include additional texinfo sources.  Put `.' and
  178.   # directory where source file(s) reside in TEXINPUTS before anything
  179.   # else.  `.' goes first to ensure that any old .aux, .cps, etc. files in
  180.   # ${directory} don't get used in preference to fresher files in `.'.
  181.   TEXINPUTS=".:${directory}:${TEXINPUTS_orig}"
  182.  
  183.   # Expand macro commands in the original source file using Makeinfo;
  184.   #   the macro syntax bfox implemented is impossible to implement in TeX.
  185.   # Always use `end' footnote style, since the `separate' style
  186.   #   generates different output (arguably this is a bug in -E).
  187.   # Discard main info output, the user asked to run TeX, not makeinfo.
  188.   # Redirect output to /dev/null to throw away `Making info file...' msg.
  189.   $verbose "Macro-expanding $command_line_filename to $filename_tmp ..."
  190.   $makeinfo --footnote-style=end -E $filename_tmp -o /dev/null \
  191.     $command_line_filename >/dev/null
  192.  
  193.   # But if there were no macros, or makeinfo failed for some reason,
  194.   # just use the original file.  (It shouldn't make any difference, but
  195.   # let's be safe.)
  196.   if test $? -ne 0 || cmp -s $filename_tmp $command_line_filename; then
  197.     $verbose "Reverting to $command_line_filename ..."
  198.     filename_input=$command_line_filename
  199.   else
  200.     filename_input=$filename_tmp
  201.   fi
  202.  
  203.   # Used most commonly for @finalout, @smallbook, etc.
  204.   if test -n "$textra"; then
  205.     $verbose "Inserting extra commands: $textra."
  206.     sed '/^@setfilename/a\
  207. '"$textra" $filename_input >$filename_tmp2
  208.    filename_input=$filename_tmp2
  209.   fi
  210.  
  211.   while true; do # will break out of loop below
  212.     # "Unset" variables that might have values from previous iterations and
  213.     # which won't be completely reset later.
  214.     definite_index_files=
  215.  
  216.     # Find all files having root filename with a two-letter extension,
  217.     # determine whether they're rea