/[emacs]/emacs/src/charset.h
ViewVC logotype

Diff of /emacs/src/charset.h

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 1.75 by handa, Sat May 31 00:10:46 2003 UTC revision 1.75.4.1 by handa, Mon Sep 8 12:48:10 2003 UTC
# Line 1  Line 1 
1  /* Header for multibyte character handler.  /* Header for charset handler.
2     Copyright (C) 1995, 1997, 1998 Electrotechnical Laboratory, JAPAN.     Copyright (C) 1995, 1997, 1998 Electrotechnical Laboratory, JAPAN.
3     Licensed to the Free Software Foundation.       Licensed to the Free Software Foundation.
4     Copyright (C) 2001 Free Software Foundation, Inc.     Copyright (C) 2001 Free Software Foundation, Inc.
5       Copyright (C) 2003
6         National Institute of Advanced Industrial Science and Technology (AIST)
7         Registration Number H13PRO009
8    
9  This file is part of GNU Emacs.  This file is part of GNU Emacs.
10    
# Line 23  Boston, MA 02111-1307, USA.  */ Line 26  Boston, MA 02111-1307, USA.  */
26  #ifndef EMACS_CHARSET_H  #ifndef EMACS_CHARSET_H
27  #define EMACS_CHARSET_H  #define EMACS_CHARSET_H
28    
29  /* #define BYTE_COMBINING_DEBUG */  /* Index to arguments of Fdefine_charset_internal.  */
30    
31  /*** GENERAL NOTE on CHARACTER SET (CHARSET) ***  enum define_charset_arg_index
32      {
33        charset_arg_name,
34        charset_arg_dimension,
35        charset_arg_code_space,
36        charset_arg_min_code,
37        charset_arg_max_code,
38        charset_arg_iso_final,
39        charset_arg_iso_revision,
40        charset_arg_emacs_mule_id,
41        charset_arg_ascii_compatible_p,
42        charset_arg_supplementary_p,
43        charset_arg_invalid_code,
44        charset_arg_code_offset,
45        charset_arg_map,
46        charset_arg_subset,
47        charset_arg_superset,
48        charset_arg_unify_map,
49        charset_arg_plist,
50        charset_arg_max
51      };
52    
53    
54    /* Indices to charset attributes vector.  */
55    
56    enum charset_attr_index
57      {
58        /* ID number of the charset.  */
59        charset_id,
60    
61        /* Name of the charset (symbol).  */
62        charset_name,
63    
64        /* Property list of the charset.  */
65        charset_plist,
66    
67        /* If the method of the charset is `MAP_DEFERRED', the value is a
68           mapping vector or a file name that contains mapping vector.
69           Otherwise, nil.  */
70        charset_map,
71    
72        /* If the method of the charset is `MAP', the value is a vector
73           that maps code points of the charset to characters.  The vector
74           is indexed by a character index.  A character index is
75           calculated from a code point and the code-space table of the
76           charset.  */
77        charset_decoder,
78    
79        /* If the method of the charset is `MAP', the value is a
80           char-table that maps characters of the charset to code
81           points.  */
82        charset_encoder,
83    
84        /* If the method of the charset is `SUBSET', the value is a vector
85           that has this form:
86    
87            [ CHARSET-ID MIN-CODE MAX-CODE OFFSET ]
88    
89           CHARSET-ID is an ID number of a parent charset.  MIN-CODE and
90           MAX-CODE specify the range of characters inherited from the
91           parent.  OFFSET is an integer value to add to a code point of
92           the parent charset to get the corresponding code point of this
93           charset.  */
94        charset_subset,
95    
96        /* If the method of the charset is `SUPERSET', the value is a list
97           whose elements have this form:
98    
99            (CHARSET-ID . OFFSET)
100    
101          CHARSET-IDs are ID numbers of parent charsets.  OFFSET is an
102          integer value to add to a code point of the parent charset to
103          get the corresponding code point of this charset.  */
104        charset_superset,
105    
106        /* The value is a mapping vector or a file name that contains the
107           mapping.  This defines how characters in the charset should be
108           unified with Unicode.  The value of the member
109           `charset_deunifier' is created from this information.  */
110        charset_unify_map,
111    
112        /* If characters in the charset must be unified Unicode, the value
113           is a char table that maps a character code in the charset to
114           the corresponding Unicode character.  */
115        charset_deunifier,
116    
117        /* The length of the charset attribute vector.  */
118        charset_attr_max
119      };
120    
121    /* Methods for converting code points and characters of charsets.  */
122    
123    enum charset_method
124      {
125        /* For a charset of this method, a character code is calculated
126           from a character index (which is calculated from a code point)
127           simply by adding an offset value.  */
128        CHARSET_METHOD_OFFSET,
129    
130        /* For a charset of this method, a decoder vector and an encoder
131           char-table is used for code point <-> character code
132           conversion.  */
133        CHARSET_METHOD_MAP,
134    
135        /* Same as above but decoder and encoder are loaded from a file on
136           demand.  Once loaded, the method is changed to
137           CHARSET_METHOD_MAP.  */
138        CHARSET_METHOD_MAP_DEFERRED,
139    
140        /* A charset of this method is a subset of another charset.  */
141        CHARSET_METHOD_SUBSET,
142    
143        /* A charset of this method is a superset of other charsets.  */
144        CHARSET_METHOD_SUPERSET
145      };
146    
147    struct charset
148    {
149      /* Index to charset_table.  */
150      int id;
151    
152      /* Index to Vcharset_hash_table.  */
153      int hash_index;
154    
155      /* Dimension of the charset: 1, 2, 3, or 4.  */
156      int dimension;
157    
158      /* Byte code range of each dimension.  <code_space>[4N] is a mininum
159         byte code of the (N+1)th dimension, <code_space>[4N+1] is a
160         maximum byte code of the (N+1)th dimension, <code_space>[4N+2] is
161         (<code_space>[4N+1] - <code_space>[4N] + 1), <code_space>[4N+3]
162         is a number of characters containd in the first to (N+1)th
163         dismesions.  We get `char-index' of a `code-point' from this
164         information.  */
165      int code_space[16];
166    
167      /* If B is a byte of Nth dimension of a code-point, the (N-1)th bit
168         of code_space_mask[B] is set.  This array is used to quickly
169         check if a code-point is in a valid range.  */
170      unsigned char *code_space_mask;
171    
172      /* 1 if there's no gap in code-points.  */
173      int code_linear_p;
174    
175      /* If the charset is treated as 94-chars in ISO-2022, the value is 0.
176         If the charset is treated as 96-chars in ISO-2022, the value is 1.  */
177      int iso_chars_96;
178    
179      /* ISO final byte of the charset: 48..127.  It may be -1 if the
180         charset doesn't conform to ISO-2022.  */
181      int iso_final;
182    
183      /* ISO revision number of the charset.  */
184      int iso_revision;
185    
186      /* If the charset is identical to what supported by Emacs 21 and the
187         priors, the identification number of the charset used in those
188         version.  Otherwise, -1.  */
189      int emacs_mule_id;
190    
191      /* Nonzero iff the charset is compatible with ASCII.  */
192      int ascii_compatible_p;
193    
194      /* Nonzero iff the charset is supplementary.  */
195      int supplementary_p;
196    
197      /* Nonzero iff all the code points are representable by Lisp_Int.  */
198      int compact_codes_p;
199    
200      /* The method for encoding/decoding characters of the charset.  */
201      enum charset_method method;
202    
203      /* Mininum and Maximum code points of the charset.  */
204      unsigned min_code, max_code;
205    
206      /* Offset value used by macros CODE_POINT_TO_INDEX and
207          INDEX_TO_CODE_POINT. .  */
208      unsigned char_index_offset;
209    
210      /* Mininum and Maximum character codes of the charset.  If the
211         charset is compatible with ASCII, min_char is a minimum non-ASCII
212         character of the charset.  If the method of charset is
213         CHARSET_METHOD_OFFSET, even if the charset is unified, min_char
214         and max_char doesn't change.  */
215      int min_char, max_char;
216    
217      /* The code returned by ENCODE_CHAR if a character is not encodable
218         by the charset.  */
219      unsigned invalid_code;
220    
221      /* If the method of the charset is CHARSET_METHOD_MAP, this is a
222         table of bits used to quickly and roughly guess if a character
223         belongs to the charset.
224    
225         The first 64 elements are 512 bits for characters less than
226         0x10000.  Each bit corresponds to 128-character block.  The last
227         126 elements are 1008 bits for the greater characters
228         (0x10000..0x3FFFFF).  Each bit corresponds to 4096-character
229         block.
230    
231         If a bit is 1, at least one character in the corresponding block is
232         in this charset.  */
233      unsigned char fast_map[190];
234    
235      /* Offset value to calculate a character code from code-point, and
236         visa versa.  */
237      int code_offset;
238    
239      int unified_p;
240    };
241    
242    /* Hash table of charset symbols vs. the correponding attribute
243       vectors.  */
244    extern Lisp_Object Vcharset_hash_table;
245    
246    /* Table of struct charset.  */
247    extern struct charset *charset_table;
248    extern int charset_table_used;
249    
250    #define CHARSET_FROM_ID(id) (charset_table + (id))
251    
252    extern Lisp_Object Vcharset_ordered_list;
253    
254    /* Incremented everytime we change the priority of charsets.  */
255    extern unsigned short charset_ordered_list_tick;
256    
257    extern Lisp_Object Vcharset_list;
258    extern Lisp_Object Viso_2022_charset_list;
259    extern Lisp_Object Vemacs_mule_charset_list;
260    
261    extern struct charset *emacs_mule_charset[256];
262    
263    
264    /* Macros to access information about charset.  */
265    
266    /* Return the attribute vector of charset whose symbol is SYMBOL.  */
267    #define CHARSET_SYMBOL_ATTRIBUTES(symbol)       \
268      Fgethash ((symbol), Vcharset_hash_table, Qnil)
269    
270    #define CHARSET_ATTR_ID(attrs)          AREF ((attrs), charset_id)
271    #define CHARSET_ATTR_NAME(attrs)        AREF ((attrs), charset_name)
272    #define CHARSET_ATTR_PLIST(attrs)       AREF ((attrs), charset_plist)
273    #define CHARSET_ATTR_MAP(attrs)         AREF ((attrs), charset_map)
274    #define CHARSET_ATTR_DECODER(attrs)     AREF ((attrs), charset_decoder)
275    #define CHARSET_ATTR_ENCODER(attrs)     AREF ((attrs), charset_encoder)
276    #define CHARSET_ATTR_SUBSET(attrs)      AREF ((attrs), charset_subset)
277    #define CHARSET_ATTR_SUPERSET(attrs)    AREF ((attrs), charset_superset)
278    #define CHARSET_ATTR_UNIFY_MAP(attrs)   AREF ((attrs), charset_unify_map)
279    #define CHARSET_ATTR_DEUNIFIER(attrs)   AREF ((attrs), charset_deunifier)
280    
281    #define CHARSET_SYMBOL_ID(symbol)       \
282      CHARSET_ATTR_ID (CHARSET_SYMBOL_ATTRIBUTES (symbol))
283    
284    /* Return an index to Vcharset_hash_table of the charset whose symbol
285       is SYMBOL.  */
286    #define CHARSET_SYMBOL_HASH_INDEX(symbol)       \
287      hash_lookup (XHASH_TABLE (Vcharset_hash_table), symbol, NULL)
288    
289    /* Return the attribute vector of CHARSET.  */
290    #define CHARSET_ATTRIBUTES(charset)     \
291      (HASH_VALUE (XHASH_TABLE (Vcharset_hash_table), (charset)->hash_index))
292    
293    #define CHARSET_ID(charset)             ((charset)->id)
294    #define CHARSET_HASH_INDEX(charset)     ((charset)->hash_index)
295    #define CHARSET_DIMENSION(charset)      ((charset)->dimension)
296    #define CHARSET_CODE_SPACE(charset)     ((charset)->code_space)
297    #define CHARSET_CODE_LINEAR_P(charset)  ((charset)->code_linear_p)
298    #define CHARSET_ISO_CHARS_96(charset)   ((charset)->iso_chars_96)
299    #define CHARSET_ISO_FINAL(charset)      ((charset)->iso_final)
300    #define CHARSET_ISO_PLANE(charset)      ((charset)->iso_plane)
301    #define CHARSET_ISO_REVISION(charset)   ((charset)->iso_revision)
302    #define CHARSET_EMACS_MULE_ID(charset)  ((charset)->emacs_mule_id)
303    #define CHARSET_ASCII_COMPATIBLE_P(charset) ((charset)->ascii_compatible_p)
304    #define CHARSET_COMPACT_CODES_P(charset) ((charset)->compact_codes_p)
305    #define CHARSET_METHOD(charset)         ((charset)->method)
306    #define CHARSET_MIN_CODE(charset)       ((charset)->min_code)
307    #define CHARSET_MAX_CODE(charset)       ((charset)->max_code)
308    #define CHARSET_INVALID_CODE(charset)   ((charset)->invalid_code)
309    #define CHARSET_MIN_CHAR(charset)       ((charset)->min_char)
310    #define CHARSET_MAX_CHAR(charset)       ((charset)->max_char)
311    #define CHARSET_CODE_OFFSET(charset)    ((charset)->code_offset)
312    #define CHARSET_UNIFIED_P(charset)      ((charset)->unified_p)
313    
314    #define CHARSET_NAME(charset)           \
315      (CHARSET_ATTR_NAME (CHARSET_ATTRIBUTES (charset)))
316    #define CHARSET_MAP(charset)    \
317      (CHARSET_ATTR_MAP (CHARSET_ATTRIBUTES (charset)))
318    #define CHARSET_DECODER(charset)        \
319      (CHARSET_ATTR_DECODER (CHARSET_ATTRIBUTES (charset)))
320    #define CHARSET_ENCODER(charset)        \
321      (CHARSET_ATTR_ENCODER (CHARSET_ATTRIBUTES (charset)))
322    #define CHARSET_SUBSET(charset) \
323      (CHARSET_ATTR_SUBSET (CHARSET_ATTRIBUTES (charset)))
324    #define CHARSET_SUPERSET(charset)       \
325      (CHARSET_ATTR_SUPERSET (CHARSET_ATTRIBUTES (charset)))
326    #define CHARSET_UNIFY_MAP(charset)      \
327      (CHARSET_ATTR_UNIFY_MAP (CHARSET_ATTRIBUTES (charset)))
328    #define CHARSET_DEUNIFIER(charset)      \
329      (CHARSET_ATTR_DEUNIFIER (CHARSET_ATTRIBUTES (charset)))
330    
   A character set ("charset" hereafter) is a meaningful collection  
   (i.e. language, culture, functionality, etc) of characters.  Emacs  
   handles multiple charsets at once.  Each charset corresponds to one  
   of the ISO charsets.  Emacs identifies a charset by a unique  
   identification number, whereas ISO identifies a charset by a triplet  
   of DIMENSION, CHARS and FINAL-CHAR.  So, hereafter, just saying  
   "charset" means an identification number (integer value).  
   
   The value range of charsets is 0x00, 0x81..0xFE.  There are four  
   kinds of charset depending on DIMENSION (1 or 2) and CHARS (94 or  
   96).  For instance, a charset of DIMENSION2_CHARS94 contains 94x94  
   characters.  
   
   Within Emacs Lisp, a charset is treated as a symbol which has a  
   property `charset'.  The property value is a vector containing  
   various information about the charset.  For readability of C code,  
   we use the following convention for C variable names:  
         charset_symbol: Emacs Lisp symbol of a charset  
         charset_id: Emacs Lisp integer of an identification number of a charset  
         charset: C integer of an identification number of a charset  
   
   Each charset (except for ascii) is assigned a base leading-code  
   (range 0x80..0x9E).  In addition, a charset of greater than 0xA0  
   (whose base leading-code is 0x9A..0x9D) is assigned an extended  
   leading-code (range 0xA0..0xFE).  In this case, each base  
   leading-code specifies the allowable range of extended leading-code  
   as shown in the table below.  A leading-code is used to represent a  
   character in Emacs' buffer and string.  
   
   We call a charset which has extended leading-code a "private  
   charset" because those are mainly for a charset which is not yet  
   registered by ISO.  On the contrary, we call a charset which does  
   not have extended leading-code an "official charset".  
   
   ---------------------------------------------------------------------------  
   charset       dimension        base leading-code      extended leading-code  
   ---------------------------------------------------------------------------  
   0x00          official dim1    -- none --             -- none --  
                 (ASCII)  
   0x01..0x7F    --never used--  
   0x80          official dim1    -- none --             -- none --  
                 (eight-bit-graphic)  
   0x81..0x8F    official dim1    same as charset        -- none --  
   0x90..0x99    official dim2    same as charset        -- none --  
   0x9A..0x9D    --never used--  
   0x9E          official dim1    same as charset        -- none --  
                 (eight-bit-control)  
   0x9F          --never used--  
   0xA0..0xDF    private dim1        0x9A                same as charset  
                 of 1-column width  
   0xE0..0xEF    private dim1        0x9B                same as charset  
                 of 2-column width  
   0xF0..0xF4    private dim2        0x9C                same as charset  
                 of 1-column width  
   0xF5..0xFE    private dim2        0x9D                same as charset  
                 of 2-column width  
   0xFF          --never used--  
   ---------------------------------------------------------------------------  
   
 */  
   
 /* Definition of special leading-codes.  */  
 /* Leading-code followed by extended leading-code.  */  
 #define LEADING_CODE_PRIVATE_11 0x9A /* for private DIMENSION1 of 1-column */  
 #define LEADING_CODE_PRIVATE_12 0x9B /* for private DIMENSION1 of 2-column */  
 #define LEADING_CODE_PRIVATE_21 0x9C /* for private DIMENSION2 of 1-column */  
 #define LEADING_CODE_PRIVATE_22 0x9D /* for private DIMENSION2 of 2-column */  
   
 #define LEADING_CODE_8_BIT_CONTROL 0x9E /* for `eight-bit-control' */  
   
 /* Extended leading-code.  */  
 /* Start of each extended leading-codes.  */  
 #define LEADING_CODE_EXT_11 0xA0 /* follows LEADING_CODE_PRIVATE_11 */  
 #define LEADING_CODE_EXT_12 0xE0 /* follows LEADING_CODE_PRIVATE_12 */  
 #define LEADING_CODE_EXT_21 0xF0 /* follows LEADING_CODE_PRIVATE_21 */  
 #define LEADING_CODE_EXT_22 0xF5 /* follows LEADING_CODE_PRIVATE_22 */  
 /* Maximum value of extended leading-codes.  */  
 #define LEADING_CODE_EXT_MAX 0xFE  
   
 /* Definition of minimum/maximum charset of each DIMENSION.  */  
 #define MIN_CHARSET_OFFICIAL_DIMENSION1 0x80  
 #define MAX_CHARSET_OFFICIAL_DIMENSION1 0x8F  
 #define MIN_CHARSET_OFFICIAL_DIMENSION2 0x90  
 #define MAX_CHARSET_OFFICIAL_DIMENSION2 0x99  
 #define MIN_CHARSET_PRIVATE_DIMENSION1  LEADING_CODE_EXT_11  
 #define MIN_CHARSET_PRIVATE_DIMENSION2  LEADING_CODE_EXT_21  
   
 /* Maximum value of overall charset identification number.  */  
 #define MAX_CHARSET 0xFE  
   
 /* Definition of special charsets.  */  
 #define CHARSET_ASCII           0       /* 0x00..0x7F */  
 #define CHARSET_8_BIT_CONTROL   0x9E    /* 0x80..0x9F */  
 #define CHARSET_8_BIT_GRAPHIC   0x80    /* 0xA0..0xFF */  
   
 extern int charset_latin_iso8859_1; /* ISO8859-1 (Latin-1) */  
 extern int charset_jisx0208_1978; /* JISX0208.1978 (Japanese Kanji old set) */  
 extern int charset_jisx0208;    /* JISX0208.1983 (Japanese Kanji) */  
 extern int charset_katakana_jisx0201; /* JISX0201.Kana (Japanese Katakana) */  
 extern int charset_latin_jisx0201; /* JISX0201.Roman (Japanese Roman) */  
 extern int charset_big5_1;      /* Big5 Level 1 (Chinese Traditional) */  
 extern int charset_big5_2;      /* Big5 Level 2 (Chinese Traditional) */  
   
 /* Check if CH is an ASCII character or a base leading-code.  
    Nowadays, any byte can be the first byte of a character in a  
    multibyte buffer/string.  So this macro name is not appropriate.  */  
 #define CHAR_HEAD_P(ch) ((unsigned char) (ch) < 0xA0)  
   
 /*** GENERAL NOTE on CHARACTER REPRESENTATION ***  
   
   Firstly, the term "character" or "char" is used for a multilingual  
   character (of course, including ASCII characters), not for a byte in  
   computer memory.  We use the term "code" or "byte" for the latter  
   case.  
   
   A character is identified by charset and one or two POSITION-CODEs.  
   POSITION-CODE is the position of the character in the charset.  A  
   character of DIMENSION1 charset has one POSITION-CODE: POSITION-CODE-1.  
   A character of DIMENSION2 charset has two POSITION-CODE:  
   POSITION-CODE-1 and POSITION-CODE-2.  The code range of  
   POSITION-CODE is 0x20..0x7F.  
   
   Emacs has two kinds of representation of a character: multi-byte  
   form (for buffers and strings) and single-word form (for character  
   objects in Emacs Lisp).  The latter is called "character code"  
   hereafter.  Both representations encode the information of charset  
   and POSITION-CODE but in a different way (for instance, the MSB of  
   POSITION-CODE is set in multi-byte form).  
   
   For details of the multi-byte form, see the section "2. Emacs  
   internal format handlers" of `coding.c'.  
   
   Emacs uses 19 bits for a character code.  The bits are divided into  
   3 fields: FIELD1(5bits):FIELD2(7bits):FIELD3(7bits).  
   
   A character code of DIMENSION1 character uses FIELD2 to hold charset  
   and FIELD3 to hold POSITION-CODE-1.  A character code of DIMENSION2  
   character uses FIELD1 to hold charset, FIELD2 and FIELD3 to hold  
   POSITION-CODE-1 and POSITION-CODE-2 respectively.  
   
   More precisely...  
   
   FIELD2 of DIMENSION1 character (except for ascii, eight-bit-control,  
   and eight-bit-graphic) is "charset - 0x70".  This is to make all  
   character codes except for ASCII and 8-bit codes greater than 256.  
   So, the range of FIELD2 of DIMENSION1 character is 0, 1, or  
   0x11..0x7F.  
   
   FIELD1 of DIMENSION2 character is "charset - 0x8F" for official  
   charset and "charset - 0xE0" for private charset.  So, the range of  
   FIELD1 of DIMENSION2 character is 0x01..0x1E.  
   
   -----------------------------------------------------------------------------  
   charset               FIELD1 (5-bit)      FIELD2 (7-bit)      FIELD3 (7-bit)  
   -----------------------------------------------------------------------------  
   ascii                 0                   0                   0x00..0x7F  
   eight-bit-control     0                   1                   0x00..0x1F  
   eight-bit-graphic     0                   1                   0x20..0x7F  
   DIMENSION1            0                   charset - 0x70      POSITION-CODE-1  
   DIMENSION2(o)         charset - 0x8F      POSITION-CODE-1     POSITION-CODE-2  
   DIMENSION2(p)         charset - 0xE0      POSITION-CODE-1     POSITION-CODE-2  
   -----------------------------------------------------------------------------  
   "(o)": official, "(p)": private  
   -----------------------------------------------------------------------------  
 */  
   
 /* Masks of each field of character code.  */  
 #define CHAR_FIELD1_MASK (0x1F << 14)  
 #define CHAR_FIELD2_MASK (0x7F << 7)  
 #define CHAR_FIELD3_MASK 0x7F  
   
 /* Macros to access each field of character C.  */  
 #define CHAR_FIELD1(c) (((c) & CHAR_FIELD1_MASK) >> 14)  
 #define CHAR_FIELD2(c) (((c) & CHAR_FIELD2_MASK) >> 7)  
 #define CHAR_FIELD3(c) ((c) & CHAR_FIELD3_MASK)  
   
 /* Minimum character code of character of each DIMENSION.  */  
 #define MIN_CHAR_OFFICIAL_DIMENSION1 \  
   ((0x81 - 0x70) << 7)  
 #define MIN_CHAR_PRIVATE_DIMENSION1 \  
   ((MIN_CHARSET_PRIVATE_DIMENSION1 - 0x70) << 7)  
 #define MIN_CHAR_OFFICIAL_DIMENSION2 \  
   ((MIN_CHARSET_OFFICIAL_DIMENSION2 - 0x8F) << 14)  
 #define MIN_CHAR_PRIVATE_DIMENSION2 \  
   ((MIN_CHARSET_PRIVATE_DIMENSION2 - 0xE0) << 14)  
 /* Maximum character code currently used plus 1.  */  
 #define MAX_CHAR (0x1F << 14)  
   
 /* 1 if C is a single byte character, else 0.  */  
 #define SINGLE_BYTE_CHAR_P(c) ((unsigned) (c) < 0x100)  
   
 /* 1 if BYTE is an ASCII character in itself, in multibyte mode.  */  
 #define ASCII_BYTE_P(byte) ((byte) < 0x80)  
   
 /* A char-table containing information on each character set.  
   
    Unlike ordinary char-tables, this doesn't contain any nested tables.  
    Only the top level elements are used.  Each element is a vector of  
    the following information:  
         CHARSET-ID, BYTES, DIMENSION, CHARS, WIDTH, DIRECTION,  
         LEADING-CODE-BASE, LEADING-CODE-EXT,  
         ISO-FINAL-CHAR, ISO-GRAPHIC-PLANE,  
         REVERSE-CHARSET, SHORT-NAME, LONG-NAME, DESCRIPTION,  
         PLIST.  
   
    CHARSET-ID (integer) is the identification number of the charset.  
   
    BYTES (integer) is the length of the multi-byte form of a character  
    in the charset: one of 1, 2, 3, and 4.  
   
    DIMENSION (integer) is the number of bytes to represent a character: 1 or 2.  
   
    CHARS (integer) is the number of characters in a dimension: 94 or 96.  
   
    WIDTH (integer) is the number of columns a character in the charset  
    occupies on the screen: one of 0, 1, and 2..  
   
    DIRECTION (integer) is the rendering direction of characters in the  
    charset when rendering.  If 0, render from left to right, else  
    render from right to left.  
   
    LEADING-CODE-BASE (integer) is the base leading-code for the  
    charset.  
   
    LEADING-CODE-EXT (integer) is the extended leading-code for the  
    charset.  All charsets of less than 0xA0 have the value 0.  
   
    ISO-FINAL-CHAR (character) is the final character of the  
    corresponding ISO 2022 charset.  It is -1 for such a character  
    that is used only internally (e.g. `eight-bit-control').  
   
    ISO-GRAPHIC-PLANE (integer) is the graphic plane to be invoked  
    while encoding to variants of ISO 2022 coding system, one of the  
    following: 0/graphic-plane-left(GL), 1/graphic-plane-right(GR).  It  
    is -1 for such a character that is used only internally  
    (e.g. `eight-bit-control').  
   
    REVERSE-CHARSET (integer) is the charset which differs only in  
    LEFT-TO-RIGHT value from the charset.  If there's no such a  
    charset, the value is -1.  
   
    SHORT-NAME (string) is the short name to refer to the charset.  
   
    LONG-NAME (string) is the long name to refer to the charset.  
   
    DESCRIPTION (string) is the description string of the charset.  
   
    PLIST (property list) may contain any type of information a user  
    wants to put and get by functions `put-charset-property' and  
    `get-charset-property' respectively.  */  
 extern Lisp_Object Vcharset_table;  
   
 /* Macros to access various information of CHARSET in Vcharset_table.  
    We provide these macros for efficiency.  No range check of CHARSET.  */  
   
 /* Return entry of CHARSET (C integer) in Vcharset_table.  */  
 #define CHARSET_TABLE_ENTRY(charset)                                    \  
   XCHAR_TABLE (Vcharset_table)->contents[((charset) == CHARSET_ASCII    \  
                                           ? 0 : (charset) + 128)]  
   
 /* Return information INFO-IDX of CHARSET.  */  
 #define CHARSET_TABLE_INFO(charset, info_idx) \  
   XVECTOR (CHARSET_TABLE_ENTRY (charset))->contents[info_idx]  
   
 #define CHARSET_ID_IDX (0)  
 #define CHARSET_BYTES_IDX (1)  
 #define CHARSET_DIMENSION_IDX (2)  
 #define CHARSET_CHARS_IDX (3)  
 #define CHARSET_WIDTH_IDX (4)  
 #define CHARSET_DIRECTION_IDX (5)  
 #define CHARSET_LEADING_CODE_BASE_IDX (6)  
 #define CHARSET_LEADING_CODE_EXT_IDX (7)  
 #define CHARSET_ISO_FINAL_CHAR_IDX (8)  
 #define CHARSET_ISO_GRAPHIC_PLANE_IDX (9)  
 #define CHARSET_REVERSE_CHARSET_IDX (10)  
 #define CHARSET_SHORT_NAME_IDX (11)  
 #define CHARSET_LONG_NAME_IDX (12)  
 #define CHARSET_DESCRIPTION_IDX (13)  
 #define CHARSET_PLIST_IDX (14)  
 /* Size of a vector of each entry of Vcharset_table.  */  
 #define CHARSET_MAX_IDX (15)  
   
 /* And several more macros to be used frequently.  */  
 #define CHARSET_BYTES(charset) \  
   XFASTINT (CHARSET_TABLE_INFO (charset, CHARSET_BYTES_IDX))  
 #define CHARSET_DIMENSION(charset) \  
   XFASTINT (CHARSET_TABLE_INFO (charset, CHARSET_DIMENSION_IDX))  
 #define CHARSET_CHARS(charset) \  
   XFASTINT (CHARSET_TABLE_INFO (charset, CHARSET_CHARS_IDX))  
 #define CHARSET_WIDTH(charset) \  
   XFASTINT (CHARSET_TABLE_INFO (charset, CHARSET_WIDTH_IDX))  
 #define CHARSET_DIRECTION(charset) \  
   XFASTINT (CHARSET_TABLE_INFO (charset, CHARSET_DIRECTION_IDX))  
 #define CHARSET_LEADING_CODE_BASE(charset) \  
   XFASTINT (CHARSET_TABLE_INFO (charset, CHARSET_LEADING_CODE_BASE_IDX))  
 #define CHARSET_LEADING_CODE_EXT(charset) \  
   XFASTINT (CHARSET_TABLE_INFO (charset, CHARSET_LEADING_CODE_EXT_IDX))  
 #define CHARSET_ISO_FINAL_CHAR(charset) \  
   XINT (CHARSET_TABLE_INFO (charset, CHARSET_ISO_FINAL_CHAR_IDX))  
 #define CHARSET_ISO_GRAPHIC_PLANE(charset) \  
   XINT (CHARSET_TABLE_INFO (charset, CHARSET_ISO_GRAPHIC_PLANE_IDX))  
 #define CHARSET_REVERSE_CHARSET(charset) \  
   XINT (CHARSET_TABLE_INFO (charset, CHARSET_REVERSE_CHARSET_IDX))  
   
 /* Macros to specify direction of a charset.  */  
 #define CHARSET_DIRECTION_LEFT_TO_RIGHT 0  
 #define CHARSET_DIRECTION_RIGHT_TO_LEFT 1  
   
 /* A vector of charset symbol indexed by charset-id.  This is used  
    only for returning charset symbol from C functions.  */  
 extern Lisp_Object Vcharset_symbol_table;  
   
 /* Return symbol of CHARSET.  */  
 #define CHARSET_SYMBOL(charset) \  
   XVECTOR (Vcharset_symbol_table)->contents[charset]  
   
 /* 1 if CHARSET is in valid value range, else 0.  */  
 #define CHARSET_VALID_P(charset)                                         \  
   ((charset) == 0                                                        \  
    || ((charset) > 0x80 && (charset) <= MAX_CHARSET_OFFICIAL_DIMENSION2) \  
    || ((charset) >= MIN_CHARSET_PRIVATE_DIMENSION1                       \  
        && (charset) <= MAX_CHARSET)                                      \  
    || ((charset) == CHARSET_8_BIT_CONTROL)                               \  
    || ((charset) == CHARSET_8_BIT_GRAPHIC))  
   
 /* 1 if CHARSET is already defined, else 0.  */  
 #define CHARSET_DEFINED_P(charset)                      \  
   (((charset) >= 0) && ((charset) <= MAX_CHARSET)       \  
    && !NILP (CHARSET_TABLE_ENTRY (charset)))  
   
 /* Since the information CHARSET-BYTES and CHARSET-WIDTH of  
    Vcharset_table can be retrieved only by the first byte of  
    multi-byte form (an ASCII code or a base leading-code), we provide  
    here tables to be used by macros BYTES_BY_CHAR_HEAD and  
    WIDTH_BY_CHAR_HEAD for faster information retrieval.  */  
 extern int bytes_by_char_head[256];  
 extern int width_by_char_head[256];  
   
 #define BYTES_BY_CHAR_HEAD(char_head)   \  
   (ASCII_BYTE_P (char_head) ? 1 : bytes_by_char_head[char_head])  
 #define WIDTH_BY_CHAR_HEAD(char_head)   \  
   (ASCII_BYTE_P (char_head) ? 1 : width_by_char_head[char_head])  
   
 /* Charset of the character C.  */  
 #define CHAR_CHARSET(c)                                                 \  
   (SINGLE_BYTE_CHAR_P (c)                                               \  
    ? (ASCII_BYTE_P (c)                                                  \  
       ? CHARSET_ASCII                                                   \  
       : (c) < 0xA0 ? CHARSET_8_BIT_CONTROL : CHARSET_8_BIT_GRAPHIC)     \  
    : ((c) < MIN_CHAR_OFFICIAL_DIMENSION2                                \  
       ? CHAR_FIELD2 (c) + 0x70                                          \  
       : ((c) < MIN_CHAR_PRIVATE_DIMENSION2                              \  
          ? CHAR_FIELD1 (c) + 0x8F                                       \  
          : CHAR_FIELD1 (c) + 0xE0)))  
