]> code.delx.au - gnu-emacs/blobdiff - src/character.h
(fatal): Add a final \n if needed (bug#5596).
[gnu-emacs] / src / character.h
index 44b8b29101a2fae52f9bde8e83b61f5dcaf3d704..1f1f6eade84be74434c28654104d440bca3a8223 100644 (file)
@@ -1,7 +1,7 @@
 /* Header for multibyte character handler.
    Copyright (C) 1995, 1997, 1998 Electrotechnical Laboratory, JAPAN.
      Licensed to the Free Software Foundation.
-   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008
+   Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
      National Institute of Advanced Industrial Science and Technology (AIST)
      Registration Number H13PRO009
 
@@ -62,6 +62,9 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 /* Return the character code for raw 8-bit byte BYTE.  */
 #define BYTE8_TO_CHAR(byte) ((byte) + 0x3FFF00)
 
+#define UNIBYTE_TO_CHAR(byte) \
+  (ASCII_BYTE_P (byte) ? (byte) : BYTE8_TO_CHAR (byte))
+
 /* Return the raw 8-bit byte for character C.  */
 #define CHAR_TO_BYTE8(c)       \
   (CHAR_BYTE8_P (c)            \
@@ -79,20 +82,6 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
    that corresponds to a raw 8-bit byte.  */
 #define CHAR_BYTE8_HEAD_P(byte) ((byte) == 0xC0 || (byte) == 0xC1)
 
-/* Mapping table from unibyte chars to multibyte chars.  */
-extern int unibyte_to_multibyte_table[256];
-
-/* Convert the unibyte character C to the corresponding multibyte
-   character.  If C can't be converted, return C.  */
-#define unibyte_char_to_multibyte(c)   \
-  ((c) < 256 ? unibyte_to_multibyte_table[(c)] : (c))
-
-/* Nth element is 1 iff unibyte char N can be mapped to a multibyte
-   char.  */
-extern char unibyte_has_multibyte_table[256];
-
-#define UNIBYTE_CHAR_HAS_MULTIBYTE_P(c) (unibyte_has_multibyte_table[(c)])
-
 /* If C is not ASCII, make it unibyte. */
 #define MAKE_CHAR_UNIBYTE(c)   \
   do {                         \
@@ -103,7 +92,7 @@ extern char unibyte_has_multibyte_table[256];
 
 /* If C is not ASCII, make it multibyte.  Assumes C < 256.  */
 #define MAKE_CHAR_MULTIBYTE(c) \
-  (eassert ((c) >= 0 && (c) < 256), (c) = unibyte_to_multibyte_table[(c)])
+  (eassert ((c) >= 0 && (c) < 256), (c) = UNIBYTE_TO_CHAR (c))
 
 /* This is the maximum byte length of multibyte form.  */
 #define MAX_MULTIBYTE_LENGTH 5
@@ -147,8 +136,8 @@ extern char unibyte_has_multibyte_table[256];
 
 /* Nonzero if character C has a printable glyph.  */
 #define CHAR_PRINTABLE_P(c)    \
-  (((c) >= 32 && ((c) < 127)   \
-    || ! NILP (CHAR_TABLE_REF (Vprintable_chars, (c)))))
+  (((c) >= 32 && (c) < 127)    \
+   || ! NILP (CHAR_TABLE_REF (Vprintable_chars, (c))))
 
 /* Return byte length of multibyte form for character C.  */
 #define CHAR_BYTES(c)                  \
@@ -322,10 +311,9 @@ extern char unibyte_has_multibyte_table[256];
   } while (0)
 
 /* Return the character code of character whose multibyte form is at
-   P.  The argument LEN is ignored.  It will be removed in the
-   future.  */
+   P.  */
 
-#define STRING_CHAR(p, len)                                    \
+#define STRING_CHAR(p)                                         \
   (!((p)[0] & 0x80)                                            \
    ? (p)[0]                                                    \
    : ! ((p)[0] & 0x20)                                         \
@@ -340,10 +328,9 @@ extern char unibyte_has_multibyte_table[256];
 
 
 /* Like STRING_CHAR, but set ACTUAL_LEN to the length of multibyte
-   form.  The argument LEN is ignored.  It will be removed in the
-   future.  */
+   form.  */
 
-#define STRING_CHAR_AND_LENGTH(p, len, actual_len)             \
+#define STRING_CHAR_AND_LENGTH(p, actual_len)                  \
   (!((p)[0] & 0x80)                                            \
    ? ((actual_len) = 1, (p)[0])                                        \
    : ! ((p)[0] & 0x20)                                         \
@@ -393,7 +380,7 @@ extern char unibyte_has_multibyte_table[256];
          unsigned char *ptr = &SDATA (STRING)[BYTEIDX];                \
          int len;                                                      \
                                                                        \
-         OUTPUT = STRING_CHAR_AND_LENGTH (ptr, 0, len);                \
+         OUTPUT = STRING_CHAR_AND_LENGTH (ptr, len);                   \
          BYTEIDX += len;                                               \
        }                                                               \
       else                                                             \
@@ -416,7 +403,7 @@ extern char unibyte_has_multibyte_table[256];
          unsigned char *ptr = &SDATA (STRING)[BYTEIDX];                      \
          int len;                                                            \
                                                                              \
-         OUTPUT = STRING_CHAR_AND_LENGTH (ptr, 0, len);                      \
+         OUTPUT = STRING_CHAR_AND_LENGTH (ptr, len);                         \
          BYTEIDX += len;                                                     \
        }                                                                     \
       else                                                                   \
@@ -437,7 +424,7 @@ extern char unibyte_has_multibyte_table[256];
       unsigned char *ptr = &SDATA (STRING)[BYTEIDX];                        \
       int len;                                                              \
                                                                             \
-      OUTPUT = STRING_CHAR_AND_LENGTH (ptr, 0, len);                        \
+      OUTPUT = STRING_CHAR_AND_LENGTH (ptr, len);                           \
       BYTEIDX += len;                                                       \
       CHARIDX++;                                                            \
     }                                                                       \
@@ -456,7 +443,7 @@ extern char unibyte_has_multibyte_table[256];
          unsigned char *ptr = BYTE_POS_ADDR (BYTEIDX);         \
          int len;                                              \
                                                                \
-         OUTPUT= STRING_CHAR_AND_LENGTH (ptr, 0, len);         \
+         OUTPUT= STRING_CHAR_AND_LENGTH (ptr, len);            \
          BYTEIDX += len;                                       \
        }                                                       \
       else                                                     \
