Mercurial > hg > xemacs-beta
comparison src/buffer.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 | 1ccc32a20af4 |
comparison
equal
deleted
inserted
replaced
443:a8296e22da4e | 444:576fb035e263 |
---|---|
406 the character it's moving over. */ | 406 the character it's moving over. */ |
407 | 407 |
408 #define REAL_INC_CHARPTR(ptr) \ | 408 #define REAL_INC_CHARPTR(ptr) \ |
409 ((void) ((ptr) += REP_BYTES_BY_FIRST_BYTE (* (unsigned char *) (ptr)))) | 409 ((void) ((ptr) += REP_BYTES_BY_FIRST_BYTE (* (unsigned char *) (ptr)))) |
410 | 410 |
411 #define REAL_INC_CHARBYTIND(ptr,pos) \ | 411 #define REAL_INC_CHARBYTIND(ptr, pos) \ |
412 (pos += REP_BYTES_BY_FIRST_BYTE (* (unsigned char *) (ptr))) | 412 (pos += REP_BYTES_BY_FIRST_BYTE (* (unsigned char *) (ptr))) |
413 | 413 |
414 #define REAL_DEC_CHARPTR(ptr) do { \ | 414 #define REAL_DEC_CHARPTR(ptr) do { \ |
415 (ptr)--; \ | 415 (ptr)--; \ |
416 } while (!VALID_CHARPTR_P (ptr)) | 416 } while (!VALID_CHARPTR_P (ptr)) |
419 #define INC_CHARPTR(ptr) do { \ | 419 #define INC_CHARPTR(ptr) do { \ |
420 ASSERT_VALID_CHARPTR (ptr); \ | 420 ASSERT_VALID_CHARPTR (ptr); \ |
421 REAL_INC_CHARPTR (ptr); \ | 421 REAL_INC_CHARPTR (ptr); \ |
422 } while (0) | 422 } while (0) |
423 | 423 |
424 #define INC_CHARBYTIND(ptr,pos) do { \ | 424 #define INC_CHARBYTIND(ptr, pos) do { \ |
425 ASSERT_VALID_CHARPTR (ptr); \ | 425 ASSERT_VALID_CHARPTR (ptr); \ |
426 REAL_INC_CHARBYTIND (ptr,pos); \ | 426 REAL_INC_CHARBYTIND (ptr, pos); \ |
427 } while (0) | 427 } while (0) |
428 | 428 |
429 #define DEC_CHARPTR(ptr) do { \ | 429 #define DEC_CHARPTR(ptr) do { \ |
430 const Bufbyte *dc_ptr1 = (ptr); \ | 430 const Bufbyte *dc_ptr1 = (ptr); \ |
431 const Bufbyte *dc_ptr2 = dc_ptr1; \ | 431 const Bufbyte *dc_ptr2 = dc_ptr1; \ |
432 REAL_DEC_CHARPTR (dc_ptr2); \ | 432 REAL_DEC_CHARPTR (dc_ptr2); \ |
433 assert (dc_ptr1 - dc_ptr2 == \ | 433 assert (dc_ptr1 - dc_ptr2 == \ |
434 REP_BYTES_BY_FIRST_BYTE (*dc_ptr2)); \ | 434 REP_BYTES_BY_FIRST_BYTE (*dc_ptr2)); \ |
435 (ptr) = dc_ptr2; \ | 435 (ptr) = (Bufbyte *) dc_ptr2; \ |
436 } while (0) | 436 } while (0) |
437 | 437 |
438 #else /* ! ERROR_CHECK_BUFPOS */ | 438 #else /* ! ERROR_CHECK_BUFPOS */ |
439 #define INC_CHARBYTIND(ptr,pos) REAL_INC_CHARBYTIND (ptr,pos) | 439 #define INC_CHARBYTIND(ptr, pos) REAL_INC_CHARBYTIND (ptr, pos) |
440 #define INC_CHARPTR(ptr) REAL_INC_CHARPTR (ptr) | 440 #define INC_CHARPTR(ptr) REAL_INC_CHARPTR (ptr) |
441 #define DEC_CHARPTR(ptr) REAL_DEC_CHARPTR (ptr) | 441 #define DEC_CHARPTR(ptr) REAL_DEC_CHARPTR (ptr) |
442 #endif /* ! ERROR_CHECK_BUFPOS */ | 442 #endif /* ! ERROR_CHECK_BUFPOS */ |
443 | 443 |
444 #ifdef MULE | 444 #ifdef MULE |
488 | 488 |
489 #ifdef MULE | 489 #ifdef MULE |
490 | 490 |
491 Emchar non_ascii_charptr_emchar (const Bufbyte *ptr); | 491 Emchar non_ascii_charptr_emchar (const Bufbyte *ptr); |
492 Bytecount non_ascii_set_charptr_emchar (Bufbyte *ptr, Emchar c); | 492 Bytecount non_ascii_set_charptr_emchar (Bufbyte *ptr, Emchar c); |
493 Bytecount non_ascii_charptr_copy_char (const Bufbyte *ptr, Bufbyte *ptr2); | 493 Bytecount non_ascii_charptr_copy_char (const Bufbyte *src, Bufbyte *dst); |
494 | 494 |
495 INLINE_HEADER Emchar charptr_emchar (const Bufbyte *ptr); | 495 INLINE_HEADER Emchar charptr_emchar (const Bufbyte *ptr); |
496 INLINE_HEADER Emchar | 496 INLINE_HEADER Emchar |
497 charptr_emchar (const Bufbyte *ptr) | 497 charptr_emchar (const Bufbyte *ptr) |
498 { | 498 { |
508 return !CHAR_MULTIBYTE_P (x) ? | 508 return !CHAR_MULTIBYTE_P (x) ? |
509 simple_set_charptr_emchar (ptr, x) : | 509 simple_set_charptr_emchar (ptr, x) : |
510 non_ascii_set_charptr_emchar (ptr, x); | 510 non_ascii_set_charptr_emchar (ptr, x); |
511 } | 511 } |
512 | 512 |
513 /* Copy the character pointed to by SRC into DST. | |
514 Return the number of bytes copied. */ | |
513 INLINE_HEADER Bytecount | 515 INLINE_HEADER Bytecount |
514 charptr_copy_char (const Bufbyte *ptr, Bufbyte *ptr2); | 516 charptr_copy_char (const Bufbyte *src, Bufbyte *dst); |
515 INLINE_HEADER Bytecount | 517 INLINE_HEADER Bytecount |
516 charptr_copy_char (const Bufbyte *ptr, Bufbyte *ptr2) | 518 charptr_copy_char (const Bufbyte *src, Bufbyte *dst) |
517 { | 519 { |
518 return BYTE_ASCII_P (*ptr) ? | 520 return BYTE_ASCII_P (*src) ? |
519 simple_charptr_copy_char (ptr, ptr2) : | 521 simple_charptr_copy_char (src, dst) : |
520 non_ascii_charptr_copy_char (ptr, ptr2); | 522 non_ascii_charptr_copy_char (src, dst); |
521 } | 523 } |
522 | 524 |
523 #else /* not MULE */ | 525 #else /* not MULE */ |
524 | 526 |
525 # define charptr_emchar(ptr) simple_charptr_emchar (ptr) | 527 # define charptr_emchar(ptr) simple_charptr_emchar (ptr) |
555 | 557 |
556 #define CHAR_INTP(x) (INTP (x) && valid_char_p (XINT (x))) | 558 #define CHAR_INTP(x) (INTP (x) && valid_char_p (XINT (x))) |
557 | 559 |
558 #define CHAR_OR_CHAR_INTP(x) (CHARP (x) || CHAR_INTP (x)) | 560 #define CHAR_OR_CHAR_INTP(x) (CHARP (x) || CHAR_INTP (x)) |
559 | 561 |
560 #ifdef ERROR_CHECK_TYPECHECK | |
561 | |
562 INLINE_HEADER Emchar XCHAR_OR_CHAR_INT (Lisp_Object obj); | 562 INLINE_HEADER Emchar XCHAR_OR_CHAR_INT (Lisp_Object obj); |
563 INLINE_HEADER Emchar | 563 INLINE_HEADER Emchar |
564 XCHAR_OR_CHAR_INT (Lisp_Object obj) | 564 XCHAR_OR_CHAR_INT (Lisp_Object obj) |
565 { | 565 { |
566 assert (CHAR_OR_CHAR_INTP (obj)); | |
567 return CHARP (obj) ? XCHAR (obj) : XINT (obj); | 566 return CHARP (obj) ? XCHAR (obj) : XINT (obj); |
568 } | 567 } |
569 | |
570 #else | |
571 | |
572 #define XCHAR_OR_CHAR_INT(obj) (CHARP (obj) ? XCHAR (obj) : XINT (obj)) | |
573 | |
574 #endif | |
575 | 568 |
576 #define CHECK_CHAR_COERCE_INT(x) do { \ | 569 #define CHECK_CHAR_COERCE_INT(x) do { \ |
577 if (CHARP (x)) \ | 570 if (CHARP (x)) \ |
578 ; \ | 571 ; \ |
579 else if (CHAR_INTP (x)) \ | 572 else if (CHAR_INTP (x)) \ |
1061 The source or sink can be specified in one of these ways: | 1054 The source or sink can be specified in one of these ways: |
1062 | 1055 |
1063 DATA, (ptr, len), // input data is a fixed buffer of size len | 1056 DATA, (ptr, len), // input data is a fixed buffer of size len |
1064 ALLOCA, (ptr, len), // output data is in a alloca()ed buffer of size len | 1057 ALLOCA, (ptr, len), // output data is in a alloca()ed buffer of size len |
1065 MALLOC, (ptr, len), // output data is in a malloc()ed buffer of size len | 1058 MALLOC, (ptr, len), // output data is in a malloc()ed buffer of size len |
1066 C_STRING_ALLOCA, ptr, // equivalent to ALLOCA (ptr, len_ignored) on output. | 1059 C_STRING_ALLOCA, ptr, // equivalent to ALLOCA (ptr, len_ignored) on output |
1067 C_STRING_MALLOC, ptr, // equivalent to MALLOC (ptr, len_ignored) on output. | 1060 C_STRING_MALLOC, ptr, // equivalent to MALLOC (ptr, len_ignored) on output |
1068 C_STRING, ptr, // equivalent to DATA, (ptr, strlen (ptr) + 1) on input | 1061 C_STRING, ptr, // equivalent to DATA, (ptr, strlen (ptr) + 1) on input |
1069 LISP_STRING, string, // input or output is a Lisp_Object of type string | 1062 LISP_STRING, string, // input or output is a Lisp_Object of type string |
1070 LISP_BUFFER, buffer, // output is written to (point) in lisp buffer | 1063 LISP_BUFFER, buffer, // output is written to (point) in lisp buffer |
1071 LISP_LSTREAM, lstream, // input or output is a Lisp_Object of type lstream | 1064 LISP_LSTREAM, lstream, // input or output is a Lisp_Object of type lstream |
1072 LISP_OPAQUE, object, // input or output is a Lisp_Object of type opaque | 1065 LISP_OPAQUE, object, // input or output is a Lisp_Object of type opaque |
1785 | 1778 |
1786 /* Downcase a character, or make no change if that cannot be done. */ | 1779 /* Downcase a character, or make no change if that cannot be done. */ |
1787 | 1780 |
1788 #define DOWNCASE(buf, ch) DOWNCASE_TABLE_OF (buf, ch) | 1781 #define DOWNCASE(buf, ch) DOWNCASE_TABLE_OF (buf, ch) |
1789 | 1782 |
1783 /************************************************************************/ | |
1784 /* Lisp string representation convenience functions */ | |
1785 /************************************************************************/ | |
1786 /* Because the representation of internally formatted data is subject to change, | |
1787 It's bad style to do something like strcmp (XSTRING_DATA (s), "foo") | |
1788 Instead, use the portable: bufbyte_strcmp (XSTRING_DATA (s), "foo") | |
1789 or bufbyte_memcmp (XSTRING_DATA (s), "foo", 3) */ | |
1790 | |
1791 /* Like strcmp, except first arg points at internally formatted data, | |
1792 while the second points at a string of only ASCII chars. */ | |
1793 INLINE_HEADER int | |
1794 bufbyte_strcmp (const Bufbyte *bp, const char *ascii_string); | |
1795 INLINE_HEADER int | |
1796 bufbyte_strcmp (const Bufbyte *bp, const char *ascii_string) | |
1797 { | |
1798 #ifdef MULE | |
1799 while (1) | |
1800 { | |
1801 int diff; | |
1802 type_checking_assert (BYTE_ASCII_P (*ascii_string)); | |
1803 if ((diff = charptr_emchar (bp) - *(Bufbyte *) ascii_string) != 0) | |
1804 return diff; | |
1805 if (*ascii_string == '\0') | |
1806 return 0; | |
1807 ascii_string++; | |
1808 INC_CHARPTR (bp); | |
1809 } | |
1810 #else | |
1811 return strcmp ((char *)bp, ascii_string); | |
1812 #endif | |
1813 } | |
1814 | |
1815 | |
1816 /* Like memcmp, except first arg points at internally formatted data, | |
1817 while the second points at a string of only ASCII chars. */ | |
1818 INLINE_HEADER int | |
1819 bufbyte_memcmp (const Bufbyte *bp, const char *ascii_string, size_t len); | |
1820 INLINE_HEADER int | |
1821 bufbyte_memcmp (const Bufbyte *bp, const char *ascii_string, size_t len) | |
1822 { | |
1823 #ifdef MULE | |
1824 while (len--) | |
1825 { | |
1826 int diff = charptr_emchar (bp) - *(Bufbyte *) ascii_string; | |
1827 type_checking_assert (BYTE_ASCII_P (*ascii_string)); | |
1828 if (diff != 0) | |
1829 return diff; | |
1830 ascii_string++; | |
1831 INC_CHARPTR (bp); | |
1832 } | |
1833 return 0; | |
1834 #else | |
1835 return memcmp (bp, ascii_string, len); | |
1836 #endif | |
1837 } | |
1838 | |
1790 #endif /* INCLUDED_buffer_h_ */ | 1839 #endif /* INCLUDED_buffer_h_ */ |