331    
332  /* Check if two characters C1 and C2 belong to the same charset.  */  /* Nonzero iff OBJ is a valid charset symbol.  */
333  #define SAME_CHARSET_P(c1, c2)                          \  #define CHARSETP(obj) (CHARSET_SYMBOL_HASH_INDEX (obj) >= 0)
   (c1 < MIN_CHAR_OFFICIAL_DIMENSION2                    \  
    ? (c1 & CHAR_FIELD2_MASK) == (c2 & CHAR_FIELD2_MASK) \  
    : (c1 & CHAR_FIELD1_MASK) == (c2 & CHAR_FIELD1_MASK))  
   
 /* Return a character of which charset is CHARSET and position-codes  
    are C1 and C2.  DIMENSION1 character ignores C2.  */  
 #define MAKE_CHAR(charset, c1, c2)                                          \  
   ((charset) == CHARSET_ASCII                                               \  
    ? (c1) & 0x7F                                                            \  
    : (((charset) == CHARSET_8_BIT_CONTROL                                   \  
        || (charset) == CHARSET_8_BIT_GRAPHIC)                               \  
       ? ((c1) & 0x7F) | 0x80                                                \  
       : ((CHARSET_DEFINED_P (charset)                                       \  
           ? CHARSET_DIMENSION (charset) == 1                                \  
           : (charset) < MIN_CHARSET_PRIVATE_DIMENSION2)                     \  
          ? (((charset) - 0x70) << 7) | ((c1) <= 0 ? 0 : ((c1) & 0x7F))      \  
          : ((((charset)                                                     \  
               - ((charset) < MIN_CHARSET_PRIVATE_DIMENSION2 ? 0x8F : 0xE0)) \  
              << 14)                                                         \  
             | ((c2) <= 0 ? 0 : ((c2) & 0x7F))                               \  
             | ((c1) <= 0 ? 0 : (((c1) & 0x7F) << 7))))))  
   
   
 /* If GENERICP is nonzero, return nonzero iff C is a valid normal or  
    generic character.  If GENERICP is zero, return nonzero iff C is a  
    valid normal character.  */  
 #define CHAR_VALID_P(c, genericp)       \  
   ((c) >= 0                             \  
    && (SINGLE_BYTE_CHAR_P (c) || char_valid_p (c, genericp)))  
   
 /* This default value is used when nonascii-translation-table or  
    nonascii-insert-offset fail to convert unibyte character to a valid  
    multibyte character.  This makes a Latin-1 character.  */  
   
 #define DEFAULT_NONASCII_INSERT_OFFSET 0x800  
   
 /* Parse multibyte string STR of length LENGTH and set BYTES to the  
    byte length of a character at STR.  */  
