guile-elisp bootstrap (lisp)
[bpt/emacs.git] / src / charset.h
index 334d54d..4176ce5 100644 (file)
@@ -1,6 +1,5 @@
 /* Header for charset handler.
-   Copyright (C) 2001, 2002, 2003, 2004, 2005,
-                 2006, 2007, 2008, 2009, 2010, 2011, 2012 Free Software Foundation, Inc.
+   Copyright (C) 2001-2014 Free Software Foundation, Inc.
    Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
      2005, 2006, 2007, 2008, 2009, 2010, 2011
      National Institute of Advanced Industrial Science and Technology (AIST)
@@ -28,6 +27,10 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #ifndef EMACS_CHARSET_H
 #define EMACS_CHARSET_H
 
+#include <verify.h>
+
+INLINE_HEADER_BEGIN
+
 /* Index to arguments of Fdefine_charset_internal.  */
 
 enum define_charset_arg_index
@@ -147,31 +150,44 @@ struct charset
   int id;
 
   /* Index to Vcharset_hash_table.  */
-  int hash_index;
+  ptrdiff_t hash_index;
 
   /* Dimension of the charset: 1, 2, 3, or 4.  */
   int dimension;
 
-  /* Byte code range of each dimension.  <code_space>[4N] is a mininum
+  /* Byte code range of each dimension.  <code_space>[4N] is a minimum
      byte code of the (N+1)th dimension, <code_space>[4N+1] is a
      maximum byte code of the (N+1)th dimension, <code_space>[4N+2] is
      (<code_space>[4N+1] - <code_space>[4N] + 1), <code_space>[4N+3]
-     is a number of characters containd in the first to (N+1)th
-     dismesions.  We get `char-index' of a `code-point' from this
+     is the number of characters contained in the first through (N+1)th
+     dimensions, except that there is no <code_space>[15].
+     We get `char-index' of a `code-point' from this
      information.  */
-  int code_space[16];
+  int code_space[15];
 
   /* If B is a byte of Nth dimension of a code-point, the (N-1)th bit
      of code_space_mask[B] is set.  This array is used to quickly
      check if a code-point is in a valid range.  */
   unsigned char *code_space_mask;
 
-  /* 1 if there's no gap in code-points.  */
-  int code_linear_p;
+  /* True if there's no gap in code-points.  */
+  bool_bf code_linear_p : 1;
+
+  /* True if the charset is treated as 96 chars in ISO-2022
+     as opposed to 94 chars.  */
+  bool_bf iso_chars_96 : 1;
+
+  /* True if the charset is compatible with ASCII.  */
+  bool_bf ascii_compatible_p : 1;
+
+  /* True if the charset is supplementary.  */
+  bool_bf supplementary_p : 1;
 
-  /* If the charset is treated as 94-chars in ISO-2022, the value is 0.
-     If the charset is treated as 96-chars in ISO-2022, the value is 1.  */
-  int iso_chars_96;
+  /* True if all the code points are representable by Lisp_Int.  */
+  bool_bf compact_codes_p : 1;
+
+  /* True if the charset is unified with Unicode.  */
+  bool_bf unified_p : 1;
 
   /* ISO final byte of the charset: 48..127.  It may be -1 if the
      charset doesn't conform to ISO-2022.  */
@@ -185,26 +201,17 @@ struct charset
      version.  Otherwise, -1.  */
   int emacs_mule_id;
 
-  /* Nonzero if the charset is compatible with ASCII.  */
-  int ascii_compatible_p;
-
-  /* Nonzero if the charset is supplementary.  */
-  int supplementary_p;
-
-  /* Nonzero if all the code points are representable by Lisp_Int.  */
-  int compact_codes_p;
-
   /* The method for encoding/decoding characters of the charset.  */
   enum charset_method method;
 
-  /* Mininum and Maximum code points of the charset.  */
+  /* Minimum and Maximum code points of the charset.  */
   unsigned min_code, max_code;
 
   /* Offset value used by macros CODE_POINT_TO_INDEX and
-      INDEX_TO_CODE_POINT.  */
+      INDEX_TO_CODE_POINT.  */
   unsigned char_index_offset;
 
-  /* Mininum and Maximum character codes of the charset.  If the
+  /* Minimum and Maximum character codes of the charset.  If the
      charset is compatible with ASCII, min_char is a minimum non-ASCII
      character of the charset.  If the method of charset is
      CHARSET_METHOD_OFFSET, even if the charset is unified, min_char
@@ -232,11 +239,9 @@ struct charset
   /* Offset value to calculate a character code from code-point, and
      visa versa.  */
   int code_offset;
