void mcview_moveto (WView * view, off_t line, off_t col) { off_t offset; mcview_coord_to_offset (view, &offset, line, col); mcview_moveto_offset (view, offset); }
gboolean mcview_dialog_goto (WView * view, off_t * offset) { typedef enum { MC_VIEW_GOTO_LINENUM = 0, MC_VIEW_GOTO_PERCENT = 1, MC_VIEW_GOTO_OFFSET_DEC = 2, MC_VIEW_GOTO_OFFSET_HEX = 3 } mcview_goto_type_t; const char *mc_view_goto_str[] = { N_("&Line number"), N_("Pe&rcents"), N_("&Decimal offset"), N_("He&xadecimal offset") }; static mcview_goto_type_t current_goto_type = MC_VIEW_GOTO_LINENUM; size_t num_of_types; char *exp = NULL; int qd_result; gboolean res; num_of_types = G_N_ELEMENTS (mc_view_goto_str); #ifdef ENABLE_NLS { size_t i; for (i = 0; i < num_of_types; i++) mc_view_goto_str[i] = _(mc_view_goto_str[i]); } #endif { quick_widget_t quick_widgets[] = { /* *INDENT-OFF* */ QUICK_INPUT (INPUT_LAST_TEXT, MC_HISTORY_VIEW_GOTO, &exp, NULL, FALSE, FALSE, INPUT_COMPLETE_NONE), QUICK_RADIO (num_of_types, (const char **) mc_view_goto_str, (int *) ¤t_goto_type, NULL), QUICK_BUTTONS_OK_CANCEL, QUICK_END /* *INDENT-ON* */ }; quick_dialog_t qdlg = { -1, -1, 40, N_("Goto"), "[Input Line Keys]", quick_widgets, NULL, NULL }; /* run dialog */ qd_result = quick_dialog (&qdlg); } *offset = -1; /* check input line value */ res = (qd_result != B_CANCEL && exp != NULL && exp[0] != '\0'); if (res) { int base = (current_goto_type == MC_VIEW_GOTO_OFFSET_HEX) ? 16 : 10; off_t addr; char *error; addr = (off_t) g_ascii_strtoll (exp, &error, base); if ((*error == '\0') && (addr >= 0)) { switch (current_goto_type) { case MC_VIEW_GOTO_LINENUM: /* Line number entered by user is 1-based. */ if (addr > 0) addr--; mcview_coord_to_offset (view, offset, addr, 0); *offset = mcview_bol (view, *offset, 0); break; case MC_VIEW_GOTO_PERCENT: if (addr > 100) addr = 100; /* read all data from pipe to get real size */ if (view->growbuf_in_use) mcview_growbuf_read_all_data (view); *offset = addr * mcview_get_filesize (view) / 100; if (!view->mode_flags.hex) *offset = mcview_bol (view, *offset, 0); break; case MC_VIEW_GOTO_OFFSET_DEC: case MC_VIEW_GOTO_OFFSET_HEX: if (!view->mode_flags.hex) { if (view->growbuf_in_use) mcview_growbuf_read_until (view, addr); *offset = mcview_bol (view, addr, 0); } else { /* read all data from pipe to get real size */ if (view->growbuf_in_use) mcview_growbuf_read_all_data (view); *offset = addr; addr = mcview_get_filesize (view); if (*offset > addr) *offset = addr; } break; default: *offset = 0; break; } } } g_free (exp); return res; }
gboolean mcview_dialog_goto (mcview_t * view, off_t * offset) { typedef enum { MC_VIEW_GOTO_LINENUM = 0, MC_VIEW_GOTO_PERCENT = 1, MC_VIEW_GOTO_OFFSET_DEC = 2, MC_VIEW_GOTO_OFFSET_HEX = 3 } mcview_goto_type_t; const char *mc_view_goto_str[] = { N_("&Line number (decimal)"), N_("Pe&rcents"), N_("&Decimal offset"), N_("He&xadecimal offset") }; const int goto_dlg_height = 12; int goto_dlg_width = 40; static mcview_goto_type_t current_goto_type = MC_VIEW_GOTO_LINENUM; size_t i; size_t num_of_types = sizeof (mc_view_goto_str) / sizeof (mc_view_goto_str[0]); char *exp = NULL; int qd_result; gboolean res = FALSE; QuickWidget quick_widgets[] = { QUICK_BUTTON (6, 10, goto_dlg_height - 3, goto_dlg_height, N_("&Cancel"), B_CANCEL, NULL), QUICK_BUTTON (2, 10, goto_dlg_height - 3, goto_dlg_height, N_("&OK"), B_ENTER, NULL), QUICK_RADIO (3, goto_dlg_width, 4, goto_dlg_height, num_of_types, (const char **) mc_view_goto_str, (int *) ¤t_goto_type), QUICK_INPUT (3, goto_dlg_width, 2, goto_dlg_height, INPUT_LAST_TEXT, goto_dlg_width - 6, 0, MC_HISTORY_VIEW_GOTO, &exp), QUICK_END }; QuickDialog Quick_input = { goto_dlg_width, goto_dlg_height, -1, -1, N_("Goto"), "[Input Line Keys]", quick_widgets, NULL, NULL, FALSE }; #ifdef ENABLE_NLS for (i = 0; i < num_of_types; i++) mc_view_goto_str[i] = _(mc_view_goto_str[i]); quick_widgets[0].u.button.text = _(quick_widgets[0].u.button.text); quick_widgets[1].u.button.text = _(quick_widgets[1].u.button.text); #endif /* calculate widget coordinates */ { int b0_len, b1_len, len; const int button_gap = 2; /* preliminary dialog width */ goto_dlg_width = max (goto_dlg_width, str_term_width1 (Quick_input.title) + 4); /* length of radiobuttons */ for (i = 0; i < num_of_types; i++) goto_dlg_width = max (goto_dlg_width, str_term_width1 (mc_view_goto_str[i]) + 10); /* length of buttons */ b0_len = str_term_width1 (quick_widgets[0].u.button.text) + 3; b1_len = str_term_width1 (quick_widgets[1].u.button.text) + 5; /* default button */ len = b0_len + b1_len + button_gap * 2; /* dialog width */ Quick_input.xlen = max (goto_dlg_width, len + 6); /* correct widget coordinates */ for (i = sizeof (quick_widgets) / sizeof (quick_widgets[0]); i > 0; i--) quick_widgets[i - 1].x_divisions = Quick_input.xlen; /* input length */ quick_widgets[3].u.input.len = Quick_input.xlen - 6; /* button positions */ quick_widgets[1].relative_x = Quick_input.xlen / 2 - len / 2; quick_widgets[0].relative_x = quick_widgets[1].relative_x + b1_len + button_gap; } /* run dialog */ qd_result = quick_dialog (&Quick_input); *offset = -1; /* check input line value */ if ((qd_result != B_CANCEL) && (exp != NULL) && (exp[0] != '\0')) { int base = (current_goto_type == MC_VIEW_GOTO_OFFSET_HEX) ? 16 : 10; off_t addr; char *error; res = TRUE; addr = strtoll (exp, &error, base); if ((*error == '\0') && (addr >= 0)) { switch (current_goto_type) { case MC_VIEW_GOTO_LINENUM: mcview_coord_to_offset (view, offset, addr, 0); *offset = mcview_bol (view, *offset, 0); break; case MC_VIEW_GOTO_PERCENT: if (addr > 100) addr = 100; *offset = addr * mcview_get_filesize (view) / 100; if (!view->hex_mode) *offset = mcview_bol (view, *offset, 0); break; case MC_VIEW_GOTO_OFFSET_DEC: case MC_VIEW_GOTO_OFFSET_HEX: *offset = addr; if (!view->hex_mode) *offset = mcview_bol (view, *offset, 0); else { addr = mcview_get_filesize (view); if (*offset > addr) *offset = addr; } break; default: *offset = 0; break; } } } g_free (exp); return res; }
void mcview_ccache_dump (mcview_t * view) { FILE *f; off_t offset, line, column, nextline_offset, filesize; guint i; const coord_cache_t *cache = view->coord_cache; #ifdef HAVE_ASSERT_H assert (cache != NULL); #endif filesize = mcview_get_filesize (view); f = fopen ("mcview-ccache.out", "w"); if (f == NULL) return; (void) setvbuf (f, NULL, _IONBF, 0); /* cache entries */ for (i = 0; i < cache->size; i++) { (void) fprintf (f, "entry %8u offset %8" PRIuMAX " line %8" PRIuMAX " column %8" PRIuMAX " nroff_column %8" PRIuMAX "\n", (unsigned int) i, (uintmax_t) cache->cache[i]->cc_offset, (uintmax_t) cache->cache[i]->cc_line, (uintmax_t) cache->cache[i]->cc_column, (uintmax_t) cache->cache[i]->cc_nroff_column); } (void) fprintf (f, "\n"); /* offset -> line/column translation */ for (offset = 0; offset < filesize; offset++) { mcview_offset_to_coord (view, &line, &column, offset); (void) fprintf (f, "offset %8" PRIuMAX " line %8" PRIuMAX " column %8" PRIuMAX "\n", (uintmax_t) offset, (uintmax_t) line, (uintmax_t) column); } /* line/column -> offset translation */ for (line = 0; TRUE; line++) { mcview_coord_to_offset (view, &nextline_offset, line + 1, 0); (void) fprintf (f, "nextline_offset %8" PRIuMAX "\n", (uintmax_t) nextline_offset); for (column = 0; TRUE; column++) { mcview_coord_to_offset (view, &offset, line, column); if (offset >= nextline_offset) break; (void) fprintf (f, "line %8" PRIuMAX " column %8" PRIuMAX " offset %8" PRIuMAX "\n", (uintmax_t) line, (uintmax_t) column, (uintmax_t) offset); } if (nextline_offset >= filesize - 1) break; } (void) fclose (f); }