update.
[chise/xemacs-chise.git.1] / src / char-lb.h
1 /* Header for leading-byte character representation.
2    Copyright (C) 1999,2000 MORIOKA Tomohiko
3
4 This file is part of XEmacs.
5
6 XEmacs is free software; you can redistribute it and/or modify it
7 under the terms of the GNU General Public License as published by the
8 Free Software Foundation; either version 2, or (at your option) any
9 later version.
10
11 XEmacs is distributed in the hope that it will be useful, but WITHOUT
12 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
14 for more details.
15
16 You should have received a copy of the GNU General Public License
17 along with XEmacs; see the file COPYING.  If not, write to
18 the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 Boston, MA 02111-1307, USA.  */
20
21 #ifndef _XEMACS_CHAR_LB_H
22 #define _XEMACS_CHAR_LB_H
23
24 #include "mule-charset.h"
25
26 int non_ascii_valid_char_p (Emchar ch);
27
28 INLINE_HEADER int valid_char_p (Emchar ch);
29 INLINE_HEADER int
30 valid_char_p (Emchar ch)
31 {
32   return ((unsigned int) (ch) <= 0xff) || non_ascii_valid_char_p (ch);
33 }
34
35 #define CHAR_COLUMNS(c)     (XCHARSET_COLUMNS(CHAR_CHARSET(c)))
36
37
38 INLINE_HEADER Emchar DECODE_CHAR (Lisp_Object charset, int code_point);
39 INLINE_HEADER Emchar
40 DECODE_CHAR (Lisp_Object charset, int code_point)
41 {
42   if (EQ (charset, Vcharset_ascii))
43     return code_point;
44   else if (EQ (charset, Vcharset_control_1))
45     return code_point | 0x80;
46   else if (XCHARSET_DIMENSION (charset) == 1)
47     return ((XCHARSET_LEADING_BYTE (charset) -
48              FIELD2_TO_OFFICIAL_LEADING_BYTE) << 7) | code_point;
49   else if (!XCHARSET_PRIVATE_P (charset))
50     return ((XCHARSET_LEADING_BYTE (charset) -
51              FIELD1_TO_OFFICIAL_LEADING_BYTE) << 14)
52       | ((code_point >> 1) & 0x3F80) | (code_point & 0x7F);
53   else
54     return ((XCHARSET_LEADING_BYTE (charset) -
55              FIELD1_TO_PRIVATE_LEADING_BYTE) << 14)
56       | ((code_point >> 1) & 0x3F80) | (code_point & 0x7F);
57 }
58
59 INLINE_HEADER int encode_char_1 (Emchar ch, Lisp_Object* charset);
60 INLINE_HEADER int
61 encode_char_1 (Emchar ch, Lisp_Object* charset)
62 {
63   *charset = CHAR_CHARSET (ch);
64   return  XCHARSET_DIMENSION (*charset) == 1
65     ? CHAR_FIELD3 (ch)
66     : (CHAR_FIELD2 (ch) << 8) | CHAR_FIELD3 (ch);
67 }
68
69 #define ENCODE_CHAR(ch, charset)        encode_char_1 (ch, &(charset))
70
71
72 typedef struct Charc
73 {
74   Lisp_Object charset;
75   unsigned short code_point;
76 } Charc;
77
78 INLINE_HEADER Charc CHAR_TO_CHARC (Emchar ch);
79 INLINE_HEADER Charc
80 CHAR_TO_CHARC (Emchar ch)
81 {
82   Charc cc;
83
84   cc.code_point = encode_char_1 (ch, &cc.charset);
85   return cc;
86 }
87
88 #endif /* _XEMACS_CHAR_LB_H */