[svn.haxx.se] · SVN Dev · SVN Users · SVN Org · TSVN Dev · TSVN Users · Subclipse Dev · Subclipse Users · this month's index

[PATCH] $EDITOR with spaces

From: Daniel Stenberg <daniel_at_haxx.se>
Date: 2002-04-16 00:53:05 CEST

Yes

As was just pointed out on IRC to me, the $EDITOR code didn't handle the fact
that it might contain spaces and possible options. I wrote this patch up very
quickly and I'd like your comments before I go ahead and commit anything like
this. Its been a while since I did my last confe^H^H^Hmitts.

* subversion/clients/cmdline/util.c

 (svn_cl__edit_externally) added magic to deal with EDITOR strings that
 contain spaces/options. Removed old command building sprintf().

Index: ./util.c
===================================================================
--- ./util.c
+++ ./util.c Tue Apr 16 00:38:53 2002
@@ -366,16 +366,19 @@
                          apr_pool_t *pool)
 {
   const char *editor = NULL;
- const char *command = NULL;
+ svn_stringbuf_t *command = NULL;
+ svn_stringbuf_t **cmdstrings;
   apr_file_t *tmp_file;
   svn_stringbuf_t *tmpfile_name;
   apr_status_t apr_err;
   apr_size_t written;
   apr_finfo_t finfo_before, finfo_after;
   svn_error_t *err = SVN_NO_ERROR;
- const char *cmd_args[3] = { 0 };
+ const char **cmd_args;
   int exit_code = 0;
   apr_exit_why_e exit_why;
+ apr_array_header_t *array;
+ int i;

   /* Try to find an editor in the environment. */
   editor = getenv ("SVN_EDITOR");
@@ -422,20 +425,36 @@
       goto cleanup;
     }

- /* Create the editor command line. */
- command = apr_psprintf (pool, "%s %s", editor, tmpfile_name->data);
-
   /* Get information about the temporary file before the user has
      been allowed to edit its contents. */
   apr_stat (&finfo_before, tmpfile_name->data,
             APR_FINFO_MTIME | APR_FINFO_SIZE, pool);

+ /* split the EDITOR varible into an array, we need to do this since the
+ variable may contain spaces and options etc */
+ command = svn_stringbuf_create (editor, pool);
+
+ array = svn_cl__stringlist_to_array (command, pool);
+
+ /* now we must convert the stringbuf** array to a plain char ** array,
+ allocate two extra entries for the file and the trailing NULL */
+ cmd_args = (const char **)apr_palloc (pool,
+ sizeof (char *) * (array->nelts + 2) );
+
+ cmdstrings=(svn_stringbuf_t **)array->elts;
+ for (i=0 ; i < array->nelts; i++)
+ cmd_args[i] = cmdstrings[i]->data;
+
+ /* it is important to add the file name here and not just as a part of the
+ 'editor' string above, as we must preserve spaces etc that this file name
+ might contain */
+ cmd_args[i++] = tmpfile_name->data;
+ cmd_args[i] = NULL;
+
   /* Now, run the editor command line. Ignore the return values; all
      we really care about (for now) is whether or not our tmpfile
      contents have changed. */
- cmd_args[0] = editor;
- cmd_args[1] = tmpfile_name->data;
- SVN_ERR (svn_io_run_cmd (".", editor, cmd_args, &exit_code, &exit_why,
+ SVN_ERR (svn_io_run_cmd (".", cmd_args[0], cmd_args, &exit_code, &exit_why,
                            TRUE, NULL, NULL, NULL, pool));

   /* Get information about the temporary file after the assumed editing. */

-- 
      Daniel Stenberg - http://daniel.haxx.se - +46-705-44 31 77
   ech`echo xiun|tr nu oc|sed 'sx\([sx]\)\([xoi]\)xo un\2\1 is xg'`ol
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@subversion.tigris.org
For additional commands, e-mail: dev-help@subversion.tigris.org
Received on Tue Apr 16 00:55:23 2002

This is an archived mail posted to the Subversion Dev mailing list.