Index: texi2dvi =================================================================== --- texi2dvi (revision 6578) +++ texi2dvi (working copy) @@ -51,7 +51,6 @@ # Instead, assign them an empty value. action=compile batch=false # interact normally -catcode_special=maybe debug=false escape="\\" expand=false # true for expansion via makeinfo @@ -691,9 +690,37 @@ } -# 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.fls"; then + grep '^OUTPUT ' "$1.fls" \ + | cut -b 8- + fi + echo "$1.fls" +} + +# +# 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 @@ -703,17 +730,9 @@ # 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" + # generated_files_get_method is a variable set to one of + # generated_files_get_from_log and generated_files_get_from_fls. + $generated_files_get_method "$1" ) | # Depending on these files, infer outputs from other tools. while read file; do @@ -814,11 +833,10 @@ 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 +894,11 @@ 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" @@ -913,7 +936,14 @@ # 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 () +{ + test x$catcode_special = xfalse || catcode_special=maybe + 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 @@ -1401,7 +1431,126 @@ run_tex_suite } +# +make_openout_test() +{ + ensure_dir $workdir/check_recorder + pushd $workdir/check_recorder > /dev/null + 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 +1946,9 @@ # 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.