334    
335  #ifdef BYTE_COMBINING_DEBUG  /* Check if X is a valid charset symbol.  If not, signal an error.  */
336    #define CHECK_CHARSET(x)                                        \
 #define PARSE_MULTIBYTE_SEQ(str, length, bytes)                 \  
337    do {                                                          \    do {                                                          \
338      int i = 1;                                                  \      if (! SYMBOLP (x) || CHARSET_SYMBOL_HASH_INDEX (x) < 0)     \
339      while (i < (length) && ! CHAR_HEAD_P ((str)[i])) i++;       \        x = wrong_type_argument (Qcharsetp, (x));                 \
     (bytes) = BYTES_BY_CHAR_HEAD ((str)[0]);                    \  
     if ((bytes) > i)                                            \  
       abort ();                                                 \  
340    } while (0)    } while (0)
341    
 #else  /* not BYTE_COMBINING_DEBUG */  
   
 #define PARSE_MULTIBYTE_SEQ(str, length, bytes) \  
   ((void)(length), (bytes) = BYTES_BY_CHAR_HEAD ((str)[0]))  
   
 #endif /* not BYTE_COMBINING_DEBUG */  
   
 #define VALID_LEADING_CODE_P(code)      \  
   (! NILP (CHARSET_TABLE_ENTRY (code)))  
   
 /* Return 1 iff the byte sequence at unibyte string STR (LENGTH bytes)  
    is valid as a multibyte form.  If valid, by a side effect, BYTES is  
    set to the byte length of the multibyte form.  */  
   
 #define UNIBYTE_STR_AS_MULTIBYTE_P(str, length, bytes)          \  
   (((str)[0] < 0x80 || (str)[0] >= 0xA0)                        \  
    ? ((bytes) = 1)                                              \  
    : (((bytes) = BYTES_BY_CHAR_HEAD ((str)[0])),                \  
       ((bytes) <= (length)                                      \  
        && !CHAR_HEAD_P ((str)[1])                               \  
        && ((bytes) == 2                                         \  
            ? (str)[0] != LEADING_CODE_8_BIT_CONTROL             \  
            : (!CHAR_HEAD_P ((str)[2])                           \  
               && ((bytes) == 3                                  \  
                   ? (((str)[0] != LEADING_CODE_PRIVATE_11       \  
                       && (str)[0] != LEADING_CODE_PRIVATE_12)   \  
                      || VALID_LEADING_CODE_P (str[1]))          \  
                   : (!CHAR_HEAD_P ((str)[3])                    \  
                      && VALID_LEADING_CODE_P (str[1]))))))))  
   
   
 /* Return 1 iff the byte sequence at multibyte string STR is valid as  
    a unibyte form.  By a side effect, BYTES is set to the byte length  
    of one character at STR.  */  
   
 #define MULTIBYTE_STR_AS_UNIBYTE_P(str, bytes)  \  
   ((bytes) = BYTES_BY_CHAR_HEAD ((str)[0]),     \  
    (str)[0] != LEADING_CODE_8_BIT_CONTROL)  
   
 /* The charset of character C is stored in CHARSET, and the  
    position-codes of C are stored in C1 and C2.  
    We store -1 in C2 if the dimension of the charset is 1.  */  
   
 #define SPLIT_CHAR(c, charset, c1, c2)                                      \  
   (SINGLE_BYTE_CHAR_P (c)                                                   \  
    ? ((charset                                                              \  
        = (ASCII_BYTE_P (c)                                                  \  
           ? CHARSET_ASCII                                                   \  
           : ((c) < 0xA0 ? CHARSET_8_BIT_CONTROL : CHARSET_8_BIT_GRAPHIC))), \  
       c1 = (c), c2 = -1)                                                    \  
    : ((c) & CHAR_FIELD1_MASK                                                \  
       ? (charset = (CHAR_FIELD1 (c)                                         \  
                     + ((c) < MIN_CHAR_PRIVATE_DIMENSION2 ? 0x8F : 0xE0)),   \  
          c1 = CHAR_FIELD2 (c),                                              \  
          c2 = CHAR_FIELD3 (c))                                              \  
       : (charset = CHAR_FIELD2 (c) + 0x70,                                  \  
          c1 = CHAR_FIELD3 (c),                                              \  
          c2 = -1)))  
   
 /* Return 1 iff character C has valid printable glyph.  */  
 #define CHAR_PRINTABLE_P(c) (ASCII_BYTE_P (c) || char_printable_p (c))  
   
 /* The charset of the character at STR is stored in CHARSET, and the  
    position-codes are stored in C1 and C2.  
    We store -1 in C2 if the character is just 2 bytes.  */  
   
 #define SPLIT_STRING(str, len, charset, c1, c2)                 \  
   ((BYTES_BY_CHAR_HEAD ((unsigned char) *(str)) < 2             \  
     || BYTES_BY_CHAR_HEAD ((unsigned char) *(str)) > len        \  
     || split_string (str, len, &charset, &c1, &c2) < 0)         \  
    ? c1 = *(str), charset = CHARSET_ASCII                       \  
    : charset)  
   
 /* Mapping table from ISO2022's charset (specified by DIMENSION,  
    CHARS, and FINAL_CHAR) to Emacs' charset.  Should be accessed by  
    macro ISO_CHARSET_TABLE (DIMENSION, CHARS, FINAL_CHAR).  */  
 extern int iso_charset_table[2][2][128];  
   
 #define ISO_CHARSET_TABLE(dimension, chars, final_char) \  
   iso_charset_table[XINT (dimension) - 1][XINT (chars) > 94][XINT (final_char)]  
   
 #define BASE_LEADING_CODE_P(c) (BYTES_BY_CHAR_HEAD ((unsigned char) (c)) > 1)  
