Merge from emacs-24; up to 2012-12-26T16:22:18Z!michael.albinus@gmx.de
[bpt/emacs.git] / src / character.c
index b85ceda..5a06c7f 100644 (file)
@@ -1,6 +1,6 @@
 /* Basic character support.
 
-Copyright (C) 2001-201 Free Software Foundation, Inc.
+Copyright (C) 2001-2013 Free Software Foundation, Inc.
 Copyright (C) 1995, 1997, 1998, 2001 Electrotechnical Laboratory, JAPAN.
   Licensed to the Free Software Foundation.
 Copyright (C) 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010, 2011
@@ -29,12 +29,13 @@ along with GNU Emacs.  If not, see <http://www.gnu.org/licenses/>.  */
 #include <config.h>
 #endif
 
+#define CHARACTER_INLINE EXTERN_INLINE
+
 #include <stdio.h>
 
 #ifdef emacs
 
 #include <sys/types.h>
-#include <setjmp.h>
 #include <intprops.h>
 #include "lisp.h"
 #include "character.h"
@@ -57,9 +58,6 @@ static Lisp_Object Qauto_fill_chars;
    Unicode character.  Mainly used by the macro MAYBE_UNIFY_CHAR.  */
 Lisp_Object Vchar_unify_table;
 
-/* Variable used locally in the macro FETCH_MULTIBYTE_CHAR.  */
-unsigned char *_fetch_multibyte_char_p;
-
 static Lisp_Object Qchar_script_table;
 
 \f
@@ -128,8 +126,6 @@ char_string (unsigned int c, unsigned char *p)
       c &= ~CHAR_MODIFIER_MASK;
     }
 
-  MAYBE_UNIFY_CHAR (c);
-
   if (c <= MAX_3_BYTE_CHAR)
     {
       bytes = CHAR_STRING (c, p);
@@ -197,8 +193,6 @@ string_char (const unsigned char *p, const unsigned char **advanced, int *len)
       p += 5;
     }
 
-  MAYBE_UNIFY_CHAR (c);
-
   if (len)
     *len = p - saved_p;
   if (advanced)
