| 1 | /* winduni.c -- unicode support for the windres program. |
| 2 | Copyright 1997, 1998, 2000, 2001, 2003, 2007 |
| 3 | Free Software Foundation, Inc. |
| 4 | Written by Ian Lance Taylor, Cygnus Support. |
| 5 | Rewritten by Kai Tietz, Onevision. |
| 6 | |
| 7 | This file is part of GNU Binutils. |
| 8 | |
| 9 | This program is free software; you can redistribute it and/or modify |
| 10 | it under the terms of the GNU General Public License as published by |
| 11 | the Free Software Foundation; either version 2 of the License, or |
| 12 | (at your option) any later version. |
| 13 | |
| 14 | This program is distributed in the hope that it will be useful, |
| 15 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | GNU General Public License for more details. |
| 18 | |
| 19 | You should have received a copy of the GNU General Public License |
| 20 | along with this program; if not, write to the Free Software |
| 21 | Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA |
| 22 | 02110-1301, USA. */ |
| 23 | |
| 24 | /* This file contains unicode support routines for the windres |
| 25 | program. Ideally, we would have generic unicode support which |
| 26 | would work on all systems. However, we don't. Instead, on a |
| 27 | Windows host, we are prepared to call some Windows routines. This |
| 28 | means that we will generate different output on Windows and Unix |
| 29 | hosts, but that seems better than not really supporting unicode at |
| 30 | all. */ |
| 31 | |
| 32 | #include "sysdep.h" |
| 33 | #include "bfd.h" |
| 34 | #include "libiberty.h" /* for xstrdup */ |
| 35 | #include "bucomm.h" |
| 36 | /* Must be include before windows.h and winnls.h. */ |
| 37 | #if defined (_WIN32) || defined (__CYGWIN__) |
| 38 | #include <windows.h> |
| 39 | #include <winnls.h> |
| 40 | #endif |
| 41 | #include "winduni.h" |
| 42 | #include "safe-ctype.h" |
| 43 | |
| 44 | #if HAVE_ICONV_H |
| 45 | #include <iconv.h> |
| 46 | #endif |
| 47 | |
| 48 | static rc_uint_type wind_WideCharToMultiByte (rc_uint_type, const unichar *, char *, rc_uint_type); |
| 49 | static rc_uint_type wind_MultiByteToWideChar (rc_uint_type, const char *, unichar *, rc_uint_type); |
| 50 | |
| 51 | /* Prototypes. */ |
| 52 | static int unichar_isascii (const unichar *, rc_uint_type); |
| 53 | |
| 54 | #if !defined (_WIN32) && !defined (__CYGWIN__) |
| 55 | |
| 56 | /* Codepages mapped. */ |
| 57 | static local_iconv_map codepages[] = |
| 58 | { |
| 59 | { 0, "MS-ANSI" }, |
| 60 | { 1, "WINDOWS-1252" }, |
| 61 | { 437, "MS-ANSI" }, |
| 62 | { 737, "MS-GREEK" }, |
| 63 | { 775, "WINBALTRIM" }, |
| 64 | { 850, "MS-ANSI" }, |
| 65 | { 852, "MS-EE" }, |
| 66 | { 857, "MS-TURK" }, |
| 67 | { 862, "CP862" }, |
| 68 | { 864, "CP864" }, |
| 69 | { 866, "MS-CYRL" }, |
| 70 | { 874, "WINDOWS-874" }, |
| 71 | { 932, "CP932" }, |
| 72 | { 936, "CP936" }, |
| 73 | { 949, "CP949" }, |
| 74 | { 950, "CP950" }, |
| 75 | { 1250, "WINDOWS-1250" }, |
| 76 | { 1251, "WINDOWS-1251" }, |
| 77 | { 1252, "WINDOWS-1252" }, |
| 78 | { 1253, "WINDOWS-1253" }, |
| 79 | { 1254, "WINDOWS-1254" }, |
| 80 | { 1255, "WINDOWS-1255" }, |
| 81 | { 1256, "WINDOWS-1256" }, |
| 82 | { 1257, "WINDOWS-1257" }, |
| 83 | { 1258, "WINDOWS-1258" }, |
| 84 | { CP_UTF7, "UTF-7" }, |
| 85 | { CP_UTF8, "UTF-8" }, |
| 86 | { CP_UTF16, "UTF-16" }, |
| 87 | { (rc_uint_type) -1, NULL } |
| 88 | }; |
| 89 | |
| 90 | /* Languages supported. */ |
| 91 | static const wind_language_t languages[] = |
| 92 | { |
| 93 | { 0x0000, 437, 1252, "Neutral", "Neutral" }, |
| 94 | { 0x0401, 864, 1256, "Arabic", "Saudi Arabia" }, { 0x0402, 866, 1251, "Bulgarian", "Bulgaria" }, |
| 95 | { 0x0403, 850, 1252, "Catalan", "Spain" }, { 0x0404, 950, 950, "Chinese", "Taiwan" }, |
| 96 | { 0x0405, 852, 1250, "Czech", "Czech Republic" }, { 0x0406, 850, 1252, "Danish", "Denmark" }, |
| 97 | { 0x0407, 850, 1252, "German", "Germany" }, { 0x0408, 737, 1253, "Greek", "Greece" }, |
| 98 | { 0x0409, 437, 1252, "English", "United States" }, { 0x040A, 850, 1252, "Spanish - Traditional Sort", "Spain" }, |
| 99 | { 0x040B, 850, 1252, "Finnish", "Finland" }, { 0x040C, 850, 1252, "French", "France" }, |
| 100 | { 0x040D, 862, 1255, "Hebrew", "Israel" }, { 0x040E, 852, 1250, "Hungarian", "Hungary" }, |
| 101 | { 0x040F, 850, 1252, "Icelandic", "Iceland" }, { 0x0410, 850, 1252, "Italian", "Italy" }, |
| 102 | { 0x0411, 932, 932, "Japanese", "Japan" }, { 0x0412, 949, 949, "Korean", "Korea (south)" }, |