342    
343  /* Return how many bytes C will occupy in a multibyte buffer.  */  /* Check if X is a valid charset symbol.  If valid, set ID to the id
344  #define CHAR_BYTES(c)                                   \     number of the charset.  Otherwise, signal an error. */
345    (SINGLE_BYTE_CHAR_P (c)                               \  #define CHECK_CHARSET_GET_ID(x, id)                                     \
346     ? ((ASCII_BYTE_P (c) || (c) >= 0xA0) ? 1 : 2)        \    do {                                                                  \
347     : char_bytes (c))      int idx;                                                            \
348                                                                            \
349  /* The following two macros CHAR_STRING and STRING_CHAR are the main      if (! SYMBOLP (x) || (idx = CHARSET_SYMBOL_HASH_INDEX (x)) < 0)     \
350     entry points to convert between Emacs's two types of character        x = wrong_type_argument (Qcharsetp, (x));                         \
351     representations: multi-byte form and single-word form (character      id = XINT (AREF (HASH_VALUE (XHASH_TABLE (Vcharset_hash_table), idx), \
352     code).  */                       charset_id));                                      \
   
 /* Store multi-byte form of the character C in STR.  The caller should  
    allocate at least MAX_MULTIBYTE_LENGTH bytes area at STR in  
    advance.  Returns the length of the multi-byte form.  If C is an  
    invalid character code, signal an error.  */  
   
 #define CHAR_STRING(c, str)                                               \  
   (SINGLE_BYTE_CHAR_P (c)                                                 \  
    ? ((ASCII_BYTE_P (c) || c >= 0xA0)                                     \  
       ? (*(str) = (unsigned char)(c), 1)                                  \  
       : (*(str) = LEADING_CODE_8_BIT_CONTROL, *((str)+ 1) = c + 0x20, 2)) \  
    : char_to_string (c, (unsigned char *) str))  
   
 /* Like CHAR_STRING but don't signal an error if C is invalid.  
    Value is -1 in this case.  */  
   
 #define CHAR_STRING_NO_SIGNAL(c, str)                                     \  
   (SINGLE_BYTE_CHAR_P (c)                                                 \  
    ? ((ASCII_BYTE_P (c) || c >= 0xA0)                                     \  
       ? (*(str) = (unsigned char)(c), 1)                                  \  
       : (*(str) = LEADING_CODE_8_BIT_CONTROL, *((str)+ 1) = c + 0x20, 2)) \  
    : char_to_string_1 (c, (unsigned char *) str))  
   
 /* Return a character code of the character of which multi-byte form  
    is at STR and the length is LEN.  If STR doesn't contain valid  
    multi-byte form, only the first byte in STR is returned.  */  
   
 #define STRING_CHAR(str, len)                           \  
   (BYTES_BY_CHAR_HEAD ((unsigned char) *(str)) == 1     \  
    ? (unsigned char) *(str)                             \  
    : string_to_char (str, len, 0))  
   
 /* This is like STRING_CHAR but the third arg ACTUAL_LEN is set to the  
    length of the multi-byte form.  Just to know the length, use  
    MULTIBYTE_FORM_LENGTH.  */  
   
 #define STRING_CHAR_AND_LENGTH(str, len, actual_len)    \  
   (BYTES_BY_CHAR_HEAD ((unsigned char) *(str)) == 1     \  
    ? ((actual_len) = 1), (unsigned char) *(str)         \  
    : string_to_char (str, len, &(actual_len)))  
   
 /* Fetch the "next" character from Lisp string STRING at byte position  
    BYTEIDX, character position CHARIDX.  Store it into OUTPUT.  
   
    All the args must be side-effect-free.  
    BYTEIDX and CHARIDX must be lvalues;  
    we increment them past the character fetched.  */  
   
 #define FETCH_STRING_CHAR_ADVANCE(OUTPUT, STRING, CHARIDX, BYTEIDX)        \  
 if (1)                                                                     \  
   {                                                                        \  
     CHARIDX++;                                                             \  
     if (STRING_MULTIBYTE (STRING))                                         \  
       {                                                                    \  
         const unsigned char *ptr = SDATA (STRING) + BYTEIDX;               \  
         int space_left = SBYTES (STRING) - BYTEIDX;                        \  
         int actual_len;                                                    \  
                                                                            \  
         OUTPUT = STRING_CHAR_AND_LENGTH (ptr, space_left, actual_len);     \  
         BYTEIDX += actual_len;                                             \  
       }                                                                    \  
     else                                                                   \  
       OUTPUT = SREF (STRING, BYTEIDX++);                                   \  
   }                                                                        \  
 else  
   
 /* Like FETCH_STRING_CHAR_ADVANCE but assume STRING is multibyte.  */  
   
 #define FETCH_STRING_CHAR_ADVANCE_NO_CHECK(OUTPUT, STRING, CHARIDX, BYTEIDX)  \  
 if (1)                                                                        \  
   {                                                                           \  
     const unsigned char *fetch_string_char_ptr = SDATA (STRING) + BYTEIDX;    \  
     int fetch_string_char_space_left = SBYTES (STRING) - BYTEIDX;             \  
     int actual_len;                                                           \  
                                                                               \  
     OUTPUT                                                                    \  
       = STRING_CHAR_AND_LENGTH (fetch_string_char_ptr,                        \  
                                 fetch_string_char_space_left, actual_len);    \  
                                                                               \  
     BYTEIDX += actual_len;                                                    \  
     CHARIDX++;                                                                \  
   }                                                                           \  
 else  
   
 /* Like FETCH_STRING_CHAR_ADVANCE but fetch character from the current  
    buffer.  */  
   
 #define FETCH_CHAR_ADVANCE(OUTPUT, CHARIDX, BYTEIDX)                      \  
 if (1)                                                                    \  
   {                                                                       \  
     CHARIDX++;                                                            \  
     if (!NILP (current_buffer->enable_multibyte_characters))              \  
       {                                                                   \  
         unsigned char *ptr = BYTE_POS_ADDR (BYTEIDX);                     \  
         int space_left = ((CHARIDX < GPT ? GPT_BYTE : Z_BYTE) - BYTEIDX); \  
         int actual_len;                                                   \  
                                                                           \  
         OUTPUT= STRING_CHAR_AND_LENGTH (ptr, space_left, actual_len);     \  
         BYTEIDX += actual_len;                                            \  
       }                                                                   \  
     else                                                                  \  
       {                                                                   \  
         OUTPUT = *(BYTE_POS_ADDR (BYTEIDX));                              \  
         BYTEIDX++;                                                        \  
       }                                                                   \  
   }                                                                       \  
 else  
   
 /* Return the length of the multi-byte form at string STR of length LEN.  */  
   
 #define MULTIBYTE_FORM_LENGTH(str, len)                 \  
   (BYTES_BY_CHAR_HEAD (*(unsigned char *)(str)) == 1    \  
    ? 1                                                  \  
    : multibyte_form_length (str, len))  
   
 /* If P is before LIMIT, advance P to the next character boundary.  It  
    assumes that P is already at a character boundary of the sane  
    mulitbyte form whose end address is LIMIT.  */  
   
 #define NEXT_CHAR_BOUNDARY(p, limit)    \  
   do {                                  \  
     if ((p) < (limit))                  \  
       (p) += BYTES_BY_CHAR_HEAD (*(p)); \  
353    } while (0)    } while (0)
354    
355    
356  /* If P is after LIMIT, advance P to the previous character boundary.  /* Check if X is a valid charset symbol.  If valid, set ATTR to the
357     It assumes that P is already at a character boundary of the sane     attr vector of the charset.  Otherwise, signal an error. */
358     mulitbyte form whose beginning address is LIMIT.  */  #define CHECK_CHARSET_GET_ATTR(x, attr)                         \
   
 #define PREV_CHAR_BOUNDARY(p, limit)                                    \  
