Automatic date update in version.in
[deliverable/binutils-gdb.git] / gdb / charset.h
index d4bd1bc99100d749d676c974c59b1e63437756a7..dba95beeb406a7566d5a5ca3152f1158954b76eb 100644 (file)
@@ -1,11 +1,11 @@
 /* Character set conversion support for GDB.
-   Copyright (C) 2001 Free Software Foundation, Inc.
+   Copyright (C) 2001-2020 Free Software Foundation, Inc.
 
    This file is part of GDB.
 
    This program is free software; you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
-   the Free Software Foundation; either version 2 of the License, or
+   the Free Software Foundation; either version 3 of the License, or
    (at your option) any later version.
 
    This program is distributed in the hope that it will be useful,
    GNU General Public License for more details.
 
    You should have received a copy of the GNU General Public License
-   along with this program; if not, write to the Free Software
-   Foundation, Inc., 51 Franklin Street, Fifth Floor,
-   Boston, MA 02110-1301, USA.  */
+   along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
 
 #ifndef CHARSET_H
 #define CHARSET_H
 
+#include "gdbsupport/def-vector.h"
 
 /* If the target program uses a different character set than the host,
    GDB has some support for translating between the two; GDB converts
    them, and converts characters and strings appearing in expressions
    entered by the user to the target character set.
 
-   At the moment, GDB only supports single-byte, stateless character
-   sets.  This includes the ISO-8859 family (ASCII extended with
-   accented characters, and (I think) Cyrillic, for European
-   languages), and the EBCDIC family (used on IBM's mainframes).
-   Unfortunately, it excludes many Asian scripts, the fixed- and
-   variable-width Unicode encodings, and other desireable things.
-   Patches are welcome!  (For example, it would be nice if the Java
-   string support could simply get absorbed into some more general
-   multi-byte encoding support.)
-
-   Furthermore, GDB's code pretty much assumes that the host character
-   set is some superset of ASCII; there are plenty if ('0' + n)
-   expressions and the like.
-
-   When the `iconv' library routine supports a character set meeting
-   the requirements above, it's easy to plug an entry into GDB's table
-   that uses iconv to handle the details.  */
+   GDB's code pretty much assumes that the host character set is some
+   superset of ASCII; there are plenty if ('0' + n) expressions and
+   the like.  */
 
 /* Return the name of the current host/target character set.  The
    result is owned by the charset module; the caller should not free
    it.  */
 const char *host_charset (void);
