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



On Sat, Nov 27, 2004 at 09:30:47AM +0100, Oswald Buddenhagen wrote:
> On Sat, Nov 27, 2004 at 03:06:53AM +0100, q# wrote:
> > This patch fix this issue, but please _double check_ this patch.
> > Comments are _very_ welcome.
> > 
> so here we go: this patch sucks. :-P
> glib provides a proper shell command interpretation function; use that
> instead of crafting some fragile dequoting voodoo. (yes, i know you
> didn't start this, but once you touch that code ...)

I tried to rewrite this function. I'm stuck little with condition

  (get_current_type () == view_tree) 

I can't force mc to show me this "FIXME" dialog :/ and also don't
undesrstand for what this part of code was (in old function).

In `do_cd_command()' I want:

 remove unnecessary spaces before and after dirname,
 striped dir stored in cmd (it goes to mc history),
 unqoted dir pass on to `examine_cd()'.

Comments and constructive flames are very welcome.

-- 
best regards
q#
Index: src/command.c
===================================================================
RCS file: /cvsroot/mc/mc/src/command.c,v
retrieving revision 1.28
diff -u -r1.28 command.c
--- src/command.c	3 Nov 2004 19:43:17 -0000	1.28
+++ src/command.c	28 Nov 2004 02:38:48 -0000
@@ -138,53 +138,35 @@
 /* Execute the cd command on the command line */
 void do_cd_command (char *cmd)
 {
-    int len;
-
     /* Any final whitespace should be removed here
        (to see why, try "cd fred "). */
     /* NOTE: I think we should not remove the extra space,
        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 --;
+    char *dir = g_strstrip (g_strdup (cmd+2));
+    char *unq = g_shell_unquote (g_strdup (dir), NULL);
+
+    if (unq == NULL) {
+
+	message (1, MSG_ERROR, _(" Cannot unquote shell string "));
+
+    } else if (get_current_type () == view_tree) {
+
+	message (1, MSG_ERROR, _(" FIXME: Not implemented yet "));
+
+    } else if (!examine_cd (unq)) {
+
+	char *d = strip_password (g_strdup (unq), 1);
+	message (1, MSG_ERROR, _(" Cannot chdir to \"%s\" \n %s "),
+	    d, unix_error_string (errno));
+	g_free (d);
     }
-    
-    if (cmd [2] == 0)
-	cmd = "cd ";
-
-    if (get_current_type () == view_tree){
-	if (cmd [0] == 0){
-	    sync_tree (home_dir);
-	} else if (strcmp (cmd+3, "..") == 0){
-	    char *dir = current_panel->cwd;
-	    int len = strlen (dir);
-	    while (len && dir [--len] != PATH_SEP);
-	    dir [len] = 0;
-	    if (len)
-		sync_tree (dir);
-	    else
-		sync_tree (PATH_SEP_STR);
-	} else if (cmd [3] == PATH_SEP){
-	    sync_tree (cmd+3);
-	} else {
-	    char *old = current_panel->cwd;
-	    char *new;
-	    new = concat_dir_and_file (old, cmd+3);
-	    sync_tree (new);
-	    g_free (new);
-	}
-    } else
-	if (!examine_cd (&cmd [3])) {
-	    char *d = strip_password (g_strdup (&cmd [3]), 1);
-	    message (1, MSG_ERROR, _(" Cannot chdir to \"%s\" \n %s "),
-		     d, unix_error_string (errno));
-	    g_free (d);
-	    return;
-	}
+
+    g_sprintf (cmd, "cd %s", dir);
+    g_free (dir);
+    g_free (unq);
+    return;
 }
 
 /* Handle Enter on the command line */


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