The R Project SVN R

Rev

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

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