359    do {                                                                  \    do {                                                                  \
360      if ((p) > (limit))                                                  \      if (!SYMBOLP (x) || NILP (attr = CHARSET_SYMBOL_ATTRIBUTES (x)))    \
361        {                                                                 \        x = wrong_type_argument (Qcharsetp, (x));                         \
         const unsigned char *p0 = (p);                                  \  
         do {                                                            \  
           p0--;                                                         \  
         } while (p0 >= limit && ! CHAR_HEAD_P (*p0));                   \  
         (p) = (BYTES_BY_CHAR_HEAD (*p0) == (p) - p0) ? p0 : (p) - 1;    \  
       }                                                                 \  
362    } while (0)    } while (0)
363    
364    
365  #ifdef emacs  #define CHECK_CHARSET_GET_CHARSET(x, charset)   \
366      do {                                          \
367  /* Increase the buffer byte position POS_BYTE of the current buffer to      int id;                                     \
368     the next character boundary.  This macro relies on the fact that      CHECK_CHARSET_GET_ID (x, id);               \
369     *GPT_ADDR and *Z_ADDR are always accessible and the values are      charset = CHARSET_FROM_ID (id);             \
    '\0'.  No range checking of POS.  */  
   
 #ifdef BYTE_COMBINING_DEBUG  
   
 #define INC_POS(pos_byte)                               \  
   do {                                                  \  
     unsigned char *p = BYTE_POS_ADDR (pos_byte);        \  
     if (BASE_LEADING_CODE_P (*p))                       \  
       {                                                 \  
         int len, bytes;                                 \  
         len = Z_BYTE - pos_byte;                        \  
         PARSE_MULTIBYTE_SEQ (p, len, bytes);            \  
         pos_byte += bytes;                              \  
       }                                                 \  
     else                                                \  
       pos_byte++;                                       \  
370    } while (0)    } while (0)
371    
 #else  /* not BYTE_COMBINING_DEBUG */  