-
-  int unified_p;
 };
 
-/* Hash table of charset symbols vs. the correponding attribute
+/* Hash table of charset symbols vs. the corresponding attribute
    vectors.  */
 extern Lisp_Object Vcharset_hash_table;
 
@@ -251,14 +256,11 @@ extern Lisp_Object Vcharset_non_preferred_head;
 /* Incremented everytime we change the priority of charsets.  */
 extern unsigned short charset_ordered_list_tick;
 
-extern Lisp_Object Vcharset_list;
 extern Lisp_Object Viso_2022_charset_list;
 extern Lisp_Object Vemacs_mule_charset_list;
 
 extern int emacs_mule_charset[256];
 
-extern Lisp_Object Vcurrent_iso639_language;
-
 /* Macros to access information about charset.  */
 
 /* Return the attribute vector of charset whose symbol is SYMBOL.  */
@@ -326,6 +328,13 @@ extern Lisp_Object Vcurrent_iso639_language;
 #define CHARSET_DEUNIFIER(charset)     \
   (CHARSET_ATTR_DEUNIFIER (CHARSET_ATTRIBUTES (charset)))
 
+INLINE void
+set_charset_attr (struct charset *charset, enum charset_attr_index idx,
+                 Lisp_Object val)
+{
+  ASET (CHARSET_ATTRIBUTES (charset), idx, val);
+}
+
 
 /* Nonzero if OBJ is a valid charset symbol.  */
 #define CHARSETP(obj) (CHARSET_SYMBOL_HASH_INDEX (obj) >= 0)
@@ -335,20 +344,20 @@ extern Lisp_Object Vcurrent_iso639_language;
   do {                                                         \
     if (! SYMBOLP (x) || CHARSET_SYMBOL_HASH_INDEX (x) < 0)    \
       wrong_type_argument (Qcharsetp, (x));                    \
-  } while (0)
+  } while (false)
 
 
 /* Check if X is a valid charset symbol.  If valid, set ID to the id
    number of the charset.  Otherwise, signal an error. */
 #define CHECK_CHARSET_GET_ID(x, id)                                    \
   do {                                                                 \
-    int idx;                                                           \
+    ptrdiff_t idx;                                                     \
                                                                        \
     if (! SYMBOLP (x) || (idx = CHARSET_SYMBOL_HASH_INDEX (x)) < 0)    \
       wrong_type_argument (Qcharsetp, (x));                            \
     id = XINT (AREF (HASH_VALUE (XHASH_TABLE (Vcharset_hash_table), idx), \
                     charset_id));                                      \
-  } while (0)
+  } while (false)
 
 
 /* Check if X is a valid charset symbol.  If valid, set ATTR to the
@@ -357,15 +366,15 @@ extern Lisp_Object Vcurrent_iso639_language;
   do {                                                                 \
     if (!SYMBOLP (x) || NILP (attr = CHARSET_SYMBOL_ATTRIBUTES (x)))   \
       wrong_type_argument (Qcharsetp, (x));                            \
-  } while (0)
+  } while (false)
 
 
 #define CHECK_CHARSET_GET_CHARSET(x, charset)  \
   do {                                         \
-    int id;                                    \
-    CHECK_CHARSET_GET_ID (x, id);              \
-    charset = CHARSET_FROM_ID (id);            \
-  } while (0)
+    int csid;                                  \
+    CHECK_CHARSET_GET_ID (x, csid);            \
+    charset = CHARSET_FROM_ID (csid);          \
+  } while (false)
 
 
 /* Lookup Vcharset_ordered_list and return the first charset that
@@ -374,7 +383,7 @@ extern Lisp_Object Vcurrent_iso639_language;
   ((c) < 0x80 ? CHARSET_FROM_ID (charset_ascii)        \
    : char_charset ((c), Qnil, NULL))
 
-#if 0
+#if false
 /* Char-table of charset-sets.  Each element is a bool vector indexed
    by a charset ID.  */
 extern Lisp_Object Vchar_charset_set;
@@ -390,11 +399,11 @@ extern Lisp_Object Vchar_charset_set;
 #endif
 
 