-const char *target_charset (void);
-
-/* In general, the set of C backslash escapes (\n, \f) is specific to
-   the character set.  Not all character sets will have form feed
-   characters, for example.
-
-   The following functions allow GDB to parse and print control
-   characters in a character-set-independent way.  They are both
-   language-specific (to C and C++) and character-set-specific.
-   Putting them here is a compromise.  */
-
-
-/* If the target character TARGET_CHAR have a backslash escape in the
-   C language (i.e., a character like 'n' or 't'), return the host
-   character string that should follow the backslash.  Otherwise,
-   return zero.
-
-   When this function returns non-zero, the string it returns is
-   statically allocated; the caller is not responsible for freeing it.  */
-const char *c_target_char_has_backslash_escape (int target_char);
-
-
-/* If the host character HOST_CHAR is a valid backslash escape in the
-   C language for the target character set, return non-zero, and set
-   *TARGET_CHAR to the target character the backslash escape represents.
-   Otherwise, return zero.  */
-int c_parse_backslash (int host_char, int *target_char);
-
-
-/* Return non-zero if the host character HOST_CHAR can be printed
-   literally --- that is, if it can be readably printed as itself in a
-   character or string constant.  Return zero if it should be printed
-   using some kind of numeric escape, like '\031' in C, '^(25)' in
-   Chill, or #25 in Pascal.  */
-int host_char_print_literally (int host_char);
-
-
-/* If the host character HOST_CHAR has an equivalent in the target
-   character set, set *TARGET_CHAR to that equivalent, and return
-   non-zero.  Otherwise, return zero.  */
-int host_char_to_target (int host_char, int *target_char);
-
-
-/* If the target character TARGET_CHAR has an equivalent in the host
-   character set, set *HOST_CHAR to that equivalent, and return
-   non-zero.  Otherwise, return zero.  */
-int target_char_to_host (int target_char, int *host_char);
-
-
-/* If the target character TARGET_CHAR has a corresponding control
-   character (also in the target character set), set *TARGET_CTRL_CHAR
-   to the control character, and return non-zero.  Otherwise, return
-   zero.  */
-int target_char_to_control_char (int target_char, int *target_ctrl_char);
-
+const char *target_charset (struct gdbarch *gdbarch);
+const char *target_wide_charset (struct gdbarch *gdbarch);
+
+/* These values are used to specify the type of transliteration done
+   by convert_between_encodings.  */
+enum transliterations
+  {
+    /* Error on failure to convert.  */
+    translit_none,
+    /* Transliterate to host char.  */
+    translit_char
+  };
+
+/* Convert between two encodings.
+
+   FROM is the name of the source encoding.
+   TO is the name of the target encoding.
+   BYTES holds the bytes to convert; this is assumed to be characters
+   in the target encoding.
+   NUM_BYTES is the number of bytes.
+   WIDTH is the width of a character from the FROM charset, in bytes.
+   For a variable width encoding, WIDTH should be the size of a "base
+   character".
+   OUTPUT is an obstack where the converted data is written.  The
+   caller is responsible for initializing the obstack, and for
+   destroying the obstack should an error occur.
+   TRANSLIT specifies how invalid conversions should be handled.  */
+
+void convert_between_encodings (const char *from, const char *to,
+                               const gdb_byte *bytes,
+                               unsigned int num_bytes,
+                               int width, struct obstack *output,
+                               enum transliterations translit);
+
+
+/* These values are used by wchar_iterate to report errors.  */
+enum wchar_iterate_result
+  {
+    /* Ordinary return.  */
+    wchar_iterate_ok,
+    /* Invalid input sequence.  */
+    wchar_iterate_invalid,
+    /* Incomplete input sequence at the end of the input.  */
+    wchar_iterate_incomplete,
+    /* EOF.  */
+    wchar_iterate_eof
+  };
+
+/* An iterator that returns host wchar_t's from a target string.  */
+class wchar_iterator
+{
+ public:
+
+  /* Create a new character iterator which returns wchar_t's.  INPUT is
+     the input buffer.  BYTES is the number of bytes in the input
+     buffer.  CHARSET is the name of the character set in which INPUT is
+     encoded.  WIDTH is the number of bytes in a base character of
+     CHARSET.
+
+     This constructor can throw on error.  */
+  wchar_iterator (const gdb_byte *input, size_t bytes, const char *charset,
+                 size_t width);
+
+  ~wchar_iterator ();
+
+  /* Perform a single iteration of a wchar_t iterator.
+   
+     Returns the number of characters converted.  A negative result
+     means that EOF has been reached.  A positive result indicates the
+     number of valid wchar_ts in the result; *OUT_CHARS is updated to
+     point to the first valid character.
+
+     In all cases aside from EOF, *PTR is set to point to the first
+     converted target byte.  *LEN is set to the number of bytes
+     converted.
+
+     A zero result means one of several unusual results.  *OUT_RESULT is
+     set to indicate the type of un-ordinary return.
+
+     wchar_iterate_invalid means that an invalid input character was
+     seen.  The iterator is advanced by WIDTH (the argument to
+     the wchar_iterator constructor) bytes.
+
+     wchar_iterate_incomplete means that an incomplete character was
+     seen at the end of the input sequence.
+   
+     wchar_iterate_eof means that all bytes were successfully
+     converted.  The other output arguments are not set.  */
+  int iterate (enum wchar_iterate_result *out_result, gdb_wchar_t **out_chars,
+              const gdb_byte **ptr, size_t *len);
+
+ private:
+
+  /* The underlying iconv descriptor.  */
+#ifdef PHONY_ICONV
+  int m_desc;
+#else
+  iconv_t m_desc;
+#endif
+
+  /* The input string.  This is updated as we convert characters.  */
+  const gdb_byte *m_input;
+  /* The number of bytes remaining in the input.  */
+  size_t m_bytes;
+
+  /* The width of an input character.  */
+  size_t m_width;
+
+  /* The output buffer.  */
+  gdb::def_vector<gdb_wchar_t> m_out;
+};
+
+\f
+
+/* GDB needs to know a few details of its execution character set.
+   This knowledge is isolated here and in charset.c.  */
+
+/* The escape character.  */
+#define HOST_ESCAPE_CHAR 27
+
+/* Convert a letter, like 'c', to its corresponding control
+   character.  */
+char host_letter_to_control_character (char c);
+
+/* Convert a hex digit character to its numeric value.  E.g., 'f' is
+   converted to 15.  This function assumes that C is a valid hex
+   digit.  Both upper- and lower-case letters are recognized.  */
+int host_hex_value (char c);
 
 #endif /* CHARSET_H */
This page took 0.025061 seconds and 4 git commands to generate.