Merge changes made in Gnus trunk.
[bpt/emacs.git] / src / character.h
index 075d36b..aea1a47 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, 2009
+   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)                  \
@@ -232,10 +221,6 @@ extern char unibyte_has_multibyte_table[256];
        (ASCII_BYTE_P (byte) || LEADING_CODE_P (byte))  */
 #define CHAR_HEAD_P(byte) (((byte) & 0xC0) != 0x80)
 
-/* Kept for backward compatibility.  This macro will be removed in the
-   future.  */
-#define BASE_LEADING_CODE_P LEADING_CODE_P
-
 /* How many bytes a character that starts with BYTE occupies in a
    multibyte form.  */
 #define BYTES_BY_CHAR_HEAD(byte)       \
@@ -246,23 +231,6 @@ extern char unibyte_has_multibyte_table[256];
    : 5)
 
 
-/* Return the length of the multi-byte form at string STR of length
-   LEN while assuming that STR points a valid multi-byte form.  As
-   this macro isn't necessary anymore, all callers will be changed to
-   use BYTES_BY_CHAR_HEAD directly in the future.  */
-
-#define MULTIBYTE_FORM_LENGTH(str, len)                \
-  BYTES_BY_CHAR_HEAD (*(str))
-
-/* Parse multibyte string STR of length LENGTH and set BYTES to the
-   byte length of a character at STR while assuming that STR points a
-   valid multibyte form.  As this macro isn't necessary anymore, all
-   callers will be changed to use BYTES_BY_CHAR_HEAD directly in the
-   future.  */
-
-#define PARSE_MULTIBYTE_SEQ(str, length, bytes)        \
-  (bytes) = BYTES_BY_CHAR_HEAD (*(str))
-
 /* The byte length of multibyte form at unibyte string P ending at
    PEND.  If STR doesn't point to a valid multibyte form, return 0.  */
 
@@ -296,7 +264,7 @@ extern char unibyte_has_multibyte_table[256];
 
 /* If P is before LIMIT, advance P to the next character boundary.
    Assumes that P is already at a character boundary of the same
-   mulitbyte form whose end address is LIMIT.  */
+   multibyte form whose end address is LIMIT.  */
 
 #define NEXT_CHAR_BOUNDARY(p, limit)   \
   do {                                 \
@@ -307,7 +275,7 @@ extern char unibyte_has_multibyte_table[256];
 
 /* If P is after LIMIT, advance P to the previous character boundary.
    Assumes that P is already at a character boundary of the same
-   mulitbyte form whose beginning address is LIMIT.  */
+   multibyte form whose beginning address is LIMIT.  */
 
 #define PREV_CHAR_BOUNDARY(p, limit)                                   \
   do {                                                                 \
@@ -322,10 +290,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 +307,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 +359,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 +382,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 +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;                                                       \
       CHARIDX++;                                                            \
     }                                                                       \
@@ -456,7 +422,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 +442,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++;                                               \
     }                                                          \
@@ -621,7 +587,7 @@ extern char unibyte_has_multibyte_table[256];
    : 0)
 
 /* If C is a high surrogate, return 1.  If C is a low surrogate,
-   return 0. Otherwise, return 0.  */
+   return 0.  Otherwise, return 0.  */
 
 #define CHAR_SURROGATE_PAIR_P(c)       \
   ((c) < 0xD800 ? 0                    \
@@ -630,24 +596,27 @@ extern char unibyte_has_multibyte_table[256];
    : 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 *,
-                           const unsigned char **, int *));
-
-extern int translate_char P_ ((Lisp_Object, int c));
-extern int char_printable_p P_ ((int c));
-extern void parse_str_as_multibyte P_ ((const unsigned char *, int, int *,
-                                       int *));
-extern int parse_str_to_multibyte P_ ((unsigned char *, int));
-extern int str_as_multibyte P_ ((unsigned char *, int, int, int *));
-extern int str_to_multibyte P_ ((unsigned char *, int, int));
-extern int str_as_unibyte P_ ((unsigned char *, int));
-extern EMACS_INT str_to_unibyte P_ ((const unsigned char *, unsigned char *,
-                                    EMACS_INT, int));
-extern int strwidth P_ ((unsigned char *, int));
-extern int c_string_width P_ ((const unsigned char *, int, int, int *, int *));
-extern int lisp_string_width P_ ((Lisp_Object, int, int *, int *));
+extern int char_resolve_modifier_mask (int);
+extern int char_string (unsigned, unsigned char *);
+extern int string_char (const unsigned char *,
+                        const unsigned char **, int *);
+
+extern int translate_char (Lisp_Object, int c);
+extern int char_printable_p (int c);
+extern void parse_str_as_multibyte (const unsigned char *,
+                                   EMACS_INT, EMACS_INT *, EMACS_INT *);
+extern EMACS_INT parse_str_to_multibyte (const unsigned char *, EMACS_INT);
+extern EMACS_INT str_as_multibyte (unsigned char *, EMACS_INT, EMACS_INT,
+                            EMACS_INT *);
+extern EMACS_INT str_to_multibyte (unsigned char *, EMACS_INT, EMACS_INT);
+extern EMACS_INT str_as_unibyte (unsigned char *, EMACS_INT);
+extern EMACS_INT str_to_unibyte (const unsigned char *, unsigned char *,
+                                 EMACS_INT, int);
+extern EMACS_INT strwidth (const unsigned char *, EMACS_INT);
+extern EMACS_INT c_string_width (const unsigned char *, EMACS_INT, int,
+                                EMACS_INT *, EMACS_INT *);
+extern EMACS_INT lisp_string_width (Lisp_Object, int,
+                                   EMACS_INT *, EMACS_INT *);
 
 extern Lisp_Object Vprintable_chars;
 
@@ -658,7 +627,7 @@ extern Lisp_Object Vchar_direction_table;
 extern Lisp_Object Vchar_unify_table;
 extern Lisp_Object Vunicode_category_table;
 
-extern Lisp_Object string_escape_byte8 P_ ((Lisp_Object));
+extern Lisp_Object string_escape_byte8 (Lisp_Object);
 
 /* Return a translation table of id number ID.  */
 #define GET_TRANSLATION_TABLE(id) \
@@ -670,20 +639,8 @@ extern Lisp_Object Vauto_fill_chars;
 extern Lisp_Object Vchar_script_table;
 extern Lisp_Object Vscript_representative_chars;
 
-/* Copy LEN bytes from FROM to TO.  This macro should be used only
-   when a caller knows that LEN is short and the obvious copy loop is
-   faster than calling bcopy which has some overhead.  Copying a
-   multibyte sequence of a character is the typical case.  */
-
-#define BCOPY_SHORT(from, to, len)             \
-  do {                                         \
-    int i = len;                               \
-    unsigned char *from_p = from, *to_p = to;  \
-    while (i--) *to_p++ = *from_p++;           \
-  } 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 */