The R Project SVN R

Rev

Rev 26409 | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

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