GDB (API)
/home/stan/gdb/src/gdb/gdb_wchar.h
Go to the documentation of this file.
00001 /* Wide characters for gdb
00002    Copyright (C) 2009-2013 Free Software Foundation, Inc.
00003 
00004    This file is part of GDB.
00005 
00006    This program is free software; you can redistribute it and/or modify
00007    it under the terms of the GNU General Public License as published by
00008    the Free Software Foundation; either version 3 of the License, or
00009    (at your option) any later version.
00010 
00011    This program is distributed in the hope that it will be useful,
00012    but WITHOUT ANY WARRANTY; without even the implied warranty of
00013    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014    GNU General Public License for more details.
00015 
00016    You should have received a copy of the GNU General Public License
00017    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
00018 
00019 #ifndef GDB_WCHAR_H
00020 #define GDB_WCHAR_H
00021 
00022 /* We handle three different modes here.
00023    
00024    Capable systems have the full suite: wchar_t support and iconv
00025    (perhaps via GNU libiconv).  On these machines, full functionality
00026    is available.  Note that full functionality is dependent on us
00027    being able to convert from an arbitrary encoding to wchar_t.  In
00028    practice this means we look for __STDC_ISO_10646__ (where we know
00029    the name of the wchar_t encoding) or GNU libiconv, where we can use
00030    "wchar_t".
00031    
00032    DJGPP is known to have libiconv but not wchar_t support.  On
00033    systems like this, we use the narrow character functions.  The full
00034    functionality is available to the user, but many characters (those
00035    outside the narrow range) will be displayed as escapes.
00036    
00037    Finally, some systems do not have iconv, or are really broken
00038    (e.g., Solaris, which almost has all of this working, but where
00039    just enough is broken to make it too hard to use).  Here we provide
00040    a phony iconv which only handles a single character set, and we
00041    provide wrappers for the wchar_t functionality we use.  */
00042 
00043 
00044 #if defined (HAVE_ICONV)
00045 #include <iconv.h>
00046 #else
00047 /* This define is used elsewhere so we don't need to duplicate the
00048    same checking logic in multiple places.  */
00049 #define PHONY_ICONV
00050 #endif
00051 
00052 /* We use "btowc" as a sentinel to detect functioning wchar_t support.
00053    We check for either __STDC_ISO_10646__ or a new-enough libiconv in
00054    order to ensure we can convert to and from wchar_t.  We choose
00055    libiconv version 0x108 because it is the first version with
00056    iconvlist.  */
00057 #if defined (HAVE_ICONV) && defined (HAVE_WCHAR_H) && defined (HAVE_BTOWC) \
00058   && (defined (__STDC_ISO_10646__) \
00059       || (defined (_LIBICONV_VERSION) && _LIBICONV_VERSION >= 0x108))
00060 
00061 #include <wchar.h>
00062 #include <wctype.h>
00063 
00064 typedef wchar_t gdb_wchar_t;
00065 typedef wint_t gdb_wint_t;
00066 
00067 #define gdb_wcslen wcslen
00068 #define gdb_iswprint iswprint
00069 #define gdb_iswdigit iswdigit
00070 #define gdb_btowc btowc
00071 #define gdb_WEOF WEOF
00072 
00073 #define LCST(X) L ## X
00074 
00075 /* If __STDC_ISO_10646__ is defined, then the host wchar_t is UCS-4.
00076    We exploit this fact in the hope that there are hosts that define
00077    this but which do not support "wchar_t" as an encoding argument to
00078    iconv_open.  We put the endianness into the encoding name to avoid
00079    hosts that emit a BOM when the unadorned name is used.  */
00080 #if defined (__STDC_ISO_10646__)
00081 #define USE_INTERMEDIATE_ENCODING_FUNCTION
00082 #define INTERMEDIATE_ENCODING intermediate_encoding ()
00083 const char *intermediate_encoding (void);
00084 
00085 #elif defined (_LIBICONV_VERSION) && _LIBICONV_VERSION >= 0x108
00086 #define INTERMEDIATE_ENCODING "wchar_t"
00087 #else
00088 /* This shouldn't happen, because the earlier #if should have filtered
00089    out this case.  */
00090 #error "Neither __STDC_ISO_10646__ nor _LIBICONV_VERSION defined"
00091 #endif
00092 
00093 #else
00094 
00095 /* If we got here and have wchar_t support, we might be on a system
00096    with some problem.  So, we just disable everything.  */
00097 #if defined (HAVE_WCHAR_H) && defined (HAVE_BTOWC)
00098 #define PHONY_ICONV
00099 #endif
00100 
00101 typedef char gdb_wchar_t;
00102 typedef int gdb_wint_t;
00103 
00104 #define gdb_wcslen strlen
00105 #define gdb_iswprint isprint
00106 #define gdb_iswdigit isdigit
00107 #define gdb_btowc /* empty */
00108 #define gdb_WEOF EOF
00109 
00110 #define LCST(X) X
00111 
00112 /* If we are using the narrow character set, we want to use the host
00113    narrow encoding as our intermediate encoding.  However, if we are
00114    also providing a phony iconv, we might as well just stick with
00115    "wchar_t".  */
00116 #ifdef PHONY_ICONV
00117 #define INTERMEDIATE_ENCODING "wchar_t"
00118 #else
00119 #define INTERMEDIATE_ENCODING host_charset ()
00120 #endif
00121 
00122 #endif
00123 
00124 #endif /* GDB_WCHAR_H */
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Defines