1#! /bin/sh
2# texi2dvi --- produce DVI (or PDF) files from Texinfo (or LaTeX) sources.
3#
4# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2001,
5# 2002, 2003 Free Software Foundation, Inc.
6#
7# This program is free software; you can redistribute it and/or modify
8# it under the terms of the GNU General Public License as published by
9# the Free Software Foundation; either version 2, or (at your option)
10# any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15# GNU General Public License for more details.
16#
17# You should have received a copy of the GNU General Public License
18# along with this program; if not, you can either send email to this
19# program's maintainer or write to: The Free Software Foundation,
20# Inc.; 51 Franklin Street, Fifth Floor; Boston, MA 02110-1301, USA.
21#
22# Original author: Noah Friedman <friedman@gnu.org>.
23#
24# Please send bug reports, etc. to bug-texinfo@gnu.org.
25# If possible, please send a copy of the output of the script called with
26# the `--debug' option when making a bug report.
27
28program=`echo $0 | sed -e 's!.*/!!'`
29version="texi2dvi (GNU Texinfo 4.5)
30
31Copyright (C) 2003 Free Software Foundation, Inc.
32There is NO warranty.  You may redistribute this software
33under the terms of the GNU General Public License.
34For more information about these matters, see the files named COPYING."
35
36usage="Usage: $program [OPTION]... FILE...
37
38Run each Texinfo or LaTeX FILE through TeX in turn until all
39cross-references are resolved, building all indices.  The directory
40containing each FILE is searched for included files.  The suffix of FILE
41is used to determine its language (LaTeX or Texinfo).
42
43Makeinfo is used to perform Texinfo macro expansion before running TeX
44when needed.
45
46Operation modes:
47  -b, --batch         no interaction
48  -c, --clean         remove all auxiliary files
49  -D, --debug         turn on shell debugging (set -x)
50  -h, --help          display this help and exit successfully
51  -o, --output=OFILE  leave output in OFILE (implies --clean);
52                      Only one input FILE may be specified in this case
53  -q, --quiet         no output unless errors (implies --batch)
54  -s, --silent        same as --quiet
55  -v, --version       display version information and exit successfully
56  -V, --verbose       report on what is done
57
58TeX tuning:
59  -@                   use @input instead of \input; for preloaded Texinfo
60  -e, -E, --expand     force macro expansion using makeinfo
61  -I DIR               search DIR for Texinfo files
62  -l, --language=LANG  specify the LANG of FILE (LaTeX or Texinfo)
63  -p, --pdf            use pdftex or pdflatex for processing
64  -t, --texinfo=CMD    insert CMD after @setfilename in copy of input file
65                       multiple values accumulate
66
67The values of the BIBTEX, LATEX (or PDFLATEX), MAKEINDEX, MAKEINFO,
68TEX (or PDFTEX), and TEXINDEX environment variables are used to run
69those commands, if they are set.
70
71Email bug reports to <bug-texinfo@gnu.org>,
72general questions and discussion to <help-texinfo@gnu.org>.
73Texinfo home page: http://www.gnu.org/software/texinfo/"
74
75# Initialize variables for option overriding and otherwise.
76# Don't use `unset' since old bourne shells don't have this command.
77# Instead, assign them an empty value.
78batch=false     # eval for batch mode
79clean=
80debug=
81escape='\'
82expand=         # t for expansion via makeinfo
83miincludes=     # makeinfo include path
84oformat=dvi
85oname=          # --output
86quiet=          # by default let the tools' message be displayed
87set_language=
88textra=
89tmpdir=${TMPDIR:-/tmp}/t2d$$  # avoid collisions on 8.3 filesystems.
90txincludes=     # TEXINPUTS extensions, with trailing colon
91txiprereq=19990129 # minimum texinfo.tex version to have macro expansion
92verbose=false   # echo for verbose mode
93
94orig_pwd=`pwd`
95
96# Systems which define $COMSPEC or $ComSpec use semicolons to separate
97# directories in TEXINPUTS.
98if test -n "$COMSPEC$ComSpec"; then
99  path_sep=";"
100else
101  path_sep=":"
102fi
103
104# Pacify verbose cds.
105CDPATH=${ZSH_VERSION+.}$path_sep
106
107# In case someone crazy insists on using grep -E.
108: ${EGREP=egrep}
109
110# Save this so we can construct a new TEXINPUTS path for each file.
111TEXINPUTS_orig="$TEXINPUTS"
112# Unfortunately makeindex does not read TEXINPUTS.
113INDEXSTYLE_orig="$INDEXSTYLE"
114export TEXINPUTS INDEXSTYLE
115
116# Push a token among the arguments that will be used to notice when we
117# ended options/arguments parsing.
118# Use "set dummy ...; shift" rather than 'set - ..." because on
119# Solaris set - turns off set -x (but keeps set -e).
120# Use ${1+"$@"} rather than "$@" because Digital Unix and Ultrix 4.3
121# still expand "$@" to a single argument (the empty string) rather
122# than nothing at all.
123arg_sep="$$--$$"
124set dummy ${1+"$@"} "$arg_sep"; shift
125
126#
127# Parse command line arguments.
128while test x"$1" != x"$arg_sep"; do
129
130  # Handle --option=value by splitting apart and putting back on argv.
131  case "$1" in
132    --*=*)
133      opt=`echo "$1" | sed -e 's/=.*//'`
134      val=`echo "$1" | sed -e 's/[^=]*=//'`
135      shift
136      set dummy "$opt" "$val" ${1+"$@"}; shift
137      ;;
138  esac
139
140  # This recognizes --quark as --quiet.  So what.
141  case "$1" in
142    -@ ) escape=@;;
143    # Silently and without documentation accept -b and --b[atch] as synonyms.
144    -b | --b*) batch=eval;;
145    -q | -s | --q* | --s*) quiet=t; batch=eval;;
146    -c | --c*) clean=t;;
147    -D | --d*) debug=t;;
148    -e | -E | --e*) expand=t;;
149    -h | --h*) echo "$usage"; exit 0;;
150    -I | --I*)
151      shift
152      miincludes="$miincludes -I $1"
153      txincludes="$txincludes$1$path_sep"
154      ;;
155    -l | --l*) shift; set_language=$1;;
156    -o | --o*)
157      shift
158      clean=t
159      case "$1" in
160        /* | ?:/*) oname=$1;;
161                *) oname="$orig_pwd/$1";;
162      esac;;
163    -p | --p*) oformat=pdf;;
164    -t | --t*) shift; textra="$textra\\
165$1";;
166    -v | --vers*) echo "$version"; exit 0;;
167    -V | --verb*) verbose=echo;;
168    --) # What remains are not options.
169      shift
170      while test x"$1" != x"$arg_sep"; do
171        set dummy ${1+"$@"} "$1"; shift
172        shift
173      done
174      break;;
175    -*)
176      echo "$0: Unknown or ambiguous option \`$1'." >&2
177      echo "$0: Try \`--help' for more information." >&2
178      exit 1;;
179    *) set dummy ${1+"$@"} "$1"; shift;;
180   esac
181   shift
182done
183# Pop the token
184shift
185
186# Interpret remaining command line args as filenames.
187case $# in
188 0)
189  echo "$0: Missing file arguments." >&2
190  echo "$0: Try \`--help' for more information." >&2
191  exit 2
192  ;;
193 1) ;;
194 *)
195  if test -n "$oname"; then
196    echo "$0: Can't use option \`--output' with more than one argument." >&2
197    exit 2
198  fi
199  ;;
200esac
201
202# Prepare the temporary directory.  Remove it at exit, unless debugging.
203if test -z "$debug"; then
204  trap "cd / && rm -rf $tmpdir" 0 1 2 15
205fi
206
207# Create the temporary directory with strict rights
208(umask 077 && mkdir $tmpdir) || exit 1
209
210# Prepare the tools we might need.  This may be extra work in some
211# cases, but improves the readibility of the script.
212utildir=$tmpdir/utils
213mkdir $utildir || exit 1
214
215# A sed script that preprocesses Texinfo sources in order to keep the
216# iftex sections only.  We want to remove non TeX sections, and
217# comment (with `@c texi2dvi') TeX sections so that makeinfo does not
218# try to parse them.  Nevertheless, while commenting TeX sections,
219# don't comment @macro/@end macro so that makeinfo does propagate
220# them.  Unfortunately makeinfo --iftex --no-ifhtml --no-ifinfo
221# doesn't work well enough (yet) to use that, so work around with sed.
222comment_iftex_sed=$utildir/comment.sed
223cat <<EOF >$comment_iftex_sed
224/^@tex/,/^@end tex/{
225  s/^/@c texi2dvi/
226}
227/^@iftex/,/^@end iftex/{
228  s/^/@c texi2dvi/
229  /^@c texi2dvi@macro/,/^@c texi2dvi@end macro/{
230    s/^@c texi2dvi//
231  }
232}
233/^@html/,/^@end html/{
234  s/^/@c (texi2dvi)/
235}
236/^@ifhtml/,/^@end ifhtml/{
237  s/^/@c (texi2dvi)/
238}
239/^@ifnottex/,/^@end ifnottex/{
240  s/^/@c (texi2dvi)/
241}
242/^@ifinfo/,/^@end ifinfo/{
243  /^@node/p
244  /^@menu/,/^@end menu/p
245  t
246  s/^/@c (texi2dvi)/
247}
248s/^@ifnotinfo/@c texi2dvi@ifnotinfo/
249s/^@end ifnotinfo/@c texi2dvi@end ifnotinfo/
250EOF
251# Uncommenting is simple: Remove any leading `@c texi2dvi'.
252uncomment_iftex_sed=$utildir/uncomment.sed
253cat <<EOF >$uncomment_iftex_sed
254s/^@c texi2dvi//
255EOF
256
257# A shell script that computes the list of xref files.
258# Takes the filename (without extension) of which we look for xref
259# files as argument.  The index files must be reported last.
260get_xref_files=$utildir/get_xref.sh
261cat <<\EOF >$get_xref_files
262#! /bin/sh
263
264# Get list of xref files (indexes, tables and lists).
265# Find all files having root filename with a two-letter extension,
266# saves the ones that are really Texinfo-related files.  .?o? catches
267# many files: .toc, .log, LaTeX tables and lists, FiXme's .lox, maybe more.
268for this_file in "$1".?o? "$1".aux "$1".?? "$1".idx; do
269  # If file is empty, skip it.
270  test -s "$this_file" || continue
271  # If the file is not suitable to be an index or xref file, don't
272  # process it.  The file can't be if its first character is not a
273  # backslash or single quote.
274  first_character=`sed -n '1s/^\(.\).*$/\1/p;q' $this_file`
275  if test "x$first_character" = "x\\" \
276     || test "x$first_character" = "x'"; then
277    xref_files="$xref_files ./$this_file"
278  fi
279done
280echo "$xref_files"
281EOF
282chmod 500 $get_xref_files
283
284# File descriptor usage:
285# 0 standard input
286# 1 standard output (--verbose messages)
287# 2 standard error
288# 3 some systems may open it to /dev/tty
289# 4 used on the Kubota Titan
290# 5 tools output (turned off by --quiet)
291
292# Tools' output.  If quiet, discard, else redirect to the message flow.
293if test "$quiet" = t; then
294  exec 5>/dev/null
295else
296  exec 5>&1
297fi
298
299# Enable tracing
300test "$debug" = t && set -x
301
302#
303# TeXify files.
304
305for command_line_filename in ${1+"$@"}; do
306  $verbose "Processing $command_line_filename ..."
307
308  # If the COMMAND_LINE_FILENAME is not absolute (e.g., --debug.tex),
309  # prepend `./' in order to avoid that the tools take it as an option.
310  echo "$command_line_filename" | $EGREP '^(/|[A-z]:/)' >/dev/null \
311  || command_line_filename="./$command_line_filename"
312
313  # See if the file exists.  If it doesn't we're in trouble since, even
314  # though the user may be able to reenter a valid filename at the tex
315  # prompt (assuming they're attending the terminal), this script won't
316  # be able to find the right xref files and so forth.
317  if test ! -r "$command_line_filename"; then
318    echo "$0: Could not read $command_line_filename, skipping." >&2
319    continue
320  fi
321
322  # Get the name of the current directory.  We want the full path
323  # because in clean mode we are in tmp, in which case a relative
324  # path has no meaning.
325  filename_dir=`echo $command_line_filename | sed 's!/[^/]*$!!;s!^$!.!'`
326  filename_dir=`cd "$filename_dir" >/dev/null && pwd`
327
328  # Strip directory part but leave extension.
329  filename_ext=`basename "$command_line_filename"`
330  # Strip extension.
331  filename_noext=`echo "$filename_ext" | sed 's/\.[^.]*$//'`
332  ext=`echo "$filename_ext" | sed 's/^.*\.//'`
333
334  # _src.  Use same basename since we want to generate aux files with
335  # the same basename as the manual.  If --expand, then output the
336  # macro-expanded file to here, else copy the original file.
337  tmpdir_src=$tmpdir/src
338  filename_src=$tmpdir_src/$filename_noext.$ext
339
340  # _xtr.  The file with the user's extra commands.
341  tmpdir_xtr=$tmpdir/xtr
342  filename_xtr=$tmpdir_xtr/$filename_noext.$ext
343
344  # _bak.  Copies of the previous xref files (another round is run if
345  # they differ from the new one).
346  tmpdir_bak=$tmpdir/bak
347
348  # Make all those directories and give up if we can't succeed.
349  mkdir $tmpdir_src $tmpdir_xtr $tmpdir_bak || exit 1
350
351  # Source file might include additional sources.
352  # We want `.:$orig_pwd' before anything else.  (We'll add `.:' later
353  # after all other directories have been turned into absolute paths.)
354  # `.' goes first to ensure that any old .aux, .cps,
355  # etc. files in ${directory} don't get used in preference to fresher
356  # files in `.'.  Include orig_pwd in case we are in clean mode, where
357  # we've cd'd to a temp directory.
358  common="$orig_pwd$path_sep$filename_dir$path_sep$txincludes"
359   TEXINPUTS="$common$TEXINPUTS_orig"
360  INDEXSTYLE="$common$INDEXSTYLE_orig"
361
362  # Convert relative paths to absolute paths, so we can run in another
363  # directory (e.g., in --clean mode, or during the macro-support
364  # detection.)
365  #
366  # Empty path components are meaningful to tex.  We rewrite them
367  # as `EMPTY' so they don't get lost when we split on $path_sep.
368   TEXINPUTS=`echo $TEXINPUTS  |sed 's/^:/EMPTY:/;s/:$/:EMPTY/;s/::/:EMPTY:/g'`
369  INDEXSTYLE=`echo $INDEXSTYLE |sed 's/^:/EMPTY:/;s/:$/:EMPTY/;s/::/:EMPTY:/g'`
370  save_IFS=$IFS
371  IFS=$path_sep
372  set x $TEXINPUTS; shift
373  TEXINPUTS=.
374  for dir
375  do
376    case $dir in
377      EMPTY)
378        TEXINPUTS=$TEXINPUTS$path_sep
379        ;;
380      [\\/]* | ?:[\\/]*)        # Absolute paths don't need to be expansed.
381        TEXINPUTS=$TEXINPUTS$path_sep$dir
382        ;;
383      *)
384        abs=`cd "$dir" && pwd` && TEXINPUTS=$TEXINPUTS$path_sep$abs
385        ;;
386    esac
387  done
388  set x $INDEXSTYLE; shift
389  INDEXSTYLE=.
390  for dir
391  do
392    case $dir in
393      EMPTY)
394        INDEXSTYLE=$INDEXSTYLE$path_sep
395        ;;
396      [\\/]* | ?:[\\/]*)        # Absolute paths don't need to be expansed.
397        INDEXSTYLE=$INDEXSTYLE$path_sep$dir
398        ;;
399      *)
400        abs=`cd "$dir" && pwd` && INDEXSTYLE=$INDEXSTYLE$path_sep$abs
401        ;;
402    esac
403  done
404  IFS=$save_IFS
405
406  # If the user explicitly specified the language, use that.
407  # Otherwise, if the first line is \input texinfo, assume it's texinfo.
408  # Otherwise, guess from the file extension.
409  if test -n "$set_language"; then
410    language=$set_language
411  elif sed 1q "$command_line_filename" | grep 'input texinfo' >/dev/null; then
412    language=texinfo
413  else
414    language=
415  fi
416
417  # Get the type of the file (latex or texinfo) from the given language
418  # we just guessed, or from the file extension if not set yet.
419  case ${language:-$filename_ext} in
420    [lL]a[tT]e[xX] | *.ltx | *.tex)
421      # Assume a LaTeX file.  LaTeX needs bibtex and uses latex for
422      # compilation.  No makeinfo.
423      bibtex=${BIBTEX:-bibtex}
424      makeinfo= # no point in running makeinfo on latex source.
425      texindex=${MAKEINDEX:-makeindex}
426      if test $oformat = dvi; then
427        tex=${LATEX:-latex}
428      else
429        tex=${PDFLATEX:-pdflatex}
430      fi
431      ;;
432
433    *)
434      # Assume a Texinfo file.  Texinfo files need makeinfo, texindex and tex.
435      bibtex=
436      texindex=${TEXINDEX:-texindex}
437      if test $oformat = dvi; then
438        tex=${TEX:-tex}
439      else
440        tex=${PDFTEX:-pdftex}
441      fi
442      # Unless required by the user, makeinfo expansion is wanted only
443      # if texinfo.tex is too old.
444      if test "$expand" = t; then
445        makeinfo=${MAKEINFO:-makeinfo}
446      else
447        # Check if texinfo.tex performs macro expansion by looking for
448        # its version.  The version is a date of the form YEAR-MO-DA.
449        # We don't need to use [0-9] to match the digits since anyway
450        # the comparison with $txiprereq, a number, will fail with non
451        # digits.
452        txiversion_tex=txiversion.tex
453        echo '\input texinfo.tex @bye' >$tmpdir/$txiversion_tex
454        # Run in the tmpdir to avoid leaving files.
455        eval `cd $tmpdir >/dev/null &&
456              $tex $txiversion_tex 2>/dev/null |
457              sed -n 's/^.*\[\(.*\)version \(....\)-\(..\)-\(..\).*$/txiformat=\1 txiversion="\2\3\4"/p'`
458        $verbose "texinfo.tex preloaded as \`$txiformat', version is \`$txiversion' ..."
459        if test "$txiprereq" -le "$txiversion" >/dev/null 2>&1; then
460          makeinfo=
461        else
462          makeinfo=${MAKEINFO:-makeinfo}
463        fi
464        # As long as we had to run TeX, offer the user this convenience
465        if test "$txiformat" = Texinfo; then
466          escape=@
467        fi
468      fi
469      ;;
470  esac
471
472  # Expand macro commands in the original source file using Makeinfo.
473  # Always use `end' footnote style, since the `separate' style
474  #   generates different output (arguably this is a bug in -E).
475  # Discard main info output, the user asked to run TeX, not makeinfo.
476  if test -n "$makeinfo"; then
477    $verbose "Macro-expanding $command_line_filename to $filename_src ..."
478    sed -f $comment_iftex_sed "$command_line_filename" \
479      | $makeinfo --footnote-style=end -I "$filename_dir" $miincludes \
480        -o /dev/null --macro-expand=- \
481      | sed -f $uncomment_iftex_sed >"$filename_src"
482    filename_input=$filename_src
483  fi
484
485  # If makeinfo failed (or was not even run), use the original file as input.
486  if test $? -ne 0 \
487     || test ! -r "$filename_src"; then
488    $verbose "Reverting to $command_line_filename ..."
489    filename_input=$filename_dir/$filename_ext
490  fi
491
492  # Used most commonly for @finalout, @smallbook, etc.
493  if test -n "$textra"; then
494    $verbose "Inserting extra commands: $textra"
495    sed '/^@setfilename/a\
496'"$textra" "$filename_input" >$filename_xtr
497    filename_input=$filename_xtr
498  fi
499
500  # If clean mode was specified, then move to the temporary directory.
501  if test "$clean" = t; then
502    $verbose "cd $tmpdir_src"
503    cd "$tmpdir_src" || exit 1
504  fi
505
506  while :; do # will break out of loop below
507    orig_xref_files=`$get_xref_files "$filename_noext"`
508
509    # Save copies of originals for later comparison.
510    if test -n "$orig_xref_files"; then
511      $verbose "Backing up xref files: `echo $orig_xref_files | sed 's|\./||g'`"
512      cp $orig_xref_files $tmpdir_bak
513    fi
514
515    # Run bibtex on current file.
516    # - If its input (AUX) exists.
517    # - If AUX contains both `\bibdata' and `\bibstyle'.
518    # - If some citations are missing (LOG contains `Citation').
519    #   or the LOG complains of a missing .bbl
520    #
521    # We run bibtex first, because I can see reasons for the indexes
522    # to change after bibtex is run, but I see no reason for the
523    # converse.
524    #
525    # Don't try to be too smart.  Running bibtex only if the bbl file
526    # exists and is older than the LaTeX file is wrong, since the
527    # document might include files that have changed.  Because there
528    # can be several AUX (if there are \include's), but a single LOG,
529    # looking for missing citations in LOG is easier, though we take
530    # the risk to match false messages.
531    if test -n "$bibtex" \
532       && test -r "$filename_noext.aux" \
533       && test -r "$filename_noext.log" \
534       && (grep '^\\bibdata[{]'  "$filename_noext.aux" \
535           && grep '^\\bibstyle[{]' "$filename_noext.aux" \
536           && (grep 'Warning:.*Citation.*undefined' "$filename_noext.log" \
537               || grep 'No file .*\.bbl\.' "$filename_noext.log")) \
538          >/dev/null 2>&1; \
539    then
540      $verbose "Running $bibtex $filename_noext ..."
541      if $bibtex "$filename_noext" >&5; then :; else
542        echo "$0: $bibtex exited with bad status, quitting." >&2
543        exit 1
544      fi
545    fi
546
547    # What we'll run texindex on -- exclude non-index files.
548    # Since we know index files are last, it is correct to remove everything
549    # before .aux and .?o?.  But don't really do <anything>o<anything>
550    # -- don't match whitespace as <anything>.
551    # Otherwise, if orig_xref_files contains something like
552    #   foo.xo foo.whatever
553    # the space after the o will get matched.
554    index_files=`echo "$orig_xref_files" \
555                 | sed "s!.*\.aux!!g;
556                        s!./$filename_noext\.[^ ]o[^ ]!!g;
557                        s/^[ ]*//;s/[ ]*$//"`
558    # Run texindex (or makeindex) on current index files.  If they
559    # already exist, and after running TeX a first time the index
560    # files don't change, then there's no reason to run TeX again.
561    # But we won't know that if the index files are out of date or
562    # nonexistent.
563    if test -n "$texindex" && test -n "$index_files"; then
564      $verbose "Running $texindex $index_files ..."
565      if $texindex $index_files 2>&5 1>&2; then :; else
566         echo "$0: $texindex exited with bad status, quitting." >&2
567         exit 1
568      fi
569    fi
570
571    # Finally, run TeX.
572    # Prevent $ESCAPE from being interpreted by the shell if it happens
573    # to be `/'.
574    $batch tex_args="\\${escape}nonstopmode\ \\${escape}input"
575    cmd="$tex $tex_args $filename_input"
576    $verbose "Running $cmd ..."
577    if $cmd >&5; then :; else
578      echo "$0: $tex exited with bad status, quitting." >&2
579      echo "$0: see $filename_noext.log for errors." >&2
580      test "$clean" = t \
581        && cp "$filename_noext.log" "$orig_pwd"
582      exit 1
583    fi
584
585
586    # Decide if looping again is needed.
587    finished=t
588
589    # LaTeX (and the package changebar) report in the LOG file if it
590    # should be rerun.  This is needed for files included from
591    # subdirs, since texi2dvi does not try to compare xref files in
592    # subdirs.  Performing xref files test is still good since LaTeX
593    # does not report changes in xref files.
594    if grep "Rerun to get" "$filename_noext.log" >/dev/null 2>&1; then
595      finished=
596    fi
597
598    # Check if xref files changed.
599    new_xref_files=`$get_xref_files "$filename_noext"`
600    $verbose "Original xref files = `echo $orig_xref_files | sed 's|\./||g'`"
601    $verbose "New xref files      = `echo $new_xref_files | sed 's|\./||g'`"
602
603    # If old and new lists don't at least have the same file list,
604    # then one file or another has definitely changed.
605    test "x$orig_xref_files" != "x$new_xref_files" && finished=
606
607    # File list is the same.  We must compare each file until we find
608    # a difference.
609    if test -n "$finished"; then
610      for this_file in $new_xref_files; do
611        $verbose "Comparing xref file `echo $this_file | sed 's|\./||g'` ..."
612        # cmp -s returns nonzero exit status if files differ.
613        if cmp -s "$this_file" "$tmpdir_bak/$this_file"; then :; else
614          # We only need to keep comparing until we find one that
615          # differs, because we'll have to run texindex & tex again no
616          # matter how many more there might be.
617          finished=
618          $verbose "xref file `echo $this_file | sed 's|\./||g'` differed ..."
619          test "$debug" = t && diff -c "$tmpdir_bak/$this_file" "$this_file"
620          break
621        fi
622      done
623    fi
624
625    # If finished, exit the loop, else rerun the loop.
626    test -n "$finished" && break
627  done
628
629  # If we were in clean mode, compilation was in a tmp directory.
630  # Copy the DVI (or PDF) file into the directory where the compilation
631  # has been done.  (The temp dir is about to get removed anyway.)
632  # We also return to the original directory so that
633  # - the next file is processed in correct conditions
634  # - the temporary file can be removed
635  if test -n "$clean"; then
636    if test -n "$oname"; then
637       dest=$oname
638    else
639       dest=$orig_pwd
640    fi
641    $verbose "Copying $oformat file from `pwd` to $dest"
642    cp -p "./$filename_noext.$oformat" "$dest"
643    cd / # in case $orig_pwd is on a different drive (for DOS)
644    cd $orig_pwd || exit 1
645  fi
646
647  # Remove temporary files.
648  if test "x$debug" = "x"; then
649    $verbose "Removing $tmpdir_src $tmpdir_xtr $tmpdir_bak ..."
650    cd /
651    rm -rf $tmpdir_src $tmpdir_xtr $tmpdir_bak
652  fi
653done
654
655$verbose "$0 done."
656exit 0 # exit successfully, not however we ended the loop.
657