update.
[chise/xemacs-chise.git-] / src / mb-multibyte.h
index 69f137c..f8db3f8 100644 (file)
@@ -24,6 +24,28 @@ Boston, MA 02111-1307, USA.  */
 #ifndef _XEMACS_MB_MULTIBYTE_H
 #define _XEMACS_MB_MULTIBYTE_H
 
+/************************************************************************/
+/*                     Operations on individual bytes                   */
+/*                             of any format                            */
+/************************************************************************/
+
+/* These are carefully designed to work if BYTE is signed or unsigned. */
+/* Note that SPC and DEL are considered ASCII, not control. */
+
+#define BYTE_ASCII_P(byte) (((byte) & ~0x7f) == 0)
+#define BYTE_C0_P(byte)    (((byte) & ~0x1f) == 0)
+#define BYTE_C1_P(byte)    (((byte) & ~0x1f) == 0x80)
+
+
+/************************************************************************/
+/*                        Dealing with characters                       */
+/************************************************************************/
+
+/* Is this character represented by more than one byte in a string? */
+
+#define CHAR_MULTIBYTE_P(c) ((c) >= 0x80)
+
+
 /* ---------------------------------------------------------------------- */
 /* (A) For working with charptr's (pointers to internally-formatted text) */
 /* ---------------------------------------------------------------------- */
@@ -55,21 +77,21 @@ Boston, MA 02111-1307, USA.  */
 #define simple_set_charptr_emchar(ptr, x)      ((ptr)[0] = (Bufbyte) (x), 1)
 #define simple_charptr_copy_char(ptr, ptr2)    ((ptr2)[0] = *(ptr), 1)
 
-Emchar non_ascii_charptr_emchar (CONST Bufbyte *ptr);
+Emchar non_ascii_charptr_emchar (const Bufbyte *ptr);
 Bytecount non_ascii_set_charptr_emchar (Bufbyte *ptr, Emchar c);
-Bytecount non_ascii_charptr_copy_char (CONST Bufbyte *ptr, Bufbyte *ptr2);
+Bytecount non_ascii_charptr_copy_char (const Bufbyte *src, Bufbyte *dst);
 
-INLINE Emchar charptr_emchar (CONST Bufbyte *ptr);
-INLINE Emchar
-charptr_emchar (CONST Bufbyte *ptr)
+INLINE_HEADER Emchar charptr_emchar (const Bufbyte *ptr);
+INLINE_HEADER Emchar
+charptr_emchar (const Bufbyte *ptr)
 {
   return BYTE_ASCII_P (*ptr) ?
     simple_charptr_emchar (ptr) :
     non_ascii_charptr_emchar (ptr);
 }
 
-INLINE Bytecount set_charptr_emchar (Bufbyte *ptr, Emchar x);
-INLINE Bytecount
+INLINE_HEADER Bytecount set_charptr_emchar (Bufbyte *ptr, Emchar x);
+INLINE_HEADER Bytecount
 set_charptr_emchar (Bufbyte *ptr, Emchar x)
 {
   return !CHAR_MULTIBYTE_P (x) ?
@@ -77,13 +99,30 @@ set_charptr_emchar (Bufbyte *ptr, Emchar x)
     non_ascii_set_charptr_emchar (ptr, x);
 }
 
-INLINE Bytecount charptr_copy_char (CONST Bufbyte *ptr, Bufbyte *ptr2);
-INLINE Bytecount
-charptr_copy_char (CONST Bufbyte *ptr, Bufbyte *ptr2)
+/* Copy the character pointed to by SRC into DST.
+   Return the number of bytes copied.  */
+INLINE_HEADER Bytecount
+charptr_copy_char (const Bufbyte *src, Bufbyte *dst);
+INLINE_HEADER Bytecount
+charptr_copy_char (const Bufbyte *src, Bufbyte *dst)
 {
-  return BYTE_ASCII_P (*ptr) ?
-    simple_charptr_copy_char (ptr, ptr2) :
-    non_ascii_charptr_copy_char (ptr, ptr2);
+  return BYTE_ASCII_P (*src) ?
+    simple_charptr_copy_char (src, dst) :
+    non_ascii_charptr_copy_char (src, dst);
 }
 
+
+/************************************************************************/
+/*                            Exported functions                        */
+/************************************************************************/
+
+Emchar Lstream_get_emchar_1 (Lstream *stream, int first_char);
+int Lstream_fput_emchar (Lstream *stream, Emchar ch);
+void Lstream_funget_emchar (Lstream *stream, Emchar ch);
+
+int copy_internal_to_external (const Bufbyte *internal, Bytecount len,
+                              unsigned char *external);
+Bytecount copy_external_to_internal (const unsigned char *external,
+                                    int len, Bufbyte *internal);
+
 #endif /* _XEMACS_MB_MULTIBYTE_H */