On 2 May 2016 at 20:53, Gavin Smith <[email protected]> wrote:
> I've been working on a patch to avoid the use of absolute paths
> altogether, but it isn't done yet.

Here's what I have so far. It needs more testing and scrutiny, though.
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 7143)
+++ ChangeLog	(working copy)
@@ -1,3 +1,29 @@
+2016-05-03  Gavin Smith  <[email protected]>
+
+	* util/texi2dvi (cd_dir): New function, to change directory
+	while updating variables containing paths.
+	(cd_orig): Reverse the changes to these variables made in cd_dir.
+
+	(run_tex_suite, make_openout_test): Use 'cd_dir' instead of 
+	'cd'.
+
+	(input_file_name_decode, main program loop, cleanup): Don't 
+	change variables t2ddir, in_dir to be absolute.  This could 
+	cause problems if the absolute path to the input file contained 
+	a space.  (Problem found following report by Stephen Dawson.)
+
+	(run_tex) [--tidy]: Remove code that uses a symbolic link to the 
+	file being processed.  This meant that --command didn't work 
+	along with --tidy due to the path to the file with the inserted 
+	commands being overridden.  It is less necessary when absolute 
+	paths aren't used.  (Problem found following report by
+	Guo Yixuan).
+
+	(cleanup): Refer to 'clean' and 'tidy' variables instead of 
+	'build_mode'.  (No functional change.)
+	(compile): Change a comment.
+
+
 2016-05-01  Gavin Smith  <[email protected]>
 
 	* util/texi2dvi (usage): Streamline help message.  Don't mention 
Index: util/texi2dvi
===================================================================
--- util/texi2dvi	(revision 7143)
+++ util/texi2dvi	(working copy)
@@ -233,6 +233,37 @@ EOF
 
 #  Generic auxiliary functions.
 
+# List of variables containing paths to directories or files that
+# we need to update.
+path_vars='work_build workdir t2ddir work_bak in_input'
+
+# Change directory, updating some relative paths.
+cd_dir ()
+{
+  cd "$1"
+  # Replace each path component with ".." and remove any trailing slash.
+  cdd_prefix=`echo "$1" | sed -e 's/[^/\\]\+/../g' -e 's/[/\\]$//'`
+
+  # Add this prefix for some variables.
+  for cdd_dir in $path_vars; do
+    eval "case \"$$cdd_dir\" in
+          [\\/]* | ?:[\\/]*) ;;  # absolute path - do nothing
+          ?*)
+             eval \"\$cdd_dir=\$cdd_prefix/\\\$\$cdd_dir\" ;;
+          esac"
+    # Without first level of quotes, where CDD_DIR is $cdd_dir:
+    #      case "$CDD_DIR" in
+    #      [\\/]* | ?:[\\/]*) ;;
+    #      *)
+    #         eval "$cdd_dir=$cdd_prefix/\$$cdd_dir" ;;
+    #      esac
+    #
+    # Inner 'eval' becomes
+    #     CDD_DIR=CDD_PREFIX/$CDD_DIR
+    # where CDD_DIR is $cdd_dir and CDD_PREFIX is $cdd_prefix
+  done
+}
+
 # cd_orig - Return to the original directory.
 cd_orig ()
 {
@@ -243,6 +274,11 @@ cd_orig ()
   # - the next file is processed in correct conditions
   # - the temporary file can be removed
   cd "$orig_pwd" || exit 1
+  
+  # strip off ../../ from some variables
+  for cdo_dir in $path_vars ; do
+    eval $cdo_dir=\${$cdo_dir#\$cdd_prefix/}
+  done
 }
 
 
@@ -890,34 +926,7 @@ 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
-  # names may include white spaces.  Improve the situation using a
-  # symbolic link to the filename in the current directory, in tidy mode
-  # only.  Do not alter in_input.
-  #
-  # The filename is almost always tokenized using plain TeX conventions
-  # (the exception would be if the user made a texinfo.fmt file).  Not
-  # all the plain TeX special characters cause trouble, but there's no
-  # harm in making the link.
-  #
-  case $tidy:`func_dirname "$in_input"` in
-    true:*["$space$tab$newline\"#\$%\\^_{}~"]*)
-      _run_tex_file_name=`basename "$in_input"`
-      if test ! -f "$_run_tex_file_name"; then
-        # It might not be a file, clear it.
-        run rm -f "$_run_tex_file_name"
-        run ln -s "$in_input"
-      fi
-      tex_cmd="$tex_cmd '$_run_tex_file_name'"
-      ;;
-
-    *)
-      tex_cmd="$tex_cmd '$in_input'"
-      ;;
-  esac
-
+  tex_cmd="$tex_cmd '$in_input'"
   verbose "$0: Running $tex_cmd ..."
   if eval "$tex_cmd" >&5; then
     case $out_lang in
@@ -1103,7 +1112,7 @@ run_tex_suite ()
   # Move to the working directory.
   if $tidy; then
     verbose "cd $work_build"
-    cd "$work_build" || exit 1
+    cd_dir "$work_build" || exit 1
   fi
 
   # Count the number of cycles.
@@ -1448,7 +1457,7 @@ compile ()
   # --command, --texinfo
   insert_commands
 
-  # Run until a fix point is reached.
+  # Run until a fixed point is reached.
   run_tex_suite
 }
 
@@ -1458,7 +1467,7 @@ compile ()
 make_openout_test ()
 {
     ensure_dir "$workdir"/check_recorder
-    cd "$workdir"/check_recorder
+    cd_dir "$workdir"/check_recorder
     cat > openout.tex <<EOF
 \newwrite\ourwrite
 \immediate\openout\ourwrite dum.dum
@@ -1642,10 +1651,9 @@ mostly_clean ()
 # the script.  Changes the current directory.
 cleanup ()
 {
-  case $build_mode in
-    local) cd_orig; remove "$t2ddir";;
-    clean) mostly_clean;;
-    tidy)  ;;
+  case $clean:$tidy in
+    true:false) mostly_clean ;;               # build mode is "clean"
+    false:false) cd_orig; remove "$t2ddir";;  # build mode is "local"
   esac
 }
 
@@ -1656,7 +1664,7 @@ cleanup ()
 # - COMMAND_LINE_FILENAME
 #   The filename given on the commmand line, but cleaned of TeX commands.
 # - IN_DIR
-#   The directory containing the input file, possibly absolute if needed.
+#   The directory containing the input file.
 # - IN_DIR_ABS
 #   The absolute directory of the input file.
 # - IN_BASE
@@ -1699,10 +1707,6 @@ input_file_name_decode ()
   # Get the name of the current directory.
   in_dir=`func_dirname "$command_line_filename"`
   in_dir_abs=`absolute "$in_dir"`
-  # In a clean build, we `cd', so get an absolute file name.
-  if $tidy; then
-    in_dir=$in_dir_abs
-  fi
 
   # Strip directory part but leave extension.
   in_base=`basename "$command_line_filename"`
@@ -1938,8 +1942,6 @@ do
 
   ensure_dir "$build_dir" "$t2ddir"
 
-  # We will change directory, better work with an absolute path...
-  t2ddir=`absolute "$t2ddir"`
   # Sometimes there are incompatibilities between auxiliary files for
   # DVI and PDF.  The contents can also change whether we work on PDF
   # and/or DVI.  So keep separate spaces for each.

Reply via email to