Mercurial > ~mikael > mcabber > hg
annotate mcabber/mcabber/hbuf.c @ 1961:39021fd6b0e1
Try to improve readmarks in some cases
This patch removes the readmark when entering chatmode if the mark is on the
last line. This should hopefully fix weird behavior seen under some
circumstances.
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Tue, 15 Mar 2011 00:39:17 +0100 |
parents | f309f343070c |
children | ec737f5f1d6f |
rev | line source |
---|---|
71 | 1 /* |
2 * hbuf.c -- History buffer implementation | |
393 | 3 * |
1729
e6e89b1d7831
Minor style and header updates
Mikael Berthe <mikael@lilotux.net>
parents:
1668
diff
changeset
|
4 * Copyright (C) 2005-2010 Mikael Berthe <mikael@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 | |
22 #include <string.h> | |
1485
0121b6f3047c
New command: /buffer save
Mikael Berthe <mikael@lilotux.net>
parents:
1424
diff
changeset
|
23 #include <sys/types.h> |
0121b6f3047c
New command: /buffer save
Mikael Berthe <mikael@lilotux.net>
parents:
1424
diff
changeset
|
24 #include <sys/stat.h> |
0121b6f3047c
New command: /buffer save
Mikael Berthe <mikael@lilotux.net>
parents:
1424
diff
changeset
|
25 #include <unistd.h> |
71 | 26 |
27 #include "hbuf.h" | |
804
339c76ed5c0d
Remove a warning on Cygwin (implicit strcasestr() declaration)
Mikael Berthe <mikael@lilotux.net>
parents:
790
diff
changeset
|
28 #include "utils.h" |
930
a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
Mikael Berthe <mikael@lilotux.net>
parents:
924
diff
changeset
|
29 #include "utf8.h" |
1485
0121b6f3047c
New command: /buffer save
Mikael Berthe <mikael@lilotux.net>
parents:
1424
diff
changeset
|
30 #include "screen.h" |
71 | 31 |
32 | |
33 /* This is a private structure type */ | |
34 | |
35 typedef struct { | |
36 char *ptr; | |
182 | 37 char *ptr_end; // beginning of the block |
38 char *ptr_end_alloc; // end of the current persistent block | |
71 | 39 guchar flags; |
40 | |
41 // XXX This should certainly be a pointer, and be allocated only when needed | |
42 // (for ex. when HBB_FLAG_PERSISTENT is set). | |
43 struct { // hbuf_line_info | |
184 | 44 time_t timestamp; |
1290
e42f48103609
Drawing the MUC nicks by a different color
Michal 'vorner' Vaner <vorner@ucw.cz>
parents:
1268
diff
changeset
|
45 unsigned mucnicklen; |
850
d0781ca2dd08
Use new status buffer window
Mikael Berthe <mikael@lilotux.net>
parents:
804
diff
changeset
|
46 guint flags; |
1602 | 47 gpointer xep184; |
184 | 48 } prefix; |
71 | 49 } hbuf_block; |
50 | |
51 | |
943
9ac0d166a85b
hbuf: Refactor line wrapping stuff
Mikael Berthe <mikael@lilotux.net>
parents:
942
diff
changeset
|
52 // do_wrap(p_hbuf, first_hbuf_elt, width) |
9ac0d166a85b
hbuf: Refactor line wrapping stuff
Mikael Berthe <mikael@lilotux.net>
parents:
942
diff
changeset
|
53 // Wrap hbuf lines with the specified width. |
9ac0d166a85b
hbuf: Refactor line wrapping stuff
Mikael Berthe <mikael@lilotux.net>
parents:
942
diff
changeset
|
54 // '\n' are handled by this routine (they are removed and persistent lines |
9ac0d166a85b
hbuf: Refactor line wrapping stuff
Mikael Berthe <mikael@lilotux.net>
parents:
942
diff
changeset
|
55 // are created). |
9ac0d166a85b
hbuf: Refactor line wrapping stuff
Mikael Berthe <mikael@lilotux.net>
parents:
942
diff
changeset
|
56 // All hbuf elements are processed, starting from first_hbuf_elt. |
9ac0d166a85b
hbuf: Refactor line wrapping stuff
Mikael Berthe <mikael@lilotux.net>
parents:
942
diff
changeset
|
57 static inline void do_wrap(GList **p_hbuf, GList *first_hbuf_elt, |
9ac0d166a85b
hbuf: Refactor line wrapping stuff
Mikael Berthe <mikael@lilotux.net>
parents:
942
diff
changeset
|
58 unsigned int width) |
71 | 59 { |
943
9ac0d166a85b
hbuf: Refactor line wrapping stuff
Mikael Berthe <mikael@lilotux.net>
parents:
942
diff
changeset
|
60 GList *curr_elt = first_hbuf_elt; |
942
c6bd42119c31
Make hbuf_add_line() UTF-8 aware
Mikael Berthe <mikael@lilotux.net>
parents:
932
diff
changeset
|
61 |
71 | 62 // Let's add non-persistent blocs if necessary |
63 // - If there are '\n' in the string | |
64 // - If length > width (and width != 0) | |
942
c6bd42119c31
Make hbuf_add_line() UTF-8 aware
Mikael Berthe <mikael@lilotux.net>
parents:
932
diff
changeset
|
65 while (curr_elt) { |
943
9ac0d166a85b
hbuf: Refactor line wrapping stuff
Mikael Berthe <mikael@lilotux.net>
parents:
942
diff
changeset
|
66 hbuf_block *hbuf_b_curr, *hbuf_b_prev; |
942
c6bd42119c31
Make hbuf_add_line() UTF-8 aware
Mikael Berthe <mikael@lilotux.net>
parents:
932
diff
changeset
|
67 char *c, *end; |
c6bd42119c31
Make hbuf_add_line() UTF-8 aware
Mikael Berthe <mikael@lilotux.net>
parents:
932
diff
changeset
|
68 char *br = NULL; // break pointer |
c6bd42119c31
Make hbuf_add_line() UTF-8 aware
Mikael Berthe <mikael@lilotux.net>
parents:
932
diff
changeset
|
69 char *cr = NULL; // CR pointer |
c6bd42119c31
Make hbuf_add_line() UTF-8 aware
Mikael Berthe <mikael@lilotux.net>
parents:
932
diff
changeset
|
70 unsigned int cur_w = 0; |
c6bd42119c31
Make hbuf_add_line() UTF-8 aware
Mikael Berthe <mikael@lilotux.net>
parents:
932
diff
changeset
|
71 |
c6bd42119c31
Make hbuf_add_line() UTF-8 aware
Mikael Berthe <mikael@lilotux.net>
parents:
932
diff
changeset
|
72 // We want to break where we can find a space char or a CR |
c6bd42119c31
Make hbuf_add_line() UTF-8 aware
Mikael Berthe <mikael@lilotux.net>
parents:
932
diff
changeset
|
73 |
c6bd42119c31
Make hbuf_add_line() UTF-8 aware
Mikael Berthe <mikael@lilotux.net>
parents:
932
diff
changeset
|
74 hbuf_b_curr = (hbuf_block*)(curr_elt->data); |
c6bd42119c31
Make hbuf_add_line() UTF-8 aware
Mikael Berthe <mikael@lilotux.net>
parents:
932
diff
changeset
|
75 hbuf_b_prev = hbuf_b_curr; |
c6bd42119c31
Make hbuf_add_line() UTF-8 aware
Mikael Berthe <mikael@lilotux.net>
parents:
932
diff
changeset
|
76 c = hbuf_b_curr->ptr; |
71 | 77 |
942
c6bd42119c31
Make hbuf_add_line() UTF-8 aware
Mikael Berthe <mikael@lilotux.net>
parents:
932
diff
changeset
|
78 while (*c && (!width || cur_w <= width)) { |
c6bd42119c31
Make hbuf_add_line() UTF-8 aware
Mikael Berthe <mikael@lilotux.net>
parents:
932
diff
changeset
|
79 if (*c == '\n') { |
c6bd42119c31
Make hbuf_add_line() UTF-8 aware
Mikael Berthe <mikael@lilotux.net>
parents:
932
diff
changeset
|
80 br = cr = c; |
c6bd42119c31
Make hbuf_add_line() UTF-8 aware
Mikael Berthe <mikael@lilotux.net>
parents:
932
diff
changeset
|
81 *c = 0; |
c6bd42119c31
Make hbuf_add_line() UTF-8 aware
Mikael Berthe <mikael@lilotux.net>
parents:
932
diff
changeset
|
82 break; |
c6bd42119c31
Make hbuf_add_line() UTF-8 aware
Mikael Berthe <mikael@lilotux.net>
parents:
932
diff
changeset
|
83 } |
c6bd42119c31
Make hbuf_add_line() UTF-8 aware
Mikael Berthe <mikael@lilotux.net>
parents:
932
diff
changeset
|
84 if (iswblank(get_char(c))) |
c6bd42119c31
Make hbuf_add_line() UTF-8 aware
Mikael Berthe <mikael@lilotux.net>
parents:
932
diff
changeset
|
85 br = c; |
c6bd42119c31
Make hbuf_add_line() UTF-8 aware
Mikael Berthe <mikael@lilotux.net>
parents:
932
diff
changeset
|
86 cur_w += get_char_width(c); |
c6bd42119c31
Make hbuf_add_line() UTF-8 aware
Mikael Berthe <mikael@lilotux.net>
parents:
932
diff
changeset
|
87 c = next_char(c); |
c6bd42119c31
Make hbuf_add_line() UTF-8 aware
Mikael Berthe <mikael@lilotux.net>
parents:
932
diff
changeset
|
88 } |
c6bd42119c31
Make hbuf_add_line() UTF-8 aware
Mikael Berthe <mikael@lilotux.net>
parents:
932
diff
changeset
|
89 |
c6bd42119c31
Make hbuf_add_line() UTF-8 aware
Mikael Berthe <mikael@lilotux.net>
parents:
932
diff
changeset
|
90 if (cr || (*c && cur_w > width)) { |
c6bd42119c31
Make hbuf_add_line() UTF-8 aware
Mikael Berthe <mikael@lilotux.net>
parents:
932
diff
changeset
|
91 if (!br || br == hbuf_b_curr->ptr) |
c6bd42119c31
Make hbuf_add_line() UTF-8 aware
Mikael Berthe <mikael@lilotux.net>
parents:
932
diff
changeset
|
92 br = c; |
71 | 93 else |
942
c6bd42119c31
Make hbuf_add_line() UTF-8 aware
Mikael Berthe <mikael@lilotux.net>
parents:
932
diff
changeset
|
94 br = next_char(br); |
c6bd42119c31
Make hbuf_add_line() UTF-8 aware
Mikael Berthe <mikael@lilotux.net>
parents:
932
diff
changeset
|
95 end = hbuf_b_curr->ptr_end; |
c6bd42119c31
Make hbuf_add_line() UTF-8 aware
Mikael Berthe <mikael@lilotux.net>
parents:
932
diff
changeset
|
96 hbuf_b_curr->ptr_end = br; |
c6bd42119c31
Make hbuf_add_line() UTF-8 aware
Mikael Berthe <mikael@lilotux.net>
parents:
932
diff
changeset
|
97 // Create another block |
c6bd42119c31
Make hbuf_add_line() UTF-8 aware
Mikael Berthe <mikael@lilotux.net>
parents:
932
diff
changeset
|
98 hbuf_b_curr = g_new0(hbuf_block, 1); |
c6bd42119c31
Make hbuf_add_line() UTF-8 aware
Mikael Berthe <mikael@lilotux.net>
parents:
932
diff
changeset
|
99 // The block must be persistent after a CR |
c6bd42119c31
Make hbuf_add_line() UTF-8 aware
Mikael Berthe <mikael@lilotux.net>
parents:
932
diff
changeset
|
100 if (cr) { |
c6bd42119c31
Make hbuf_add_line() UTF-8 aware
Mikael Berthe <mikael@lilotux.net>
parents:
932
diff
changeset
|
101 hbuf_b_curr->ptr = hbuf_b_prev->ptr_end + 1; // == cr+1 |
c6bd42119c31
Make hbuf_add_line() UTF-8 aware
Mikael Berthe <mikael@lilotux.net>
parents:
932
diff
changeset
|
102 hbuf_b_curr->flags = HBB_FLAG_PERSISTENT; |
c6bd42119c31
Make hbuf_add_line() UTF-8 aware
Mikael Berthe <mikael@lilotux.net>
parents:
932
diff
changeset
|
103 } else { |
c6bd42119c31
Make hbuf_add_line() UTF-8 aware
Mikael Berthe <mikael@lilotux.net>
parents:
932
diff
changeset
|
104 hbuf_b_curr->ptr = hbuf_b_prev->ptr_end; // == br |
c6bd42119c31
Make hbuf_add_line() UTF-8 aware
Mikael Berthe <mikael@lilotux.net>
parents:
932
diff
changeset
|
105 hbuf_b_curr->flags = 0; |
c6bd42119c31
Make hbuf_add_line() UTF-8 aware
Mikael Berthe <mikael@lilotux.net>
parents:
932
diff
changeset
|
106 } |
c6bd42119c31
Make hbuf_add_line() UTF-8 aware
Mikael Berthe <mikael@lilotux.net>
parents:
932
diff
changeset
|
107 hbuf_b_curr->ptr_end = end; |
c6bd42119c31
Make hbuf_add_line() UTF-8 aware
Mikael Berthe <mikael@lilotux.net>
parents:
932
diff
changeset
|
108 hbuf_b_curr->ptr_end_alloc = hbuf_b_prev->ptr_end_alloc; |
c6bd42119c31
Make hbuf_add_line() UTF-8 aware
Mikael Berthe <mikael@lilotux.net>
parents:
932
diff
changeset
|
109 // This is OK because insert_before(NULL) == append(): |
c6bd42119c31
Make hbuf_add_line() UTF-8 aware
Mikael Berthe <mikael@lilotux.net>
parents:
932
diff
changeset
|
110 *p_hbuf = g_list_insert_before(*p_hbuf, curr_elt->next, hbuf_b_curr); |
71 | 111 } |
942
c6bd42119c31
Make hbuf_add_line() UTF-8 aware
Mikael Berthe <mikael@lilotux.net>
parents:
932
diff
changeset
|
112 curr_elt = g_list_next(curr_elt); |
71 | 113 } |
114 } | |
115 | |
1141
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1011
diff
changeset
|
116 // hbuf_add_line(p_hbuf, text, prefix_flags, width, maxhbufblocks) |
943
9ac0d166a85b
hbuf: Refactor line wrapping stuff
Mikael Berthe <mikael@lilotux.net>
parents:
942
diff
changeset
|
117 // Add a line to the given buffer. If width is not null, then lines are |
9ac0d166a85b
hbuf: Refactor line wrapping stuff
Mikael Berthe <mikael@lilotux.net>
parents:
942
diff
changeset
|
118 // wrapped at this length. |
1141
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1011
diff
changeset
|
119 // maxhbufblocks is the maximum number of hbuf blocks we can allocate. If |
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1011
diff
changeset
|
120 // null, there is no limit. If non-null, it should be >= 2. |
943
9ac0d166a85b
hbuf: Refactor line wrapping stuff
Mikael Berthe <mikael@lilotux.net>
parents:
942
diff
changeset
|
121 // |
9ac0d166a85b
hbuf: Refactor line wrapping stuff
Mikael Berthe <mikael@lilotux.net>
parents:
942
diff
changeset
|
122 // Note 1: Splitting according to width won't work if there are tabs; they |
9ac0d166a85b
hbuf: Refactor line wrapping stuff
Mikael Berthe <mikael@lilotux.net>
parents:
942
diff
changeset
|
123 // should be expanded before. |
9ac0d166a85b
hbuf: Refactor line wrapping stuff
Mikael Berthe <mikael@lilotux.net>
parents:
942
diff
changeset
|
124 // Note 2: width does not include the ending \0. |
9ac0d166a85b
hbuf: Refactor line wrapping stuff
Mikael Berthe <mikael@lilotux.net>
parents:
942
diff
changeset
|
125 void hbuf_add_line(GList **p_hbuf, const char *text, time_t timestamp, |
1290
e42f48103609
Drawing the MUC nicks by a different color
Michal 'vorner' Vaner <vorner@ucw.cz>
parents:
1268
diff
changeset
|
126 guint prefix_flags, guint width, guint maxhbufblocks, |
1602 | 127 unsigned mucnicklen, gpointer xep184) |
943
9ac0d166a85b
hbuf: Refactor line wrapping stuff
Mikael Berthe <mikael@lilotux.net>
parents:
942
diff
changeset
|
128 { |
9ac0d166a85b
hbuf: Refactor line wrapping stuff
Mikael Berthe <mikael@lilotux.net>
parents:
942
diff
changeset
|
129 GList *curr_elt; |
1141
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1011
diff
changeset
|
130 char *line; |
1364
ff1f6facdc0c
Allow dynamic HBB sizes
Mikael Berthe <mikael@lilotux.net>
parents:
1290
diff
changeset
|
131 guint hbb_blocksize, textlen; |
943
9ac0d166a85b
hbuf: Refactor line wrapping stuff
Mikael Berthe <mikael@lilotux.net>
parents:
942
diff
changeset
|
132 hbuf_block *hbuf_block_elt; |
9ac0d166a85b
hbuf: Refactor line wrapping stuff
Mikael Berthe <mikael@lilotux.net>
parents:
942
diff
changeset
|
133 |
9ac0d166a85b
hbuf: Refactor line wrapping stuff
Mikael Berthe <mikael@lilotux.net>
parents:
942
diff
changeset
|
134 if (!text) return; |
9ac0d166a85b
hbuf: Refactor line wrapping stuff
Mikael Berthe <mikael@lilotux.net>
parents:
942
diff
changeset
|
135 |
1602 | 136 prefix_flags |= (xep184 ? HBB_PREFIX_RECEIPT : 0); |
137 | |
1364
ff1f6facdc0c
Allow dynamic HBB sizes
Mikael Berthe <mikael@lilotux.net>
parents:
1290
diff
changeset
|
138 textlen = strlen(text); |
ff1f6facdc0c
Allow dynamic HBB sizes
Mikael Berthe <mikael@lilotux.net>
parents:
1290
diff
changeset
|
139 hbb_blocksize = MAX(textlen+1, HBB_BLOCKSIZE); |
ff1f6facdc0c
Allow dynamic HBB sizes
Mikael Berthe <mikael@lilotux.net>
parents:
1290
diff
changeset
|
140 |
943
9ac0d166a85b
hbuf: Refactor line wrapping stuff
Mikael Berthe <mikael@lilotux.net>
parents:
942
diff
changeset
|
141 hbuf_block_elt = g_new0(hbuf_block, 1); |
9ac0d166a85b
hbuf: Refactor line wrapping stuff
Mikael Berthe <mikael@lilotux.net>
parents:
942
diff
changeset
|
142 hbuf_block_elt->prefix.timestamp = timestamp; |
9ac0d166a85b
hbuf: Refactor line wrapping stuff
Mikael Berthe <mikael@lilotux.net>
parents:
942
diff
changeset
|
143 hbuf_block_elt->prefix.flags = prefix_flags; |
1290
e42f48103609
Drawing the MUC nicks by a different color
Michal 'vorner' Vaner <vorner@ucw.cz>
parents:
1268
diff
changeset
|
144 hbuf_block_elt->prefix.mucnicklen = mucnicklen; |
1602 | 145 hbuf_block_elt->prefix.xep184 = xep184; |
1011
b5bcc223cf51
Fix a bug in hbuf_add_line()
Mikael Berthe <mikael@lilotux.net>
parents:
943
diff
changeset
|
146 if (!*p_hbuf) { |
1364
ff1f6facdc0c
Allow dynamic HBB sizes
Mikael Berthe <mikael@lilotux.net>
parents:
1290
diff
changeset
|
147 hbuf_block_elt->ptr = g_new(char, hbb_blocksize); |
ff1f6facdc0c
Allow dynamic HBB sizes
Mikael Berthe <mikael@lilotux.net>
parents:
1290
diff
changeset
|
148 if (!hbuf_block_elt->ptr) { |
ff1f6facdc0c
Allow dynamic HBB sizes
Mikael Berthe <mikael@lilotux.net>
parents:
1290
diff
changeset
|
149 g_free(hbuf_block_elt); |
ff1f6facdc0c
Allow dynamic HBB sizes
Mikael Berthe <mikael@lilotux.net>
parents:
1290
diff
changeset
|
150 return; |
ff1f6facdc0c
Allow dynamic HBB sizes
Mikael Berthe <mikael@lilotux.net>
parents:
1290
diff
changeset
|
151 } |
943
9ac0d166a85b
hbuf: Refactor line wrapping stuff
Mikael Berthe <mikael@lilotux.net>
parents:
942
diff
changeset
|
152 hbuf_block_elt->flags = HBB_FLAG_ALLOC | HBB_FLAG_PERSISTENT; |
1364
ff1f6facdc0c
Allow dynamic HBB sizes
Mikael Berthe <mikael@lilotux.net>
parents:
1290
diff
changeset
|
153 hbuf_block_elt->ptr_end_alloc = hbuf_block_elt->ptr + hbb_blocksize; |
943
9ac0d166a85b
hbuf: Refactor line wrapping stuff
Mikael Berthe <mikael@lilotux.net>
parents:
942
diff
changeset
|
154 } else { |
9ac0d166a85b
hbuf: Refactor line wrapping stuff
Mikael Berthe <mikael@lilotux.net>
parents:
942
diff
changeset
|
155 hbuf_block *hbuf_b_prev; |
9ac0d166a85b
hbuf: Refactor line wrapping stuff
Mikael Berthe <mikael@lilotux.net>
parents:
942
diff
changeset
|
156 // Set p_hbuf to the end of the list, to speed up history loading |
9ac0d166a85b
hbuf: Refactor line wrapping stuff
Mikael Berthe <mikael@lilotux.net>
parents:
942
diff
changeset
|
157 // (or CPU time will be used by g_list_last() for each line) |
1011
b5bcc223cf51
Fix a bug in hbuf_add_line()
Mikael Berthe <mikael@lilotux.net>
parents:
943
diff
changeset
|
158 *p_hbuf = g_list_last(*p_hbuf); |
b5bcc223cf51
Fix a bug in hbuf_add_line()
Mikael Berthe <mikael@lilotux.net>
parents:
943
diff
changeset
|
159 hbuf_b_prev = (*p_hbuf)->data; |
943
9ac0d166a85b
hbuf: Refactor line wrapping stuff
Mikael Berthe <mikael@lilotux.net>
parents:
942
diff
changeset
|
160 hbuf_block_elt->ptr = hbuf_b_prev->ptr_end; |
9ac0d166a85b
hbuf: Refactor line wrapping stuff
Mikael Berthe <mikael@lilotux.net>
parents:
942
diff
changeset
|
161 hbuf_block_elt->flags = HBB_FLAG_PERSISTENT; |
9ac0d166a85b
hbuf: Refactor line wrapping stuff
Mikael Berthe <mikael@lilotux.net>
parents:
942
diff
changeset
|
162 hbuf_block_elt->ptr_end_alloc = hbuf_b_prev->ptr_end_alloc; |
9ac0d166a85b
hbuf: Refactor line wrapping stuff
Mikael Berthe <mikael@lilotux.net>
parents:
942
diff
changeset
|
163 } |
1011
b5bcc223cf51
Fix a bug in hbuf_add_line()
Mikael Berthe <mikael@lilotux.net>
parents:
943
diff
changeset
|
164 *p_hbuf = g_list_append(*p_hbuf, hbuf_block_elt); |
943
9ac0d166a85b
hbuf: Refactor line wrapping stuff
Mikael Berthe <mikael@lilotux.net>
parents:
942
diff
changeset
|
165 |
1364
ff1f6facdc0c
Allow dynamic HBB sizes
Mikael Berthe <mikael@lilotux.net>
parents:
1290
diff
changeset
|
166 if (hbuf_block_elt->ptr + textlen >= hbuf_block_elt->ptr_end_alloc) { |
943
9ac0d166a85b
hbuf: Refactor line wrapping stuff
Mikael Berthe <mikael@lilotux.net>
parents:
942
diff
changeset
|
167 // Too long for the current allocated bloc, we need another one |
1364
ff1f6facdc0c
Allow dynamic HBB sizes
Mikael Berthe <mikael@lilotux.net>
parents:
1290
diff
changeset
|
168 if (!maxhbufblocks || textlen >= HBB_BLOCKSIZE) { |
1141
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1011
diff
changeset
|
169 // No limit, let's allocate a new block |
1364
ff1f6facdc0c
Allow dynamic HBB sizes
Mikael Berthe <mikael@lilotux.net>
parents:
1290
diff
changeset
|
170 // If the message text is big, we won't bother to reuse an old block |
ff1f6facdc0c
Allow dynamic HBB sizes
Mikael Berthe <mikael@lilotux.net>
parents:
1290
diff
changeset
|
171 // as well (it could be too small and cause a segfault). |
ff1f6facdc0c
Allow dynamic HBB sizes
Mikael Berthe <mikael@lilotux.net>
parents:
1290
diff
changeset
|
172 hbuf_block_elt->ptr = g_new0(char, hbb_blocksize); |
ff1f6facdc0c
Allow dynamic HBB sizes
Mikael Berthe <mikael@lilotux.net>
parents:
1290
diff
changeset
|
173 hbuf_block_elt->ptr_end_alloc = hbuf_block_elt->ptr + hbb_blocksize; |
ff1f6facdc0c
Allow dynamic HBB sizes
Mikael Berthe <mikael@lilotux.net>
parents:
1290
diff
changeset
|
174 // XXX We should check the return value. |
1141
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1011
diff
changeset
|
175 } else { |
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1011
diff
changeset
|
176 GList *hbuf_head, *hbuf_elt; |
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1011
diff
changeset
|
177 hbuf_block *hbuf_b_elt; |
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1011
diff
changeset
|
178 guint n = 0; |
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1011
diff
changeset
|
179 hbuf_head = g_list_first(*p_hbuf); |
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1011
diff
changeset
|
180 // We need at least 2 allocated blocks |
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1011
diff
changeset
|
181 if (maxhbufblocks == 1) |
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1011
diff
changeset
|
182 maxhbufblocks = 2; |
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1011
diff
changeset
|
183 // Let's count the number of allocated areas |
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1011
diff
changeset
|
184 for (hbuf_elt = hbuf_head; hbuf_elt; hbuf_elt = g_list_next(hbuf_elt)) { |
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1011
diff
changeset
|
185 hbuf_b_elt = (hbuf_block*)(hbuf_elt->data); |
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1011
diff
changeset
|
186 if (hbuf_b_elt->flags & HBB_FLAG_ALLOC) |
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1011
diff
changeset
|
187 n++; |
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1011
diff
changeset
|
188 } |
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1011
diff
changeset
|
189 // If we can't allocate a new area, reuse the previous block(s) |
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1011
diff
changeset
|
190 if (n < maxhbufblocks) { |
1364
ff1f6facdc0c
Allow dynamic HBB sizes
Mikael Berthe <mikael@lilotux.net>
parents:
1290
diff
changeset
|
191 hbuf_block_elt->ptr = g_new0(char, hbb_blocksize); |
ff1f6facdc0c
Allow dynamic HBB sizes
Mikael Berthe <mikael@lilotux.net>
parents:
1290
diff
changeset
|
192 hbuf_block_elt->ptr_end_alloc = hbuf_block_elt->ptr + hbb_blocksize; |
1141
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1011
diff
changeset
|
193 } else { |
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1011
diff
changeset
|
194 // Let's use an old block, and free the extra blocks if needed |
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1011
diff
changeset
|
195 char *allocated_block = NULL; |
1364
ff1f6facdc0c
Allow dynamic HBB sizes
Mikael Berthe <mikael@lilotux.net>
parents:
1290
diff
changeset
|
196 char *end_of_allocated_block = NULL; |
1141
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1011
diff
changeset
|
197 while (n >= maxhbufblocks) { |
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1011
diff
changeset
|
198 int start_of_block = 1; |
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1011
diff
changeset
|
199 for (hbuf_elt = hbuf_head; hbuf_elt; hbuf_elt = hbuf_head) { |
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1011
diff
changeset
|
200 hbuf_b_elt = (hbuf_block*)(hbuf_elt->data); |
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1011
diff
changeset
|
201 if (hbuf_b_elt->flags & HBB_FLAG_ALLOC) { |
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1011
diff
changeset
|
202 if (start_of_block-- == 0) |
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1011
diff
changeset
|
203 break; |
1364
ff1f6facdc0c
Allow dynamic HBB sizes
Mikael Berthe <mikael@lilotux.net>
parents:
1290
diff
changeset
|
204 if (n == maxhbufblocks) { |
1141
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1011
diff
changeset
|
205 allocated_block = hbuf_b_elt->ptr; |
1364
ff1f6facdc0c
Allow dynamic HBB sizes
Mikael Berthe <mikael@lilotux.net>
parents:
1290
diff
changeset
|
206 end_of_allocated_block = hbuf_b_elt->ptr_end_alloc; |
ff1f6facdc0c
Allow dynamic HBB sizes
Mikael Berthe <mikael@lilotux.net>
parents:
1290
diff
changeset
|
207 } else { |
1141
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1011
diff
changeset
|
208 g_free(hbuf_b_elt->ptr); |
1364
ff1f6facdc0c
Allow dynamic HBB sizes
Mikael Berthe <mikael@lilotux.net>
parents:
1290
diff
changeset
|
209 } |
1141
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1011
diff
changeset
|
210 } |
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1011
diff
changeset
|
211 g_free(hbuf_b_elt); |
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1011
diff
changeset
|
212 hbuf_head = *p_hbuf = g_list_delete_link(hbuf_head, hbuf_elt); |
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1011
diff
changeset
|
213 } |
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1011
diff
changeset
|
214 n--; |
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1011
diff
changeset
|
215 } |
1364
ff1f6facdc0c
Allow dynamic HBB sizes
Mikael Berthe <mikael@lilotux.net>
parents:
1290
diff
changeset
|
216 memset(allocated_block, 0, end_of_allocated_block-allocated_block); |
1141
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1011
diff
changeset
|
217 hbuf_block_elt->ptr = allocated_block; |
1364
ff1f6facdc0c
Allow dynamic HBB sizes
Mikael Berthe <mikael@lilotux.net>
parents:
1290
diff
changeset
|
218 hbuf_block_elt->ptr_end_alloc = end_of_allocated_block; |
1141
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1011
diff
changeset
|
219 } |
5be2408a6534
Add option "max_history_blocks"
Mikael Berthe <mikael@lilotux.net>
parents:
1011
diff
changeset
|
220 } |
943
9ac0d166a85b
hbuf: Refactor line wrapping stuff
Mikael Berthe <mikael@lilotux.net>
parents:
942
diff
changeset
|
221 hbuf_block_elt->flags = HBB_FLAG_ALLOC | HBB_FLAG_PERSISTENT; |
9ac0d166a85b
hbuf: Refactor line wrapping stuff
Mikael Berthe <mikael@lilotux.net>
parents:
942
diff
changeset
|
222 } |
9ac0d166a85b
hbuf: Refactor line wrapping stuff
Mikael Berthe <mikael@lilotux.net>
parents:
942
diff
changeset
|
223 |
9ac0d166a85b
hbuf: Refactor line wrapping stuff
Mikael Berthe <mikael@lilotux.net>
parents:
942
diff
changeset
|
224 line = hbuf_block_elt->ptr; |
9ac0d166a85b
hbuf: Refactor line wrapping stuff
Mikael Berthe <mikael@lilotux.net>
parents:
942
diff
changeset
|
225 // Ok, now we can copy the text.. |
9ac0d166a85b
hbuf: Refactor line wrapping stuff
Mikael Berthe <mikael@lilotux.net>
parents:
942
diff
changeset
|
226 strcpy(line, text); |
1364
ff1f6facdc0c
Allow dynamic HBB sizes
Mikael Berthe <mikael@lilotux.net>
parents:
1290
diff
changeset
|
227 hbuf_block_elt->ptr_end = line + textlen + 1; |
943
9ac0d166a85b
hbuf: Refactor line wrapping stuff
Mikael Berthe <mikael@lilotux.net>
parents:
942
diff
changeset
|
228 |
1011
b5bcc223cf51
Fix a bug in hbuf_add_line()
Mikael Berthe <mikael@lilotux.net>
parents:
943
diff
changeset
|
229 curr_elt = g_list_last(*p_hbuf); |
943
9ac0d166a85b
hbuf: Refactor line wrapping stuff
Mikael Berthe <mikael@lilotux.net>
parents:
942
diff
changeset
|
230 |
9ac0d166a85b
hbuf: Refactor line wrapping stuff
Mikael Berthe <mikael@lilotux.net>
parents:
942
diff
changeset
|
231 // Wrap lines and handle CRs ('\n') |
9ac0d166a85b
hbuf: Refactor line wrapping stuff
Mikael Berthe <mikael@lilotux.net>
parents:
942
diff
changeset
|
232 do_wrap(p_hbuf, curr_elt, width); |
9ac0d166a85b
hbuf: Refactor line wrapping stuff
Mikael Berthe <mikael@lilotux.net>
parents:
942
diff
changeset
|
233 } |
9ac0d166a85b
hbuf: Refactor line wrapping stuff
Mikael Berthe <mikael@lilotux.net>
parents:
942
diff
changeset
|
234 |
71 | 235 // hbuf_free() |
236 // Destroys all hbuf list. | |
237 void hbuf_free(GList **p_hbuf) | |
238 { | |
239 hbuf_block *hbuf_b_elt; | |
240 GList *hbuf_elt; | |
241 GList *first_elt = g_list_first(*p_hbuf); | |
242 | |
243 for (hbuf_elt = first_elt; hbuf_elt; hbuf_elt = g_list_next(hbuf_elt)) { | |
244 hbuf_b_elt = (hbuf_block*)(hbuf_elt->data); | |
245 if (hbuf_b_elt->flags & HBB_FLAG_ALLOC) { | |
246 g_free(hbuf_b_elt->ptr); | |
247 } | |
390 | 248 g_free(hbuf_b_elt); |
71 | 249 } |
250 | |
893
92aaf2af786b
Fix a small memory leak in /buffer purge
Mikael Berthe <mikael@lilotux.net>
parents:
852
diff
changeset
|
251 g_list_free(first_elt); |
71 | 252 *p_hbuf = NULL; |
253 } | |
254 | |
255 // hbuf_rebuild() | |
256 // Rebuild all hbuf list, with the new width. | |
257 // If width == 0, lines are not wrapped. | |
258 void hbuf_rebuild(GList **p_hbuf, unsigned int width) | |
259 { | |
260 GList *first_elt, *curr_elt, *next_elt; | |
261 hbuf_block *hbuf_b_curr, *hbuf_b_next; | |
262 | |
150 | 263 // *p_hbuf needs to be the head of the list |
264 first_elt = *p_hbuf = g_list_first(*p_hbuf); | |
71 | 265 |
266 // #1 Remove non-persistent blocks (ptr_end should be updated!) | |
267 curr_elt = first_elt; | |
268 while (curr_elt) { | |
269 next_elt = g_list_next(curr_elt); | |
270 // Last element? | |
271 if (!next_elt) | |
272 break; | |
273 hbuf_b_curr = (hbuf_block*)(curr_elt->data); | |
274 hbuf_b_next = (hbuf_block*)(next_elt->data); | |
275 // Is next line not-persistent? | |
276 if (!(hbuf_b_next->flags & HBB_FLAG_PERSISTENT)) { | |
277 hbuf_b_curr->ptr_end = hbuf_b_next->ptr_end; | |
390 | 278 g_free(hbuf_b_next); |
790
5d4ad1d77da4
Kill a few gcc4 warnings
Mikael Berthe <mikael@lilotux.net>
parents:
733
diff
changeset
|
279 curr_elt = g_list_delete_link(curr_elt, next_elt); |
393 | 280 } else |
71 | 281 curr_elt = next_elt; |
282 } | |
283 // #2 Go back to head and create non-persistent blocks when needed | |
943
9ac0d166a85b
hbuf: Refactor line wrapping stuff
Mikael Berthe <mikael@lilotux.net>
parents:
942
diff
changeset
|
284 if (width) |
9ac0d166a85b
hbuf: Refactor line wrapping stuff
Mikael Berthe <mikael@lilotux.net>
parents:
942
diff
changeset
|
285 do_wrap(p_hbuf, first_elt, width); |
71 | 286 } |
287 | |
189 | 288 // hbuf_previous_persistent() |
289 // Returns the previous persistent block (line). If the given line is | |
290 // persistent, then it is returned. | |
291 // This function is used for example when resizing a buffer. If the top of the | |
292 // screen is on a non-persistent block, then a screen resize could destroy this | |
293 // line... | |
294 GList *hbuf_previous_persistent(GList *l_line) | |
295 { | |
296 hbuf_block *hbuf_b_elt; | |
297 | |
298 while (l_line) { | |
299 hbuf_b_elt = (hbuf_block*)l_line->data; | |
300 if (hbuf_b_elt->flags & HBB_FLAG_PERSISTENT) | |
301 return l_line; | |
302 l_line = g_list_previous(l_line); | |
303 } | |
304 | |
305 return NULL; | |
306 } | |
307 | |
368
da50f08ea058
Update hbuf_get_lines() comment
Mikael Berthe <mikael@lilotux.net>
parents:
197
diff
changeset
|
308 // hbuf_get_lines(hbuf, n) |
370
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
368
diff
changeset
|
309 // Returns an array of n hbb_line pointers |
71 | 310 // (The first line will be the line currently pointed by hbuf) |
898
c65b71dcda94
Fix memory leak in scr_UpdateWindow()
Mikael Berthe <mikael@lilotux.net>
parents:
893
diff
changeset
|
311 // Note: The caller should free the array, the hbb_line pointers and the |
c65b71dcda94
Fix memory leak in scr_UpdateWindow()
Mikael Berthe <mikael@lilotux.net>
parents:
893
diff
changeset
|
312 // text pointers after use. |
184 | 313 hbb_line **hbuf_get_lines(GList *hbuf, unsigned int n) |
71 | 314 { |
315 unsigned int i; | |
729
39f67cade02c
Use bold font for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
316 hbuf_block *blk; |
1204
e802ec0c02d2
Basic support for nick highlighting in MUC rooms (the whole line is colored)
Mikael Berthe <mikael@lilotux.net>
parents:
1141
diff
changeset
|
317 guint last_persist_prefixflags = 0; |
733
c502bfe67c31
Fix highlighting of outgoing multi-line messages
Mikael Berthe <mikael@lilotux.net>
parents:
729
diff
changeset
|
318 GList *last_persist; // last persistent flags |
852
a3b8956db7bc
hbuf: minor fixes and typos
Mikael Berthe <mikael@lilotux.net>
parents:
850
diff
changeset
|
319 hbb_line **array, **array_elt; |
1948 | 320 hbb_line *prev_array_elt = NULL; |
729
39f67cade02c
Use bold font for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
321 |
733
c502bfe67c31
Fix highlighting of outgoing multi-line messages
Mikael Berthe <mikael@lilotux.net>
parents:
729
diff
changeset
|
322 // 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
|
323 // 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
|
324 // line of the message. |
729
39f67cade02c
Use bold font for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
325 last_persist = hbuf_previous_persistent(hbuf); |
733
c502bfe67c31
Fix highlighting of outgoing multi-line messages
Mikael Berthe <mikael@lilotux.net>
parents:
729
diff
changeset
|
326 while (last_persist) { |
c502bfe67c31
Fix highlighting of outgoing multi-line messages
Mikael Berthe <mikael@lilotux.net>
parents:
729
diff
changeset
|
327 blk = (hbuf_block*)last_persist->data; |
c502bfe67c31
Fix highlighting of outgoing multi-line messages
Mikael Berthe <mikael@lilotux.net>
parents:
729
diff
changeset
|
328 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
|
329 last_persist_prefixflags = blk->prefix.flags; |
c502bfe67c31
Fix highlighting of outgoing multi-line messages
Mikael Berthe <mikael@lilotux.net>
parents:
729
diff
changeset
|
330 break; |
c502bfe67c31
Fix highlighting of outgoing multi-line messages
Mikael Berthe <mikael@lilotux.net>
parents:
729
diff
changeset
|
331 } |
c502bfe67c31
Fix highlighting of outgoing multi-line messages
Mikael Berthe <mikael@lilotux.net>
parents:
729
diff
changeset
|
332 last_persist = g_list_previous(last_persist); |
729
39f67cade02c
Use bold font for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
333 } |
71 | 334 |
852
a3b8956db7bc
hbuf: minor fixes and typos
Mikael Berthe <mikael@lilotux.net>
parents:
850
diff
changeset
|
335 array = g_new0(hbb_line*, n); |
a3b8956db7bc
hbuf: minor fixes and typos
Mikael Berthe <mikael@lilotux.net>
parents:
850
diff
changeset
|
336 array_elt = array; |
71 | 337 |
852
a3b8956db7bc
hbuf: minor fixes and typos
Mikael Berthe <mikael@lilotux.net>
parents:
850
diff
changeset
|
338 for (i = 0 ; i < n ; i++) { |
71 | 339 if (hbuf) { |
340 int maxlen; | |
1485
0121b6f3047c
New command: /buffer save
Mikael Berthe <mikael@lilotux.net>
parents:
1424
diff
changeset
|
341 |
729
39f67cade02c
Use bold font for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
342 blk = (hbuf_block*)(hbuf->data); |
71 | 343 maxlen = blk->ptr_end - blk->ptr; |
184 | 344 *array_elt = (hbb_line*)g_new(hbb_line, 1); |
1290
e42f48103609
Drawing the MUC nicks by a different color
Michal 'vorner' Vaner <vorner@ucw.cz>
parents:
1268
diff
changeset
|
345 (*array_elt)->timestamp = blk->prefix.timestamp; |
e42f48103609
Drawing the MUC nicks by a different color
Michal 'vorner' Vaner <vorner@ucw.cz>
parents:
1268
diff
changeset
|
346 (*array_elt)->flags = blk->prefix.flags; |
e42f48103609
Drawing the MUC nicks by a different color
Michal 'vorner' Vaner <vorner@ucw.cz>
parents:
1268
diff
changeset
|
347 (*array_elt)->mucnicklen = blk->prefix.mucnicklen; |
e42f48103609
Drawing the MUC nicks by a different color
Michal 'vorner' Vaner <vorner@ucw.cz>
parents:
1268
diff
changeset
|
348 (*array_elt)->text = g_strndup(blk->ptr, maxlen); |
184 | 349 |
733
c502bfe67c31
Fix highlighting of outgoing multi-line messages
Mikael Berthe <mikael@lilotux.net>
parents:
729
diff
changeset
|
350 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
|
351 last_persist_prefixflags = blk->prefix.flags; |
39f67cade02c
Use bold font for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
352 } else { |
1204
e802ec0c02d2
Basic support for nick highlighting in MUC rooms (the whole line is colored)
Mikael Berthe <mikael@lilotux.net>
parents:
1141
diff
changeset
|
353 // Propagate highlighting flags |
e802ec0c02d2
Basic support for nick highlighting in MUC rooms (the whole line is colored)
Mikael Berthe <mikael@lilotux.net>
parents:
1141
diff
changeset
|
354 (*array_elt)->flags |= last_persist_prefixflags & |
1268
dbc907b2d92f
Add configurable colors for info and incoming messages (Michal 'vorner' Vaner)
Mikael Berthe <mikael@lilotux.net>
parents:
1241
diff
changeset
|
355 (HBB_PREFIX_HLIGHT_OUT | HBB_PREFIX_HLIGHT | |
1948 | 356 HBB_PREFIX_INFO | HBB_PREFIX_IN | |
357 HBB_PREFIX_READMARK); | |
1485
0121b6f3047c
New command: /buffer save
Mikael Berthe <mikael@lilotux.net>
parents:
1424
diff
changeset
|
358 // Continuation of a message - omit the prefix |
1268
dbc907b2d92f
Add configurable colors for info and incoming messages (Michal 'vorner' Vaner)
Mikael Berthe <mikael@lilotux.net>
parents:
1241
diff
changeset
|
359 (*array_elt)->flags |= HBB_PREFIX_CONT; |
1485
0121b6f3047c
New command: /buffer save
Mikael Berthe <mikael@lilotux.net>
parents:
1424
diff
changeset
|
360 (*array_elt)->mucnicklen = 0; // The nick is in the first one |
1948 | 361 // Remove readmark flag from the previous line |
362 if (last_persist_prefixflags & HBB_PREFIX_READMARK) | |
363 prev_array_elt->flags &= ~HBB_PREFIX_READMARK; | |
729
39f67cade02c
Use bold font for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
364 } |
39f67cade02c
Use bold font for outgoing messages
Mikael Berthe <mikael@lilotux.net>
parents:
699
diff
changeset
|
365 |
1948 | 366 prev_array_elt = *array_elt; |
367 | |
71 | 368 hbuf = g_list_next(hbuf); |
369 } else | |
184 | 370 break; |
371 | |
372 array_elt++; | |
71 | 373 } |
374 | |
375 return array; | |
376 } | |
377 | |
370
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
368
diff
changeset
|
378 // hbuf_search(hbuf, direction, string) |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
368
diff
changeset
|
379 // 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
|
380 // 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
|
381 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
|
382 { |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
368
diff
changeset
|
383 hbuf_block *blk; |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
368
diff
changeset
|
384 |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
368
diff
changeset
|
385 for (;;) { |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
368
diff
changeset
|
386 if (direction > 0) |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
368
diff
changeset
|
387 hbuf = g_list_next(hbuf); |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
368
diff
changeset
|
388 else |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
368
diff
changeset
|
389 hbuf = g_list_previous(hbuf); |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
368
diff
changeset
|
390 |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
368
diff
changeset
|
391 if (!hbuf) break; |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
368
diff
changeset
|
392 |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
368
diff
changeset
|
393 blk = (hbuf_block*)(hbuf->data); |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
368
diff
changeset
|
394 // 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
|
395 // not be after ptr_end. We should check that... |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
368
diff
changeset
|
396 if (strcasestr(blk->ptr, string)) |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
368
diff
changeset
|
397 break; |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
368
diff
changeset
|
398 } |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
368
diff
changeset
|
399 |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
368
diff
changeset
|
400 return hbuf; |
dd9e2eb52916
Add /buffer search_{backward,forward}
Mikael Berthe <mikael@lilotux.net>
parents:
368
diff
changeset
|
401 } |
462 | 402 |
464 | 403 // hbuf_jump_date(hbuf, t) |
404 // Return a pointer to the first line after date t in the history buffer | |
405 GList *hbuf_jump_date(GList *hbuf, time_t t) | |
406 { | |
407 hbuf_block *blk; | |
408 | |
409 hbuf = g_list_first(hbuf); | |
410 | |
411 for ( ; hbuf && g_list_next(hbuf); hbuf = g_list_next(hbuf)) { | |
412 blk = (hbuf_block*)(hbuf->data); | |
413 if (blk->prefix.timestamp >= t) break; | |
414 } | |
415 | |
416 return hbuf; | |
417 } | |
418 | |
462 | 419 // hbuf_jump_percent(hbuf, pc) |
420 // Return a pointer to the line at % pc of the history buffer | |
421 GList *hbuf_jump_percent(GList *hbuf, int pc) | |
422 { | |
423 guint hlen; | |
424 | |
425 hbuf = g_list_first(hbuf); | |
426 hlen = g_list_length(hbuf); | |
427 | |
428 return g_list_nth(hbuf, pc*hlen/100); | |
429 } | |
576 | 430 |
1956
f309f343070c
Add command /buffer readmark
Mikael Berthe <mikael@lilotux.net>
parents:
1948
diff
changeset
|
431 // hbuf_jump_readmark(hbuf) |
f309f343070c
Add command /buffer readmark
Mikael Berthe <mikael@lilotux.net>
parents:
1948
diff
changeset
|
432 // Return a pointer to the line following the readmark |
f309f343070c
Add command /buffer readmark
Mikael Berthe <mikael@lilotux.net>
parents:
1948
diff
changeset
|
433 // or NULL if no mark was found. |
f309f343070c
Add command /buffer readmark
Mikael Berthe <mikael@lilotux.net>
parents:
1948
diff
changeset
|
434 GList *hbuf_jump_readmark(GList *hbuf) |
f309f343070c
Add command /buffer readmark
Mikael Berthe <mikael@lilotux.net>
parents:
1948
diff
changeset
|
435 { |
f309f343070c
Add command /buffer readmark
Mikael Berthe <mikael@lilotux.net>
parents:
1948
diff
changeset
|
436 hbuf_block *blk; |
f309f343070c
Add command /buffer readmark
Mikael Berthe <mikael@lilotux.net>
parents:
1948
diff
changeset
|
437 |
f309f343070c
Add command /buffer readmark
Mikael Berthe <mikael@lilotux.net>
parents:
1948
diff
changeset
|
438 hbuf = g_list_last(hbuf); |
f309f343070c
Add command /buffer readmark
Mikael Berthe <mikael@lilotux.net>
parents:
1948
diff
changeset
|
439 for ( ; hbuf; hbuf = g_list_previous(hbuf)) { |
f309f343070c
Add command /buffer readmark
Mikael Berthe <mikael@lilotux.net>
parents:
1948
diff
changeset
|
440 blk = (hbuf_block*)(hbuf->data); |
f309f343070c
Add command /buffer readmark
Mikael Berthe <mikael@lilotux.net>
parents:
1948
diff
changeset
|
441 if (blk->prefix.flags & HBB_PREFIX_READMARK) |
f309f343070c
Add command /buffer readmark
Mikael Berthe <mikael@lilotux.net>
parents:
1948
diff
changeset
|
442 return g_list_next(hbuf); |
f309f343070c
Add command /buffer readmark
Mikael Berthe <mikael@lilotux.net>
parents:
1948
diff
changeset
|
443 } |
f309f343070c
Add command /buffer readmark
Mikael Berthe <mikael@lilotux.net>
parents:
1948
diff
changeset
|
444 |
f309f343070c
Add command /buffer readmark
Mikael Berthe <mikael@lilotux.net>
parents:
1948
diff
changeset
|
445 return NULL; |
f309f343070c
Add command /buffer readmark
Mikael Berthe <mikael@lilotux.net>
parents:
1948
diff
changeset
|
446 } |
f309f343070c
Add command /buffer readmark
Mikael Berthe <mikael@lilotux.net>
parents:
1948
diff
changeset
|
447 |
1485
0121b6f3047c
New command: /buffer save
Mikael Berthe <mikael@lilotux.net>
parents:
1424
diff
changeset
|
448 // hbuf_dump_to_file(hbuf, filename) |
0121b6f3047c
New command: /buffer save
Mikael Berthe <mikael@lilotux.net>
parents:
1424
diff
changeset
|
449 // Save the buffer to a file. |
0121b6f3047c
New command: /buffer save
Mikael Berthe <mikael@lilotux.net>
parents:
1424
diff
changeset
|
450 void hbuf_dump_to_file(GList *hbuf, const char *filename) |
0121b6f3047c
New command: /buffer save
Mikael Berthe <mikael@lilotux.net>
parents:
1424
diff
changeset
|
451 { |
0121b6f3047c
New command: /buffer save
Mikael Berthe <mikael@lilotux.net>
parents:
1424
diff
changeset
|
452 hbuf_block *blk; |
0121b6f3047c
New command: /buffer save
Mikael Berthe <mikael@lilotux.net>
parents:
1424
diff
changeset
|
453 hbb_line line; |
1547 | 454 guint last_persist_prefixflags = 0; |
1486
f83a51eaa5ed
Fix multiline output in /buffer save
Mikael Berthe <mikael@lilotux.net>
parents:
1485
diff
changeset
|
455 guint prefixwidth; |
1485
0121b6f3047c
New command: /buffer save
Mikael Berthe <mikael@lilotux.net>
parents:
1424
diff
changeset
|
456 char pref[96]; |
0121b6f3047c
New command: /buffer save
Mikael Berthe <mikael@lilotux.net>
parents:
1424
diff
changeset
|
457 FILE *fp; |
0121b6f3047c
New command: /buffer save
Mikael Berthe <mikael@lilotux.net>
parents:
1424
diff
changeset
|
458 struct stat statbuf; |
0121b6f3047c
New command: /buffer save
Mikael Berthe <mikael@lilotux.net>
parents:
1424
diff
changeset
|
459 |
0121b6f3047c
New command: /buffer save
Mikael Berthe <mikael@lilotux.net>
parents:
1424
diff
changeset
|
460 if (!stat(filename, &statbuf)) { |
0121b6f3047c
New command: /buffer save
Mikael Berthe <mikael@lilotux.net>
parents:
1424
diff
changeset
|
461 scr_LogPrint(LPRINT_NORMAL, "The file already exists."); |
0121b6f3047c
New command: /buffer save
Mikael Berthe <mikael@lilotux.net>
parents:
1424
diff
changeset
|
462 return; |
0121b6f3047c
New command: /buffer save
Mikael Berthe <mikael@lilotux.net>
parents:
1424
diff
changeset
|
463 } |
0121b6f3047c
New command: /buffer save
Mikael Berthe <mikael@lilotux.net>
parents:
1424
diff
changeset
|
464 fp = fopen(filename, "w"); |
0121b6f3047c
New command: /buffer save
Mikael Berthe <mikael@lilotux.net>
parents:
1424
diff
changeset
|
465 if (!fp) { |
0121b6f3047c
New command: /buffer save
Mikael Berthe <mikael@lilotux.net>
parents:
1424
diff
changeset
|
466 scr_LogPrint(LPRINT_NORMAL, "Unable to open the file."); |
0121b6f3047c
New command: /buffer save
Mikael Berthe <mikael@lilotux.net>
parents:
1424
diff
changeset
|
467 return; |
0121b6f3047c
New command: /buffer save
Mikael Berthe <mikael@lilotux.net>
parents:
1424
diff
changeset
|
468 } |
0121b6f3047c
New command: /buffer save
Mikael Berthe <mikael@lilotux.net>
parents:
1424
diff
changeset
|
469 |
1487 | 470 prefixwidth = scr_getprefixwidth(); |
1486
f83a51eaa5ed
Fix multiline output in /buffer save
Mikael Berthe <mikael@lilotux.net>
parents:
1485
diff
changeset
|
471 prefixwidth = MIN(prefixwidth, sizeof pref); |
f83a51eaa5ed
Fix multiline output in /buffer save
Mikael Berthe <mikael@lilotux.net>
parents:
1485
diff
changeset
|
472 |
1485
0121b6f3047c
New command: /buffer save
Mikael Berthe <mikael@lilotux.net>
parents:
1424
diff
changeset
|
473 for (hbuf = g_list_first(hbuf); hbuf; hbuf = g_list_next(hbuf)) { |
0121b6f3047c
New command: /buffer save
Mikael Berthe <mikael@lilotux.net>
parents:
1424
diff
changeset
|
474 int maxlen; |
0121b6f3047c
New command: /buffer save
Mikael Berthe <mikael@lilotux.net>
parents:
1424
diff
changeset
|
475 |
0121b6f3047c
New command: /buffer save
Mikael Berthe <mikael@lilotux.net>
parents:
1424
diff
changeset
|
476 blk = (hbuf_block*)(hbuf->data); |
0121b6f3047c
New command: /buffer save
Mikael Berthe <mikael@lilotux.net>
parents:
1424
diff
changeset
|
477 maxlen = blk->ptr_end - blk->ptr; |
0121b6f3047c
New command: /buffer save
Mikael Berthe <mikael@lilotux.net>
parents:
1424
diff
changeset
|
478 |
0121b6f3047c
New command: /buffer save
Mikael Berthe <mikael@lilotux.net>
parents:
1424
diff
changeset
|
479 memset(&line, 0, sizeof(line)); |
0121b6f3047c
New command: /buffer save
Mikael Berthe <mikael@lilotux.net>
parents:
1424
diff
changeset
|
480 line.timestamp = blk->prefix.timestamp; |
0121b6f3047c
New command: /buffer save
Mikael Berthe <mikael@lilotux.net>
parents:
1424
diff
changeset
|
481 line.flags = blk->prefix.flags; |
0121b6f3047c
New command: /buffer save
Mikael Berthe <mikael@lilotux.net>
parents:
1424
diff
changeset
|
482 line.mucnicklen = blk->prefix.mucnicklen; |
0121b6f3047c
New command: /buffer save
Mikael Berthe <mikael@lilotux.net>
parents:
1424
diff
changeset
|
483 line.text = g_strndup(blk->ptr, maxlen); |
0121b6f3047c
New command: /buffer save
Mikael Berthe <mikael@lilotux.net>
parents:
1424
diff
changeset
|
484 |
0121b6f3047c
New command: /buffer save
Mikael Berthe <mikael@lilotux.net>
parents:
1424
diff
changeset
|
485 if ((blk->flags & HBB_FLAG_PERSISTENT) && blk->prefix.flags) { |
0121b6f3047c
New command: /buffer save
Mikael Berthe <mikael@lilotux.net>
parents:
1424
diff
changeset
|
486 last_persist_prefixflags = blk->prefix.flags; |
0121b6f3047c
New command: /buffer save
Mikael Berthe <mikael@lilotux.net>
parents:
1424
diff
changeset
|
487 } else { |
0121b6f3047c
New command: /buffer save
Mikael Berthe <mikael@lilotux.net>
parents:
1424
diff
changeset
|
488 // Propagate highlighting flags |
0121b6f3047c
New command: /buffer save
Mikael Berthe <mikael@lilotux.net>
parents:
1424
diff
changeset
|
489 line.flags |= last_persist_prefixflags & |
0121b6f3047c
New command: /buffer save
Mikael Berthe <mikael@lilotux.net>
parents:
1424
diff
changeset
|
490 (HBB_PREFIX_HLIGHT_OUT | HBB_PREFIX_HLIGHT | |
0121b6f3047c
New command: /buffer save
Mikael Berthe <mikael@lilotux.net>
parents:
1424
diff
changeset
|
491 HBB_PREFIX_INFO | HBB_PREFIX_IN); |
0121b6f3047c
New command: /buffer save
Mikael Berthe <mikael@lilotux.net>
parents:
1424
diff
changeset
|
492 // Continuation of a message - omit the prefix |
0121b6f3047c
New command: /buffer save
Mikael Berthe <mikael@lilotux.net>
parents:
1424
diff
changeset
|
493 line.flags |= HBB_PREFIX_CONT; |
0121b6f3047c
New command: /buffer save
Mikael Berthe <mikael@lilotux.net>
parents:
1424
diff
changeset
|
494 line.mucnicklen = 0; // The nick is in the first one |
0121b6f3047c
New command: /buffer save
Mikael Berthe <mikael@lilotux.net>
parents:
1424
diff
changeset
|
495 } |
0121b6f3047c
New command: /buffer save
Mikael Berthe <mikael@lilotux.net>
parents:
1424
diff
changeset
|
496 |
1486
f83a51eaa5ed
Fix multiline output in /buffer save
Mikael Berthe <mikael@lilotux.net>
parents:
1485
diff
changeset
|
497 scr_line_prefix(&line, pref, prefixwidth); |
1485
0121b6f3047c
New command: /buffer save
Mikael Berthe <mikael@lilotux.net>
parents:
1424
diff
changeset
|
498 fprintf(fp, "%s%s\n", pref, line.text); |
0121b6f3047c
New command: /buffer save
Mikael Berthe <mikael@lilotux.net>
parents:
1424
diff
changeset
|
499 } |
0121b6f3047c
New command: /buffer save
Mikael Berthe <mikael@lilotux.net>
parents:
1424
diff
changeset
|
500 |
0121b6f3047c
New command: /buffer save
Mikael Berthe <mikael@lilotux.net>
parents:
1424
diff
changeset
|
501 fclose(fp); |
0121b6f3047c
New command: /buffer save
Mikael Berthe <mikael@lilotux.net>
parents:
1424
diff
changeset
|
502 return; |
0121b6f3047c
New command: /buffer save
Mikael Berthe <mikael@lilotux.net>
parents:
1424
diff
changeset
|
503 } |
0121b6f3047c
New command: /buffer save
Mikael Berthe <mikael@lilotux.net>
parents:
1424
diff
changeset
|
504 |
1602 | 505 // hbuf_remove_receipt(hbuf, xep184) |
506 // Remove the Receipt Flag for the message with the given xep184 id | |
507 // Returns TRUE if it was found and removed, otherwise FALSE | |
508 gboolean hbuf_remove_receipt(GList *hbuf, gpointer xep184) | |
509 { | |
510 hbuf_block *blk; | |
511 | |
1817
fb6d20a17584
Improve hbuf_remove_receipt() efficiency
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
512 hbuf = g_list_last(hbuf); |
1602 | 513 |
1817
fb6d20a17584
Improve hbuf_remove_receipt() efficiency
Mikael Berthe <mikael@lilotux.net>
parents:
1811
diff
changeset
|
514 for ( ; hbuf; hbuf = g_list_previous(hbuf)) { |
1602 | 515 blk = (hbuf_block*)(hbuf->data); |
516 if (blk->prefix.xep184 == xep184) { | |
517 blk->prefix.xep184 = NULL; | |
518 blk->prefix.flags ^= HBB_PREFIX_RECEIPT; | |
519 return TRUE; | |
520 } | |
521 } | |
522 return FALSE; | |
523 } | |
524 | |
1948 | 525 // hbuf_set_readmark(hbuf, action) |
526 // Set/Reset the readmark Flag | |
527 // If action is TRUE, set a mark to the latest line, | |
528 // if action is FALSE, remove a previous readmark flag. | |
529 void hbuf_set_readmark(GList *hbuf, gboolean action) | |
530 { | |
531 hbuf_block *blk; | |
532 | |
533 if (!hbuf) return; | |
534 | |
535 hbuf = g_list_last(hbuf); | |
536 | |
537 if (action) { | |
538 // Add a readmark flag | |
539 blk = (hbuf_block*)(hbuf->data); | |
540 blk->prefix.flags ^= HBB_PREFIX_READMARK; | |
541 // Shift hbuf in order to remove previous flags | |
1956
f309f343070c
Add command /buffer readmark
Mikael Berthe <mikael@lilotux.net>
parents:
1948
diff
changeset
|
542 // (maybe it can be optimized out, if there's no risk |
1948 | 543 // we have several marks) |
544 hbuf = g_list_previous(hbuf); | |
545 } | |
546 | |
1956
f309f343070c
Add command /buffer readmark
Mikael Berthe <mikael@lilotux.net>
parents:
1948
diff
changeset
|
547 // Remove old mark |
1948 | 548 for ( ; hbuf; hbuf = g_list_previous(hbuf)) { |
549 blk = (hbuf_block*)(hbuf->data); | |
550 if (blk->prefix.flags & HBB_PREFIX_READMARK) { | |
551 blk->prefix.flags &= ~HBB_PREFIX_READMARK; | |
552 break; | |
553 } | |
554 } | |
555 } | |
556 | |
1961
39021fd6b0e1
Try to improve readmarks in some cases
Mikael Berthe <mikael@lilotux.net>
parents:
1956
diff
changeset
|
557 // hbuf_remove_trailing_readmark(hbuf) |
39021fd6b0e1
Try to improve readmarks in some cases
Mikael Berthe <mikael@lilotux.net>
parents:
1956
diff
changeset
|
558 // Unset the buffer readmark if it is on the last line |
39021fd6b0e1
Try to improve readmarks in some cases
Mikael Berthe <mikael@lilotux.net>
parents:
1956
diff
changeset
|
559 void hbuf_remove_trailing_readmark(GList *hbuf) |
39021fd6b0e1
Try to improve readmarks in some cases
Mikael Berthe <mikael@lilotux.net>
parents:
1956
diff
changeset
|
560 { |
39021fd6b0e1
Try to improve readmarks in some cases
Mikael Berthe <mikael@lilotux.net>
parents:
1956
diff
changeset
|
561 hbuf_block *blk; |
39021fd6b0e1
Try to improve readmarks in some cases
Mikael Berthe <mikael@lilotux.net>
parents:
1956
diff
changeset
|
562 |
39021fd6b0e1
Try to improve readmarks in some cases
Mikael Berthe <mikael@lilotux.net>
parents:
1956
diff
changeset
|
563 if (!hbuf) return; |
39021fd6b0e1
Try to improve readmarks in some cases
Mikael Berthe <mikael@lilotux.net>
parents:
1956
diff
changeset
|
564 |
39021fd6b0e1
Try to improve readmarks in some cases
Mikael Berthe <mikael@lilotux.net>
parents:
1956
diff
changeset
|
565 hbuf = g_list_last(hbuf); |
39021fd6b0e1
Try to improve readmarks in some cases
Mikael Berthe <mikael@lilotux.net>
parents:
1956
diff
changeset
|
566 blk = (hbuf_block*)(hbuf->data); |
39021fd6b0e1
Try to improve readmarks in some cases
Mikael Berthe <mikael@lilotux.net>
parents:
1956
diff
changeset
|
567 blk->prefix.flags &= ~HBB_PREFIX_READMARK; |
39021fd6b0e1
Try to improve readmarks in some cases
Mikael Berthe <mikael@lilotux.net>
parents:
1956
diff
changeset
|
568 } |
39021fd6b0e1
Try to improve readmarks in some cases
Mikael Berthe <mikael@lilotux.net>
parents:
1956
diff
changeset
|
569 |
1227
79c396678f1b
Make buffer list display the number of allocated HBB blocks
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
570 // hbuf_get_blocks_number() |
79c396678f1b
Make buffer list display the number of allocated HBB blocks
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
571 // Returns the number of allocated hbuf_block's. |
79c396678f1b
Make buffer list display the number of allocated HBB blocks
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
572 guint hbuf_get_blocks_number(GList *hbuf) |
79c396678f1b
Make buffer list display the number of allocated HBB blocks
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
573 { |
79c396678f1b
Make buffer list display the number of allocated HBB blocks
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
574 hbuf_block *hbuf_b_elt; |
79c396678f1b
Make buffer list display the number of allocated HBB blocks
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
575 guint count = 0U; |
79c396678f1b
Make buffer list display the number of allocated HBB blocks
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
576 |
79c396678f1b
Make buffer list display the number of allocated HBB blocks
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
577 for (hbuf = g_list_first(hbuf); hbuf; hbuf = g_list_next(hbuf)) { |
79c396678f1b
Make buffer list display the number of allocated HBB blocks
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
578 hbuf_b_elt = (hbuf_block*)(hbuf->data); |
79c396678f1b
Make buffer list display the number of allocated HBB blocks
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
579 if (hbuf_b_elt->flags & HBB_FLAG_ALLOC) |
79c396678f1b
Make buffer list display the number of allocated HBB blocks
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
580 count++; |
79c396678f1b
Make buffer list display the number of allocated HBB blocks
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
581 } |
79c396678f1b
Make buffer list display the number of allocated HBB blocks
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
582 return count; |
79c396678f1b
Make buffer list display the number of allocated HBB blocks
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
583 } |
79c396678f1b
Make buffer list display the number of allocated HBB blocks
Mikael Berthe <mikael@lilotux.net>
parents:
1205
diff
changeset
|
584 |
1811 | 585 /* vim: set expandtab cindent cinoptions=>2\:2(0 sw=2 ts=2: For Vim users... */ |