diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-09-22 20:30:25 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-09-22 20:30:25 +0000 |
commit | 2d71f5b7d33f7f6eb0a5d280962c35c5a028a428 (patch) | |
tree | 918b98e862a3ac4c8ed1e7458a02025c9cd02c4d | |
parent | 9bfa571d1da9090e2031d843c114e7b70e6e7d0b (diff) | |
download | libextractor-2d71f5b7d33f7f6eb0a5d280962c35c5a028a428.tar.gz libextractor-2d71f5b7d33f7f6eb0a5d280962c35c5a028a428.zip |
trying to make code build even without GNU iconv
-rw-r--r-- | src/include/platform.h | 2 | ||||
-rw-r--r-- | src/main/extract.c | 14 | ||||
-rw-r--r-- | src/main/extractor_print.c | 15 | ||||
-rw-r--r-- | src/main/iconv.c | 15 |
4 files changed, 42 insertions, 4 deletions
diff --git a/src/include/platform.h b/src/include/platform.h index 922302e..a992301 100644 --- a/src/include/platform.h +++ b/src/include/platform.h | |||
@@ -63,7 +63,9 @@ | |||
63 | #include <winsock2.h> | 63 | #include <winsock2.h> |
64 | #endif | 64 | #endif |
65 | #include <locale.h> | 65 | #include <locale.h> |
66 | #if HAVE_ICONV_H | ||
66 | #include <iconv.h> | 67 | #include <iconv.h> |
68 | #endif | ||
67 | #include <langinfo.h> | 69 | #include <langinfo.h> |
68 | 70 | ||
69 | #ifndef SIZE_MAX | 71 | #ifndef SIZE_MAX |
diff --git a/src/main/extract.c b/src/main/extract.c index 61f2e21..95a2170 100644 --- a/src/main/extract.c +++ b/src/main/extract.c | |||
@@ -245,7 +245,9 @@ print_help () | |||
245 | 245 | ||
246 | } | 246 | } |
247 | 247 | ||
248 | #if HAVE_ICONV | ||
248 | #include "iconv.c" | 249 | #include "iconv.c" |
250 | #endif | ||
249 | 251 | ||
250 | /** | 252 | /** |
251 | * Print a keyword list to a file. | 253 | * Print a keyword list to a file. |
@@ -273,7 +275,9 @@ print_selected_keywords (void *cls, | |||
273 | size_t data_len) | 275 | size_t data_len) |
274 | { | 276 | { |
275 | char *keyword; | 277 | char *keyword; |
278 | #if HAVE_ICONV | ||
276 | iconv_t cd; | 279 | iconv_t cd; |
280 | #endif | ||
277 | const char *stype; | 281 | const char *stype; |
278 | const char *mt; | 282 | const char *mt; |
279 | 283 | ||
@@ -294,12 +298,14 @@ print_selected_keywords (void *cls, | |||
294 | (unsigned int) data_len); | 298 | (unsigned int) data_len); |
295 | break; | 299 | break; |
296 | case EXTRACTOR_METAFORMAT_UTF8: | 300 | case EXTRACTOR_METAFORMAT_UTF8: |
301 | #if HAVE_ICONV | ||
297 | cd = iconv_open (nl_langinfo(CODESET), "UTF-8"); | 302 | cd = iconv_open (nl_langinfo(CODESET), "UTF-8"); |
298 | if (((iconv_t) -1) != cd) | 303 | if (((iconv_t) -1) != cd) |
299 | keyword = iconv_helper (cd, | 304 | keyword = iconv_helper (cd, |
300 | data, | 305 | data, |
301 | data_len); | 306 | data_len); |
302 | else | 307 | else |
308 | #endif | ||
303 | keyword = strdup (data); | 309 | keyword = strdup (data); |
304 | if (NULL != keyword) | 310 | if (NULL != keyword) |
305 | { | 311 | { |
@@ -309,8 +315,10 @@ print_selected_keywords (void *cls, | |||
309 | keyword); | 315 | keyword); |
310 | free (keyword); | 316 | free (keyword); |
311 | } | 317 | } |
318 | #if HAVE_ICONV | ||
312 | if (((iconv_t) -1) != cd) | 319 | if (((iconv_t) -1) != cd) |
313 | iconv_close (cd); | 320 | iconv_close (cd); |
321 | #endif | ||
314 | break; | 322 | break; |
315 | case EXTRACTOR_METAFORMAT_BINARY: | 323 | case EXTRACTOR_METAFORMAT_BINARY: |
316 | fprintf (stdout, | 324 | fprintf (stdout, |
@@ -358,7 +366,9 @@ print_selected_keywords_grep_friendly (void *cls, | |||
358 | size_t data_len) | 366 | size_t data_len) |
359 | { | 367 | { |
360 | char *keyword; | 368 | char *keyword; |
369 | #if HAVE_ICONV | ||
361 | iconv_t cd; | 370 | iconv_t cd; |
371 | #endif | ||
362 | const char *mt; | 372 | const char *mt; |
363 | 373 | ||
364 | if (YES != print[type]) | 374 | if (YES != print[type]) |
@@ -375,12 +385,14 @@ print_selected_keywords_grep_friendly (void *cls, | |||
375 | fprintf (stdout, | 385 | fprintf (stdout, |
376 | "%s: ", | 386 | "%s: ", |
377 | gettext(mt)); | 387 | gettext(mt)); |
388 | #if HAVE_ICONV | ||
378 | cd = iconv_open (nl_langinfo (CODESET), "UTF-8"); | 389 | cd = iconv_open (nl_langinfo (CODESET), "UTF-8"); |
379 | if (((iconv_t) -1) != cd) | 390 | if (((iconv_t) -1) != cd) |
380 | keyword = iconv_helper (cd, | 391 | keyword = iconv_helper (cd, |
381 | data, | 392 | data, |
382 | data_len); | 393 | data_len); |
383 | else | 394 | else |
395 | #endif | ||
384 | keyword = strdup (data); | 396 | keyword = strdup (data); |
385 | if (NULL != keyword) | 397 | if (NULL != keyword) |
386 | { | 398 | { |
@@ -389,8 +401,10 @@ print_selected_keywords_grep_friendly (void *cls, | |||
389 | keyword); | 401 | keyword); |
390 | free (keyword); | 402 | free (keyword); |
391 | } | 403 | } |
404 | #if HAVE_ICONV | ||
392 | if (((iconv_t) -1) != cd) | 405 | if (((iconv_t) -1) != cd) |
393 | iconv_close (cd); | 406 | iconv_close (cd); |
407 | #endif | ||
394 | break; | 408 | break; |
395 | case EXTRACTOR_METAFORMAT_BINARY: | 409 | case EXTRACTOR_METAFORMAT_BINARY: |
396 | break; | 410 | break; |
diff --git a/src/main/extractor_print.c b/src/main/extractor_print.c index 430f766..5ded7c4 100644 --- a/src/main/extractor_print.c +++ b/src/main/extractor_print.c | |||
@@ -22,11 +22,12 @@ | |||
22 | * @brief convenience functions for printing meta data | 22 | * @brief convenience functions for printing meta data |
23 | * @author Christian Grothoff | 23 | * @author Christian Grothoff |
24 | */ | 24 | */ |
25 | |||
26 | #include "platform.h" | 25 | #include "platform.h" |
27 | #include "extractor.h" | 26 | #include "extractor.h" |
28 | #include "extractor_logging.h" | 27 | #include "extractor_logging.h" |
28 | #if HAVE_ICONV | ||
29 | #include "iconv.c" | 29 | #include "iconv.c" |
30 | #endif | ||
30 | 31 | ||
31 | /** | 32 | /** |
32 | * Simple EXTRACTOR_MetaDataProcessor implementation that simply | 33 | * Simple EXTRACTOR_MetaDataProcessor implementation that simply |
@@ -53,13 +54,16 @@ EXTRACTOR_meta_data_print (void *handle, | |||
53 | const char *data, | 54 | const char *data, |
54 | size_t data_len) | 55 | size_t data_len) |
55 | { | 56 | { |
57 | #if HAVE_ICONV | ||
56 | iconv_t cd; | 58 | iconv_t cd; |
59 | #endif | ||
57 | char * buf; | 60 | char * buf; |
58 | int ret; | 61 | int ret; |
59 | const char *mt; | 62 | const char *mt; |
60 | 63 | ||
61 | if (EXTRACTOR_METAFORMAT_UTF8 != format) | 64 | if (EXTRACTOR_METAFORMAT_UTF8 != format) |
62 | return 0; | 65 | return 0; |
66 | #if HAVE_ICONV | ||
63 | cd = iconv_open (nl_langinfo(CODESET), | 67 | cd = iconv_open (nl_langinfo(CODESET), |
64 | "UTF-8"); | 68 | "UTF-8"); |
65 | if (((iconv_t) -1) == cd) | 69 | if (((iconv_t) -1) == cd) |
@@ -85,6 +89,15 @@ EXTRACTOR_meta_data_print (void *handle, | |||
85 | free(buf); | 89 | free(buf); |
86 | } | 90 | } |
87 | iconv_close(cd); | 91 | iconv_close(cd); |
92 | #else | ||
93 | ret = fprintf (handle, | ||
94 | "%s - %.*s\n", | ||
95 | (NULL == mt) | ||
96 | ? dgettext ("libextractor", gettext_noop ("unknown")) | ||
97 | : dgettext ("libextractor", mt), | ||
98 | (int) data_len, | ||
99 | data); | ||
100 | #endif | ||
88 | return (ret < 0) ? 1 : 0; | 101 | return (ret < 0) ? 1 : 0; |
89 | } | 102 | } |
90 | 103 | ||
diff --git a/src/main/iconv.c b/src/main/iconv.c index 38150ad..8b71b91 100644 --- a/src/main/iconv.c +++ b/src/main/iconv.c | |||
@@ -38,9 +38,10 @@ iconv_helper (iconv_t cd, | |||
38 | const char *in, | 38 | const char *in, |
39 | size_t inSize) | 39 | size_t inSize) |
40 | { | 40 | { |
41 | char * buf; | 41 | #if HAVE_ICONV |
42 | char * ibuf; | 42 | char *buf; |
43 | const char * i; | 43 | char *ibuf; |
44 | const char *i; | ||
44 | size_t outSize; | 45 | size_t outSize; |
45 | size_t outLeft; | 46 | size_t outLeft; |
46 | 47 | ||
@@ -66,6 +67,14 @@ iconv_helper (iconv_t cd, | |||
66 | return strdup (i); | 67 | return strdup (i); |
67 | } | 68 | } |
68 | return buf; | 69 | return buf; |
70 | #else | ||
71 | /* good luck, just copying string... */ | ||
72 | char *buf; | ||
73 | |||
74 | buf = malloc (inSize + 1); | ||
75 | memcpy (buf, in, inSize); | ||
76 | buf[inSize] = '\0'; | ||
77 | #endif | ||
69 | } | 78 | } |
70 | 79 | ||
71 | /* end of iconv.c */ | 80 | /* end of iconv.c */ |