(CHAR_TO_CHARC): New inline function.
[chise/xemacs-chise.git-] / src / character.h
1 /* Header for 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_CHARACTER_H
22 #define _XEMACS_CHARACTER_H
23
24 #if !defined(MULE) /* unibyte representation */
25 # include "char-1byte.h"
26 #elif !defined(CHAR_IS_UCS4) /* leading-byte representation */
27 # include "char-lb.h"
28 #else /* CHAR_IS_UCS4 */
29 # include "char-ucs.h"
30 #endif /* CHAR_IS_UCS4 */
31
32 /********************************/
33 /*                              */
34 /*   Interface for characters   */
35 /*                              */
36 /********************************/
37 /*
38    valid_char_p (ch):
39         Return whether the given Emchar is valid.
40
41    CHARP (ch):
42         Return whether the given Lisp_Object is a character.
43
44    CHECK_CHAR_COERCE_INT (ch):
45         Signal an error if CH is not a valid character or integer
46         Lisp_Object.
47         If CH is an integer Lisp_Object, convert it to a character
48         Lisp_Object, but merely by repackaging, without performing
49         tests for char validity.
50
51 Functions/macros when MULE is defined:
52
53    CHAR_ASCII_P (ch):
54         Return whether the given Emchar is ASCII.
55
56    MAKE_CHAR (CHARSET, B1, B2):
57         Return a character whose coded-charset is CHARSET and
58         position-codes are B1 and B2.  1 byte character ignores B2.
59
60    BREAKUP_CHAR (ch, charset, B1, B2):
61         Break up the given Emchar, and store found coded-charset and
62         position-codes to CHARSET, B1 and B2.
63
64    CHAR_CHARSET (CH):
65         Return coded-charset object of Emchar CH.
66
67    CHAR_LEADING_BYTE (CH):
68         Return Charset-ID of Emchar CH.
69 */
70
71 #define CHAR_INTP(x) (INTP (x) && valid_char_p (XINT (x)))
72
73 #define CHAR_OR_CHAR_INTP(x) (CHARP (x) || CHAR_INTP (x))
74
75 #ifdef ERROR_CHECK_TYPECHECK
76
77 INLINE_HEADER Emchar XCHAR_OR_CHAR_INT (Lisp_Object obj);
78 INLINE_HEADER Emchar
79 XCHAR_OR_CHAR_INT (Lisp_Object obj)
80 {
81   assert (CHAR_OR_CHAR_INTP (obj));
82   return CHARP (obj) ? XCHAR (obj) : XINT (obj);
83 }
84
85 #else
86
87 #define XCHAR_OR_CHAR_INT(obj) (CHARP ((obj)) ? XCHAR ((obj)) : XINT ((obj)))
88
89 #endif
90
91 #define CHECK_CHAR_COERCE_INT(x) do {           \
92   if (CHARP (x))                                \
93      ;                                          \
94   else if (CHAR_INTP (x))                       \
95     x = make_char (XINT (x));                   \
96   else                                          \
97     x = wrong_type_argument (Qcharacterp, x);   \
98 } while (0)
99
100
101 typedef struct
102 {
103   Dynarr_declare (Charc);
104 } Charc_dynarr;
105
106 #endif /* _XEMACS_CHARACTER_H */