372    
373  #define INC_POS(pos_byte)                               \  /* Lookup Vcharset_order_list and return the first charset that
374    do {                                                  \     contains the character C.  */
375      unsigned char *p = BYTE_POS_ADDR (pos_byte);        \  #define CHAR_CHARSET(c) \
376      pos_byte += BYTES_BY_CHAR_HEAD (*p);                \    char_charset ((c), Qnil, NULL)
377    } while (0)  
378    #if 0
379    /* Char-table of charset-sets.  Each element is a bool vector indexed
380       by a charset ID.  */
381    extern Lisp_Object Vchar_charset_set;
382    
383    /* Charset-bag of character C.  */
384    #define CHAR_CHARSET_SET(c) \
385      CHAR_TABLE_REF (Vchar_charset_set, c)
386    
387  #endif /* not BYTE_COMBINING_DEBUG */  /* Check if two characters C1 and C2 belong to the same charset.  */
388    #define SAME_CHARSET_P(c1, c2)  \
389      intersection_p (CHAR_CHARSET_SET (c1), CHAR_CHARSET_SET (c2))
390    
391  /* Decrease the buffer byte position POS_BYTE of the current buffer to  #endif
    the previous character boundary.  No range checking of POS.  */  
 #define DEC_POS(pos_byte)                                               \  
   do {                                                                  \  
     unsigned char *p, *p_min;                                           \  
                                                                         \  
     pos_byte--;                                                         \  
     if (pos_byte < GPT_BYTE)                                            \  
       p = BEG_ADDR + pos_byte - BEG_BYTE, p_min = BEG_ADDR;             \  
     else                                                                \  
       p = BEG_ADDR + GAP_SIZE + pos_byte - BEG_BYTE, p_min = GAP_END_ADDR;\  
     if (p > p_min && !CHAR_HEAD_P (*p))                                 \  
       {                                                                 \  
         unsigned char *pend = p--;                                      \  
         int len, bytes;                                                 \  
         if (p_min < p - MAX_MULTIBYTE_LENGTH)                           \  
           p_min = p - MAX_MULTIBYTE_LENGTH;                             \  
         while (p > p_min && !CHAR_HEAD_P (*p)) p--;                     \  
         len = pend + 1 - p;                                             \  
         PARSE_MULTIBYTE_SEQ (p, len, bytes);                            \  
         if (bytes == len)                                               \  
           pos_byte -= len - 1;                                          \  
       }                                                                 \  
   } while (0)  