@@ -259,6 +253,9 @@ multibyte_char_to_unibyte_safe (int c)
 
 DEFUN ("characterp", Fcharacterp, Scharacterp, 1, 2, 0,
        doc: /* Return non-nil if OBJECT is a character.
+In Emacs Lisp, characters are represented by character codes, which
+are non-negative integers.  The function `max-char' returns the
+maximum character code.
 usage: (characterp OBJECT)  */)
   (Lisp_Object object, Lisp_Object ignore)
 {
@@ -425,7 +422,7 @@ lisp_string_width (Lisp_Object string, ptrdiff_t precision,
   /* This set multibyte to 0 even if STRING is multibyte when it
      contains only ascii and eight-bit-graphic, but that's
      intentional.  */
-  int multibyte = len < SBYTES (string);
+  bool multibyte = len < SBYTES (string);
   unsigned char *str = SDATA (string);
   ptrdiff_t i = 0, i_byte = 0;
   ptrdiff_t width = 0;
@@ -539,7 +536,7 @@ multibyte_chars_in_text (const unsigned char *ptr, ptrdiff_t nbytes)
       int len = MULTIBYTE_LENGTH (ptr, endp);
 
       if (len == 0)
-       abort ();
+       emacs_abort ();
       ptr += len;
       chars++;
     }
@@ -763,13 +760,10 @@ str_as_unibyte (unsigned char *str, ptrdiff_t bytes)
    corresponding byte and store in DST.  CHARS is the number of
    characters in SRC.  The value is the number of bytes stored in DST.
    Usually, the value is the same as CHARS, but is less than it if SRC
-   contains a non-ASCII, non-eight-bit character.  If ACCEPT_LATIN_1
-   is nonzero, a Latin-1 character is accepted and converted to a byte
-   of that character code.
-   Note: Currently the arg ACCEPT_LATIN_1 is not used.  */
+   contains a non-ASCII, non-eight-bit character.  */
 
 ptrdiff_t
-str_to_unibyte (const unsigned char *src, unsigned char *dst, ptrdiff_t chars, int accept_latin_1)
+str_to_unibyte (const unsigned char *src, unsigned char *dst, ptrdiff_t chars)
 {
   ptrdiff_t i;
 
@@ -779,8 +773,7 @@ str_to_unibyte (const unsigned char *src, unsigned char *dst, ptrdiff_t chars, i
 
       if (CHAR_BYTE8_P (c))
        c = CHAR_TO_BYTE8 (c);
-      else if (! ASCII_CHAR_P (c)
-              && (! accept_latin_1 || c >= 0x100))
+      else if (! ASCII_CHAR_P (c))
        return i;
       *dst++ = c;
     }
@@ -791,7 +784,7 @@ str_to_unibyte (const unsigned char *src, unsigned char *dst, ptrdiff_t chars, i
 static ptrdiff_t
 string_count_byte8 (Lisp_Object string)
 {
-  int multibyte = STRING_MULTIBYTE (string);
+  bool multibyte = STRING_MULTIBYTE (string);
   ptrdiff_t nbytes = SBYTES (string);
   unsigned char *p = SDATA (string);
   unsigned char *pend = p + nbytes;
@@ -823,7 +816,7 @@ string_escape_byte8 (Lisp_Object string)
 {
   ptrdiff_t nchars = SCHARS (string);
   ptrdiff_t nbytes = SBYTES (string);
-  int multibyte = STRING_MULTIBYTE (string);
+  bool multibyte = STRING_MULTIBYTE (string);
   ptrdiff_t byte8_count;
   const unsigned char *src, *src_end;
   unsigned char *dst;
@@ -840,8 +833,8 @@ string_escape_byte8 (Lisp_Object string)
 
   if (multibyte)
     {
-      if ((MOST_POSITIVE_FIXNUM - nchars) / 3 < byte8_count
-         || (STRING_BYTES_BOUND - nbytes) / 2 < byte8_count)
+      if (byte8_count > (MOST_POSITIVE_FIXNUM - nchars) / 3
+         || byte8_count > (STRING_BYTES_BOUND - nbytes) / 2)
        string_overflow ();
 
       /* Convert 2-byte sequence of byte8 chars to 4-byte octal.  */
@@ -850,7 +843,7 @@ string_escape_byte8 (Lisp_Object string)
     }
   else
     {
-      if ((STRING_BYTES_BOUND - nbytes) / 3 < byte8_count)
+      if (byte8_count > (STRING_BYTES_BOUND - nbytes) / 3)
        string_overflow ();
 
       /* Convert 1-byte sequence of byte8 chars to 4-byte octal.  */
@@ -870,8 +863,7 @@ string_escape_byte8 (Lisp_Object string)
          {
            c = STRING_CHAR_ADVANCE (src);
            c = CHAR_TO_BYTE8 (c);
-           sprintf ((char *) dst, "\\%03o", c);
-           dst += 4;
+           dst += sprintf ((char *) dst, "\\%03o", c);
          }
        else
          while (len--) *dst++ = *src++;
@@ -881,10 +873,7 @@ string_escape_byte8 (Lisp_Object string)
       {
        c = *src++;
        if (c >= 0x80)
-         {
-           sprintf ((char *) dst, "\\%03o", c);
-           dst += 4;
-         }
+         dst += sprintf ((char *) dst, "\\%03o", c);
        else
          *dst++ = c;
       }
@@ -925,16 +914,14 @@ usage: (unibyte-string &rest BYTES)  */)
   (ptrdiff_t n, Lisp_Object *args)
 {
   ptrdiff_t i;
-  unsigned char *buf, *p;
   Lisp_Object str;
   USE_SAFE_ALLOCA;
-
-  SAFE_ALLOCA (buf, unsigned char *, n);
-  p = buf;
+  unsigned char *buf = SAFE_ALLOCA (n);
+  unsigned char *p = buf;
 
   for (i = 0; i < n; i++)
     {
-      CHECK_RANGED_INTEGER (0, args[i], 255);
+      CHECK_RANGED_INTEGER (args[i], 0, 255);
       *p++ = XINT (args[i]);
     }
 
@@ -1017,12 +1004,6 @@ character is not ASCII nor 8-bit character, an error is signaled.  */)
   return make_number (c);
 }
 
-
-void
-init_character_once (void)
-{
-}
-
 #ifdef emacs
 
 void