gboolean exit_subshell (void) { gboolean subshell_quit = TRUE; if (subshell_state != INACTIVE && subshell_alive) subshell_quit = query_dialog (_("Warning"), _("The shell is still active. Quit anyway?"), D_NORMAL, 2, _("&Yes"), _("&No")) == 0; if (subshell_quit) { if (subshell_type == TCSH) { if (unlink (tcsh_fifo) == -1) fprintf (stderr, "Cannot remove named pipe %s: %s\r\n", tcsh_fifo, unix_error_string (errno)); } g_string_free (subshell_prompt, TRUE); subshell_prompt = NULL; pty_buffer[0] = '\0'; } return subshell_quit; }
/* * Run viewer (internal or external) on the currently selected file. * If normal is 1, force internal viewer and raw mode (used for F13). */ static void do_view_cmd (int normal) { int dir, file_idx; /* Directories are viewed by changing to them */ if (S_ISDIR (selection (current_panel)->st.st_mode) || link_isdir (selection (current_panel))) { if (confirm_view_dir && (current_panel->marked || current_panel->dirs_marked)) { if (query_dialog (_(" Confirmation "), _("Files tagged, want to cd?"), 0, 2, _("&Yes"), _("&No")) != 0) { return; } } if (!do_cd (selection (current_panel)->fname, cd_exact)) message (1, MSG_ERROR, _("Cannot change directory")); return; } file_idx = current_panel->selected; while (1) { char *filename; filename = current_panel->dir.list[file_idx].fname; dir = view_file (filename, normal, use_internal_view); if (dir == 0) break; file_idx = scan_for_file (current_panel, file_idx, dir); } }
gboolean mcview_hexedit_save_changes (mcview_t * view) { int answer = 0; if (view->change_list == NULL) return TRUE; while (answer == 0) { int fp; char *text; struct hexedit_change_node *curr, *next; #ifdef HAVE_ASSERT_H assert (view->filename_vpath != NULL); #endif fp = mc_open (view->filename_vpath, O_WRONLY); if (fp != -1) { for (curr = view->change_list; curr != NULL; curr = next) { next = curr->next; if (mc_lseek (fp, curr->offset, SEEK_SET) == -1 || mc_write (fp, &(curr->value), 1) != 1) goto save_error; /* delete the saved item from the change list */ view->change_list = next; view->dirty++; mcview_set_byte (view, curr->offset, curr->value); g_free (curr); } view->change_list = NULL; if (view->locked) view->locked = unlock_file (view->filename_vpath); if (mc_close (fp) == -1) message (D_ERROR, _("Save file"), _("Error while closing the file:\n%s\n" "Data may have been written or not"), unix_error_string (errno)); view->dirty++; return TRUE; } save_error: text = g_strdup_printf (_("Cannot save file:\n%s"), unix_error_string (errno)); (void) mc_close (fp); answer = query_dialog (_("Save file"), text, D_ERROR, 2, _("&Retry"), _("&Cancel")); g_free (text); } return FALSE; }
static void tree_rmdir_cmd (WTree *tree) { off_t count = 0; double bytes = 0; FileOpContext *ctx; if (!tree->selected_ptr) return; if (confirm_delete) { char *buf; int result; buf = g_strdup_printf (_(" Delete %s? "), tree->selected_ptr->name); result = query_dialog (_(" Delete "), buf, 3, 2, _("&Yes"), _("&No")); g_free (buf); if (result != 0) return; } ctx = file_op_context_new (OP_DELETE); file_op_context_create_ui (ctx, FALSE); if (erase_dir (ctx, tree->selected_ptr->name, &count, &bytes) == FILE_CONT) tree_forget_cmd (tree); file_op_context_destroy (ctx); }
/* edit syntax file for mcedit */ void edit_syntax_cmd (void) { char *buffer; char *extdir; int dir = 0; if (geteuid () == 0) { dir = query_dialog (_("Syntax file edit"), _(" Which syntax file you want to edit? "), 0, 2, _("&User"), _("&System Wide")); } extdir = concat_dir_and_file (mc_home, "syntax" PATH_SEP_STR "Syntax"); if (dir == 0) { buffer = concat_dir_and_file (home_dir, SYNTAX_FILE); check_for_default (extdir, buffer); do_edit (buffer); g_free (buffer); } else if (dir == 1) do_edit (extdir); g_free (extdir); }
/** * Run viewer (internal or external) on the currently selected file. * If normal is TRUE, force internal viewer and raw mode (used for F13). */ static void do_view_cmd (gboolean normal) { /* Directories are viewed by changing to them */ if (S_ISDIR (selection (current_panel)->st.st_mode) || link_isdir (selection (current_panel))) { vfs_path_t *fname_vpath; if (confirm_view_dir && (current_panel->marked || current_panel->dirs_marked)) { if (query_dialog (_("Confirmation"), _("Files tagged, want to cd?"), D_NORMAL, 2, _("&Yes"), _("&No")) != 0) { return; } } fname_vpath = vfs_path_from_str (selection (current_panel)->fname); if (!do_cd (fname_vpath, cd_exact)) message (D_ERROR, MSG_ERROR, _("Cannot change directory")); vfs_path_free (fname_vpath); } else { int file_idx; vfs_path_t *filename_vpath; file_idx = current_panel->selected; filename_vpath = vfs_path_from_str (current_panel->dir.list[file_idx].fname); view_file (filename_vpath, normal, use_internal_view != 0); vfs_path_free (filename_vpath); } repaint_screen (); }
void compare_dirs_cmd (void) { int choice; enum CompareMode thorough_flag; choice = query_dialog (_("Compare directories"), _("Select compare method:"), D_NORMAL, 4, _("&Quick"), _("&Size only"), _("&Thorough"), _("&Cancel")); if (choice < 0 || choice > 2) return; thorough_flag = choice; if (get_current_type () == view_listing && get_other_type () == view_listing) { compare_dir (current_panel, other_panel, thorough_flag); compare_dir (other_panel, current_panel, thorough_flag); } else { message (D_ERROR, MSG_ERROR, _("Both panels should be in the listing mode\nto use this command")); } }
static void tree_rmdir (void *data) { WTree *tree = data; file_op_context_t *ctx; file_op_total_context_t *tctx; if (!tree->selected_ptr) return; if (confirm_delete) { char *buf; int result; buf = g_strdup_printf (_("Delete %s?"), vfs_path_as_str (tree->selected_ptr->name)); result = query_dialog (Q_ ("DialogTitle|Delete"), buf, D_ERROR, 2, _("&Yes"), _("&No")); g_free (buf); if (result != 0) return; } ctx = file_op_context_new (OP_DELETE); tctx = file_op_total_context_new (); file_op_context_create_ui (ctx, FALSE, FILEGUI_DIALOG_ONE_ITEM); if (erase_dir (tctx, ctx, tree->selected_ptr->name) == FILE_CONT) tree_forget (tree); file_op_total_context_destroy (tctx); file_op_context_destroy (ctx); }
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 = mc_config_get_full_path (MC_FILEBIND_FILE); 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 (); }
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? "), 0, 2, _("&User"), _("&System Wide")); } extdir = concat_dir_and_file (mc_home, MC_LIB_EXT); if (dir == 0){ buffer = concat_dir_and_file (home_dir, MC_USER_EXT); check_for_default (extdir, buffer); do_edit (buffer); g_free (buffer); } else if (dir == 1) do_edit (extdir); g_free (extdir); flush_extension_file (); }
static int check_sid (void) { pid_t my_sid, old_sid; const char *sid_str; int r; sid_str = getenv ("MC_SID"); if (!sid_str) return 0; old_sid = (pid_t) strtol (sid_str, NULL, 0); if (!old_sid) return 0; my_sid = getsid (0); if (my_sid == -1) return 0; /* The parent mc is in a different session, it's OK */ if (old_sid != my_sid) return 0; r = query_dialog (_("Warning"), _("GNU Midnight Commander is already\n" "running on this terminal.\n" "Subshell support will be disabled."), D_ERROR, 2, _("&OK"), _("&Quit")); if (r != 0) { return 2; } return 1; }
static cb_ret_t listbox_execute_cmd (WListbox * l, long command) { cb_ret_t ret = MSG_HANDLED; Widget *w = WIDGET (l); if (l->list == NULL || g_queue_is_empty (l->list)) return MSG_NOT_HANDLED; switch (command) { case CK_Up: listbox_back (l, TRUE); break; case CK_Down: listbox_fwd (l, TRUE); break; case CK_Top: listbox_select_first (l); break; case CK_Bottom: listbox_select_last (l); break; case CK_PageUp: listbox_back_n (l, w->lines - 1); break; case CK_PageDown: listbox_fwd_n (l, w->lines - 1); break; case CK_Delete: if (l->deletable) { gboolean is_last, is_more; int length; length = g_queue_get_length (l->list); is_last = (l->pos + 1 >= length); is_more = (l->top + w->lines >= length); listbox_remove_current (l); if ((l->top > 0) && (is_last || is_more)) l->top--; } break; case CK_Clear: if (l->deletable && mc_global.widget.confirm_history_cleanup /* TRANSLATORS: no need to translate 'DialogTitle', it's just a context prefix */ && (query_dialog (Q_ ("DialogTitle|History cleanup"), _("Do you want clean this history?"), D_ERROR, 2, _("&Yes"), _("&No")) == 0)) listbox_remove_list (l); break; default: ret = MSG_NOT_HANDLED; } return ret; }
static gboolean learn_check_key (int c) { int i; for (i = 0; i < learn_total; i++) { if (key_name_conv_tab[i].code != c || learnkeys[i].ok) continue; dlg_select_widget (learnkeys[i].button); /* TRANSLATORS: This label appears near learned keys. Keep it short. */ label_set_text (LABEL (learnkeys[i].label), _("OK")); learnkeys[i].ok = TRUE; learnok++; if (learnok >= learn_total) { learn_dlg->ret_value = B_CANCEL; if (learnchanged) { if (query_dialog (learn_title, _ ("It seems that all your keys already\n" "work fine. That's great."), D_ERROR, 2, _("&Save"), _("&Discard")) == 0) learn_dlg->ret_value = B_ENTER; } else { message (D_ERROR, learn_title, _ ("Great! You have a complete terminal database!\n" "All your keys work well.")); } dlg_stop (learn_dlg); } return TRUE; } switch (c) { case KEY_LEFT: case 'h': return learn_move (FALSE); case KEY_RIGHT: case 'l': return learn_move (TRUE); case 'j': dlg_one_down (learn_dlg); return TRUE; case 'k': dlg_one_up (learn_dlg); return TRUE; } /* Prevent from disappearing if a non-defined sequence is pressed and contains a button hotkey. Only recognize hotkeys with ALT. */ return (c < 255 && g_ascii_isalnum (c)); }
static int learn_check_key (int c) { int i; for (i = 0; i < learn_total; i++) { if (key_name_conv_tab [i].code == c) { if (!learnkeys [i].ok) { dlg_select_widget (learn_dlg, learnkeys [i].button); label_set_text ((WLabel *) learnkeys [i].label, _("OK")); learnkeys [i].ok = 1; learnok++; if (learnok >= learn_total) { learn_dlg->ret_value = B_CANCEL; if (learnchanged) { if (query_dialog (learn_title, _("It seems that all your keys already\n" "work fine. That's great."), 1, 2, _("&Save"), _("&Discard")) == 0) learn_dlg->ret_value = B_ENTER; } else { message (1, learn_title, _("Great! You have a complete terminal database!\n" "All your keys work well.")); } dlg_stop (learn_dlg); } return 1; } } } switch (c) { case KEY_LEFT: case 'h': return learn_move (0); case KEY_RIGHT: case 'l': return learn_move (1); case 'j': dlg_one_down (learn_dlg); return 1; case 'k': dlg_one_up (learn_dlg); return 1; } /* Prevent from disappearing if a non-defined sequence is pressed and contains s or c. Use ALT('s') or ALT('c'). */ if (c < 255 && isalpha(c)) { c = toupper(c); for (i = 0; i < BUTTONS; i++) if (c == learn_but [i].hotkey) return 1; } return 0; }
static void edit_about_cmd (void) { query_dialog (_(" About "), _("\n Cooledit v3.11.5\n\n" " Copyright (C) 1996 the Free Software Foundation\n\n" " A user friendly text editor written\n" " for the Midnight Commander.\n"), D_NORMAL, 1, _("&OK")); }
void edit_mc_menu_cmd (void) { vfs_path_t *buffer_vpath; vfs_path_t *menufile_vpath; int dir = 0; query_set_sel (1); dir = query_dialog (_("Menu edit"), _("Which menu file do you want to edit?"), D_NORMAL, geteuid ()? 2 : 3, _("&Local"), _("&User"), _("&System Wide")); menufile_vpath = vfs_path_build_filename (mc_global.sysconfig_dir, MC_GLOBAL_MENU, NULL); if (!exist_file (vfs_path_get_last_path_str (menufile_vpath))) { vfs_path_free (menufile_vpath); menufile_vpath = vfs_path_build_filename (mc_global.share_data_dir, MC_GLOBAL_MENU, NULL); } switch (dir) { case 0: buffer_vpath = vfs_path_from_str (MC_LOCAL_MENU); check_for_default (menufile_vpath, buffer_vpath); chmod (vfs_path_get_last_path_str (buffer_vpath), 0600); break; case 1: buffer_vpath = mc_config_get_full_vpath (MC_USERMENU_FILE); check_for_default (menufile_vpath, buffer_vpath); break; case 2: buffer_vpath = vfs_path_build_filename (mc_global.sysconfig_dir, MC_GLOBAL_MENU, NULL); if (!exist_file (vfs_path_get_last_path_str (buffer_vpath))) { vfs_path_free (buffer_vpath); buffer_vpath = vfs_path_build_filename (mc_global.share_data_dir, MC_GLOBAL_MENU, NULL); } break; default: vfs_path_free (menufile_vpath); return; } do_edit (buffer_vpath); vfs_path_free (buffer_vpath); vfs_path_free (menufile_vpath); }
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 = mc_config_get_full_path (MC_USERMENU_FILE); 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 gnome_quit_cmd (void) { int q = 0; if (!confirm_exit) q = 1; else if (query_dialog (_(" The Midnight Commander "), _(" Do you really want to quit the Midnight Commander? "), 0, 2, _("&Yes"), _("&No")) == 0) q = 1; if (q == 1) gtk_main_quit (); }
static struct WDialog * do_create_message (int flags, const char *title, const char *text) { char *p; WDialog *d; /* Add empty lines before and after the message */ p = g_strconcat ("\n", text, "\n", (char *) NULL); query_dialog (title, p, flags, 0); d = last_query_dlg; /* do resize before initing and running */ send_message (d, NULL, MSG_RESIZE, 0, NULL); dlg_init (d); g_free (p); return d; }
static struct Dlg_head * do_create_message (int flags, const char *title, const char *text) { char *p; Dlg_head *d; /* Add empty lines before and after the message */ p = g_strconcat ("\n", text, "\n", (char *) NULL); query_dialog (title, p, flags, 0); d = last_query_dlg; /* do resize before initing and running */ default_query_callback (d, NULL, DLG_RESIZE, 0, NULL); init_dlg (d); g_free (p); return d; }
void edit_fhl_cmd (void) { vfs_path_t *fhlfile_vpath = 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_vpath = vfs_path_build_filename (mc_global.sysconfig_dir, MC_FHL_INI_FILE, NULL); if (dir == 0) { vfs_path_t *buffer_vpath; buffer_vpath = mc_config_get_full_vpath (MC_FHL_INI_FILE); check_for_default (fhlfile_vpath, buffer_vpath); do_edit (buffer_vpath); vfs_path_free (buffer_vpath); } else if (dir == 1) { if (!exist_file (vfs_path_get_last_path_str (fhlfile_vpath))) { vfs_path_free (fhlfile_vpath); fhlfile_vpath = vfs_path_build_filename (mc_global.sysconfig_dir, MC_FHL_INI_FILE, NULL); } do_edit (fhlfile_vpath); } vfs_path_free (fhlfile_vpath); /* refresh highlighting rules */ mc_fhl_free (&mc_filehighlight); mc_filehighlight = mc_fhl_new (TRUE); }
/* where = 1 - do edit file menu for mcedit */ static void menu_edit_cmd (int where) { char *buffer; char *menufile; int dir = 0; dir = query_dialog ( _(" Menu edit "), _(" Which menu file do you want to edit? "), 0, geteuid() ? 2 : 3, _("&Local"), _("&Home"), _("&System Wide") ); menufile = concat_dir_and_file (mc_home, where ? CEDIT_GLOBAL_MENU : MC_GLOBAL_MENU); switch (dir) { case 0: buffer = g_strdup (where ? CEDIT_LOCAL_MENU : MC_LOCAL_MENU); check_for_default (menufile, buffer); break; case 1: buffer = concat_dir_and_file (home_dir, where ? CEDIT_HOME_MENU : MC_HOME_MENU); check_for_default (menufile, buffer); break; case 2: buffer = concat_dir_and_file (mc_home, where ? CEDIT_GLOBAL_MENU : MC_GLOBAL_MENU); break; default: g_free (menufile); return; } do_edit (buffer); if (dir == 0) chmod(buffer, 0600); g_free (buffer); g_free (menufile); }
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 = mc_config_get_full_path (MC_FHL_INI_FILE); 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); }
void ext_cmd (void) { vfs_path_t *extdir_vpath; 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_vpath = vfs_path_build_filename (mc_global.sysconfig_dir, MC_LIB_EXT, NULL); if (dir == 0) { vfs_path_t *buffer_vpath; buffer_vpath = mc_config_get_full_vpath (MC_FILEBIND_FILE); check_for_default (extdir_vpath, buffer_vpath); do_edit (buffer_vpath); vfs_path_free (buffer_vpath); } else if (dir == 1) { if (!exist_file (vfs_path_get_last_path_str (extdir_vpath))) { vfs_path_free (extdir_vpath); extdir_vpath = vfs_path_build_filename (mc_global.share_data_dir, MC_LIB_EXT, NULL); } do_edit (extdir_vpath); } vfs_path_free (extdir_vpath); flush_extension_file (); }
void mcview_do_search (WView * view, off_t want_search_start) { mcview_search_status_msg_t vsm; off_t search_start = 0; off_t orig_search_start = view->search_start; gboolean found = FALSE; size_t match_len; view->search_start = want_search_start; /* for avoid infinite search loop we need to increase or decrease start offset of search */ if (view->search_start != 0) { if (!view->text_nroff_mode) search_start = view->search_start + (mcview_search_options.backwards ? -2 : 0); else { if (mcview_search_options.backwards) { mcview_nroff_t *nroff; nroff = mcview_nroff_seq_new_num (view, view->search_start); if (mcview_nroff_seq_prev (nroff) != -1) search_start = -(mcview__get_nroff_real_len (view, nroff->index - 1, 2) + nroff->char_length + 1); else search_start = -2; mcview_nroff_seq_free (&nroff); } else { search_start = mcview__get_nroff_real_len (view, view->search_start + 1, 2); } search_start += view->search_start; } } if (mcview_search_options.backwards && search_start < 0) search_start = 0; /* Compute the percent steps */ mcview_search_update_steps (view); view->update_activate = search_start; vsm.first = TRUE; vsm.view = view; vsm.offset = search_start; status_msg_init (STATUS_MSG (&vsm), _("Search"), 1.0, simple_status_msg_init_cb, mcview_search_status_update_cb, NULL); do { off_t growbufsize; if (view->growbuf_in_use) growbufsize = mcview_growbuf_filesize (view); else growbufsize = view->search->original_len; if (mcview_find (&vsm, search_start, mcview_get_filesize (view), &match_len)) { mcview_search_show_result (view, match_len); found = TRUE; break; } if (view->search->error == MC_SEARCH_E_ABORT || view->search->error == MC_SEARCH_E_NOTFOUND) break; search_start = growbufsize - view->search->original_len; } while (search_start > 0 && mcview_may_still_grow (view)); status_msg_deinit (STATUS_MSG (&vsm)); if (orig_search_start != 0 && (!found && view->search->error == MC_SEARCH_E_NOTFOUND) && !mcview_search_options.backwards) { view->search_start = orig_search_start; mcview_update (view); if (query_dialog (_("Search done"), _("Continue from beginning?"), D_NORMAL, 2, _("&Yes"), _("&No")) != 0) found = TRUE; else { /* continue search from beginning */ view->update_activate = 0; vsm.first = TRUE; vsm.view = view; vsm.offset = 0; status_msg_init (STATUS_MSG (&vsm), _("Search"), 1.0, simple_status_msg_init_cb, mcview_search_status_update_cb, NULL); /* search from file begin up to initial search start position */ if (mcview_find (&vsm, 0, orig_search_start, &match_len)) { mcview_search_show_result (view, match_len); found = TRUE; } status_msg_deinit (STATUS_MSG (&vsm)); } } if (!found) { view->search_start = orig_search_start; mcview_update (view); if (view->search->error == MC_SEARCH_E_NOTFOUND) query_dialog (_("Search"), _(STR_E_NOTFOUND), D_NORMAL, 1, _("&Dismiss")); else if (view->search->error_str != NULL) query_dialog (_("Search"), view->search->error_str, D_NORMAL, 1, _("&Dismiss")); } view->dirty++; }
void mcview_do_search (mcview_t * view) { off_t search_start = 0; gboolean isFound = FALSE; gboolean need_search_again = TRUE; Dlg_head *d = NULL; size_t match_len; if (verbose) { d = create_message (D_NORMAL, _("Search"), _("Searching %s"), view->last_search_string); tty_refresh (); } /*for avoid infinite search loop we need to increase or decrease start offset of search */ if (view->search_start != 0) { if (!view->text_nroff_mode) search_start = view->search_start + (mcview_search_options.backwards ? -2 : 0); else { if (mcview_search_options.backwards) { mcview_nroff_t *nroff; nroff = mcview_nroff_seq_new_num (view, view->search_start); if (mcview_nroff_seq_prev (nroff) != -1) search_start = -(mcview__get_nroff_real_len (view, nroff->index - 1, 2) + nroff->char_width + 1); else search_start = -2; mcview_nroff_seq_free (&nroff); } else { search_start = mcview__get_nroff_real_len (view, view->search_start + 1, 2); } search_start += view->search_start; } } if (mcview_search_options.backwards && (int) search_start < 0) search_start = 0; /* Compute the percent steps */ mcview_search_update_steps (view); view->update_activate = 0; tty_enable_interrupt_key (); do { off_t growbufsize; if (view->growbuf_in_use) growbufsize = mcview_growbuf_filesize (view); else growbufsize = view->search->original_len; if (mcview_find (view, search_start, &match_len)) { mcview_search_show_result (view, &d, match_len); need_search_again = FALSE; isFound = TRUE; break; } if (view->search->error_str == NULL) break; search_start = growbufsize - view->search->original_len; if (search_start <= 0) { search_start = 0; break; } } while (mcview_may_still_grow (view)); if (view->search_start != 0 && !isFound && need_search_again && !mcview_search_options.backwards) { int result; mcview_update (view); result = query_dialog (_("Search done"), _("Continue from beginning?"), D_NORMAL, 2, _("&Yes"), _("&No")); if (result != 0) isFound = TRUE; else search_start = 0; } if (!isFound && view->search->error_str != NULL && mcview_find (view, search_start, &match_len)) { mcview_search_show_result (view, &d, match_len); isFound = TRUE; } tty_disable_interrupt_key (); if (verbose) { dlg_run_done (d); destroy_dlg (d); } if (!isFound && view->search->error_str != NULL) message (D_NORMAL, _("Search"), "%s", view->search->error_str); view->dirty++; mcview_update (view); }
int lock_file (const vfs_path_t * fname_vpath) { char *lockfname = NULL, *newlock, *msg, *lock; struct stat statbuf; struct lock_s *lockinfo; gboolean is_local; gboolean symlink_ok = FALSE; const char *elpath; if (fname_vpath == NULL) return 0; elpath = vfs_path_get_by_index (fname_vpath, 0)->path; /* Just to be sure (and don't lock new file) */ if (*elpath == '\0') return 0; /* Locking on VFS is not supported */ is_local = vfs_file_is_local (fname_vpath); if (is_local) { /* Check if already locked */ lockfname = lock_build_symlink_name (fname_vpath); } if (!is_local || lockfname == NULL) return 0; if (lstat (lockfname, &statbuf) == 0) { lock = lock_get_info (lockfname); if (lock == NULL) goto ret; lockinfo = lock_extract_info (lock); /* Check if locking process alive, ask user if required */ if (lockinfo->pid == 0 || !(kill (lockinfo->pid, 0) == -1 && errno == ESRCH)) { msg = g_strdup_printf (_ ("File \"%s\" is already being edited.\n" "User: %s\nProcess ID: %d"), x_basename (lockfname) + 2, lockinfo->who, (int) lockinfo->pid); /* TODO: Implement "Abort" - needs to rewind undo stack */ switch (query_dialog (_("File locked"), msg, D_NORMAL, 2, _("&Grab lock"), _("&Ignore lock"))) { case 0: break; case 1: case -1: g_free (msg); goto ret; break; /* FIXME: unneeded? */ } g_free (msg); } unlink (lockfname); } /* Create lock symlink */ newlock = lock_build_name (); symlink_ok = (symlink (newlock, lockfname) != -1); g_free (newlock); ret: g_free (lockfname); return symlink_ok ? 1 : 0; }
void mcview_do_search (mcview_t * view) { mcview_search_status_msg_t vsm; off_t search_start = 0; gboolean isFound = FALSE; gboolean need_search_again = TRUE; size_t match_len; /* for avoid infinite search loop we need to increase or decrease start offset of search */ if (view->search_start != 0) { if (!view->text_nroff_mode) search_start = view->search_start + (mcview_search_options.backwards ? -2 : 0); else { if (mcview_search_options.backwards) { mcview_nroff_t *nroff; nroff = mcview_nroff_seq_new_num (view, view->search_start); if (mcview_nroff_seq_prev (nroff) != -1) search_start = -(mcview__get_nroff_real_len (view, nroff->index - 1, 2) + nroff->char_width + 1); else search_start = -2; mcview_nroff_seq_free (&nroff); } else { search_start = mcview__get_nroff_real_len (view, view->search_start + 1, 2); } search_start += view->search_start; } } if (mcview_search_options.backwards && (int) search_start < 0) search_start = 0; /* Compute the percent steps */ mcview_search_update_steps (view); view->update_activate = search_start; vsm.first = TRUE; vsm.view = view; vsm.offset = search_start; status_msg_init (STATUS_MSG (&vsm), _("Search"), 1.0, simple_status_msg_init_cb, mcview_search_status_update_cb, NULL); do { off_t growbufsize; if (view->growbuf_in_use) growbufsize = mcview_growbuf_filesize (view); else growbufsize = view->search->original_len; if (mcview_find (&vsm, search_start, mcview_get_filesize (view), &match_len)) { mcview_search_show_result (view, match_len); need_search_again = FALSE; isFound = TRUE; break; } if (view->search->error_str == NULL) break; search_start = growbufsize - view->search->original_len; if (search_start <= 0) { search_start = 0; break; } } while (mcview_may_still_grow (view)); status_msg_deinit (STATUS_MSG (&vsm)); if (view->search_start != 0 && !isFound && need_search_again && !mcview_search_options.backwards) { int result; mcview_update (view); result = query_dialog (_("Search done"), _("Continue from beginning?"), D_NORMAL, 2, _("&Yes"), _("&No")); if (result != 0) isFound = TRUE; else search_start = 0; } if (!isFound && view->search->error_str != NULL) { /* continue search form beginning */ off_t search_end; search_end = view->search_start; /* search_start is 0 here */ view->update_activate = search_start; vsm.first = TRUE; vsm.view = view; vsm.offset = search_start; status_msg_init (STATUS_MSG (&vsm), _("Search"), 1.0, simple_status_msg_init_cb, mcview_search_status_update_cb, NULL); if (mcview_find (&vsm, search_start, search_end, &match_len)) { mcview_search_show_result (view, match_len); isFound = TRUE; } status_msg_deinit (STATUS_MSG (&vsm)); } if (!isFound && view->search->error_str != NULL) query_dialog (_("Search"), view->search->error_str, D_NORMAL, 1, _("&Dismiss")); view->dirty++; }