$TERM is now set to dumb.
[bpt/emacs.git] / src / charset.h
index d6b1dee..c20766f 100644 (file)
@@ -1,6 +1,8 @@
 /* Header for multibyte character handler.
 /* Header for multibyte character handler.
-   Copyright (C) 2001, 2002, 2003, 2004, 2005 Free Software Foundation, Inc.
-   Copyright (C) 1995, 1997, 1998, 2003
+   Copyright (C) 2001, 2002, 2003, 2004, 2005,
+                 2006, 2007 Free Software Foundation, Inc.
+   Copyright (C) 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, 2003, 2004,
+     2005, 2006, 2007
      National Institute of Advanced Industrial Science and Technology (AIST)
      Registration Number H14PRO021
 
      National Institute of Advanced Industrial Science and Technology (AIST)
      Registration Number H14PRO021
 
@@ -8,7 +10,7 @@ This file is part of GNU Emacs.
 
 GNU Emacs is free software; you can redistribute it and/or modify
 it under the terms of the GNU General Public License as published by
 
 GNU Emacs 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, or (at your option)
+the Free Software Foundation; either version 3, or (at your option)
 any later version.
 
 GNU Emacs is distributed in the hope that it will be useful,
 any later version.
 
 GNU Emacs is distributed in the hope that it will be useful,
@@ -411,8 +413,8 @@ extern int width_by_char_head[256];
            | ((c1) <= 0 ? 0 : (((c1) & 0x7F) << 7))))))
 
 
            | ((c1) <= 0 ? 0 : (((c1) & 0x7F) << 7))))))
 
 
-/* If GENERICP is nonzero, return nonzero iff C is a valid normal or
-   generic character.  If GENERICP is zero, return nonzero iff C is a
+/* If GENERICP is nonzero, return nonzero if C is a valid normal or
+   generic character.  If GENERICP is zero, return nonzero if C is a
    valid normal character.  */
 #define CHAR_VALID_P(c, genericp)      \
   ((c) >= 0                            \
    valid normal character.  */
 #define CHAR_VALID_P(c, genericp)      \
   ((c) >= 0                            \
@@ -448,7 +450,7 @@ extern int width_by_char_head[256];
 #define VALID_LEADING_CODE_P(code)     \
   (! NILP (CHARSET_TABLE_ENTRY (code)))
 
 #define VALID_LEADING_CODE_P(code)     \
   (! NILP (CHARSET_TABLE_ENTRY (code)))
 
-/* Return 1 iff the byte sequence at unibyte string STR (LENGTH bytes)
+/* Return 1 if the byte sequence at unibyte string STR (LENGTH bytes)
    is valid as a multibyte form.  If valid, by a side effect, BYTES is
    set to the byte length of the multibyte form.  */
 
    is valid as a multibyte form.  If valid, by a side effect, BYTES is
    set to the byte length of the multibyte form.  */
 
@@ -469,7 +471,7 @@ extern int width_by_char_head[256];
                     && VALID_LEADING_CODE_P (str[1]))))))))
 
 
                     && VALID_LEADING_CODE_P (str[1]))))))))
 
 
-/* Return 1 iff the byte sequence at multibyte string STR is valid as
+/* Return 1 if the byte sequence at multibyte string STR is valid as
    a unibyte form.  By a side effect, BYTES is set to the byte length
    of one character at STR.  */
 
    a unibyte form.  By a side effect, BYTES is set to the byte length
    of one character at STR.  */
 
@@ -497,7 +499,7 @@ extern int width_by_char_head[256];
         c1 = CHAR_FIELD3 (c),                                              \
         c2 = -1)))
 
         c1 = CHAR_FIELD3 (c),                                              \
         c2 = -1)))
 
-/* Return 1 iff character C has valid printable glyph.  */
+/* Return 1 if character C has valid printable glyph.  */
 #define CHAR_PRINTABLE_P(c) (ASCII_BYTE_P (c) || char_printable_p (c))
 
 /* The charset of the character at STR is stored in CHARSET, and the
 #define CHAR_PRINTABLE_P(c) (ASCII_BYTE_P (c) || char_printable_p (c))
 
 /* The charset of the character at STR is stored in CHARSET, and the
@@ -657,22 +659,34 @@ else
   } while (0)
 
 
   } while (0)
 
 
-/* If P is after LIMIT, advance P to the previous character boundary.
-   It assumes that P is already at a character boundary of the sane
-   mulitbyte form whose beginning address is LIMIT.  */
+/* If P is after LIMIT, advance P to the previous character boundary.  */
 
 #define PREV_CHAR_BOUNDARY(p, limit)                                   \
   do {                                                                 \
     if ((p) > (limit))                                                 \
       {                                                                        \
        const unsigned char *p0 = (p);                                  \
 
 #define PREV_CHAR_BOUNDARY(p, limit)                                   \
   do {                                                                 \
     if ((p) > (limit))                                                 \
       {                                                                        \
        const unsigned char *p0 = (p);                                  \
+       const unsigned char *p_limit = max (limit, p0 - MAX_MULTIBYTE_LENGTH);\
        do {                                                            \
          p0--;                                                         \
        do {                                                            \
          p0--;                                                         \
-       } while (p0 >= limit && ! CHAR_HEAD_P (*p0));                   \
-       (p) = (BYTES_BY_CHAR_HEAD (*p0) == (p) - p0) ? p0 : (p) - 1;    \
+       } while (p0 >= p_limit && ! CHAR_HEAD_P (*p0));                 \
+       /* If BBCH(*p0) > p-p0, it means we were not on a boundary.  */ \
+       (p) = (BYTES_BY_CHAR_HEAD (*p0) >= (p) - p0) ? p0 : (p) - 1;    \
       }                                                                        \
   } while (0)
 
       }                                                                        \
   } while (0)
 
+#define AT_CHAR_BOUNDARY_P(result, p, limit)   \
+  do {                                         \
+    if (CHAR_HEAD_P (*(p)) || (p) <= limit)    \
+      /* Optimization for the common case. */  \
+      (result) = 1;                            \
+    else                                       \
+      {                                                \
+       const unsigned char *p_aux = (p)+1;     \
+       PREV_CHAR_BOUNDARY (p_aux, limit);      \
+       (result) = (p_aux == (p));              \
+      }                                                \
+} while (0)
 
 #ifdef emacs
 
 
 #ifdef emacs
 
@@ -824,7 +838,7 @@ while (0)
 /* This is the maximum byte length of multi-byte sequence.  */
 #define MAX_MULTIBYTE_LENGTH 4
 
 /* This is the maximum byte length of multi-byte sequence.  */
 #define MAX_MULTIBYTE_LENGTH 4
 
-extern void invalid_character P_ ((int));
+extern void invalid_character P_ ((int)) NO_RETURN;
 
 extern int translate_char P_ ((Lisp_Object, int, int, int, int));
 extern int split_string P_ ((const unsigned char *, int, int *,
 
 extern int translate_char P_ ((Lisp_Object, int, int, int, int));
 extern int split_string P_ ((const unsigned char *, int, int *,