Ticket #1649: Prepare for prerelease mc-4.7.0-pre3 (code cleanup)
[midnight-commander.git] / src / viewer / plain.c
blob9b1aeeee31941491d2a51531ed6275569d529c2f
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/main.h"
42 #include "../src/charsets.h"
43 #include "../src/tty/tty.h"
44 #include "../src/skin/skin.h"
45 #include "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, prev_ch;
72 gboolean read_res = TRUE;
73 struct hexedit_change_node *curr = view->change_list;
75 mcview_display_clean (view);
76 mcview_display_ruler (view);
78 /* Find the first displayable changed byte */
79 from = view->dpy_start;
80 while (curr && (curr->offset < from)) {
81 curr = curr->next;
84 tty_setcolor (NORMAL_COLOR);
85 for (row = 0, col = 0; row < height;) {
86 #ifdef HAVE_CHARSET
87 if (view->utf8) {
88 c = mcview_get_utf (view, from, &cw, &read_res);
89 if (!read_res)
90 break;
91 } else
92 #endif
94 if (! mcview_get_byte (view, from, &c))
95 break;
97 from++;
98 if (cw > 1)
99 from += cw - 1;
101 if (c != '\n' && prev_ch == '\r') {
102 col = 0;
103 row++;
104 tty_print_anychar ('\n');
107 prev_ch = c;
108 if (c == '\r')
109 continue;
111 if ((c == '\n') || (col >= width && view->text_wrap_mode)) {
112 col = 0;
113 row++;
114 if (c == '\n' || row >= height)
115 continue;
118 if (c == '\t') {
119 off_t line, column;
120 mcview_offset_to_coord (view, &line, &column, from);
121 col += (8 - column % 8);
122 if (view->text_wrap_mode && col >= width && width != 0) {
123 row += col / width;
124 col %= width;
126 continue;
129 if (view->search_start <= from && from < view->search_end) {
130 tty_setcolor (SELECTED_COLOR);
133 if (col >= view->dpy_text_column && col - view->dpy_text_column < width) {
134 widget_move (view, top + row, left + (col - view->dpy_text_column));
135 #ifdef HAVE_CHARSET
136 if (utf8_display) {
137 if (!view->utf8) {
138 c = convert_from_8bit_to_utf_c (c, view->converter);
140 if (!g_unichar_isprint (c))
141 c = '.';
142 } else {
143 if (view->utf8) {
144 c = convert_from_utf_to_current_c (c, view->converter);
145 } else {
146 #endif
147 c = convert_to_display_c (c);
148 #ifdef HAVE_CHARSET
151 #endif
152 tty_print_anychar (c);
154 col++;
155 tty_setcolor (NORMAL_COLOR);
157 view->dpy_end = from;
160 /* --------------------------------------------------------------------------------------------- */