@@ -476,7 +463,7 @@ extern char unibyte_has_multibyte_table[256];
       unsigned char *ptr = BYTE_POS_ADDR (BYTEIDX);            \
       int len;                                                 \
                                                                \
-      OUTPUT= STRING_CHAR_AND_LENGTH (ptr, 0, len);            \
+      OUTPUT = STRING_CHAR_AND_LENGTH (ptr, len);              \
       BYTEIDX += len;                                          \
       CHARIDX++;                                               \
     }                                                          \
@@ -574,26 +561,18 @@ extern char unibyte_has_multibyte_table[256];
 /* If C is a character to be unified with a Unicode character, return
    the unified Unicode character.  */
 
-#define MAYBE_UNIFY_CHAR(c)                                    \
-  if (c > MAX_UNICODE_CHAR                                     \
-      && CHAR_TABLE_P (Vchar_unify_table))                     \
-    {                                                          \
-      Lisp_Object val;                                         \
-      int unified;                                             \
-                                                               \
-      val = CHAR_TABLE_REF (Vchar_unify_table, c);             \
-      if (! NILP (val))                                                \
-       {                                                       \
-         if (SYMBOLP (val))                                    \
-           {                                                   \
-             Funify_charset (val, Qnil, Qnil);                 \
-             val = CHAR_TABLE_REF (Vchar_unify_table, c);      \
-           }                                                   \
-         if ((unified = XINT (val)) >= 0)                      \
-           c = unified;                                        \
-       }                                                       \
-    }                                                          \
-  else
+#define MAYBE_UNIFY_CHAR(c)                            \
+  do {                                                 \
+    if (c > MAX_UNICODE_CHAR && c <= MAX_5_BYTE_CHAR)  \
+      {                                                        \
+       Lisp_Object val;                                \
+       val = CHAR_TABLE_REF (Vchar_unify_table, c);    \
+       if (INTEGERP (val))                             \
+         c = XINT (val);                               \
+       else if (! NILP (val))                          \
+         c = maybe_unify_char (c, val);                \
+      }                                                        \
+  } while (0)
 
 
 /* Return the width of ASCII character C.  The width is measured by
@@ -618,6 +597,26 @@ extern char unibyte_has_multibyte_table[256];
    ? ASCII_CHAR_WIDTH (c)      \
    : XINT (CHAR_TABLE_REF (Vchar_width_table, c)))
 
+/* If C is a variation selector, return the index numnber of the
+   variation selector (1..256).  Otherwise, return 0.  */
+
+#define CHAR_VARIATION_SELECTOR_P(c)           \
+  ((c) < 0xFE00 ? 0                            \
+   : (c) <= 0xFE0F ? (c) - 0xFE00 + 1          \
+   : (c) < 0xE0100 ? 0                         \
+   : (c) <= 0xE01EF ? (c) - 0xE0100 + 17       \
+   : 0)
+
+/* If C is a high surrogate, return 1.  If C is a low surrogate,
+   return 0. Otherwise, return 0.  */
+
+#define CHAR_SURROGATE_PAIR_P(c)       \
+  ((c) < 0xD800 ? 0                    \
+   : (c) <= 0xDBFF ? 1                 \
+   : (c) <= 0xDFFF ? 2                 \
+   : 0)
+
+
 extern int char_resolve_modifier_mask P_ ((int));
 extern int char_string P_ ((unsigned, unsigned char *));
 extern int string_char P_ ((const unsigned char *,
@@ -671,7 +670,7 @@ extern Lisp_Object Vscript_representative_chars;
   } while (0)
 
 #define DEFSYM(sym, name)      \
-  do { (sym) = intern ((name)); staticpro (&(sym)); } while (0)
+  do { (sym) = intern_c_string ((name)); staticpro (&(sym)); } while (0)
 
 #endif /* EMACS_CHARACTER_H */