-
-/* ---------------------------------------------------------------------- */
-/* (A) For working with charptr's (pointers to internally-formatted text) */
-/* ---------------------------------------------------------------------- */
-
-#ifdef MULE
-# define VALID_CHARPTR_P(ptr) BUFBYTE_FIRST_BYTE_P (* (unsigned char *) ptr)
-#else
-# define VALID_CHARPTR_P(ptr) 1
-#endif
-
-#ifdef ERROR_CHECK_BUFPOS
-# define ASSERT_VALID_CHARPTR(ptr) assert (VALID_CHARPTR_P (ptr))
-#else
-# define ASSERT_VALID_CHARPTR(ptr)
-#endif
-
-/* Note that INC_CHARPTR() and DEC_CHARPTR() have to be written in
- completely separate ways. INC_CHARPTR() cannot use the DEC_CHARPTR()
- trick of looking for a valid first byte because it might run off
- the end of the string. DEC_CHARPTR() can't use the INC_CHARPTR()
- method because it doesn't have easy access to the first byte of
- the character it's moving over. */
-
-#define REAL_INC_CHARPTR(ptr) \
- ((void) ((ptr) += REP_BYTES_BY_FIRST_BYTE (* (unsigned char *) (ptr))))
-
-#define REAL_DEC_CHARPTR(ptr) do { \
- (ptr)--; \
-} while (!VALID_CHARPTR_P (ptr))
-
-#ifdef ERROR_CHECK_BUFPOS
-#define INC_CHARPTR(ptr) do { \
- ASSERT_VALID_CHARPTR (ptr); \
- REAL_INC_CHARPTR (ptr); \
-} while (0)
-
-#define DEC_CHARPTR(ptr) do { \
- CONST Bufbyte *dc_ptr1 = (ptr); \
- CONST Bufbyte *dc_ptr2 = dc_ptr1; \
- REAL_DEC_CHARPTR (dc_ptr2); \
- assert (dc_ptr1 - dc_ptr2 == \
- REP_BYTES_BY_FIRST_BYTE (*dc_ptr2)); \
- (ptr) = dc_ptr2; \
-} while (0)
-
-#else /* ! ERROR_CHECK_BUFPOS */
-#define INC_CHARPTR(ptr) REAL_INC_CHARPTR (ptr)
-#define DEC_CHARPTR(ptr) REAL_DEC_CHARPTR (ptr)
-#endif /* ! ERROR_CHECK_BUFPOS */
-
-#ifdef MULE
-
-#define VALIDATE_CHARPTR_BACKWARD(ptr) do { \
- while (!VALID_CHARPTR_P (ptr)) ptr--; \
-} while (0)
-
-/* This needs to be trickier to avoid the possibility of running off
- the end of the string. */
-
-#define VALIDATE_CHARPTR_FORWARD(ptr) do { \
- Bufbyte *vcf_ptr = (ptr); \
- VALIDATE_CHARPTR_BACKWARD (vcf_ptr); \
- if (vcf_ptr != (ptr)) \
- { \
- (ptr) = vcf_ptr; \
- INC_CHARPTR (ptr); \
- } \
-} while (0)
-
-#else /* not MULE */
-#define VALIDATE_CHARPTR_BACKWARD(ptr)
-#define VALIDATE_CHARPTR_FORWARD(ptr)
-#endif /* not MULE */
-
-/* -------------------------------------------------------------- */
-/* (B) For working with the length (in bytes and characters) of a */
-/* section of internally-formatted text */
-/* -------------------------------------------------------------- */
-
-INLINE CONST Bufbyte *charptr_n_addr (CONST Bufbyte *ptr, Charcount offset);
-INLINE CONST Bufbyte *
-charptr_n_addr (CONST Bufbyte *ptr, Charcount offset)
-{
- return ptr + charcount_to_bytecount (ptr, offset);
-}
-
-/* -------------------------------------------------------------------- */
-/* (C) For retrieving or changing the character pointed to by a charptr */
-/* -------------------------------------------------------------------- */
-
-#define simple_charptr_emchar(ptr) ((Emchar) (ptr)[0])
-#define simple_set_charptr_emchar(ptr, x) ((ptr)[0] = (Bufbyte) (x), 1)
-#define simple_charptr_copy_char(ptr, ptr2) ((ptr2)[0] = *(ptr), 1)
-
-#ifdef MULE
-
-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);
-
-INLINE Emchar charptr_emchar (CONST Bufbyte *ptr);
-INLINE 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
-set_charptr_emchar (Bufbyte *ptr, Emchar x)
-{
- return !CHAR_MULTIBYTE_P (x) ?
- simple_set_charptr_emchar (ptr, 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)
-{
- return BYTE_ASCII_P (*ptr) ?
- simple_charptr_copy_char (ptr, ptr2) :
- non_ascii_charptr_copy_char (ptr, ptr2);
-}
-
-#else /* not MULE */
-
-# define charptr_emchar(ptr) simple_charptr_emchar (ptr)
-# define set_charptr_emchar(ptr, x) simple_set_charptr_emchar (ptr, x)
-# define charptr_copy_char(ptr, ptr2) simple_charptr_copy_char (ptr, ptr2)
-
-#endif /* not MULE */
-
-#define charptr_emchar_n(ptr, offset) \
- charptr_emchar (charptr_n_addr (ptr, offset))
-
-
-/* ---------------------------- */
-/* (D) For working with Emchars */
-/* ---------------------------- */
-
-#ifdef MULE
-
-#ifdef UTF2000
-#define valid_char_p(ch) 1
-#else
-int non_ascii_valid_char_p (Emchar ch);
-
-INLINE int valid_char_p (Emchar ch);
-INLINE int
-valid_char_p (Emchar ch)
-{
- return ((unsigned int) (ch) <= 0xff) || non_ascii_valid_char_p (ch);
-}
-#endif
-
-#else /* not MULE */
-
-#define valid_char_p(ch) ((unsigned int) (ch) <= 0xff)
-
-#endif /* not MULE */
-
-#define CHAR_INTP(x) (INTP (x) && valid_char_p (XINT (x)))
-
-#define CHAR_OR_CHAR_INTP(x) (CHARP (x) || CHAR_INTP (x))
-
-#ifdef ERROR_CHECK_TYPECHECK
-
-INLINE Emchar XCHAR_OR_CHAR_INT (Lisp_Object obj);
-INLINE Emchar
-XCHAR_OR_CHAR_INT (Lisp_Object obj)
-{
- assert (CHAR_OR_CHAR_INTP (obj));
- return CHARP (obj) ? XCHAR (obj) : XINT (obj);
-}
-
-#else
-
-#define XCHAR_OR_CHAR_INT(obj) (CHARP ((obj)) ? XCHAR ((obj)) : XINT ((obj)))
-
-#endif
-
-#define CHECK_CHAR_COERCE_INT(x) do { \
- if (CHARP (x)) \
- ; \
- else if (CHAR_INTP (x)) \
- x = make_char (XINT (x)); \
- else \
- x = wrong_type_argument (Qcharacterp, x); \
-} while (0)
-
-#ifdef UTF2000
-# define MAX_EMCHAR_LEN 6
-#else
-#ifdef MULE
-# define MAX_EMCHAR_LEN 4
-#else
-# define MAX_EMCHAR_LEN 1
-#endif
-#endif
-