|
diff --git a/cgit.h b/cgit.h index 6c7a941..6291c58 100644 --- a/ cgit.h+++ b/ cgit.h |
|
@@ -16,6 +16,7 @@ |
16 | #include <log-tree.h> |
16 | #include <log-tree.h> |
17 | #include <archive.h> |
17 | #include <archive.h> |
18 | #include <xdiff/xdiff.h> |
18 | #include <xdiff/xdiff.h> |
| |
19 | #include <utf8.h> |
19 | |
20 | |
20 | |
21 | |
21 | /* |
22 | /* |
|
|
diff --git a/parsing.c b/parsing.c index c731084..e8c7ab9 100644 --- a/ parsing.c+++ b/ parsing.c |
|
@@ -6,8 +6,6 @@ |
6 | * (see COPYING for full license text) |
6 | * (see COPYING for full license text) |
7 | */ |
7 | */ |
8 | |
8 | |
9 | #include <iconv.h> |
| |
10 | |
| |
11 | #include "cgit.h" |
9 | #include "cgit.h" |
12 | |
10 | |
13 | int next_char(FILE *f) |
11 | int next_char(FILE *f) |
@@ -178,62 +176,6 @@ void cgit_parse_url(const char *url) |
178 | } |
176 | } |
179 | } |
177 | } |
180 | |
178 | |
181 | static char *iconv_msg(char *msg, const char *encoding) |
| |
182 | { |
| |
183 | iconv_t msg_conv = iconv_open(PAGE_ENCODING, encoding); |
| |
184 | size_t inlen = strlen(msg); |
| |
185 | char *in; |
| |
186 | char *out; |
| |
187 | size_t inleft; |
| |
188 | size_t outleft; |
| |
189 | char *buf; |
| |
190 | char *ret; |
| |
191 | size_t buf_sz; |
| |
192 | int again, fail; |
| |
193 | |
| |
194 | if(msg_conv == (iconv_t)-1) |
| |
195 | return NULL; |
| |
196 | |
| |
197 | buf_sz = inlen * 2; |
| |
198 | buf = xmalloc(buf_sz+1); |
| |
199 | do { |
| |
200 | in = msg; |
| |
201 | inleft = inlen; |
| |
202 | |
| |
203 | out = buf; |
| |
204 | outleft = buf_sz; |
| |
205 | iconv(msg_conv, &in, &inleft, &out, &outleft); |
| |
206 | |
| |
207 | if(inleft == 0) { |
| |
208 | fail = 0; |
| |
209 | again = 0; |
| |
210 | } else if(inleft != 0 && errno == E2BIG) { |
| |
211 | fail = 0; |
| |
212 | again = 1; |
| |
213 | |
| |
214 | buf_sz *= 2; |
| |
215 | free(buf); |
| |
216 | buf = xmalloc(buf_sz+1); |
| |
217 | } else { |
| |
218 | fail = 1; |
| |
219 | again = 0; |
| |
220 | } |
| |
221 | } while(again && !fail); |
| |
222 | |
| |
223 | if(fail) { |
| |
224 | free(buf); |
| |
225 | ret = NULL; |
| |
226 | } else { |
| |
227 | buf = xrealloc(buf, out - buf); |
| |
228 | *out = 0; |
| |
229 | ret = buf; |
| |
230 | } |
| |
231 | |
| |
232 | iconv_close(msg_conv); |
| |
233 | |
| |
234 | return ret; |
| |
235 | } |
| |
236 | |
| |
237 | char *substr(const char *head, const char *tail) |
179 | char *substr(const char *head, const char *tail) |
238 | { |
180 | { |
239 | char *buf; |
181 | char *buf; |
@@ -321,13 +263,15 @@ struct commitinfo *cgit_parse_commit(struct commit *commit) |
321 | ret->subject = substr(p, p+strlen(p)); |
263 | ret->subject = substr(p, p+strlen(p)); |
322 | |
264 | |
323 | if(strcmp(ret->msg_encoding, PAGE_ENCODING)) { |
265 | if(strcmp(ret->msg_encoding, PAGE_ENCODING)) { |
324 | t = iconv_msg(ret->subject, ret->msg_encoding); |
266 | t = reencode_string(ret->subject, PAGE_ENCODING, |
| |
267 | ret->msg_encoding); |
325 | if(t) { |
268 | if(t) { |
326 | free(ret->subject); |
269 | free(ret->subject); |
327 | ret->subject = t; |
270 | ret->subject = t; |
328 | } |
271 | } |
329 | |
272 | |
330 | t = iconv_msg(ret->msg, ret->msg_encoding); |
273 | t = reencode_string(ret->msg, PAGE_ENCODING, |
| |
274 | ret->msg_encoding); |
331 | if(t) { |
275 | if(t) { |
332 | free(ret->msg); |
276 | free(ret->msg); |
333 | ret->msg = t; |
277 | ret->msg = t; |
|