-/* Return a character correponding to the code-point CODE of CHARSET.
+/* Return a character corresponding to the code-point CODE of CHARSET.
    Try some optimization before calling decode_char.  */
 
 #define DECODE_CHAR(charset, code)                                     \
-  ((ASCII_BYTE_P (code) && (charset)->ascii_compatible_p)              \
+  ((ASCII_CHAR_P (code) && (charset)->ascii_compatible_p)              \
    ? (code)                                                            \
    : ((code) < (charset)->min_code || (code) > (charset)->max_code)    \
    ? -1                                                                        \
@@ -402,7 +411,7 @@ extern Lisp_Object Vchar_charset_set;
    ? decode_char ((charset), (code))                                   \
    : (charset)->method == CHARSET_METHOD_OFFSET                                \
    ? ((charset)->code_linear_p                                         \
-      ? (code) - (charset)->min_code + (charset)->code_offset          \
+      ? (int) ((code) - (charset)->min_code) + (charset)->code_offset  \
       : decode_char ((charset), (code)))                               \
    : (charset)->method == CHARSET_METHOD_MAP                           \
    ? (((charset)->code_linear_p                                                \
@@ -412,48 +421,40 @@ extern Lisp_Object Vchar_charset_set;
       : decode_char ((charset), (code)))                               \
    : decode_char ((charset), (code)))
 
-
-/* If CHARSET is a simple offset base charset, return it's offset,
-   otherwise return -1.  */
-#define CHARSET_OFFSET(charset)                                \
-  (((charset)->method == CHARSET_METHOD_OFFSET         \
-    && (charset)->code_linear_p                                \
-    && ! (charset)->unified_p)                         \
-   ? (charset)->code_offset - (charset)->min_code      \
-   : -1)
-
 extern Lisp_Object charset_work;
 
 /* Return a code point of CHAR in CHARSET.
    Try some optimization before calling encode_char.  */
 
-#define ENCODE_CHAR(charset, c)                                                 \
-  ((ASCII_CHAR_P (c) && (charset)->ascii_compatible_p)                  \
-   ? (c)                                                                \
-   : ((charset)->unified_p                                              \
-      || (charset)->method == CHARSET_METHOD_SUBSET                     \
-      || (charset)->method == CHARSET_METHOD_SUPERSET)                  \
-   ? encode_char ((charset), (c))                                       \
-   : ((c) < (charset)->min_char || (c) > (charset)->max_char)           \
-   ? (charset)->invalid_code                                            \
-   : (charset)->method == CHARSET_METHOD_OFFSET                                 \
-   ? ((charset)->code_linear_p                                          \
-      ? (c) - (charset)->code_offset + (charset)->min_code              \
-      : encode_char ((charset), (c)))                                   \
-   : (charset)->method == CHARSET_METHOD_MAP                            \
-   ? (((charset)->compact_codes_p                                       \
-       && CHAR_TABLE_P (CHARSET_ENCODER (charset)))                     \
-      ? (charset_work = CHAR_TABLE_REF (CHARSET_ENCODER (charset), (c)), \
-        (NILP (charset_work)                                            \
-         ? (charset)->invalid_code                                      \
-         : XFASTINT (charset_work)))                                    \
-      : encode_char ((charset), (c)))                                   \
-   : encode_char ((charset), (c)))
-
-
-/* Set to 1 when a charset map is loaded to warn that a buffer text
+#define ENCODE_CHAR(charset, c)                                                \
+  (verify_expr                                                         \
+   (sizeof (c) <= sizeof (int),                                                \
+    (ASCII_CHAR_P (c) && (charset)->ascii_compatible_p                 \
+     ? (unsigned) (c)                                                  \
+     : ((charset)->unified_p                                           \
+       || (charset)->method == CHARSET_METHOD_SUBSET                   \
+       || (charset)->method == CHARSET_METHOD_SUPERSET)                \
+     ? encode_char (charset, c)                                                \
+     : (c) < (charset)->min_char || (c) > (charset)->max_char          \
+     ? (charset)->invalid_code                                         \
+     : (charset)->method == CHARSET_METHOD_OFFSET                      \
+     ? ((charset)->code_linear_p                                       \
+       ? (unsigned) ((c) - (charset)->code_offset) + (charset)->min_code \
+       : encode_char (charset, c))                                     \
+     : (charset)->method == CHARSET_METHOD_MAP                         \
+     ? (((charset)->compact_codes_p                                    \
+        && CHAR_TABLE_P (CHARSET_ENCODER (charset)))                   \
+       ? (charset_work = CHAR_TABLE_REF (CHARSET_ENCODER (charset), c), \
+          (NILP (charset_work)                                         \
+           ? (charset)->invalid_code                                   \
+           : (unsigned) XFASTINT (charset_work)))                      \
+       : encode_char (charset, c))                                     \
+     : encode_char (charset, c))))
+
+
+/* Set to true when a charset map is loaded to warn that a buffer text
    and a string data may be relocated.  */
-extern int charset_map_loaded;
+extern bool charset_map_loaded;
 
 
 /* Set CHARSET to the charset highest priority of C, CODE to the
@@ -471,10 +472,10 @@ extern int charset_map_loaded;
    macro ISO_CHARSET_TABLE (DIMENSION, CHARS, FINAL_CHAR).  */
 extern int iso_charset_table[ISO_MAX_DIMENSION][ISO_MAX_CHARS][ISO_MAX_FINAL];
 
-/* A charset of type iso2022 who has DIMENSION, CHARS, and FINAL
+/* A charset of type iso2022 who has DIMENSION, CHARS_96, and FINAL
    (final character).  */
 #define ISO_CHARSET_TABLE(dimension, chars_96, final)  \
-  iso_charset_table[(dimension) - 1][(chars_96)][(final)]
+  iso_charset_table[(dimension) - 1][chars_96][final]
 
 /* Nonzero if the charset who has FAST_MAP may contain C.  */
 #define CHARSET_FAST_MAP_REF(c, fast_map)              \
@@ -488,11 +489,11 @@ extern int iso_charset_table[ISO_MAX_DIMENSION][ISO_MAX_CHARS][ISO_MAX_FINAL];
       (fast_map)[(c) >> 10] |= 1 << (((c) >> 7) & 7);          \
     else                                                       \
       (fast_map)[((c) >> 15) + 62] |= 1 << (((c) >> 12) & 7);  \
-  } while (0)
+  } while (false)
 
 
 
