comparison src/buffer.h @ 404:2f8bb876ab1d r21-2-32

Import from CVS: tag r21-2-32
author cvs
date Mon, 13 Aug 2007 11:16:07 +0200
parents 74fd4e045ea6
children b8cc9ab3f761
comparison
equal deleted inserted replaced
403:9f011ab08d48 404:2f8bb876ab1d
468 /* -------------------------------------------------------------- */ 468 /* -------------------------------------------------------------- */
469 /* (B) For working with the length (in bytes and characters) of a */ 469 /* (B) For working with the length (in bytes and characters) of a */
470 /* section of internally-formatted text */ 470 /* section of internally-formatted text */
471 /* -------------------------------------------------------------- */ 471 /* -------------------------------------------------------------- */
472 472
473 INLINE const Bufbyte *charptr_n_addr (const Bufbyte *ptr, Charcount offset); 473 INLINE_HEADER const Bufbyte *
474 INLINE const Bufbyte * 474 charptr_n_addr (const Bufbyte *ptr, Charcount offset);
475 INLINE_HEADER const Bufbyte *
475 charptr_n_addr (const Bufbyte *ptr, Charcount offset) 476 charptr_n_addr (const Bufbyte *ptr, Charcount offset)
476 { 477 {
477 return ptr + charcount_to_bytecount (ptr, offset); 478 return ptr + charcount_to_bytecount (ptr, offset);
478 } 479 }
479 480
489 490
490 Emchar non_ascii_charptr_emchar (const Bufbyte *ptr); 491 Emchar non_ascii_charptr_emchar (const Bufbyte *ptr);
491 Bytecount non_ascii_set_charptr_emchar (Bufbyte *ptr, Emchar c); 492 Bytecount non_ascii_set_charptr_emchar (Bufbyte *ptr, Emchar c);
492 Bytecount non_ascii_charptr_copy_char (const Bufbyte *ptr, Bufbyte *ptr2); 493 Bytecount non_ascii_charptr_copy_char (const Bufbyte *ptr, Bufbyte *ptr2);
493 494
494 INLINE Emchar charptr_emchar (const Bufbyte *ptr); 495 INLINE_HEADER Emchar charptr_emchar (const Bufbyte *ptr);
495 INLINE Emchar 496 INLINE_HEADER Emchar
496 charptr_emchar (const Bufbyte *ptr) 497 charptr_emchar (const Bufbyte *ptr)
497 { 498 {
498 return BYTE_ASCII_P (*ptr) ? 499 return BYTE_ASCII_P (*ptr) ?
499 simple_charptr_emchar (ptr) : 500 simple_charptr_emchar (ptr) :
500 non_ascii_charptr_emchar (ptr); 501 non_ascii_charptr_emchar (ptr);
501 } 502 }
502 503
503 INLINE Bytecount set_charptr_emchar (Bufbyte *ptr, Emchar x); 504 INLINE_HEADER Bytecount set_charptr_emchar (Bufbyte *ptr, Emchar x);
504 INLINE Bytecount 505 INLINE_HEADER Bytecount
505 set_charptr_emchar (Bufbyte *ptr, Emchar x) 506 set_charptr_emchar (Bufbyte *ptr, Emchar x)
506 { 507 {
507 return !CHAR_MULTIBYTE_P (x) ? 508 return !CHAR_MULTIBYTE_P (x) ?
508 simple_set_charptr_emchar (ptr, x) : 509 simple_set_charptr_emchar (ptr, x) :
509 non_ascii_set_charptr_emchar (ptr, x); 510 non_ascii_set_charptr_emchar (ptr, x);
510 } 511 }
511 512
512 INLINE Bytecount charptr_copy_char (const Bufbyte *ptr, Bufbyte *ptr2); 513 INLINE_HEADER Bytecount
513 INLINE Bytecount 514 charptr_copy_char (const Bufbyte *ptr, Bufbyte *ptr2);
515 INLINE_HEADER Bytecount
514 charptr_copy_char (const Bufbyte *ptr, Bufbyte *ptr2) 516 charptr_copy_char (const Bufbyte *ptr, Bufbyte *ptr2)
515 { 517 {
516 return BYTE_ASCII_P (*ptr) ? 518 return BYTE_ASCII_P (*ptr) ?
517 simple_charptr_copy_char (ptr, ptr2) : 519 simple_charptr_copy_char (ptr, ptr2) :
518 non_ascii_charptr_copy_char (ptr, ptr2); 520 non_ascii_charptr_copy_char (ptr, ptr2);
536 538
537 #ifdef MULE 539 #ifdef MULE
538 540
539 int non_ascii_valid_char_p (Emchar ch); 541 int non_ascii_valid_char_p (Emchar ch);
540 542
541 INLINE int valid_char_p (Emchar ch); 543 INLINE_HEADER int valid_char_p (Emchar ch);
542 INLINE int 544 INLINE_HEADER int
543 valid_char_p (Emchar ch) 545 valid_char_p (Emchar ch)
544 { 546 {
545 return ((unsigned int) (ch) <= 0xff) || non_ascii_valid_char_p (ch); 547 return ((unsigned int) (ch) <= 0xff) || non_ascii_valid_char_p (ch);
546 } 548 }
547 549
555 557
556 #define CHAR_OR_CHAR_INTP(x) (CHARP (x) || CHAR_INTP (x)) 558 #define CHAR_OR_CHAR_INTP(x) (CHARP (x) || CHAR_INTP (x))
557 559
558 #ifdef ERROR_CHECK_TYPECHECK 560 #ifdef ERROR_CHECK_TYPECHECK
559 561
560 INLINE Emchar XCHAR_OR_CHAR_INT (Lisp_Object obj); 562 INLINE_HEADER Emchar XCHAR_OR_CHAR_INT (Lisp_Object obj);
561 INLINE Emchar 563 INLINE_HEADER Emchar
562 XCHAR_OR_CHAR_INT (Lisp_Object obj) 564 XCHAR_OR_CHAR_INT (Lisp_Object obj)
563 { 565 {
564 assert (CHAR_OR_CHAR_INTP (obj)); 566 assert (CHAR_OR_CHAR_INTP (obj));
565 return CHARP (obj) ? XCHAR (obj) : XINT (obj); 567 return CHARP (obj) ? XCHAR (obj) : XINT (obj);
566 } 568 }
620 /*----------------------------------------------------------------------*/ 622 /*----------------------------------------------------------------------*/
621 /* Converting between positions and addresses */ 623 /* Converting between positions and addresses */
622 /*----------------------------------------------------------------------*/ 624 /*----------------------------------------------------------------------*/
623 625
624 /* Convert the address of a byte in the buffer into a position. */ 626 /* Convert the address of a byte in the buffer into a position. */
625 INLINE Bytind BI_BUF_PTR_BYTE_POS (struct buffer *buf, Bufbyte *ptr); 627 INLINE_HEADER Bytind BI_BUF_PTR_BYTE_POS (struct buffer *buf, Bufbyte *ptr);
626 INLINE Bytind 628 INLINE_HEADER Bytind
627 BI_BUF_PTR_BYTE_POS (struct buffer *buf, Bufbyte *ptr) 629 BI_BUF_PTR_BYTE_POS (struct buffer *buf, Bufbyte *ptr)
628 { 630 {
629 return (ptr - buf->text->beg + 1 631 return (ptr - buf->text->beg + 1
630 - ((ptr - buf->text->beg + 1) > buf->text->gpt 632 - ((ptr - buf->text->beg + 1) > buf->text->gpt
631 ? buf->text->gap_size : 0)); 633 ? buf->text->gap_size : 0));
633 635
634 #define BUF_PTR_BYTE_POS(buf, ptr) \ 636 #define BUF_PTR_BYTE_POS(buf, ptr) \
635 bytind_to_bufpos (buf, BI_BUF_PTR_BYTE_POS (buf, ptr)) 637 bytind_to_bufpos (buf, BI_BUF_PTR_BYTE_POS (buf, ptr))
636 638
637 /* Address of byte at position POS in buffer. */ 639 /* Address of byte at position POS in buffer. */
638 INLINE Bufbyte * BI_BUF_BYTE_ADDRESS (struct buffer *buf, Bytind pos); 640 INLINE_HEADER Bufbyte * BI_BUF_BYTE_ADDRESS (struct buffer *buf, Bytind pos);
639 INLINE Bufbyte * 641 INLINE_HEADER Bufbyte *
640 BI_BUF_BYTE_ADDRESS (struct buffer *buf, Bytind pos) 642 BI_BUF_BYTE_ADDRESS (struct buffer *buf, Bytind pos)
641 { 643 {
642 return (buf->text->beg + 644 return (buf->text->beg +
643 ((pos >= buf->text->gpt ? (pos + buf->text->gap_size) : pos) 645 ((pos >= buf->text->gpt ? (pos + buf->text->gap_size) : pos)
644 - 1)); 646 - 1));
646 648
647 #define BUF_BYTE_ADDRESS(buf, pos) \ 649 #define BUF_BYTE_ADDRESS(buf, pos) \
648 BI_BUF_BYTE_ADDRESS (buf, bufpos_to_bytind (buf, pos)) 650 BI_BUF_BYTE_ADDRESS (buf, bufpos_to_bytind (buf, pos))
649 651
650 /* Address of byte before position POS in buffer. */ 652 /* Address of byte before position POS in buffer. */
651 INLINE Bufbyte * BI_BUF_BYTE_ADDRESS_BEFORE (struct buffer *buf, Bytind pos); 653 INLINE_HEADER Bufbyte * BI_BUF_BYTE_ADDRESS_BEFORE (struct buffer *buf, Bytind pos);
652 INLINE Bufbyte * 654 INLINE_HEADER Bufbyte *
653 BI_BUF_BYTE_ADDRESS_BEFORE (struct buffer *buf, Bytind pos) 655 BI_BUF_BYTE_ADDRESS_BEFORE (struct buffer *buf, Bytind pos)
654 { 656 {
655 return (buf->text->beg + 657 return (buf->text->beg +
656 ((pos > buf->text->gpt ? (pos + buf->text->gap_size) : pos) 658 ((pos > buf->text->gpt ? (pos + buf->text->gap_size) : pos)
657 - 2)); 659 - 2));
662 664
663 /*----------------------------------------------------------------------*/ 665 /*----------------------------------------------------------------------*/
664 /* Converting between byte indices and memory indices */ 666 /* Converting between byte indices and memory indices */
665 /*----------------------------------------------------------------------*/ 667 /*----------------------------------------------------------------------*/
666 668
667 INLINE int valid_memind_p (struct buffer *buf, Memind x); 669 INLINE_HEADER int valid_memind_p (struct buffer *buf, Memind x);
668 INLINE int 670 INLINE_HEADER int
669 valid_memind_p (struct buffer *buf, Memind x) 671 valid_memind_p (struct buffer *buf, Memind x)
670 { 672 {
671 return ((x >= 1 && x <= (Memind) buf->text->gpt) || 673 return ((x >= 1 && x <= (Memind) buf->text->gpt) ||
672 (x > (Memind) (buf->text->gpt + buf->text->gap_size) && 674 (x > (Memind) (buf->text->gpt + buf->text->gap_size) &&
673 x <= (Memind) (buf->text->z + buf->text->gap_size))); 675 x <= (Memind) (buf->text->z + buf->text->gap_size)));
674 } 676 }
675 677
676 INLINE Memind bytind_to_memind (struct buffer *buf, Bytind x); 678 INLINE_HEADER Memind bytind_to_memind (struct buffer *buf, Bytind x);
677 INLINE Memind 679 INLINE_HEADER Memind
678 bytind_to_memind (struct buffer *buf, Bytind x) 680 bytind_to_memind (struct buffer *buf, Bytind x)
679 { 681 {
680 return (Memind) ((x > buf->text->gpt) ? (x + buf->text->gap_size) : x); 682 return (Memind) ((x > buf->text->gpt) ? (x + buf->text->gap_size) : x);
681 } 683 }
682 684
683 685
684 INLINE Bytind memind_to_bytind (struct buffer *buf, Memind x); 686 INLINE_HEADER Bytind memind_to_bytind (struct buffer *buf, Memind x);
685 INLINE Bytind 687 INLINE_HEADER Bytind
686 memind_to_bytind (struct buffer *buf, Memind x) 688 memind_to_bytind (struct buffer *buf, Memind x)
687 { 689 {
688 #ifdef ERROR_CHECK_BUFPOS 690 #ifdef ERROR_CHECK_BUFPOS
689 assert (valid_memind_p (buf, x)); 691 assert (valid_memind_p (buf, x));
690 #endif 692 #endif
900 the correct side of the gap */ \ 902 the correct side of the gap */ \
901 (x)--; \ 903 (x)--; \
902 VALIDATE_BYTIND_BACKWARD (buf, x); \ 904 VALIDATE_BYTIND_BACKWARD (buf, x); \
903 } while (0) 905 } while (0)
904 906
905 INLINE Bytind prev_bytind (struct buffer *buf, Bytind x); 907 INLINE_HEADER Bytind prev_bytind (struct buffer *buf, Bytind x);
906 INLINE Bytind 908 INLINE_HEADER Bytind
907 prev_bytind (struct buffer *buf, Bytind x) 909 prev_bytind (struct buffer *buf, Bytind x)
908 { 910 {
909 DEC_BYTIND (buf, x); 911 DEC_BYTIND (buf, x);
910 return x; 912 return x;
911 } 913 }
912 914
913 INLINE Bytind next_bytind (struct buffer *buf, Bytind x); 915 INLINE_HEADER Bytind next_bytind (struct buffer *buf, Bytind x);
914 INLINE Bytind 916 INLINE_HEADER Bytind
915 next_bytind (struct buffer *buf, Bytind x) 917 next_bytind (struct buffer *buf, Bytind x)
916 { 918 {
917 INC_BYTIND (buf, x); 919 INC_BYTIND (buf, x);
918 return x; 920 return x;
919 } 921 }
971 64K for width-three characters. 973 64K for width-three characters.
972 */ 974 */
973 975
974 extern short three_to_one_table[]; 976 extern short three_to_one_table[];
975 977
976 INLINE int real_bufpos_to_bytind (struct buffer *buf, Bufpos x); 978 INLINE_HEADER int real_bufpos_to_bytind (struct buffer *buf, Bufpos x);
977 INLINE int 979 INLINE_HEADER int
978 real_bufpos_to_bytind (struct buffer *buf, Bufpos x) 980 real_bufpos_to_bytind (struct buffer *buf, Bufpos x)
979 { 981 {
980 if (x >= buf->text->mule_bufmin && x <= buf->text->mule_bufmax) 982 if (x >= buf->text->mule_bufmin && x <= buf->text->mule_bufmax)
981 return (buf->text->mule_bytmin + 983 return (buf->text->mule_bytmin +
982 ((x - buf->text->mule_bufmin) << buf->text->mule_shifter) + 984 ((x - buf->text->mule_bufmin) << buf->text->mule_shifter) +
983 (buf->text->mule_three_p ? (x - buf->text->mule_bufmin) : 0)); 985 (buf->text->mule_three_p ? (x - buf->text->mule_bufmin) : 0));
984 else 986 else
985 return bufpos_to_bytind_func (buf, x); 987 return bufpos_to_bytind_func (buf, x);
986 } 988 }
987 989
988 INLINE int real_bytind_to_bufpos (struct buffer *buf, Bytind x); 990 INLINE_HEADER int real_bytind_to_bufpos (struct buffer *buf, Bytind x);
989 INLINE int 991 INLINE_HEADER int
990 real_bytind_to_bufpos (struct buffer *buf, Bytind x) 992 real_bytind_to_bufpos (struct buffer *buf, Bytind x)
991 { 993 {
992 if (x >= buf->text->mule_bytmin && x <= buf->text->mule_bytmax) 994 if (x >= buf->text->mule_bytmin && x <= buf->text->mule_bytmax)
993 return (buf->text->mule_bufmin + 995 return (buf->text->mule_bufmin +
994 ((buf->text->mule_three_p 996 ((buf->text->mule_three_p
1265 (dfc_slbta, BUF_PT (dfc_slbta), 0); \ 1267 (dfc_slbta, BUF_PT (dfc_slbta), 0); \
1266 dfc_simplified_sink_type = DFC_TYPE_LISP_LSTREAM; \ 1268 dfc_simplified_sink_type = DFC_TYPE_LISP_LSTREAM; \
1267 } while (0) 1269 } while (0)
1268 1270
1269 /* Assign to the `sink' lvalue(s) using the converted data. */ 1271 /* Assign to the `sink' lvalue(s) using the converted data. */
1272 typedef union { char c; void *p; } *dfc_aliasing_voidpp;
1270 #define DFC_ALLOCA_USE_CONVERTED_DATA(sink) do { \ 1273 #define DFC_ALLOCA_USE_CONVERTED_DATA(sink) do { \
1271 void * dfc_sink_ret = alloca (dfc_sink.data.len + 1); \ 1274 void * dfc_sink_ret = alloca (dfc_sink.data.len + 1); \
1272 memcpy (dfc_sink_ret, dfc_sink.data.ptr, dfc_sink.data.len + 1); \ 1275 memcpy (dfc_sink_ret, dfc_sink.data.ptr, dfc_sink.data.len + 1); \
1273 (DFC_CPP_CAR sink) = (unsigned char *) dfc_sink_ret; \ 1276 ((dfc_aliasing_voidpp) &(DFC_CPP_CAR sink))->p = dfc_sink_ret; \
1274 (DFC_CPP_CDR sink) = dfc_sink.data.len; \ 1277 (DFC_CPP_CDR sink) = dfc_sink.data.len; \
1275 } while (0) 1278 } while (0)
1276 #define DFC_MALLOC_USE_CONVERTED_DATA(sink) do { \ 1279 #define DFC_MALLOC_USE_CONVERTED_DATA(sink) do { \
1277 void * dfc_sink_ret = xmalloc (dfc_sink.data.len + 1); \ 1280 void * dfc_sink_ret = xmalloc (dfc_sink.data.len + 1); \
1278 memcpy (dfc_sink_ret, dfc_sink.data.ptr, dfc_sink.data.len + 1); \ 1281 memcpy (dfc_sink_ret, dfc_sink.data.ptr, dfc_sink.data.len + 1); \
1279 (DFC_CPP_CAR sink) = (unsigned char *) dfc_sink_ret; \ 1282 ((dfc_aliasing_voidpp) &(DFC_CPP_CAR sink))->p = dfc_sink_ret; \
1280 (DFC_CPP_CDR sink) = dfc_sink.data.len; \ 1283 (DFC_CPP_CDR sink) = dfc_sink.data.len; \
1281 } while (0) 1284 } while (0)
1282 #define DFC_C_STRING_ALLOCA_USE_CONVERTED_DATA(sink) do { \ 1285 #define DFC_C_STRING_ALLOCA_USE_CONVERTED_DATA(sink) do { \
1283 void * dfc_sink_ret = alloca (dfc_sink.data.len + 1); \ 1286 void * dfc_sink_ret = alloca (dfc_sink.data.len + 1); \
1284 memcpy (dfc_sink_ret, dfc_sink.data.ptr, dfc_sink.data.len + 1); \ 1287 memcpy (dfc_sink_ret, dfc_sink.data.ptr, dfc_sink.data.len + 1); \
1702 TRT_TABLE_AS_STRING (buf->case_canon_table) 1705 TRT_TABLE_AS_STRING (buf->case_canon_table)
1703 #define MIRROR_EQV_TABLE_AS_STRING(buf) \ 1706 #define MIRROR_EQV_TABLE_AS_STRING(buf) \
1704 TRT_TABLE_AS_STRING (buf->case_eqv_table) 1707 TRT_TABLE_AS_STRING (buf->case_eqv_table)
1705 #endif 1708 #endif
1706 1709
1707 INLINE Emchar TRT_TABLE_OF (Lisp_Object trt, Emchar c); 1710 INLINE_HEADER Emchar TRT_TABLE_OF (Lisp_Object trt, Emchar c);
1708 INLINE Emchar 1711 INLINE_HEADER Emchar
1709 TRT_TABLE_OF (Lisp_Object trt, Emchar c) 1712 TRT_TABLE_OF (Lisp_Object trt, Emchar c)
1710 { 1713 {
1711 return IN_TRT_TABLE_DOMAIN (c) ? TRT_TABLE_CHAR_1 (trt, c) : c; 1714 return IN_TRT_TABLE_DOMAIN (c) ? TRT_TABLE_CHAR_1 (trt, c) : c;
1712 } 1715 }
1713 1716
1715 #define DOWNCASE_TABLE_OF(buf, c) TRT_TABLE_OF (buf->downcase_table, c) 1718 #define DOWNCASE_TABLE_OF(buf, c) TRT_TABLE_OF (buf->downcase_table, c)
1716 #define UPCASE_TABLE_OF(buf, c) TRT_TABLE_OF (buf->upcase_table, c) 1719 #define UPCASE_TABLE_OF(buf, c) TRT_TABLE_OF (buf->upcase_table, c)
1717 1720
1718 /* 1 if CH is upper case. */ 1721 /* 1 if CH is upper case. */
1719 1722
1720 INLINE int UPPERCASEP (struct buffer *buf, Emchar ch); 1723 INLINE_HEADER int UPPERCASEP (struct buffer *buf, Emchar ch);
1721 INLINE int 1724 INLINE_HEADER int
1722 UPPERCASEP (struct buffer *buf, Emchar ch) 1725 UPPERCASEP (struct buffer *buf, Emchar ch)
1723 { 1726 {
1724 return DOWNCASE_TABLE_OF (buf, ch) != ch; 1727 return DOWNCASE_TABLE_OF (buf, ch) != ch;
1725 } 1728 }
1726 1729
1727 /* 1 if CH is lower case. */ 1730 /* 1 if CH is lower case. */
1728 1731
1729 INLINE int LOWERCASEP (struct buffer *buf, Emchar ch); 1732 INLINE_HEADER int LOWERCASEP (struct buffer *buf, Emchar ch);
1730 INLINE int 1733 INLINE_HEADER int
1731 LOWERCASEP (struct buffer *buf, Emchar ch) 1734 LOWERCASEP (struct buffer *buf, Emchar ch)
1732 { 1735 {
1733 return (UPCASE_TABLE_OF (buf, ch) != ch && 1736 return (UPCASE_TABLE_OF (buf, ch) != ch &&
1734 DOWNCASE_TABLE_OF (buf, ch) == ch); 1737 DOWNCASE_TABLE_OF (buf, ch) == ch);
1735 } 1738 }
1736 1739
1737 /* 1 if CH is neither upper nor lower case. */ 1740 /* 1 if CH is neither upper nor lower case. */
1738 1741
1739 INLINE int NOCASEP (struct buffer *buf, Emchar ch); 1742 INLINE_HEADER int NOCASEP (struct buffer *buf, Emchar ch);
1740 INLINE int 1743 INLINE_HEADER int
1741 NOCASEP (struct buffer *buf, Emchar ch) 1744 NOCASEP (struct buffer *buf, Emchar ch)
1742 { 1745 {
1743 return UPCASE_TABLE_OF (buf, ch) == ch; 1746 return UPCASE_TABLE_OF (buf, ch) == ch;
1744 } 1747 }
1745 1748
1746 /* Upcase a character, or make no change if that cannot be done. */ 1749 /* Upcase a character, or make no change if that cannot be done. */
1747 1750
1748 INLINE Emchar UPCASE (struct buffer *buf, Emchar ch); 1751 INLINE_HEADER Emchar UPCASE (struct buffer *buf, Emchar ch);
1749 INLINE Emchar 1752 INLINE_HEADER Emchar
1750 UPCASE (struct buffer *buf, Emchar ch) 1753 UPCASE (struct buffer *buf, Emchar ch)
1751 { 1754 {
1752 return (DOWNCASE_TABLE_OF (buf, ch) == ch) ? UPCASE_TABLE_OF (buf, ch) : ch; 1755 return (DOWNCASE_TABLE_OF (buf, ch) == ch) ? UPCASE_TABLE_OF (buf, ch) : ch;
1753 } 1756 }
1754 1757