This source file includes following definitions.
- double_marks
- book_mark_find
- book_mark_query_color
- book_mark_insert
- book_mark_clear
- book_mark_flush
- book_mark_inc
- book_mark_dec
- book_mark_serialize
- book_mark_restore
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 #include <config.h>
33
34 #include <ctype.h>
35 #include <stdarg.h>
36 #include <stdio.h>
37 #include <stdlib.h>
38 #include <string.h>
39
40 #include <sys/types.h>
41 #include <sys/stat.h>
42 #include <unistd.h>
43
44 #include "lib/global.h"
45 #include "lib/util.h"
46
47 #include "editwidget.h"
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67 static edit_book_mark_t *
68 double_marks (WEdit *edit, edit_book_mark_t *p)
69 {
70 (void) edit;
71
72 if (p->next != NULL)
73 while (p->next->line == p->line)
74 p = p->next;
75 return p;
76 }
77
78
79
80
81 edit_book_mark_t *
82 book_mark_find (WEdit *edit, long line)
83 {
84 edit_book_mark_t *p;
85
86 if (edit->book_mark == NULL)
87 {
88
89 edit->book_mark = g_new0 (edit_book_mark_t, 1);
90 edit->book_mark->line = -1;
91 return edit->book_mark;
92 }
93
94 for (p = edit->book_mark; p != NULL; p = p->next)
95 {
96 if (p->line > line)
97 break;
98
99 if (p->next != NULL)
100 {
101 if (p->next->line > line)
102 {
103 edit->book_mark = p;
104 return double_marks (edit, p);
105 }
106 }
107 else
108 {
109 edit->book_mark = p;
110 return double_marks (edit, p);
111 }
112 }
113
114 for (p = edit->book_mark; p != NULL; p = p->prev)
115 {
116 if (p->next != NULL && p->next->line <= line)
117 break;
118
119 if (p->line <= line)
120 {
121 if (p->next != NULL)
122 {
123 if (p->next->line > line)
124 {
125 edit->book_mark = p;
126 return double_marks (edit, p);
127 }
128 }
129 else
130 {
131 edit->book_mark = p;
132 return double_marks (edit, p);
133 }
134 }
135 }
136
137 return NULL;
138 }
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153 gboolean
154 book_mark_query_color (WEdit *edit, long line, int c)
155 {
156 if (edit->book_mark != NULL)
157 {
158 edit_book_mark_t *p;
159
160 for (p = book_mark_find (edit, line); p != NULL; p = p->prev)
161 {
162 if (p->line != line)
163 return FALSE;
164 if (p->c == c)
165 return TRUE;
166 }
167 }
168
169 return FALSE;
170 }
171
172
173
174
175 void
176 book_mark_insert (WEdit *edit, long line, int c)
177 {
178 edit_book_mark_t *p, *q;
179
180 p = book_mark_find (edit, line);
181 #if 0
182 if (p->line == line)
183 {
184
185 if (p->c != c)
186 {
187 p->c = c;
188 edit->force |= REDRAW_LINE;
189 }
190 return;
191 }
192 #endif
193
194 q = g_new (edit_book_mark_t, 1);
195 q->line = line;
196 q->c = c;
197 q->next = p->next;
198
199 q->prev = p;
200 if (p->next != NULL)
201 p->next->prev = q;
202 p->next = q;
203
204 edit->force |= REDRAW_LINE;
205 }
206
207
208
209
210
211
212
213
214
215
216
217 gboolean
218 book_mark_clear (WEdit *edit, long line, int c)
219 {
220 edit_book_mark_t *p, *q;
221 gboolean r = FALSE;
222
223 if (edit->book_mark == NULL)
224 return r;
225
226 for (p = book_mark_find (edit, line); p != NULL; p = q)
227 {
228 q = p->prev;
229 if (p->line == line && (p->c == c || c == -1))
230 {
231 r = TRUE;
232 edit->book_mark = p->prev;
233 p->prev->next = p->next;
234 if (p->next != NULL)
235 p->next->prev = p->prev;
236 g_free (p);
237 edit->force |= REDRAW_LINE;
238 break;
239 }
240 }
241
242 if (edit->book_mark->line == -1 && edit->book_mark->next == NULL)
243 MC_PTR_FREE (edit->book_mark);
244
245 return r;
246 }
247
248
249
250
251 void
252 book_mark_flush (WEdit *edit, int c)
253 {
254 edit_book_mark_t *p, *q;
255
256 if (edit->book_mark == NULL)
257 return;
258
259 while (edit->book_mark->prev != NULL)
260 edit->book_mark = edit->book_mark->prev;
261
262 for (q = edit->book_mark->next; q != NULL; q = p)
263 {
264 p = q->next;
265 if (q->c == c || c == -1)
266 {
267 q->prev->next = q->next;
268 if (p != NULL)
269 p->prev = q->prev;
270 g_free (q);
271 }
272 }
273 if (edit->book_mark->next == NULL)
274 MC_PTR_FREE (edit->book_mark);
275
276 edit->force |= REDRAW_PAGE;
277 }
278
279
280
281
282 void
283 book_mark_inc (WEdit *edit, long line)
284 {
285 if (edit->book_mark != NULL)
286 {
287 edit_book_mark_t *p;
288
289 p = book_mark_find (edit, line);
290 for (p = p->next; p != NULL; p = p->next)
291 p->line++;
292 }
293 }
294
295
296
297
298 void
299 book_mark_dec (WEdit *edit, long line)
300 {
301 if (edit->book_mark != NULL)
302 {
303 edit_book_mark_t *p;
304
305 p = book_mark_find (edit, line);
306 for (p = p->next; p != NULL; p = p->next)
307 p->line--;
308 }
309 }
310
311
312
313
314 void
315 book_mark_serialize (WEdit *edit, int color)
316 {
317 if (edit->serialized_bookmarks != NULL)
318 g_array_set_size (edit->serialized_bookmarks, 0);
319
320 if (edit->book_mark != NULL)
321 {
322 edit_book_mark_t *p;
323
324 if (edit->serialized_bookmarks == NULL)
325 edit->serialized_bookmarks = g_array_sized_new (FALSE, FALSE, sizeof (size_t),
326 MAX_SAVED_BOOKMARKS);
327
328 for (p = book_mark_find (edit, 0); p != NULL; p = p->next)
329 if (p->c == color && p->line >= 0)
330 g_array_append_val (edit->serialized_bookmarks, p->line);
331 }
332 }
333
334
335
336
337 void
338 book_mark_restore (WEdit *edit, int color)
339 {
340 if (edit->serialized_bookmarks != NULL)
341 {
342 size_t i;
343
344 for (i = 0; i < edit->serialized_bookmarks->len; i++)
345 book_mark_insert (edit, g_array_index (edit->serialized_bookmarks, size_t, i), color);
346 }
347 }
348
349