]> git.ipfire.org Git - thirdparty/binutils-gdb.git/blame - gdb/gdb_wchar.h
Update copyright year range in header of all files managed by GDB
[thirdparty/binutils-gdb.git] / gdb / gdb_wchar.h
CommitLineData
6c7a06a3 1/* Wide characters for gdb
213516ef 2 Copyright (C) 2009-2023 Free Software Foundation, Inc.
6c7a06a3
TT
3
4 This file is part of GDB.
5
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
10
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
18
19#ifndef GDB_WCHAR_H
20#define GDB_WCHAR_H
21
732f6a93
TT
22/* We handle three different modes here.
23
24 Capable systems have the full suite: wchar_t support and iconv
25 (perhaps via GNU libiconv). On these machines, full functionality
62234ccc
TT
26 is available. Note that full functionality is dependent on us
27 being able to convert from an arbitrary encoding to wchar_t. In
28 practice this means we look for __STDC_ISO_10646__ (where we know
29 the name of the wchar_t encoding) or GNU libiconv, where we can use
30 "wchar_t".
732f6a93
TT
31
32 DJGPP is known to have libiconv but not wchar_t support. On
33 systems like this, we use the narrow character functions. The full
34 functionality is available to the user, but many characters (those
35 outside the narrow range) will be displayed as escapes.
36
62234ccc
TT
37 Finally, some systems do not have iconv, or are really broken
38 (e.g., Solaris, which almost has all of this working, but where
39 just enough is broken to make it too hard to use). Here we provide
40 a phony iconv which only handles a single character set, and we
41 provide wrappers for the wchar_t functionality we use. */
732f6a93
TT
42
43
732f6a93 44#if defined (HAVE_ICONV)
6c7a06a3 45#include <iconv.h>
732f6a93
TT
46#else
47/* This define is used elsewhere so we don't need to duplicate the
48 same checking logic in multiple places. */
49#define PHONY_ICONV
50#endif
51
e01e2baa
YQ
52#include <wchar.h>
53#include <wctype.h>
54
62234ccc
TT
55/* We use "btowc" as a sentinel to detect functioning wchar_t support.
56 We check for either __STDC_ISO_10646__ or a new-enough libiconv in
57 order to ensure we can convert to and from wchar_t. We choose
716b65bf
TT
58 libiconv version 0x108 because it is the first version with
59 iconvlist. */
e01e2baa 60#if defined (HAVE_ICONV) && defined (HAVE_BTOWC) \
62234ccc 61 && (defined (__STDC_ISO_10646__) \
716b65bf 62 || (defined (_LIBICONV_VERSION) && _LIBICONV_VERSION >= 0x108))
732f6a93 63
6c7a06a3
TT
64typedef wchar_t gdb_wchar_t;
65typedef wint_t gdb_wint_t;
66
67#define gdb_wcslen wcslen
68#define gdb_iswprint iswprint
3041b931 69#define gdb_iswxdigit iswxdigit
6c7a06a3
TT
70#define gdb_btowc btowc
71#define gdb_WEOF WEOF
72
73#define LCST(X) L ## X
74
62234ccc
TT
75/* If __STDC_ISO_10646__ is defined, then the host wchar_t is UCS-4.
76 We exploit this fact in the hope that there are hosts that define
77 this but which do not support "wchar_t" as an encoding argument to
78 iconv_open. We put the endianness into the encoding name to avoid
79 hosts that emit a BOM when the unadorned name is used. */
80#if defined (__STDC_ISO_10646__)
bcb28afc
PM
81#define USE_INTERMEDIATE_ENCODING_FUNCTION
82#define INTERMEDIATE_ENCODING intermediate_encoding ()
83const char *intermediate_encoding (void);
84
716b65bf 85#elif defined (_LIBICONV_VERSION) && _LIBICONV_VERSION >= 0x108
62234ccc
TT
86#define INTERMEDIATE_ENCODING "wchar_t"
87#else
88/* This shouldn't happen, because the earlier #if should have filtered
89 out this case. */
90#error "Neither __STDC_ISO_10646__ nor _LIBICONV_VERSION defined"
91#endif
92
93#else
94
95/* If we got here and have wchar_t support, we might be on a system
96 with some problem. So, we just disable everything. */
e01e2baa 97#if defined (HAVE_BTOWC)
62234ccc
TT
98#define PHONY_ICONV
99#endif
6c7a06a3
TT
100
101typedef char gdb_wchar_t;
102typedef int gdb_wint_t;
103
104#define gdb_wcslen strlen
105#define gdb_iswprint isprint
3041b931 106#define gdb_iswxdigit isxdigit
6c7a06a3
TT
107#define gdb_btowc /* empty */
108#define gdb_WEOF EOF
109
110#define LCST(X) X
111
732f6a93
TT
112/* If we are using the narrow character set, we want to use the host
113 narrow encoding as our intermediate encoding. However, if we are
114 also providing a phony iconv, we might as well just stick with
115 "wchar_t". */
62234ccc
TT
116#ifdef PHONY_ICONV
117#define INTERMEDIATE_ENCODING "wchar_t"
118#else
732f6a93
TT
119#define INTERMEDIATE_ENCODING host_charset ()
120#endif
6c7a06a3 121
732f6a93 122#endif
6c7a06a3
TT
123
124#endif /* GDB_WCHAR_H */