392    
 /* Increment both CHARPOS and BYTEPOS, each in the appropriate way.  */  
393    
394  #define INC_BOTH(charpos, bytepos)                              \  /* Return a character correponding to the code-point CODE of CHARSET.
395  do                                                              \     Try some optimization before calling decode_char.  */
   {                                                             \  
     (charpos)++;                                                \  
     if (NILP (current_buffer->enable_multibyte_characters))     \  
       (bytepos)++;                                              \  
     else                                                        \  
       INC_POS ((bytepos));                                      \  
   }                                                             \  
 while (0)  
   
 /* Decrement both CHARPOS and BYTEPOS, each in the appropriate way.  */  
   
 #define DEC_BOTH(charpos, bytepos)                              \  
 do                                                              \  
   {                                                             \  
     (charpos)--;                                                \  
     if (NILP (current_buffer->enable_multibyte_characters))     \  
       (bytepos)--;                                              \  
     else                                                        \  
       DEC_POS ((bytepos));                                      \  
   }                                                             \  
 while (0)  
   
 /* Increase the buffer byte position POS_BYTE of the current buffer to  
    the next character boundary.  This macro relies on the fact that  
    *GPT_ADDR and *Z_ADDR are always accessible and the values are  
    '\0'.  No range checking of POS_BYTE.  */  
396    
397  #ifdef BYTE_COMBINING_DEBUG  #define DECODE_CHAR(charset, code)                                      \
398      ((ASCII_BYTE_P (code) && (charset)->ascii_compatible_p)               \
399       ? (code)                                                             \
400       : ((code) < (charset)->min_code || (code) > (charset)->max_code)     \
401       ? -1                                                                 \
402       : (charset)->unified_p                                               \
403       ? decode_char ((charset), (code))                                    \
404       : (charset)->method == CHARSET_METHOD_OFFSET                         \
405       ? ((charset)->code_linear_p                                          \
406          ? (code) - (charset)->min_code + (charset)->code_offset           \
407          : decode_char ((charset), (code)))                                \
408       : (charset)->method == CHARSET_METHOD_MAP                            \
409       ? ((charset)->code_linear_p                                          \
410          ? XINT (AREF (CHARSET_DECODER (charset),                          \
411                            (code) - (charset)->min_code))                  \
412          : decode_char ((charset), (code)))                                \
413       : decode_char ((charset), (code)))
414    
415    
416    extern Lisp_Object charset_work;
417    
418    /* Return a code point of CHAR in CHARSET.
419       Try some optimization before calling encode_char.  */
420    
421    #define ENCODE_CHAR(charset, c)                                          \
422      ((ASCII_CHAR_P (c) && (charset)->ascii_compatible_p)                   \
423       ? (c)                                                                 \
424       : ((charset)->unified_p                                               \
425          || (charset)->method == CHARSET_METHOD_SUBSET                      \
426          || (charset)->method == CHARSET_METHOD_SUPERSET)                   \
427       ? encode_char ((charset), (c))                                        \
428       : ((c) < (charset)->min_char || (c) > (charset)->max_char)            \
429       ? (charset)->invalid_code                                             \
430       : (charset)->method == CHARSET_METHOD_OFFSET                          \
431       ? ((charset)->code_linear_p                                           \
432          ? (c) - (charset)->code_offset + (charset)->min_code               \
433          : encode_char ((charset), (c)))                                    \
434       : (charset)->method == CHARSET_METHOD_MAP                             \
435       ? ((charset)->compact_codes_p                                         \
436          ? (charset_work = CHAR_TABLE_REF (CHARSET_ENCODER (charset), (c)), \
437             (NILP (charset_work)                                            \
438              ? (charset)->invalid_code                                      \
439              : XFASTINT (charset_work)))                                    \
440          : encode_char ((charset), (c)))                                    \
441       : encode_char ((charset), (c)))
442    
443    
444    /* Set to 1 when a charset map is loaded to warn that a buffer text
445       and a string data may be relocated.  */
446    extern int charset_map_loaded;
447    
448    
449    /* Set CHARSET to the charset highest priority of C, CODE to the
450       code-point of C in CHARSET.  */
451    #define SPLIT_CHAR(c, charset, code)    \
452      ((charset) = char_charset ((c), Qnil, &(code)))
453    
454    
455    #define ISO_MAX_DIMENSION 3
456    #define ISO_MAX_CHARS 2
457    #define ISO_MAX_FINAL 0x80      /* only 0x30..0xFF are used */
458    
459  #define BUF_INC_POS(buf, pos_byte)                              \  /* Mapping table from ISO2022's charset (specified by DIMENSION,
460    do {                                                          \     CHARS, and FINAL_CHAR) to Emacs' charset ID.  Should be accessed by
461      unsigned char *p = BUF_BYTE_ADDRESS (buf, pos_byte);        \     macro ISO_CHARSET_TABLE (DIMENSION, CHARS, FINAL_CHAR).  */
462      if (BASE_LEADING_CODE_P (*p))                               \  extern int iso_charset_table[ISO_MAX_DIMENSION][ISO_MAX_CHARS][ISO_MAX_FINAL];
       {                                                         \  
         int len, bytes;                                         \  
         len = BUF_Z_BYTE (buf) - pos_byte;                      \  
         PARSE_MULTIBYTE_SEQ (p, len, bytes);                    \  
         pos_byte += bytes;                                      \  
       }                                                         \  
     else                                                        \  
       pos_byte++;                                               \  
   } while (0)  
