source: Daodan/MinGW/msys/1.0/bin/texi2dvi@ 1063

Last change on this file since 1063 was 1046, checked in by alloc, 8 years ago

Daodan: Added Windows MinGW and build batch file

File size: 51.5 KB
RevLine 
[1046]1#! /bin/sh
2# texi2dvi --- produce DVI (or PDF) files from Texinfo (or (La)TeX) sources.
3# $Id: texi2dvi,v 1.135 2008/09/18 18:46:01 karl Exp $
4#
5# Copyright (C) 1992, 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2001,
6# 2002, 2003, 2004, 2005, 2006, 2007, 2008 Free Software Foundation, Inc.
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 3 of the License,
11# or (at your option) 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, see <http://www.gnu.org/licenses/>.
20#
21# Original author: Noah Friedman.
22#
23# Please send bug reports, etc. to bug-texinfo@gnu.org.
24# If possible, please send a copy of the output of the script called with
25# the `--debug' option when making a bug report.
26
27test -f /bin/ksh && test -z "$RUNNING_KSH" \
28 && { UNAMES=`uname -s`; test "x$UNAMES" = xULTRIX; } 2>/dev/null \
29 && { RUNNING_KSH=true; export RUNNING_KSH; exec /bin/ksh $0 ${1+"$@"}; }
30unset RUNNING_KSH
31
32# No failure shall remain unpunished.
33set -e
34
35if ! command -v tex >/dev/null 2>&1; then
36 cat <<%EOM%
37You don't have a working TeX binary installed, but the texi2dvi script
38can't proceed without it. If you want to use this script, you have to
39install some kind of TeX, for example the MikTeX package from
40http://miktex.org/ (which is not part of the typical MSYS environment).
41%EOM%
42 exit 1
43fi
44
45# This string is expanded by rcs automatically when this file is checked out.
46rcs_revision='$Revision: 1.135 $'
47rcs_version=`set - $rcs_revision; echo $2`
48program=`echo $0 | sed -e 's!.*/!!'`
49
50build_mode=${TEXI2DVI_BUILD_MODE:-local}
51build_dir=${TEXI2DVI_BUILD_DIRECTORY:-.}
52
53# Initialize variables for option overriding and otherwise.
54# Don't use `unset' since old bourne shells don't have this command.
55# Instead, assign them an empty value.
56action=compile
57batch=false # true for batch mode
58catcode_special=true
59debug=false
60escape="\\"
61expand= # t for expansion via makeinfo
62includes=
63line_error=true # Pass --file-line-error to TeX.
64no_line_error=false # absolutely do not pass --file-line-error to TeX
65oname= # --output
66out_lang=dvi
67quiet=false # by default let the tools' message be displayed
68recode=false
69set_language=
70src_specials=
71textra= # Extra TeX commands to insert in the input file.
72txiprereq=19990129 # minimum texinfo.tex version with macro expansion
73verb=false # true for verbose mode
74translate_file= # name of charset translation file
75recode_from= # if not empty, recode from this encoding to @documentencoding
76
77orig_pwd=`pwd`
78
79# We have to initialize IFS to space tab newline since we save and
80# restore IFS and apparently POSIX allows stupid/broken behavior with
81# empty-but-set IFS.
82# http://lists.gnu.org/archive/html/automake-patches/2006-05/msg00008.html
83# We need space, tab and new line, in precisely that order. And don't leave
84# trailing blanks.
85space=' '
86tab=' '
87newline='
88'
89IFS="$space$tab$newline"
90
91# In case someone pedantic insists on using grep -E.
92: ${EGREP=egrep}
93
94# Systems which define $COMSPEC or $ComSpec use semicolons to separate
95# directories in TEXINPUTS -- except for Cygwin et al., where COMSPEC
96# might be inherited, but : is used.
97if test -n "$COMSPEC$ComSpec" \
98 && uname | $EGREP -iv 'cygwin|mingw|djgpp' >/dev/null; then
99 path_sep=";"
100else
101 path_sep=":"
102fi
103
104# Pacify verbose cds.
105CDPATH=${ZSH_VERSION+.}$path_sep
106
107# If $TEX is set to a directory, don't use it.
108test -n "$TEX" && test -d "$TEX" && unset TEX
109
110#
111
112## --------------------- ##
113## Auxiliary functions. ##
114## --------------------- ##
115
116# In case `local' is not supported by the shell, provide a function
117# that simulates it by simply performing the assignments. This means
118# that we must not expect `local' to work, i.e., we must not (i) rely
119# on it during recursion, and (ii) have two local declarations of the
120# same variable. (ii) is easy to check statically, and our test suite
121# does make sure there is never twice a static local declaration of a
122# variable. (i) cannot be checked easily, so just be careful.
123#
124# Note that since we might use a function simulating `local', we can
125# no longer rely on the fact that no IFS-splitting is performed. So,
126# while
127#
128# foo=$bar
129#
130# is fine (no IFS-splitting), never write
131#
132# local foo=$bar
133#
134# but rather
135#
136# local foo="$bar"
137(
138 foo=bar
139 test_local () {
140 local foo=foo
141 }
142 test_local
143 test $foo = bar
144) || local () {
145 case $1 in
146 *=*) eval "$1";;
147 esac
148}
149
150
151# cd_orig
152# -------
153# Return to the original directory.
154cd_orig ()
155{
156 # In case $orig_pwd is on a different drive (for DOS).
157 cd /
158
159 # Return to the original directory so that
160 # - the next file is processed in correct conditions
161 # - the temporary file can be removed
162 cd "$orig_pwd" || exit 1
163}
164
165# func_dirname FILE
166# -----------------
167# Return the directory part of FILE.
168func_dirname ()
169{
170 dirname "$1" 2>/dev/null \
171 || { echo "$1" | sed 's!/[^/]*$!!;s!^$!.!'; }
172}
173
174
175# absolute NAME -> ABS-NAME
176# -------------------------
177# Return an absolute path to NAME.
178absolute ()
179{
180 case $1 in
181 [\\/]* | ?:[\\/]*)
182 # Absolute paths don't need to be expanded.
183 echo "$1"
184 ;;
185 *) local slashes
186 slashes=`echo "$1" | sed -n 's,.*[^/]\(/*\)$,\1,p'`
187 local rel
188 rel=$orig_pwd/`func_dirname "$1"`
189 if test -d "$rel"; then
190 (cd "$rel" 2>/dev/null &&
191 local n
192 n=`pwd`/`basename "$1"`"$slashes"
193 echo "$n")
194 else
195 error 1 "not a directory: $rel"
196 fi
197 ;;
198 esac
199}
200
201
202# ensure_dir DIR1 DIR2...
203# -----------------------
204# Make sure the directories exist.
205ensure_dir ()
206{
207 for dir
208 do
209 test -d "$dir" \
210 || mkdir "$dir" \
211 || error 1 "cannot create directory: $dir"
212 done
213}
214
215
216# error EXIT_STATUS LINE1 LINE2...
217# --------------------------------
218# Report an error and exit with failure if EXIT_STATUS is non null.
219error ()
220{
221 local s="$1"
222 shift
223 report "$@"
224 if test "$s" != 0; then
225 exit $s
226 fi
227}
228
229
230# findprog PROG
231# -------------
232# Return true if PROG is somewhere in PATH, else false.
233findprog ()
234{
235 local saveIFS="$IFS"
236 IFS=$path_sep # break path components at the path separator
237 for dir in $PATH; do
238 IFS=$saveIFS
239 # The basic test for an executable is `test -f $f && test -x $f'.
240 # (`test -x' is not enough, because it can also be true for directories.)
241 # We have to try this both for $1 and $1.exe.
242 #
243 # Note: On Cygwin and DJGPP, `test -x' also looks for .exe. On Cygwin,
244 # also `test -f' has this enhancement, bot not on DJGPP. (Both are
245 # design decisions, so there is little chance to make them consistent.)
246 # Thusly, it seems to be difficult to make use of these enhancements.
247 #
248 if { test -f "$dir/$1" && test -x "$dir/$1"; } ||
249 { test -f "$dir/$1.exe" && test -x "$dir/$1.exe"; }; then
250 return 0
251 fi
252 done
253 return 1
254}
255
256# report LINE1 LINE2...
257# ---------------------
258# Report some information on stderr.
259report ()
260{
261 for i in "$@"
262 do
263 echo >&2 "$0: $i"
264 done
265}
266
267
268# run COMMAND-LINE
269# ----------------
270# Run the COMMAND-LINE verbosely, and catching errors as failures.
271run ()
272{
273 verbose "Running $@"
274 "$@" 2>&5 1>&2 ||
275 error 1 "$1 failed"
276}
277
278
279# usage
280# -----
281# Display usage and exit successfully.
282usage ()
283{
284 # We used to simply have `echo "$usage"', but coping with the
285 # changing behavior of `echo' is much harder than simply using a
286 # here-doc.
287 #
288 # echo '\noto' echo '\\noto' echo -e '\\noto'
289 # bash 3.1 \noto \\noto \noto
290 # bash 3.2 %oto \noto -e \noto
291 #
292 # where % denotes the eol character.
293 cat <<EOF
294Usage: $program [OPTION]... FILE...
295
296Run each Texinfo or (La)TeX FILE through TeX in turn until all
297cross-references are resolved, building all indices. The directory
298containing each FILE is searched for included files. The suffix of FILE
299is used to determine its language ((La)TeX or Texinfo). To process
300(e)plain TeX files, set the environment variable LATEX=tex.
301
302In order to make texi2dvi a drop-in replacement of TeX/LaTeX in AUC-TeX,
303the FILE may also be composed of the following simple TeX commands.
304 \`\\input{FILE}' the actual file to compile
305 \`\\nonstopmode' same as --batch
306
307Makeinfo is used to perform Texinfo macro expansion before running TeX
308when needed.
309
310General options:
311 -b, --batch no interaction
312 -D, --debug turn on shell debugging (set -x)
313 -h, --help display this help and exit successfully
314 -o, --output=OFILE leave output in OFILE (implies --clean);
315 only one input FILE may be specified in this case
316 -q, --quiet no output unless errors (implies --batch)
317 -s, --silent same as --quiet
318 -v, --version display version information and exit successfully
319 -V, --verbose report on what is done
320
321TeX tuning:
322 -@ use @input instead of \input for preloaded Texinfo
323 --dvi output a DVI file [default]
324 --dvipdf output a PDF file via DVI (using dvipdf)
325 -e, -E, --expand force macro expansion using makeinfo
326 -I DIR search DIR for Texinfo files
327 -l, --language=LANG specify LANG for FILE, either latex or texinfo
328 --no-line-error do not pass --file-line-error to TeX
329 -p, --pdf use pdftex or pdflatex for processing
330 -r, --recode call recode before TeX to translate input
331 --recode-from=ENC recode from ENC to the @documentencoding
332 --src-specials pass --src-specials to TeX
333 -t, --command=CMD insert CMD in copy of input file
334 or --texinfo=CMD multiple values accumulate
335 --translate-file=FILE use given charset translation file for TeX
336
337Build modes:
338 --build=MODE specify the treatment of auxiliary files [$build_mode]
339 --tidy same as --build=tidy
340 -c, --clean same as --build=clean
341 --build-dir=DIR specify where the tidy compilation is performed;
342 implies --tidy;
343 defaults to TEXI2DVI_BUILD_DIRECTORY [$build_dir]
344 --mostly-clean remove the auxiliary files and directories
345 but not the output
346
347The MODE specifies where the TeX compilation takes place, and, as a
348consequence, how auxiliary files are treated. The build mode
349can also be set using the environment variable TEXI2DVI_BUILD_MODE.
350
351Valid MODEs are:
352 \`local' compile in the current directory, leaving all the auxiliary
353 files around. This is the traditional TeX use.
354 \`tidy' compile in a local *.t2d directory, where the auxiliary files
355 are left. Output files are copied back to the original file.
356 \`clean' same as \`tidy', but remove the auxiliary directory afterwards.
357 Every compilation therefore requires the full cycle.
358
359Using the \`tidy' mode brings several advantages:
360 - the current directory is not cluttered with plethora of temporary files.
361 - clutter can be even reduced using --build-dir=dir: all the *.t2d
362 directories are stored there.
363 - clutter can be reduced to zero using, e.g., --build-dir=/tmp/\$USER.t2d
364 or --build-dir=\$HOME/.t2d.
365 - the output file is updated after every succesful TeX run, for
366 sake of concurrent visualization of the output. In a \`local' build
367 the viewer stops during the whole TeX run.
368 - if the compilation fails, the previous state of the output file
369 is preserved.
370 - PDF and DVI compilation are kept in separate subdirectories
371 preventing any possibility of auxiliary file incompatibility.
372
373On the other hand, because \`tidy' compilation takes place in another
374directory, occasionally TeX won't be able to find some files (e.g., when
375using \\graphicspath): in that case use -I to specify the additional
376directories to consider.
377
378The values of the BIBTEX, LATEX (or PDFLATEX), MAKEINDEX, MAKEINFO,
379TEX (or PDFTEX), TEXINDEX, and THUMBPDF environment variables are used
380to run those commands, if they are set. Any CMD strings are added
381after @setfilename for Texinfo input, in the first line for LaTeX input.
382
383Email bug reports to <bug-texinfo@gnu.org>,
384general questions and discussion to <help-texinfo@gnu.org>.
385Texinfo home page: http://www.gnu.org/software/texinfo/
386EOF
387 exit 0
388}
389
390
391# verbose WORD1 WORD2
392# -------------------
393# Report some verbose information.
394verbose ()
395{
396 if $verb; then
397 echo >&2 "$0: $@"
398 fi
399}
400
401
402# version
403# -------
404# Display version info and exit succesfully.
405version ()
406{
407 cat <<EOF
408texi2dvi (GNU Texinfo 4.13) $rcs_version
409
410Copyright (C) 2008 Free Software Foundation, Inc.
411License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
412This is free software: you are free to change and redistribute it.
413There is NO WARRANTY, to the extent permitted by law.
414EOF
415 exit 0
416}
417
418
419## ---------------- ##
420## Handling lists. ##
421## ---------------- ##
422
423
424# list_append LIST-NAME ELEM
425# --------------------------
426# Set LIST-NAME to its former contents, with ELEM appended.
427list_append ()
428{
429 local la_l="$1"
430 shift
431 eval set X \$$la_l "$@"
432 shift
433 eval $la_l=\""$@"\"
434}
435
436
437# list_concat_dirs LIST-NAME DIR-LIST
438# -----------------------------------
439# Append to LIST-NAME all the components (included empty) from
440# the $path_sep separated list DIR-LIST. Make the paths absolute.
441list_concat_dirs ()
442{
443 local lcd_list="$1"
444 # Empty path components are meaningful to tex. We rewrite them as
445 # `EMPTY' so they don't get lost when we split on $path_sep.
446 # Hopefully no one will have an actual directory named EMPTY.
447 local replace_EMPTY="-e 's/^$path_sep/EMPTY$path_sep/g' \
448 -e 's/$path_sep\$/${path_sep}EMPTY/g' \
449 -e 's/$path_sep$path_sep/${path_sep}EMPTY:/g'"
450 save_IFS=$IFS
451 IFS=$path_sep
452 set x `echo "$2" | eval sed $replace_EMPTY`; shift
453 IFS=$save_IFS
454 local dir
455 for dir
456 do
457 case $dir in
458 EMPTY)
459 list_append $lcd_list ""
460 ;;
461 *)
462 if test -d $dir; then
463 dir=`absolute "$dir"`
464 list_append $lcd_list "$dir"
465 fi
466 ;;
467 esac
468 done
469}
470
471
472# list_prefix LIST-NAME SEP -> STRING
473# -----------------------------------
474# Return a string that is composed of the LIST-NAME with each item
475# preceded by SEP.
476list_prefix ()
477{
478 local lp_p="$2"
479 eval set X \$$1
480 shift
481 local lp_res
482 for i
483 do
484 lp_res="$lp_res \"$lp_p\" \"$i\""
485 done
486 echo "$lp_res"
487}
488
489# list_infix LIST-NAME SEP -> STRING
490# ----------------------------------
491# Same as list_prefix, but a separator.
492list_infix ()
493{
494 eval set X \$$1
495 shift
496 local la_IFS="$IFS"
497 IFS=$path_sep
498 echo "$*"
499 IFS=$la_IFS
500}
501
502# list_dir_to_abs LIST-NAME
503# -------------------------
504# Convert the list to using only absolute dir names.
505# Currently unused, but should replace absolute_filenames some day.
506list_dir_to_abs ()
507{
508 local ld_l="$1"
509 eval set X \$$ld_l
510 shift
511 local ld_res
512 for dir
513 do
514 dir=`absolute "$dir"`
515 test -d "$dir" || continue
516 ld_res="$ld_res \"$dir\""
517 done
518 set X $ld_res; shift
519 eval $ld_l=\"$@\"
520}
521
522
523## ------------------------------ ##
524## Language auxiliary functions. ##
525## ------------------------------ ##
526
527# out_lang_tex
528# ------------
529# Return the tex output language (DVI or PDF) for $OUT_LANG.
530out_lang_tex ()
531{
532 case $out_lang in
533 dvi | ps | dvipdf ) echo dvi;;
534 pdf ) echo $out_lang;;
535 html | info | text ) echo $out_lang;;
536 *) error 1 "$0: invalid out_lang: $1";;
537 esac
538}
539
540
541# out_lang_ext
542# ------------
543# Return the extension for $OUT_LANG.
544out_lang_ext ()
545{
546 case $out_lang in
547 dvipdf ) echo pdf;;
548 dvi | html | info | pdf | ps | text ) echo $out_lang;;
549 *) error 1 "$0: invalid out_lang: $1";;
550 esac
551}
552
553
554## ------------------------- ##
555## TeX auxiliary functions. ##
556## ------------------------- ##
557
558# Save TEXINPUTS so we can construct a new TEXINPUTS path for each file.
559# Likewise for bibtex and makeindex.
560tex_envvars="BIBINPUTS BSTINPUTS DVIPSHEADERS INDEXSTYLE MFINPUTS MPINPUTS \
561TEXINPUTS TFMFONTS"
562for var in $tex_envvars; do
563 eval ${var}_orig=\$$var
564 export $var
565done
566
567
568# absolute_filenames TEX-PATH -> TEX-PATH
569# ---------------------------------------
570# Convert relative paths to absolute paths, so we can run in another
571# directory (e.g., in tidy build mode, or during the macro-support
572# detection). Prepend ".".
573absolute_filenames ()
574{
575 # Empty path components are meaningful to tex. We rewrite them as
576 # `EMPTY' so they don't get lost when we split on $path_sep.
577 # Hopefully no one will have an actual directory named EMPTY.
578 local replace_empty="-e 's/^$path_sep/EMPTY$path_sep/g' \
579 -e 's/$path_sep\$/${path_sep}EMPTY/g' \
580 -e 's/$path_sep$path_sep/${path_sep}EMPTY:/g'"
581 local res
582 res=`echo "$1" | eval sed $replace_empty`
583 save_IFS=$IFS
584 IFS=$path_sep
585 set x $res; shift
586 res=.
587 for dir
588 do
589 case $dir in
590 EMPTY)
591 res=$res$path_sep
592 ;;
593 *)
594 if test -d "$dir"; then
595 res=$res$path_sep`absolute "$dir"`
596 else
597 # Even if $dir is not a directory, preserve it in the path.
598 # It might contain metacharacters that TeX will expand in
599 # turn, e.g., /some/path/{a,b,c}. This will not get the
600 # implicit absolutification of the path, but we can't help that.
601 res=$res$path_sep$dir
602 fi
603 ;;
604 esac
605 done
606 echo "$res"
607}
608
609
610# output_base_name FILE
611# ---------------------
612# The name of FILE, possibly renamed to satisfy --output.
613output_base_name ()
614{
615 case $oname in
616 '') echo "$1";;
617 *) local out_noext
618 out_noext=`echo "$oname" | sed 's/\.[^.]*$//'`
619 local file_ext
620 file_ext=`echo "$1" | sed 's/^.*\.//'`
621 echo "$out_noext.$file_ext"
622 ;;
623 esac
624}
625
626
627# move_to_dest FILE...
628# --------------------
629# Move FILE to the place where the user expects it. Truly move it, that
630# is, it must not remain in its build location unless that is also the
631# output location. (Otherwise it might appear as an extra file in make
632# distcheck.)
633#
634# FILE can be the principal output (in which case -o directly applies), or
635# an auxiliary file with the same base name.
636move_to_dest ()
637{
638 local dest
639 local destfile
640 local destdir
641 local destbase
642 local sourcedir
643 local sourcebase
644
645 for file
646 do
647 case $tidy:$oname in
648 true:) dest=$orig_pwd;;
649 false:) dest=;;
650 *:*) dest=`output_base_name "$file"`;;
651 esac
652 if test ! -f "$file"; then
653 error 1 "no such file or directory: $file"
654 fi
655 if test -n "$dest"; then
656 # We need to know whether $dest is a directory.
657 if test -d "$dest"; then
658 destdir=$dest
659 destfile=$dest/$file
660 else
661 destdir="`dirname $dest`"
662 destfile=$dest
663 fi
664 # We want to compare the source location and the output location,
665 # and if they are different, do the move. But if they are the
666 # same, we must preserve the source. Since we can't assume
667 # stat(1) or test -ef is available, resort to comparing the
668 # directory names, canonicalized with pwd. We can't use cmp -s
669 # since the output file might not actually change from run to run;
670 # e.g., TeX DVI output is timestamped to only the nearest minute.
671 destdir=`cd $destdir && pwd`
672 destbase=`basename $destfile`
673 #
674 sourcedir=`dirname $file`
675 sourcedir=`cd $sourcedir && pwd`
676 sourcebase=`basename $file`
677 #
678 if test "$sourcedir/$sourcebase" != "$destdir/$destbase"; then
679 verbose "Moving $file to $destfile"
680 rm -f "$destfile"
681 mv "$file" "$destfile"
682 fi
683 fi
684 done
685}
686
687
688## --------------------- ##
689## Managing xref files. ##
690## --------------------- ##
691
692# aux_file_p FILE
693# ---------------
694# Return with success with FILE is an aux file.
695aux_file_p ()
696{
697 test -f "$1" || return 1
698 case $1 in
699 *.aux) return 0;;
700 *) return 1;;
701 esac
702}
703
704# bibaux_file_p FILE
705# ------------------
706# Return with success with FILE is an aux file containing citation
707# requests.
708bibaux_file_p ()
709{
710 test -s "$1" || return 1
711 if (grep '^\\bibstyle[{]' "$1" \
712 && grep '^\\bibdata[{]' "$1" \
713 ## The following line is suspicious: fails when there
714 ## are citations in sub aux files. We need to be
715 ## smarter in this case.
716 ## && grep '^\\citation[{]' "$f"
717 ) >&6 2>&1;
718 then
719 return 0
720 fi
721 return 1
722}
723
724# index_file_p FILE
725# -----------------
726# Return with success with FILE is an index file.
727# When index.sty is used, there is a space before the brace.
728index_file_p ()
729{
730 test -f "$1" || return 1
731 case `sed '1q' "$1"` in
732 "\\entry{"*|"\\indexentry{"*|"\\indexentry {"*) return 0;;
733 *) return 1;;
734 esac
735}
736
737# xref_file_p FILE
738# ----------------
739# Return with success if FILE is an xref file (indexes, tables and lists).
740xref_file_p ()
741{
742 test -f "$1" || return 1
743 # If the file is not suitable to be an index or xref file, don't
744 # process it. It's suitable if the first character is a
745 # backslash or right quote or at, as long as the first line isn't
746 # \input texinfo.
747 case `sed '1q' "$1"` in
748 "\\input texinfo"*) return 1;;
749 [\\''@]*) return 0;;
750 *) return 1;;
751 esac
752}
753
754
755# generated_files_get FILENAME-NOEXT [PREDICATE-FILTER]
756# -----------------------------------------------------
757# Return the list of files generated by the TeX compilation of FILENAME-NOEXT.
758generated_files_get ()
759{
760 local filter=true
761 if test -n "$2"; then
762 filter=$2
763 fi
764
765 # Gather the files created by TeX.
766 (
767 if test -f "$1.log"; then
768 sed -n -e "s,^\\\\openout.* = \`\\(.*\\)'\\.,\\1,p" "$1.log"
769 fi
770 echo "$1.log"
771 ) |
772 # Depending on these files, infer outputs from other tools.
773 while read file; do
774 echo $file
775 case $in_lang in
776 texinfo)
777 # texindex: texinfo.cp -> texinfo.cps
778 if index_file_p $file; then
779 echo ${file}s
780 fi
781 ;;
782 latex)
783 if aux_file_p $file; then
784 # bibtex: *.aux -> *.bbl and *.blg.
785 echo $file | sed 's/^\(.*\)\.aux$/\1.bbl/'
786 echo $file | sed 's/^\(.*\)\.aux$/\1.blg/'
787 # -recorder: .fls
788 echo $file | sed 's/^\(.*\)\.aux$/\1.fls/'
789 fi
790 ;;
791 esac
792 done |
793 # Filter existing files matching the criterion.
794 #
795 # With an input file name containing a space, this produces a
796 # "command not found" message (and filtering is ineffective).
797 # The situation with a newline is presumably even worse.
798 while read file; do
799 if $filter "$file"; then
800 echo $file
801 fi
802 done |
803 sort |
804 # Some files are opened several times, e.g., listings.sty's *.vrb.
805 uniq
806}
807
808
809# xref_files_save
810# ---------------
811# Save the xref files.
812xref_files_save ()
813{
814 # Save copies of auxiliary files for later comparison.
815 xref_files_orig=`generated_files_get "$in_noext" xref_file_p`
816 if test -n "$xref_files_orig"; then
817 verbose "Backing up xref files: $xref_files_orig"
818 # The following line improves `cp $xref_files_orig "$work_bak"'
819 # by preserving the directory parts. Think of
820 # cp chap1/main.aux chap2/main.aux $work_bak.
821 #
822 # Users may have, e.g., --keep-old-files. Don't let this interfere.
823 # (Don't use unset for the sake of ancient shells.)
824 TAR_OPTIONS=; export TAR_OPTIONS
825 tar cf - $xref_files_orig | (cd "$work_bak" && tar xf -)
826 fi
827}
828
829
830# xref_files_changed
831# ------------------
832# Whether the xref files were changed since the previous run.
833xref_files_changed ()
834{
835 # LaTeX (and the package changebar) report in the LOG file if it
836 # should be rerun. This is needed for files included from
837 # subdirs, since texi2dvi does not try to compare xref files in
838 # subdirs. Performing xref files test is still good since LaTeX
839 # does not report changes in xref files.
840 if grep "Rerun to get" "$in_noext.log" >&6 2>&1; then
841 return 0
842 fi
843
844 # If old and new lists don't at least have the same file list,
845 # then one file or another has definitely changed.
846 xref_files_new=`generated_files_get "$in_noext" xref_file_p`
847 verbose "Original xref files = $xref_files_orig"
848 verbose "New xref files = $xref_files_new"
849 if test "x$xref_files_orig" != "x$xref_files_new"; then
850 return 0
851 fi
852
853 # Compare each file until we find a difference.
854 for this_file in $xref_files_new; do
855 verbose "Comparing xref file `echo $this_file | sed 's|\./||g'` ..."
856 # cmp -s returns nonzero exit status if files differ.
857 if cmp -s "$this_file" "$work_bak/$this_file"; then :; else
858 verbose "xref file `echo $this_file | sed 's|\./||g'` differed ..."
859 if $debug; then
860 diff -u "$work_bak/$this_file" "$this_file"
861 fi
862 return 0
863 fi
864 done
865
866 # No change.
867 return 1
868}
869
870
871
872## ----------------------- ##
873## Running the TeX suite. ##
874## ----------------------- ##
875
876
877
878# run_tex ()
879# ----------
880# Run TeX as "$tex $in_input", taking care of errors and logs.
881run_tex ()
882{
883 case $in_lang:`out_lang_tex` in
884 latex:dvi) tex=${LATEX:-latex};;
885 latex:pdf) tex=${PDFLATEX:-pdflatex};;
886 texinfo:dvi)
887 # MetaPost also uses the TEX environment variable. If the user
888 # has set TEX=latex for that reason, don't bomb out.
889 case $TEX in
890 *latex) tex=tex;; # don't bother trying to find etex
891 *) tex=$TEX
892 esac;;
893 texinfo:pdf) tex=$PDFTEX;;
894
895 *) error 1 "$0: $out_lang not supported for $in_lang";;
896 esac
897
898 # Beware of aux files in subdirectories that require the
899 # subdirectory to exist.
900 case $in_lang:$tidy in
901 latex:true)
902 sed -n 's|^[ ]*\\include{\(.*\)/.*}.*|\1|p' "$in_input" |
903 sort -u |
904 while read d
905 do
906 ensure_dir "$work_build/$d"
907 done
908 ;;
909 esac
910
911 # Note that this will be used via an eval: quote properly.
912 local cmd="$tex"
913
914 # If possible, make TeX report error locations in GNU format.
915 if test "${tex_help:+set}" != set; then
916 # Go to a temporary directory to try --help, since old versions that
917 # don't accept --help will generate a texput.log.
918 tex_help_dir=$t2ddir/tex_help
919 ensure_dir "$tex_help_dir"
920 tex_help=`cd "$tex_help_dir" >&6 && $tex --help </dev/null 2>&1`
921 fi
922 if $no_line_error; then :; else
923 # The mk program and perhaps others want to parse TeX's
924 # original error messages.
925 case $line_error:$tex_help in
926 true:*file-line-error*) cmd="$cmd --file-line-error";;
927 esac
928 fi
929
930 # Tell TeX about TCX file, if specified.
931 test -n "$translate_file" && cmd="$cmd --translate-file=$translate_file"
932
933 # Tell TeX to make source specials (for backtracking from output to
934 # source, given a sufficiently smart editor), if specifed.
935 test -n "$src_specials" && cmd="$cmd $src_specials"
936
937 # Tell TeX to be batch if requested.
938 if $batch; then
939 # \batchmode does not show terminal output at all, so we don't
940 # want that. And even in batch mode, TeX insists on having input
941 # from the user. Close its stdin to make it impossible.
942 cmd="$cmd </dev/null '${escape}nonstopmode'"
943 fi
944
945 # we'd like to handle arbitrary input file names, especially
946 # foo~bar/a~b.tex, since Debian likes ~ characters.
947 if $catcode_special; then
948 # $normaltilde is just to reduce line length in this source file.
949 # The idea is to define \normaltilde as a catcode other ~ character,
950 # then make the active ~ be equivalent to that, instead of the plain
951 # TeX tie. Then when the active ~ appears in the filename, it will
952 # be expanded to itself, as far as \input will see. (This is the
953 # same thing that texinfo.tex does in general, BTW.)
954 normaltilde="${escape}catcode126=12 ${escape}def${escape}normaltilde{~}"
955 cmd="$cmd '$normaltilde${escape}catcode126=13 ${escape}let~\normaltilde '"
956 fi
957 # Other special (non-active) characters could be supported by
958 # resetting their catcodes to other on the command line and changing
959 # texinfo.tex to initialize everything to plain catcodes. Maybe someday.
960
961 # append the \input command.
962 cmd="$cmd '${escape}input'"
963
964 # TeX's \input does not (easily or reliably) support whitespace
965 # characters or other special characters in file names. Our intensive
966 # use of absolute file names makes this worse: the enclosing directory
967 # names may include white spaces. Improve the situation using a
968 # symbolic link to the filename in the current directory, in tidy mode
969 # only. Do not alter in_input.
970 #
971 # The filename is almost always tokenized using plain TeX conventions
972 # (the exception would be if the user made a texinfo.fmt file). Not
973 # all the plain TeX special characters cause trouble, but there's no
974 # harm in making the link.
975 #
976 case $tidy:`func_dirname "$in_input"` in
977 true:*["$space$tab$newline\"#\$%\\^_{}~"]*)
978 _run_tex_file_name=`basename "$in_input"`
979 if test ! -f "$_run_tex_file_name"; then
980 # It might not be a file, clear it.
981 run rm -f "$_run_tex_file_name"
982 run ln -s "$in_input"
983 fi
984 cmd="$cmd '$_run_tex_file_name'"
985 ;;
986
987 *)
988 cmd="$cmd '$in_input'"
989 ;;
990 esac
991
992 verbose "$0: Running $cmd ..."
993 if eval "$cmd" >&5; then
994 case $out_lang in
995 dvi | pdf ) move_to_dest "$in_noext.$out_lang";;
996 esac
997 else
998 error 1 "$tex exited with bad status, quitting."
999 fi
1000}
1001
1002# run_bibtex ()
1003# -------------
1004# Run bibtex on current file.
1005# - If its input (AUX) exists.
1006# - If some citations are missing (LOG contains `Citation').
1007# or the LOG complains of a missing .bbl
1008#
1009# Don't try to be too smart:
1010#
1011# 1. Running bibtex only if the bbl file exists and is older than
1012# the LaTeX file is wrong, since the document might include files
1013# that have changed.
1014#
1015# 3. Because there can be several AUX (if there are \include's),
1016# but a single LOG, looking for missing citations in LOG is
1017# easier, though we take the risk to match false messages.
1018run_bibtex ()
1019{
1020 case $in_lang in
1021 latex) bibtex=${BIBTEX:-bibtex};;
1022 texinfo) return;;
1023 esac
1024
1025 # "Citation undefined" is for LaTeX, "Undefined citation" for btxmac.tex.
1026 # The no .aux && \bibdata test is also for btxmac, in case it was the
1027 # first run of a bibtex-using document. Otherwise, it's possible that
1028 # bibtex would never be run.
1029 if test -r "$in_noext.aux" \
1030 && test -r "$in_noext.log" \
1031 && (grep 'Warning:.*Citation.*undefined' "$in_noext.log" \
1032 || grep '.*Undefined citation' "$in_noext.log" \
1033 || grep 'No file .*\.bbl\.' "$in_noext.log") \
1034 || (grep 'No \.aux file' "$in_noext.log" \
1035 && grep '^\\bibdata' "$in_noext.aux") \
1036 >&6 2>&1; \
1037 then
1038 for f in `generated_files_get "$in_noext" bibaux_file_p`
1039 do
1040 run $bibtex "$f"
1041 done
1042 fi
1043}
1044
1045# run_index ()
1046# ------------
1047# Run texindex (or makeindex) on current index files. If they already
1048# exist, and after running TeX a first time the index files don't
1049# change, then there's no reason to run TeX again. But we won't know
1050# that if the index files are out of date or nonexistent.
1051run_index ()
1052{
1053 case $in_lang in
1054 latex) texindex=${MAKEINDEX:-makeindex};;
1055 texinfo) texindex=${TEXINDEX:-texindex};;
1056 esac
1057 index_files=`generated_files_get $in_noext index_file_p`
1058 if test -n "$texindex" && test -n "$index_files"; then
1059 run $texindex $index_files
1060 fi
1061}
1062
1063
1064# run_thumbpdf ()
1065# ---------------
1066run_thumbpdf ()
1067{
1068 if test `out_lang_tex` = pdf \
1069 && test -r "$in_noext.log" \
1070 && grep 'thumbpdf\.sty' "$in_noext.log" >&6 2>&1; \
1071 then
1072 thumbpdf=${THUMBPDF:-thumbpdf}
1073 thumbcmd="$thumbpdf $in_dir/$in_noext"
1074 verbose "Running $thumbcmd ..."
1075 if $thumbcmd >&5; then
1076 run_tex
1077 else
1078 report "$thumbpdf exited with bad status." \
1079 "Ignoring its output."
1080 fi
1081 fi
1082}
1083
1084
1085# run_dvipdf FILE.dvi
1086# -------------------
1087# Convert FILE.dvi to FILE.pdf.
1088run_dvipdf ()
1089{
1090 # Find which dvi->pdf program is available.
1091 if test -z "$dvipdf"; then
1092 for i in "$DVIPDF" dvipdfmx dvipdfm dvipdf dvi2pdf dvitopdf;
1093 do
1094 if findprog $i; then
1095 dvipdf=$i
1096 fi
1097 done
1098 fi
1099 # These tools have varying interfaces, some 'input output', others
1100 # 'input -o output'. They all seem to accept 'input' only,
1101 # outputting using the expected file name.
1102 run $dvipdf "$1"
1103 if test ! -f `echo "$1" | sed -e 's/\.dvi$/.pdf/'`; then
1104 error 1 "$0: cannot find output file"
1105 fi
1106}
1107
1108# run_tex_suite ()
1109# ----------------
1110# Run the TeX tools until a fix point is reached.
1111run_tex_suite ()
1112{
1113 # Move to the working directory.
1114 if $tidy; then
1115 verbose "cd $work_build"
1116 cd "$work_build" || exit 1
1117 fi
1118
1119 # Count the number of cycles.
1120 local cycle=0
1121
1122 while :; do
1123 cycle=`expr $cycle + 1`
1124 verbose "Cycle $cycle for $command_line_filename"
1125
1126 xref_files_save
1127
1128 # We run bibtex first, because I can see reasons for the indexes
1129 # to change after bibtex is run, but I see no reason for the
1130 # converse.
1131 run_bibtex
1132 run_index
1133 run_core_conversion
1134
1135 xref_files_changed || break
1136 done
1137
1138 # If we were using thumbpdf and producing PDF, then run thumbpdf
1139 # and TeX one last time.
1140 run_thumbpdf
1141
1142 # Install the result if we didn't already (i.e., if the output is
1143 # dvipdf or ps).
1144 case $out_lang in
1145 dvipdf)
1146 run_dvipdf "$in_noext.`out_lang_tex`"
1147 move_to_dest "$in_noext.`out_lang_ext`"
1148 ;;
1149 ps)
1150 dvips -o "$in_noext.`out_lang_ext`" "$in_noext.`out_lang_tex`"
1151 move_to_dest "$in_noext.`out_lang_ext`"
1152 ;;
1153 esac
1154
1155 cd_orig
1156}
1157
1158## -------------------------------- ##
1159## TeX processing auxiliary tools. ##
1160## -------------------------------- ##
1161
1162
1163# A sed script that preprocesses Texinfo sources in order to keep the
1164# iftex sections only. We want to remove non TeX sections, and comment
1165# (with `@c texi2dvi') TeX sections so that makeinfo does not try to
1166# parse them. Nevertheless, while commenting TeX sections, don't
1167# comment @macro/@end macro so that makeinfo does propagate them.
1168# Unfortunately makeinfo --iftex --no-ifinfo doesn't work well enough
1169# (yet), makeinfo can't parse the TeX commands, so work around with sed.
1170#
1171comment_iftex=\
1172'/^@tex/,/^@end tex/{
1173 s/^/@c texi2dvi/
1174}
1175/^@iftex/,/^@end iftex/{
1176 s/^/@c texi2dvi/
1177 /^@c texi2dvi@macro/,/^@c texi2dvi@end macro/{
1178 s/^@c texi2dvi//
1179 }
1180}
1181/^@ifnottex/,/^@end ifnottex/{
1182 s/^/@c (texi2dvi)/
1183}
1184/^@ifinfo/,/^@end ifinfo/{
1185 /^@node/p
1186 /^@menu/,/^@end menu/p
1187 t
1188 s/^/@c (texi2dvi)/
1189}
1190s/^@ifnotinfo/@c texi2dvi@ifnotinfo/
1191s/^@end ifnotinfo/@c texi2dvi@end ifnotinfo/'
1192
1193# Uncommenting is simple: Remove any leading `@c texi2dvi'.
1194uncomment_iftex='s/^@c texi2dvi//'
1195
1196
1197# run_makeinfo ()
1198# ---------------
1199# Expand macro commands in the original source file using Makeinfo.
1200# Always use `end' footnote style, since the `separate' style
1201# generates different output (arguably this is a bug in -E). Discard
1202# main info output, the user asked to run TeX, not makeinfo.
1203run_makeinfo ()
1204{
1205 test $in_lang = texinfo \
1206 || return 0
1207
1208 # Unless required by the user, makeinfo expansion is wanted only
1209 # if texinfo.tex is too old.
1210 if test "$expand" = t; then
1211 makeinfo=${MAKEINFO:-makeinfo}
1212 else
1213 # Check if texinfo.tex performs macro expansion by looking for
1214 # its version. The version is a date of the form YEAR-MO-DA.
1215 # We don't need to use [0-9] to match the digits since anyway
1216 # the comparison with $txiprereq, a number, will fail with non
1217 # digits.
1218 # Run in a temporary directory to avoid leaving files.
1219 version_test_dir=$t2ddir/version_test
1220 ensure_dir "$version_test_dir"
1221 (
1222 cd "$version_test_dir"
1223 echo '\input texinfo.tex @bye' >txiversion.tex
1224 # Be sure that if tex wants to fail, it is not interactive:
1225 # close stdin.
1226 $TEX txiversion.tex </dev/null >txiversion.out 2>txiversion.err
1227 )
1228 if test $? != 0; then
1229 cat "$version_test_dir/txiversion.out"
1230 cat "$version_test_dir/txiversion.err" >&2
1231 error 1 "texinfo.tex appears to be broken, quitting."
1232 fi
1233 eval `sed -n 's/^.*\[\(.*\)version \(....\)-\(..\)-\(..\).*$/txiformat=\1 txiversion="\2\3\4"/p' "$version_test_dir/txiversion.out"`
1234 verbose "texinfo.tex preloaded as \`$txiformat', version is \`$txiversion' ..."
1235 if test "$txiprereq" -le "$txiversion" >&6 2>&1; then
1236 makeinfo=
1237 else
1238 makeinfo=${MAKEINFO:-makeinfo}
1239 fi
1240 # As long as we had to run TeX, offer the user this convenience:
1241 if test "$txiformat" = Texinfo; then
1242 escape=@
1243 fi
1244 fi
1245
1246 if test -n "$makeinfo"; then
1247 # in_src: the file with macros expanded.
1248 # Use the same basename to generate the same aux file names.
1249 work_src=$workdir/src
1250 ensure_dir "$work_src"
1251 in_src=$work_src/$in_base
1252 local miincludes
1253 miincludes=`list_prefix includes -I`
1254 verbose "Macro-expanding $command_line_filename to $in_src ..."
1255 # eval $makeinfo because it might be defined as something complex
1256 # (running missing) and then we end up with things like '"-I"',
1257 # and "-I" (including the quotes) is not an option name. This
1258 # happens with gettext 0.14.5, at least.
1259 sed "$comment_iftex" "$command_line_filename" \
1260 | eval $makeinfo --footnote-style=end -I "$in_dir" $miincludes \
1261 -o /dev/null --macro-expand=- \
1262 | sed "$uncomment_iftex" >"$in_src"
1263 # Continue only if everything succeeded.
1264 if test $? -ne 0 \
1265 || test ! -r "$in_src"; then
1266 verbose "Expansion failed, ignored...";
1267 else
1268 in_input=$in_src
1269 fi
1270 fi
1271}
1272
1273# insert_commands ()
1274# ------------------
1275# Used most commonly for @finalout, @smallbook, etc.
1276insert_commands ()
1277{
1278 local textra_cmd
1279 case $in_lang in
1280 latex) textra_cmd=1i;;
1281 texinfo) textra_cmd='/^@setfilename/a';;
1282 *) error 1 "internal error, unknown language: $in_lang";;
1283 esac
1284
1285 if test -n "$textra"; then
1286 # _xtr. The file with the user's extra commands.
1287 work_xtr=$workdir/xtr
1288 in_xtr=$work_xtr/$in_base
1289 ensure_dir "$work_xtr"
1290 verbose "Inserting extra commands: $textra"
1291 sed "$textra_cmd\\
1292$textra" "$in_input" >"$in_xtr"
1293 in_input=$in_xtr
1294 fi
1295}
1296
1297# run_recode ()
1298# -------------
1299# If this is a Texinfo file with a specified input encoding, and
1300# recode is available, then recode to plain 7 bit Texinfo.
1301run_recode ()
1302{
1303 local from
1304 local to
1305
1306 if test $in_lang = texinfo; then
1307 pgm='s/^ *@documentencoding *\([^ ][^ ]*\) *$/\1/
1308 t found
1309 d
1310 :found
1311 q'
1312 encoding=`sed -e "$pgm" "$in_input"`
1313 if $recode && test -n "$encoding" && findprog recode; then
1314 if test -n "$recode_from"; then
1315 from=$recode_from
1316 to=$encoding
1317 else
1318 from=$encoding
1319 to=$texinfo
1320 fi
1321 verbose "Recoding from $from to $to."
1322 # _rcd. The Texinfo file recoded in 7bit.
1323 work_rcd=$workdir/recode
1324 in_rcd=$work_rcd/$in_base
1325 ensure_dir "$work_rcd"
1326 if recode "$encoding..$to" <"$in_input" >"$in_rcd" \
1327 && test -s "$in_rcd"; then
1328 in_input=$in_rcd
1329 else
1330 verbose "Recoding failed, using original input."
1331 fi
1332 fi
1333 fi
1334}
1335
1336# compute_language FILENAME
1337# -------------------------
1338# Return the short string describing the language in which FILENAME
1339# is written: `texinfo' or `latex'.
1340compute_language ()
1341{
1342 # If the user explicitly specified the language, use that.
1343 # Otherwise, if the first line is \input texinfo, assume it's texinfo.
1344 # Otherwise, guess from the file extension.
1345 if test -n "$set_language"; then
1346 echo $set_language
1347 elif sed 1q "$1" | grep 'input texinfo' >&6; then
1348 echo texinfo
1349 else
1350 # Get the type of the file (latex or texinfo) from the given language
1351 # we just guessed, or from the file extension if not set yet.
1352 case $1 in
1353 *.ltx | *.tex | *.drv | *.dtx) echo latex;;
1354 *) echo texinfo;;
1355 esac
1356 fi
1357}
1358
1359
1360# run_hevea (MODE)
1361# ----------------
1362# Convert to HTML/INFO/TEXT.
1363#
1364# Don't pass `-noiso' to hevea: it's useless in HTML since anyway the
1365# charset is set to latin1, and troublesome in other modes since
1366# accented characters loose their accents.
1367#
1368# Don't pass `-o DEST' to hevea because in that case it leaves all its
1369# auxiliary files there too... Too bad, because it means we will need
1370# to handle images some day.
1371run_hevea ()
1372{
1373 local hevea="${HEVEA:-hevea}"
1374 local run_hevea="$hevea"
1375
1376 case $1 in
1377 html) ;;
1378 text|info) run_hevea="$run_hevea -$1";;
1379 *) error 1 "run_hevea: invalid argument: $1";;
1380 esac
1381
1382 # Compiling to the tmp directory enables to preserve a previous
1383 # successful compilation.
1384 run_hevea="$run_hevea -fix -O -o '$out_base'"
1385 run_hevea="$run_hevea `list_prefix includes -I` -I '$orig_pwd' "
1386 run_hevea="$run_hevea '$in_input'"
1387
1388 if $debug; then
1389 run_hevea="$run_hevea -v -v"
1390 fi
1391
1392 verbose "running $run_hevea"
1393 if eval "$run_hevea" >&5; then
1394 # hevea leaves trailing white spaces, this is annoying.
1395 case $1 in text|info)
1396 perl -pi -e 's/[ \t]+$//g' "$out_base"*;;
1397 esac
1398 case $1 in
1399 html|text) move_to_dest "$out_base";;
1400 info) # There can be foo.info-1, foo.info-2 etc.
1401 move_to_dest "$out_base"*;;
1402 esac
1403 else
1404 error 1 "$hevea exited with bad status, quitting."
1405 fi
1406}
1407
1408
1409# run_core_conversion ()
1410# ----------------------
1411# Run the TeX (or HeVeA).
1412run_core_conversion ()
1413{
1414 case $in_lang:`out_lang_tex` in
1415 *:dvi|*:pdf)
1416 run_tex;;
1417 latex:html|latex:text|latex:info)
1418 run_hevea $out_lang;;
1419 *)
1420 error 1 "invalid input/output combination: $in_lang/$out_lang";;
1421 esac
1422}
1423
1424
1425# compile ()
1426# ----------
1427# Run the full compilation chain, from pre-processing to installation
1428# of the output at its expected location.
1429compile ()
1430{
1431 # Source file might include additional sources.
1432 # We want `.:$orig_pwd' before anything else. (We'll add `.:' later
1433 # after all other directories have been turned into absolute paths.)
1434 # `.' goes first to ensure that any old .aux, .cps,
1435 # etc. files in ${directory} don't get used in preference to fresher
1436 # files in `.'. Include orig_pwd in case we are in clean build mode, where
1437 # we've cd'd to a temp directory.
1438 txincludes=`list_infix includes $path_sep`
1439 common="$orig_pwd$path_sep$in_dir$path_sep$txincludes$path_sep"
1440 for var in $tex_envvars; do
1441 eval val="\$common\$${var}_orig"
1442 # Convert relative paths to absolute paths, so we can run in another
1443 # directory (e.g., in clean build mode, or during the macro-support
1444 # detection). ".:" is added here.
1445 val=`absolute_filenames "$val"`
1446 eval $var="\"$val\""
1447 export $var
1448 eval verbose \"$var=\'\$${var}\'\"
1449 done
1450
1451 # --expand
1452 run_makeinfo
1453
1454 # --command, --texinfo
1455 insert_commands
1456
1457 # --recode
1458 run_recode
1459
1460 # Run until a fix point is reached.
1461 run_tex_suite
1462}
1463
1464
1465# remove FILES
1466# ------------
1467remove ()
1468{
1469 verbose "Removing" "$@"
1470 rm -rf "$@"
1471}
1472
1473
1474# mostly_clean
1475# ------------
1476# Remove auxiliary files and directories. Changes the current directory.
1477mostly_clean ()
1478{
1479 cd_orig
1480 set X "$t2ddir"
1481 shift
1482 $tidy || {
1483 local log="$work_build/$in_noext.log"
1484 set X ${1+"$@"} "$log" `generated_files_get "$work_build/$in_noext"`
1485 shift
1486 }
1487 remove ${1+"$@"}
1488}
1489
1490
1491# cleanup ()
1492# ----------
1493# Remove what should be removed according to options.
1494# Called at the end of each compilation cycle, and at the end of
1495# the script. Changes the current directory.
1496cleanup ()
1497{
1498 case $build_mode in
1499 local) cd_orig; remove "$t2ddir";;
1500 clean) mostly_clean;;
1501 tidy) ;;
1502 esac
1503}
1504
1505
1506
1507## ---------------------- ##
1508## Command line parsing. ##
1509## ---------------------- ##
1510
1511# Push a token among the arguments that will be used to notice when we
1512# ended options/arguments parsing.
1513# Use "set dummy ...; shift" rather than 'set - ..." because on
1514# Solaris set - turns off set -x (but keeps set -e).
1515# Use ${1+"$@"} rather than "$@" because Digital Unix and Ultrix 4.3
1516# still expand "$@" to a single argument (the empty string) rather
1517# than nothing at all.
1518arg_sep="$$--$$"
1519set dummy ${1+"$@"} "$arg_sep"; shift
1520
1521#
1522
1523# Parse command line arguments.
1524while test x"$1" != x"$arg_sep"; do
1525
1526 # Handle --option=value by splitting apart and putting back on argv.
1527 case "$1" in
1528 --*=*)
1529 opt=`echo "$1" | sed -e 's/=.*//'`
1530 val=`echo "$1" | sed -e 's/[^=]*=//'`
1531 shift
1532 set dummy "$opt" "$val" ${1+"$@"}; shift
1533 ;;
1534 esac
1535
1536 # This recognizes --quark as --quiet. So what.
1537 case "$1" in
1538 -@ ) escape=@;;
1539 # Silently and without documentation accept -b and --b[atch] as synonyms.
1540 -b | --batch) batch=true;;
1541 --build) shift; build_mode=$1;;
1542 --build-dir) shift; build_dir=$1; build_mode=tidy;;
1543 -c | --clean) build_mode=clean;;
1544 -D | --debug) debug=true;;
1545 --dvi) out_lang=dvi;;
1546 --dvipdf) out_lang=dvipdf;;
1547 -e | -E | --expand) expand=t;;
1548 -h | --help) usage;;
1549 --html) out_lang=html;;
1550 -I) shift; list_concat_dirs includes "$1";;
1551 --info) out_lang=info;;
1552 -l | --lang | --language) shift; set_language=$1;;
1553 --mostly-clean) action=mostly-clean;;
1554 --no-line-error) no_line_error=true;;
1555 -o | --out | --output)
1556 shift
1557 # Make it absolute, just in case we also have --clean, or whatever.
1558 oname=`absolute "$1"`;;
1559 -p | --pdf) out_lang=pdf;;
1560 --ps) out_lang=ps;;
1561 -q | -s | --quiet | --silent) quiet=true; batch=true;;
1562 -r | --recode) recode=true;;
1563 --recode-from) shift; recode=true; recode_from="$1";;
1564 --src-specials) src_specials=--src-specials;;
1565 -t | --texinfo | --command ) shift; textra="$textra\\
1566"`echo "$1" | sed 's/\\\\/\\\\\\\\/g'`;;
1567 --text) out_lang=text;;
1568 --translate-file ) shift; translate_file="$1";;
1569 --tidy) build_mode=tidy;;
1570 -v | --vers*) version;;
1571 -V | --verb*) verb=true;;
1572 --) # What remains are not options.
1573 shift
1574 while test x"$1" != x"$arg_sep"; do
1575 set dummy ${1+"$@"} "$1"; shift
1576 shift
1577 done
1578 break;;
1579 -*)
1580 error 1 "Unknown or ambiguous option \`$1'." \
1581 "Try \`--help' for more information."
1582 ;;
1583 *) set dummy ${1+"$@"} "$1"; shift;;
1584 esac
1585 shift
1586done
1587# Pop the token
1588shift
1589
1590# $tidy: compile in a t2d directory.
1591# $clean: remove all the aux files.
1592case $build_mode in
1593 local) clean=false; tidy=false;;
1594 tidy) clean=false; tidy=true;;
1595 clean) clean=true; tidy=true;;
1596 *) error 1 "invalid build mode: $build_mode";;
1597esac
1598
1599# Interpret remaining command line args as filenames.
1600case $# in
1601 0)
1602 error 2 "Missing file arguments." "Try \`--help' for more information."
1603 ;;
1604 1) ;;
1605 *)
1606 if test -n "$oname"; then
1607 error 2 "Can't use option \`--output' with more than one argument."
1608 fi
1609 ;;
1610esac
1611
1612
1613# We can't do much without tex.
1614#
1615if findprog ${TEX:-tex}; then :; else cat <<EOM
1616You don't have a working TeX binary (${TEX:-tex}) installed anywhere in
1617your PATH, and texi2dvi cannot proceed without one. If you want to use
1618this script, you'll need to install TeX (if you don't have it) or change
1619your PATH or TEX environment variable (if you do). See the --help
1620output for more details.
1621
1622For information about obtaining TeX, please see http://www.tug.org. If
1623you happen to be using Debian, you can get it with this command:
1624 apt-get install tetex-bin
1625EOM
1626 exit 1
1627fi
1628
1629
1630# We want to use etex (or pdftex) if they are available, and the user
1631# didn't explicitly specify. We don't check for elatex and pdfelatex
1632# because (as of 2003), the LaTeX team has asked that new distributions
1633# use etex by default anyway.
1634#
1635# End up with the TEX and PDFTEX variables set to what we are going to use.
1636if test -z "$TEX"; then
1637 if findprog etex; then TEX=etex; else TEX=tex; fi
1638fi
1639#
1640if test -z "$PDFTEX"; then
1641 if findprog pdfetex; then PDFTEX=pdfetex; else PDFTEX=pdftex; fi
1642fi
1643
1644
1645# File descriptor usage:
1646# 0 standard input
1647# 1 standard output (--verbose messages)
1648# 2 standard error
1649# 3 some systems may open it to /dev/tty
1650# 4 used on the Kubota Titan
1651# 5 tools output (turned off by --quiet)
1652# 6 tracing/debugging (set -x output, etc.)
1653
1654
1655# Main tools' output (TeX, etc.) that TeX users are used to seeing.
1656#
1657# If quiet, discard, else redirect to the message flow.
1658if $quiet; then
1659 exec 5>/dev/null
1660else
1661 exec 5>&1
1662fi
1663
1664
1665# Enable tracing, and auxiliary tools output.
1666#
1667# Should be used where you'd typically use /dev/null to throw output
1668# away. But sometimes it is convenient to see that output (e.g., from
1669# a grep) to aid debugging. Especially debugging at distance, via the
1670# user.
1671if $debug; then
1672 exec 6>&1
1673 set -x
1674else
1675 exec 6>/dev/null
1676fi
1677
1678#
1679
1680
1681# input_file_name_decode
1682# ----------------------
1683# Decode COMMAND_LINE_FILENAME, and compute:
1684# - COMMAND_LINE_FILENAME clean of TeX commands
1685# - IN_DIR
1686# The directory to the input file, possibly absolute if needed.
1687# - IN_DIR_ABS
1688# The absolute directory of the input file.
1689# - IN_BASE
1690# The input file base name (no directory part).
1691# - IN_NOEXT
1692# The input file name without extensions (nor directory part).
1693# - IN_INPUT
1694# Defaults to COMMAND_LINE_FILENAME, but might change if the
1695# input is preprocessed (recode etc.). With directory, possibly absolute.
1696input_file_name_decode ()
1697{
1698 # See if we are run from within AUC-Tex, in which case we are
1699 # passed `\input{FOO.tex}' or even `\nonstopmode\input{FOO.tex}'.
1700 case $command_line_filename in
1701 *\\nonstopmode*)
1702 batch=true;;
1703 esac
1704 case $command_line_filename in
1705 *\\input{*}*)
1706 # Let AUC-TeX error parser deal with line numbers.
1707 line_error=false
1708 command_line_filename=`\
1709 expr X"$command_line_filename" : X'.*input{\([^}]*\)}'`
1710 ;;
1711 esac
1712
1713 # If the COMMAND_LINE_FILENAME is not absolute (e.g., --debug.tex),
1714 # prepend `./' in order to avoid that the tools take it as an option.
1715 echo "$command_line_filename" | $EGREP '^(/|[A-z]:/)' >&6 \
1716 || command_line_filename="./$command_line_filename"
1717
1718 # See if the file exists. If it doesn't we're in trouble since, even
1719 # though the user may be able to reenter a valid filename at the tex
1720 # prompt (assuming they're attending the terminal), this script won't
1721 # be able to find the right xref files and so forth.
1722 test -r "$command_line_filename" ||
1723 error 1 "cannot read $command_line_filename, skipping."
1724
1725 # Get the name of the current directory.
1726 in_dir=`func_dirname "$command_line_filename"`
1727 in_dir_abs=`absolute "$in_dir"`
1728 # In a clean build, we `cd', so get an absolute file name.
1729 if $tidy; then
1730 in_dir=$in_dir_abs
1731 fi
1732
1733 # Strip directory part but leave extension.
1734 in_base=`basename "$command_line_filename"`
1735 # Strip extension.
1736 in_noext=`echo "$in_base" | sed 's/\.[^.]*$//'`
1737
1738 # The normalized file name to compile. Must always point to the
1739 # file to actually compile (in case of recoding, macro-expansion etc.).
1740 in_input=$in_dir/$in_base
1741
1742
1743 # Compute the output file name.
1744 if test x"$oname" != x; then
1745 out_name=$oname
1746 else
1747 out_name=$in_noext.`out_lang_ext`
1748 fi
1749 out_dir=`func_dirname "$out_name"`
1750 out_dir_abs=`absolute "$out_dir"`
1751 out_base=`basename "$out_name"`
1752 out_noext=`echo "$out_base" | sed 's/\.[^.]*$//'`
1753}
1754
1755
1756## -------------- ##
1757## TeXify files. ##
1758## -------------- ##
1759
1760for command_line_filename
1761do
1762 verbose "Processing $command_line_filename ..."
1763
1764 input_file_name_decode
1765
1766 # `texinfo' or `latex'?
1767 in_lang=`compute_language "$command_line_filename"`
1768
1769 # An auxiliary directory used for all the auxiliary tasks involved
1770 # in compiling this document.
1771 case $build_dir in
1772 '' | . ) t2ddir=$out_noext.t2d ;;
1773 *) # Avoid collisions between multiple occurrences of the same
1774 # file. The sed expression is fragile if the cwd has
1775 # active characters.
1776 t2ddir=$build_dir/`echo "$out_dir_abs/$out_noext.t2d" |
1777 sed "s,^$orig_pwd/,," |
1778 sed 's,/,!,g'`
1779 esac
1780 # Remove it at exit if clean mode.
1781 trap "cleanup" 0 HUP INT TERM
1782
1783 ensure_dir "$build_dir" "$t2ddir"
1784
1785 # We will change directory, better work with an absolute path...
1786 t2ddir=`absolute "$t2ddir"`
1787 # Sometimes there are incompatibilities between auxiliary files for
1788 # DVI and PDF. The contents can also change whether we work on PDF
1789 # and/or DVI. So keep separate spaces for each.
1790 workdir=$t2ddir/`out_lang_tex`
1791 ensure_dir "$workdir"
1792
1793 # _build. In a tidy build, where the auxiliary files are output.
1794 if $tidy; then
1795 work_build=$workdir/build
1796 else
1797 work_build=.
1798 fi
1799
1800 # _bak. Copies of the previous auxiliary files (another round is
1801 # run if they differ from the new ones).
1802 work_bak=$workdir/bak
1803
1804 # Make those directories.
1805 ensure_dir "$work_build" "$work_bak"
1806
1807 case $action in
1808 compile)
1809 # Compile the document.
1810 compile
1811 cleanup
1812 ;;
1813
1814 mostly-clean)
1815 mostly_clean
1816 ;;
1817 esac
1818done
1819
1820verbose "done."
1821exit 0 # exit successfully, not however we ended the loop.
Note: See TracBrowser for help on using the repository browser.