X-Git-Url: http://git.chise.org/gitweb/?a=blobdiff_plain;f=src%2Fmule-charset.h;h=95ee6f286073f23ed8bbf5b2b384618628f130a8;hb=3227ffc80b8c4875e38f7e9ad5c248c4e2ad2818;hp=c7b669328b42e1ef93bc7b403ea19b2930281cd4;hpb=c8aa261a7bf3eb1389d2e018be1d715f73cacd66;p=chise%2Fxemacs-chise.git- diff --git a/src/mule-charset.h b/src/mule-charset.h index c7b6693..95ee6f2 100644 --- a/src/mule-charset.h +++ b/src/mule-charset.h @@ -324,7 +324,7 @@ Boston, MA 02111-1307, USA. */ /* Definition of leading bytes */ /************************************************************************/ -typedef int Charset_ID; +typedef unsigned char Charset_ID; #define MIN_LEADING_BYTE 0x80 /* These need special treatment in a string and/or character */ @@ -403,19 +403,19 @@ enum LEADING_BYTE_OFFICIAL_2 /* Is this a prefix for a private leading byte? */ -INLINE int LEADING_BYTE_PREFIX_P (unsigned char lb); -INLINE int -LEADING_BYTE_PREFIX_P (unsigned char lb) +INLINE_HEADER int LEADING_BYTE_PREFIX_P (Bufbyte lb); +INLINE_HEADER int +LEADING_BYTE_PREFIX_P (Bufbyte lb) { return (lb == PRE_LEADING_BYTE_PRIVATE_1 || lb == PRE_LEADING_BYTE_PRIVATE_2); } /* Given a private leading byte, return the leading byte prefix stored - in a string */ + in a string. */ #define PRIVATE_LEADING_BYTE_PREFIX(lb) \ - ((lb) < MIN_LEADING_BYTE_PRIVATE_2 ? \ + ((unsigned int) (lb) < MIN_LEADING_BYTE_PRIVATE_2 ? \ PRE_LEADING_BYTE_PRIVATE_1 : \ PRE_LEADING_BYTE_PRIVATE_2) @@ -425,13 +425,12 @@ LEADING_BYTE_PREFIX_P (unsigned char lb) /* of any format */ /************************************************************************/ -/* Argument `c' should be (unsigned int) or (unsigned char). */ -/* Note that SP and DEL are not included. */ +/* 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(c) ((c) < 0x80) -#define BYTE_C0_P(c) ((c) < 0x20) -/* Do some forced casting just to make *sure* things are gotten right. */ -#define BYTE_C1_P(c) ((unsigned int) ((unsigned int) (c) - 0x80) < 0x20) +#define BYTE_ASCII_P(byte) (((byte) & ~0x7f) == 0) +#define BYTE_C0_P(byte) (((byte) & ~0x1f) == 0) +#define BYTE_C1_P(byte) (((byte) & ~0x1f) == 0x80) /************************************************************************/ @@ -439,13 +438,13 @@ LEADING_BYTE_PREFIX_P (unsigned char lb) /* in a Mule-formatted string */ /************************************************************************/ -/* Does this byte represent the first byte of a character? */ +/* Does BYTE represent the first byte of a character? */ -#define BUFBYTE_FIRST_BYTE_P(c) ((c) < 0xA0) +#define BUFBYTE_FIRST_BYTE_P(byte) ((byte) < 0xA0) -/* Does this byte represent the first byte of a multi-byte character? */ +/* Does BYTE represent the first byte of a multi-byte character? */ -#define BUFBYTE_LEADING_BYTE_P(c) BYTE_C1_P (c) +#define BUFBYTE_LEADING_BYTE_P(byte) BYTE_C1_P (byte) /************************************************************************/ @@ -559,33 +558,39 @@ struct charset_lookup { /* Table of charsets indexed by type/final-byte/direction. */ Lisp_Object charset_by_attributes[4][128][2]; + + Charset_ID next_allocated_1_byte_leading_byte; + Charset_ID next_allocated_2_byte_leading_byte; }; -extern struct charset_lookup *chlook; +INLINE_HEADER Lisp_Object CHARSET_BY_LEADING_BYTE (Bufbyte lb); +INLINE_HEADER Lisp_Object +CHARSET_BY_LEADING_BYTE (Bufbyte lb) +{ + extern struct charset_lookup *chlook; #ifdef ERROR_CHECK_TYPECHECK -/* int not Bufbyte even though that is the actual type of a leading byte. - This way, out-ot-range values will get caught rather than automatically - truncated. */ -INLINE Lisp_Object CHARSET_BY_LEADING_BYTE (int lb); -INLINE Lisp_Object -CHARSET_BY_LEADING_BYTE (int lb) -{ - assert (lb >= MIN_LEADING_BYTE && - lb < (MIN_LEADING_BYTE + NUM_LEADING_BYTES)); + /* When error-checking is on, x86 GCC 2.95.2 -O3 miscompiles the + following unless we introduce `tem'. */ + int tem = lb; + type_checking_assert (tem >= MIN_LEADING_BYTE && + tem < (MIN_LEADING_BYTE + NUM_LEADING_BYTES)); +#endif return chlook->charset_by_leading_byte[lb - MIN_LEADING_BYTE]; } -#else - -#define CHARSET_BY_LEADING_BYTE(lb) \ - (chlook->charset_by_leading_byte[(lb) - MIN_LEADING_BYTE]) - -#endif - -#define CHARSET_BY_ATTRIBUTES(type, final, dir) \ - (chlook->charset_by_attributes[type][final][dir]) +INLINE_HEADER Lisp_Object +CHARSET_BY_ATTRIBUTES (unsigned int type, unsigned char final, int dir); +INLINE_HEADER Lisp_Object +CHARSET_BY_ATTRIBUTES (unsigned int type, unsigned char final, int dir) +{ + extern struct charset_lookup *chlook; + type_checking_assert (type < countof (chlook->charset_by_attributes) && + final < countof (chlook->charset_by_attributes[0]) && + dir < countof (chlook->charset_by_attributes[0][0])); + return chlook->charset_by_attributes[type][final][dir]; +} /* Table of number of bytes in the string representation of a character indexed by the first byte of that representation. @@ -596,13 +601,11 @@ CHARSET_BY_LEADING_BYTE (int lb) extern const Bytecount rep_bytes_by_first_byte[0xA0]; /* Number of bytes in the string representation of a character. */ -INLINE int REP_BYTES_BY_FIRST_BYTE (int fb); -INLINE int -REP_BYTES_BY_FIRST_BYTE (int fb) +INLINE_HEADER int REP_BYTES_BY_FIRST_BYTE (Bufbyte fb); +INLINE_HEADER int +REP_BYTES_BY_FIRST_BYTE (Bufbyte fb) { -#ifdef ERROR_CHECK_TYPECHECK - assert (0 <= fb && fb < 0xA0); -#endif + type_checking_assert (fb < 0xA0); return rep_bytes_by_first_byte[fb]; } @@ -675,8 +678,8 @@ REP_BYTES_BY_FIRST_BYTE (int fb) FIELD2_TO_PRIVATE_LEADING_BYTE are the same. */ -INLINE Bufbyte CHAR_LEADING_BYTE (Emchar c); -INLINE Bufbyte +INLINE_HEADER Bufbyte CHAR_LEADING_BYTE (Emchar c); +INLINE_HEADER Bufbyte CHAR_LEADING_BYTE (Emchar c) { if (CHAR_ASCII_P (c)) @@ -710,8 +713,8 @@ CHAR_LEADING_BYTE (Emchar c) FIELD2_TO_PRIVATE_LEADING_BYTE are the same. */ -INLINE Emchar MAKE_CHAR (Lisp_Object charset, int c1, int c2); -INLINE Emchar +INLINE_HEADER Emchar MAKE_CHAR (Lisp_Object charset, int c1, int c2); +INLINE_HEADER Emchar MAKE_CHAR (Lisp_Object charset, int c1, int c2) { if (EQ (charset, Vcharset_ascii)) @@ -748,8 +751,8 @@ MAKE_CHAR (Lisp_Object charset, int c1, int c2) : ((c1) = CHAR_FIELD2 (c), \ (c2) = CHAR_FIELD3 (c)) -INLINE void breakup_char_1 (Emchar c, Lisp_Object *charset, int *c1, int *c2); -INLINE void +INLINE_HEADER void breakup_char_1 (Emchar c, Lisp_Object *charset, int *c1, int *c2); +INLINE_HEADER void breakup_char_1 (Emchar c, Lisp_Object *charset, int *c1, int *c2) { *charset = CHAR_CHARSET (c); @@ -786,9 +789,9 @@ 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, +int copy_internal_to_external (const Bufbyte *internal, Bytecount len, unsigned char *external); -Bytecount copy_external_to_internal (CONST unsigned char *external, +Bytecount copy_external_to_internal (const unsigned char *external, int len, Bufbyte *internal); #endif /* INCLUDED_mule_charset_h_ */