diff options
Diffstat (limited to 'readline/doc/texi2dvi')
-rwxr-xr-x | readline/doc/texi2dvi | 728 |
1 files changed, 467 insertions, 261 deletions
diff --git a/readline/doc/texi2dvi b/readline/doc/texi2dvi index 3d7134d..c186848 100755 --- a/readline/doc/texi2dvi +++ b/readline/doc/texi2dvi @@ -1,8 +1,8 @@ #! /bin/sh -# texi2dvi --- smartly produce DVI files from texinfo sources +# texi2dvi --- produce DVI (or PDF) files from Texinfo (or LaTeX) sources. # $Id$ # -# Copyright (C) 1992, 93, 94, 95, 96, 97, 98 Free Software Foundation, Inc. +# Copyright (C) 1992, 93, 94, 95, 96, 97, 98, 99 Free Software Foundation, Inc. # # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by @@ -19,344 +19,550 @@ # program's maintainer or write to: The Free Software Foundation, # Inc.; 59 Temple Place, Suite 330; Boston, MA 02111-1307, USA. # -# Commentary: -# -# Author: Noah Friedman <friedman@gnu.org> +# Original author: Noah Friedman <friedman@gnu.org>. # # Please send bug reports, etc. to bug-texinfo@gnu.org. # If possible, please send a copy of the output of the script called with # the `--debug' option when making a bug report. -# -# In the interest of general portability, some common bourne shell -# constructs were avoided because they weren't guaranteed to be available -# in some earlier implementations. I've tried to make this program as -# portable as possible. Welcome to unix, where the lowest common -# denominator is rapidly diminishing. -# -# Among the more interesting lossages I noticed among Bourne shells: -# * No shell functions. -# * No `unset' builtin. -# * `shift' cannot take a numeric argument, and signals an error if -# there are no arguments to shift. -# -# Code: - -# Name by which this script was invoked. -progname=`echo "$0" | sed -e 's/[^\/]*\///g'` # This string is expanded by rcs automatically when this file is checked out. rcs_revision='$Revision$' -version=`set - $rcs_revision; echo $2` - -# To prevent hairy quoting and escaping later. -bq='`' -eq="'" +rcs_version=`set - $rcs_revision; echo $2` +program=`echo $0 | sed -e 's!.*/!!'` +version="texi2dvi (GNU Texinfo 4.0) $rcs_version -usage="Usage: $0 [OPTION]... FILE... -Run a Texinfo document through TeX. +Copyright (C) 1999 Free Software Foundation, Inc. +There is NO warranty. You may redistribute this software +under the terms of the GNU General Public License. +For more information about these matters, see the files named COPYING." -Options: --b, --batch No interaction (\nonstopmode in TeX). --c, --clean Remove all auxiliary files. --D, --debug Turn on shell debugging ($bq${bq}set -x$eq$eq). --t, --texinfo CMD Insert CMD after @setfilename before running TeX. ---verbose Report on what is done. --h, --help Display this help and exit. --v, --version Display version information and exit. +usage="Usage: $program [OPTION]... FILE... -The values of the TEX, TEXINDEX, and MAKEINFO environment variables are -used to run those commands, if they are set. +Run each Texinfo or LaTeX FILE through TeX in turn until all +cross-references are resolved, building all indices. The directory +containing each FILE is searched for included files. The suffix of FILE +is used to determine its language (LaTeX or Texinfo). -Email bug reports to bug-texinfo@gnu.org." +Makeinfo is used to perform Texinfo macro expansion before running TeX +when needed. -# Initialize variables. +Options: + -@ Use @input instead of \input; for preloaded Texinfo. + -b, --batch No interaction. + -c, --clean Remove all auxiliary files. + -D, --debug Turn on shell debugging (set -x). + -e, --expand Force macro expansion using makeinfo. + -I DIR Search DIR for Texinfo files. + -h, --help Display this help and exit successfully. + -l, --language=LANG Specify the LANG of FILE: LaTeX or Texinfo. + -p, --pdf Use pdftex or pdflatex for processing. + -q, --quiet No output unless errors (implies --batch). + -s, --silent Same as --quiet. + -t, --texinfo=CMD Insert CMD after @setfilename in copy of input file. + Multiple values accumulate. + -v, --version Display version information and exit successfully. + -V, --verbose Report on what is done. + +The values of the BIBTEX, LATEX (or PDFLATEX), MAKEINDEX, MAKEINFO, +TEX (or PDFTEX), and TEXINDEX environment variables are used to run +those commands, if they are set. + +Email bug reports to <bug-texinfo@gnu.org>, +general questions and discussion to <help-texinfo@gnu.org>." + +# Initialize variables for option overriding and otherwise. # Don't use `unset' since old bourne shells don't have this command. # Instead, assign them an empty value. -# Some of these, like TEX and TEXINDEX, may be inherited from the environment. -backup_extension=.bak # these files get deleted if all goes well. -batch= +escape='\' +batch=false # eval for batch mode clean= debug= -orig_pwd="`pwd`" +expand= # t for expansion via makeinfo +oformat=dvi +set_language= +miincludes= # makeinfo include path textra= -verbose=false -makeinfo="${MAKEINFO-makeinfo}" -texindex="${TEXINDEX-texindex}" -tex="${TEX-tex}" +tmpdir=${TMPDIR:-/tmp}/t2d$$ # avoid collisions on 8.3 filesystems. +txincludes= # TEXINPUTS extensions +txiprereq=19990129 # minimum texinfo.tex version to have macro expansion +quiet= # by default let the tools' message be displayed +verbose=false # echo for verbose mode + +orig_pwd=`pwd` + +# Systems which define $COMSPEC or $ComSpec use semicolons to separate +# directories in TEXINPUTS. +if test -n "$COMSPEC$ComSpec"; then + path_sep=";" +else + path_sep=":" +fi # Save this so we can construct a new TEXINPUTS path for each file. TEXINPUTS_orig="$TEXINPUTS" -export TEXINPUTS - +# Unfortunately makeindex does not read TEXINPUTS. +INDEXSTYLE_orig="$INDEXSTYLE" +export TEXINPUTS INDEXSTYLE + +# Push a token among the arguments that will be used to notice when we +# ended options/arguments parsing. +# Use "set dummy ...; shift" rather than 'set - ..." because on +# Solaris set - turns off set -x (but keeps set -e). +# Use ${1+"$@"} rather than "$@" because Digital Unix and Ultrix 4.3 +# still expand "$@" to a single argument (the empty string) rather +# than nothing at all. +arg_sep="$$--$$" +set dummy ${1+"$@"} "$arg_sep"; shift + +# # Parse command line arguments. -# Make sure that all wildcarded options are long enough to be unambiguous. -# It's a good idea to document the full long option name in each case. -# Long options which take arguments will need a `*' appended to the -# canonical name to match the value appended after the `=' character. -while :; do - test $# -eq 0 && break - +while test x"$1" != x"$arg_sep"; do + + # Handle --option=value by splitting apart and putting back on argv. case "$1" in - -b | --batch | --b* ) batch=t; shift ;; - -c | --clean | --c* ) clean=t; shift ;; - -D | --debug | --d* ) debug=t; shift ;; - -h | --help | --h* ) echo "$usage"; exit 0 ;; - # OK, we should do real option parsing here, but be lazy for now. - -t | --texinfo | --t*) shift; textra="$textra $1"; shift ;; - -v | --vers* ) - echo "$progname (GNU Texinfo 3.12) $version" - echo "Copyright (C) 1998 Free Software Foundation, Inc. -There is NO warranty. You may redistribute this software -under the terms of the GNU General Public License. -For more information about these matters, see the files named COPYING." - exit 0 ;; - --verb* ) verbose=echo; shift ;; - -- ) # Stop option processing + --*=*) + opt=`echo "$1" | sed -e 's/=.*//'` + val=`echo "$1" | sed -e 's/[^=]*=//'` + shift + set dummy "$opt" "$val" ${1+"$@"}; shift + ;; + esac + + # This recognizes --quark as --quiet. So what. + case "$1" in + -@ ) escape=@;; + # Silently and without documentation accept -b and --b[atch] as synonyms. + -b | --b*) batch=eval;; + -q | -s | --q* | --s*) quiet=t; batch=eval;; + -c | --c*) clean=t;; + -D | --d*) debug=t;; + -e | --e*) expand=t;; + -h | --h*) echo "$usage"; exit 0;; + -I | --I*) + shift + miincludes="$miincludes -I $1" + txincludes="$txincludes$path_sep$1" + ;; + -l | --l*) shift; set_language=$1;; + -p | --p*) oformat=pdf;; + -t | --t*) shift; textra="$textra\\ +$1";; + -v | --vers*) echo "$version"; exit 0;; + -V | --verb*) verbose=echo;; + --) # What remains are not options. shift - break ;; - -* ) - case "$1" in - --*=* ) arg=`echo "$1" | sed -e 's/=.*//'` ;; - * ) arg="$1" ;; - esac - exec 1>&2 - echo "$progname: Unknown or ambiguous option $bq$arg$eq." - echo "$progname: Try $bq--help$eq for more information." - exit 1 ;; - * ) break ;; + while test x"$1" != x"$arg_sep"; do + set dummy ${1+"$@"} "$1"; shift + shift + done + break;; + -*) + echo "$0: Unknown or ambiguous option \`$1'." >&2 + echo "$0: Try \`--help' for more information." >&2 + exit 1;; + *) set dummy ${1+"$@"} "$1"; shift;; esac + shift done +# Pop the token +shift -# See if there are any command line args left (which will be interpreted as -# filename arguments). -if test $# -eq 0; then - exec 1>&2 - echo "$progname: At least one file name is required as an argument." - echo "$progname: Try $bq--help$eq for more information." +# Interpret remaining command line args as filenames. +if test $# = 0; then + echo "$0: Missing file arguments." >&2 + echo "$0: Try \`--help' for more information." >&2 exit 2 fi +# Prepare the temporary directory. Remove it at exit, unless debugging. +if test -z "$debug"; then + trap "cd / && rm -rf $tmpdir" 0 1 2 15 +fi + +# Create the temporary directory with strict rights +(umask 077 && mkdir $tmpdir) || exit 1 + +# Prepare the tools we might need. This may be extra work in some +# cases, but improves the readibility of the script. +utildir=$tmpdir/utils +mkdir $utildir || exit 1 + +# A sed script that preprocesses Texinfo sources in order to keep the +# iftex sections only. We want to remove non TeX sections, and +# comment (with `@c texi2dvi') TeX sections so that makeinfo does not +# try to parse them. Nevertheless, while commenting TeX sections, +# don't comment @macro/@end macro so that makeinfo does propagate +# them. Unfortunately makeinfo --iftex --no-ifhtml --no-ifinfo +# doesn't work well enough (yet) to use that, so work around with sed. +comment_iftex_sed=$utildir/comment.sed +cat <<EOF >$comment_iftex_sed +/^@tex/,/^@end tex/{ + s/^/@c texi2dvi/ +} +/^@iftex/,/^@end iftex/{ + s/^/@c texi2dvi/ + /^@c texi2dvi@macro/,/^@c texi2dvi@end macro/{ + s/^@c texi2dvi// + } +} +/^@html/,/^@end html/d +/^@ifhtml/,/^@end ifhtml/d +/^@ifnottex/,/^@end ifnottex/d +/^@ifinfo/,/^@end ifinfo/{ + /^@node/p + /^@menu/,/^@end menu/p + d +} +EOF +# Uncommenting is simple: Remove any leading `@c texi2dvi'. +uncomment_iftex_sed=$utildir/uncomment.sed +cat <<EOF >$uncomment_iftex_sed +s/^@c texi2dvi// +EOF + +# A shell script that computes the list of xref files. +# Takes the filename (without extension) of which we look for xref +# files as argument. The index files must be reported last. +get_xref_files=$utildir/get_xref.sh +cat <<\EOF >$get_xref_files +#! /bin/sh + +# Get list of xref files (indexes, tables and lists). +# Find all files having root filename with a two-letter extension, +# saves the ones that are really Texinfo-related files. .?o? catches +# LaTeX tables and lists. +for this_file in "$1".?o? "$1".aux "$1".?? "$1".idx; do + # If file is empty, skip it. + test -s "$this_file" || continue + # If the file is not suitable to be an index or xref file, don't + # process it. The file can't be if its first character is not a + # backslash or single quote. + first_character=`sed -n '1s/^\(.\).*$/\1/p;q' $this_file` + if test "x$first_character" = "x\\" \ + || test "x$first_character" = "x'"; then + xref_files="$xref_files ./$this_file" + fi +done +echo "$xref_files" +EOF +chmod 500 $get_xref_files + +# File descriptor usage: +# 0 standard input +# 1 standard output (--verbose messages) +# 2 standard error +# 3 some systems may open it to /dev/tty +# 4 used on the Kubota Titan +# 5 tools output (turned off by --quiet) + +# Tools' output. If quiet, discard, else redirect to the message flow. +if test "$quiet" = t; then + exec 5>/dev/null +else + exec 5>&1 +fi + +# Enable tracing test "$debug" = t && set -x -# Texify files +# +# TeXify files. + for command_line_filename in ${1+"$@"}; do $verbose "Processing $command_line_filename ..." - # See if file exists. If it doesn't we're in trouble since, even + # If the COMMAND_LINE_FILENAME is not absolute (e.g., --debug.tex), + # prepend `./' in order to avoid that the tools take it as an option. + echo "$command_line_filename" | egrep '^(/|[A-z]:/)' >/dev/null \ + || command_line_filename="./$command_line_filename" + + # See if the file exists. If it doesn't we're in trouble since, even # though the user may be able to reenter a valid filename at the tex # prompt (assuming they're attending the terminal), this script won't - # be able to find the right index files and so forth. - if test ! -r "${command_line_filename}"; then - echo "$0: Could not read ${command_line_filename}." >&2 + # be able to find the right xref files and so forth. + if test ! -r "$command_line_filename"; then + echo "$0: Could not read $command_line_filename, skipping." >&2 continue fi - # Roughly equivalent to `dirname ...`, but more portable - directory="`echo ${command_line_filename} | sed 's/\/[^\/]*$//'`" - filename_texi="`basename ${command_line_filename}`" - # Strip off the last extension part (probably .texinfo or .texi) - filename_noext="`echo ${filename_texi} | sed 's/\.[^.]*$//'`" - - # Use same basename since we want to generate aux files with the same - # basename as the manual. Use extension .texi for the temp file so - # that TeX will ignore it. Thus, we must use a subdirectory. - # - # Output the macro-expanded file to here. The vastly abbreviated - # temporary directory name is so we don't have collisions on 8.3 or - # 14-character filesystems. - tmp_dir=${TMPDIR-/tmp}/txi2d.$$ - filename_tmp=$tmp_dir/$filename_noext.texi - # Output the file with the user's extra commands to here. - tmp_dir2=${tmp_dir}.2 - filename_tmp2=$tmp_dir2/$filename_noext.texi - mkdir $tmp_dir $tmp_dir2 - # Always remove the temporary directories. - trap "rm -rf $tmp_dir $tmp_dir2" 1 2 15 - - # If directory and file are the same, then it's probably because there's - # no pathname component. Set dirname to `.', the current directory. - if test "z${directory}" = "z${command_line_filename}"; then - directory=. - fi + # Get the name of the current directory. We want the full path + # because in clean mode we are in tmp, in which case a relative + # path has no meaning. + filename_dir=`echo $command_line_filename | sed 's!/[^/]*$!!;s!^$!.!'` + filename_dir=`cd "$filename_dir" >/dev/null && pwd` + + # Strip directory part but leave extension. + filename_ext=`basename "$command_line_filename"` + # Strip extension. + filename_noext=`echo "$filename_ext" | sed 's/\.[^.]*$//'` + ext=`echo "$filename_ext" | sed 's/^.*\.//'` + + # _src. Use same basename since we want to generate aux files with + # the same basename as the manual. If --expand, then output the + # macro-expanded file to here, else copy the original file. + tmpdir_src=$tmpdir/src + filename_src=$tmpdir_src/$filename_noext.$ext + + # _xtr. The file with the user's extra commands. + tmpdir_xtr=$tmpdir/xtr + filename_xtr=$tmpdir_xtr/$filename_noext.$ext + + # _bak. Copies of the previous xref files (another round is run if + # they differ from the new one). + tmpdir_bak=$tmpdir/bak + + # Make all those directories and give up if we can't succeed. + mkdir $tmpdir_src $tmpdir_xtr $tmpdir_bak || exit 1 - # Source file might @include additional texinfo sources. Put `.' and + # Source file might include additional sources. Put `.' and # directory where source file(s) reside in TEXINPUTS before anything - # else. `.' goes first to ensure that any old .aux, .cps, etc. files in - # ${directory} don't get used in preference to fresher files in `.'. - TEXINPUTS=".:${directory}:${TEXINPUTS_orig}" + # else. `.' goes first to ensure that any old .aux, .cps, + # etc. files in ${directory} don't get used in preference to fresher + # files in `.'. Include orig_pwd in case we are in clean mode, where + # we've cd'd to a temp directory. + common=".$path_sep$orig_pwd$path_sep$filename_dir$path_sep$txincludes$path_sep" + TEXINPUTS="$common$TEXINPUTS_orig" + INDEXSTYLE="$common$INDEXSTYLE_orig" + + # If the user explicitly specified the language, use that. + # Otherwise, if the first line is \input texinfo, assume it's texinfo. + # Otherwise, guess from the file extension. + if test -n "$set_language"; then + language=$set_language + elif sed 1q "$command_line_filename" | fgrep 'input texinfo' >/dev/null; then + language=texinfo + else + language= + fi + + # Get the type of the file (latex or texinfo) from the given language + # we just guessed, or from the file extension if not set yet. + case ${language:-$filename_ext} in + [lL]a[tT]e[xX] | *.ltx | *.tex) + # Assume a LaTeX file. LaTeX needs bibtex and uses latex for + # compilation. No makeinfo. + bibtex=${BIBTEX:-bibtex} + makeinfo= # no point in running makeinfo on latex source. + texindex=${MAKEINDEX:-makeindex} + if test $oformat = dvi; then + tex=${LATEX:-latex} + else + tex=${PDFLATEX:-pdflatex} + fi + ;; + + *) + # Assume a Texinfo file. Texinfo files need makeinfo, texindex and tex. + bibtex= + texindex=${TEXINDEX:-texindex} + if test $oformat = dvi; then + tex=${TEX:-tex} + else + tex=${PDFTEX:-pdftex} + fi + # Unless required by the user, makeinfo expansion is wanted only + # if texinfo.tex is too old. + if test "$expand" = t; then + makeinfo=${MAKEINFO:-makeinfo} + else + # Check if texinfo.tex performs macro expansion by looking for + # its version. The version is a date of the form YEAR-MO-DA. + # We don't need to use [0-9] to match the digits since anyway + # the comparison with $txiprereq, a number, will fail with non + # digits. + txiversion_tex=txiversion.tex + echo '\input texinfo.tex @bye' >$tmpdir/$txiversion_tex + # Run in the tmpdir to avoid leaving files. + eval `cd $tmpdir >/dev/null \ + && $tex $txiversion_tex 2>/dev/null \ +| sed -n 's/^.*\[\(.*\)version \(....\)-\(..\)-\(..\).*$/txiformat=\1 txiversion="\2\3\4"/p'` + $verbose "texinfo.tex preloaded as \`$txiformat', version is \`$txiversion' ..." + if test "$txiprereq" -le "$txiversion" >/dev/null 2>&1; then + makeinfo= + else + makeinfo=${MAKEINFO:-makeinfo} + fi + # As long as we had to run TeX, offer the user this convenience + if test "$txiformat" = Texinfo; then + escape=@ + fi + fi + ;; + esac - # Expand macro commands in the original source file using Makeinfo; - # the macro syntax bfox implemented is impossible to implement in TeX. + # Expand macro commands in the original source file using Makeinfo. # Always use `end' footnote style, since the `separate' style # generates different output (arguably this is a bug in -E). # Discard main info output, the user asked to run TeX, not makeinfo. - # Redirect output to /dev/null to throw away `Making info file...' msg. - $verbose "Macro-expanding $command_line_filename to $filename_tmp ..." - $makeinfo --footnote-style=end -E $filename_tmp -o /dev/null \ - $command_line_filename >/dev/null - - # But if there were no macros, or makeinfo failed for some reason, - # just use the original file. (It shouldn't make any difference, but - # let's be safe.) - if test $? -ne 0 || cmp -s $filename_tmp $command_line_filename; then + if test -n "$makeinfo"; then + $verbose "Macro-expanding $command_line_filename to $filename_src ..." + sed -f $comment_iftex_sed "$command_line_filename" \ + | $makeinfo --footnote-style=end -I "$filename_dir" $miincludes \ + -o /dev/null --macro-expand=- \ + | sed -f $uncomment_iftex_sed >"$filename_src" + filename_input=$filename_src + fi + + # If makeinfo failed (or was not even run), use the original file as input. + if test $? -ne 0 \ + || test ! -r "$filename_src"; then $verbose "Reverting to $command_line_filename ..." - cp -p $command_line_filename $filename_tmp + filename_input=$filename_dir/$filename_ext fi - filename_input=$filename_tmp - dirname_input=$tmp_dir # Used most commonly for @finalout, @smallbook, etc. if test -n "$textra"; then - $verbose "Inserting extra commands: $textra." + $verbose "Inserting extra commands: $textra" sed '/^@setfilename/a\ -'"$textra" $filename_input >$filename_tmp2 - filename_input=$filename_tmp2 - dirname_input=$tmp_dir2 +'"$textra" "$filename_input" >$filename_xtr + filename_input=$filename_xtr fi # If clean mode was specified, then move to the temporary directory. if test "$clean" = t; then - $verbose "cd $dirname_input" - cd $dirname_input || exit 1 - filename_input=`basename $filename_input` + $verbose "cd $tmpdir_src" + cd "$tmpdir_src" || exit 1 fi - while true; do # will break out of loop below - # "Unset" variables that might have values from previous iterations and - # which won't be completely reset later. - definite_index_files= - - # Find all files having root filename with a two-letter extension, - # determine whether they're really index files, and save them. Foo.aux - # is actually the cross-references file, but we need to keep track of - # that too. - possible_index_files="`eval echo ${filename_noext}.?? ${filename_noext}.aux`" - for this_file in ${possible_index_files}; do - # If file is empty, forget it. - test -s "${this_file}" || continue - - # Examine first character of file. If it's not suitable to be an - # index or xref file, don't process it. - first_character="`sed -n '1s/^\(.\).*$/\1/p;q' ${this_file}`" - if test "x${first_character}" = "x\\" \ - || test "x${first_character}" = "x'"; then - definite_index_files="${definite_index_files} ${this_file}" + while :; do # will break out of loop below + orig_xref_files=`$get_xref_files "$filename_noext"` + + # Save copies of originals for later comparison. + if test -n "$orig_xref_files"; then + $verbose "Backing up xref files: `echo $orig_xref_files | sed 's|\./||g'`" + cp $orig_xref_files $tmpdir_bak + fi + + # Run bibtex on current file. + # - If its input (AUX) exists. + # - If AUX contains both `\bibdata' and `\bibstyle'. + # - If some citations are missing (LOG contains `Citation'). + # or the LOG complains of a missing .bbl + # + # We run bibtex first, because I can see reasons for the indexes + # to change after bibtex is run, but I see no reason for the + # converse. + # + # Don't try to be too smart. Running bibtex only if the bbl file + # exists and is older than the LaTeX file is wrong, since the + # document might include files that have changed. Because there + # can be several AUX (if there are \include's), but a single LOG, + # looking for missing citations in LOG is easier, though we take + # the risk to match false messages. + if test -n "$bibtex" \ + && test -r "$filename_noext.aux" \ + && test -r "$filename_noext.log" \ + && (grep '^\\bibdata[{]' "$filename_noext.aux" \ + && grep '^\\bibstyle[{]' "$filename_noext.aux" \ + && (grep 'Warning:.*Citation.*undefined' "$filename_noext.log" \ + || grep 'No file .*\.bbl\.' "$filename_noext.log")) \ + >/dev/null 2>&1; \ + then + $verbose "Running $bibtex $filename_noext ..." + if $bibtex "$filename_noext" >&5; then :; else + echo "$0: $bibtex exited with bad status, quitting." >&2 + exit 1 + fi + fi + + # What we'll run texindex on -- exclude non-index files. + # Since we know index files are last, it is correct to remove everything + # before .aux and .?o?. + index_files=`echo "$orig_xref_files" \ + | sed "s!.*\.aux!!g; + s!./$filename_noext\..o.!!g; + s/^[ ]*//;s/[ ]*$//"` + # Run texindex (or makeindex) on current index files. If they + # already exist, and after running TeX a first time the index + # files don't change, then there's no reason to run TeX again. + # But we won't know that if the index files are out of date or + # nonexistent. + if test -n "$texindex" && test -n "$index_files"; then + $verbose "Running $texindex $index_files ..." + if $texindex $index_files 2>&5 1>&2; then :; else + echo "$0: $texindex exited with bad status, quitting." >&2 + exit 1 fi - done - orig_index_files="${definite_index_files}" - orig_index_files_sans_aux="`echo ${definite_index_files} \ - | sed 's/'${filename_noext}'\.aux//; - s/^[ ]*//;s/[ ]*$//;'`" - - # Now save copies of original index files so we have some means of - # comparison later. - $verbose "Backing up current index files: $orig_index_files ..." - for index_file_to_save in ${orig_index_files}; do - cp "${index_file_to_save}" "${index_file_to_save}${backup_extension}" - done - - # Run texindex on current index files. If they already exist, and - # after running TeX a first time the index files don't change, then - # there's no reason to run TeX again. But we won't know that if the - # index files are out of date or nonexistent. - if test -n "${orig_index_files_sans_aux}"; then - $verbose "Running $texindex $orig_index_files_sans_aux ..." - ${texindex} ${orig_index_files_sans_aux} fi # Finally, run TeX. - if test "$batch" = t; then - tex_mode='\nonstopmode' - else - tex_mode= + # Prevent $ESCAPE from being interpreted by the shell if it happens + # to be `/'. + $batch tex_args="\\${escape}nonstopmode\ \\${escape}input" + $verbose "Running $cmd ..." + cmd="$tex $tex_args $filename_input" + if $cmd >&5; then :; else + echo "$0: $tex exited with bad status, quitting." >&2 + echo "$0: see $filename_noext.log for errors." >&2 + test "$clean" = t \ + && cp "$filename_noext.log" "$orig_pwd" + exit 1 fi - $verbose "Running $tex $filename_input ..." - cmd="$tex $tex_mode \\input $filename_input" - $cmd - - # Check if index files changed. - # - definite_index_files= - # Get list of new index files. - possible_index_files="`eval echo ${filename_noext}.?? ${filename_noext}.aux`" - for this_file in ${possible_index_files}; do - # If file is empty, forget it. - test -s "${this_file}" || continue - - # Examine first character of file. If it's not a backslash or - # single quote, then it's definitely not an index or xref file. - # (Will have to check for @ when we switch to Texinfo syntax in - # all these files...) - first_character="`sed -n '1s/^\(.\).*$/\1/p;q' ${this_file}`" - if test "x${first_character}" = "x\\" \ - || test "x${first_character}" = "x'"; then - definite_index_files="${definite_index_files} ${this_file}" - fi - done - new_index_files="${definite_index_files}" - new_index_files_sans_aux="`echo ${definite_index_files} \ - | sed 's/'${filename_noext}'\.aux//; - s/^[ ]*//;s/[ ]*$//;'`" - - # If old and new list don't at least have the same file list, then one - # file or another has definitely changed. - $verbose "Original index files =$orig_index_files" - $verbose "New index files =$new_index_files" - if test "z${orig_index_files}" != "z${new_index_files}"; then - index_files_changed_p=t - else - # File list is the same. We must compare each file until we find a - # difference. - index_files_changed_p= - for this_file in ${new_index_files}; do - $verbose "Comparing index file $this_file ..." - # cmp -s will return nonzero exit status if files differ. - cmp -s "${this_file}" "${this_file}${backup_extension}" - if test $? -ne 0; then - # We only need to keep comparing until we find *one* that - # differs, because we'll have to run texindex & tex no - # matter what. - index_files_changed_p=t - $verbose "Index file $this_file differed:" - test $verbose = echo \ - && diff -c "${this_file}${backup_extension}" "${this_file}" + + + # Decide if looping again is needed. + finished=t + + # LaTeX (and the package changebar) report in the LOG file if it + # should be rerun. This is needed for files included from + # subdirs, since texi2dvi does not try to compare xref files in + # subdirs. Performing xref files test is still good since LaTeX + # does not report changes in xref files. + if fgrep "Rerun to get" "$filename_noext.log" >/dev/null 2>&1; then + finished= + fi + + # Check if xref files changed. + new_xref_files=`$get_xref_files "$filename_noext"` + $verbose "Original xref files = `echo $orig_xref_files | sed 's|\./||g'`" + $verbose "New xref files = `echo $new_xref_files | sed 's|\./||g'`" + + # If old and new lists don't at least have the same file list, + # then one file or another has definitely changed. + test "x$orig_xref_files" != "x$new_xref_files" && finished= + + # File list is the same. We must compare each file until we find + # a difference. + if test -n "$finished"; then + for this_file in $new_xref_files; do + $verbose "Comparing xref file `echo $this_file | sed 's|\./||g'` ..." + # cmp -s returns nonzero exit status if files differ. + if cmp -s "$this_file" "$tmpdir_bak/$this_file"; then :; else + # We only need to keep comparing until we find one that + # differs, because we'll have to run texindex & tex again no + # matter how many more there might be. + finished= + $verbose "xref file `echo $this_file | sed 's|\./||g'` differed ..." + test "$debug" = t && diff -c "$tmpdir_bak/$this_file" "$this_file" break fi done fi - # If index files have changed since TeX has been run, or if the aux - # file wasn't present originally, run texindex and TeX again. - if test "${index_files_changed_p}"; then :; else - # Nothing changed. We're done with TeX. - break - fi + # If finished, exit the loop, else rerun the loop. + test -n "$finished" && break done # If we were in clean mode, compilation was in a tmp directory. - # Copy the DVI file into the directory where the compilation + # Copy the DVI (or PDF) file into the directory where the compilation # has been done. (The temp dir is about to get removed anyway.) # We also return to the original directory so that # - the next file is processed in correct conditions # - the temporary file can be removed if test -n "$clean"; then - $verbose "Copying DVI file from `pwd` to $orig_pwd" - cp -p $filename_noext.dvi $orig_pwd + $verbose "Copying $oformat file from `pwd` to $orig_pwd" + cp -p "./$filename_noext.$oformat" "$orig_pwd" + cd / # in case $orig_pwd is on a different drive (for DOS) cd $orig_pwd || exit 1 fi - # Generate list of files to delete, then call rm once with the entire - # list. This is significantly faster than multiple executions of rm. - file_list= - for file in ${orig_index_files}; do - file_list="${file_list} ${file}${backup_extension}" - done - if test -n "${file_list}"; then - $verbose "Removing $file_list $tmp_dir $tmp_dir2 ..." - rm -f ${file_list} - rm -rf $tmp_dir $tmp_dir2 + # Remove temporary files. + if test "x$debug" = "x"; then + $verbose "Removing $tmpdir_src $tmpdir_xtr $tmpdir_bak ..." + cd / + rm -rf $tmpdir_src $tmpdir_xtr $tmpdir_bak fi done $verbose "$0 done." -true # exit successfully. +exit 0 # exit successfully, not however we ended the loop. |