463    
464  #else  /* not BYTE_COMBINING_DEBUG */  /* A charset of type iso2022 who has DIMENSION, CHARS, and FINAL
465       (final character).  */
466    #define ISO_CHARSET_TABLE(dimension, chars_96, final)   \
467      iso_charset_table[(dimension) - 1][(chars_96)][(final)]
468    
469    /* Nonzero iff the charset who has FAST_MAP may contain C.  */
470    #define CHARSET_FAST_MAP_REF(c, fast_map)               \
471      ((c) < 0x10000                                        \
472       ? fast_map[(c) >> 10] & (1 << (((c) >> 7) & 7))      \
473       : fast_map[((c) >> 15) + 62] & (1 << (((c) >> 12) & 7)))
474    
475  #define BUF_INC_POS(buf, pos_byte)                              \  #define CHARSET_FAST_MAP_SET(c, fast_map)                       \
476    do {                                                          \    do {                                                          \
477      unsigned char *p = BUF_BYTE_ADDRESS (buf, pos_byte);        \      if ((c) < 0x10000)                                          \
478      pos_byte += BYTES_BY_CHAR_HEAD (*p);                        \        (fast_map)[(c) >> 10] |= 1 << (((c) >> 7) & 7);           \
479    } while (0)      else                                                        \
480          (fast_map)[((c) >> 15) + 62] |= 1 << (((c) >> 12) & 7);   \
 #endif /* not BYTE_COMBINING_DEBUG */  
   
 /* Decrease the buffer byte position POS_BYTE of the current buffer to  
    the previous character boundary.  No range checking of POS_BYTE.  */  
 #define BUF_DEC_POS(buf, pos_byte)                                      \  
   do {                                                                  \  
     unsigned char *p, *p_min;                                           \  
     pos_byte--;                                                         \  
     if (pos_byte < BUF_GPT_BYTE (buf))                                  \  
       {                                                                 \  
         p = BUF_BEG_ADDR (buf) + pos_byte - BEG_BYTE;                   \  
         p_min = BUF_BEG_ADDR (buf);                                     \  
       }                                                                 \  
     else                                                                \  
       {                                                                 \  
         p = BUF_BEG_ADDR (buf) + BUF_GAP_SIZE (buf) + pos_byte - BEG_BYTE;\  
         p_min = BUF_GAP_END_ADDR (buf);                                 \  
       }                                                                 \  
     if (p > p_min && !CHAR_HEAD_P (*p))                                 \  
       {                                                                 \  
         unsigned char *pend = p--;                                      \  
         int len, bytes;                                                 \  
         if (p_min < p - MAX_MULTIBYTE_LENGTH)                           \  
           p_min = p - MAX_MULTIBYTE_LENGTH;                             \  
         while (p > p_min && !CHAR_HEAD_P (*p)) p--;                     \  
         len = pend + 1 - p;                                             \  
         PARSE_MULTIBYTE_SEQ (p, len, bytes);                            \  
         if (bytes == len)                                               \  
           pos_byte -= len - 1;                                          \  
       }                                                                 \  
481    } while (0)    } while (0)
482    
 #endif /* emacs */  
   
 /* This is the maximum byte length of multi-byte sequence.  */  
 #define MAX_MULTIBYTE_LENGTH 4  
483    
 extern void invalid_character P_ ((int));  
484    
485  extern int translate_char P_ ((Lisp_Object, int, int, int, int));  /* 1 iff CHARSET may contain the character C.  */
486  extern int split_string P_ ((const unsigned char *, int, int *,  #define CHAR_CHARSET_P(c, charset)                                       \
487                                         unsigned char *, unsigned char *));    ((ASCII_CHAR_P (c) && (charset)->ascii_compatible_p)                   \
488  extern int char_to_string P_ ((int, unsigned char *));     || (CHARSET_UNIFIED_P (charset)                                       \
489  extern int char_to_string_1 P_ ((int, unsigned char *));         ? encode_char ((charset), (c)) != (charset)->invalid_code         \
490  extern int string_to_char P_ ((const unsigned char *, int, int *));         : (CHARSET_FAST_MAP_REF ((c), (charset)->fast_map)                \
491  extern int char_printable_p P_ ((int c));            && ((charset)->method == CHARSET_METHOD_OFFSET                 \
492  extern int multibyte_form_length P_ ((const unsigned char *, int));                ? (c) >= (charset)->min_char && (c) <= (charset)->max_char \
493  extern void parse_str_as_multibyte P_ ((const unsigned char *, int, int *,                : ((charset)->method == CHARSET_METHOD_MAP                 \
494                                          int *));                   && (charset)->compact_codes_p)                          \
495  extern int str_as_multibyte P_ ((unsigned char *, int, int, int *));                ? ! NILP (CHAR_TABLE_REF (CHARSET_ENCODER (charset), (c))) \
496  extern int parse_str_to_multibyte P_ ((unsigned char *, int));                : encode_char ((charset), (c)) != (charset)->invalid_code))))
497  extern int str_to_multibyte P_ ((unsigned char *, int, int));  
498  extern int str_as_unibyte P_ ((unsigned char *, int));  
499  extern int get_charset_id P_ ((Lisp_Object));  /* Special macros for emacs-mule encoding.  */
500  extern int find_charset_in_text P_ ((const unsigned char *, int, int, int *,  
501                                      Lisp_Object));  /* Leading-code followed by extended leading-code.    DIMENSION/COLUMN */
502  extern int strwidth P_ ((unsigned char *, int));  #define EMACS_MULE_LEADING_CODE_PRIVATE_11      0x9A /* 1/1 */
503  extern int c_string_width P_ ((const unsigned char *, int, int, int *, int *));  #define EMACS_MULE_LEADING_CODE_PRIVATE_12      0x9B /* 1/2 */
504  extern int lisp_string_width P_ ((Lisp_Object, int, int *, int *));  #define EMACS_MULE_LEADING_CODE_PRIVATE_21      0x9C /* 2/2 */
505  extern int char_bytes P_ ((int));  #define EMACS_MULE_LEADING_CODE_PRIVATE_22      0x9D /* 2/2 */
506  extern int char_valid_p P_ ((int, int));  
507    extern struct charset *emacs_mule_charset[256];
508  EXFUN (Funibyte_char_to_multibyte, 1);  
509    
510  extern Lisp_Object Vtranslation_table_vector;  
511    extern Lisp_Object Qcharsetp;
512  /* Return a translation table of id number ID.  */  
513  #define GET_TRANSLATION_TABLE(id) \  extern Lisp_Object Qascii, Qunicode;
514    (XCDR(XVECTOR(Vtranslation_table_vector)->contents[(id)]))  extern int charset_ascii, charset_eight_bit;
515    extern int charset_iso_8859_1;
516  /* A char-table for characters which may invoke auto-filling.  */  extern int charset_jisx0201_roman;
517  extern Lisp_Object Vauto_fill_chars;  extern int charset_jisx0208_1978;
518    extern int charset_jisx0208;
519  /* Copy LEN bytes from FROM to TO.  This macro should be used only  
520     when a caller knows that LEN is short and the obvious copy loop is  extern int charset_unibyte;
521     faster than calling bcopy which has some overhead.  Copying a  
522     multibyte sequence of a multibyte character is the typical case.  */  extern struct charset *char_charset P_ ((int, Lisp_Object, unsigned *));
523    extern Lisp_Object charset_attributes P_ ((int));
524    
525    extern int decode_char P_ ((struct charset *, unsigned));
526    extern unsigned encode_char P_ ((struct charset *, int));
527    extern int string_xstring_p P_ ((Lisp_Object));
528    
529    extern void map_charset_chars P_ ((void (*) (Lisp_Object, Lisp_Object),
530                                       Lisp_Object, Lisp_Object,
531                                       struct charset *, unsigned, unsigned));
532    
533  #define BCOPY_SHORT(from, to, len)              \  EXFUN (Funify_charset, 3);
   do {                                          \  
     int i = len;                                \  
     const unsigned char *from_p = from;         \  
     unsigned char *to_p = to;                   \  
     while (i--) *to_p++ = *from_p++;            \  
   } while (0)  
534    
535  #endif /* EMACS_CHARSET_H */  #endif /* EMACS_CHARSET_H */

Legend:
Removed from v.1.75  
changed lines
  Added in v.1.75.4.1

savannah-hackers-public@gnu.org
ViewVC Help
Powered by ViewVC 1.1.26