Esempio n. 1
0
static char *
get_absolute_name (char *file)
{
    char dir[MC_MAXPATHLEN];

    if (file[0] == PATH_SEP)
	return g_strdup (file);
    mc_get_current_wd (dir, MC_MAXPATHLEN);
    return concat_dir_and_file (dir, file);
}
Esempio n. 2
0
File: tree.c Progetto: ebichu/dd-wrt
static void
tree_rescan_cmd (WTree *tree)
{
    char old_dir [MC_MAXPATHLEN];

    if (!tree->selected_ptr || !mc_get_current_wd (old_dir, MC_MAXPATHLEN) ||
	mc_chdir (tree->selected_ptr->name))
	return;

    tree_store_rescan (tree->selected_ptr->name);
    mc_chdir (old_dir);
}
Esempio n. 3
0
File: tree.c Progetto: ebichu/dd-wrt
static void
tree_mkdir_cmd (WTree *tree)
{
    char old_dir [MC_MAXPATHLEN];

    if (!tree->selected_ptr)
	return;
    if (!mc_get_current_wd (old_dir, MC_MAXPATHLEN))
	return;
    if (chdir (tree->selected_ptr->name))
	return;
    /* FIXME
    mkdir_cmd (tree);
    */
    tree_rescan_cmd (tree);
    chdir (old_dir);
}
Esempio n. 4
0
File: user.c Progetto: dborca/mc
char *
expand_format (struct WEdit *edit_widget, char c, int quote)
{
    WPanel *panel = NULL;
    char *(*quote_func) (const char *, int);
    char *fname;
    char *result;
    char c_lc;

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

    if (edit_one_file != NULL)
	fname = edit_widget->filename;
    else {
	if (islower ((unsigned char) c))
	    panel = current_panel;
	else {
	    if (get_other_type () != view_listing)
		return g_strdup ("");
	    panel = other_panel;
	}
	fname = panel->dir.list[panel->selected].fname;
    }

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

    c_lc = tolower ((unsigned char) c);

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

	    cwd = g_malloc(MC_MAXPATHLEN + 1);

	    if (panel)
		g_strlcpy(cwd, panel->cwd, MC_MAXPATHLEN + 1);
	    else
		mc_get_current_wd(cwd, MC_MAXPATHLEN + 1);

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

	    g_free (cwd);

	    return qstr;
	}
    case 'i':			/* indent equal number cursor position in line */
	if (edit_widget)
	    return g_strnfill (edit_widget->curs_col, ' ');
	break;
    case 'y':			/* syntax type */
	if (edit_widget && edit_widget->syntax_type)
	    return g_strdup (edit_widget->syntax_type);
	break;
    case 'k':			/* block file name */
    case 'b':			/* block file name / strip extension */  {
	    if (edit_widget) {
		char *file = g_strconcat (home_dir, PATH_SEP_STR BLOCK_FILE, (char *) NULL);
		fname = (*quote_func) (file, 0);
		g_free (file);
		return fname;
	    } else if (c_lc == 'b') {
		return strip_ext ((*quote_func) (fname, 0));
	    }
	    break;
	}
    case 'e':			/* was "cooledit.error" */
	return g_strdup("/dev/null");
    case 'n':			/* strip extension in editor */
	if (edit_widget)
	    return strip_ext ((*quote_func) (fname, 0));
	break;
    case 'm':			/* menu file name */
	if (menu)
	    return (*quote_func) (menu, 0);
	break;
    case 's':
	if (!panel || !panel->marked)
	    return (*quote_func) (fname, 0);

	/* Fall through */

    case 't':
    case 'u':
	{
	    int length = 2, i;
	    char *block, *tmp;

	    if (!panel)
		return g_strdup ("");

	    for (i = 0; i < panel->count; i++)
		if (panel->dir.list[i].f.marked)
		    length += strlen (panel->dir.list[i].fname) + 1;	/* for space */

	    block = g_malloc (length * 2 + 1);
	    *block = 0;
	    for (i = 0; i < panel->count; i++)
		if (panel->dir.list[i].f.marked) {
		    strcat (block, tmp =
			    (*quote_func) (panel->dir.list[i].fname, 0));
		    g_free (tmp);
		    strcat (block, " ");
		    if (c_lc == 'u')
			do_file_mark (panel, i, 0);
		}
	    return block;
	}			/* sub case block */
    }				/* switch */
    result = g_strdup ("% ");
    result[1] = c;
    return result;
}
Esempio n. 5
0
File: layout.c Progetto: artzub/mc
void
set_display_type (int num, panel_view_mode_t type)
{
    int x = 0, y = 0, cols = 0, lines = 0;
    unsigned int the_other = 0; /* Index to the other panel */
    const char *file_name = NULL;       /* For Quick view */
    Widget *new_widget = NULL, *old_widget = NULL;
    panel_view_mode_t old_type;
    WPanel *the_other_panel = NULL;

    if (num >= MAX_VIEWS)
    {
        fprintf (stderr, "Cannot allocate more that %d views\n", MAX_VIEWS);
        abort ();
    }
    /* Check that we will have a WPanel * at least */
    if (type != view_listing)
    {
        the_other = num == 0 ? 1 : 0;

        if (panels[the_other].type != view_listing)
            return;
    }

    /* Get rid of it */
    if (panels[num].widget != NULL)
    {
        Widget *w = panels[num].widget;
        WPanel *panel = (WPanel *) w;

        x = w->x;
        y = w->y;
        cols = w->cols;
        lines = w->lines;
        old_widget = w;
        old_type = panels[num].type;

        if (old_type == view_listing && panel->frame_size == frame_full && type != view_listing)
        {
            cols = COLS - first_panel_size;
            if (num == 1)
                x = first_panel_size;
        }
    }

    /* Restoring saved path from panels.ini for nonlist panel */
    /* when it's first creation (for example view_info) */
    if (old_widget == NULL && type != view_listing)
    {
        char panel_dir[MC_MAXPATHLEN];
        mc_get_current_wd (panel_dir, sizeof (panel_dir));
        panels[num].last_saved_dir = g_strdup (panel_dir);
    }

    switch (type)
    {
    case view_nothing:
    case view_listing:
        new_widget = restore_into_right_dir_panel (num, old_widget);
        widget_set_size (new_widget, y, x, lines, cols);
        break;

    case view_info:
        new_widget = (Widget *) info_new (y, x, lines, cols);
        break;

    case view_tree:
        new_widget = (Widget *) tree_new (y, x, lines, cols, TRUE);
        break;

    case view_quick:
        new_widget = (Widget *) mcview_new (y, x, lines, cols, TRUE);
        the_other_panel = (WPanel *) panels[the_other].widget;
        if (the_other_panel != NULL)
            file_name = the_other_panel->dir.list[the_other_panel->selected].fname;
        else
            file_name = "";

        mcview_load ((struct mcview_struct *) new_widget, 0, file_name, 0);
        break;
    }

    if (type != view_listing)
        /* Must save dir, for restoring after change type to */
        /* view_listing */
        save_panel_dir (num);

    panels[num].type = type;
    panels[num].widget = new_widget;

    /* We use replace to keep the circular list of the dialog in the */
    /* same state.  Maybe we could just kill it and then replace it  */
    if ((midnight_dlg != NULL) && (old_widget != NULL))
    {
        if (old_widget == view_listing)
        {
            /* save and write directory history of panel
             * ... and other histories of midnight_dlg  */
            dlg_save_history (midnight_dlg);
        }

        dlg_replace_widget (old_widget, new_widget);
    }

    if (type == view_listing)
    {
        WPanel *panel = (WPanel *) new_widget;

        /* if existing panel changed type to view_listing, then load history */
        if (old_widget != NULL)
        {
            ev_history_load_save_t event_data = { NULL, new_widget };

            mc_event_raise (midnight_dlg->event_group, MCEVENT_HISTORY_LOAD, &event_data);
        }

        if (num == 0)
            left_panel = panel;
        else
            right_panel = panel;

        /* forced update format after set new sizes */
        set_panel_formats (panel);
    }

    if (type == view_tree)
        the_tree = (WTree *) new_widget;

    /* Prevent current_panel's value from becoming invalid.
     * It's just a quick hack to prevent segfaults. Comment out and
     * try following:
     * - select left panel
     * - invoke menue left/tree
     * - as long as you stay in the left panel almost everything that uses
     *   current_panel causes segfault, e.g. C-Enter, C-x c, ...
     */
    if ((type != view_listing) && (current_panel == (WPanel *) old_widget))
        current_panel = num == 0 ? right_panel : left_panel;

    g_free (old_widget);
}
Esempio n. 6
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 ("%");

    if (mc_run_mode == 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 = panel->dir.list[panel->selected].fname;
    }
#ifdef USE_INTERNAL_EDIT
    else if (mc_run_mode == MC_RUN_EDITOR)
        fname = (char *) edit_get_file_name (edit_widget);
#endif

    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':
        return (*quote_func) (fname, 0);
    case 'x':
        return (*quote_func) (extension (fname), 0);
    case 'd':
        {
            char *cwd;
            char *qstr;

            cwd = g_malloc (MC_MAXPATHLEN + 1);

            if (panel)
                g_strlcpy (cwd, panel->cwd, MC_MAXPATHLEN + 1);
            else
                mc_get_current_wd (cwd, MC_MAXPATHLEN + 1);

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

            g_free (cwd);

            return qstr;
        }
    case 'i':                  /* indent equal number cursor position in line */
#ifdef USE_INTERNAL_EDIT
        if (edit_widget)
            return g_strnfill (edit_get_curs_col (edit_widget), ' ');
#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)
                return g_strdup (syntax_type);
        }
#endif
        break;
    case 'k':                  /* block file name */
    case 'b':                  /* block file name / strip extension */
        {
#ifdef USE_INTERNAL_EDIT
            if (edit_widget)
            {
                char *file = concat_dir_and_file (mc_config_get_cache_path (), EDIT_BLOCK_FILE);
                fname = (*quote_func) (file, 0);
                g_free (file);
                return fname;
            }
#endif
            if (c_lc == 'b')
                return strip_ext ((*quote_func) (fname, 0));
            break;
        }
    case 'n':                  /* strip extension in editor */
#ifdef USE_INTERNAL_EDIT
        if (edit_widget)
            return strip_ext ((*quote_func) (fname, 0));
#endif
        break;
    case 'm':                  /* menu file name */
        if (menu)
            return (*quote_func) (menu, 0);
        break;
    case 's':
        if (!panel || !panel->marked)
            return (*quote_func) (fname, 0);

        /* Fall through */

    case 't':
    case 'u':
        {
            int length = 2, i;
            char *block, *tmp;

            if (!panel)
                return g_strdup ("");

            for (i = 0; i < panel->count; i++)
                if (panel->dir.list[i].f.marked)
                    length += strlen (panel->dir.list[i].fname) + 1;    /* for space */

            block = g_malloc (length * 2 + 1);
            *block = 0;
            for (i = 0; i < panel->count; i++)
                if (panel->dir.list[i].f.marked)
                {
                    tmp = (*quote_func) (panel->dir.list[i].fname, 0);
                    strcat (block, tmp);
                    g_free (tmp);
                    strcat (block, " ");
                    if (c_lc == 'u')
                        do_file_mark (panel, i, 0);
                }
            return block;
        }                       /* sub case block */
    }                           /* switch */
    result = g_strdup ("% ");
    result[1] = c;
    return result;
}