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 ()); }
static FILE * open_include_file (const char *filename) { FILE *f; MC_PTR_FREE (error_file_name); error_file_name = g_strdup (filename); if (g_path_is_absolute (filename)) return fopen (filename, "r"); g_free (error_file_name); error_file_name = g_build_filename (mc_config_get_data_path (), EDIT_DIR, filename, (char *) NULL); f = fopen (error_file_name, "r"); if (f != NULL) return f; g_free (error_file_name); error_file_name = g_build_filename (mc_global.sysconfig_dir, "syntax", filename, (char *) NULL); f = fopen (error_file_name, "r"); if (f != NULL) return f; g_free (error_file_name); error_file_name = g_build_filename (mc_global.share_data_dir, "syntax", filename, (char *) NULL); return fopen (error_file_name, "r"); }
gboolean mc_skin_ini_file_load (mc_skin_t * mc_skin) { char *file_name; file_name = g_path_get_basename (mc_skin->name); if (file_name == NULL) return FALSE; if (strcmp (file_name, mc_skin->name) != 0) { g_free (file_name); if (!g_path_is_absolute (mc_skin->name)) return FALSE; mc_skin->config = mc_config_init (mc_skin->name, TRUE); return (mc_skin->config != NULL); } g_free (file_name); /* ${XDG_DATA_HOME}/mc/skins/ */ if (mc_skin_ini_file_load_search_in_dir (mc_skin, mc_config_get_data_path ())) return TRUE; /* /etc/mc/skins/ */ if (mc_skin_ini_file_load_search_in_dir (mc_skin, mc_global.sysconfig_dir)) return TRUE; /* /usr/share/mc/skins/ */ return mc_skin_ini_file_load_search_in_dir (mc_skin, mc_global.share_data_dir); }
gboolean mc_fhl_init_from_standard_files (mc_fhl_t * fhl) { gchar *name; gboolean ok; /* ${XDG_CONFIG_HOME}/mc/filehighlight.ini */ name = g_build_filename (mc_config_get_data_path (), MC_FHL_INI_FILE, (char *) NULL); ok = mc_fhl_read_ini_file (fhl, name); g_free (name); if (ok) return TRUE; /* ${sysconfdir}/mc/filehighlight.ini */ name = g_build_filename (mc_global.sysconfig_dir, MC_FHL_INI_FILE, (char *) NULL); ok = mc_fhl_read_ini_file (fhl, name); g_free (name); if (ok) return TRUE; /* ${datadir}/mc/filehighlight.ini */ name = g_build_filename (mc_global.share_data_dir, MC_FHL_INI_FILE, (char *) NULL); ok = mc_fhl_read_ini_file (fhl, name); g_free (name); return ok; }
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; }
void ext_cmd (void) { char *buffer; char *extdir; int dir; dir = 0; if (geteuid () == 0) { dir = query_dialog (_("Extension file edit"), _("Which extension file you want to edit?"), D_NORMAL, 2, _("&User"), _("&System Wide")); } extdir = concat_dir_and_file (mc_global.sysconfig_dir, MC_LIB_EXT); if (dir == 0) { buffer = g_build_filename (mc_config_get_data_path (), MC_FILEBIND_FILE, NULL); check_for_default (extdir, buffer); do_edit (buffer); g_free (buffer); } else if (dir == 1) { if (!exist_file (extdir)) { g_free (extdir); extdir = concat_dir_and_file (mc_global.share_data_dir, MC_LIB_EXT); } do_edit (extdir); } g_free (extdir); flush_extension_file (); }
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; }
GPtrArray * mc_skin_list (void) { GPtrArray *list; list = g_ptr_array_new (); mc_skin_get_list_from_dir (mc_config_get_data_path (), list); mc_skin_get_list_from_dir (mc_global.sysconfig_dir, list); mc_skin_get_list_from_dir (mc_global.share_data_dir, list); g_ptr_array_sort (list, (GCompareFunc) string_array_comparator); return list; }
void edit_mc_menu_cmd (void) { char *buffer; char *menufile; int dir = 0; dir = query_dialog (_("Menu edit"), _("Which menu file do you want to edit?"), D_NORMAL, geteuid ()? 2 : 3, _("&Local"), _("&User"), _("&System Wide")); menufile = concat_dir_and_file (mc_global.sysconfig_dir, MC_GLOBAL_MENU); if (!exist_file (menufile)) { g_free (menufile); menufile = concat_dir_and_file (mc_global.share_data_dir, MC_GLOBAL_MENU); } switch (dir) { case 0: buffer = g_strdup (MC_LOCAL_MENU); check_for_default (menufile, buffer); chmod (buffer, 0600); break; case 1: buffer = g_build_filename (mc_config_get_data_path (), MC_USERMENU_FILE, NULL); check_for_default (menufile, buffer); break; case 2: buffer = concat_dir_and_file (mc_global.sysconfig_dir, MC_GLOBAL_MENU); if (!exist_file (buffer)) { g_free (buffer); buffer = concat_dir_and_file (mc_global.share_data_dir, MC_GLOBAL_MENU); } break; default: g_free (menufile); return; } do_edit (buffer); g_free (buffer); g_free (menufile); }
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 ()); }
gboolean user_menu_cmd (struct WEdit *edit_widget) { char *p; char *data, **entries; int max_cols, menu_lines, menu_limit; int col, i, accept_entry = 1; int selected, old_patterns; Listbox *listbox; gboolean res = FALSE; if (!vfs_current_is_local ()) { message (D_ERROR, MSG_ERROR, "%s", _("Cannot execute commands on non-local filesystems")); return FALSE; } menu = g_strdup (edit_widget ? EDIT_LOCAL_MENU : MC_LOCAL_MENU); if (!exist_file (menu) || !menu_file_own (menu)) { g_free (menu); if (edit_widget) menu = concat_dir_and_file (mc_config_get_data_path (), EDIT_HOME_MENU); else menu = g_build_filename (mc_config_get_data_path (), MC_USERMENU_FILE, NULL); if (!exist_file (menu)) { g_free (menu); menu = concat_dir_and_file (mc_config_get_home_dir (), edit_widget ? EDIT_GLOBAL_MENU : MC_GLOBAL_MENU); if (!exist_file (menu)) { g_free (menu); menu = concat_dir_and_file (mc_sysconfig_dir, edit_widget ? EDIT_GLOBAL_MENU : MC_GLOBAL_MENU); if (!exist_file (menu)) { g_free (menu); menu = concat_dir_and_file (mc_share_data_dir, edit_widget ? EDIT_GLOBAL_MENU : MC_GLOBAL_MENU); } } } } 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)); g_free (menu); menu = NULL; 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 == '#') { /* 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 { 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]); res = TRUE; } do_refresh (); } easy_patterns = old_patterns; g_free (menu); menu = NULL; g_free (entries); g_free (data); return res; }