bug-texinfo
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

texi2dvi: Factor some code


From: Akim Demaille
Subject: texi2dvi: Factor some code
Date: Mon, 19 Dec 2005 18:00:02 +0100
User-agent: Gnus/5.110004 (No Gnus v0.4) Emacs/21.4 (gnu/linux)

Minor details.  The most interesting thing is that I realized that the
log contains the list of the auxiliary files!  That's valuable information!

2005-12-19  Akim Demaille  <address@hidden>

        * util/texi2dvi (run_conversion): Rename as...
        (run_core_conversion): this.
        (compile): New.
        This is the former main program.
        (clean): New.
        Use it.
        (language): Compute it in the main loop.


Index: doc/texi2dvi.1
===================================================================
RCS file: /cvsroot/texinfo/texinfo/doc/texi2dvi.1,v
retrieving revision 1.43
diff -u -u -r1.43 texi2dvi.1
--- doc/texi2dvi.1 12 Dec 2005 13:57:44 -0000 1.43
+++ doc/texi2dvi.1 19 Dec 2005 16:58:36 -0000
@@ -1,4 +1,4 @@
-.\" DO NOT MODIFY THIS FILE!  It was generated by help2man 1.35.
+.\" DO NOT MODIFY THIS FILE!  It was generated by help2man 1.36.
 .TH TEXI2DVI "1" "December 2005" "texi2dvi 1.67" "User Commands"
 .SH NAME
 texi2dvi \- convert Texinfo documents to DVI
@@ -77,7 +77,7 @@
 .SS "Build modes:"
 .TP
 \fB\-\-build\fR=\fIMODE\fR
-specify the treatment of auxiliary files [local]
+specify the treatment of auxiliary files [tidy]
 .TP
 \fB\-\-tidy\fR
 same as \fB\-\-build\fR=\fItidy\fR
@@ -88,7 +88,7 @@
 \fB\-\-build\-dir\fR=\fIDIR\fR
 specify where the tidy compilation is performed.
 implies \fB\-\-tidy\fR
-defaults to TEXI2DVI_BUILD_DIRECTORY [.]
+defaults to TEXI2DVI_BUILD_DIRECTORY [/tmp/akim.t2d]
 .PP
 The MODE specifies where the TeX compilation takes place, and, as a
 consequence, how auxiliary files are treated.  The build mode
@@ -120,7 +120,7 @@
 .IP
 \- clutter can be reduced to zero using \fB\-\-build\-dir=\fR/tmp/$USER.t2d or
 .HP
-\fB\-\-build\-dir=\fR/u/karl/.t2d.
+\fB\-\-build\-dir=\fR/home/akim/.t2d.
 .IP
 \- the output file is updated after every succesful TeX run, for
 .TP
Index: util/texi2dvi
===================================================================
RCS file: /cvsroot/texinfo/texinfo/util/texi2dvi,v
retrieving revision 1.67
diff -u -u -r1.67 texi2dvi
--- util/texi2dvi 18 Nov 2005 12:58:50 -0000 1.67
+++ util/texi2dvi 19 Dec 2005 16:58:36 -0000
@@ -349,7 +349,6 @@
   done
   set X $ld_res; shift
   eval $ld_l=\"address@hidden"
-  eval echo $ld_l=\$$ld_l
 }
 
 ## ------------------------- ##
@@ -951,10 +950,10 @@
 }
 
 
-# run_conversion ()
-# -----------------
+# run_core_conversion ()
+# ----------------------
 # Run the TeX tools until a fix point is reached.
-run_conversion ()
+run_core_conversion ()
 {
   # Move to the working directory.
   if $tidy; then
@@ -976,6 +975,77 @@
   cd "$orig_pwd" || exit 1
 }
 
+
+# compile ()
+# ----------
+# Run the full compilation chain, from pre-processing to 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've cd'd to a temp directory.
+  txincludes=`list_infix includes $path_sep`
+  common="$orig_pwd$path_sep$in_dir$path_sep$txincludes$path_sep"
+  for var in $tex_envvars; do
+    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).
+    val=`absolute_filenames "$val"`
+    eval $var="$val"
+    eval export $var
+    eval verbose "$var=\'\$${var}\'"
+  done
+
+  # --expand
+  run_makeinfo
+
+  # --command, --texinfo
+  insert_commands
+
+  # --recode
+  run_recode
+
+  # Run until a fix point is reached.
+  run_core_conversion
+}
+
+
+# clean ()
+# --------
+# Remove auxiliary files.
+clean ()
+{
+  # In case $orig_pwd is on a different drive (for DOS).
+  cd /
+
+  # Return to the original directory so that
+  # - the next file is processed in correct conditions
+  # - the temporary file can be removed
+  cd "$orig_pwd" || exit 1
+
+  if $tidy; then
+    # Simply remove the build dir.
+    verbose "Removing $t2ddir"
+    rm -rf "$t2ddir"
+  else
+    # Find the auxiliary files, and remove them.
+    local log=$work_build/$in_noext.log
+    if test -f "$log"; then
+      local aux=$(sed -n "s,^\\\\openout.* = \`\\(.*\\)'\\.,$work_build/\\1,p" 
"$log")
+      cp $work_build/$in_noext.log /tmp
+      echo rm $aux
+    fi
+  fi
+}
+
+
+
 ## ---------------------- ##
 ## Command line parsing.  ##
 ## ---------------------- ##
@@ -1225,6 +1295,9 @@
 
   input_file_name_decode
 
+  # `texinfo' or `latex'?
+  language=`compute_language $command_line_filename`
+
   # An auxiliary directory used for all the auxiliary tasks involved
   # in compiling this document.
   case $build_dir in
@@ -1235,7 +1308,7 @@
   esac
   # Remove it at exit if clean mode.
   $clean &&
-    trap "cd / && rm -rf $t2ddir" 0 1 2 15
+    trap "clean" 0 1 2 15
 
   ensure_dir "$build_dir" "$t2ddir"
 
@@ -1261,46 +1334,11 @@
   # Make those directories.
   ensure_dir "$work_build" "$work_bak"
 
-  # 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've cd'd to a temp directory.
-  txincludes=`list_infix includes $path_sep`
-  common="$orig_pwd$path_sep$in_dir$path_sep$txincludes$path_sep"
-  for var in $tex_envvars; do
-    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).
-    val=`absolute_filenames "$val"`
-    eval $var="$val"
-    eval export $var
-    eval verbose "$var=\'\$${var}\'"
-  done
-
-  # `texinfo' or `latex'?
-  language=`compute_language $command_line_filename`
-
-  # --expand
-  run_makeinfo
-
-  # --command, --texinfo
-  insert_commands
-
-  # --recode
-  run_recode
-
-  # Run until a fix point is reached.
-  run_conversion
+  # Compile the document.
+  compile
 
   # Remove temporary files.
-  if $clean; then
-    verbose "Removing $t2ddir"
-    rm -rf "$t2ddir"
-  fi
+  $clean && clean
 done
 
 verbose "done."





reply via email to

[Prev in Thread] Current Thread [Next in Thread]