Re: prompt, spaces, `cd' and system commands..



On Thu, Nov 25, 2004 at 12:25:23PM +0100, Leonard den Ottolander wrote:
> Hi q#,
> 
> On Thu, 2004-11-25 at 03:24, q# wrote:
> > I often copy paths with to prompt with (CTRL+x, p) and when your path
> > has space I've got this error when tryin co cd'in.
> 
> As always, patches are welcome.

This patch fix this issue, but please _double check_ this patch.
Comments are _very_ welcome.

-- 
best regards
q#
Index: command.c
===================================================================
RCS file: /cvsroot/mc/mc/src/command.c,v
retrieving revision 1.28
diff -u -r1.28 command.c
--- command.c	3 Nov 2004 19:43:17 -0000	1.28
+++ command.c	27 Nov 2004 02:01:55 -0000
@@ -138,7 +138,9 @@
 /* Execute the cd command on the command line */
 void do_cd_command (char *cmd)
 {
-    int len;
+    int bs = 0;
+    int len = 0;
+    int sn;
 
     /* Any final whitespace should be removed here
        (to see why, try "cd fred "). */
@@ -146,20 +148,31 @@
        that way, we can cd into hidden directories */
     /* FIXME: what about interpreting quoted strings like the shell.
        so one could type "cd <tab> M-a <enter>" and it would work. */
-    len = strlen (cmd) - 1;
-    while (len >= 0 &&
-	   (cmd [len] == ' ' || cmd [len] == '\t' || cmd [len] == '\n')){
-	cmd [len] = 0;
-	len --;
+
+    sn = strlen (cmd) - 1;
+    while (sn >= 0 && (cmd [sn - 1] != '\\') &&
+           (cmd [sn] == ' ' || cmd [sn] == '\t' || cmd [sn] == '\n')) {
+        cmd [sn] = 0;
+        sn --;
+    }
+
+    char *tmp = g_strdup(&cmd [0]);
+
+    while (len + bs <= sn) {
+	if (tmp [len + bs] == '\\')
+	    bs ++;
+	tmp [len] = tmp [len + bs];
+	len ++;
     }
-    
-    if (cmd [2] == 0)
-	cmd = "cd ";
+    tmp [len] = 0;
+
+    if (tmp [2] == 0)
+	tmp = "cd ";
 
     if (get_current_type () == view_tree){
-	if (cmd [0] == 0){
+	if (tmp [0] == 0){
 	    sync_tree (home_dir);
-	} else if (strcmp (cmd+3, "..") == 0){
+	} else if (strcmp (tmp+3, "..") == 0){
 	    char *dir = current_panel->cwd;
 	    int len = strlen (dir);
 	    while (len && dir [--len] != PATH_SEP);
@@ -168,23 +181,25 @@
 		sync_tree (dir);
 	    else
 		sync_tree (PATH_SEP_STR);
-	} else if (cmd [3] == PATH_SEP){
-	    sync_tree (cmd+3);
+	} else if (tmp [3] == PATH_SEP){
+	    sync_tree (tmp+3);
 	} else {
 	    char *old = current_panel->cwd;
 	    char *new;
-	    new = concat_dir_and_file (old, cmd+3);
+	    new = concat_dir_and_file (old, tmp+3);
 	    sync_tree (new);
 	    g_free (new);
 	}
     } else
-	if (!examine_cd (&cmd [3])) {
-	    char *d = strip_password (g_strdup (&cmd [3]), 1);
+	if (!examine_cd (&tmp [3])) {
+	    char *d = strip_password (g_strdup (&tmp [3]), 1);
 	    message (1, MSG_ERROR, _(" Cannot chdir to \"%s\" \n %s "),
 		     d, unix_error_string (errno));
 	    g_free (d);
-	    return;
 	}
+
+    g_free (tmp);
+    return;
 }
 
 /* Handle Enter on the command line */


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