Change sources over to using GPLv3
[deliverable/binutils-gdb.git] / binutils / winduni.c
CommitLineData
252b5132 1/* winduni.c -- unicode support for the windres program.
3db64b00
AM
2 Copyright 1997, 1998, 2000, 2001, 2003, 2007
3 Free Software Foundation, Inc.
252b5132 4 Written by Ian Lance Taylor, Cygnus Support.
4a594fce 5 Rewritten by Kai Tietz, Onevision.
252b5132
RH
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
32866df7 11 the Free Software Foundation; either version 3 of the License, or
252b5132
RH
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
b43b5d5f
NC
21 Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
22 02110-1301, USA. */
252b5132 23
32866df7 24
252b5132
RH
25/* This file contains unicode support routines for the windres
26 program. Ideally, we would have generic unicode support which
27 would work on all systems. However, we don't. Instead, on a
28 Windows host, we are prepared to call some Windows routines. This
29 means that we will generate different output on Windows and Unix
30 hosts, but that seems better than not really supporting unicode at
31 all. */
32
3db64b00 33#include "sysdep.h"
252b5132 34#include "bfd.h"
5ba684e2 35#include "libiberty.h" /* for xstrdup */
4a594fce 36#include "bucomm.h"
5ba684e2
NC
37/* Must be include before windows.h and winnls.h. */
38#if defined (_WIN32) || defined (__CYGWIN__)
39#include <windows.h>
40#include <winnls.h>
41#endif
252b5132 42#include "winduni.h"
3882b010 43#include "safe-ctype.h"
252b5132 44
5ba684e2
NC
45#if HAVE_ICONV_H
46#include <iconv.h>
252b5132
RH
47#endif
48
5ba684e2
NC
49static rc_uint_type wind_WideCharToMultiByte (rc_uint_type, const unichar *, char *, rc_uint_type);
50static rc_uint_type wind_MultiByteToWideChar (rc_uint_type, const char *, unichar *, rc_uint_type);
4a594fce
NC
51static int unichar_isascii (const unichar *, rc_uint_type);
52
d856f2dd
NC
53/* Convert an ASCII string to a unicode string. We just copy it,
54 expanding chars to shorts, rather than doing something intelligent. */
55
5ba684e2
NC
56#if !defined (_WIN32) && !defined (__CYGWIN__)
57
58/* Codepages mapped. */
59static local_iconv_map codepages[] =
60{
61 { 0, "MS-ANSI" },
62 { 1, "WINDOWS-1252" },
63 { 437, "MS-ANSI" },
64 { 737, "MS-GREEK" },
65 { 775, "WINBALTRIM" },
66 { 850, "MS-ANSI" },
67 { 852, "MS-EE" },
68 { 857, "MS-TURK" },
69 { 862, "CP862" },
70 { 864, "CP864" },
71 { 866, "MS-CYRL" },
72 { 874, "WINDOWS-874" },
73 { 932, "CP932" },
74 { 936, "CP936" },
75 { 949, "CP949" },
76 { 950, "CP950" },
77 { 1250, "WINDOWS-1250" },
78 { 1251, "WINDOWS-1251" },
79 { 1252, "WINDOWS-1252" },
80 { 1253, "WINDOWS-1253" },
81 { 1254, "WINDOWS-1254" },
82 { 1255, "WINDOWS-1255" },
83 { 1256, "WINDOWS-1256" },
84 { 1257, "WINDOWS-1257" },
85 { 1258, "WINDOWS-1258" },
86 { CP_UTF7, "UTF-7" },
87 { CP_UTF8, "UTF-8" },
88 { CP_UTF16, "UTF-16" },
89 { (rc_uint_type) -1, NULL }
90};
91
92/* Languages supported. */
93static const wind_language_t languages[] =
94{
95 { 0x0000, 437, 1252, "Neutral", "Neutral" },
96 { 0x0401, 864, 1256, "Arabic", "Saudi Arabia" }, { 0x0402, 866, 1251, "Bulgarian", "Bulgaria" },
97 { 0x0403, 850, 1252, "Catalan", "Spain" }, { 0x0404, 950, 950, "Chinese", "Taiwan" },
98 { 0x0405, 852, 1250, "Czech", "Czech Republic" }, { 0x0406, 850, 1252, "Danish", "Denmark" },
99 { 0x0407, 850, 1252, "German", "Germany" }, { 0x0408, 737, 1253, "Greek", "Greece" },
100 { 0x0409, 437, 1252, "English", "United States" }, { 0x040A, 850, 1252, "Spanish - Traditional Sort", "Spain" },
101 { 0x040B, 850, 1252, "Finnish", "Finland" }, { 0x040C, 850, 1252, "French", "France" },
102 { 0x040D, 862, 1255, "Hebrew", "Israel" }, { 0x040E, 852, 1250, "Hungarian", "Hungary" },
103 { 0x040F, 850, 1252, "Icelandic", "Iceland" }, { 0x0410, 850, 1252, "Italian", "Italy" },
104 { 0x0411, 932, 932, "Japanese", "Japan" }, { 0x0412, 949, 949, "Korean", "Korea (south)" },