This source file includes following definitions.
- mcview_nroff_get_char
- mcview__get_nroff_real_len
- mcview_nroff_seq_new_num
- mcview_nroff_seq_new
- mcview_nroff_seq_free
- mcview_nroff_seq_info
- mcview_nroff_seq_next
- mcview_nroff_seq_prev
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36 #include <config.h>
37
38 #include "lib/global.h"
39 #include "lib/tty/tty.h"
40 #include "lib/skin.h"
41 #ifdef HAVE_CHARSET
42 #include "lib/charsets.h"
43 #endif
44
45 #include "internal.h"
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61 static gboolean
62 mcview_nroff_get_char (mcview_nroff_t *nroff, int *ret_val, off_t nroff_index)
63 {
64 int c = 0;
65
66 #ifdef HAVE_CHARSET
67 if (nroff->view->utf8)
68 {
69 if (!mcview_get_utf (nroff->view, nroff_index, &c, &nroff->char_length))
70 {
71
72 nroff->char_length = 1;
73 if (!mcview_get_byte (nroff->view, nroff_index, &c) || !g_ascii_isprint (c))
74 return FALSE;
75 }
76 }
77 else
78 #endif
79 {
80 nroff->char_length = 1;
81 if (!mcview_get_byte (nroff->view, nroff_index, &c))
82 return FALSE;
83 }
84
85 *ret_val = c;
86
87 return g_unichar_isprint (c);
88 }
89
90
91
92
93
94 int
95 mcview__get_nroff_real_len (WView *view, off_t start, off_t length)
96 {
97 mcview_nroff_t *nroff;
98 int ret = 0;
99 off_t i = 0;
100
101 if (!view->mode_flags.nroff)
102 return 0;
103
104 nroff = mcview_nroff_seq_new_num (view, start);
105 if (nroff == NULL)
106 return 0;
107 while (i < length)
108 {
109 switch (nroff->type)
110 {
111 case NROFF_TYPE_BOLD:
112 ret += 1 + nroff->char_length;
113 break;
114 case NROFF_TYPE_UNDERLINE:
115 ret += 2;
116 break;
117 default:
118 break;
119 }
120 i += nroff->char_length;
121 mcview_nroff_seq_next (nroff);
122 }
123
124 mcview_nroff_seq_free (&nroff);
125 return ret;
126 }
127
128
129
130 mcview_nroff_t *
131 mcview_nroff_seq_new_num (WView *view, off_t lc_index)
132 {
133 mcview_nroff_t *nroff;
134
135 nroff = g_try_malloc0 (sizeof (mcview_nroff_t));
136 if (nroff != NULL)
137 {
138 nroff->index = lc_index;
139 nroff->view = view;
140 mcview_nroff_seq_info (nroff);
141 }
142 return nroff;
143 }
144
145
146
147 mcview_nroff_t *
148 mcview_nroff_seq_new (WView *view)
149 {
150 return mcview_nroff_seq_new_num (view, (off_t) 0);
151
152 }
153
154
155
156 void
157 mcview_nroff_seq_free (mcview_nroff_t **nroff)
158 {
159 if (nroff == NULL || *nroff == NULL)
160 return;
161 MC_PTR_FREE (*nroff);
162 }
163
164
165
166 nroff_type_t
167 mcview_nroff_seq_info (mcview_nroff_t *nroff)
168 {
169 int next, next2;
170
171 if (nroff == NULL)
172 return NROFF_TYPE_NONE;
173 nroff->type = NROFF_TYPE_NONE;
174
175 if (!mcview_nroff_get_char (nroff, &nroff->current_char, nroff->index))
176 return nroff->type;
177
178 if (!mcview_get_byte (nroff->view, nroff->index + nroff->char_length, &next) || next != '\b')
179 return nroff->type;
180
181 if (!mcview_nroff_get_char (nroff, &next2, nroff->index + 1 + nroff->char_length))
182 return nroff->type;
183
184 if (nroff->current_char == '_' && next2 == '_')
185 {
186 nroff->type = (nroff->prev_type == NROFF_TYPE_BOLD)
187 ? NROFF_TYPE_BOLD : NROFF_TYPE_UNDERLINE;
188
189 }
190 else if (nroff->current_char == next2)
191 {
192 nroff->type = NROFF_TYPE_BOLD;
193 }
194 else if (nroff->current_char == '_')
195 {
196 nroff->current_char = next2;
197 nroff->type = NROFF_TYPE_UNDERLINE;
198 }
199 else if (nroff->current_char == '+' && next2 == 'o')
200 {
201
202 }
203 return nroff->type;
204 }
205
206
207
208 int
209 mcview_nroff_seq_next (mcview_nroff_t *nroff)
210 {
211 if (nroff == NULL)
212 return -1;
213
214 nroff->prev_type = nroff->type;
215
216 switch (nroff->type)
217 {
218 case NROFF_TYPE_BOLD:
219 nroff->index += 1 + nroff->char_length;
220 break;
221 case NROFF_TYPE_UNDERLINE:
222 nroff->index += 2;
223 break;
224 default:
225 break;
226 }
227
228 nroff->index += nroff->char_length;
229
230 mcview_nroff_seq_info (nroff);
231 return nroff->current_char;
232 }
233
234
235
236 int
237 mcview_nroff_seq_prev (mcview_nroff_t *nroff)
238 {
239 int prev;
240 off_t prev_index, prev_index2;
241
242 if (nroff == NULL)
243 return -1;
244
245 nroff->prev_type = NROFF_TYPE_NONE;
246
247 if (nroff->index == 0)
248 return -1;
249
250 prev_index = nroff->index - 1;
251
252 while (prev_index != 0)
253 {
254 if (mcview_nroff_get_char (nroff, &nroff->current_char, prev_index))
255 break;
256 prev_index--;
257 }
258 if (prev_index == 0)
259 {
260 nroff->index--;
261 mcview_nroff_seq_info (nroff);
262 return nroff->current_char;
263 }
264
265 prev_index--;
266
267 if (!mcview_get_byte (nroff->view, prev_index, &prev) || prev != '\b')
268 {
269 nroff->index = prev_index;
270 mcview_nroff_seq_info (nroff);
271 return nroff->current_char;
272 }
273 prev_index2 = prev_index - 1;
274
275 while (prev_index2 != 0)
276 {
277 if (mcview_nroff_get_char (nroff, &prev, prev_index))
278 break;
279 prev_index2--;
280 }
281
282 nroff->index = (prev_index2 == 0) ? prev_index : prev_index2;
283 mcview_nroff_seq_info (nroff);
284 return nroff->current_char;
285 }
286
287