comparison src/mule-charset.c @ 444:576fb035e263 r21-2-37

Import from CVS: tag r21-2-37
author cvs
date Mon, 13 Aug 2007 11:36:19 +0200
parents abe6d1db359e
children 1ccc32a20af4
comparison
equal deleted inserted replaced
443:a8296e22da4e 444:576fb035e263
320 320
321 /************************************************************************/ 321 /************************************************************************/
322 /* Basic string functions */ 322 /* Basic string functions */
323 /************************************************************************/ 323 /************************************************************************/
324 324
325 /* Copy the character pointed to by PTR into STR, assuming it's 325 /* Copy the character pointed to by SRC into DST. Do not call this
326 non-ASCII. Do not call this directly. Use the macro 326 directly. Use the macro charptr_copy_char() instead.
327 charptr_copy_char() instead. */ 327 Return the number of bytes copied. */
328 328
329 Bytecount 329 Bytecount
330 non_ascii_charptr_copy_char (const Bufbyte *ptr, Bufbyte *str) 330 non_ascii_charptr_copy_char (const Bufbyte *src, Bufbyte *dst)
331 { 331 {
332 Bufbyte *strptr = str; 332 unsigned int bytes = REP_BYTES_BY_FIRST_BYTE (*src);
333 *strptr = *ptr++; 333 unsigned int i;
334 switch (REP_BYTES_BY_FIRST_BYTE (*strptr)) 334 for (i = bytes; i; i--, dst++, src++)
335 { 335 *dst = *src;
336 /* Notice fallthrough. */ 336 return bytes;
337 case 4: *++strptr = *ptr++;
338 case 3: *++strptr = *ptr++;
339 case 2: *++strptr = *ptr;
340 break;
341 default:
342 abort ();
343 }
344 return strptr + 1 - str;
345 } 337 }
346 338
347 339
348 /************************************************************************/ 340 /************************************************************************/
349 /* streams of Emchars */ 341 /* streams of Emchars */
356 Emchar 348 Emchar
357 Lstream_get_emchar_1 (Lstream *stream, int ch) 349 Lstream_get_emchar_1 (Lstream *stream, int ch)
358 { 350 {
359 Bufbyte str[MAX_EMCHAR_LEN]; 351 Bufbyte str[MAX_EMCHAR_LEN];
360 Bufbyte *strptr = str; 352 Bufbyte *strptr = str;
353 unsigned int bytes;
361 354
362 str[0] = (Bufbyte) ch; 355 str[0] = (Bufbyte) ch;
363 switch (REP_BYTES_BY_FIRST_BYTE (ch)) 356
357 for (bytes = REP_BYTES_BY_FIRST_BYTE (ch) - 1; bytes; bytes--)
364 { 358 {
365 /* Notice fallthrough. */ 359 int c = Lstream_getc (stream);
366 case 4: 360 bufpos_checking_assert (c >= 0);
367 ch = Lstream_getc (stream); 361 *++strptr = (Bufbyte) c;
368 assert (ch >= 0);
369 *++strptr = (Bufbyte) ch;
370 case 3:
371 ch = Lstream_getc (stream);
372 assert (ch >= 0);
373 *++strptr = (Bufbyte) ch;
374 case 2:
375 ch = Lstream_getc (stream);
376 assert (ch >= 0);
377 *++strptr = (Bufbyte) ch;
378 break;
379 default:
380 abort ();
381 } 362 }
382 return charptr_emchar (str); 363 return charptr_emchar (str);
383 } 364 }
384 365
385 int 366 int
627 608
628 return charset_list; 609 return charset_list;
629 } 610 }
630 611
631 DEFUN ("charset-name", Fcharset_name, 1, 1, 0, /* 612 DEFUN ("charset-name", Fcharset_name, 1, 1, 0, /*
632 Return the name of the given charset. 613 Return the name of charset CHARSET.
633 */ 614 */
634 (charset)) 615 (charset))
635 { 616 {
636 return XCHARSET_NAME (Fget_charset (charset)); 617 return XCHARSET_NAME (Fget_charset (charset));
637 } 618 }
772 signal_simple_error ("Invalid value for 'final", value); 753 signal_simple_error ("Invalid value for 'final", value);
773 } 754 }
774 755
775 else if (EQ (keyword, Qccl_program)) 756 else if (EQ (keyword, Qccl_program))
776 { 757 {
777 CHECK_VECTOR (value); 758 struct ccl_program test_ccl;
759
760 if (setup_ccl_program (&test_ccl, value) < 0)
761 signal_simple_error ("Invalid value for 'ccl-program", value);
778 ccl_program = value; 762 ccl_program = value;
779 } 763 }
780 764
781 else 765 else
782 signal_simple_error ("Unrecognized property", keyword); 766 signal_simple_error ("Unrecognized property", keyword);
1028 DEFUN ("set-charset-ccl-program", Fset_charset_ccl_program, 2, 2, 0, /* 1012 DEFUN ("set-charset-ccl-program", Fset_charset_ccl_program, 2, 2, 0, /*
1029 Set the 'ccl-program property of CHARSET to CCL-PROGRAM. 1013 Set the 'ccl-program property of CHARSET to CCL-PROGRAM.
1030 */ 1014 */
1031 (charset, ccl_program)) 1015 (charset, ccl_program))
1032 { 1016 {
1017 struct ccl_program test_ccl;
1018
1033 charset = Fget_charset (charset); 1019 charset = Fget_charset (charset);
1034 CHECK_VECTOR (ccl_program); 1020 if (setup_ccl_program (&test_ccl, ccl_program) < 0)
1021 signal_simple_error ("Invalid ccl-program", ccl_program);
1035 XCHARSET_CCL_PROGRAM (charset) = ccl_program; 1022 XCHARSET_CCL_PROGRAM (charset) = ccl_program;
1036 return Qnil; 1023 return Qnil;
1037 } 1024 }
1038 1025
1039 static void 1026 static void
1113 1100
1114 return make_char (MAKE_CHAR (charset, a1, a2)); 1101 return make_char (MAKE_CHAR (charset, a1, a2));
1115 } 1102 }
1116 1103
1117 DEFUN ("char-charset", Fchar_charset, 1, 1, 0, /* 1104 DEFUN ("char-charset", Fchar_charset, 1, 1, 0, /*
1118 Return the character set of char CH. 1105 Return the character set of CHARACTER.
1119 */ 1106 */
1120 (ch)) 1107 (character))
1121 { 1108 {
1122 CHECK_CHAR_COERCE_INT (ch); 1109 CHECK_CHAR_COERCE_INT (character);
1123 1110
1124 return XCHARSET_NAME (CHARSET_BY_LEADING_BYTE 1111 return XCHARSET_NAME (CHARSET_BY_LEADING_BYTE
1125 (CHAR_LEADING_BYTE (XCHAR (ch)))); 1112 (CHAR_LEADING_BYTE (XCHAR (character))));
1126 } 1113 }
1127 1114
1128 DEFUN ("char-octet", Fchar_octet, 1, 2, 0, /* 1115 DEFUN ("char-octet", Fchar_octet, 1, 2, 0, /*
1129 Return the octet numbered N (should be 0 or 1) of char CH. 1116 Return the octet numbered N (should be 0 or 1) of CHARACTER.
1130 N defaults to 0 if omitted. 1117 N defaults to 0 if omitted.
1131 */ 1118 */
1132 (ch, n)) 1119 (character, n))
1133 { 1120 {
1134 Lisp_Object charset; 1121 Lisp_Object charset;
1135 int octet0, octet1; 1122 int octet0, octet1;
1136 1123
1137 CHECK_CHAR_COERCE_INT (ch); 1124 CHECK_CHAR_COERCE_INT (character);
1138 1125
1139 BREAKUP_CHAR (XCHAR (ch), charset, octet0, octet1); 1126 BREAKUP_CHAR (XCHAR (character), charset, octet0, octet1);
1140 1127
1141 if (NILP (n) || EQ (n, Qzero)) 1128 if (NILP (n) || EQ (n, Qzero))
1142 return make_int (octet0); 1129 return make_int (octet0);
1143 else if (EQ (n, make_int (1))) 1130 else if (EQ (n, make_int (1)))
1144 return make_int (octet1); 1131 return make_int (octet1);
1145 else 1132 else
1146 signal_simple_error ("Octet number must be 0 or 1", n); 1133 signal_simple_error ("Octet number must be 0 or 1", n);
1147 } 1134 }
1148 1135
1149 DEFUN ("split-char", Fsplit_char, 1, 1, 0, /* 1136 DEFUN ("split-char", Fsplit_char, 1, 1, 0, /*
1150 Return list of charset and one or two position-codes of CHAR. 1137 Return list of charset and one or two position-codes of CHARACTER.
1151 */ 1138 */
1152 (character)) 1139 (character))
1153 { 1140 {
1154 /* This function can GC */ 1141 /* This function can GC */
1155 struct gcpro gcpro1, gcpro2; 1142 struct gcpro gcpro1, gcpro2;