Mercurial > ~mikael > mcabber > hg
annotate mcabber/src/hbuf.c @ 830:80434fde7cfa
Display presence notification timestamps when they exist
These timestamps were used in the roster, but not in the buffer window
message nor in the history logfile. Reported by "ze".
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Wed, 03 May 2006 11:28:41 +0200 |
parents | 339c76ed5c0d |
children | d0781ca2dd08 |
rev | line source |
---|---|
71 | 1 /* |
2 * hbuf.c -- History buffer implementation | |
393 | 3 * |
699 | 4 * Copyright (C) 2005, 2006 Mikael Berthe <bmikael@lists.lilotux.net> |
71 | 5 * |
6 * This program is free software; you can redistribute it and/or modify | |
7 * it under the terms of the GNU General Public License as published by | |
8 * the Free Software Foundation; either version 2 of the License, or (at | |
9 * your option) any later version. | |
10 * | |
11 * This program is distributed in the hope that it will be useful, but | |
12 * WITHOUT ANY WARRANTY; without even the implied warranty of | |
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | |
14 * General Public License for more details. | |
15 * | |
16 * You should have received a copy of the GNU General Public License | |
17 * along with this program; if not, write to the Free Software | |
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | |
19 * USA | |
20 */ | |
21 | |
370
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
368
diff
changeset
|
22 #define _GNU_SOURCE /* We need glibc for strptime */ |
71 | 23 #include <string.h> |
24 | |
25 #include "hbuf.h" | |
804
339c76ed5c0d
Remove a warning on Cygwin (implicit strcasestr() declaration)
Mikael Berthe <mikael@lilotux.net>
parents:
790
diff
changeset
|
26 #include "utils.h" |
71 | 27 |
28 | |
29 /* This is a private structure type */ | |
30 | |
31 typedef struct { | |
32 char *ptr; | |
182 | 33 char *ptr_end; // beginning of the block |
34 char *ptr_end_alloc; // end of the current persistent block | |
71 | 35 guchar flags; |
36 | |
37 // XXX This should certainly be a pointer, and be allocated only when needed | |
38 // (for ex. when HBB_FLAG_PERSISTENT is set). | |
39 struct { // hbuf_line_info | |
184 | 40 time_t timestamp; |
41 guchar flags; | |
42 } prefix; | |
71 | 43 } hbuf_block; |
44 | |
45 | |
184 | 46 // hbuf_add_line(p_hbuf, text, prefix_flags, width) |
71 | 47 // Add a line to the given buffer. If width is not null, then lines are |
48 // wrapped at this length. | |
49 // | |
50 // Note 1: Splitting according to width won't work if there are tabs; they | |
51 // should be expanded before. | |
52 // Note 2: width does not include the ending \0. | |
184 | 53 void hbuf_add_line(GList **p_hbuf, const char *text, time_t timestamp, |
54 guint prefix_flags, guint width) | |
71 | 55 { |
56 GList *hbuf = *p_hbuf; | |
57 char *line, *cr, *end; | |
83 | 58 hbuf_block *hbuf_block_elt; |
71 | 59 |
60 if (!text) return; | |
61 | |
83 | 62 hbuf_block_elt = g_new0(hbuf_block, 1); |
184 | 63 hbuf_block_elt->prefix.timestamp = timestamp; |
64 hbuf_block_elt->prefix.flags = prefix_flags; | |
71 | 65 if (!hbuf) { |
390 | 66 hbuf_block_elt->ptr = g_new(char, HBB_BLOCKSIZE); |
71 | 67 hbuf_block_elt->flags = HBB_FLAG_ALLOC | HBB_FLAG_PERSISTENT; |
182 | 68 hbuf_block_elt->ptr_end_alloc = hbuf_block_elt->ptr + HBB_BLOCKSIZE; |
71 | 69 *p_hbuf = g_list_append(*p_hbuf, hbuf_block_elt); |
70 } else { | |
502
3134b4960cdb
Fix mixed declaration and code
Mikael Berthe <mikael@lilotux.net>
parents:
464
diff
changeset
|
71 hbuf_block *hbuf_b_prev; |
392
6329c9601704
Speed up hbuf_add_line()
Mikael Berthe <mikael@lilotux.net>
parents:
390
diff
changeset
|
72 // Set p_hbuf to the end of the list, to speed up history loading |
6329c9601704
Speed up hbuf_add_line()
Mikael Berthe <mikael@lilotux.net>
parents:
390
diff
changeset
|
73 // (or CPU time will be used by g_list_last() for each line) |
6329c9601704
Speed up hbuf_add_line()
Mikael Berthe <mikael@lilotux.net>
parents:
390
diff
changeset
|
74 hbuf = *p_hbuf = g_list_last(*p_hbuf); |
502
3134b4960cdb
Fix mixed declaration and code
Mikael Berthe <mikael@lilotux.net>
parents:
464
diff
changeset
|
75 hbuf_b_prev = hbuf->data; |
71 | 76 hbuf_block_elt->ptr = hbuf_b_prev->ptr_end; |
77 hbuf_block_elt->flags = HBB_FLAG_PERSISTENT; | |
182 | 78 hbuf_block_elt->ptr_end_alloc = hbuf_b_prev->ptr_end_alloc; |
790
5d4ad1d77da4
Kill a few gcc4 warnings
Mikael Berthe <mikael@lilotux.net>
parents:
733
diff
changeset
|
79 *p_hbuf = g_list_append(*p_hbuf, hbuf_block_elt); |
71 | 80 } |
81 | |
82 if (strlen(text) >= HBB_BLOCKSIZE) { | |
83 // Too long | |
84 text = "[ERR:LINE_TOO_LONG]"; | |
197 | 85 hbuf_block_elt->prefix.flags |= HBB_PREFIX_INFO; |
71 | 86 } |
182 | 87 if (hbuf_block_elt->ptr + strlen(text) >= hbuf_block_elt->ptr_end_alloc) { |
71 | 88 // Too long for the current allocated bloc, we need another one |
390 | 89 hbuf_block_elt->ptr = g_new0(char, HBB_BLOCKSIZE); |
71 | 90 hbuf_block_elt->flags = HBB_FLAG_ALLOC | HBB_FLAG_PERSISTENT; |
182 | 91 hbuf_block_elt->ptr_end_alloc = hbuf_block_elt->ptr + HBB_BLOCKSIZE; |
71 | 92 } |
93 | |
94 line = hbuf_block_elt->ptr; | |
95 // Ok, now we can copy the text.. | |
96 strcpy(line, text); | |
97 hbuf_block_elt->ptr_end = line + strlen(line) + 1; | |
98 end = hbuf_block_elt->ptr_end; | |
99 | |
100 // Let's add non-persistent blocs if necessary | |
101 // - If there are '\n' in the string | |
102 // - If length > width (and width != 0) | |
103 cr = strchr(line, '\n'); | |
104 while (cr || (width && strlen(line) > width)) { | |
105 hbuf_block *hbuf_b_prev = hbuf_block_elt; | |
106 | |
107 if (!width || (cr && (cr - line <= (int)width))) { | |
108 // Carriage return | |
109 *cr = 0; | |
110 hbuf_block_elt->ptr_end = cr; | |
111 // Create another persistent block | |
112 hbuf_block_elt = g_new0(hbuf_block, 1); | |
113 hbuf_block_elt->ptr = hbuf_b_prev->ptr_end + 1; // == cr+1 | |
114 hbuf_block_elt->ptr_end = end; | |
115 hbuf_block_elt->flags = HBB_FLAG_PERSISTENT; | |
182 | 116 hbuf_block_elt->ptr_end_alloc = hbuf_b_prev->ptr_end_alloc; |
790
5d4ad1d77da4
Kill a few gcc4 warnings
Mikael Berthe <mikael@lilotux.net>
parents:
733
diff
changeset
|
117 *p_hbuf = g_list_append(*p_hbuf, hbuf_block_elt); |
71 | 118 line = hbuf_block_elt->ptr; |
119 } else { | |
120 // We need to break where we can find a space char | |
121 char *br; // break pointer | |
122 for (br = line + width; br > line && *br != 32 && *br != 9; br--) | |
123 ; | |
124 if (br <= line) | |
125 br = line + width; | |
126 else | |
127 br++; | |
128 hbuf_block_elt->ptr_end = br; | |
129 // Create another block, non-persistent | |
130 hbuf_block_elt = g_new0(hbuf_block, 1); | |
131 hbuf_block_elt->ptr = hbuf_b_prev->ptr_end; // == br | |
132 hbuf_block_elt->ptr_end = end; | |
133 hbuf_block_elt->flags = 0; | |
182 | 134 hbuf_block_elt->ptr_end_alloc = hbuf_b_prev->ptr_end_alloc; |
790
5d4ad1d77da4
Kill a few gcc4 warnings
Mikael Berthe <mikael@lilotux.net>
parents:
733
diff
changeset
|
135 *p_hbuf = g_list_append(*p_hbuf, hbuf_block_elt); |
71 | 136 line = hbuf_block_elt->ptr; |
137 } | |
138 cr = strchr(line, '\n'); | |
139 } | |
140 } | |
141 | |
142 // hbuf_free() | |
143 // Destroys all hbuf list. | |
144 void hbuf_free(GList **p_hbuf) | |
145 { | |
146 hbuf_block *hbuf_b_elt; | |
147 GList *hbuf_elt; | |
148 GList *first_elt = g_list_first(*p_hbuf); | |
149 | |
150 for (hbuf_elt = first_elt; hbuf_elt; hbuf_elt = g_list_next(hbuf_elt)) { | |
151 hbuf_b_elt = (hbuf_block*)(hbuf_elt->data); | |
152 if (hbuf_b_elt->flags & HBB_FLAG_ALLOC) { | |
153 g_free(hbuf_b_elt->ptr); | |
154 } | |
390 | 155 g_free(hbuf_b_elt); |
71 | 156 } |
157 | |
158 g_list_free(*p_hbuf); | |
159 *p_hbuf = NULL; | |
160 } | |
161 | |
162 // hbuf_rebuild() | |
163 // Rebuild all hbuf list, with the new width. | |
164 // If width == 0, lines are not wrapped. | |
165 void hbuf_rebuild(GList **p_hbuf, unsigned int width) | |
166 { | |
167 GList *first_elt, *curr_elt, *next_elt; | |
168 hbuf_block *hbuf_b_curr, *hbuf_b_next; | |
169 | |
150 | 170 // *p_hbuf needs to be the head of the list |
171 first_elt = *p_hbuf = g_list_first(*p_hbuf); | |
71 | 172 |
173 // #1 Remove non-persistent blocks (ptr_end should be updated!) | |
174 curr_elt = first_elt; | |
175 while (curr_elt) { | |
176 next_elt = g_list_next(curr_elt); | |
177 // Last element? | |
178 if (!next_elt) | |
179 break; | |
180 hbuf_b_curr = (hbuf_block*)(curr_elt->data); | |
181 hbuf_b_next = (hbuf_block*)(next_elt->data); | |
182 // Is next line not-persistent? | |
183 if (!(hbuf_b_next->flags & HBB_FLAG_PERSISTENT)) { | |
184 hbuf_b_curr->ptr_end = hbuf_b_next->ptr_end; | |
390 | 185 g_free(hbuf_b_next); |
790
5d4ad1d77da4
Kill a few gcc4 warnings
Mikael Berthe <mikael@lilotux.net>
parents:
733
diff
changeset
|
186 curr_elt = g_list_delete_link(curr_elt, next_elt); |
393 | 187 } else |
71 | 188 curr_elt = next_elt; |
189 } | |
190 // #2 Go back to head and create non-persistent blocks when needed | |
191 if (width) { | |
192 char *line, *end; | |
193 curr_elt = first_elt; | |
194 | |
195 while (curr_elt) { | |
196 hbuf_b_curr = (hbuf_block*)(curr_elt->data); | |
197 line = hbuf_b_curr->ptr; | |
198 if (strlen(line) > width) { | |
199 hbuf_block *hbuf_b_prev = hbuf_b_curr; | |
200 | |
201 // We need to break where we can find a space char | |
202 char *br; // break pointer | |
203 for (br = line + width; br > line && *br != 32 && *br != 9; br--) | |
204 ; | |
205 if (br <= line) | |
206 br = line + width; | |
207 else | |
208 br++; | |
209 end = hbuf_b_curr->ptr_end; | |
210 hbuf_b_curr->ptr_end = br; | |
211 // Create another block, non-persistent | |
212 hbuf_b_curr = g_new0(hbuf_block, 1); | |
213 hbuf_b_curr->ptr = hbuf_b_prev->ptr_end; // == br | |
214 hbuf_b_curr->ptr_end = end; | |
215 hbuf_b_curr->flags = 0; | |
182 | 216 hbuf_b_curr->ptr_end_alloc = hbuf_b_prev->ptr_end_alloc; |
150 | 217 // This is OK because insert_before(NULL) == append(): |
218 *p_hbuf = g_list_insert_before(*p_hbuf, curr_elt->next, hbuf_b_curr); | |
71 | 219 } |
220 curr_elt = g_list_next(curr_elt); | |
221 } | |
222 } | |
223 } | |
224 | |
189 | 225 // hbuf_previous_persistent() |
226 // Returns the previous persistent block (line). If the given line is | |
227 // persistent, then it is returned. | |
228 // This function is used for example when resizing a buffer. If the top of the | |
229 // screen is on a non-persistent block, then a screen resize could destroy this | |
230 // line... | |
231 GList *hbuf_previous_persistent(GList *l_line) | |
232 { | |
233 hbuf_block *hbuf_b_elt; | |
234 | |
235 while (l_line) { | |
236 hbuf_b_elt = (hbuf_block*)l_line->data; | |
237 if (hbuf_b_elt->flags & HBB_FLAG_PERSISTENT) | |
238 return l_line; | |
239 l_line = g_list_previous(l_line); | |
240 } | |
241 | |
242 return NULL; | |
243 } | |
244 | |
368
da50f08ea058
Update hbuf_get_lines() comment
Mikael Berthe <mikael@lilotux.net>
parents:
197
diff
changeset
|
245 // hbuf_get_lines(hbuf, n) |
370
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
368
diff
changeset
|
246 // Returns an array of n hbb_line pointers |
71 | 247 // (The first line will be the line currently pointed by hbuf) |
368
da50f08ea058
Update hbuf_get_lines() comment
Mikael Berthe <mikael@lilotux.net>
parents:
197
diff
changeset
|
248 // Note: The caller should free the array and the text pointers after use. |
184 | 249 hbb_line **hbuf_get_lines(GList *hbuf, unsigned int n) |
71 | 250 { |
251 unsigned int i; | |
729
39f67cade02c
Use bold font for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
252 hbuf_block *blk; |
39f67cade02c
Use bold font for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
253 guchar last_persist_prefixflags = 0; |
733
c502bfe67c31
Fix highlighting of outgoing multi-line messages
Mikael Berthe <mikael@lilotux.net>
parents:
729
diff
changeset
|
254 GList *last_persist; // last persistent flags |
729
39f67cade02c
Use bold font for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
255 |
733
c502bfe67c31
Fix highlighting of outgoing multi-line messages
Mikael Berthe <mikael@lilotux.net>
parents:
729
diff
changeset
|
256 // To be able to correctly highlight multi-line messages, |
c502bfe67c31
Fix highlighting of outgoing multi-line messages
Mikael Berthe <mikael@lilotux.net>
parents:
729
diff
changeset
|
257 // we need to look at the last non-null prefix, which should be the first |
c502bfe67c31
Fix highlighting of outgoing multi-line messages
Mikael Berthe <mikael@lilotux.net>
parents:
729
diff
changeset
|
258 // line of the message. |
729
39f67cade02c
Use bold font for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
259 last_persist = hbuf_previous_persistent(hbuf); |
733
c502bfe67c31
Fix highlighting of outgoing multi-line messages
Mikael Berthe <mikael@lilotux.net>
parents:
729
diff
changeset
|
260 while (last_persist) { |
c502bfe67c31
Fix highlighting of outgoing multi-line messages
Mikael Berthe <mikael@lilotux.net>
parents:
729
diff
changeset
|
261 blk = (hbuf_block*)last_persist->data; |
c502bfe67c31
Fix highlighting of outgoing multi-line messages
Mikael Berthe <mikael@lilotux.net>
parents:
729
diff
changeset
|
262 if ((blk->flags & HBB_FLAG_PERSISTENT) && blk->prefix.flags) { |
c502bfe67c31
Fix highlighting of outgoing multi-line messages
Mikael Berthe <mikael@lilotux.net>
parents:
729
diff
changeset
|
263 last_persist_prefixflags = blk->prefix.flags; |
c502bfe67c31
Fix highlighting of outgoing multi-line messages
Mikael Berthe <mikael@lilotux.net>
parents:
729
diff
changeset
|
264 break; |
c502bfe67c31
Fix highlighting of outgoing multi-line messages
Mikael Berthe <mikael@lilotux.net>
parents:
729
diff
changeset
|
265 } |
c502bfe67c31
Fix highlighting of outgoing multi-line messages
Mikael Berthe <mikael@lilotux.net>
parents:
729
diff
changeset
|
266 last_persist = g_list_previous(last_persist); |
729
39f67cade02c
Use bold font for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
267 } |
71 | 268 |
184 | 269 hbb_line **array = g_new0(hbb_line*, n); |
270 hbb_line **array_elt = array; | |
71 | 271 |
272 for (i=0 ; i < n ; i++) { | |
273 if (hbuf) { | |
274 int maxlen; | |
729
39f67cade02c
Use bold font for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
275 blk = (hbuf_block*)(hbuf->data); |
71 | 276 maxlen = blk->ptr_end - blk->ptr; |
184 | 277 *array_elt = (hbb_line*)g_new(hbb_line, 1); |
278 (*array_elt)->timestamp = blk->prefix.timestamp; | |
279 (*array_elt)->flags = blk->prefix.flags; | |
280 (*array_elt)->text = g_strndup(blk->ptr, maxlen); | |
281 | |
733
c502bfe67c31
Fix highlighting of outgoing multi-line messages
Mikael Berthe <mikael@lilotux.net>
parents:
729
diff
changeset
|
282 if ((blk->flags & HBB_FLAG_PERSISTENT) && blk->prefix.flags) { |
729
39f67cade02c
Use bold font for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
283 last_persist_prefixflags = blk->prefix.flags; |
39f67cade02c
Use bold font for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
284 } else { |
39f67cade02c
Use bold font for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
285 // Propagate hilighting flag |
39f67cade02c
Use bold font for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
286 (*array_elt)->flags |= last_persist_prefixflags & HBB_PREFIX_HLIGHT; |
39f67cade02c
Use bold font for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
287 } |
39f67cade02c
Use bold font for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
288 |
71 | 289 hbuf = g_list_next(hbuf); |
290 } else | |
184 | 291 break; |
292 | |
293 array_elt++; | |
71 | 294 } |
295 | |
296 return array; | |
297 } | |
298 | |
370
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
368
diff
changeset
|
299 // hbuf_search(hbuf, direction, string) |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
368
diff
changeset
|
300 // Look backward/forward for a line containing string in the history buffer |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
368
diff
changeset
|
301 // Search starts at hbuf, and goes forward if direction == 1, backward if -1 |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
368
diff
changeset
|
302 GList *hbuf_search(GList *hbuf, int direction, const char *string) |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
368
diff
changeset
|
303 { |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
368
diff
changeset
|
304 hbuf_block *blk; |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
368
diff
changeset
|
305 |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
368
diff
changeset
|
306 for (;;) { |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
368
diff
changeset
|
307 if (direction > 0) |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
368
diff
changeset
|
308 hbuf = g_list_next(hbuf); |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
368
diff
changeset
|
309 else |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
368
diff
changeset
|
310 hbuf = g_list_previous(hbuf); |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
368
diff
changeset
|
311 |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
368
diff
changeset
|
312 if (!hbuf) break; |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
368
diff
changeset
|
313 |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
368
diff
changeset
|
314 blk = (hbuf_block*)(hbuf->data); |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
368
diff
changeset
|
315 // XXX blk->ptr is (maybe) not really correct, because the match should |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
368
diff
changeset
|
316 // not be after ptr_end. We should check that... |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
368
diff
changeset
|
317 if (strcasestr(blk->ptr, string)) |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
368
diff
changeset
|
318 break; |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
368
diff
changeset
|
319 } |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
368
diff
changeset
|
320 |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
368
diff
changeset
|
321 return hbuf; |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
368
diff
changeset
|
322 } |
462 | 323 |
464 | 324 // hbuf_jump_date(hbuf, t) |
325 // Return a pointer to the first line after date t in the history buffer | |
326 GList *hbuf_jump_date(GList *hbuf, time_t t) | |
327 { | |
328 hbuf_block *blk; | |
329 | |
330 hbuf = g_list_first(hbuf); | |
331 | |
332 for ( ; hbuf && g_list_next(hbuf); hbuf = g_list_next(hbuf)) { | |
333 blk = (hbuf_block*)(hbuf->data); | |
334 if (blk->prefix.timestamp >= t) break; | |
335 } | |
336 | |
337 return hbuf; | |
338 } | |
339 | |
462 | 340 // hbuf_jump_percent(hbuf, pc) |
341 // Return a pointer to the line at % pc of the history buffer | |
342 GList *hbuf_jump_percent(GList *hbuf, int pc) | |
343 { | |
344 guint hlen; | |
345 | |
346 hbuf = g_list_first(hbuf); | |
347 hlen = g_list_length(hbuf); | |
348 | |
349 return g_list_nth(hbuf, pc*hlen/100); | |
350 } | |
576 | 351 |
580 | 352 /* vim: set expandtab cindent cinoptions=>2\:2(0: For Vim users... */ |