comparison texi2dvi @ 2518:64de62e8e73d

[project @ 1996-11-14 20:42:03 by jwe]
author jwe
date Thu, 14 Nov 1996 20:42:37 +0000
parents
children 6914eab16f0b
comparison
equal deleted inserted replaced
2517:0c5e671499ed 2518:64de62e8e73d
1 #! /bin/sh
2 # texi2dvi --- smartly produce DVI files from texinfo sources
3
4 # Copyright (C) 1992, 93, 94, 95, 96 Free Software Foundation, Inc.
5
6 # $Id: texi2dvi,v 1.1 1996-11-14 20:42:03 jwe Exp $
7
8 # This program is free software; you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation; either version 2, or (at your option)
11 # any later version.
12 #
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
17 #
18 # You should have received a copy of the GNU General Public License
19 # along with this program; if not, you can either send email to this
20 # program's maintainer or write to: The Free Software Foundation,
21 # Inc.; 59 Temple Place, Suite 330; Boston, MA 02111-1307, USA.
22
23 # Commentary:
24
25 # Author: Noah Friedman <friedman@prep.ai.mit.edu>
26
27 # Please send bug reports, etc. to bug-texinfo@prep.ai.mit.edu
28 # If possible, please send a copy of the output of the script called with
29 # the `--debug' option when making a bug report.
30
31 # In the interest of general portability, some common bourne shell
32 # constructs were avoided because they weren't guaranteed to be available
33 # in some earlier implementations. I've tried to make this program as
34 # portable as possible. Welcome to unix, where the lowest common
35 # denominator is rapidly diminishing.
36 #
37 # Among the more interesting lossages I noticed with some bourne shells
38 # are:
39 # * No shell functions.
40 # * No `unset' builtin.
41 # * `shift' cannot take a numeric argument, and signals an error if
42 # there are no arguments to shift.
43
44 # Code:
45
46 # Name by which this script was invoked.
47 progname=`echo "$0" | sed -e 's/[^\/]*\///g'`
48
49 # This string is expanded by rcs automatically when this file is checked out.
50 rcs_revision='$Revision: 1.1 $'
51 version=`set - $rcs_revision; echo $2`
52
53 # To prevent hairy quoting and escaping later.
54 bq='`'
55 eq="'"
56
57 usage="Usage: $0 [OPTION]... FILE...
58 Run a Texinfo document through TeX.
59
60 Options:
61 -D, --debug Turn on shell debugging ($bq${bq}set -x$eq$eq).
62 -t, --texinfo CMD Insert CMD after @setfilename before running TeX.
63 --verbose Report on what is done.
64 -h, --help Display this help and exit.
65 -v, --version Display version information and exit.
66
67 The values of the TEX, TEXINDEX, and MAKEINFO environment variables are
68 used to run those commands, if they are set.
69
70 Email bug reports to bug-texinfo@prep.ai.mit.edu.
71 "
72
73 # Initialize variables.
74 # Don't use `unset' since old bourne shells don't have this command.
75 # Instead, assign them an empty value.
76 # Some of these, like TEX and TEXINDEX, may be inherited from the environment.
77 backup_extension=.bak # these files get deleted if all goes well.
78 debug=
79 orig_pwd="`pwd`"
80 textra=
81 verbose=false
82 makeinfo="${MAKEINFO-makeinfo}"
83 texindex="${TEXINDEX-texindex}"
84 tex="${TEX-tex}"
85
86 # Save this so we can construct a new TEXINPUTS path for each file.
87 TEXINPUTS_orig="$TEXINPUTS"
88 export TEXINPUTS
89
90 # Parse command line arguments.
91 # Make sure that all wildcarded options are long enough to be unambiguous.
92 # It's a good idea to document the full long option name in each case.
93 # Long options which take arguments will need a `*' appended to the
94 # canonical name to match the value appended after the `=' character.
95 while : ; do
96 case $# in 0) break ;; esac
97 case "$1" in
98 -D | --debug | --d* ) debug=t; shift ;;
99 -h | --help | --h* ) echo "$usage"; exit 0 ;;
100 # OK, we should do real option parsing here, but be lazy for now.
101 -t | --texinfo | --t*) shift; textra="$textra $1"; shift ;;
102 -v | --vers* )
103 echo "$progname (Texinfo 3.9) $version"
104 echo "Copyright (C) 1996 Free Software Foundation, Inc.
105 There is NO warranty. You may redistribute this software
106 under the terms of the GNU General Public License.
107 For more information about these matters, see the files named COPYING."
108 exit 0 ;;
109 --verb* ) verbose=echo; shift ;;
110 -- ) # Stop option processing
111 shift
112 break
113 ;;
114 -* )
115 case "$1" in
116 --*=* ) arg=`echo "$1" | sed -e 's/=.*//'` ;;
117 * ) arg="$1" ;;
118 esac
119 exec 1>&2
120 echo "$progname: Unknown or ambiguous option $bq$arg$eq."
121 echo "$progname: Try $bq--help$eq for more information."
122 exit 1
123 ;;
124 * )
125 break
126 ;;
127 esac
128 done
129
130 # See if there are any command line args left (which will be interpreted as
131 # filename arguments).
132 if test $# -eq 0; then
133 exec 1>&2
134 echo "$progname: At least one file name is required as an argument."
135 echo "$progname: Try $bq--help$eq for more information."
136 exit 2
137 fi
138
139 test "$debug" = t && set -x
140
141 # Texify files
142 for command_line_filename in ${1+"$@"} ; do
143 $verbose "Processing $command_line_filename ..."
144
145 # See if file exists. If it doesn't we're in trouble since, even
146 # though the user may be able to reenter a valid filename at the tex
147 # prompt (assuming they're attending the terminal), this script won't
148 # be able to find the right index files and so forth.
149 if test ! -r "${command_line_filename}" ; then
150 echo "$0: Could not read ${command_line_filename}." >&2
151 continue
152 fi
153
154 # Roughly equivalent to `dirname ...`, but more portable
155 directory="`echo ${command_line_filename} | sed 's/\/[^\/]*$//'`"
156 filename_texi="`basename ${command_line_filename}`"
157 # Strip off the last extension part (probably .texinfo or .texi)
158 filename_noext="`echo ${filename_texi} | sed 's/\.[^.]*$//'`"
159
160 # Use same basename since we want to generate aux files with the same
161 # basename as the manual. Use extension .texi for the temp file so
162 # that TeX will ignore it. Thus, we must use a subdirectory.
163 #
164 # Output the macro-expanded file to here.
165 tmp_dir=${TMPDIR-/tmp}/$$
166 filename_tmp=$tmp_dir/$filename_noext.texi
167 # Output the file with the user's extra commands to here.
168 filename_tmp2=$tmp_dir.2/$filename_noext.texi
169 mkdir $tmp_dir $tmp_dir.2
170
171 # If directory and file are the same, then it's probably because there's
172 # no pathname component. Set dirname to `.', the current directory.
173 if test "z${directory}" = "z${command_line_filename}" ; then
174 directory=.
175 fi
176
177 # Source file might @include additional texinfo sources. Put `.' and
178 # directory where source file(s) reside in TEXINPUTS before anything
179 # else. `.' goes first to ensure that any old .aux, .cps, etc. files in
180 # ${directory} don't get used in preference to fresher files in `.'.
181 TEXINPUTS=".:${directory}:${TEXINPUTS_orig}"
182 makeinfo_inputs="-I `echo $TEXINPUTS | sed 's,:, -I ,g'`"
183
184 # Expand macro commands in the original source file using Makeinfo;
185 # the macro syntax bfox implemented is impossible to implement in TeX.
186 # Always use `end' footnote style, since the `separate' style
187 # generates different output (arguably this is a bug in -E).
188 # Discard main info output, the user asked to run TeX, not makeinfo.
189 # Redirect output to /dev/null to throw away `Making info file...' msg.
190 $verbose "Macro-expanding $command_line_filename to $filename_tmp ..."
191 $makeinfo --footnote-style=end -E $filename_tmp -o /dev/null \
192 $command_line_filename >/dev/null
193
194 # But if there were no macros, or makeinfo failed for some reason,
195 # just use the original file. (It shouldn't make any difference, but
196 # let's be safe.)
197 if test $? -ne 0 || cmp -s $filename_tmp $command_line_filename; then
198 $verbose "Reverting to $command_line_filename ..."
199 filename_input=$command_line_filename
200 else
201 filename_input=$filename_tmp
202 fi
203
204 # Used most commonly for @finalout, @smallbook, etc.
205 if test -n "$textra"; then
206 $verbose "Inserting extra commands: $textra."
207 sed '/^@setfilename/a\
208 '"$textra" $filename_input >$filename_tmp2
209 filename_input=$filename_tmp2
210 fi
211
212 while true; do # will break out of loop below
213 # "Unset" variables that might have values from previous iterations and
214 # which won't be completely reset later.
215 definite_index_files=
216
217 # Find all files having root filename with a two-letter extension,
218 # determine whether they're really index files, and save them. Foo.aux
219 # is actually the cross-references file, but we need to keep track of
220 # that too.
221 possible_index_files="`eval echo ${filename_noext}.?? ${filename_noext}.aux`"
222 for this_file in ${possible_index_files} ; do
223 # If file is empty, forget it.
224 test -s "${this_file}" || continue
225
226 # Examine first character of file. If it's not suitable to be an
227 # index or xref file, don't process it.
228 first_character="`sed -n '1s/^\(.\).*$/\1/p;q' ${this_file}`"
229 if test "x${first_character}" = "x\\" \
230 || test "x${first_character}" = "x'"; then
231 definite_index_files="${definite_index_files} ${this_file}"
232 fi
233 done
234 orig_index_files="${definite_index_files}"
235 orig_index_files_sans_aux="`echo ${definite_index_files} \
236 | sed 's/'${filename_noext}'\.aux//;
237 s/^[ ]*//;s/[ ]*$//;'`"
238
239 # Now save copies of original index files so we have some means of
240 # comparison later.
241 $verbose "Backing up current index files: $orig_index_files ..."
242 for index_file_to_save in ${orig_index_files} ; do
243 cp "${index_file_to_save}" "${index_file_to_save}${backup_extension}"
244 done
245
246 # Run texindex on current index files. If they already exist, and
247 # after running TeX a first time the index files don't change, then
248 # there's no reason to run TeX again. But we won't know that if the
249 # index files are out of date or nonexistent.
250 if test -n "${orig_index_files_sans_aux}" ; then
251 $verbose "Running $texindex $orig_index_files_sans_aux ..."
252 ${texindex} ${orig_index_files_sans_aux}
253 fi
254
255 # Finally, run TeX.
256 $verbose "Running $tex $filename_input ..."
257 ${tex} "$filename_input"
258
259 # Check if index files changed.
260 #
261 definite_index_files=
262 # Get list of new index files.
263 possible_index_files="`eval echo ${filename_noext}.?? ${filename_noext}.aux`"
264 for this_file in ${possible_index_files} ; do
265 # If file is empty, forget it.
266 test -s "${this_file}" || continue
267
268 # Examine first character of file. If it's not a backslash or
269 # single quote, then it's definitely not an index or xref file.
270 # (Will have to check for @ when we switch to Texinfo syntax in
271 # all these files...)
272 first_character="`sed -n '1s/^\(.\).*$/\1/p;q' ${this_file}`"
273 if test "x${first_character}" = "x\\" \
274 || test "x${first_character}" = "x'"; then
275 definite_index_files="${definite_index_files} ${this_file}"
276 fi
277 done
278 new_index_files="${definite_index_files}"
279 new_index_files_sans_aux="`echo ${definite_index_files} \
280 | sed 's/'${filename_noext}'\.aux//;
281 s/^[ ]*//;s/[ ]*$//;'`"
282
283 # If old and new list don't at least have the same file list, then one
284 # file or another has definitely changed.
285 $verbose "Original index files =$orig_index_files"
286 $verbose "New index files =$new_index_files"
287 if test "z${orig_index_files}" != "z${new_index_files}" ; then
288 index_files_changed_p=t
289 else
290 # File list is the same. We must compare each file until we find a
291 # difference.
292 index_files_changed_p=
293 for this_file in ${new_index_files} ; do
294 $verbose "Comparing index file $this_file ..."
295 # cmp -s will return nonzero exit status if files differ.
296 cmp -s "${this_file}" "${this_file}${backup_extension}"
297 if test $? -ne 0 ; then
298 # We only need to keep comparing until we find *one* that
299 # differs, because we'll have to run texindex & tex no
300 # matter what.
301 index_files_changed_p=t
302 $verbose "Index file $this_file differed:"
303 test $verbose = echo \
304 && diff -c "${this_file}${backup_extension}" "${this_file}"
305 break
306 fi
307 done
308 fi
309
310 # If index files have changed since TeX has been run, or if the aux
311 # file wasn't present originally, run texindex and TeX again.
312 if test "${index_files_changed_p}" ; then :; else
313 # Nothing changed. We're done with TeX.
314 break
315 fi
316 done
317
318 # Generate list of files to delete, then call rm once with the entire
319 # list. This is significantly faster than multiple executions of rm.
320 file_list=
321 for file in ${orig_index_files} ; do
322 file_list="${file_list} ${file}${backup_extension}"
323 done
324 if test -n "${file_list}" ; then
325 $verbose "Removing $file_list $tmp_dir $tmp_dir.2 ..."
326 rm -f ${file_list}
327 rm -rf $tmp_dir $tmp_dir.2
328 fi
329 done
330
331 $verbose "$0 done."
332 true # exit successfully.
333
334 # texi2dvi ends here
335 # $Log: texi2dvi,v $
336 # Revision 1.1 1996-11-14 20:42:03 jwe
337 # *** empty log message ***
338 #
339 # Revision 1.10 1996/10/04 18:21:55 karl
340 # Include only the current year in the copyright message.
341 #
342 # Revision 1.9 1996/10/04 11:49:48 karl
343 # Exit successfully. From arnold.
344 #
345 # Revision 1.8 1996/10/03 23:14:26 karl
346 # Only show diff if verbose.
347 # Update version number.
348 #
349 # Revision 1.7 1996/09/29 22:56:08 karl
350 # Use $progname instead of $0 for --version.
351 #
352 # Revision 1.6 1996/09/28 21:01:23 karl
353 # Recompute original index files each time through loop.
354 # Make indentation uniform.
355 # Use same basename for the temp input files.
356 # Standardize --version output.
357 #
358 # Revision 1.5 1996/09/26 14:46:34 karl
359 # (texi2dvi): Run TeX until the aux/index files stabilize, instead of just
360 # twice. From: David Shaw <daves@gsms01.alcatel.com.au>.
361 #
362 # Revision 1.4 1996/08/27 18:59:26 karl
363 # Include bug reporting address.
364 #
365 # Revision 1.3 1996/07/26 18:20:56 karl
366 # Do macro expansion with makeinfo before running TeX.
367 # Various expansion safety measures added for test; avoid use of -o.
368 #