static void load_tree (WTree * tree) { tree_store_load (); tree->selected_ptr = tree->store->tree_first; tree_chdir (tree, mc_config_get_home_dir ()); }
static void load_tree (WTree * tree) { vfs_path_t *vpath; tree_store_load (); tree->selected_ptr = tree->store->tree_first; vpath = vfs_path_from_str (mc_config_get_home_dir ()); tree_chdir (tree, vpath); vfs_path_free (vpath); }
const char * strip_home_and_password (const char *dir) { size_t len; static char newdir[MC_MAXPATHLEN]; len = strlen (mc_config_get_home_dir ()); if (mc_config_get_home_dir () != NULL && strncmp (dir, mc_config_get_home_dir (), len) == 0 && (dir[len] == PATH_SEP || dir[len] == '\0')) { newdir[0] = '~'; g_strlcpy (&newdir[1], &dir[len], sizeof (newdir) - 1); return newdir; } /* We do not strip homes in /#ftp tree, I do not like ~'s there (see ftpfs.c why) */ g_strlcpy (newdir, dir, sizeof (newdir)); strip_password (newdir, 1); return newdir; }
void show_datadirs_extended (void) { (void) printf ("%s %s\n", _("Root directory:"), mc_config_get_home_dir ()); (void) puts (""); PRINTF_GROUP (_("System data")); PRINTF_SECTION (_("Config directory:"), mc_global.sysconfig_dir); PRINTF_SECTION (_("Data directory:"), mc_global.share_data_dir); PRINTF_SECTION (_("File extension handlers:"), EXTHELPERSDIR); #if defined ENABLE_VFS_EXTFS || defined ENABLE_VFS_FISH PRINTF_SECTION (_("VFS plugins and scripts:"), LIBEXECDIR); #ifdef ENABLE_VFS_EXTFS PRINTF2 ("extfs.d:", LIBEXECDIR, MC_EXTFS_DIR "/"); #endif #ifdef ENABLE_VFS_FISH PRINTF2 ("fish:", LIBEXECDIR, FISH_PREFIX "/"); #endif #endif /* ENABLE_VFS_EXTFS || defiined ENABLE_VFS_FISH */ (void) puts (""); PRINTF_GROUP (_("User data")); PRINTF_SECTION2 (_("Config directory:"), mc_config_get_path ()); PRINTF_SECTION2 (_("Data directory:"), mc_config_get_data_path ()); PRINTF ("skins:", mc_config_get_data_path (), MC_SKINS_SUBDIR "/"); #ifdef ENABLE_VFS_EXTFS PRINTF ("extfs.d:", mc_config_get_data_path (), MC_EXTFS_DIR "/"); #endif #ifdef ENABLE_VFS_FISH PRINTF ("fish:", mc_config_get_data_path (), FISH_PREFIX "/"); #endif #ifdef USE_INTERNAL_EDIT PRINTF ("mcedit macros:", mc_config_get_data_path (), MC_MACRO_FILE); PRINTF ("mcedit external macros:", mc_config_get_data_path (), MC_EXTMACRO_FILE ".*"); #endif PRINTF_SECTION2 (_("Cache directory:"), mc_config_get_cache_path ()); }
static void init_subshell_child (const char *pty_name) { char *init_file = NULL; pid_t mc_sid; (void) pty_name; setsid (); /* Get a fresh terminal session */ /* Make sure that it has become our controlling terminal */ /* Redundant on Linux and probably most systems, but just in case: */ #ifdef TIOCSCTTY ioctl (subshell_pty_slave, TIOCSCTTY, 0); #endif /* Configure its terminal modes and window size */ /* Set up the pty with the same termios flags as our own tty */ if (tcsetattr (subshell_pty_slave, TCSANOW, &shell_mode)) { fprintf (stderr, "Cannot set pty terminal modes: %s\r\n", unix_error_string (errno)); my_exit (FORK_FAILURE); } /* Set the pty's size (80x25 by default on Linux) according to the */ /* size of the real terminal as calculated by ncurses, if possible */ tty_resize (subshell_pty_slave); /* Set up the subshell's environment and init file name */ /* It simplifies things to change to our home directory here, */ /* and the user's startup file may do a 'cd' command anyway */ { int ret; ret = chdir (mc_config_get_home_dir ()); /* FIXME? What about when we re-run the subshell? */ (void) ret; } /* Set MC_SID to prevent running one mc from another */ mc_sid = getsid (0); if (mc_sid != -1) { char sid_str[BUF_SMALL]; g_snprintf (sid_str, sizeof (sid_str), "MC_SID=%ld", (long) mc_sid); putenv (g_strdup (sid_str)); } switch (subshell_type) { case BASH: init_file = mc_config_get_full_path ("bashrc"); if (access (init_file, R_OK) == -1) { g_free (init_file); init_file = g_strdup (".bashrc"); } /* Make MC's special commands not show up in bash's history */ putenv ((char *) "HISTCONTROL=ignorespace"); /* Allow alternative readline settings for MC */ { char *input_file = mc_config_get_full_path ("inputrc"); if (access (input_file, R_OK) == 0) { char *putenv_str = g_strconcat ("INPUTRC=", input_file, NULL); putenv (putenv_str); g_free (putenv_str); } g_free (input_file); } break; /* TODO: Find a way to pass initfile to TCSH and ZSH */ case TCSH: case ZSH: case FISH: break; default: fprintf (stderr, __FILE__ ": unimplemented subshell type %d\r\n", subshell_type); my_exit (FORK_FAILURE); } /* Attach all our standard file descriptors to the pty */ /* This is done just before the fork, because stderr must still */ /* be connected to the real tty during the above error messages; */ /* otherwise the user will never see them. */ dup2 (subshell_pty_slave, STDIN_FILENO); dup2 (subshell_pty_slave, STDOUT_FILENO); dup2 (subshell_pty_slave, STDERR_FILENO); close (subshell_pipe[READ]); close (subshell_pty_slave); /* These may be FD_CLOEXEC, but just in case... */ /* Close master side of pty. This is important; apart from */ /* freeing up the descriptor for use in the subshell, it also */ /* means that when MC exits, the subshell will get a SIGHUP and */ /* exit too, because there will be no more descriptors pointing */ /* at the master side of the pty and so it will disappear. */ close (mc_global.tty.subshell_pty); /* Execute the subshell at last */ switch (subshell_type) { case BASH: execl (mc_global.tty.shell, "bash", "-rcfile", init_file, (char *) NULL); break; case TCSH: execl (mc_global.tty.shell, "tcsh", (char *) NULL); break; case ZSH: /* Use -g to exclude cmds beginning with space from history * and -Z to use the line editor on non-interactive term */ execl (mc_global.tty.shell, "zsh", "-Z", "-g", (char *) NULL); break; case FISH: execl (mc_global.tty.shell, "fish", (char *) NULL); break; } /* If we get this far, everything failed miserably */ g_free (init_file); my_exit (FORK_FAILURE); }
int main (int argc, char *argv[]) { GError *error = NULL; int exit_code = EXIT_FAILURE; /* We had LC_CTYPE before, LC_ALL includs LC_TYPE as well */ (void) setlocale (LC_ALL, ""); (void) bindtextdomain ("mc", LOCALEDIR); (void) textdomain ("mc"); /* do this before args parsing */ str_init_strings (NULL); if (!mc_args_parse (&argc, &argv, "mc", &error)) { startup_exit_falure: fprintf (stderr, _("Failed to run:\n%s\n"), error->message); g_error_free (error); g_free (shell); startup_exit_ok: str_uninit_strings (); return exit_code; } /* do this before mc_args_show_info () to view paths in the --datadir-info output */ OS_Setup (); if (!g_path_is_absolute (mc_config_get_home_dir ())) { error = g_error_new (MC_ERROR, 0, "%s: %s", _("Home directory path is not absolute"), mc_config_get_home_dir ()); mc_event_deinit (NULL); goto startup_exit_falure; } if (!mc_args_show_info ()) { exit_code = EXIT_SUCCESS; goto startup_exit_ok; } if (!events_init (&error)) goto startup_exit_falure; mc_config_init_config_paths (&error); if (error == NULL && mc_config_deprecated_dir_present ()) mc_config_migrate_from_old_place (&error); if (error != NULL) { mc_event_deinit (NULL); goto startup_exit_falure; } vfs_init (); vfs_plugins_init (); vfs_setup_work_dir (); /* do this after vfs initialization due to mc_setctl() call in mc_setup_by_args() */ if (!mc_setup_by_args (argc, argv, &error)) { vfs_shut (); mc_event_deinit (NULL); goto startup_exit_falure; } /* check terminal type * $TEMR must be set and not empty * mc_global.tty.xterm_flag is used in init_key() and tty_init() * Do this after mc_args_handle() where mc_args__force_xterm is set up. */ mc_global.tty.xterm_flag = tty_check_term (mc_args__force_xterm); /* NOTE: This has to be called before tty_init or whatever routine calls any define_sequence */ init_key (); /* Must be done before installing the SIGCHLD handler [[FIXME]] */ handle_console (CONSOLE_INIT); #ifdef HAVE_SUBSHELL_SUPPORT /* Don't use subshell when invoked as viewer or editor */ if (mc_global.mc_run_mode != MC_RUN_FULL) mc_global.tty.use_subshell = FALSE; if (mc_global.tty.use_subshell) subshell_get_console_attributes (); #endif /* HAVE_SUBSHELL_SUPPORT */ /* Install the SIGCHLD handler; must be done before init_subshell() */ init_sigchld (); /* We need this, since ncurses endwin () doesn't restore the signals */ save_stop_handler (); /* Must be done before init_subshell, to set up the terminal size: */ /* FIXME: Should be removed and LINES and COLS computed on subshell */ tty_init (!mc_args__nomouse, mc_global.tty.xterm_flag); load_setup (); /* start check mc_global.display_codepage and mc_global.source_codepage */ check_codeset (); /* Removing this from the X code let's us type C-c */ load_key_defs (); load_keymap_defs (!mc_args__nokeymap); macros_list = g_array_new (TRUE, FALSE, sizeof (macros_t)); tty_init_colors (mc_global.tty.disable_colors, mc_args__force_colors); mc_skin_init (&error); if (error != NULL) { message (D_ERROR, _("Warning"), "%s", error->message); g_error_free (error); error = NULL; } mc_filehighlight = mc_fhl_new (TRUE); dlg_set_default_colors (); #ifdef HAVE_SUBSHELL_SUPPORT /* Done here to ensure that the subshell doesn't */ /* inherit the file descriptors opened below, etc */ if (mc_global.tty.use_subshell) init_subshell (); #endif /* HAVE_SUBSHELL_SUPPORT */ /* Also done after init_subshell, to save any shell init file messages */ if (mc_global.tty.console_flag != '\0') handle_console (CONSOLE_SAVE); if (mc_global.tty.alternate_plus_minus) application_keypad_mode (); #ifdef HAVE_SUBSHELL_SUPPORT if (mc_global.tty.use_subshell) { mc_prompt = strip_ctrl_codes (subshell_prompt); if (mc_prompt == NULL) mc_prompt = (geteuid () == 0) ? "# " : "$ "; } else #endif /* HAVE_SUBSHELL_SUPPORT */ mc_prompt = (geteuid () == 0) ? "# " : "$ "; /* Program main loop */ if (mc_global.midnight_shutdown) exit_code = EXIT_SUCCESS; else exit_code = do_nc ()? EXIT_SUCCESS : EXIT_FAILURE; /* Save the tree store */ (void) tree_store_save (); free_keymap_defs (); /* Virtual File System shutdown */ vfs_shut (); flush_extension_file (); /* does only free memory */ mc_fhl_free (&mc_filehighlight); mc_skin_deinit (); tty_colors_done (); tty_shutdown (); done_setup (); if (mc_global.tty.console_flag != '\0' && (quit & SUBSHELL_EXIT) == 0) handle_console (CONSOLE_RESTORE); if (mc_global.tty.alternate_plus_minus) numeric_keypad_mode (); (void) signal (SIGCHLD, SIG_DFL); /* Disable the SIGCHLD handler */ if (mc_global.tty.console_flag != '\0') handle_console (CONSOLE_DONE); if (mc_global.mc_run_mode == MC_RUN_FULL && mc_args__last_wd_file != NULL && last_wd_string != NULL && !print_last_revert) { int last_wd_fd; last_wd_fd = open (mc_args__last_wd_file, O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, S_IRUSR | S_IWUSR); if (last_wd_fd != -1) { ssize_t ret1; int ret2; ret1 = write (last_wd_fd, last_wd_string, strlen (last_wd_string)); ret2 = close (last_wd_fd); } } g_free (last_wd_string); g_free (shell); done_key (); if (macros_list != NULL) { guint i; macros_t *macros; for (i = 0; i < macros_list->len; i++) { macros = &g_array_index (macros_list, struct macros_t, i); if (macros != NULL && macros->macro != NULL) (void) g_array_free (macros->macro, FALSE); } (void) g_array_free (macros_list, TRUE); }
gboolean user_menu_cmd (struct WEdit * edit_widget, const char *menu_file, int selected_entry) { char *p; char *data, **entries; int max_cols, menu_lines, menu_limit; int col, i, accept_entry = 1; int selected, old_patterns; gboolean res = FALSE; gboolean interactive = TRUE; if (!vfs_current_is_local ()) { message (D_ERROR, MSG_ERROR, "%s", _("Cannot execute commands on non-local filesystems")); return FALSE; } if (menu_file != NULL) menu = g_strdup (menu_file); else menu = g_strdup (edit_widget ? EDIT_LOCAL_MENU : MC_LOCAL_MENU); if (!exist_file (menu) || !menu_file_own (menu)) { if (menu_file != NULL) { message (D_ERROR, MSG_ERROR, _("Cannot open file %s\n%s"), menu, unix_error_string (errno)); MC_PTR_FREE (menu); return FALSE; } g_free (menu); if (edit_widget) menu = mc_config_get_full_path (EDIT_HOME_MENU); else menu = mc_config_get_full_path (MC_USERMENU_FILE); if (!exist_file (menu)) { g_free (menu); menu = mc_build_filename (mc_config_get_home_dir (), edit_widget ? EDIT_GLOBAL_MENU : MC_GLOBAL_MENU, NULL); if (!exist_file (menu)) { g_free (menu); menu = mc_build_filename (mc_global.sysconfig_dir, edit_widget ? EDIT_GLOBAL_MENU : MC_GLOBAL_MENU, NULL); if (!exist_file (menu)) { g_free (menu); menu = mc_build_filename (mc_global.share_data_dir, edit_widget ? EDIT_GLOBAL_MENU : MC_GLOBAL_MENU, NULL); } } } } if (!g_file_get_contents (menu, &data, NULL, NULL)) { message (D_ERROR, MSG_ERROR, _("Cannot open file%s\n%s"), menu, unix_error_string (errno)); MC_PTR_FREE (menu); return FALSE; } max_cols = 0; selected = 0; menu_limit = 0; entries = 0; /* Parse the menu file */ old_patterns = easy_patterns; p = check_patterns (data); for (menu_lines = col = 0; *p; str_next_char (&p)) { if (menu_lines >= menu_limit) { char **new_entries; menu_limit += MAX_ENTRIES; new_entries = g_try_realloc (entries, sizeof (new_entries[0]) * menu_limit); if (new_entries == NULL) break; entries = new_entries; new_entries += menu_limit; while (--new_entries >= &entries[menu_lines]) *new_entries = NULL; } if (col == 0 && !entries[menu_lines]) { if (*p == '#') { /* show prompt if first line of external script is #interactive */ if (selected_entry >= 0 && strncmp (p, "#silent", 7) == 0) interactive = FALSE; /* A commented menu entry */ accept_entry = 1; } else if (*p == '+') { if (*(p + 1) == '=') { /* Combined adding and default */ p = test_line (edit_widget, p + 1, &accept_entry); if (selected == 0 && accept_entry) selected = menu_lines; } else { /* A condition for adding the entry */ p = test_line (edit_widget, p, &accept_entry); } } else if (*p == '=') { if (*(p + 1) == '+') { /* Combined adding and default */ p = test_line (edit_widget, p + 1, &accept_entry); if (selected == 0 && accept_entry) selected = menu_lines; } else { /* A condition for making the entry default */ i = 1; p = test_line (edit_widget, p, &i); if (selected == 0 && i) selected = menu_lines; } } else if (*p != ' ' && *p != '\t' && str_isprint (p)) { /* A menu entry title line */ if (accept_entry) entries[menu_lines] = p; else accept_entry = 1; } } if (*p == '\n') { if (entries[menu_lines]) { menu_lines++; accept_entry = 1; } max_cols = max (max_cols, col); col = 0; } else { if (*p == '\t') *p = ' '; col++; } } if (menu_lines == 0) { message (D_ERROR, MSG_ERROR, _("No suitable entries found in %s"), menu); res = FALSE; } else { if (selected_entry >= 0) selected = selected_entry; else { Listbox *listbox; max_cols = min (max (max_cols, col), MAX_ENTRY_LEN); /* Create listbox */ listbox = create_listbox_window (menu_lines, max_cols + 2, _("User menu"), "[Menu File Edit]"); /* insert all the items found */ for (i = 0; i < menu_lines; i++) { p = entries[i]; LISTBOX_APPEND_TEXT (listbox, (unsigned char) p[0], extract_line (p, p + MAX_ENTRY_LEN), p); } /* Select the default entry */ listbox_select_entry (listbox->list, selected); selected = run_listbox (listbox); } if (selected >= 0) { execute_menu_command (edit_widget, entries[selected], interactive); res = TRUE; } do_refresh (); } easy_patterns = old_patterns; MC_PTR_FREE (menu); g_free (entries); g_free (data); return res; }
int main (int argc, char *argv[]) { GError *mcerror = NULL; gboolean config_migrated = FALSE; char *config_migrate_msg; int exit_code = EXIT_FAILURE; mc_global.timer = mc_timer_new (); /* We had LC_CTYPE before, LC_ALL includs LC_TYPE as well */ #ifdef HAVE_SETLOCALE (void) setlocale (LC_ALL, ""); #endif (void) bindtextdomain (PACKAGE, LOCALEDIR); (void) textdomain (PACKAGE); /* do this before args parsing */ str_init_strings (NULL); if (!mc_args_parse (&argc, &argv, "mc", &mcerror)) { startup_exit_falure: fprintf (stderr, _("Failed to run:\n%s\n"), mcerror->message); g_error_free (mcerror); g_free (mc_global.tty.shell); startup_exit_ok: str_uninit_strings (); mc_timer_destroy (mc_global.timer); return exit_code; } /* do this before mc_args_show_info () to view paths in the --datadir-info output */ OS_Setup (); if (!g_path_is_absolute (mc_config_get_home_dir ())) { mc_propagate_error (&mcerror, 0, "%s: %s", _("Home directory path is not absolute"), mc_config_get_home_dir ()); mc_event_deinit (NULL); goto startup_exit_falure; } if (!mc_args_show_info ()) { exit_code = EXIT_SUCCESS; goto startup_exit_ok; } if (!events_init (&mcerror)) goto startup_exit_falure; mc_config_init_config_paths (&mcerror); config_migrated = mc_config_migrate_from_old_place (&mcerror, &config_migrate_msg); if (mcerror != NULL) { mc_event_deinit (NULL); goto startup_exit_falure; } vfs_init (); vfs_plugins_init (); load_setup (); /* Must be done after load_setup because depends on mc_global.vfs.cd_symlinks */ vfs_setup_work_dir (); /* Resolve the other_dir panel option. Must be done after vfs_setup_work_dir */ { char *buffer; vfs_path_t *vpath; buffer = mc_config_get_string (mc_panels_config, "Dirs", "other_dir", "."); vpath = vfs_path_from_str (buffer); if (vfs_file_is_local (vpath)) saved_other_dir = buffer; else g_free (buffer); vfs_path_free (vpath); } /* Set up temporary directory after VFS initialization */ mc_tmpdir (); /* do this after vfs initialization and vfs working directory setup due to mc_setctl() and mcedit_arg_vpath_new() calls in mc_setup_by_args() */ if (!mc_setup_by_args (argc, argv, &mcerror)) { vfs_shut (); done_setup (); g_free (saved_other_dir); mc_event_deinit (NULL); goto startup_exit_falure; } /* check terminal type * $TEMR must be set and not empty * mc_global.tty.xterm_flag is used in init_key() and tty_init() * Do this after mc_args_handle() where mc_args__force_xterm is set up. */ mc_global.tty.xterm_flag = tty_check_term (mc_args__force_xterm); /* NOTE: This has to be called before tty_init or whatever routine calls any define_sequence */ init_key (); /* Must be done before installing the SIGCHLD handler [[FIXME]] */ handle_console (CONSOLE_INIT); #ifdef ENABLE_SUBSHELL /* Don't use subshell when invoked as viewer or editor */ if (mc_global.mc_run_mode != MC_RUN_FULL) mc_global.tty.use_subshell = FALSE; if (mc_global.tty.use_subshell) subshell_get_console_attributes (); #endif /* ENABLE_SUBSHELL */ /* Install the SIGCHLD handler; must be done before init_subshell() */ init_sigchld (); /* We need this, since ncurses endwin () doesn't restore the signals */ save_stop_handler (); /* Must be done before init_subshell, to set up the terminal size: */ /* FIXME: Should be removed and LINES and COLS computed on subshell */ tty_init (!mc_args__nomouse, mc_global.tty.xterm_flag); /* start check mc_global.display_codepage and mc_global.source_codepage */ check_codeset (); /* Removing this from the X code let's us type C-c */ load_key_defs (); load_keymap_defs (!mc_args__nokeymap); macros_list = g_array_new (TRUE, FALSE, sizeof (macros_t)); tty_init_colors (mc_global.tty.disable_colors, mc_args__force_colors); mc_skin_init (NULL, &mcerror); dlg_set_default_colors (); input_set_default_colors (); if (mc_global.mc_run_mode == MC_RUN_FULL) command_set_default_colors (); mc_error_message (&mcerror); #ifdef ENABLE_SUBSHELL /* Done here to ensure that the subshell doesn't */ /* inherit the file descriptors opened below, etc */ if (mc_global.tty.use_subshell) init_subshell (); #endif /* ENABLE_SUBSHELL */ /* Also done after init_subshell, to save any shell init file messages */ if (mc_global.tty.console_flag != '\0') handle_console (CONSOLE_SAVE); if (mc_global.tty.alternate_plus_minus) application_keypad_mode (); /* Done after subshell initialization to allow select and paste text by mouse w/o Shift button in subshell in the native console */ init_mouse (); /* Done after do_enter_ca_mode (tty_init) because in VTE bracketed mode is separate for the normal and alternate screens */ enable_bracketed_paste (); /* subshell_prompt is NULL here */ mc_prompt = (geteuid () == 0) ? "# " : "$ "; if (config_migrated) { message (D_ERROR, _("Warning"), "%s", config_migrate_msg); g_free (config_migrate_msg); } /* Program main loop */ if (mc_global.midnight_shutdown) exit_code = EXIT_SUCCESS; else exit_code = do_nc ()? EXIT_SUCCESS : EXIT_FAILURE; /* Save the tree store */ (void) tree_store_save (); free_keymap_defs (); /* Virtual File System shutdown */ vfs_shut (); flush_extension_file (); /* does only free memory */ mc_skin_deinit (); tty_colors_done (); tty_shutdown (); done_setup (); if (mc_global.tty.console_flag != '\0' && (quit & SUBSHELL_EXIT) == 0) handle_console (CONSOLE_RESTORE); if (mc_global.tty.alternate_plus_minus) numeric_keypad_mode (); (void) signal (SIGCHLD, SIG_DFL); /* Disable the SIGCHLD handler */ if (mc_global.tty.console_flag != '\0') handle_console (CONSOLE_DONE); if (mc_global.mc_run_mode == MC_RUN_FULL && mc_args__last_wd_file != NULL && last_wd_string != NULL && !print_last_revert) { int last_wd_fd; last_wd_fd = open (mc_args__last_wd_file, O_WRONLY | O_CREAT | O_TRUNC | O_EXCL, S_IRUSR | S_IWUSR); if (last_wd_fd != -1) { ssize_t ret1; int ret2; ret1 = write (last_wd_fd, last_wd_string, strlen (last_wd_string)); ret2 = close (last_wd_fd); (void) ret1; (void) ret2; } } g_free (last_wd_string); g_free (mc_global.tty.shell); done_key (); if (macros_list != NULL) { guint i; for (i = 0; i < macros_list->len; i++) { macros_t *macros; macros = &g_array_index (macros_list, struct macros_t, i); if (macros != NULL && macros->macro != NULL) (void) g_array_free (macros->macro, FALSE); } (void) g_array_free (macros_list, TRUE); }
void do_cd_command (char *orig_cmd) { int len; int operand_pos = CD_OPERAND_OFFSET; const char *cmd; /* 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 (orig_cmd) - 1; while (len >= 0 && (orig_cmd[len] == ' ' || orig_cmd[len] == '\t' || orig_cmd[len] == '\n')) { orig_cmd[len] = 0; len--; } cmd = orig_cmd; if (cmd[CD_OPERAND_OFFSET - 1] == 0) cmd = "cd "; /* 0..2 => given text, 3 => \0 */ /* allow any amount of white space in front of the path operand */ while (cmd[operand_pos] == ' ' || cmd[operand_pos] == '\t') operand_pos++; if (get_current_type () == view_tree) { if (cmd[0] == 0) { sync_tree (mc_config_get_home_dir ()); } else if (DIR_IS_DOTDOT (cmd + operand_pos)) { if (vfs_path_elements_count (current_panel->cwd_vpath) != 1 || strlen (vfs_path_get_by_index (current_panel->cwd_vpath, 0)->path) > 1) { vfs_path_t *tmp_vpath = current_panel->cwd_vpath; current_panel->cwd_vpath = vfs_path_vtokens_get (tmp_vpath, 0, vfs_path_tokens_count (tmp_vpath) - 1); vfs_path_free (tmp_vpath); } sync_tree (vfs_path_as_str (current_panel->cwd_vpath)); } else if (cmd[operand_pos] == PATH_SEP) { sync_tree (cmd + operand_pos); } else { vfs_path_t *new_vpath; new_vpath = vfs_path_append_new (current_panel->cwd_vpath, cmd + operand_pos, NULL); sync_tree (vfs_path_as_str (new_vpath)); vfs_path_free (new_vpath); } } else { char *path; vfs_path_t *q_vpath; gboolean ok; path = examine_cd (&cmd[operand_pos]); if (*path == '\0') q_vpath = vfs_path_from_str (mc_config_get_home_dir ()); else q_vpath = vfs_path_from_str_flags (path, VPF_NO_CANON); ok = do_cd (q_vpath, cd_parse_command); if (!ok) ok = handle_cdpath (path); if (!ok) { char *d; d = vfs_path_to_str_flags (q_vpath, 0, VPF_STRIP_PASSWORD); message (D_ERROR, MSG_ERROR, _("Cannot chdir to \"%s\"\n%s"), d, unix_error_string (errno)); g_free (d); } vfs_path_free (q_vpath); g_free (path); } }