Exemplo n.º 1
0
void
vfs_stamp_create (struct vfs_class *oldvfs, vfsid oldvfsid)
{
    struct vfs_class *nvfs, *n2vfs, *n3vfs;
    vfsid nvfsid, n2vfsid, n3vfsid;

    /* There are three directories we have to take care of: current_dir,
       current_panel->cwd and other_panel->cwd. Athough most of the time either
       current_dir and current_panel->cwd or current_dir and other_panel->cwd are the
       same, it's possible that all three are different -- Norbert */

    if (current_panel == NULL)
        return;

    nvfs = vfs_get_class (vfs_get_current_dir ());
    nvfsid = vfs_getid (nvfs, vfs_get_current_dir ());
    vfs_rmstamp (nvfs, nvfsid);

    if ((nvfs == oldvfs && nvfsid == oldvfsid) || oldvfsid == NULL)
    {
        return;
    }

    if (get_current_type () == view_listing)
    {
        n2vfs = vfs_get_class (current_panel->cwd);
        n2vfsid = vfs_getid (n2vfs, current_panel->cwd);
        if (n2vfs == oldvfs && n2vfsid == oldvfsid)
            return;
    }
    else
    {
        n2vfs = NULL;
        n2vfsid = NULL;
    }

    if (get_other_type () == view_listing)
    {
        n3vfs = vfs_get_class (other_panel->cwd);
        n3vfsid = vfs_getid (n3vfs, other_panel->cwd);
        if (n3vfs == oldvfs && n3vfsid == oldvfsid)
            return;
    }
    else
    {
        n3vfs = NULL;
        n3vfsid = NULL;
    }

    if (!oldvfs || !oldvfs->nothingisopen || !(*oldvfs->nothingisopen) (oldvfsid))
        return;

    vfs_addstamp (oldvfs, oldvfsid);
}
Exemplo n.º 2
0
char *
expand_format (struct WEdit *edit_widget, char c, gboolean do_quote)
{
    WPanel *panel = NULL;
    char *(*quote_func) (const char *, int);
    char *fname = NULL;
    char *result;
    char c_lc;

#ifndef USE_INTERNAL_EDIT
    (void) edit_widget;
#endif

    if (c == '%')
        return g_strdup ("%");

    switch (mc_global.mc_run_mode)
    {
    case MC_RUN_FULL:
        if (g_ascii_islower ((gchar) c))
            panel = current_panel;
        else
        {
            if (get_other_type () != view_listing)
                return g_strdup ("");
            panel = other_panel;
        }
        fname = g_strdup (panel->dir.list[panel->selected].fname);
        break;

#ifdef USE_INTERNAL_EDIT
    case MC_RUN_EDITOR:
        fname = edit_get_file_name (edit_widget);
        break;
#endif

    default:
        /* other modes don't use formats */
        return g_strdup ("");
    }

    if (do_quote)
        quote_func = name_quote;
    else
        quote_func = fake_name_quote;

    c_lc = g_ascii_tolower ((gchar) c);

    switch (c_lc)
    {
    case 'f':
    case 'p':
        result = (*quote_func) (fname, 0);
        goto ret;
    case 'x':
        result = (*quote_func) (extension (fname), 0);
        goto ret;
    case 'd':
        {
            char *cwd;
            char *qstr;

            if (panel)
                cwd = g_strdup (vfs_path_as_str (panel->cwd_vpath));
            else
                cwd = vfs_get_current_dir ();

            qstr = (*quote_func) (cwd, 0);

            g_free (cwd);

            result = qstr;
            goto ret;
        }
    case 'i':                  /* indent equal number cursor position in line */
#ifdef USE_INTERNAL_EDIT
        if (edit_widget)
        {
            result = g_strnfill (edit_get_curs_col (edit_widget), ' ');
            goto ret;
        }
#endif
        break;
    case 'y':                  /* syntax type */
#ifdef USE_INTERNAL_EDIT
        if (edit_widget)
        {
            const char *syntax_type = edit_get_syntax_type (edit_widget);
            if (syntax_type != NULL)
            {
                result = g_strdup (syntax_type);
                goto ret;
            }
        }
#endif
        break;
    case 'k':                  /* block file name */
    case 'b':                  /* block file name / strip extension */
        {
#ifdef USE_INTERNAL_EDIT
            if (edit_widget)
            {
                char *file;

                file = mc_config_get_full_path (EDIT_BLOCK_FILE);
                result = (*quote_func) (file, 0);
                g_free (file);
                goto ret;
            }
#endif
            if (c_lc == 'b')
            {
                result = strip_ext ((*quote_func) (fname, 0));
                goto ret;
            }
            break;
        }
    case 'n':                  /* strip extension in editor */
#ifdef USE_INTERNAL_EDIT
        if (edit_widget)
        {
            result = strip_ext ((*quote_func) (fname, 0));
            goto ret;
        }
#endif
        break;
    case 'm':                  /* menu file name */
        if (menu)
        {
            result = (*quote_func) (menu, 0);
            goto ret;
        }
        break;
    case 's':
        if (!panel || !panel->marked)
        {
            result = (*quote_func) (fname, 0);
            goto ret;
        }

        /* Fall through */

    case 't':
    case 'u':
        {
            GString *block;
            int i;

            if (panel == NULL)
            {
                result = g_strdup ("");
                goto ret;
            }

            block = g_string_sized_new (16);

            for (i = 0; i < panel->dir.len; i++)
                if (panel->dir.list[i].f.marked)
                {
                    char *tmp;

                    tmp = (*quote_func) (panel->dir.list[i].fname, 0);
                    g_string_append (block, tmp);
                    g_string_append_c (block, ' ');
                    g_free (tmp);

                    if (c_lc == 'u')
                        do_file_mark (panel, i, 0);
                }
            result = g_string_free (block, FALSE);
            goto ret;
        }                       /* sub case block */
    }                           /* switch */
    result = g_strdup ("% ");
    result[1] = c;
  ret:
    g_free (fname);
    return result;
}
Exemplo n.º 3
0
static void
do_execute (const char *shell, const char *command, int flags)
{
#ifdef HAVE_SUBSHELL_SUPPORT
    char *new_dir = NULL;
#endif				/* HAVE_SUBSHELL_SUPPORT */

#ifdef USE_VFS
    char *old_vfs_dir = 0;

    if (!vfs_current_is_local ())
	old_vfs_dir = g_strdup (vfs_get_current_dir ());
#endif				/* USE_VFS */

    save_cwds_stat ();
    pre_exec ();
    if (console_flag)
	handle_console (CONSOLE_RESTORE);

    if (!use_subshell && command && !(flags & EXECUTE_INTERNAL)) {
	printf ("%s%s\n", prompt, command);
    }
#ifdef HAVE_SUBSHELL_SUPPORT
    if (use_subshell && !(flags & EXECUTE_INTERNAL)) {
	do_update_prompt ();

	/* We don't care if it died, higher level takes care of this */
#ifdef USE_VFS
	invoke_subshell (command, VISIBLY, old_vfs_dir ? 0 : &new_dir);
#else
	invoke_subshell (command, VISIBLY, &new_dir);
#endif				/* !USE_VFS */
    } else
#endif				/* HAVE_SUBSHELL_SUPPORT */
	my_system (flags, shell, command);

    if (!(flags & EXECUTE_INTERNAL)) {
	if ((pause_after_run == pause_always
	     || (pause_after_run == pause_on_dumb_terminals && !xterm_flag
		 && !console_flag)) && !quit
#ifdef HAVE_SUBSHELL_SUPPORT
	    && subshell_state != RUNNING_COMMAND
#endif				/* HAVE_SUBSHELL_SUPPORT */
	    ) {
	    printf (_("Press any key to continue..."));
	    fflush (stdout);
	    mc_raw_mode ();
	    get_key_code (0);
	    printf ("\r\n");
	    fflush (stdout);
	}
	if (console_flag) {
	    if (output_lines && keybar_visible) {
		putchar ('\n');
		fflush (stdout);
	    }
	}
    }

    if (console_flag)
	handle_console (CONSOLE_SAVE);
    edition_post_exec ();

#ifdef HAVE_SUBSHELL_SUPPORT
    if (new_dir)
	do_possible_cd (new_dir);

#endif				/* HAVE_SUBSHELL_SUPPORT */

#ifdef USE_VFS
    if (old_vfs_dir) {
	mc_chdir (old_vfs_dir);
	g_free (old_vfs_dir);
    }
#endif				/* USE_VFS */

    update_panels (UP_OPTIMIZE, UP_KEEPSEL);
    update_xterm_title_path ();

    do_refresh ();
    use_dash (TRUE);
}