+/* 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. Do not call this function directly,
+ instead use macro CHAR_VALID_P. */
+int
+char_valid_p (c, genericp)
+ int c, genericp;
+{
+ int charset, c1, c2;
+
+ if (c < 0 || c >= MAX_CHAR)
+ return 0;
+ if (SINGLE_BYTE_CHAR_P (c))
+ return 1;
+ SPLIT_CHAR (c, charset, c1, c2);
+ if (genericp)
+ {
+ if (c1)
+ {
+ if (c2 <= 0) c2 = 0x20;
+ }
+ else
+ {
+ if (c2 <= 0) c1 = c2 = 0x20;
+ }
+ }
+ return (CHARSET_DEFINED_P (charset)
+ && CHAR_COMPONENTS_VALID_P (charset, c1, c2));
+}
+
+DEFUN ("char-valid-p", Fchar_valid_p, Schar_valid_p, 1, 2, 0,
+ "Return t if OBJECT is a valid normal character.\n\
+If optional arg GENERICP is non-nil, also return t if OBJECT is\n\
+a valid generic character.")
+ (object, genericp)
+ Lisp_Object object, genericp;
+{
+ if (! NATNUMP (object))
+ return Qnil;
+ return (CHAR_VALID_P (XFASTINT (object), !NILP (genericp)) ? Qt : Qnil);
+}
+
+DEFUN ("unibyte-char-to-multibyte", Funibyte_char_to_multibyte,
+ Sunibyte_char_to_multibyte, 1, 1, 0,
+ "Convert the unibyte character CH to multibyte character.\n\
+The conversion is done based on `nonascii-translation-table' (which see)\n\
+ or `nonascii-insert-offset' (which see).")
+ (ch)
+ Lisp_Object ch;
+{
+ int c;
+
+ CHECK_NUMBER (ch, 0);
+ c = XINT (ch);
+ if (c < 0 || c >= 0400)
+ error ("Invalid unibyte character: %d", c);
+ c = unibyte_char_to_multibyte (c);
+ if (c < 0)
+ error ("Can't convert to multibyte character: %d", XINT (ch));
+ return make_number (c);
+}
+
+DEFUN ("multibyte-char-to-unibyte", Fmultibyte_char_to_unibyte,
+ Smultibyte_char_to_unibyte, 1, 1, 0,
+ "Convert the multibyte character CH to unibyte character.\n\
+The conversion is done based on `nonascii-translation-table' (which see)\n\
+ or `nonascii-insert-offset' (which see).")
+ (ch)
+ Lisp_Object ch;
+{
+ int c;
+
+ CHECK_NUMBER (ch, 0);
+ c = XINT (ch);
+ if (! CHAR_VALID_P (c, 0))
+ error ("Invalid multibyte character: %d", c);
+ c = multibyte_char_to_unibyte (c, Qnil);
+ if (c < 0)
+ error ("Can't convert to unibyte character: %d", XINT (ch));
+ return make_number (c);
+}
+