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