Mercurial > ~mikael > mcabber > hg
comparison mcabber/src/hbuf.c @ 930:a75f7a13df7b
UTF-8 terminal support (Reimar Döffinger)
This is a patch from Reimar Döffinger, slightly modified,
which makes mcabber work better on UTF-8 terminals.
author | Mikael Berthe <mikael@lilotux.net> |
---|---|
date | Sat, 08 Jul 2006 09:40:05 +0200 |
parents | a07bd351008b |
children | fc6aaa223650 |
comparison
equal
deleted
inserted
replaced
929:f4bf564893b5 | 930:a75f7a13df7b |
---|---|
21 | 21 |
22 #include <string.h> | 22 #include <string.h> |
23 | 23 |
24 #include "hbuf.h" | 24 #include "hbuf.h" |
25 #include "utils.h" | 25 #include "utils.h" |
26 #include "utf8.h" | |
26 | 27 |
27 | 28 |
28 /* This is a private structure type */ | 29 /* This is a private structure type */ |
29 | 30 |
30 typedef struct { | 31 typedef struct { |
186 } else | 187 } else |
187 curr_elt = next_elt; | 188 curr_elt = next_elt; |
188 } | 189 } |
189 // #2 Go back to head and create non-persistent blocks when needed | 190 // #2 Go back to head and create non-persistent blocks when needed |
190 if (width) { | 191 if (width) { |
191 char *line, *end; | 192 char *end; |
192 curr_elt = first_elt; | 193 curr_elt = first_elt; |
193 | 194 |
194 while (curr_elt) { | 195 while (curr_elt) { |
195 hbuf_b_curr = (hbuf_block*)(curr_elt->data); | 196 hbuf_b_curr = (hbuf_block*)(curr_elt->data); |
196 line = hbuf_b_curr->ptr; | 197 hbuf_block *hbuf_b_prev = hbuf_b_curr; |
197 if (strlen(line) > width) { | 198 |
198 hbuf_block *hbuf_b_prev = hbuf_b_curr; | 199 // We need to break where we can find a space char |
199 | 200 char *br = NULL; // break pointer |
200 // We need to break where we can find a space char | 201 char *c = hbuf_b_curr->ptr; |
201 char *br; // break pointer | 202 unsigned int cur_w = 0; |
202 for (br = line + width; br > line && *br != 32 && *br != 9; br--) | 203 while (*c && cur_w <= width) { |
203 ; | 204 if (iswblank(get_char(c))) |
204 if (br <= line) | 205 br = c; |
205 br = line + width; | 206 cur_w += wcwidth(get_char(c)); |
207 c = next_char(c); | |
208 } | |
209 if (*c && cur_w > width) { | |
210 if (!br || br == hbuf_b_curr->ptr) | |
211 br = c; | |
206 else | 212 else |
207 br++; | 213 br = next_char(br); |
208 end = hbuf_b_curr->ptr_end; | 214 end = hbuf_b_curr->ptr_end; |
209 hbuf_b_curr->ptr_end = br; | 215 hbuf_b_curr->ptr_end = br; |
210 // Create another block, non-persistent | 216 // Create another block, non-persistent |
211 hbuf_b_curr = g_new0(hbuf_block, 1); | 217 hbuf_b_curr = g_new0(hbuf_block, 1); |
212 hbuf_b_curr->ptr = hbuf_b_prev->ptr_end; // == br | 218 hbuf_b_curr->ptr = hbuf_b_prev->ptr_end; // == br |