1 /* Header for generic multibyte string representation.
2 Copyright (C) 1999 Electrotechnical Laboratory, JAPAN.
3 Licensed to the Free Software Foundation.
5 This file is part of XEmacs.
7 XEmacs is free software; you can redistribute it and/or modify it
8 under the terms of the GNU General Public License as published by the
9 Free Software Foundation; either version 2, or (at your option) any
12 XEmacs is distributed in the hope that it will be useful, but WITHOUT
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
17 You should have received a copy of the GNU General Public License
18 along with XEmacs; see the file COPYING. If not, write to
19 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20 Boston, MA 02111-1307, USA. */
22 /* Rewritten by MORIOKA Tomohiko <tomo@m17n.org>. */
24 #ifndef _XEMACS_MB_MULTIBYTE_H
25 #define _XEMACS_MB_MULTIBYTE_H
27 /************************************************************************/
28 /* Operations on individual bytes */
30 /************************************************************************/
32 /* Argument `c' should be (unsigned int) or (unsigned char). */
33 /* Note that SP and DEL are not included. */
35 #define BYTE_ASCII_P(c) ((c) < 0x80)
36 #define BYTE_C0_P(c) ((c) < 0x20)
37 /* Do some forced casting just to make *sure* things are gotten right. */
38 #define BYTE_C1_P(c) ((unsigned int) ((unsigned int) (c) - 0x80) < 0x20)
41 /* ---------------------------------------------------------------------- */
42 /* (A) For working with charptr's (pointers to internally-formatted text) */
43 /* ---------------------------------------------------------------------- */
45 # define VALID_CHARPTR_P(ptr) BUFBYTE_FIRST_BYTE_P (* (unsigned char *) ptr)
47 #define VALIDATE_CHARPTR_BACKWARD(ptr) do { \
48 while (!VALID_CHARPTR_P (ptr)) ptr--; \
51 /* This needs to be trickier to avoid the possibility of running off
52 the end of the string. */
54 #define VALIDATE_CHARPTR_FORWARD(ptr) do { \
55 Bufbyte *vcf_ptr = (ptr); \
56 VALIDATE_CHARPTR_BACKWARD (vcf_ptr); \
57 if (vcf_ptr != (ptr)) \
64 /* -------------------------------------------------------------------- */
65 /* (C) For retrieving or changing the character pointed to by a charptr */
66 /* -------------------------------------------------------------------- */
68 #define simple_charptr_emchar(ptr) ((Emchar) (ptr)[0])
69 #define simple_set_charptr_emchar(ptr, x) ((ptr)[0] = (Bufbyte) (x), 1)
70 #define simple_charptr_copy_char(ptr, ptr2) ((ptr2)[0] = *(ptr), 1)
72 Emchar non_ascii_charptr_emchar (CONST Bufbyte *ptr);
73 Bytecount non_ascii_set_charptr_emchar (Bufbyte *ptr, Emchar c);
74 Bytecount non_ascii_charptr_copy_char (CONST Bufbyte *ptr, Bufbyte *ptr2);
76 INLINE Emchar charptr_emchar (CONST Bufbyte *ptr);
78 charptr_emchar (CONST Bufbyte *ptr)
80 return BYTE_ASCII_P (*ptr) ?
81 simple_charptr_emchar (ptr) :
82 non_ascii_charptr_emchar (ptr);
85 INLINE Bytecount set_charptr_emchar (Bufbyte *ptr, Emchar x);
87 set_charptr_emchar (Bufbyte *ptr, Emchar x)
89 return !CHAR_MULTIBYTE_P (x) ?
90 simple_set_charptr_emchar (ptr, x) :
91 non_ascii_set_charptr_emchar (ptr, x);
94 INLINE Bytecount charptr_copy_char (CONST Bufbyte *ptr, Bufbyte *ptr2);
96 charptr_copy_char (CONST Bufbyte *ptr, Bufbyte *ptr2)
98 return BYTE_ASCII_P (*ptr) ?
99 simple_charptr_copy_char (ptr, ptr2) :
100 non_ascii_charptr_copy_char (ptr, ptr2);
104 /************************************************************************/
105 /* Exported functions */
106 /************************************************************************/
108 Emchar Lstream_get_emchar_1 (Lstream *stream, int first_char);
109 int Lstream_fput_emchar (Lstream *stream, Emchar ch);
110 void Lstream_funget_emchar (Lstream *stream, Emchar ch);
112 int copy_internal_to_external (CONST Bufbyte *internal, Bytecount len,
113 unsigned char *external);
114 Bytecount copy_external_to_internal (CONST unsigned char *external,
115 int len, Bufbyte *internal);
117 #endif /* _XEMACS_MB_MULTIBYTE_H */