update.
[chise/xemacs-chise.git-] / src / character.h
index f7befb4..9f89559 100644 (file)
@@ -1,4 +1,4 @@
-/* Header for UCS-4 character representation.
+/* Header for character representation.
    Copyright (C) 1999 Electrotechnical Laboratory, JAPAN.
    Licensed to the Free Software Foundation.
 
@@ -32,4 +32,72 @@ Boston, MA 02111-1307, USA.  */
 # include "char-ucs.h"
 #endif /* CHAR_IS_UCS4 */
 
+/********************************/
+/*                              */
+/*   Interface for characters   */
+/*                              */
+/********************************/
+/*
+   valid_char_p (ch):
+       Return whether the given Emchar is valid.
+
+   CHARP (ch):
+       Return whether the given Lisp_Object is a character.
+
+   CHECK_CHAR_COERCE_INT (ch):
+       Signal an error if CH is not a valid character or integer
+       Lisp_Object.
+       If CH is an integer Lisp_Object, convert it to a character
+       Lisp_Object, but merely by repackaging, without performing
+       tests for char validity.
+
+Functions/macros when MULE is defined:
+
+   CHAR_ASCII_P (ch):
+        Return whether the given Emchar is ASCII.
+
+   MAKE_CHAR (CHARSET, B1, B2):
+       Return a character whose coded-charset is CHARSET and
+       position-codes are B1 and B2.  1 byte character ignores B2.
+
+   BREAKUP_CHAR (ch, charset, B1, B2):
+       Break up the given Emchar, and store found coded-charset and
+       position-codes to CHARSET, B1 and B2.
+
+   CHAR_CHARSET (CH):
+        Return coded-charset object of Emchar CH.
+
+   CHAR_LEADING_BYTE (CH):
+        Return Charset-ID of Emchar CH.
+*/
+
+#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)
+
 #endif /* _XEMACS_CHARACTER_H */