commit 2d71f5b7d33f7f6eb0a5d280962c35c5a028a428
parent 9bfa571d1da9090e2031d843c114e7b70e6e7d0b
Author: Christian Grothoff <christian@grothoff.org>
Date: Sat, 22 Sep 2012 20:30:25 +0000
trying to make code build even without GNU iconv
Diffstat:
4 files changed, 42 insertions(+), 4 deletions(-)
diff --git a/src/include/platform.h b/src/include/platform.h
@@ -63,7 +63,9 @@
#include <winsock2.h>
#endif
#include <locale.h>
+#if HAVE_ICONV_H
#include <iconv.h>
+#endif
#include <langinfo.h>
#ifndef SIZE_MAX
diff --git a/src/main/extract.c b/src/main/extract.c
@@ -245,7 +245,9 @@ print_help ()
}
+#if HAVE_ICONV
#include "iconv.c"
+#endif
/**
* Print a keyword list to a file.
@@ -273,7 +275,9 @@ print_selected_keywords (void *cls,
size_t data_len)
{
char *keyword;
+#if HAVE_ICONV
iconv_t cd;
+#endif
const char *stype;
const char *mt;
@@ -294,12 +298,14 @@ print_selected_keywords (void *cls,
(unsigned int) data_len);
break;
case EXTRACTOR_METAFORMAT_UTF8:
+#if HAVE_ICONV
cd = iconv_open (nl_langinfo(CODESET), "UTF-8");
if (((iconv_t) -1) != cd)
keyword = iconv_helper (cd,
data,
data_len);
else
+#endif
keyword = strdup (data);
if (NULL != keyword)
{
@@ -309,8 +315,10 @@ print_selected_keywords (void *cls,
keyword);
free (keyword);
}
+#if HAVE_ICONV
if (((iconv_t) -1) != cd)
iconv_close (cd);
+#endif
break;
case EXTRACTOR_METAFORMAT_BINARY:
fprintf (stdout,
@@ -358,7 +366,9 @@ print_selected_keywords_grep_friendly (void *cls,
size_t data_len)
{
char *keyword;
+#if HAVE_ICONV
iconv_t cd;
+#endif
const char *mt;
if (YES != print[type])
@@ -375,12 +385,14 @@ print_selected_keywords_grep_friendly (void *cls,
fprintf (stdout,
"%s: ",
gettext(mt));
+#if HAVE_ICONV
cd = iconv_open (nl_langinfo (CODESET), "UTF-8");
if (((iconv_t) -1) != cd)
keyword = iconv_helper (cd,
data,
data_len);
else
+#endif
keyword = strdup (data);
if (NULL != keyword)
{
@@ -389,8 +401,10 @@ print_selected_keywords_grep_friendly (void *cls,
keyword);
free (keyword);
}
+#if HAVE_ICONV
if (((iconv_t) -1) != cd)
iconv_close (cd);
+#endif
break;
case EXTRACTOR_METAFORMAT_BINARY:
break;
diff --git a/src/main/extractor_print.c b/src/main/extractor_print.c
@@ -22,11 +22,12 @@
* @brief convenience functions for printing meta data
* @author Christian Grothoff
*/
-
#include "platform.h"
#include "extractor.h"
#include "extractor_logging.h"
+#if HAVE_ICONV
#include "iconv.c"
+#endif
/**
* Simple EXTRACTOR_MetaDataProcessor implementation that simply
@@ -53,13 +54,16 @@ EXTRACTOR_meta_data_print (void *handle,
const char *data,
size_t data_len)
{
+#if HAVE_ICONV
iconv_t cd;
+#endif
char * buf;
int ret;
const char *mt;
if (EXTRACTOR_METAFORMAT_UTF8 != format)
return 0;
+#if HAVE_ICONV
cd = iconv_open (nl_langinfo(CODESET),
"UTF-8");
if (((iconv_t) -1) == cd)
@@ -85,6 +89,15 @@ EXTRACTOR_meta_data_print (void *handle,
free(buf);
}
iconv_close(cd);
+#else
+ ret = fprintf (handle,
+ "%s - %.*s\n",
+ (NULL == mt)
+ ? dgettext ("libextractor", gettext_noop ("unknown"))
+ : dgettext ("libextractor", mt),
+ (int) data_len,
+ data);
+#endif
return (ret < 0) ? 1 : 0;
}
diff --git a/src/main/iconv.c b/src/main/iconv.c
@@ -38,9 +38,10 @@ iconv_helper (iconv_t cd,
const char *in,
size_t inSize)
{
- char * buf;
- char * ibuf;
- const char * i;
+#if HAVE_ICONV
+ char *buf;
+ char *ibuf;
+ const char *i;
size_t outSize;
size_t outLeft;
@@ -66,6 +67,14 @@ iconv_helper (iconv_t cd,
return strdup (i);
}
return buf;
+#else
+ /* good luck, just copying string... */
+ char *buf;
+
+ buf = malloc (inSize + 1);
+ memcpy (buf, in, inSize);
+ buf[inSize] = '\0';
+#endif
}
/* end of iconv.c */