comparison src/mule-charset.h @ 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 af57a77cbc92
comparison
equal deleted inserted replaced
443:a8296e22da4e 444:576fb035e263
399 399
400 #define LEADING_BYTE_PRIVATE_P(lb) ((lb) >= MIN_LEADING_BYTE_PRIVATE_1) 400 #define LEADING_BYTE_PRIVATE_P(lb) ((lb) >= MIN_LEADING_BYTE_PRIVATE_1)
401 401
402 /* Is this a prefix for a private leading byte? */ 402 /* Is this a prefix for a private leading byte? */
403 403
404 INLINE_HEADER int LEADING_BYTE_PREFIX_P (unsigned char lb); 404 INLINE_HEADER int LEADING_BYTE_PREFIX_P (Bufbyte lb);
405 INLINE_HEADER int 405 INLINE_HEADER int
406 LEADING_BYTE_PREFIX_P (unsigned char lb) 406 LEADING_BYTE_PREFIX_P (Bufbyte lb)
407 { 407 {
408 return (lb == PRE_LEADING_BYTE_PRIVATE_1 || 408 return (lb == PRE_LEADING_BYTE_PRIVATE_1 ||
409 lb == PRE_LEADING_BYTE_PRIVATE_2); 409 lb == PRE_LEADING_BYTE_PRIVATE_2);
410 } 410 }
411 411
412 /* Given a private leading byte, return the leading byte prefix stored 412 /* Given a private leading byte, return the leading byte prefix stored
413 in a string */ 413 in a string. */
414 414
415 #define PRIVATE_LEADING_BYTE_PREFIX(lb) \ 415 #define PRIVATE_LEADING_BYTE_PREFIX(lb) \
416 ((lb) < MIN_LEADING_BYTE_PRIVATE_2 ? \ 416 ((unsigned int) (lb) < MIN_LEADING_BYTE_PRIVATE_2 ? \
417 PRE_LEADING_BYTE_PRIVATE_1 : \ 417 PRE_LEADING_BYTE_PRIVATE_1 : \
418 PRE_LEADING_BYTE_PRIVATE_2) 418 PRE_LEADING_BYTE_PRIVATE_2)
419 419
420 420
421 /************************************************************************/ 421 /************************************************************************/
422 /* Operations on individual bytes */ 422 /* Operations on individual bytes */
423 /* of any format */ 423 /* of any format */
424 /************************************************************************/ 424 /************************************************************************/
425 425
426 /* Argument `c' should be (unsigned int) or (unsigned char). */ 426 /* These are carefully designed to work if BYTE is signed or unsigned. */
427 /* Note that SP and DEL are not included. */ 427 /* Note that SPC and DEL are considered ASCII, not control. */
428 428
429 #define BYTE_ASCII_P(c) ((c) < 0x80) 429 #define BYTE_ASCII_P(byte) (((byte) & ~0x7f) == 0)
430 #define BYTE_C0_P(c) ((c) < 0x20) 430 #define BYTE_C0_P(byte) (((byte) & ~0x1f) == 0)
431 /* Do some forced casting just to make *sure* things are gotten right. */ 431 #define BYTE_C1_P(byte) (((byte) & ~0x1f) == 0x80)
432 #define BYTE_C1_P(c) ((unsigned int) ((unsigned int) (c) - 0x80) < 0x20)
433 432
434 433
435 /************************************************************************/ 434 /************************************************************************/
436 /* Operations on individual bytes */ 435 /* Operations on individual bytes */
437 /* in a Mule-formatted string */ 436 /* in a Mule-formatted string */
438 /************************************************************************/ 437 /************************************************************************/
439 438
440 /* Does this byte represent the first byte of a character? */ 439 /* Does BYTE represent the first byte of a character? */
441 440
442 #define BUFBYTE_FIRST_BYTE_P(c) ((c) < 0xA0) 441 #define BUFBYTE_FIRST_BYTE_P(byte) ((byte) < 0xA0)
443 442
444 /* Does this byte represent the first byte of a multi-byte character? */ 443 /* Does BYTE represent the first byte of a multi-byte character? */
445 444
446 #define BUFBYTE_LEADING_BYTE_P(c) BYTE_C1_P (c) 445 #define BUFBYTE_LEADING_BYTE_P(byte) BYTE_C1_P (byte)
447 446
448 447
449 /************************************************************************/ 448 /************************************************************************/
450 /* Information about a particular character set */ 449 /* Information about a particular character set */
451 /************************************************************************/ 450 /************************************************************************/
559 Lisp_Object charset_by_attributes[4][128][2]; 558 Lisp_Object charset_by_attributes[4][128][2];
560 Bufbyte next_allocated_1_byte_leading_byte; 559 Bufbyte next_allocated_1_byte_leading_byte;
561 Bufbyte next_allocated_2_byte_leading_byte; 560 Bufbyte next_allocated_2_byte_leading_byte;
562 }; 561 };
563 562
564 extern struct charset_lookup *chlook; 563 INLINE_HEADER Lisp_Object CHARSET_BY_LEADING_BYTE (Bufbyte lb);
564 INLINE_HEADER Lisp_Object
565 CHARSET_BY_LEADING_BYTE (Bufbyte lb)
566 {
567 extern struct charset_lookup *chlook;
565 568
566 #ifdef ERROR_CHECK_TYPECHECK 569 #ifdef ERROR_CHECK_TYPECHECK
567 /* int not Bufbyte even though that is the actual type of a leading byte. 570 /* When error-checking is on, x86 GCC 2.95.2 -O3 miscompiles the
568 This way, out-of-range values will get caught rather than automatically 571 following unless we introduce `tem'. */
569 truncated. */ 572 int tem = lb;
570 INLINE_HEADER Lisp_Object CHARSET_BY_LEADING_BYTE (int lb); 573 type_checking_assert (tem >= 0x80 && tem <= 0xFF);
571 INLINE_HEADER Lisp_Object 574 #endif
572 CHARSET_BY_LEADING_BYTE (int lb)
573 {
574 assert (lb >= 0x80 && lb <= 0xFF);
575 return chlook->charset_by_leading_byte[lb - 128]; 575 return chlook->charset_by_leading_byte[lb - 128];
576 } 576 }
577 577
578 #else 578 INLINE_HEADER Lisp_Object
579 579 CHARSET_BY_ATTRIBUTES (unsigned int type, unsigned char final, int dir);
580 #define CHARSET_BY_LEADING_BYTE(lb) (chlook->charset_by_leading_byte[(lb) - 128]) 580 INLINE_HEADER Lisp_Object
581 581 CHARSET_BY_ATTRIBUTES (unsigned int type, unsigned char final, int dir)
582 #endif 582 {
583 583 extern struct charset_lookup *chlook;
584 #define CHARSET_BY_ATTRIBUTES(type, final, dir) \ 584
585 (chlook->charset_by_attributes[type][final][dir]) 585 type_checking_assert (type < countof (chlook->charset_by_attributes) &&
586 586 final < countof (chlook->charset_by_attributes[0]) &&
587 dir < countof (chlook->charset_by_attributes[0][0]));
588 return chlook->charset_by_attributes[type][final][dir];
589 }
587 590
588 /* Table of number of bytes in the string representation of a character 591 /* Table of number of bytes in the string representation of a character
589 indexed by the first byte of that representation. 592 indexed by the first byte of that representation.
590 593
591 This value can be derived in other ways -- e.g. something like 594 This value can be derived in other ways -- e.g. something like
592 XCHARSET_REP_BYTES (CHARSET_BY_LEADING_BYTE (first_byte)) 595 XCHARSET_REP_BYTES (CHARSET_BY_LEADING_BYTE (first_byte))
593 but it's faster this way. */ 596 but it's faster this way. */
594 extern const Bytecount rep_bytes_by_first_byte[0xA0]; 597 extern const Bytecount rep_bytes_by_first_byte[0xA0];
595 598
596 /* Number of bytes in the string representation of a character. */ 599 /* Number of bytes in the string representation of a character. */
597 INLINE_HEADER int REP_BYTES_BY_FIRST_BYTE (int fb); 600 INLINE_HEADER int REP_BYTES_BY_FIRST_BYTE (Bufbyte fb);
598 INLINE_HEADER int 601 INLINE_HEADER int
599 REP_BYTES_BY_FIRST_BYTE (int fb) 602 REP_BYTES_BY_FIRST_BYTE (Bufbyte fb)
600 { 603 {
601 #ifdef ERROR_CHECK_TYPECHECK 604 type_checking_assert (fb < 0xA0);
602 assert (0 <= fb && fb < 0xA0);
603 #endif
604 return rep_bytes_by_first_byte[fb]; 605 return rep_bytes_by_first_byte[fb];
605 } 606 }
606 607
607 608
608 /************************************************************************/ 609 /************************************************************************/