diff --git a/src/filemanager/cmd.c b/src/filemanager/cmd.c index 1f6eb4c96..c9f96aa45 100644 --- a/src/filemanager/cmd.c +++ b/src/filemanager/cmd.c @@ -522,31 +522,30 @@ view_file_at_line (const vfs_path_t * filename_vpath, gboolean plain_view, gbool if (plain_view) { - int changed_hex_mode = 0; - int changed_nroff_flag = 0; - int changed_magic_flag = 0; + mcview_mode_flags_t changed_flags; - mcview_altered_hex_mode = 0; - mcview_altered_nroff_flag = 0; - mcview_altered_magic_flag = 0; - if (mcview_default_hex_mode) - changed_hex_mode = 1; - if (mcview_default_nroff_flag) - changed_nroff_flag = 1; - if (mcview_default_magic_flag) - changed_magic_flag = 1; - mcview_default_hex_mode = 0; - mcview_default_nroff_flag = 0; - mcview_default_magic_flag = 0; + mcview_clear_mode_flags (&changed_flags); + mcview_altered_flags.hex = FALSE; + mcview_altered_flags.magic = FALSE; + mcview_altered_flags.nroff = FALSE; + if (mcview_global_flags.hex) + changed_flags.hex = TRUE; + if (mcview_global_flags.magic) + changed_flags.magic = TRUE; + if (mcview_global_flags.nroff) + changed_flags.nroff = TRUE; + mcview_global_flags.hex = FALSE; + mcview_global_flags.magic = FALSE; + mcview_global_flags.nroff = FALSE; ret = mcview_viewer (NULL, filename_vpath, start_line, search_start, search_end); - if (changed_hex_mode && !mcview_altered_hex_mode) - mcview_default_hex_mode = 1; - if (changed_nroff_flag && !mcview_altered_nroff_flag) - mcview_default_nroff_flag = 1; - if (changed_magic_flag && !mcview_altered_magic_flag) - mcview_default_magic_flag = 1; + if (changed_flags.hex && !mcview_altered_flags.hex) + mcview_global_flags.hex = TRUE; + if (changed_flags.magic && !mcview_altered_flags.magic) + mcview_global_flags.magic = TRUE; + if (changed_flags.nroff && !mcview_altered_flags.nroff) + mcview_global_flags.nroff = TRUE; dialog_switch_process_pending (); } diff --git a/src/filemanager/ext.c b/src/filemanager/ext.c index 4ca850e0e..f1db07959 100644 --- a/src/filemanager/ext.c +++ b/src/filemanager/ext.c @@ -353,25 +353,34 @@ exec_make_shell_string (const char *lc_data, const vfs_path_t * filename_vpath) static void exec_extension_view (void *target, char *cmd, const vfs_path_t * filename_vpath, int start_line) { - int def_hex_mode = mcview_default_hex_mode, changed_hex_mode = 0; - int def_nroff_flag = mcview_default_nroff_flag, changed_nroff_flag = 0; + mcview_mode_flags_t def_flags = { + /* *INDENT-OFF* */ + .wrap = FALSE, + .hex = mcview_global_flags.hex, + .magic = FALSE, + .nroff = mcview_global_flags.nroff + /* *INDENT-ON* */ + }; - mcview_altered_hex_mode = 0; - mcview_altered_nroff_flag = 0; - if (def_hex_mode != mcview_default_hex_mode) - changed_hex_mode = 1; - if (def_nroff_flag != mcview_default_nroff_flag) - changed_nroff_flag = 1; + mcview_mode_flags_t changed_flags; + + mcview_clear_mode_flags (&changed_flags); + mcview_altered_flags.hex = FALSE; + mcview_altered_flags.nroff = FALSE; + if (def_flags.hex != mcview_global_flags.hex) + changed_flags.hex = TRUE; + if (def_flags.nroff != mcview_global_flags.nroff) + changed_flags.nroff = TRUE; if (target == NULL) mcview_viewer (cmd, filename_vpath, start_line, 0, 0); else mcview_load ((WView *) target, cmd, vfs_path_as_str (filename_vpath), start_line, 0, 0); - if (changed_hex_mode && !mcview_altered_hex_mode) - mcview_default_hex_mode = def_hex_mode; - if (changed_nroff_flag && !mcview_altered_nroff_flag) - mcview_default_nroff_flag = def_nroff_flag; + if (changed_flags.hex && !mcview_altered_flags.hex) + mcview_global_flags.hex = def_flags.hex; + if (changed_flags.nroff && !mcview_altered_flags.nroff) + mcview_global_flags.nroff = def_flags.nroff; dialog_switch_process_pending (); } diff --git a/src/setup.c b/src/setup.c index 430075ced..ac781174d 100644 --- a/src/setup.c +++ b/src/setup.c @@ -302,7 +302,7 @@ static const struct { "mouse_close_dialog", &mouse_close_dialog}, { "fast_refresh", &fast_refresh }, { "drop_menus", &drop_menus }, - { "wrap_mode", &mcview_global_wrap_mode }, + { "wrap_mode", &mcview_global_flags.wrap }, { "old_esc_mode", &old_esc_mode }, { "cd_symlinks", &mc_global.vfs.cd_symlinks }, { "show_all_if_ambiguous", &mc_global.widget.show_all_if_ambiguous }, diff --git a/src/usermenu.c b/src/usermenu.c index 858d7a3ef..3aa6bfb15 100644 --- a/src/usermenu.c +++ b/src/usermenu.c @@ -640,22 +640,22 @@ check_format_view (const char *p) { if (strncmp (q, DEFAULT_CHARSET, 5) == 0) { - mcview_default_hex_mode = 0; + mcview_global_flags.hex = FALSE; q += 4; } else if (strncmp (q, "hex", 3) == 0) { - mcview_default_hex_mode = 1; + mcview_global_flags.hex = TRUE; q += 2; } else if (strncmp (q, "nroff", 5) == 0) { - mcview_default_nroff_flag = 1; + mcview_global_flags.nroff = TRUE; q += 4; } else if (strncmp (q, "unform", 6) == 0) { - mcview_default_nroff_flag = 0; + mcview_global_flags.nroff = FALSE; q += 5; } } diff --git a/src/viewer/actions_cmd.c b/src/viewer/actions_cmd.c index 87743fb8b..2bb9abc1a 100644 --- a/src/viewer/actions_cmd.c +++ b/src/viewer/actions_cmd.c @@ -105,7 +105,7 @@ mcview_search (WView * view, gboolean start_search) { if (mcview_dialog_search (view)) { - if (view->hex_mode) + if (view->mode_flags.hex) want_search_start = view->hex_cursor; mcview_do_search (view, want_search_start); @@ -113,7 +113,7 @@ mcview_search (WView * view, gboolean start_search) } else { - if (view->hex_mode) + if (view->mode_flags.hex) { if (!mcview_search_options.backwards) want_search_start = view->hex_cursor + 1; @@ -459,11 +459,11 @@ mcview_execute_cmd (WView * view, long command) mcview_move_right (view, 1); break; case CK_LeftQuick: - if (!view->hex_mode) + if (!view->mode_flags.hex) mcview_move_left (view, 10); break; case CK_RightQuick: - if (!view->hex_mode) + if (!view->mode_flags.hex) mcview_move_right (view, 10); break; case CK_SearchContinue: @@ -552,7 +552,7 @@ mcview_handle_key (WView * view, int key) key = convert_from_input_c (key); #endif - if (view->hex_mode) + if (view->mode_flags.hex) { if (view->hexedit_mode && (mcview_handle_editkey (view, key) == MSG_HANDLED)) return MSG_HANDLED; @@ -667,7 +667,7 @@ mcview_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void * return MSG_HANDLED; case MSG_CURSOR: - if (view->hex_mode) + if (view->mode_flags.hex) mcview_place_cursor (view); return MSG_HANDLED; diff --git a/src/viewer/ascii.c b/src/viewer/ascii.c index f4b9dcbb4..e7b4833a4 100644 --- a/src/viewer/ascii.c +++ b/src/viewer/ascii.c @@ -402,7 +402,7 @@ mcview_get_next_maybe_nroff_char (WView * view, mcview_state_machine_t * state, if (color != NULL) *color = VIEW_NORMAL_COLOR; - if (!view->text_nroff_mode) + if (!view->mode_flags.nroff) return mcview_get_next_char (view, state, c); if (!mcview_get_next_char (view, state, c)) @@ -583,7 +583,7 @@ mcview_display_line (WView * view, mcview_state_machine_t * state, int row, const screen_dimen top = view->data_area.top; const screen_dimen width = view->data_area.width; const screen_dimen height = view->data_area.height; - off_t dpy_text_column = view->text_wrap_mode ? 0 : view->dpy_text_column; + off_t dpy_text_column = view->mode_flags.wrap ? 0 : view->dpy_text_column; screen_dimen col = 0; int cs[1 + MAX_COMBINING_CHARS]; char str[(1 + MAX_COMBINING_CHARS) * UTF8_CHAR_LEN + 1]; @@ -592,7 +592,7 @@ mcview_display_line (WView * view, mcview_state_machine_t * state, int row, if (paragraph_ended != NULL) *paragraph_ended = TRUE; - if (!view->text_wrap_mode && (row < 0 || row >= (int) height) && linewidth == NULL) + if (!view->mode_flags.wrap && (row < 0 || row >= (int) height) && linewidth == NULL) { /* Optimization: Fast forward to the end of the line, rather than carefully * parsing and then not actually displaying it. */ @@ -661,7 +661,7 @@ mcview_display_line (WView * view, mcview_state_machine_t * state, int row, /* In wrap mode only: We're done with this row if the character sequence wouldn't fit. * Except if at the first column, because then it wouldn't fit in the next row either. * In this extreme case let the unwrapped code below do its best to display it. */ - if (view->text_wrap_mode && (off_t) col + charwidth > dpy_text_column + (off_t) width + if (view->mode_flags.wrap && (off_t) col + charwidth > dpy_text_column + (off_t) width && col > 0) { *state = state_saved; @@ -730,7 +730,7 @@ mcview_display_line (WView * view, mcview_state_machine_t * state, int row, col += charwidth; state->unwrapped_column += charwidth; - if (!view->text_wrap_mode && (off_t) col >= dpy_text_column + (off_t) width + if (!view->mode_flags.wrap && (off_t) col >= dpy_text_column + (off_t) width && linewidth == NULL) { /* Optimization: Fast forward to the end of the line, rather than carefully @@ -870,7 +870,7 @@ mcview_display_text (WView * view) mcview_display_clean (view); mcview_display_ruler (view); - if (!view->text_wrap_mode) + if (!view->mode_flags.wrap) mcview_state_machine_init (&state, view->dpy_start); else { @@ -888,7 +888,7 @@ mcview_display_text (WView * view) * scroll the file and display again. This happens when e.g. the * window is made bigger, or the file becomes shorter due to * charset change or enabling nroff. */ - if ((view->text_wrap_mode ? view->dpy_state_top.offset : view->dpy_start) > 0) + if ((view->mode_flags.wrap ? view->dpy_state_top.offset : view->dpy_start) > 0) { mcview_ascii_move_up (view, height - row); again = TRUE; @@ -940,7 +940,7 @@ mcview_ascii_move_down (WView * view, off_t lines) /* Okay, there's enough data. Move by 1 row at the top, too. No need to check for * EOF, that can't happen. */ - if (!view->text_wrap_mode) + if (!view->mode_flags.wrap) { view->dpy_start = mcview_eol (view, view->dpy_start); view->dpy_paragraph_skip_lines = 0; @@ -977,7 +977,7 @@ mcview_ascii_move_down (WView * view, off_t lines) void mcview_ascii_move_up (WView * view, off_t lines) { - if (!view->text_wrap_mode) + if (!view->mode_flags.wrap) { while (lines-- != 0) view->dpy_start = mcview_bol (view, view->dpy_start - 1, 0); @@ -1027,7 +1027,7 @@ mcview_ascii_move_up (WView * view, off_t lines) void mcview_ascii_moveto_bol (WView * view) { - if (!view->text_wrap_mode) + if (!view->mode_flags.wrap) view->dpy_text_column = 0; } @@ -1036,7 +1036,7 @@ mcview_ascii_moveto_bol (WView * view) void mcview_ascii_moveto_eol (WView * view) { - if (!view->text_wrap_mode) + if (!view->mode_flags.wrap) { mcview_state_machine_t state; off_t linewidth; diff --git a/src/viewer/coord_cache.c b/src/viewer/coord_cache.c index 8091c5047..08d2672f3 100644 --- a/src/viewer/coord_cache.c +++ b/src/viewer/coord_cache.c @@ -312,7 +312,7 @@ mcview_ccache_lookup (WView * view, coord_cache_entry_t * coord, enum ccache_typ if (sorter == CCACHE_OFFSET) cmp_func = mcview_coord_cache_entry_less_offset; - else if (view->text_nroff_mode) + else if (view->mode_flags.nroff) cmp_func = mcview_coord_cache_entry_less_nroff; else cmp_func = mcview_coord_cache_entry_less_plain; @@ -342,7 +342,8 @@ mcview_ccache_lookup (WView * view, coord_cache_entry_t * coord, enum ccache_typ if (!cmp_func (¤t, coord)) { - if (lookup_what == CCACHE_OFFSET && view->text_nroff_mode && nroff_state != NROFF_START) + if (lookup_what == CCACHE_OFFSET && view->mode_flags.nroff + && nroff_state != NROFF_START) { /* don't break here */ } diff --git a/src/viewer/dialogs.c b/src/viewer/dialogs.c index a382878dc..2d5b910e0 100644 --- a/src/viewer/dialogs.c +++ b/src/viewer/dialogs.c @@ -251,12 +251,12 @@ mcview_dialog_goto (WView * view, off_t * offset) if (view->growbuf_in_use) mcview_growbuf_read_all_data (view); *offset = addr * mcview_get_filesize (view) / 100; - if (!view->hex_mode) + 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->hex_mode) + if (!view->mode_flags.hex) { if (view->growbuf_in_use) mcview_growbuf_read_until (view, addr); diff --git a/src/viewer/display.c b/src/viewer/display.c index 12e59deea..f1aa540be 100644 --- a/src/viewer/display.c +++ b/src/viewer/display.c @@ -80,11 +80,11 @@ mcview_set_buttonbar (WView * view) { WDialog *h = WIDGET (view)->owner; WButtonBar *b = find_buttonbar (h); - const global_keymap_t *keymap = view->hex_mode ? viewer_hex_map : viewer_map; + const global_keymap_t *keymap = view->mode_flags.hex ? viewer_hex_map : viewer_map; buttonbar_set_label (b, 1, Q_ ("ButtonBar|Help"), keymap, WIDGET (view)); - if (view->hex_mode) + if (view->mode_flags.hex) { if (view->hexedit_mode) buttonbar_set_label (b, 2, Q_ ("ButtonBar|View"), keymap, WIDGET (view)); @@ -100,7 +100,7 @@ mcview_set_buttonbar (WView * view) } else { - buttonbar_set_label (b, 2, view->text_wrap_mode ? Q_ ("ButtonBar|UnWrap") + buttonbar_set_label (b, 2, view->mode_flags.wrap ? Q_ ("ButtonBar|UnWrap") : Q_ ("ButtonBar|Wrap"), keymap, WIDGET (view)); buttonbar_set_label (b, 4, Q_ ("ButtonBar|Hex"), keymap, WIDGET (view)); buttonbar_set_label (b, 6, "", keymap, WIDGET (view)); @@ -108,13 +108,13 @@ mcview_set_buttonbar (WView * view) } buttonbar_set_label (b, 5, Q_ ("ButtonBar|Goto"), keymap, WIDGET (view)); - buttonbar_set_label (b, 8, view->magic_mode ? Q_ ("ButtonBar|Raw") + buttonbar_set_label (b, 8, view->mode_flags.magic ? Q_ ("ButtonBar|Raw") : Q_ ("ButtonBar|Parse"), keymap, WIDGET (view)); if (!mcview_is_in_panel (view)) /* don't override some panel buttonbar keys */ { buttonbar_set_label (b, 3, Q_ ("ButtonBar|Quit"), keymap, WIDGET (view)); - buttonbar_set_label (b, 9, view->text_nroff_mode ? Q_ ("ButtonBar|Unform") + buttonbar_set_label (b, 9, view->mode_flags.nroff ? Q_ ("ButtonBar|Unform") : Q_ ("ButtonBar|Format"), keymap, WIDGET (view)); buttonbar_set_label (b, 10, Q_ ("ButtonBar|Quit"), keymap, WIDGET (view)); } @@ -165,7 +165,7 @@ mcview_display_status (WView * view) if (width > 40) { widget_move (view, top, width - 32); - if (view->hex_mode) + if (view->mode_flags.hex) tty_printf ("0x%08" PRIxMAX, (uintmax_t) view->hex_cursor); else { @@ -188,7 +188,7 @@ mcview_display_status (WView * view) else tty_print_string (str_fit_to_term (file_label, width - 5, J_LEFT_FIT)); if (width > 26) - mcview_display_percent (view, view->hex_mode ? view->hex_cursor : view->dpy_end); + mcview_display_percent (view, view->mode_flags.hex ? view->hex_cursor : view->dpy_end); } /* --------------------------------------------------------------------------------------------- */ @@ -244,14 +244,10 @@ mcview_update (WView * view) void mcview_display (WView * view) { - if (view->hex_mode) - { + if (view->mode_flags.hex) mcview_display_hex (view); - } else - { mcview_display_text (view); - } mcview_display_status (view); } @@ -285,7 +281,7 @@ mcview_compute_areas (WView * view) view->status_area.height = height; rest -= height; - height = (ruler == RULER_NONE || view->hex_mode) ? 0 : 2; + height = (ruler == RULER_NONE || view->mode_flags.hex) ? 0 : 2; height = MIN (rest, height); view->ruler_area.height = height; rest -= height; diff --git a/src/viewer/internal.h b/src/viewer/internal.h index 1f01195b6..5a14fc4df 100644 --- a/src/viewer/internal.h +++ b/src/viewer/internal.h @@ -134,13 +134,13 @@ struct WView growing buffer */ gboolean growbuf_finished; /* TRUE when all data has been read. */ - /* Editor modes */ - gboolean hex_mode; /* Hexview or Hexedit */ - gboolean hexedit_mode; /* Hexedit */ + mcview_mode_flags_t mode_flags; + + /* Hex editor modes */ + gboolean hexedit_mode; /* Hexview or Hexedit */ gboolean hexview_in_text; /* Is the hexview cursor in the text area? */ - gboolean text_nroff_mode; /* Nroff-style highlighting */ - gboolean text_wrap_mode; /* Wrap text lines to fit them on the screen */ - gboolean magic_mode; /* Preprocess the file using external programs */ + int bytes_per_line; /* Number of bytes per line in hex mode */ + off_t hex_cursor; /* Hexview cursor position in file */ gboolean hexedit_lownibble; /* Are we editing the last significant nibble? */ gboolean locked; /* We hold lock on current file */ @@ -160,7 +160,6 @@ struct WView gboolean dpy_wrap_dirty; /* dpy_state_top needs to be recomputed */ off_t dpy_text_column; /* Number of skipped columns in non-wrap * text mode */ - off_t hex_cursor; /* Hexview cursor position in file */ screen_dimen cursor_col; /* Cursor column */ screen_dimen cursor_row; /* Cursor row */ struct hexedit_change_node *change_list; /* Linked list of changes */ @@ -173,31 +172,25 @@ struct WView int dirty; /* Number of skipped updates */ gboolean dpy_bbar_dirty; /* Does the button bar need to be updated? */ - /* Mode variables */ - int bytes_per_line; /* Number of bytes per line in hex mode */ - - /* Search variables */ - off_t search_start; /* First character to start searching from */ - off_t search_end; /* Length of found string or 0 if none was found */ - - /* Markers */ - int marker; /* mark to use */ - off_t marks[10]; /* 10 marks: 0..9 */ - - off_t update_steps; /* The number of bytes between percent - * increments */ - off_t update_activate; /* Last point where we updated the status */ - - /* converter for translation of text */ - GIConv converter; /* handle of search engine */ mc_search_t *search; gchar *last_search_string; struct mcview_nroff_struct *search_nroff_seq; - + off_t search_start; /* First character to start searching from */ + off_t search_end; /* Length of found string or 0 if none was found */ int search_numNeedSkipChar; + /* Markers */ + int marker; /* mark to use */ + off_t marks[10]; /* 10 marks: 0..9 */ + + off_t update_steps; /* The number of bytes between percent increments */ + off_t update_activate; /* Last point where we updated the status */ + + /* converter for translation of text */ + GIConv converter; + GArray *saved_bookmarks; dir_list *dir; /* List of current directory files diff --git a/src/viewer/lib.c b/src/viewer/lib.c index b623b8a65..c2d7fe170 100644 --- a/src/viewer/lib.c +++ b/src/viewer/lib.c @@ -35,6 +35,7 @@ #include +#include /* memset() */ #include #include "lib/global.h" @@ -74,8 +75,8 @@ mcview_toggle_magic_mode (WView * view) dir_list *dir; int *dir_idx; - mcview_altered_magic_flag = 1; - view->magic_mode = !view->magic_mode; + mcview_altered_flags.magic = TRUE; + view->mode_flags.magic = !view->mode_flags.magic; /* reinit view */ filename = g_strdup (vfs_path_as_str (view->filename_vpath)); @@ -101,7 +102,7 @@ mcview_toggle_magic_mode (WView * view) void mcview_toggle_wrap_mode (WView * view) { - view->text_wrap_mode = !view->text_wrap_mode; + view->mode_flags.wrap = !view->mode_flags.wrap; view->dpy_wrap_dirty = TRUE; view->dpy_bbar_dirty = TRUE; view->dirty++; @@ -112,8 +113,8 @@ mcview_toggle_wrap_mode (WView * view) void mcview_toggle_nroff_mode (WView * view) { - view->text_nroff_mode = !view->text_nroff_mode; - mcview_altered_nroff_flag = 1; + view->mode_flags.nroff = !view->mode_flags.nroff; + mcview_altered_flags.nroff = TRUE; view->dpy_wrap_dirty = TRUE; view->dpy_bbar_dirty = TRUE; view->dirty++; @@ -124,9 +125,9 @@ mcview_toggle_nroff_mode (WView * view) void mcview_toggle_hex_mode (WView * view) { - view->hex_mode = !view->hex_mode; + view->mode_flags.hex = !view->mode_flags.hex; - if (view->hex_mode) + if (view->mode_flags.hex) { view->hex_cursor = view->dpy_start; view->dpy_start = mcview_offset_rounddown (view->dpy_start, view->bytes_per_line); @@ -138,7 +139,7 @@ mcview_toggle_hex_mode (WView * view) view->hex_cursor = view->dpy_start; widget_want_cursor (WIDGET (view), FALSE); } - mcview_altered_hex_mode = 1; + mcview_altered_flags.hex = TRUE; view->dpy_paragraph_skip_lines = 0; view->dpy_wrap_dirty = TRUE; view->dpy_bbar_dirty = TRUE; @@ -206,21 +207,16 @@ mcview_done (WView * view) if (mcview_remember_file_position && view->filename_vpath != NULL) { save_file_position (view->filename_vpath, -1, 0, - view->hex_mode ? view->hex_cursor : view->dpy_start, + view->mode_flags.hex ? view->hex_cursor : view->dpy_start, view->saved_bookmarks); view->saved_bookmarks = NULL; } /* Write back the global viewer mode */ - mcview_default_hex_mode = view->hex_mode; - mcview_default_nroff_flag = view->text_nroff_mode; - mcview_default_magic_flag = view->magic_mode; - mcview_global_wrap_mode = view->text_wrap_mode; + mcview_global_flags = view->mode_flags; /* Free memory used by the viewer */ - /* view->widget needs no destructor */ - vfs_path_free (view->filename_vpath); view->filename_vpath = NULL; vfs_path_free (view->workdir_vpath); @@ -417,7 +413,7 @@ mcview_calc_percent (WView * view, off_t p) return (-1); filesize = mcview_get_filesize (view); - if (view->hex_mode && filesize > 0) + if (view->mode_flags.hex && filesize > 0) { /* p can't be beyond the last char, only over that. Compensate for this. */ filesize--; @@ -434,3 +430,11 @@ mcview_calc_percent (WView * view, off_t p) } /* --------------------------------------------------------------------------------------------- */ + +void +mcview_clear_mode_flags (mcview_mode_flags_t * flags) +{ + memset (flags, 0, sizeof (*flags)); +} + +/* --------------------------------------------------------------------------------------------- */ diff --git a/src/viewer/mcviewer.c b/src/viewer/mcviewer.c index ff71132fe..99bf1b0c2 100644 --- a/src/viewer/mcviewer.c +++ b/src/viewer/mcviewer.c @@ -50,14 +50,19 @@ /*** global variables ****************************************************************************/ -int mcview_default_hex_mode = 0; -int mcview_default_nroff_flag = 0; -gboolean mcview_global_wrap_mode = TRUE; -int mcview_default_magic_flag = 1; +mcview_mode_flags_t mcview_global_flags = { + .wrap = TRUE, + .hex = FALSE, + .magic = TRUE, + .nroff = FALSE +}; -int mcview_altered_hex_mode = 0; -int mcview_altered_magic_flag = 0; -int mcview_altered_nroff_flag = 0; +mcview_mode_flags_t mcview_altered_flags = { + .wrap = FALSE, + .hex = FALSE, + .magic = FALSE, + .nroff = FALSE +}; gboolean mcview_remember_file_position = FALSE; @@ -109,7 +114,7 @@ mcview_mouse_callback (Widget * w, mouse_msg_t msg, mouse_event_t * event) MC_FALLTHROUGH; case MSG_MOUSE_CLICK: - if (!view->text_wrap_mode) + if (!view->mode_flags.wrap) { /* Scrolling left and right */ screen_dimen x; @@ -197,26 +202,23 @@ mcview_new (int y, int x, int lines, int cols, gboolean is_panel) widget_init (w, y, x, lines, cols, mcview_callback, mcview_mouse_callback); w->options |= WOP_SELECTABLE | WOP_TOP_SELECT; - view->hex_mode = FALSE; + mcview_clear_mode_flags (&view->mode_flags); view->hexedit_mode = FALSE; - view->locked = FALSE; view->hexview_in_text = FALSE; - view->text_nroff_mode = FALSE; - view->text_wrap_mode = FALSE; - view->magic_mode = FALSE; + view->locked = FALSE; view->dpy_frame_size = is_panel ? 1 : 0; view->converter = str_cnv_from_term; mcview_init (view); - if (mcview_default_hex_mode) + if (mcview_global_flags.hex) mcview_toggle_hex_mode (view); - if (mcview_default_nroff_flag) + if (mcview_global_flags.nroff) mcview_toggle_nroff_mode (view); - if (mcview_global_wrap_mode) + if (mcview_global_flags.wrap) mcview_toggle_wrap_mode (view); - if (mcview_default_magic_flag) + if (mcview_global_flags.magic) mcview_toggle_magic_mode (view); return view; @@ -306,7 +308,7 @@ mcview_load (WView * view, const char *command, const char *file, int start_line mcview_set_codeset (view); - if (command != NULL && (view->magic_mode || file == NULL || file[0] == '\0')) + if (command != NULL && (view->mode_flags.magic || file == NULL || file[0] == '\0')) retval = mcview_load_command_output (view, command); else if (file != NULL && file[0] != '\0') { @@ -364,7 +366,7 @@ mcview_load (WView * view, const char *command, const char *file, int start_line } else { - if (view->magic_mode) + if (view->mode_flags.magic) { int type; @@ -426,7 +428,7 @@ mcview_load (WView * view, const char *command, const char *file, int start_line new_offset = 0; else new_offset = MIN (new_offset, max_offset); - if (!view->hex_mode) + if (!view->mode_flags.hex) { view->dpy_start = mcview_bol (view, new_offset, 0); view->dpy_wrap_dirty = TRUE; diff --git a/src/viewer/mcviewer.h b/src/viewer/mcviewer.h index 28c05f0ab..d90716c6e 100644 --- a/src/viewer/mcviewer.h +++ b/src/viewer/mcviewer.h @@ -16,16 +16,18 @@ struct WView; typedef struct WView WView; +typedef struct +{ + gboolean wrap; /* Wrap text lines to fit them on the screen */ + gboolean hex; /* Plainview or hexview */ + gboolean magic; /* Preprocess the file using external programs */ + gboolean nroff; /* Nroff-style highlighting */ +} mcview_mode_flags_t; + /*** global variables defined in .c file *********************************************************/ -extern int mcview_default_hex_mode; -extern int mcview_default_nroff_flag; -extern gboolean mcview_global_wrap_mode; -extern int mcview_default_magic_flag; - -extern int mcview_altered_hex_mode; -extern int mcview_altered_magic_flag; -extern int mcview_altered_nroff_flag; +extern mcview_mode_flags_t mcview_global_flags; +extern mcview_mode_flags_t mcview_altered_flags; extern gboolean mcview_remember_file_position; extern int mcview_max_dirt_limit; @@ -49,5 +51,7 @@ extern gboolean mcview_viewer (const char *command, const vfs_path_t * file_vpat extern gboolean mcview_load (WView * view, const char *command, const char *file, int start_line, off_t search_start, off_t search_end); +extern void mcview_clear_mode_flags (mcview_mode_flags_t * flags); + /*** inline functions ****************************************************************************/ #endif /* MC__VIEWER_H */ diff --git a/src/viewer/move.c b/src/viewer/move.c index 1c7eb8c18..b4e1aeb71 100644 --- a/src/viewer/move.c +++ b/src/viewer/move.c @@ -70,7 +70,7 @@ static void mcview_scroll_to_cursor (WView * view) { - if (view->hex_mode) + if (view->mode_flags.hex) { off_t bytes = view->bytes_per_line; off_t cursor = view->hex_cursor; @@ -96,7 +96,7 @@ mcview_movement_fixups (WView * view, gboolean reset_search) mcview_scroll_to_cursor (view); if (reset_search) { - view->search_start = view->hex_mode ? view->hex_cursor : view->dpy_start; + view->search_start = view->mode_flags.hex ? view->hex_cursor : view->dpy_start; view->search_end = view->search_start; } view->dirty++; @@ -109,9 +109,10 @@ mcview_movement_fixups (WView * view, gboolean reset_search) void mcview_move_up (WView * view, off_t lines) { - if (view->hex_mode) + if (view->mode_flags.hex) { off_t bytes = lines * view->bytes_per_line; + if (view->hex_cursor >= bytes) { view->hex_cursor -= bytes; @@ -140,8 +141,10 @@ void mcview_move_down (WView * view, off_t lines) { off_t last_byte; + last_byte = mcview_get_filesize (view); - if (view->hex_mode) + + if (view->mode_flags.hex) { off_t i, limit; @@ -170,7 +173,7 @@ mcview_move_down (WView * view, off_t lines) void mcview_move_left (WView * view, off_t columns) { - if (view->hex_mode) + if (view->mode_flags.hex) { off_t old_cursor = view->hex_cursor; @@ -185,7 +188,7 @@ mcview_move_left (WView * view, off_t columns) if (old_cursor > 0 || view->hexedit_lownibble) view->hexedit_lownibble = !view->hexedit_lownibble; } - else if (!view->text_wrap_mode) + else if (!view->mode_flags.wrap) view->dpy_text_column = mcview_offset_doz (view->dpy_text_column, columns); mcview_movement_fixups (view, FALSE); } @@ -195,7 +198,7 @@ mcview_move_left (WView * view, off_t columns) void mcview_move_right (WView * view, off_t columns) { - if (view->hex_mode) + if (view->mode_flags.hex) { off_t last_byte; off_t old_cursor = view->hex_cursor; @@ -213,7 +216,7 @@ mcview_move_right (WView * view, off_t columns) if (old_cursor < last_byte || !view->hexedit_lownibble) view->hexedit_lownibble = !view->hexedit_lownibble; } - else if (!view->text_wrap_mode) + else if (!view->mode_flags.wrap) { view->dpy_text_column += columns; } @@ -247,7 +250,7 @@ mcview_moveto_bottom (WView * view) filesize = mcview_get_filesize (view); - if (view->hex_mode) + if (view->mode_flags.hex) { view->hex_cursor = mcview_offset_doz (filesize, 1); mcview_movement_fixups (view, TRUE); @@ -268,7 +271,7 @@ mcview_moveto_bottom (WView * view) void mcview_moveto_bol (WView * view) { - if (view->hex_mode) + if (view->mode_flags.hex) { view->hex_cursor -= view->hex_cursor % view->bytes_per_line; view->dpy_text_column = 0; @@ -286,7 +289,8 @@ void mcview_moveto_eol (WView * view) { off_t bol; - if (view->hex_mode) + + if (view->mode_flags.hex) { off_t filesize; @@ -313,7 +317,7 @@ mcview_moveto_eol (WView * view) void mcview_moveto_offset (WView * view, off_t offset) { - if (view->hex_mode) + if (view->mode_flags.hex) { view->hex_cursor = offset; view->dpy_start = offset - offset % view->bytes_per_line; @@ -365,7 +369,7 @@ mcview_offset_to_coord (WView * view, off_t * ret_line, off_t * ret_column, off_ mcview_ccache_lookup (view, &coord, CCACHE_LINECOL); *ret_line = coord.cc_line; - *ret_column = (view->text_nroff_mode) ? coord.cc_nroff_column : coord.cc_column; + *ret_column = view->mode_flags.nroff ? coord.cc_nroff_column : coord.cc_column; } /* --------------------------------------------------------------------------------------------- */ @@ -389,7 +393,7 @@ mcview_place_cursor (WView * view) void mcview_moveto_match (WView * view) { - if (view->hex_mode) + if (view->mode_flags.hex) { view->hex_cursor = view->search_start; view->hexedit_lownibble = FALSE; diff --git a/src/viewer/nroff.c b/src/viewer/nroff.c index 5791efce3..ba1a064b3 100644 --- a/src/viewer/nroff.c +++ b/src/viewer/nroff.c @@ -97,7 +97,7 @@ mcview__get_nroff_real_len (WView * view, off_t start, off_t length) int ret = 0; off_t i = 0; - if (!view->text_nroff_mode) + if (!view->mode_flags.nroff) return 0; nroff = mcview_nroff_seq_new_num (view, start); diff --git a/src/viewer/search.c b/src/viewer/search.c index 453826618..8dc6170e5 100644 --- a/src/viewer/search.c +++ b/src/viewer/search.c @@ -148,7 +148,7 @@ mcview_find (mcview_search_status_msg_t * ssm, off_t search_start, off_t search_ ok = mc_search_run (view->search, (void *) ssm, search_start, search_end, len); if (ok && view->search->normal_offset == search_start) { - if (view->text_nroff_mode) + if (view->mode_flags.nroff) view->search->normal_offset++; return TRUE; } @@ -178,17 +178,17 @@ mcview_search_show_result (WView * view, size_t match_len) int nroff_len; nroff_len = - view->text_nroff_mode + view->mode_flags.nroff ? mcview__get_nroff_real_len (view, view->search->start_buffer, view->search->normal_offset - view->search->start_buffer) : 0; view->search_start = view->search->normal_offset + nroff_len; - if (!view->hex_mode) + if (!view->mode_flags.hex) view->search_start++; nroff_len = - view->text_nroff_mode ? mcview__get_nroff_real_len (view, view->search_start - 1, - match_len) : 0; + view->mode_flags.nroff ? mcview__get_nroff_real_len (view, view->search_start - 1, + match_len) : 0; view->search_end = view->search_start + match_len + nroff_len; mcview_moveto_match (view); @@ -204,7 +204,7 @@ mcview_search_cmd_callback (const void *user_data, gsize char_offset, int *curre WView *view = ((const mcview_search_status_msg_t *) user_data)->view; /* view_read_continue (view, &view->search_onechar_info); *//* AB:FIXME */ - if (!view->text_nroff_mode) + if (!view->mode_flags.nroff) { mcview_get_byte (view, char_offset, current_char); return MC_SEARCH_CB_OK; @@ -309,7 +309,7 @@ mcview_do_search (WView * view, off_t want_search_start) if (view->search_start != 0) { - if (!view->text_nroff_mode) + if (!view->mode_flags.nroff) search_start = view->search_start + (mcview_search_options.backwards ? -2 : 0); else {