Split src/view.c into small files for better support of code
[midnight-commander.git] / src / viewer / plain.c
blob082832242b273a6718a47ed34b976549859309d0
1 /*
2 Internal file viewer for the Midnight Commander
3 Function for plain view
5 Copyright (C) 1994, 1995, 1996, 1998, 1999, 2000, 2001, 2002, 2003,
6 2004, 2005, 2006, 2007, 2009 Free Software Foundation, Inc.
8 Written by: 1994, 1995, 1998 Miguel de Icaza
9 1994, 1995 Janne Kukonlehto
10 1995 Jakub Jelinek
11 1996 Joseph M. Hinkle
12 1997 Norbert Warmuth
13 1998 Pavel Machek
14 2004 Roland Illig <roland.illig@gmx.de>
15 2005 Roland Illig <roland.illig@gmx.de>
16 2009 Slava Zanko <slavazanko@google.com>
17 2009 Andrew Borodin <aborodin@vmail.ru>
18 2009 Ilia Maslakov <il.smind@gmail.com>
20 This file is part of the Midnight Commander.
22 The Midnight Commander is free software; you can redistribute it
23 and/or modify it under the terms of the GNU General Public License as
24 published by the Free Software Foundation; either version 2 of the
25 License, or (at your option) any later version.
27 The Midnight Commander is distributed in the hope that it will be
28 useful, but WITHOUT ANY WARRANTY; without even the implied warranty
29 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
30 General Public License for more details.
32 You should have received a copy of the GNU General Public License
33 along with this program; if not, write to the Free Software
34 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
35 MA 02110-1301, USA.
38 #include <config.h>
40 #include "../src/global.h"
41 #include "../src/myslang.h"
42 #include "../src/main.h"
43 #include "../src/color.h"
44 #include "../src/charsets.h"
45 #include "../src/viewer/internal.h"
47 /*** global variables ****************************************************************************/
49 /*** file scope macro definitions ****************************************************************/
51 /*** file scope type declarations ****************************************************************/
53 /*** file scope variables ************************************************************************/
55 /*** file scope functions ************************************************************************/
57 /*** public functions ****************************************************************************/
59 /* --------------------------------------------------------------------------------------------- */
61 void
62 mcview_display_text (mcview_t * view)
64 const screen_dimen left = view->data_area.left;
65 const screen_dimen top = view->data_area.top;
66 const screen_dimen width = view->data_area.width;
67 const screen_dimen height = view->data_area.height;
68 screen_dimen row, col;
69 off_t from;
70 int cw = 1;
71 int c;
72 struct hexedit_change_node *curr = view->change_list;
74 mcview_display_clean (view);
75 mcview_display_ruler (view);
77 /* Find the first displayable changed byte */
78 from = view->dpy_start;
79 while (curr && (curr->offset < from)) {
80 curr = curr->next;
83 tty_setcolor (NORMAL_COLOR);
84 for (row = 0, col = 0; row < height;) {
85 #ifdef HAVE_CHARSET
86 if (view->utf8) {
87 if ((c = mcview_get_utf (view, from, &cw)) == -1)
88 break;
89 } else
90 #endif
92 if ((c = mcview_get_byte (view, from)) == -1)
93 break;
95 from++;
96 mc_log ("cw=%i\n", cw);
97 if (cw > 1)
98 from += cw - 1;
100 if (view->text_nroff_mode && c == '\b') {
101 int c_prev;
102 int c_next;
104 if ((c_next = mcview_get_byte_indexed (view, from, 1)) != -1 && g_ascii_isprint (c_next)
105 && from >= 1
106 && (c_prev = mcview_get_byte (view, from - 1)) != -1 && g_ascii_isprint (c_prev)
107 && (c_prev == c_next || c_prev == '_' || (c_prev == '+' && c_next == 'o'))) {
108 if (col == 0) {
109 if (row == 0) {
110 /* We're inside an nroff character sequence at the
111 * beginning of the screen -- just skip the
112 * backspace and continue with the next character. */
113 continue;
115 row--;
116 col = width;
118 col--;
119 if (c_prev == '_' && (c_next != '_' || mcview_count_backspaces (view, from) == 1))
120 tty_setcolor (VIEW_UNDERLINED_COLOR);
121 else
122 tty_setcolor (MARKED_COLOR);
123 continue;
127 if ((c == '\n') || (col >= width && view->text_wrap_mode)) {
128 col = 0;
129 row++;
130 if (c == '\n' || row >= height)
131 continue;
134 if (c == '\r') {
135 c = mcview_get_byte_indexed (view, from, 1);
136 if (c == '\r' || c == '\n')
137 continue;
138 col = 0;
139 row++;
140 continue;
143 if (c == '\t') {
144 off_t line, column;
145 mcview_offset_to_coord (view, &line, &column, from);
146 col += (8 - column % 8);
147 if (view->text_wrap_mode && col >= width && width != 0) {
148 row += col / width;
149 col %= width;
151 continue;
154 if (view->search_start <= from && from < view->search_end) {
155 tty_setcolor (SELECTED_COLOR);
158 if (col >= view->dpy_text_column && col - view->dpy_text_column < width) {
159 widget_move (view, top + row, left + (col - view->dpy_text_column));
160 #ifdef HAVE_CHARSET
161 if (utf8_display) {
162 if (!view->utf8) {
163 c = convert_from_8bit_to_utf_c ((unsigned char) c, view->converter);
165 } else {
166 if (view->utf8) {
167 c = convert_from_utf_to_current_c (c, view->converter);
168 } else {
169 #endif
170 c = convert_to_display_c (c);
171 #ifdef HAVE_CHARSET
174 #endif
175 tty_print_anychar (c);
177 col++;
178 tty_setcolor (NORMAL_COLOR);
180 view->dpy_end = from;
183 /* --------------------------------------------------------------------------------------------- */