Ticket #2977: mc.qview2.diff
File mc.qview2.diff, 19.4 KB (added by szaszg, 12 years ago) |
---|
-
lib/util.c
diff --git a/lib/util.c b/lib/util.c index 4c4aeb0..e6cfa56 100644
a b get_compression_type (int fd, const char *name) 846 846 } 847 847 } 848 848 849 /* JPEG files GIF8 */ 850 if (((magic[0] == 'G') && (magic[1] == 'I') && (magic[2] == 'F') && (magic[3] == '8')) || /* GIF */ 851 ((magic[0] == 0x89) && (magic[1] == 'P') && (magic[2] == 'N') && (magic[3] == 'G')) || /* PNG */ 852 ((magic[0] == 0xff) && (magic[1] == 0xd8) && (magic[2] == 0xff) && ((magic[3]&0xfe) == 0xe0)) /* JFIF or EXIF ff d8 ff e{0,1} */ 853 ) 854 { 855 return COMPRESSION_IMG; 856 } 857 849 858 /* Support for LZMA (only utils format with magic in header). 850 859 * This is the default format of LZMA utils 4.32.1 and later. */ 851 860 … … decompress_extension (int type) 890 899 return "/ulzma" VFS_PATH_URL_DELIMITER; 891 900 case COMPRESSION_XZ: 892 901 return "/uxz" VFS_PATH_URL_DELIMITER; 902 case COMPRESSION_IMG: 903 return "/img" VFS_PATH_URL_DELIMITER; 893 904 } 894 905 /* Should never reach this place */ 895 906 fprintf (stderr, "Fatal: decompress_extension called with an unknown argument\n"); -
lib/util.h
diff --git a/lib/util.h b/lib/util.h index f0c0ee2..d4a3c0f 100644
a b enum compression_type 44 44 COMPRESSION_BZIP, 45 45 COMPRESSION_BZIP2, 46 46 COMPRESSION_LZMA, 47 COMPRESSION_XZ 47 COMPRESSION_XZ, 48 49 COMPRESSION_IMG, 48 50 }; 49 51 50 52 /*** structures declarations (and typedefs of structures)*****************************************/ -
misc/ext.d/image.sh
diff --git a/misc/ext.d/image.sh b/misc/ext.d/image.sh index 61e3bc2..747b6b4 100644
a b 6 6 action=$1 7 7 filetype=$2 8 8 9 IMG2TXT=img2txt 10 command -v img2txt -h 1>/dev/null 2>&1 || IMG2TXT='echo -n ""' 9 11 [ -n "${MC_XDG_OPEN}" ] || MC_XDG_OPEN="xdg-open" 10 12 11 13 do_view_action() { … … do_view_action() { 13 15 14 16 case "${filetype}" in 15 17 jpeg) 16 identify "${MC_EXT_FILENAME}"; test -x /usr/bin/exif && echo && exif "${MC_EXT_FILENAME}" 2>/dev/null 18 identify "${MC_EXT_FILENAME}" 19 $IMG2TXT "${MC_EXT_FILENAME}"; test -x /usr/bin/exif && echo "[9999m" && exif "${MC_EXT_FILENAME}" 2>/dev/null 17 20 ;; 18 21 xpm) 19 22 sxpm "${MC_EXT_FILENAME}" 20 23 ;; 21 24 *) 22 25 identify "${MC_EXT_FILENAME}" 26 $IMG2TXT "${MC_EXT_FILENAME}" 23 27 ;; 24 28 esac 25 29 } -
src/vfs/extfs/helpers/sfs.ini
diff --git a/src/vfs/extfs/helpers/sfs.ini b/src/vfs/extfs/helpers/sfs.ini index 522cca1..cc564c6 100644
a b cr/1 fromdos < %1 > %3 26 26 url:2 lynx -source `echo "%2" | sed 's-|-/-g'` > %3 27 27 nop/1 cat %1 > %3 28 28 strings/1 strings %1 > %3 29 30 img/1 img2txt > %3 %1 -
src/viewer/Makefile.am
diff --git a/src/viewer/Makefile.am b/src/viewer/Makefile.am index 53bc7a4..d92d1f4 100644
a b libmcviewer_la_SOURCES = \ 17 17 move.c \ 18 18 nroff.c \ 19 19 plain.c \ 20 ansi.c \ 20 21 search.c 21 22 22 23 AM_CPPFLAGS = -I$(top_srcdir) $(GLIB_CFLAGS) $(PCRE_CPPFLAGS) -
new file src/viewer/ansi.c
diff --git a/src/viewer/ansi.c b/src/viewer/ansi.c new file mode 100644 index 0000000..e30b504
- + 1 /* 2 Internal file viewer for the Midnight Commander 3 Function for raw (ansi) view 4 5 Copyright (C) 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2003, 6 2004, 2005, 2006, 2007, 2009, 2011 7 The Free Software Foundation, Inc. 8 9 Written by: 10 Gergely Szasz 2013 11 12 This file is part of the Midnight Commander. 13 14 The Midnight Commander is free software: you can redistribute it 15 and/or modify it under the terms of the GNU General Public License as 16 published by the Free Software Foundation, either version 3 of the License, 17 or (at your option) any later version. 18 19 The Midnight Commander is distributed in the hope that it will be useful, 20 but WITHOUT ANY WARRANTY; without even the implied warranty of 21 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 22 GNU General Public License for more details. 23 24 You should have received a copy of the GNU General Public License 25 along with this program. If not, see <http://www.gnu.org/licenses/>. 26 */ 27 28 #include <config.h> 29 30 #include "lib/global.h" 31 #include "lib/tty/tty.h" 32 #include "lib/skin.h" 33 #include "lib/util.h" /* is_printable() */ 34 #ifdef HAVE_CHARSET 35 #include "lib/charsets.h" 36 #endif 37 38 #include "src/setup.h" /* option_tab_spacing */ 39 40 #include "internal.h" 41 #include "mcviewer.h" /* mcview_show_eof */ 42 43 /*** global variables ****************************************************************************/ 44 45 /*** file scope macro definitions ****************************************************************/ 46 /* we play maximum 1M files */ 47 #define MAX_ANSI_SIZE (1024*1024) 48 49 /*** file scope type declarations ****************************************************************/ 50 51 /*** file scope variables ************************************************************************/ 52 static const char *color_names[] = { 53 "black", "red", "green", "brown", "blue", "magenta", "cyan", "lightgray", 54 "gray", "brightred", "brightgreen", "yellow", "brightblue", "brightmagenta", "brightcyan", "white", 55 }; 56 57 /*** file scope functions ************************************************************************/ 58 /* --------------------------------------------------------------------------------------------- */ 59 static const char *get_color (int color, int bright) { 60 return bright ? color_names[0 + color] : color_names[8 + color]; 61 } 62 63 /* --------------------------------------------------------------------------------------------- */ 64 /*** public functions ****************************************************************************/ 65 /* --------------------------------------------------------------------------------------------- */ 66 /* --------------------------------------------------------------------------------------------- */ 67 68 enum nroff_high_type 69 get_nroff_high_type (mcview_t * view) 70 { 71 int c, state = 0; 72 off_t i = 0; 73 74 if (mcview_get_filesize(view) > MAX_ANSI_SIZE) 75 return NROFF_HIGH_NROFF; 76 77 while (i < 256) 78 { 79 if (!mcview_get_byte (view, i++, &c)) 80 break; 81 if (state == 0 && c == 033) 82 { 83 state = 1; 84 } 85 else if (state == 1 && c == '[') 86 { 87 state = 2; 88 } 89 else if (state == 2 && c >= '0' && c <= '9') 90 { 91 return NROFF_HIGH_ANSI; 92 } 93 else 94 { 95 state = 0; 96 } 97 } 98 return NROFF_HIGH_NROFF; 99 } 100 101 /* --------------------------------------------------------------------------------------------- */ 102 103 #define ANSI_NONE 0 104 #define ANSI_ESC 1 105 #define ANSI_SQUARE 2 106 #define ANSI_ANSI 3 107 108 void 109 mcview_display_ansi (mcview_t * view) 110 { 111 const screen_dimen left = view->data_area.left; 112 const screen_dimen top = view->data_area.top; 113 const screen_dimen width = view->data_area.width; 114 const screen_dimen height = view->data_area.height; 115 screen_dimen row = 0, col = 0; 116 off_t from, chk_from = 0; 117 int cw = 1; 118 int c, prev_ch = 0; 119 gboolean last_row = TRUE; 120 /* struct hexedit_change_node *curr = view->change_list; */ 121 int ansi_state = ANSI_NONE, ansi_check = 0, fg = 0, bg = 0, br = 0, bl = 0; 122 int ansi_puffer_idx = -1, ansi_puffer_i = 0; 123 char ansi_puffer[128]; 124 125 mcview_display_clean (view); 126 mcview_display_ruler (view); 127 128 /* Find the first displayable changed byte */ 129 from = view->dpy_start; 130 if (from > 0) 131 { 132 c = 'x'; 133 chk_from = from; 134 while (from > 0) 135 { 136 mcview_get_byte (view, --from, &c); 137 if (c == '\r' || c == '\n') { 138 from++; 139 break; 140 } 141 } 142 ansi_check = 1; /* now from == start of line; chck_from = real from*/ 143 } 144 /* while ((curr != NULL) && (curr->offset < from)) 145 curr = curr->next; */ 146 147 tty_setcolor (NORMAL_COLOR); 148 while (TRUE) 149 { 150 151 if (row >= height) 152 break; 153 154 if (ansi_state != ANSI_NONE && ansi_puffer_idx >= 127) { 155 ansi_puffer_idx = -1; 156 ansi_state = ANSI_NONE; 157 } 158 if (ansi_state == ANSI_NONE && ansi_puffer_idx >= 0) { 159 c = ansi_puffer[ansi_puffer_i++]; 160 ansi_puffer_idx--; 161 } else { 162 #ifdef HAVE_CHARSET 163 if (view->utf8) 164 { 165 gboolean read_res = TRUE; 166 167 c = mcview_get_utf (view, from, &cw, &read_res); 168 if (!read_res) 169 break; 170 } 171 else 172 #endif 173 if (!mcview_get_byte (view, from, &c)) 174 break; 175 from++; 176 if (cw > 1) 177 from += cw - 1; 178 } 179 180 last_row = FALSE; 181 182 if (ansi_state == ANSI_NONE && c == '\033') { /* ESC? */ 183 ansi_state = ANSI_ESC; 184 ansi_puffer[(ansi_puffer_i = ansi_puffer_idx = 0)] = c; 185 continue; 186 } else if (ansi_state == ANSI_ESC) { /* ^[ ? */ 187 ansi_puffer[++ansi_puffer_idx] = c; 188 if (c == '[') { 189 ansi_state = ANSI_SQUARE; 190 continue; 191 } else { 192 ansi_puffer_idx = -1; 193 ansi_state = ANSI_NONE; 194 } 195 } else if (ansi_state == ANSI_SQUARE) { /* ^[ ? */ 196 ansi_puffer[++ansi_puffer_idx] = c; 197 if (c == ';' || (c >= '0' && c <= '9')) { 198 ansi_state = ANSI_SQUARE; 199 continue; 200 } else if (c == 'm') { /* ^[#;#;#m */ 201 int color; 202 int num = 0, n = 0, i = 2; 203 204 ansi_puffer[ansi_puffer_idx++] = ';'; /* ^[#;#;#; */ 205 ansi_puffer[ansi_puffer_idx] = '\0'; 206 while (sscanf(ansi_puffer+i, "%d;%n", &num, &n) == 1) { 207 if (num == 0 ) 208 br = bl = 0; 209 else if (num == 1) 210 br = 1; 211 else if (num == 5) 212 bl = 1; 213 else if (num >= 30 && num <= 37) 214 fg = num - 30; 215 else if (num >= 40 && num <= 47) 216 bg = num - 40; 217 else if (num == 9999) 218 fg = -1; 219 i += n; 220 } 221 if (fg == -1) 222 { 223 tty_setcolor (NORMAL_COLOR); 224 } 225 else 226 { 227 color = tty_try_alloc_color_pair(get_color(fg, br), get_color(bg, bl), NULL); 228 tty_setcolor(color); 229 } 230 ansi_puffer_idx = -1; 231 ansi_state = ANSI_NONE; 232 continue; 233 } else { 234 ansi_puffer_idx = -1; 235 ansi_state = ANSI_NONE; 236 continue; 237 } 238 } 239 if (ansi_check && from < chk_from) 240 { 241 continue; 242 } 243 else if (ansi_check && from >= chk_from) 244 { 245 ansi_check = 0; 246 } 247 248 if (c != '\n' && prev_ch == '\r') 249 { 250 if (++row >= height) 251 break; 252 253 col = 0; 254 } 255 256 prev_ch = c; 257 if (c == '\r') 258 continue; 259 260 if (c == '\n') 261 { 262 col = 0; 263 row++; 264 continue; 265 } 266 267 268 if (c == '\t') 269 { 270 col += (option_tab_spacing - col % option_tab_spacing); 271 continue; 272 } 273 274 if (0 && view->search_start <= from && from < view->search_end) /****INFO no search highlite */ 275 tty_setcolor (SELECTED_COLOR); 276 277 if (((off_t) col >= view->dpy_text_column) 278 && ((off_t) col - view->dpy_text_column < (off_t) width)) 279 { 280 widget_move (view, top + row, left + ((off_t) col - view->dpy_text_column)); 281 #ifdef HAVE_CHARSET 282 if (mc_global.utf8_display) 283 { 284 if (!view->utf8) 285 c = convert_from_8bit_to_utf_c ((unsigned char) c, view->converter); 286 if (!g_unichar_isprint (c)) 287 c = '.'; 288 } 289 else if (view->utf8) 290 c = convert_from_utf_to_current_c (c, view->converter); 291 else 292 #endif 293 { 294 #ifdef HAVE_CHARSET 295 c = convert_to_display_c (c); 296 #endif 297 if (!is_printable (c)) 298 c = '.'; 299 } 300 301 tty_print_anychar (c); 302 } 303 304 col++; 305 306 #ifdef HAVE_CHARSET 307 if (view->utf8) 308 { 309 if (g_unichar_iswide (c)) 310 col++; 311 else if (g_unichar_iszerowidth (c)) 312 col--; 313 } 314 #endif 315 } 316 317 view->dpy_end = from; 318 if (mcview_show_eof != NULL && mcview_show_eof[0] != '\0') 319 { 320 if (last_row && mcview_get_byte (view, from - 1, &c)) 321 if (c != '\n') 322 row--; 323 while (++row < height) 324 { 325 widget_move (view, top + row, left); 326 tty_print_string (mcview_show_eof); 327 } 328 } 329 } 330 331 /* --------------------------------------------------------------------------------------------- */ -
src/viewer/display.c
diff --git a/src/viewer/display.c b/src/viewer/display.c index 41606c5..9780cf6 100644
a b mcview_display (mcview_t * view) 235 235 } 236 236 else if (view->text_nroff_mode) 237 237 { 238 mcview_display_nroff (view); 238 if (view->nroff_high_type == NROFF_HIGH_ANSI) 239 mcview_display_ansi (view); 240 else 241 mcview_display_nroff (view); 239 242 } 240 243 else 241 244 { -
src/viewer/internal.h
diff --git a/src/viewer/internal.h b/src/viewer/internal.h index 79728d2..0dc6033 100644
a b extern const off_t OFFSETTYPE_MAX; 26 26 27 27 /*** enums ***************************************************************************************/ 28 28 29 #define WRAP_MODE_DISABLED(view) (view->text_nroff_mode && view->nroff_high_type == NROFF_HIGH_ANSI) 30 #define TEXT_WRAP_MODE(view) (view->text_wrap_mode && !WRAP_MODE_DISABLED(view)) 31 29 32 /* data sources of the view */ 30 33 enum view_ds 31 34 { … … enum ccache_type 42 45 CCACHE_LINECOL 43 46 }; 44 47 48 enum nroff_high_type 49 { 50 NROFF_HIGH_UNCHECKED = -1, 51 NROFF_HIGH_NROFF = 0, 52 NROFF_HIGH_ANSI = 1, 53 }; 54 45 55 typedef enum 46 56 { 47 57 NROFF_TYPE_NONE = 0, … … typedef struct mcview_struct 131 141 gboolean magic_mode; /* Preprocess the file using external programs */ 132 142 gboolean hexedit_lownibble; /* Are we editing the last significant nibble? */ 133 143 gboolean locked; /* We hold lock on current file */ 144 enum nroff_high_type nroff_high_type; /* Instead of nroff style highliting, do other (e.g. ANSI) */ 134 145 135 146 gboolean utf8; /* It's multibyte file codeset */ 136 147 … … int mcview_nroff_seq_prev (mcview_nroff_t *); 322 333 /* plain.c: */ 323 334 void mcview_display_text (mcview_t *); 324 335 336 /* ansi.c: */ 337 enum nroff_high_type get_nroff_high_type (mcview_t * view); 338 void mcview_display_ansi (mcview_t *); 339 325 340 /* search.c: */ 326 341 mc_search_cbret_t mcview_search_cmd_callback (const void *user_data, gsize char_offset, 327 342 int *current_char); -
src/viewer/lib.c
diff --git a/src/viewer/lib.c b/src/viewer/lib.c index c99197f..f467d91 100644
a b mcview_toggle_magic_mode (mcview_t * view) 93 93 view->dir = NULL; 94 94 view->dir_count = NULL; 95 95 view->dir_idx = NULL; 96 view->nroff_high_type = NROFF_HIGH_UNCHECKED; 96 97 mcview_done (view); 97 98 mcview_init (view); 98 99 mcview_load (view, command, filename, 0); … … mcview_toggle_magic_mode (mcview_t * view) 111 112 void 112 113 mcview_toggle_wrap_mode (mcview_t * view) 113 114 { 114 if ( view->text_wrap_mode)115 if (TEXT_WRAP_MODE(view)) 115 116 view->dpy_start = mcview_bol (view, view->dpy_start, 0); 116 117 view->text_wrap_mode = !view->text_wrap_mode; 117 118 view->dpy_bbar_dirty = TRUE; -
src/viewer/mcviewer.c
diff --git a/src/viewer/mcviewer.c b/src/viewer/mcviewer.c index 93908f3..4e002fd 100644
a b do_mcview_event (mcview_t * view, Gpm_Event * event, int *result) 124 124 y = local.y; 125 125 126 126 /* Scrolling left and right */ 127 if (! view->text_wrap_mode)127 if (!TEXT_WRAP_MODE(view)) 128 128 { 129 129 if (x < view->data_area.width * 1 / 4) 130 130 { … … mcview_new (int y, int x, int lines, int cols, gboolean is_panel) 208 208 view->text_nroff_mode = FALSE; 209 209 view->text_wrap_mode = FALSE; 210 210 view->magic_mode = FALSE; 211 view->nroff_high_type = NROFF_HIGH_UNCHECKED; 211 212 212 213 view->dpy_frame_size = is_panel ? 1 : 0; 213 214 view->converter = str_cnv_from_term; -
src/viewer/move.c
diff --git a/src/viewer/move.c b/src/viewer/move.c index 23ab022..8550ad4 100644
a b mcview_move_up (mcview_t * view, off_t lines) 110 110 { 111 111 if (view->dpy_start == 0) 112 112 break; 113 if ( view->text_wrap_mode)113 if (TEXT_WRAP_MODE(view)) 114 114 { 115 115 new_offset = mcview_bol (view, view->dpy_start, view->dpy_start - (off_t) 1); 116 116 /* check if dpy_start == BOL or not (then new_offset = dpy_start - 1, … … mcview_move_down (mcview_t * view, off_t lines) 178 178 { 179 179 while (lines-- > 0) 180 180 { 181 if ( view->text_wrap_mode)181 if (TEXT_WRAP_MODE(view)) 182 182 view->dpy_end = 183 183 mcview_eol (view, view->dpy_end, 184 184 view->dpy_end + (off_t) view->data_area.width); 185 185 else 186 186 view->dpy_end = mcview_eol (view, view->dpy_end, last_byte); 187 187 188 if ( view->text_wrap_mode)188 if (TEXT_WRAP_MODE(view)) 189 189 new_offset = 190 190 mcview_eol (view, view->dpy_start, 191 191 view->dpy_start + (off_t) view->data_area.width); … … mcview_move_down (mcview_t * view, off_t lines) 202 202 off_t i; 203 203 for (i = 0; i < lines && new_offset < last_byte; i++) 204 204 { 205 if ( view->text_wrap_mode)205 if (TEXT_WRAP_MODE(view)) 206 206 new_offset = 207 207 mcview_eol (view, view->dpy_start, 208 208 view->dpy_start + (off_t) view->data_area.width); … … mcview_moveto_bol (mcview_t * view) 343 343 { 344 344 view->hex_cursor -= view->hex_cursor % view->bytes_per_line; 345 345 } 346 else if (! view->text_wrap_mode)346 else if (!TEXT_WRAP_MODE(view)) 347 347 { 348 348 view->dpy_start = mcview_bol (view, view->dpy_start, 0); 349 349 } -
src/viewer/nroff.c
diff --git a/src/viewer/nroff.c b/src/viewer/nroff.c index a8a77af..b79f033 100644
a b mcview_display_nroff (mcview_t * view) 107 107 int c_next = 0; 108 108 struct hexedit_change_node *curr = view->change_list; 109 109 110 if (view->nroff_high_type == NROFF_HIGH_UNCHECKED) { 111 view->nroff_high_type = get_nroff_high_type (view); 112 if (view->nroff_high_type == NROFF_HIGH_ANSI) 113 { 114 mcview_display_ansi (view); 115 return; 116 } 117 } 118 110 119 mcview_display_clean (view); 111 120 mcview_display_ruler (view); 112 121