-/* 1 if CHARSET may contain the character C.  */
+/* True if CHARSET may contain the character C.  */
 #define CHAR_CHARSET_P(c, charset)                                      \
   ((ASCII_CHAR_P (c) && (charset)->ascii_compatible_p)                  \
    || ((CHARSET_UNIFIED_P (charset)                                     \
@@ -521,9 +522,8 @@ extern int iso_charset_table[ISO_MAX_DIMENSION][ISO_MAX_CHARS][ISO_MAX_FINAL];
 
 extern Lisp_Object Qcharsetp;
 
-extern Lisp_Object Qascii, Qunicode;
+extern Lisp_Object Qascii;
 extern int charset_ascii, charset_eight_bit;
-extern int charset_iso_8859_1;
 extern int charset_unicode;
 extern int charset_jisx0201_roman;
 extern int charset_jisx0208_1978;
@@ -532,21 +532,17 @@ extern int charset_ksc5601;
 
 extern int charset_unibyte;
 
-extern struct charset *char_charset P_ ((int, Lisp_Object, unsigned *));
-extern Lisp_Object charset_attributes P_ ((int));
+extern struct charset *char_charset (int, Lisp_Object, unsigned *);
+extern Lisp_Object charset_attributes (int);
 
-extern int maybe_unify_char P_ ((int, Lisp_Object));
-extern int decode_char P_ ((struct charset *, unsigned));
-extern unsigned encode_char P_ ((struct charset *, int));
-extern int string_xstring_p P_ ((Lisp_Object));
+extern int decode_char (struct charset *, unsigned);
+extern unsigned encode_char (struct charset *, int);
+extern int string_xstring_p (Lisp_Object);
 
-extern void map_charset_chars P_ ((void (*) (Lisp_Object, Lisp_Object),
-                                  Lisp_Object, Lisp_Object,
-                                  struct charset *, unsigned, unsigned));
+extern void map_charset_chars (void (*) (Lisp_Object, Lisp_Object),
+                               Lisp_Object, Lisp_Object,
+                               struct charset *, unsigned, unsigned);
 
-EXFUN (Funify_charset, 3);
+INLINE_HEADER_END
 
 #endif /* EMACS_CHARSET_H */
-
-/* arch-tag: 3b96db55-4961-481d-ac3e-219f46a2b3aa
-   (do not change this comment) */