static void frontend_dlg_run (WDialog * h) { Widget *wh = WIDGET (h); Gpm_Event event; event.x = -1; /* close opened editors, viewers, etc */ if (!widget_get_state (wh, WST_MODAL) && mc_global.midnight_shutdown) { send_message (h, NULL, MSG_VALIDATE, 0, NULL); return; } while (widget_get_state (wh, WST_ACTIVE)) { int d_key; if (mc_global.tty.winch_flag != 0) dialog_change_screen_size (); if (is_idle ()) { if (idle_hook) execute_hooks (idle_hook); while (widget_get_state (wh, WST_IDLE) && is_idle ()) send_message (wh, NULL, MSG_IDLE, 0, NULL); /* Allow terminating the dialog from the idle handler */ if (!widget_get_state (wh, WST_ACTIVE)) break; } update_cursor (h); /* Clear interrupt flag */ tty_got_interrupt (); d_key = tty_get_event (&event, h->mouse_status == MOU_REPEAT, TRUE); dlg_process_event (h, d_key, &event); if (widget_get_state (wh, WST_CLOSED)) send_message (h, NULL, MSG_VALIDATE, 0, NULL); } }
void dlg_process_event (WDialog * h, int key, Gpm_Event * event) { if (key == EV_NONE) { if (tty_got_interrupt ()) if (send_message (h, NULL, MSG_ACTION, CK_Cancel, NULL) != MSG_HANDLED) dlg_execute_cmd (h, CK_Cancel); return; } if (key == EV_MOUSE) h->mouse_status = dlg_mouse_event (h, event); else dlg_key_event (h, key); }
void dlg_process_event (Dlg_head * h, int key, Gpm_Event * event) { if (key == EV_NONE) { if (tty_got_interrupt ()) if (h->callback (h, NULL, DLG_ACTION, CK_Cancel, NULL) != MSG_HANDLED) dlg_execute_cmd (h, CK_Cancel); return; } if (key == EV_MOUSE) h->mouse_status = dlg_mouse_event (h, event); else dlg_key_event (h, key); }
static void frontend_run_dlg (Dlg_head * h) { int d_key; Gpm_Event event; event.x = -1; /* close opened editors, viewers, etc */ if (!h->modal && mc_global.midnight_shutdown) { h->callback (h, NULL, DLG_VALIDATE, 0, NULL); return; } while (h->state == DLG_ACTIVE) { if (mc_global.tty.winch_flag) dialog_change_screen_size (); if (is_idle ()) { if (idle_hook) execute_hooks (idle_hook); while ((h->flags & DLG_WANT_IDLE) && is_idle ()) h->callback (h, NULL, DLG_IDLE, 0, NULL); /* Allow terminating the dialog from the idle handler */ if (h->state != DLG_ACTIVE) break; } update_cursor (h); /* Clear interrupt flag */ tty_got_interrupt (); d_key = tty_get_event (&event, h->mouse_status == MOU_REPEAT, TRUE); dlg_process_event (h, d_key, &event); if (h->state == DLG_CLOSED) h->callback (h, NULL, DLG_VALIDATE, 0, NULL); } }
void dlg_process_event (WDialog * h, int key, Gpm_Event * event) { switch (key) { case EV_NONE: if (tty_got_interrupt ()) dlg_execute_cmd (h, CK_Cancel); break; case EV_MOUSE: h->mouse_status = dlg_mouse_event (h, event); break; default: dlg_key_event (h, key); break; } }
int mcview_search_update_cmd_callback (const void *user_data, gsize char_offset) { mcview_t *view = (mcview_t *) user_data; if (char_offset >= (gsize) view->update_activate) { view->update_activate += view->update_steps; if (verbose) { mcview_percent (view, char_offset); tty_refresh (); } if (tty_got_interrupt ()) return MC_SEARCH_CB_ABORT; } /* may be in future return from this callback will change current position * in searching block. Now this just constant return value. */ return MC_SEARCH_CB_OK; }
static int sftpfs_open_socket (struct vfs_s_super *super, GError ** error) { struct addrinfo hints, *res = NULL, *curr_res; int my_socket = 0; char port[BUF_TINY]; int e; if (super->path_element->host == NULL || *super->path_element->host == '\0') { g_set_error (error, MC_ERROR, -1, _("sftp: Invalid host name.")); return -1; } sprintf (port, "%hu", (unsigned short) super->path_element->port); if (port == NULL) { g_set_error (error, MC_ERROR, -1, _("sftp: Invalid port value.")); return -1; } tty_enable_interrupt_key (); /* clear the interrupt flag */ memset (&hints, 0, sizeof (struct addrinfo)); hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; #ifdef AI_ADDRCONFIG /* By default, only look up addresses using address types for * which a local interface is configured (i.e. no IPv6 if no IPv6 * interfaces, likewise for IPv4 (see RFC 3493 for details). */ hints.ai_flags = AI_ADDRCONFIG; #endif e = getaddrinfo (super->path_element->host, port, &hints, &res); #ifdef AI_ADDRCONFIG if (e == EAI_BADFLAGS) { /* Retry with no flags if AI_ADDRCONFIG was rejected. */ hints.ai_flags = 0; e = getaddrinfo (super->path_element->host, port, &hints, &res); } #endif if (e != 0) { g_set_error (error, MC_ERROR, -1, _("sftp: %s"), gai_strerror (e)); my_socket = -1; goto ret; } for (curr_res = res; curr_res != NULL; curr_res = curr_res->ai_next) { my_socket = socket (curr_res->ai_family, curr_res->ai_socktype, curr_res->ai_protocol); if (my_socket < 0) { if (curr_res->ai_next != NULL) continue; vfs_print_message (_("sftp: %s"), unix_error_string (errno)); my_socket = -1; goto ret; } vfs_print_message (_("sftp: making connection to %s"), super->path_element->host); if (connect (my_socket, curr_res->ai_addr, curr_res->ai_addrlen) >= 0) break; close (my_socket); if (errno == EINTR && tty_got_interrupt ()) g_set_error (error, MC_ERROR, -1, _("sftp: connection interrupted by user")); else if (res->ai_next == NULL) g_set_error (error, MC_ERROR, -1, _("sftp: connection to server failed: %s"), unix_error_string (errno)); else continue; my_socket = -1; break; } ret: if (res != NULL) freeaddrinfo (res); tty_disable_interrupt_key (); return my_socket; }
void mcview_ccache_lookup (mcview_t * view, coord_cache_entry_t * coord, enum ccache_type lookup_what) { size_t i; coord_cache_t *cache; coord_cache_entry_t current, next, entry; enum ccache_type sorter; off_t limit; cmp_func_t cmp_func; enum { NROFF_START, NROFF_BACKSPACE, NROFF_CONTINUATION } nroff_state; if (view->coord_cache == NULL) view->coord_cache = coord_cache_new (); cache = view->coord_cache; if (cache->size == 0) { current.cc_offset = 0; current.cc_line = 0; current.cc_column = 0; current.cc_nroff_column = 0; mcview_ccache_add_entry (cache, 0, ¤t); } sorter = (lookup_what == CCACHE_OFFSET) ? CCACHE_LINECOL : CCACHE_OFFSET; if (sorter == CCACHE_OFFSET) cmp_func = mcview_coord_cache_entry_less_offset; else if (view->text_nroff_mode) cmp_func = mcview_coord_cache_entry_less_nroff; else cmp_func = mcview_coord_cache_entry_less_plain; tty_enable_interrupt_key (); retry: /* find the two neighbor entries in the cache */ i = mcview_ccache_find (view, coord, cmp_func); /* now i points to the lower neighbor in the cache */ current = *cache->cache[i]; if (i + 1 < view->coord_cache->size) limit = cache->cache[i + 1]->cc_offset; else limit = current.cc_offset + VIEW_COORD_CACHE_GRANUL; entry = current; nroff_state = NROFF_START; for (; current.cc_offset < limit; current = next) { int c, nextc; if (!mcview_get_byte (view, current.cc_offset, &c)) break; if (!cmp_func (¤t, coord)) { if (lookup_what == CCACHE_OFFSET && view->text_nroff_mode && nroff_state != NROFF_START) { /* don't break here */ } else { break; } } /* Provide useful default values for ''next'' */ next.cc_offset = current.cc_offset + 1; next.cc_line = current.cc_line; next.cc_column = current.cc_column + 1; next.cc_nroff_column = current.cc_nroff_column + 1; /* and override some of them as necessary. */ if (c == '\r') { mcview_get_byte_indexed (view, current.cc_offset, 1, &nextc); /* Ignore '\r' if it is followed by '\r' or '\n'. If it is * followed by anything else, it is a Mac line ending and * produces a line break. */ if (nextc == '\r' || nextc == '\n') { next.cc_column = current.cc_column; next.cc_nroff_column = current.cc_nroff_column; } else { next.cc_line = current.cc_line + 1; next.cc_column = 0; next.cc_nroff_column = 0; } } else if (nroff_state == NROFF_BACKSPACE) { next.cc_nroff_column = current.cc_nroff_column - 1; } else if (c == '\t') { next.cc_column = mcview_offset_rounddown (current.cc_column, 8) + 8; next.cc_nroff_column = mcview_offset_rounddown (current.cc_nroff_column, 8) + 8; } else if (c == '\n') { next.cc_line = current.cc_line + 1; next.cc_column = 0; next.cc_nroff_column = 0; } else { /* Use all default values from above */ } switch (nroff_state) { case NROFF_START: case NROFF_CONTINUATION: nroff_state = mcview_is_nroff_sequence (view, current.cc_offset) ? NROFF_BACKSPACE : NROFF_START; break; case NROFF_BACKSPACE: nroff_state = NROFF_CONTINUATION; break; } /* Cache entries must guarantee that for each i < j, * line[i] <= line[j] and column[i] < column[j]. In the case of * nroff sequences and '\r' characters, this is not guaranteed, * so we cannot save them. */ if (nroff_state == NROFF_START && c != '\r') entry = next; } if (i + 1 == cache->size && entry.cc_offset != cache->cache[i]->cc_offset) { mcview_ccache_add_entry (cache, cache->size, &entry); if (!tty_got_interrupt ()) goto retry; } tty_disable_interrupt_key (); if (lookup_what == CCACHE_OFFSET) { coord->cc_offset = current.cc_offset; } else { coord->cc_line = current.cc_line; coord->cc_column = current.cc_column; coord->cc_nroff_column = current.cc_nroff_column; } }