1/* winduni.h -- header file for unicode support for windres program.
2   Copyright (C) 1997-2017 Free Software Foundation, Inc.
3   Written by Ian Lance Taylor, Cygnus Support.
4   Rewritten by Kai Tietz, Onevision.
5
6   This file is part of GNU Binutils.
7
8   This program is free software; you can redistribute it and/or modify
9   it under the terms of the GNU General Public License as published by
10   the Free Software Foundation; either version 3 of the License, or
11   (at your option) any later version.
12
13   This program is distributed in the hope that it will be useful,
14   but WITHOUT ANY WARRANTY; without even the implied warranty of
15   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16   GNU General Public License for more details.
17
18   You should have received a copy of the GNU General Public License
19   along with this program; if not, write to the Free Software
20   Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA
21   02110-1301, USA.  */
22
23#include "ansidecl.h"
24
25#ifndef WINDUNI_H
26#define WINDUNI_H
27
28/* This header file declares the types and functions we use for
29   unicode support in windres.  Our unicode support is very limited at
30   present.
31
32   We don't put this stuff in windres.h so that winduni.c doesn't have
33   to include windres.h.  winduni.c needs to includes windows.h, and
34   that would conflict with the definitions of Windows macros we
35   already have in windres.h.  */
36
37/* Use bfd_size_type to ensure a sufficient number of bits.  */
38#ifndef DEFINED_RC_UINT_TYPE
39#define DEFINED_RC_UINT_TYPE
40typedef bfd_size_type rc_uint_type;
41#endif
42
43/* We use this type to hold a unicode character.  */
44
45typedef unsigned short unichar;
46
47/* Escape character translations.  */
48
49#define ESCAPE_A  007
50#define ESCAPE_B  010
51#define ESCAPE_F  014
52#define ESCAPE_N  012
53#define ESCAPE_R  015
54#define ESCAPE_T  011
55#define ESCAPE_V  013
56
57/* Convert an ASCII string to a unicode string.  */
58extern void unicode_from_ascii (rc_uint_type *, unichar **, const char *);
59
60/* Convert an unicode string to an ASCII string.  */
61extern void ascii_from_unicode (rc_uint_type *, const unichar *, char **);
62
63/* Duplicate a unicode string by using res_alloc.  */
64extern unichar *unichar_dup (const unichar *);
65
66/* Duplicate a unicode string by using res_alloc and make it uppercase.  */
67extern unichar *unichar_dup_uppercase (const unichar *);
68
69/* The count of unichar elements.  */
70extern rc_uint_type unichar_len (const unichar *);
71
72/* Print a unicode string to a file.  */
73extern void unicode_print (FILE *, const unichar *, rc_uint_type);
74
75/* Print a ascii string to a file.  */
76extern void ascii_print (FILE *, const char *, rc_uint_type);
77
78/* Print a quoted unicode string to a file.  */
79extern void unicode_print_quoted (FILE *, const unichar *, rc_uint_type);
80
81#ifndef CP_UTF8
82#define CP_UTF7	65000   /* UTF-7 translation.  */
83#define CP_UTF8	65001   /* UTF-8 translation.  */
84#endif
85
86#ifndef CP_UTF16
87#define CP_UTF16  65002	/* UTF-16 translation.  */
88#endif
89
90#ifndef CP_ACP
91#define CP_ACP	0	/* Default to ANSI code page.  */
92#endif
93
94#ifndef CP_OEM
95#define CP_OEM  1	/* Default OEM code page. */
96#endif
97
98/* Specifies the default codepage to be used for unicode
99   transformations.  By default this is CP_ACP.  */
100extern rc_uint_type wind_default_codepage;
101
102/* Specifies the currently used codepage for unicode
103   transformations.  By default this is CP_ACP.  */
104extern rc_uint_type wind_current_codepage;
105
106typedef struct wind_language_t
107{
108  unsigned id;
109  unsigned doscp;
110  unsigned wincp;
111  const char *name;
112  const char *country;
113} wind_language_t;
114
115extern const wind_language_t *wind_find_language_by_id (unsigned);
116extern int unicode_is_valid_codepage (rc_uint_type);
117
118typedef struct local_iconv_map
119{
120  rc_uint_type codepage;
121  const char * iconv_name;
122} local_iconv_map;
123
124extern const local_iconv_map *wind_find_codepage_info (unsigned);
125
126/* Convert an Codepage string to a unicode string.  */
127extern void unicode_from_codepage (rc_uint_type *, unichar **, const char *, rc_uint_type);
128extern void unicode_from_ascii_len (rc_uint_type *, unichar **, const char *, rc_uint_type );
129
130/* Convert an unicode string to an codepage string.  */
131extern void codepage_from_unicode (rc_uint_type *, const unichar *, char **, rc_uint_type);
132
133/* Windres support routine called by unicode_from_ascii.  This is both
134   here and in windres.h.  It should probably be in a separate header
135   file, but it hardly seems worth it for one function.  */
136
137extern void * res_alloc (rc_uint_type);
138
139#endif
140