Split file src/keybind.[ch] to lib/keybind.[ch] and src/keybind-defaults.[ch].
[midnight-commander.git] / src / viewer / plain.c
blobb25b38e2b0a399e472a9a303dd828d6d222645f6
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>
19 2010 Andrew Borodin <aborodin@vmail.ru>
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 2 of the
26 License, or (at your option) any later version.
28 The Midnight Commander is distributed in the hope that it will be
29 useful, but WITHOUT ANY WARRANTY; without even the implied warranty
30 of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
31 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, write to the Free Software
35 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
36 MA 02110-1301, USA.
39 #include <config.h>
41 #include "lib/global.h"
42 #include "lib/tty/tty.h"
43 #include "lib/skin.h"
44 #include "lib/util.h" /* is_printable() */
45 #include "lib/charsets.h"
47 #include "src/main.h" /* utf8_display */
48 #include "src/setup.h" /* option_tab_spacing */
50 #include "internal.h"
51 #include "mcviewer.h" /* mcview_show_eof */
53 /*** global variables ****************************************************************************/
55 /*** file scope macro definitions ****************************************************************/
57 /*** file scope type declarations ****************************************************************/
59 /*** file scope variables ************************************************************************/
61 /*** file scope functions ************************************************************************/
62 /* --------------------------------------------------------------------------------------------- */
64 /* --------------------------------------------------------------------------------------------- */
65 /*** public functions ****************************************************************************/
66 /* --------------------------------------------------------------------------------------------- */
68 void
69 mcview_display_text (mcview_t * view)
71 const screen_dimen left = view->data_area.left;
72 const screen_dimen top = view->data_area.top;
73 const screen_dimen width = view->data_area.width;
74 const screen_dimen height = view->data_area.height;
75 screen_dimen row = 0, col = 0;
76 off_t from;
77 int cw = 1;
78 int c, prev_ch = 0;
79 gboolean last_row = TRUE;
80 struct hexedit_change_node *curr = view->change_list;
82 mcview_display_clean (view);
83 mcview_display_ruler (view);
85 /* Find the first displayable changed byte */
86 from = view->dpy_start;
87 while ((curr != NULL) && (curr->offset < from))
88 curr = curr->next;
90 while (TRUE)
92 tty_setcolor (NORMAL_COLOR);
94 if (row >= height)
95 break;
97 #ifdef HAVE_CHARSET
98 if (view->utf8)
100 gboolean read_res = TRUE;
102 c = mcview_get_utf (view, from, &cw, &read_res);
103 if (!read_res)
104 break;
106 else
107 #endif
108 if (!mcview_get_byte (view, from, &c))
109 break;
111 last_row = FALSE;
112 from++;
113 if (cw > 1)
114 from += cw - 1;
116 if (c != '\n' && prev_ch == '\r')
118 if (++row >= height)
119 break;
121 col = 0;
122 /* tty_print_anychar ('\n'); */
125 prev_ch = c;
126 if (c == '\r')
127 continue;
129 if (c == '\n')
131 col = 0;
132 row++;
133 continue;
136 if (col >= width && view->text_wrap_mode)
138 col = 0;
139 if (++row >= height)
140 break;
143 if (c == '\t')
145 col += (option_tab_spacing - col % option_tab_spacing);
146 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);
157 if (((off_t) col >= view->dpy_text_column)
158 && ((off_t) col - view->dpy_text_column < (off_t) width))
160 widget_move (view, top + row, left + ((off_t) col - view->dpy_text_column));
161 #ifdef HAVE_CHARSET
162 if (utf8_display)
164 if (!view->utf8)
165 c = convert_from_8bit_to_utf_c ((unsigned char) c, view->converter);
166 if (!g_unichar_isprint (c))
167 c = '.';
169 else if (view->utf8)
170 c = convert_from_utf_to_current_c (c, view->converter);
171 else
172 #endif
174 c = convert_to_display_c (c);
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 /* --------------------------------------------------------------------------------------------- */