2 Internal file viewer for the Midnight Commander
3 Functions for searching in nroff-like view
5 Copyright (C) 1994-2016
6 Free Software Foundation, Inc.
9 Miguel de Icaza, 1994, 1995, 1998
10 Janne Kukonlehto, 1994, 1995
12 Joseph M. Hinkle, 1996
15 Roland Illig <roland.illig@gmx.de>, 2004, 2005
16 Slava Zanko <slavazanko@google.com>, 2009
17 Andrew Borodin <aborodin@vmail.ru>, 2009
18 Ilia Maslakov <il.smind@gmail.com>, 2009
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 3 of the License,
25 or (at your option) any later version.
27 The Midnight Commander is distributed in the hope that it will be useful,
28 but WITHOUT ANY WARRANTY; without even the implied warranty of
29 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
30 GNU 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, see <http://www.gnu.org/licenses/>.
38 #include "lib/global.h"
39 #include "lib/tty/tty.h"
42 #include "lib/charsets.h"
45 #include "src/setup.h" /* option_tab_spacing */
49 /*** global variables ****************************************************************************/
51 /*** file scope macro definitions ****************************************************************/
53 /*** file scope type declarations ****************************************************************/
55 /*** file scope variables ************************************************************************/
57 /*** file scope functions ************************************************************************/
58 /* --------------------------------------------------------------------------------------------- */
61 mcview_nroff_get_char (mcview_nroff_t
* nroff
, int *ret_val
, off_t nroff_index
)
66 if (nroff
->view
->utf8
)
68 if (!mcview_get_utf (nroff
->view
, nroff_index
, &c
, &nroff
->char_length
))
70 /* we need got symbol in any case */
71 nroff
->char_length
= 1;
72 if (!mcview_get_byte (nroff
->view
, nroff_index
, &c
) || !g_ascii_isprint (c
))
79 nroff
->char_length
= 1;
80 if (!mcview_get_byte (nroff
->view
, nroff_index
, &c
))
86 return g_unichar_isprint (c
);
89 /* --------------------------------------------------------------------------------------------- */
90 /*** public functions ****************************************************************************/
91 /* --------------------------------------------------------------------------------------------- */
94 mcview__get_nroff_real_len (WView
* view
, off_t start
, off_t length
)
96 mcview_nroff_t
*nroff
;
100 if (!view
->text_nroff_mode
)
103 nroff
= mcview_nroff_seq_new_num (view
, start
);
110 case NROFF_TYPE_BOLD
:
111 ret
+= 1 + nroff
->char_length
; /* real char length and 0x8 */
113 case NROFF_TYPE_UNDERLINE
:
114 ret
+= 2; /* underline symbol and ox8 */
119 i
+= nroff
->char_length
;
120 mcview_nroff_seq_next (nroff
);
123 mcview_nroff_seq_free (&nroff
);
127 /* --------------------------------------------------------------------------------------------- */
130 mcview_nroff_seq_new_num (WView
* view
, off_t lc_index
)
132 mcview_nroff_t
*nroff
;
134 nroff
= g_try_malloc0 (sizeof (mcview_nroff_t
));
137 nroff
->index
= lc_index
;
139 mcview_nroff_seq_info (nroff
);
144 /* --------------------------------------------------------------------------------------------- */
147 mcview_nroff_seq_new (WView
* view
)
149 return mcview_nroff_seq_new_num (view
, (off_t
) 0);
153 /* --------------------------------------------------------------------------------------------- */
156 mcview_nroff_seq_free (mcview_nroff_t
** nroff
)
158 if (nroff
== NULL
|| *nroff
== NULL
)
160 MC_PTR_FREE (*nroff
);
163 /* --------------------------------------------------------------------------------------------- */
166 mcview_nroff_seq_info (mcview_nroff_t
* nroff
)
171 return NROFF_TYPE_NONE
;
172 nroff
->type
= NROFF_TYPE_NONE
;
174 if (!mcview_nroff_get_char (nroff
, &nroff
->current_char
, nroff
->index
))
177 if (!mcview_get_byte (nroff
->view
, nroff
->index
+ nroff
->char_length
, &next
) || next
!= '\b')
180 if (!mcview_nroff_get_char (nroff
, &next2
, nroff
->index
+ 1 + nroff
->char_length
))
183 if (nroff
->current_char
== '_' && next2
== '_')
185 nroff
->type
= (nroff
->prev_type
== NROFF_TYPE_BOLD
)
186 ? NROFF_TYPE_BOLD
: NROFF_TYPE_UNDERLINE
;
189 else if (nroff
->current_char
== next2
)
191 nroff
->type
= NROFF_TYPE_BOLD
;
193 else if (nroff
->current_char
== '_')
195 nroff
->current_char
= next2
;
196 nroff
->type
= NROFF_TYPE_UNDERLINE
;
198 else if (nroff
->current_char
== '+' && next2
== 'o')
205 /* --------------------------------------------------------------------------------------------- */
208 mcview_nroff_seq_next (mcview_nroff_t
* nroff
)
213 nroff
->prev_type
= nroff
->type
;
217 case NROFF_TYPE_BOLD
:
218 nroff
->index
+= 1 + nroff
->char_length
;
220 case NROFF_TYPE_UNDERLINE
:
227 nroff
->index
+= nroff
->char_length
;
229 mcview_nroff_seq_info (nroff
);
230 return nroff
->current_char
;
233 /* --------------------------------------------------------------------------------------------- */
236 mcview_nroff_seq_prev (mcview_nroff_t
* nroff
)
239 off_t prev_index
, prev_index2
;
244 nroff
->prev_type
= NROFF_TYPE_NONE
;
246 if (nroff
->index
== 0)
249 prev_index
= nroff
->index
- 1;
251 while (prev_index
!= 0)
253 if (mcview_nroff_get_char (nroff
, &nroff
->current_char
, prev_index
))
260 mcview_nroff_seq_info (nroff
);
261 return nroff
->current_char
;
266 if (!mcview_get_byte (nroff
->view
, prev_index
, &prev
) || prev
!= '\b')
268 nroff
->index
= prev_index
;
269 mcview_nroff_seq_info (nroff
);
270 return nroff
->current_char
;
272 prev_index2
= prev_index
- 1;
274 while (prev_index2
!= 0)
276 if (mcview_nroff_get_char (nroff
, &prev
, prev_index
))
281 nroff
->index
= (prev_index2
== 0) ? prev_index
: prev_index2
;
282 mcview_nroff_seq_info (nroff
);
283 return nroff
->current_char
;
286 /* --------------------------------------------------------------------------------------------- */