octave-maintainers
[Top][All Lists]
Advanced

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

Re: Problems with spaces in filenames of external programs (gnuplot, le


From: Benjamin Lindner
Subject: Re: Problems with spaces in filenames of external programs (gnuplot, less)
Date: Tue, 30 Sep 2008 19:37:02 +0200
User-agent: Thunderbird 2.0.0.14 (Windows/20080421)


Benjamin Lindner wrote:
2) Ensure that all instances of pipe-opening or program execution quote the respective file name. I find here with respect of gnuplot the following two immediatly required changes: __gnuplot_version__.m and drawnow.m. Additionally the C++ code for the "help" function must be changed to quote the pager's executable file name.


I digged into the code, and the fix is quite simple.
Please consider the attached patches for ensuring correct quoting of gnuplot_binary() and PAGER


2008-09-30  Benjamin Lindner  <address@hidden>

        * __gnuplot_version__.m, drawnow.m : quote gnuplot_binary
        executable name
        * pager.cc : quote PAGER executable name


benjamin

diff -urN -x '*.bak' -x configure -x config.h.in -x '*~' 
octave-3.0.2-orig/scripts/plot/__gnuplot_version__.m 
octave-3.0.2/scripts/plot/__gnuplot_version__.m
--- octave-3.0.2-orig/scripts/plot/__gnuplot_version__.m        2008-08-01 
08:50:56 +0200
+++ octave-3.0.2/scripts/plot/__gnuplot_version__.m     2008-09-29 19:39:30 
+0200
@@ -27,7 +27,7 @@
   persistent __version__ = "";
 
   if (isempty (__version__))
-    [status, output] = system (sprintf ("%s --version", gnuplot_binary ()));
+    [status, output] = system (sprintf ("\"%s\" --version", gnuplot_binary 
()));
     if (status != 0)
       ## This message ends in a newline so that the traceback messages
       ## are skipped and people might actually see the message, read it,
diff -urN  -x '*.bak' -x configure -x config.h.in -x '*~' 
octave-3.0.2-orig/scripts/plot/drawnow.m octave-3.0.2/scripts/plot/drawnow.m
--- octave-3.0.2-orig/scripts/plot/drawnow.m    2008-08-01 08:50:56 +0200
+++ octave-3.0.2/scripts/plot/drawnow.m 2008-09-29 19:39:53 +0200
@@ -116,7 +116,7 @@
 
   cmd = gnuplot_binary ();
 
-  plot_stream = popen (cmd, "w");
+  plot_stream = popen (["\"",cmd,"\""], "w");
 
   if (plot_stream < 0)
     error ("drawnow: failed to open connection to gnuplot");
diff -urN -x '*.bak' -x configure -x config.h.in -x '*~' 
octave-3.0.2-orig/src/pager.cc octave-3.0.2/src/pager.cc
--- octave-3.0.2-orig/src/pager.cc      2008-08-01 08:50:56 +0200
+++ octave-3.0.2/src/pager.cc   2008-09-30 19:34:52 +0200
@@ -131,11 +131,40 @@
 static std::string
 pager_command (void)
 {
-  std::string cmd = VPAGER;
+  std::string cmd = "\"" + VPAGER + "\"";
 
   if (! (cmd.empty () || VPAGER_FLAGS.empty ()))
+  {
     cmd += " " + VPAGER_FLAGS;
 
+#ifdef __MINGW32__
+  // the documentation of CMD.EXE tells:
+  //
+  //  If /C or /K is specified, then the remainder of the command line after
+  //  the switch is processed as a command line, where the following logic is
+  //  used to process quote (") characters:
+  //  
+  //      1.  If all of the following conditions are met, then quote characters
+  //          on the command line are preserved:
+  //  
+  //          - no /S switch
+  //          - exactly two quote characters
+  //          - no special characters between the two quote characters,
+  //            where special is one of: &<>()@^|
+  //          - there are one or more whitespace characters between the
+  //            the two quote characters
+  //          - the string between the two quote characters is the name
+  //            of an executable file.
+  //  
+  //      2.  Otherwise, old behavior is to see if the first character is
+  //          a quote character and if so, strip the leading character and
+  //          remove the last quote character on the command line, preserving
+  //          any text after the last quote character.
+    
+    cmd = "\"" + cmd + "\"";
+#endif
+  }
+  
   return cmd;
 }
 

reply via email to

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