Update po/mc.pot and po/*.po files.
[midnight-commander.git] / src / viewer / plain.c
blob5bf019d748076a77f619971a2669a7dc62237f2a
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, 2011
7 The Free Software Foundation, Inc.
9 Written by:
10 Miguel de Icaza, 1994, 1995, 1998
11 Janne Kukonlehto, 1994, 1995
12 Jakub Jelinek, 1995
13 Joseph M. Hinkle, 1996
14 Norbert Warmuth, 1997
15 Pavel Machek, 1998
16 Roland Illig <roland.illig@gmx.de>, 2004, 2005
17 Slava Zanko <slavazanko@google.com>, 2009
18 Andrew Borodin <aborodin@vmail.ru>, 2009, 2010
19 Ilia Maslakov <il.smind@gmail.com>, 2009
21 This file is part of the Midnight Commander.
23 The Midnight Commander is free software: you can redistribute it
24 and/or modify it under the terms of the GNU General Public License as
25 published by the Free Software Foundation, either version 3 of the License,
26 or (at your option) any later version.
28 The Midnight Commander is distributed in the hope that it will be useful,
29 but WITHOUT ANY WARRANTY; without even the implied warranty of
30 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
31 GNU General Public License for more details.
33 You should have received a copy of the GNU General Public License
34 along with this program. If not, see <http://www.gnu.org/licenses/>.
37 #include <config.h>
39 #include "lib/global.h"
40 #include "lib/tty/tty.h"
41 #include "lib/skin.h"
42 #include "lib/util.h" /* is_printable() */
43 #ifdef HAVE_CHARSET
44 #include "lib/charsets.h"
45 #endif
47 #include "src/setup.h" /* option_tab_spacing */
49 #include "internal.h"
50 #include "mcviewer.h" /* mcview_show_eof */
52 /*** global variables ****************************************************************************/
54 /*** file scope macro definitions ****************************************************************/
56 /*** file scope type declarations ****************************************************************/
58 /*** file scope variables ************************************************************************/
60 /*** file scope functions ************************************************************************/
61 /* --------------------------------------------------------------------------------------------- */
63 /* --------------------------------------------------------------------------------------------- */
64 /*** public functions ****************************************************************************/
65 /* --------------------------------------------------------------------------------------------- */
67 void
68 mcview_display_text (mcview_t * view)
70 const screen_dimen left = view->data_area.left;
71 const screen_dimen top = view->data_area.top;
72 const screen_dimen width = view->data_area.width;
73 const screen_dimen height = view->data_area.height;
74 screen_dimen row = 0, col = 0;
75 off_t from;
76 int cw = 1;
77 int c, prev_ch = 0;
78 gboolean last_row = TRUE;
79 struct hexedit_change_node *curr = view->change_list;
81 mcview_display_clean (view);
82 mcview_display_ruler (view);
84 /* Find the first displayable changed byte */
85 from = view->dpy_start;
86 while ((curr != NULL) && (curr->offset < from))
87 curr = curr->next;
89 while (TRUE)
91 tty_setcolor (NORMAL_COLOR);
93 if (row >= height)
94 break;
96 #ifdef HAVE_CHARSET
97 if (view->utf8)
99 gboolean read_res = TRUE;
101 c = mcview_get_utf (view, from, &cw, &read_res);
102 if (!read_res)
103 break;
105 else
106 #endif
107 if (!mcview_get_byte (view, from, &c))
108 break;
110 last_row = FALSE;
111 from++;
112 if (cw > 1)
113 from += cw - 1;
115 if (c != '\n' && prev_ch == '\r')
117 if (++row >= height)
118 break;
120 col = 0;
121 /* tty_print_anychar ('\n'); */
124 prev_ch = c;
125 if (c == '\r')
126 continue;
128 if (c == '\n')
130 col = 0;
131 row++;
132 continue;
135 if (col >= width && view->text_wrap_mode)
137 col = 0;
138 if (++row >= height)
139 break;
142 if (c == '\t')
144 col += (option_tab_spacing - col % option_tab_spacing);
145 if (view->text_wrap_mode && col >= width && width != 0)
147 row += col / width;
148 col %= width;
150 continue;
153 if (view->search_start <= from && from < view->search_end)
154 tty_setcolor (SELECTED_COLOR);
156 if (((off_t) col >= view->dpy_text_column)
157 && ((off_t) col - view->dpy_text_column < (off_t) width))
159 widget_move (view, top + row, left + ((off_t) col - view->dpy_text_column));
160 #ifdef HAVE_CHARSET
161 if (mc_global.utf8_display)
163 if (!view->utf8)
164 c = convert_from_8bit_to_utf_c ((unsigned char) c, view->converter);
165 if (!g_unichar_isprint (c))
166 c = '.';
168 else if (view->utf8)
169 c = convert_from_utf_to_current_c (c, view->converter);
170 else
171 #endif
173 #ifdef HAVE_CHARSET
174 c = convert_to_display_c (c);
175 #endif
176 if (!is_printable (c))
177 c = '.';
180 tty_print_anychar (c);
183 col++;
185 #ifdef HAVE_CHARSET
186 if (view->utf8)
188 if (g_unichar_iswide (c))
189 col++;
190 else if (g_unichar_iszerowidth (c))
191 col--;
193 #endif
196 view->dpy_end = from;
197 if (mcview_show_eof != NULL && mcview_show_eof[0] != '\0')
199 if (last_row && mcview_get_byte (view, from - 1, &c))
200 if (c != '\n')
201 row--;
202 while (++row < height)
204 widget_move (view, top + row, left);
205 tty_print_string (mcview_show_eof);
210 /* --------------------------------------------------------------------------------------------- */