Mercurial > hg
comparison mcabber/src/hbuf.c @ 370:dd9e2eb52916
Add /buffer search_{backward,forward}
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Sun, 24 Jul 2005 22:56:42 +0100 |
parents | da50f08ea058 |
children | 468c9cac2798 |
comparison
equal
deleted
inserted
replaced
369:499170ed71c9 | 370:dd9e2eb52916 |
---|---|
17 * along with this program; if not, write to the Free Software | 17 * along with this program; if not, write to the Free Software |
18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 | 18 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 |
19 * USA | 19 * USA |
20 */ | 20 */ |
21 | 21 |
22 #define _GNU_SOURCE /* We need glibc for strptime */ | |
22 #include <string.h> | 23 #include <string.h> |
23 | 24 |
24 #include "hbuf.h" | 25 #include "hbuf.h" |
25 | 26 |
26 | 27 |
237 | 238 |
238 return NULL; | 239 return NULL; |
239 } | 240 } |
240 | 241 |
241 // hbuf_get_lines(hbuf, n) | 242 // hbuf_get_lines(hbuf, n) |
242 // Returns an array of n *hbb_line pointers | 243 // Returns an array of n hbb_line pointers |
243 // (The first line will be the line currently pointed by hbuf) | 244 // (The first line will be the line currently pointed by hbuf) |
244 // Note: The caller should free the array and the text pointers after use. | 245 // Note: The caller should free the array and the text pointers after use. |
245 hbb_line **hbuf_get_lines(GList *hbuf, unsigned int n) | 246 hbb_line **hbuf_get_lines(GList *hbuf, unsigned int n) |
246 { | 247 { |
247 unsigned int i; | 248 unsigned int i; |
267 } | 268 } |
268 | 269 |
269 return array; | 270 return array; |
270 } | 271 } |
271 | 272 |
273 // hbuf_search(hbuf, direction, string) | |
274 // Look backward/forward for a line containing string in the history buffer | |
275 // Search starts at hbuf, and goes forward if direction == 1, backward if -1 | |
276 GList *hbuf_search(GList *hbuf, int direction, const char *string) | |
277 { | |
278 hbuf_block *blk; | |
279 | |
280 for (;;) { | |
281 if (direction > 0) | |
282 hbuf = g_list_next(hbuf); | |
283 else | |
284 hbuf = g_list_previous(hbuf); | |
285 | |
286 if (!hbuf) break; | |
287 | |
288 blk = (hbuf_block*)(hbuf->data); | |
289 // XXX blk->ptr is (maybe) not really correct, because the match should | |
290 // not be after ptr_end. We should check that... | |
291 if (strcasestr(blk->ptr, string)) | |
292 break; | |
293 } | |
294 | |
295 return hbuf; | |
296 } |