Index: texi2dvi =================================================================== --- texi2dvi (revision 6578) +++ texi2dvi (working copy) @@ -508,7 +508,7 @@ out_lang_ext () # # absolute_filenames TEX-PATH -> TEX-PATH - Convert relative paths to # absolute, so we can run in another directory (e.g., in tidy build -# mode, or during the macro-support detection). Prepend ".$path_sep". +# mode, or during the macro-support detection). absolute_filenames () { # Empty path components are meaningful to tex. We rewrite them as @@ -521,25 +521,27 @@ absolute_filenames () save_IFS=$IFS IFS=$path_sep set x $af_result; shift - af_result=. + af_result= + af_path_sep= for dir do case $dir in EMPTY) - af_result=$af_result$path_sep + af_result=$af_result$af_path_sep ;; *) if test -d "$dir"; then - af_result=$af_result$path_sep`absolute "$dir"` + af_result=$af_result$af_path_sep`absolute "$dir"` else # Even if $dir is not a directory, preserve it in the path. # It might contain metacharacters that TeX will expand in # turn, e.g., /some/path/{a,b,c}. This will not get the # implicit absolutification of the path, but we can't help that. - af_result=$af_result$path_sep$dir + af_result=$af_result$af_path_sep$dir fi ;; esac + af_path_sep=$path_sep done echo "$af_result" } @@ -691,9 +693,37 @@ xref_file_p () } -# generated_files_get FILENAME-NOEXT [PREDICATE-FILTER] - Return the +# Used in generated_files_get +generated_files_get_from_log () +{ + if test -f "$1.log"; then + # Usually the output is like: \openout1 = `foobar.tex'. + # (including the final period) + # but luatex outputs: \openout1 = foobar.tex + # (no quotes, no period). + # So we have to make the punctuation optional. + grep '^\\openout[0-9]' "$1.log" \ + | $SED -e "s/\\\\openout[^=]*= *[\`']*//" \ + -e "s/'\.$//" + fi + echo "$1.log" +} + +# Used in generated_files_get +generated_files_get_from_fls () +{ + if test -f "$1.flz"; then + grep '^OUTPUT ' "$1.flz" \ + | cut -b 8- + fi + echo "$1.flz" +} + +# +# generated_files_get FILENAME-NOEXT [PREDICATE-FILTER] - Output the # list of files generated by the TeX compilation of FILENAME-NOEXT, # filtered by (piped through) PREDICATE-FILTER if specified. + generated_files_get () { gfg_filter=true @@ -702,20 +732,8 @@ generated_files_get () fi # Gather the files created by TeX. - ( - if test -f "$1.log"; then - # Usually the output is like: \openout1 = `foobar.tex'. - # (including the final period) - # but luatex outputs: \openout1 = foobar.tex - # (no quotes, no period). - # So we have to make the punctuation optional. - grep '^\\openout[0-9]' "$1.log" \ - | $SED -e "s/\\\\openout[^=]*= *[\`']*//" \ - -e "s/'\.$//" - fi - echo "$1.log" - ) | # Depending on these files, infer outputs from other tools. + $generated_files_get_method "$1" | while read file; do echo $file case $in_lang in @@ -752,7 +770,7 @@ generated_files_get () } -# xref_files_save - Save xref files in $work_bak with tar. +# xref_files_save - Save xref files in $work_bak, and set xref_files_orig. xref_files_save () { # Save copies of auxiliary files for later comparison. @@ -814,11 +832,10 @@ xref_files_changed () return 1 } - # Running the TeX suite. # -# run_tex - Run TeX as "$tex $in_input", taking care of errors and logs. -run_tex () +# Set tex_cmd variable, for running TeX. +make_tex_cmd () { case $in_lang:$latex2html:`out_lang_tex` in latex:*:dvi|latex:tex4ht:html) @@ -876,6 +893,11 @@ xref_files_changed () esac fi + # Tell TeX about -recorder option, if specified + # recorder_option_maybe is in { " -recorder", "" } + tex_cmd="$tex_cmd$recorder_option_maybe" + + # Tell TeX about TCX file, if specified. test -n "$translate_file" \ && tex_cmd="$tex_cmd --translate-file=$translate_file" @@ -898,7 +920,6 @@ xref_files_changed () # we'd like to handle arbitrary input file names, especially # foo~bar/a~b.tex, since Debian likes ~ characters. if $catcode_special; then - # $normaltilde is just to reduce line length in this source file. # The idea is to define \normaltilde as a catcode other ~ character, # then make the active ~ be equivalent to that, instead of the plain # TeX tie. Then when the active ~ appears in the filename, it will @@ -913,7 +934,13 @@ xref_files_changed () # append the \input command. tex_cmd="$tex_cmd '${escape}input'" +} +# run_tex - Run TeX as "$tex $in_input", taking care of errors and logs. +run_tex () +{ + make_tex_cmd + # TeX's \input does not (easily or reliably) support whitespace # characters or other special characters in file names. Our intensive # use of absolute file names makes this worse: the enclosing directory @@ -1130,12 +1157,16 @@ run_tex_suite () xref_files_save - # We run bibtex first, because it's more likely for the indexes + run_core_conversion + + # We ran the conversion before making the sorted index files + # because otherwise a sorted *.fls file (for an index `fl') could + # be overwritten by a *.fls file produced with --recorder. + # We run bibtex first, because it's more likely for the indexes # to change after bibtex is run than the reverse, though either # would be rare. run_bibtex run_index - run_core_conversion xref_files_changed || break done @@ -1359,6 +1390,7 @@ run_core_conversion () *) error 1 "invalid input/output combination: $in_lang/$out_lang";; esac + test -f "$in_noext.fls" && mv "$in_noext.fls" "$in_noext.flz" } @@ -1366,17 +1398,20 @@ run_core_conversion () # installation of the output at its expected location. compile () { - # Source file might include additional sources. - # We want `.:$orig_pwd' before anything else. (We'll add `.:' later - # after all other directories have been turned into absolute paths.) - # `.' goes first to ensure that any old .aux, .cps, - # etc. files in ${directory} don't get used in preference to fresher - # files in `.'. Include orig_pwd in case we are in clean build mode, where - # we have cd'd to a temp directory. - common="$orig_pwd$path_sep$in_dir$path_sep" + # Set include path for tools: + # . Include work_bak so we can use a sorted FILE.fls index file there + # while still writing to FILE.fls if using --recorder. + # . Include current directory in case there are files there already, so + # we don't have more TeX runs than necessary. orig_pwd is used in case + # we are in clean build mode, where we have cd'd to a temp directory. + # . Include directory containing file, in case there are other + # files @include'd. + # . Keep a final path_sep to get the default (system) TeX + # directories included. + # . If we have any includes, put those at the end. + + common="$work_bak$path_sep$orig_pwd$path_sep$in_dir$path_sep" # - # If we have any includes, put those at the end. - # Keep a final path_sep to get the default (system) TeX directories included. txincludes=`list_infix includes $path_sep` test -n "$txincludes" && common="$common$txincludes$path_sep" # @@ -1384,7 +1419,7 @@ compile () eval val="\$common\$${var}_orig" # Convert relative paths to absolute paths, so we can run in another # directory (e.g., in clean build mode, or during the macro-support - # detection). ".:" is added here. + # detection). val=`absolute_filenames "$val"` eval $var="\"$val\"" export $var @@ -1401,7 +1436,125 @@ compile () run_tex_suite } +# +make_openout_test () +{ + ensure_dir $workdir/check_recorder + cd $workdir/check_recorder + cat > openout.tex < /dev/null 2>&1 +} +# Check tex supports -recorder option +check_recorder_support () +{ + verbose "Checking TeX recorder support..." + make_openout_test " -recorder" fls + if test -f openout.fls && grep '^OUTPUT dum.dum$' openout.fls > /dev/null + then + cd_orig + verbose "Checking TeX recorder support... yes" + return 0 + else + cd_orig + verbose "Checking TeX recorder support... no" + return 1 + fi +} + +# Check tex supports \openout traces in log +check_openout_in_log_support () +{ + verbose "Checking TeX \openout in log support..." + make_openout_test "" log + if test -f openout.log \ + && grep '^\\openout0 *= *`\?dum\.dum'\''\?' openout.log + then + cd_orig + verbose "Checking TeX \openout in log support... yes" + return 0 + else + cd_orig + verbose "Checking TeX \openout in log support... no" + return 1 + fi +} + +# Set that output auxiliary files are detected with the -recorder option, +# which creates a file JOBNAME.fls which is a machine-readable listing of +# files read and written during the job. +set_aux_files_from_fls () +{ + recorder_option_maybe=" -recorder" + generated_files_get_method=generated_files_get_from_fls +} + +# Set that output auxiliary files are detected with searching for \openout +# in the log file. +set_aux_files_from_log () +{ + recorder_option_maybe='' + generated_files_get_method=generated_files_get_from_log +} + +# Decide whether output auxiliary files are detected with the -recorder +# option, or by searching for \openout in the log file. +decide_aux_files_method () +{ + # Select output file detection method + # Valid values of TEXI2DVI_USE_RECORDER are: + # yes use the -recorder option, no checks. + # no scan for \openout in the log file, no checks. + # yesmaybe check whether -recorder option is supported, and if yes + # use it, otherwise check for tracing \openout in the + # log file is supported, and if yes use it, else it is an + # error. + # nomaybe same as `yesmaybe', except that the \openout trace in + # log file is checked first. + # + # The default behaviour is `nomaybe'. + + test -n "$TEXI2DVI_USE_RECORDER" || TEXI2DVI_USE_RECORDER=yesmaybe + + case $TEXI2DVI_USE_RECORDER in + yes) set_aux_files_from_fls;; + + no) set_aux_files_from_log;; + + yesmaybe) + if check_recorder_support; then + set_aux_files_from_fls + elif check_openout_in_log_support; then + set_aux_files_from_log + else + error 1 "TeX neither supports -recorder nor outputs \\openout lines in its log file" + fi + ;; + + nomaybe) + if check_openout_in_log_support; then + set_aux_files_from_log + elif check_recorder_support; then + set_aux_files_from_fls + else + error 1 "TeX neither supports -recorder nor outputs \\openout lines in its log file" + fi + ;; + + *) error 1 "Invalid value of TEXI2DVI_USE_RECORDER environment variable : $TEXI2DVI_USE_RECORDER.";; + + esac +} + # remove FILE... remove () { @@ -1797,6 +1950,9 @@ do # Make those directories. ensure_dir "$work_build" "$work_bak" + # Decide how to find auxiliary files created by TeX. + decide_aux_files_method + case $action in compile) # Compile the document. @@ -1812,3 +1968,7 @@ done verbose "done." exit 0 # exit successfully, not however we ended the loop. +# Local Variables: +# sh-basic-offset: 2 +# sh-indentation: 2 +# End: