コード例 #1
0
/**
  Get name of config file.

 \param subdir
 if not NULL, then config also search into specified subdir.

 \param config_file_name
 If specified filename is relative, then will search in standart patches.

 \return
 Newly allocated path to config name or NULL if file not found.

 If config_file_name is a relative path, then search config in stantart paths.
*/
static char *
load_setup_get_full_config_name (const char *subdir, const char *config_file_name)
{
    /*
       TODO: IMHO, in future this function must be placed into mc_config module.
     */
    char *lc_basename, *ret;

    if (config_file_name == NULL)
        return NULL;

    if (g_path_is_absolute (config_file_name))
        return g_strdup (config_file_name);


    lc_basename = g_path_get_basename (config_file_name);
    if (lc_basename == NULL)
        return NULL;

    if (subdir != NULL)
        ret = g_build_filename (mc_config_get_path (), subdir, lc_basename, NULL);
    else
        ret = g_build_filename (mc_config_get_path (), lc_basename, NULL);

    if (exist_file (ret))
    {
        g_free (lc_basename);
        return ret;
    }
    g_free (ret);

    if (subdir != NULL)
        ret = g_build_filename (mc_sysconfig_dir, subdir, lc_basename, NULL);
    else
        ret = g_build_filename (mc_sysconfig_dir, lc_basename, NULL);

    if (exist_file (ret))
    {
        g_free (lc_basename);
        return ret;
    }
    g_free (ret);

    if (subdir != NULL)
        ret = g_build_filename (mc_share_data_dir, subdir, lc_basename, NULL);
    else
        ret = g_build_filename (mc_share_data_dir, lc_basename, NULL);

    g_free (lc_basename);

    if (exist_file (ret))
        return ret;

    g_free (ret);
    return NULL;

}
コード例 #2
0
ファイル: textconf.c プロジェクト: ilia-maslakov/mc
void
show_datadirs_extended (void)
{
    PRINTF_GROUP (_("System data"));

    PRINTF_SECTION (_("Config directory:"), mc_global.sysconfig_dir);
    PRINTF_SECTION (_("Data directory:"), mc_global.share_data_dir);

#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

    PRINTF_SECTION2 (_("Cache directory:"), mc_config_get_cache_path ());

}
コード例 #3
0
ファイル: editwidget.c プロジェクト: BpArCuCTeMbI/mc
gboolean
edit_files (const GList * files)
{
    static gboolean made_directory = FALSE;
    WDialog *edit_dlg;
    WMenuBar *menubar;
    const GList *file;
    gboolean ok = FALSE;

    if (!made_directory)
    {
        char *dir;

        dir = mc_build_filename (mc_config_get_cache_path (), EDIT_DIR, NULL);
        made_directory = (mkdir (dir, 0700) != -1 || errno == EEXIST);
        g_free (dir);

        dir = mc_build_filename (mc_config_get_path (), EDIT_DIR, NULL);
        made_directory = (mkdir (dir, 0700) != -1 || errno == EEXIST);
        g_free (dir);

        dir = mc_build_filename (mc_config_get_data_path (), EDIT_DIR, NULL);
        made_directory = (mkdir (dir, 0700) != -1 || errno == EEXIST);
        g_free (dir);
    }

    /* Create a new dialog and add it widgets to it */
    edit_dlg =
        dlg_create (FALSE, 0, 0, LINES, COLS, NULL, edit_dialog_callback, edit_dialog_event,
                    "[Internal File Editor]", NULL, DLG_WANT_TAB);

    edit_dlg->get_shortcut = edit_get_shortcut;
    edit_dlg->get_title = edit_get_title;

    menubar = menubar_new (0, 0, COLS, NULL, TRUE);
    add_widget (edit_dlg, menubar);
    edit_init_menu (menubar);

    add_widget (edit_dlg, buttonbar_new (TRUE));

    for (file = files; file != NULL; file = g_list_next (file))
    {
        Widget *w = WIDGET (edit_dlg);
        mcedit_arg_t *f = (mcedit_arg_t *) file->data;
        gboolean f_ok;

        f_ok = edit_add_window (edit_dlg, w->y + 1, w->x, w->lines - 2, w->cols, f->file_vpath,
                                f->line_number);
        /* at least one file has been opened succefully */
        ok = ok || f_ok;
    }

    if (ok)
        dlg_run (edit_dlg);

    if (!ok || edit_dlg->state == DLG_CLOSED)
        dlg_destroy (edit_dlg);

    return ok;
}
コード例 #4
0
ファイル: editwidget.c プロジェクト: artzub/mc
int
edit_file (const char *_file, int line)
{
    static gboolean made_directory = FALSE;
    Dlg_head *edit_dlg;
    WEdit *wedit;
    WMenuBar *menubar;

    if (!made_directory)
    {
        char *dir = concat_dir_and_file (mc_config_get_cache_path (), EDIT_DIR);
        made_directory = (mkdir (dir, 0700) != -1 || errno == EEXIST);
        g_free (dir);

        dir = concat_dir_and_file (mc_config_get_path (), EDIT_DIR);
        made_directory = (mkdir (dir, 0700) != -1 || errno == EEXIST);
        g_free (dir);

        dir = concat_dir_and_file (mc_config_get_data_path (), EDIT_DIR);
        made_directory = (mkdir (dir, 0700) != -1 || errno == EEXIST);
        g_free (dir);
    }

    wedit = edit_init (NULL, 1, 0, LINES - 2, COLS, _file, line);

    if (wedit == NULL)
        return 0;

    /* Create a new dialog and add it widgets to it */
    edit_dlg =
        create_dlg (FALSE, 0, 0, LINES, COLS, NULL, edit_dialog_callback,
                    "[Internal File Editor]", NULL, DLG_WANT_TAB);

    edit_dlg->get_shortcut = edit_get_shortcut;
    edit_dlg->get_title = edit_get_title;

    menubar = menubar_new (0, 0, COLS, NULL);
    add_widget (edit_dlg, menubar);
    edit_init_menu (menubar);

    init_widget (&wedit->widget, wedit->widget.y, wedit->widget.x,
                 wedit->widget.lines, wedit->widget.cols, edit_callback, edit_event);
    widget_want_cursor (wedit->widget, TRUE);

    add_widget (edit_dlg, wedit);

    add_widget (edit_dlg, buttonbar_new (TRUE));

    run_dlg (edit_dlg);

    if (edit_dlg->state == DLG_CLOSED)
        destroy_dlg (edit_dlg);

    return 1;
}
コード例 #5
0
static mc_config_t *
load_setup_get_keymap_profile_config (void)
{
    /*
       TODO: IMHO, in future this function must be placed into mc_config module.
     */
    mc_config_t *keymap_config = NULL;
    char *fname, *fname2;

    /* 1) /usr/share/mc (mc_share_data_dir) */
    fname = g_build_filename (mc_share_data_dir, GLOBAL_KEYMAP_FILE, NULL);
    load_setup_init_config_from_file (&keymap_config, fname);
    g_free (fname);

    /* 2) /etc/mc (mc_sysconfig_dir) */
    fname = g_build_filename (mc_sysconfig_dir, GLOBAL_KEYMAP_FILE, NULL);
    load_setup_init_config_from_file (&keymap_config, fname);
    g_free (fname);

    /* 3) ${XDG_CONFIG_HOME}/mc */
    fname = g_build_filename (mc_config_get_path (), GLOBAL_KEYMAP_FILE, NULL);
    load_setup_init_config_from_file (&keymap_config, fname);
    g_free (fname);

    /* 4) main config; [Midnight Commander] -> keymap */

    fname2 =
        mc_config_get_string (mc_main_config, CONFIG_APP_SECTION, "keymap", GLOBAL_KEYMAP_FILE);
    fname = load_setup_get_full_config_name (NULL, fname2);
    if (fname != NULL)
    {
        load_setup_init_config_from_file (&keymap_config, fname);
        g_free (fname);
    }
    g_free (fname2);

    /* 5) getenv("MC_KEYMAP") */
    fname = load_setup_get_full_config_name (NULL, g_getenv ("MC_KEYMAP"));
    if (fname != NULL)
    {
        load_setup_init_config_from_file (&keymap_config, fname);
        g_free (fname);
    }

    /* 6) --keymap=<keymap> */
    fname = load_setup_get_full_config_name (NULL, mc_args__keymap_file);
    if (fname != NULL)
    {
        load_setup_init_config_from_file (&keymap_config, fname);
        g_free (fname);
    }

    return keymap_config;
}
コード例 #6
0
void
save_layout (void)
{
    char *profile;
    size_t i;

    profile = g_build_filename (mc_config_get_path (), MC_CONFIG_FILE, NULL);
    /* Save integer options */
    for (i = 0; layout[i].opt_name != NULL; i++)
        mc_config_set_int (mc_main_config, "Layout", layout[i].opt_name, *layout[i].opt_addr);
    mc_config_save_to_file (mc_main_config, profile, NULL);
    g_free (profile);
}
コード例 #7
0
ファイル: cmd.c プロジェクト: artzub/mc
void
save_setup_cmd (void)
{
    char *d1;
    const char *d2;

    d1 = g_build_filename (mc_config_get_path (), MC_CONFIG_FILE, (char *) NULL);
    d2 = strip_home_and_password (d1);
    g_free (d1);

    if (save_setup (TRUE, TRUE))
        message (D_NORMAL, _("Setup"), _("Setup saved to %s"), d2);
    else
        message (D_ERROR, _("Setup"), _("Unable to save setup to %s"), d2);
}
コード例 #8
0
gboolean
save_setup (gboolean save_options, gboolean save_panel_options)
{
    gboolean ret = TRUE;

    saving_setup = 1;

    save_hotlist ();

    if (save_panel_options)
        save_panel_types ();

    if (save_options)
    {
        char *tmp_profile;

        save_config ();
        save_layout ();
        panels_save_options ();
        save_panelize ();
        /* directory_history_save (); */

#ifdef ENABLE_VFS_FTP
        mc_config_set_string (mc_main_config, "Misc", "ftpfs_password", ftpfs_anonymous_passwd);
        if (ftpfs_proxy_host)
            mc_config_set_string (mc_main_config, "Misc", "ftp_proxy_host", ftpfs_proxy_host);
#endif /* ENABLE_VFS_FTP */

#ifdef HAVE_CHARSET
        mc_config_set_string (mc_main_config, "Misc", "display_codepage",
                              get_codepage_id (display_codepage));
        mc_config_set_string (mc_main_config, "Misc", "source_codepage",
                              get_codepage_id (default_source_codepage));
        mc_config_set_string (mc_main_config, "Misc", "autodetect_codeset", autodetect_codeset);
#endif /* HAVE_CHARSET */
        mc_config_set_string (mc_main_config, "Misc", "clipboard_store", clipboard_store_path);
        mc_config_set_string (mc_main_config, "Misc", "clipboard_paste", clipboard_paste_path);

        tmp_profile = g_build_filename (mc_config_get_path (), MC_CONFIG_FILE, NULL);
        ret = mc_config_save_to_file (mc_main_config, tmp_profile, NULL);

        g_free (tmp_profile);
    }

    saving_setup = 0;

    return ret;
}
コード例 #9
0
ファイル: cmd.c プロジェクト: NoSeungHwan/mc_kor_dev
void
save_setup_cmd (void)
{
    vfs_path_t *vpath;
    const char *path;

    vpath = vfs_path_from_str_flags (mc_config_get_path (), VPF_STRIP_HOME);
    path = vfs_path_as_str (vpath);

    if (save_setup (TRUE, TRUE))
        message (D_NORMAL, _("Setup"), _("Setup saved to %s"), path);
    else
        message (D_ERROR, _("Setup"), _("Unable to save setup to %s"), path);

    vfs_path_free (vpath);
}
コード例 #10
0
ファイル: textconf.c プロジェクト: CTU-OSP/mc
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 ());

}
コード例 #11
0
ファイル: cmd.c プロジェクト: artzub/mc
void
edit_fhl_cmd (void)
{
    char *buffer = NULL;
    char *fhlfile = NULL;

    int dir;

    dir = 0;
    if (geteuid () == 0)
    {
        dir = query_dialog (_("Highlighting groups file edit"),
                            _("Which highlighting file you want to edit?"), D_NORMAL, 2,
                            _("&User"), _("&System Wide"));
    }
    fhlfile = concat_dir_and_file (mc_global.sysconfig_dir, MC_FHL_INI_FILE);

    if (dir == 0)
    {
        buffer = g_build_filename (mc_config_get_path (), MC_FHL_INI_FILE, NULL);
        check_for_default (fhlfile, buffer);
        do_edit (buffer);
        g_free (buffer);
    }
    else if (dir == 1)
    {
        if (!exist_file (fhlfile))
        {
            g_free (fhlfile);
            fhlfile = concat_dir_and_file (mc_global.sysconfig_dir, MC_FHL_INI_FILE);
        }
        do_edit (fhlfile);
    }
    g_free (fhlfile);

    /* refresh highlighting rules */
    mc_fhl_free (&mc_filehighlight);
    mc_filehighlight = mc_fhl_new (TRUE);
}
コード例 #12
0
char *
setup_init (void)
{
    char *profile;
    char *inifile;

    if (profile_name != NULL)
        return profile_name;

    profile = g_build_filename (mc_config_get_path (), MC_CONFIG_FILE, NULL);
    if (!exist_file (profile))
    {
        inifile = concat_dir_and_file (mc_sysconfig_dir, "mc.ini");
        if (exist_file (inifile))
        {
            g_free (profile);
            profile = inifile;
        }
        else
        {
            g_free (inifile);
            inifile = concat_dir_and_file (mc_share_data_dir, "mc.ini");
            if (exist_file (inifile))
            {
                g_free (profile);
                profile = inifile;
            }
            else
                g_free (inifile);
        }
    }

    profile_name = profile;

    return profile;
}
コード例 #13
0
void
save_config (void)
{
    char *profile;
    GError *error = NULL;
    size_t i;

    profile = g_build_filename (mc_config_get_path (), MC_CONFIG_FILE, NULL);

    /* Save integer options */
    for (i = 0; int_options[i].opt_name != NULL; i++)
        mc_config_set_int (mc_main_config, CONFIG_APP_SECTION, int_options[i].opt_name,
                           *int_options[i].opt_addr);

    /* Save string options */
    for (i = 0; str_options[i].opt_name != NULL; i++)
        mc_config_set_string (mc_main_config, CONFIG_APP_SECTION, str_options[i].opt_name,
                              *str_options[i].opt_addr);

    if (!mc_config_save_to_file (mc_main_config, profile, &error))
        setup_save_config_show_error (profile, &error);

    g_free (profile);
}
コード例 #14
0
ファイル: setup.c プロジェクト: CyberShadow/mc
static char *
load_setup_get_full_config_name (const char *subdir, const char *config_file_name)
{
    /*
       TODO: IMHO, in future, this function shall be placed in mcconfig module.
     */
    char *lc_basename, *ret;
    char *file_name;

    if (config_file_name == NULL)
        return NULL;

    /* check for .keymap suffix */
    if (g_str_has_suffix (config_file_name, ".keymap"))
        file_name = g_strdup (config_file_name);
    else
        file_name = g_strconcat (config_file_name, ".keymap", (char *) NULL);

    canonicalize_pathname (file_name);

    if (g_path_is_absolute (file_name))
        return file_name;

    lc_basename = g_path_get_basename (file_name);
    g_free (file_name);

    if (lc_basename == NULL)
        return NULL;

    if (subdir != NULL)
        ret = g_build_filename (mc_config_get_path (), subdir, lc_basename, NULL);
    else
        ret = g_build_filename (mc_config_get_path (), lc_basename, NULL);

    if (exist_file (ret))
    {
        g_free (lc_basename);
        canonicalize_pathname (ret);
        return ret;
    }
    g_free (ret);

    if (subdir != NULL)
        ret = g_build_filename (mc_global.sysconfig_dir, subdir, lc_basename, NULL);
    else
        ret = g_build_filename (mc_global.sysconfig_dir, lc_basename, NULL);

    if (exist_file (ret))
    {
        g_free (lc_basename);
        canonicalize_pathname (ret);
        return ret;
    }
    g_free (ret);

    if (subdir != NULL)
        ret = g_build_filename (mc_global.share_data_dir, subdir, lc_basename, NULL);
    else
        ret = g_build_filename (mc_global.share_data_dir, lc_basename, NULL);

    g_free (lc_basename);

    if (exist_file (ret))
    {
        canonicalize_pathname (ret);
        return ret;
    }

    g_free (ret);
    return NULL;
}
コード例 #15
0
ファイル: subshell.c プロジェクト: artzub/mc
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));
        _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? */
    }

    /* 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 = g_build_filename (mc_config_get_path (), "bashrc", NULL);

        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 = g_build_filename (mc_config_get_path (), "inputrc", NULL);
            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);
        _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 (shell, "bash", "-rcfile", init_file, (char *) NULL);
        break;

    case TCSH:
        execl (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 (shell, "zsh", "-Z", "-g", (char *) NULL);

        break;

    case FISH:
        execl (shell, "fish", (char *) NULL);
        break;
    }

    /* If we get this far, everything failed miserably */
    g_free (init_file);
    _exit (FORK_FAILURE);
}