/* winduni.c -- unicode support for the windres program.
- Copyright 1997, 1998, 2000, 2001, 2003, 2007
+ Copyright 1997, 1998, 2000, 2001, 2003, 2007, 2009
Free Software Foundation, Inc.
Written by Ian Lance Taylor, Cygnus Support.
Rewritten by Kai Tietz, Onevision.
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
- the Free Software Foundation; either version 2 of the License, or
+ the Free Software Foundation; either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
02110-1301, USA. */
+
/* This file contains unicode support routines for the windres
program. Ideally, we would have generic unicode support which
would work on all systems. However, we don't. Instead, on a
#include "winduni.h"
#include "safe-ctype.h"
-#if HAVE_ICONV_H
+#if HAVE_ICONV
#include <iconv.h>
#endif
static rc_uint_type wind_WideCharToMultiByte (rc_uint_type, const unichar *, char *, rc_uint_type);
static rc_uint_type wind_MultiByteToWideChar (rc_uint_type, const char *, unichar *, rc_uint_type);
-
-/* Prototypes. */
static int unichar_isascii (const unichar *, rc_uint_type);
+/* Convert an ASCII string to a unicode string. We just copy it,
+ expanding chars to shorts, rather than doing something intelligent. */
+
#if !defined (_WIN32) && !defined (__CYGWIN__)
/* Codepages mapped. */
#endif
+/* Specifies the default codepage to be used for unicode
+ transformations. By default this is CP_ACP. */
+rc_uint_type wind_default_codepage = CP_ACP;
+
+/* Specifies the currently used codepage for unicode
+ transformations. By default this is CP_ACP. */
+rc_uint_type wind_current_codepage = CP_ACP;
+
/* Convert an ASCII string to a unicode string. We just copy it,
expanding chars to shorts, rather than doing something intelligent. */
void
unicode_from_ascii (rc_uint_type *length, unichar **unicode, const char *ascii)
{
- unicode_from_codepage (length, unicode, ascii, 0 /*CP_ACP*/);
+ unicode_from_codepage (length, unicode, ascii, wind_current_codepage);
}
/* Convert an unicode string to an ASCII string. We just copy it,
void
ascii_from_unicode (rc_uint_type *length, const unichar *unicode, char **ascii)
{
- codepage_from_unicode (length, unicode, ascii, 0/*CP_ACP*/);
+ codepage_from_unicode (length, unicode, ascii, wind_current_codepage);
}
/* Print the unicode string UNICODE to the file E. LENGTH is the
else if ((ch & 0xff) == ch)
fprintf (e, "\\%03o", (unsigned int) ch);
else
- fprintf (e, "\\x%x", (unsigned int) ch);
+ fprintf (e, "\\x%04x", (unsigned int) ch);
}
}
*length = len;
}
-#ifdef HAVE_ICONV_H
+#if defined (HAVE_ICONV) && !defined (_WIN32) && !defined (__CYGWIN__)
static int
-iconv_onechar (iconv_t cd, const char *s, char *d, int d_len, const char **n_s, char **n_d)
+iconv_onechar (iconv_t cd, ICONV_CONST char *s, char *d, int d_len, const char **n_s, char **n_d)
{
int i;
for (i = 1; i <= 32; i++)
{
char *tmp_d = d;
- const char *tmp_s = s;
+ ICONV_CONST char *tmp_s = s;
size_t ret;
size_t s_left = (size_t) i;
size_t d_left = (size_t) d_len;
return NULL;
return lim->iconv_name;
}
-#endif /* HAVE_ICONV_H */
+#endif /* HAVE_ICONV */
static rc_uint_type
wind_MultiByteToWideChar (rc_uint_type cp, const char *mb,
/* Convert to bytes. */
ret *= sizeof (unichar);
-#elif defined (HAVE_ICONV_H)
+#elif defined (HAVE_ICONV)
int first = 1;
char tmp[32];
char *p_tmp;
while (1)
{
int iret;
- const char *n_mb;
- char *n_tmp;
+ const char *n_mb = "";
+ char *n_tmp = "";
p_tmp = tmp;
- iret = iconv_onechar (cd, (const char *) mb, p_tmp, 32, & n_mb, & n_tmp);
+ iret = iconv_onechar (cd, (ICONV_CONST char *) mb, p_tmp, 32, & n_mb, & n_tmp);
if (first)
{
first = 0;
ret = (rc_uint_type) WideCharToMultiByte (cp, 0, u, -1, mb, mb_len,
NULL, & used_def);
-#elif defined (HAVE_ICONV_H)
+#elif defined (HAVE_ICONV)
int first = 1;
char tmp[32];
char *p_tmp;
while (1)
{
int iret;
- const char *n_u;
- char *n_tmp;
+ const char *n_u = "";
+ char *n_tmp = "";
p_tmp = tmp;
- iret = iconv_onechar (cd, (const char *) u, p_tmp, 32, &n_u, & n_tmp);
+ iret = iconv_onechar (cd, (ICONV_CONST char *) u, p_tmp, 32, &n_u, & n_tmp);
if (first)
{
first = 0;