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