Mercurial > hg > xemacs-beta
comparison src/buffer.h @ 398:74fd4e045ea6 r21-2-29
Import from CVS: tag r21-2-29
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:13:30 +0200 |
parents | 4af0ddfb7c5b |
children | 2f8bb876ab1d |
comparison
equal
deleted
inserted
replaced
397:f4aeb21a5bad | 398:74fd4e045ea6 |
---|---|
27 FSF: long ago. | 27 FSF: long ago. |
28 JWZ: separated out bufslots.h, early in Lemacs. | 28 JWZ: separated out bufslots.h, early in Lemacs. |
29 Ben Wing: almost completely rewritten for Mule, 19.12. | 29 Ben Wing: almost completely rewritten for Mule, 19.12. |
30 */ | 30 */ |
31 | 31 |
32 #ifndef _XEMACS_BUFFER_H_ | 32 #ifndef INCLUDED_buffer_h_ |
33 #define _XEMACS_BUFFER_H_ | 33 #define INCLUDED_buffer_h_ |
34 | 34 |
35 #ifdef MULE | 35 #ifdef MULE |
36 #include "mule-charset.h" | 36 #include "mule-charset.h" |
37 #endif | 37 #endif |
38 | 38 |
164 #endif /* REGION_CACHE_NEEDS_WORK */ | 164 #endif /* REGION_CACHE_NEEDS_WORK */ |
165 | 165 |
166 /* The markers that refer to this buffer. This is actually a single | 166 /* The markers that refer to this buffer. This is actually a single |
167 marker -- successive elements in its marker `chain' are the other | 167 marker -- successive elements in its marker `chain' are the other |
168 markers referring to this buffer */ | 168 markers referring to this buffer */ |
169 struct Lisp_Marker *markers; | 169 Lisp_Marker *markers; |
170 | 170 |
171 /* The buffer's extent info. This is its own type, an extent-info | 171 /* The buffer's extent info. This is its own type, an extent-info |
172 object (done this way for ease in marking / finalizing). */ | 172 object (done this way for ease in marking / finalizing). */ |
173 Lisp_Object extent_info; | 173 Lisp_Object extent_info; |
174 | 174 |
217 | 217 |
218 DECLARE_LRECORD (buffer, struct buffer); | 218 DECLARE_LRECORD (buffer, struct buffer); |
219 #define XBUFFER(x) XRECORD (x, buffer, struct buffer) | 219 #define XBUFFER(x) XRECORD (x, buffer, struct buffer) |
220 #define XSETBUFFER(x, p) XSETRECORD (x, p, buffer) | 220 #define XSETBUFFER(x, p) XSETRECORD (x, p, buffer) |
221 #define BUFFERP(x) RECORDP (x, buffer) | 221 #define BUFFERP(x) RECORDP (x, buffer) |
222 #define GC_BUFFERP(x) GC_RECORDP (x, buffer) | |
223 #define CHECK_BUFFER(x) CHECK_RECORD (x, buffer) | 222 #define CHECK_BUFFER(x) CHECK_RECORD (x, buffer) |
224 #define CONCHECK_BUFFER(x) CONCHECK_RECORD (x, buffer) | 223 #define CONCHECK_BUFFER(x) CONCHECK_RECORD (x, buffer) |
225 | 224 |
226 #define BUFFER_LIVE_P(b) (!NILP ((b)->name)) | 225 #define BUFFER_LIVE_P(b) (!NILP ((b)->name)) |
227 | 226 |
407 the character it's moving over. */ | 406 the character it's moving over. */ |
408 | 407 |
409 #define REAL_INC_CHARPTR(ptr) \ | 408 #define REAL_INC_CHARPTR(ptr) \ |
410 ((void) ((ptr) += REP_BYTES_BY_FIRST_BYTE (* (unsigned char *) (ptr)))) | 409 ((void) ((ptr) += REP_BYTES_BY_FIRST_BYTE (* (unsigned char *) (ptr)))) |
411 | 410 |
411 #define REAL_INC_CHARBYTIND(ptr,pos) \ | |
412 (pos += REP_BYTES_BY_FIRST_BYTE (* (unsigned char *) (ptr))) | |
413 | |
412 #define REAL_DEC_CHARPTR(ptr) do { \ | 414 #define REAL_DEC_CHARPTR(ptr) do { \ |
413 (ptr)--; \ | 415 (ptr)--; \ |
414 } while (!VALID_CHARPTR_P (ptr)) | 416 } while (!VALID_CHARPTR_P (ptr)) |
415 | 417 |
416 #ifdef ERROR_CHECK_BUFPOS | 418 #ifdef ERROR_CHECK_BUFPOS |
417 #define INC_CHARPTR(ptr) do { \ | 419 #define INC_CHARPTR(ptr) do { \ |
418 ASSERT_VALID_CHARPTR (ptr); \ | 420 ASSERT_VALID_CHARPTR (ptr); \ |
419 REAL_INC_CHARPTR (ptr); \ | 421 REAL_INC_CHARPTR (ptr); \ |
420 } while (0) | 422 } while (0) |
421 | 423 |
424 #define INC_CHARBYTIND(ptr,pos) do { \ | |
425 ASSERT_VALID_CHARPTR (ptr); \ | |
426 REAL_INC_CHARBYTIND (ptr,pos); \ | |
427 } while (0) | |
428 | |
422 #define DEC_CHARPTR(ptr) do { \ | 429 #define DEC_CHARPTR(ptr) do { \ |
423 CONST Bufbyte *dc_ptr1 = (ptr); \ | 430 const Bufbyte *dc_ptr1 = (ptr); \ |
424 CONST Bufbyte *dc_ptr2 = dc_ptr1; \ | 431 const Bufbyte *dc_ptr2 = dc_ptr1; \ |
425 REAL_DEC_CHARPTR (dc_ptr2); \ | 432 REAL_DEC_CHARPTR (dc_ptr2); \ |
426 assert (dc_ptr1 - dc_ptr2 == \ | 433 assert (dc_ptr1 - dc_ptr2 == \ |
427 REP_BYTES_BY_FIRST_BYTE (*dc_ptr2)); \ | 434 REP_BYTES_BY_FIRST_BYTE (*dc_ptr2)); \ |
428 (ptr) = dc_ptr2; \ | 435 (ptr) = dc_ptr2; \ |
429 } while (0) | 436 } while (0) |
430 | 437 |
431 #else /* ! ERROR_CHECK_BUFPOS */ | 438 #else /* ! ERROR_CHECK_BUFPOS */ |
439 #define INC_CHARBYTIND(ptr,pos) REAL_INC_CHARBYTIND (ptr,pos) | |
432 #define INC_CHARPTR(ptr) REAL_INC_CHARPTR (ptr) | 440 #define INC_CHARPTR(ptr) REAL_INC_CHARPTR (ptr) |
433 #define DEC_CHARPTR(ptr) REAL_DEC_CHARPTR (ptr) | 441 #define DEC_CHARPTR(ptr) REAL_DEC_CHARPTR (ptr) |
434 #endif /* ! ERROR_CHECK_BUFPOS */ | 442 #endif /* ! ERROR_CHECK_BUFPOS */ |
435 | 443 |
436 #ifdef MULE | 444 #ifdef MULE |
460 /* -------------------------------------------------------------- */ | 468 /* -------------------------------------------------------------- */ |
461 /* (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 */ |
462 /* section of internally-formatted text */ | 470 /* section of internally-formatted text */ |
463 /* -------------------------------------------------------------- */ | 471 /* -------------------------------------------------------------- */ |
464 | 472 |
465 INLINE CONST Bufbyte *charptr_n_addr (CONST Bufbyte *ptr, Charcount offset); | 473 INLINE const Bufbyte *charptr_n_addr (const Bufbyte *ptr, Charcount offset); |
466 INLINE CONST Bufbyte * | 474 INLINE const Bufbyte * |
467 charptr_n_addr (CONST Bufbyte *ptr, Charcount offset) | 475 charptr_n_addr (const Bufbyte *ptr, Charcount offset) |
468 { | 476 { |
469 return ptr + charcount_to_bytecount (ptr, offset); | 477 return ptr + charcount_to_bytecount (ptr, offset); |
470 } | 478 } |
471 | 479 |
472 /* -------------------------------------------------------------------- */ | 480 /* -------------------------------------------------------------------- */ |
477 #define simple_set_charptr_emchar(ptr, x) ((ptr)[0] = (Bufbyte) (x), 1) | 485 #define simple_set_charptr_emchar(ptr, x) ((ptr)[0] = (Bufbyte) (x), 1) |
478 #define simple_charptr_copy_char(ptr, ptr2) ((ptr2)[0] = *(ptr), 1) | 486 #define simple_charptr_copy_char(ptr, ptr2) ((ptr2)[0] = *(ptr), 1) |
479 | 487 |
480 #ifdef MULE | 488 #ifdef MULE |
481 | 489 |
482 Emchar non_ascii_charptr_emchar (CONST Bufbyte *ptr); | 490 Emchar non_ascii_charptr_emchar (const Bufbyte *ptr); |
483 Bytecount non_ascii_set_charptr_emchar (Bufbyte *ptr, Emchar c); | 491 Bytecount non_ascii_set_charptr_emchar (Bufbyte *ptr, Emchar c); |
484 Bytecount non_ascii_charptr_copy_char (CONST Bufbyte *ptr, Bufbyte *ptr2); | 492 Bytecount non_ascii_charptr_copy_char (const Bufbyte *ptr, Bufbyte *ptr2); |
485 | 493 |
486 INLINE Emchar charptr_emchar (CONST Bufbyte *ptr); | 494 INLINE Emchar charptr_emchar (const Bufbyte *ptr); |
487 INLINE Emchar | 495 INLINE Emchar |
488 charptr_emchar (CONST Bufbyte *ptr) | 496 charptr_emchar (const Bufbyte *ptr) |
489 { | 497 { |
490 return BYTE_ASCII_P (*ptr) ? | 498 return BYTE_ASCII_P (*ptr) ? |
491 simple_charptr_emchar (ptr) : | 499 simple_charptr_emchar (ptr) : |
492 non_ascii_charptr_emchar (ptr); | 500 non_ascii_charptr_emchar (ptr); |
493 } | 501 } |
499 return !CHAR_MULTIBYTE_P (x) ? | 507 return !CHAR_MULTIBYTE_P (x) ? |
500 simple_set_charptr_emchar (ptr, x) : | 508 simple_set_charptr_emchar (ptr, x) : |
501 non_ascii_set_charptr_emchar (ptr, x); | 509 non_ascii_set_charptr_emchar (ptr, x); |
502 } | 510 } |
503 | 511 |
504 INLINE Bytecount charptr_copy_char (CONST Bufbyte *ptr, Bufbyte *ptr2); | 512 INLINE Bytecount charptr_copy_char (const Bufbyte *ptr, Bufbyte *ptr2); |
505 INLINE Bytecount | 513 INLINE Bytecount |
506 charptr_copy_char (CONST Bufbyte *ptr, Bufbyte *ptr2) | 514 charptr_copy_char (const Bufbyte *ptr, Bufbyte *ptr2) |
507 { | 515 { |
508 return BYTE_ASCII_P (*ptr) ? | 516 return BYTE_ASCII_P (*ptr) ? |
509 simple_charptr_copy_char (ptr, ptr2) : | 517 simple_charptr_copy_char (ptr, ptr2) : |
510 non_ascii_charptr_copy_char (ptr, ptr2); | 518 non_ascii_charptr_copy_char (ptr, ptr2); |
511 } | 519 } |
557 return CHARP (obj) ? XCHAR (obj) : XINT (obj); | 565 return CHARP (obj) ? XCHAR (obj) : XINT (obj); |
558 } | 566 } |
559 | 567 |
560 #else | 568 #else |
561 | 569 |
562 #define XCHAR_OR_CHAR_INT(obj) (CHARP ((obj)) ? XCHAR ((obj)) : XINT ((obj))) | 570 #define XCHAR_OR_CHAR_INT(obj) (CHARP (obj) ? XCHAR (obj) : XINT (obj)) |
563 | 571 |
564 #endif | 572 #endif |
565 | 573 |
566 #define CHECK_CHAR_COERCE_INT(x) do { \ | 574 #define CHECK_CHAR_COERCE_INT(x) do { \ |
567 if (CHARP (x)) \ | 575 if (CHARP (x)) \ |
616 /* Convert the address of a byte in the buffer into a position. */ | 624 /* Convert the address of a byte in the buffer into a position. */ |
617 INLINE Bytind BI_BUF_PTR_BYTE_POS (struct buffer *buf, Bufbyte *ptr); | 625 INLINE Bytind BI_BUF_PTR_BYTE_POS (struct buffer *buf, Bufbyte *ptr); |
618 INLINE Bytind | 626 INLINE Bytind |
619 BI_BUF_PTR_BYTE_POS (struct buffer *buf, Bufbyte *ptr) | 627 BI_BUF_PTR_BYTE_POS (struct buffer *buf, Bufbyte *ptr) |
620 { | 628 { |
621 return ((ptr) - (buf)->text->beg + 1 | 629 return (ptr - buf->text->beg + 1 |
622 - ((ptr - (buf)->text->beg + 1) > (buf)->text->gpt | 630 - ((ptr - buf->text->beg + 1) > buf->text->gpt |
623 ? (buf)->text->gap_size : 0)); | 631 ? buf->text->gap_size : 0)); |
624 } | 632 } |
625 | 633 |
626 #define BUF_PTR_BYTE_POS(buf, ptr) \ | 634 #define BUF_PTR_BYTE_POS(buf, ptr) \ |
627 bytind_to_bufpos (buf, BI_BUF_PTR_BYTE_POS (buf, ptr)) | 635 bytind_to_bufpos (buf, BI_BUF_PTR_BYTE_POS (buf, ptr)) |
628 | 636 |
629 /* Address of byte at position POS in buffer. */ | 637 /* Address of byte at position POS in buffer. */ |
630 INLINE Bufbyte * BI_BUF_BYTE_ADDRESS (struct buffer *buf, Bytind pos); | 638 INLINE Bufbyte * BI_BUF_BYTE_ADDRESS (struct buffer *buf, Bytind pos); |
631 INLINE Bufbyte * | 639 INLINE Bufbyte * |
632 BI_BUF_BYTE_ADDRESS (struct buffer *buf, Bytind pos) | 640 BI_BUF_BYTE_ADDRESS (struct buffer *buf, Bytind pos) |
633 { | 641 { |
634 return ((buf)->text->beg + | 642 return (buf->text->beg + |
635 ((pos >= (buf)->text->gpt ? (pos + (buf)->text->gap_size) : pos) | 643 ((pos >= buf->text->gpt ? (pos + buf->text->gap_size) : pos) |
636 - 1)); | 644 - 1)); |
637 } | 645 } |
638 | 646 |
639 #define BUF_BYTE_ADDRESS(buf, pos) \ | 647 #define BUF_BYTE_ADDRESS(buf, pos) \ |
640 BI_BUF_BYTE_ADDRESS (buf, bufpos_to_bytind (buf, pos)) | 648 BI_BUF_BYTE_ADDRESS (buf, bufpos_to_bytind (buf, pos)) |
642 /* Address of byte before position POS in buffer. */ | 650 /* Address of byte before position POS in buffer. */ |
643 INLINE Bufbyte * BI_BUF_BYTE_ADDRESS_BEFORE (struct buffer *buf, Bytind pos); | 651 INLINE Bufbyte * BI_BUF_BYTE_ADDRESS_BEFORE (struct buffer *buf, Bytind pos); |
644 INLINE Bufbyte * | 652 INLINE Bufbyte * |
645 BI_BUF_BYTE_ADDRESS_BEFORE (struct buffer *buf, Bytind pos) | 653 BI_BUF_BYTE_ADDRESS_BEFORE (struct buffer *buf, Bytind pos) |
646 { | 654 { |
647 return ((buf)->text->beg + | 655 return (buf->text->beg + |
648 ((pos > (buf)->text->gpt ? (pos + (buf)->text->gap_size) : pos) | 656 ((pos > buf->text->gpt ? (pos + buf->text->gap_size) : pos) |
649 - 2)); | 657 - 2)); |
650 } | 658 } |
651 | 659 |
652 #define BUF_BYTE_ADDRESS_BEFORE(buf, pos) \ | 660 #define BUF_BYTE_ADDRESS_BEFORE(buf, pos) \ |
653 BI_BUF_BYTE_ADDRESS_BEFORE (buf, bufpos_to_bytind (buf, pos)) | 661 BI_BUF_BYTE_ADDRESS_BEFORE (buf, bufpos_to_bytind (buf, pos)) |
658 | 666 |
659 INLINE int valid_memind_p (struct buffer *buf, Memind x); | 667 INLINE int valid_memind_p (struct buffer *buf, Memind x); |
660 INLINE int | 668 INLINE int |
661 valid_memind_p (struct buffer *buf, Memind x) | 669 valid_memind_p (struct buffer *buf, Memind x) |
662 { | 670 { |
663 return ((x >= 1 && x <= (Memind) (buf)->text->gpt) || | 671 return ((x >= 1 && x <= (Memind) buf->text->gpt) || |
664 (x > (Memind) ((buf)->text->gpt + (buf)->text->gap_size) && | 672 (x > (Memind) (buf->text->gpt + buf->text->gap_size) && |
665 x <= (Memind) ((buf)->text->z + (buf)->text->gap_size))); | 673 x <= (Memind) (buf->text->z + buf->text->gap_size))); |
666 } | 674 } |
667 | 675 |
668 INLINE Memind bytind_to_memind (struct buffer *buf, Bytind x); | 676 INLINE Memind bytind_to_memind (struct buffer *buf, Bytind x); |
669 INLINE Memind | 677 INLINE Memind |
670 bytind_to_memind (struct buffer *buf, Bytind x) | 678 bytind_to_memind (struct buffer *buf, Bytind x) |
671 { | 679 { |
672 return (Memind) ((x > (buf)->text->gpt) ? (x + (buf)->text->gap_size) : x); | 680 return (Memind) ((x > buf->text->gpt) ? (x + buf->text->gap_size) : x); |
673 } | 681 } |
674 | 682 |
675 | 683 |
676 INLINE Bytind memind_to_bytind (struct buffer *buf, Memind x); | 684 INLINE Bytind memind_to_bytind (struct buffer *buf, Memind x); |
677 INLINE Bytind | 685 INLINE Bytind |
678 memind_to_bytind (struct buffer *buf, Memind x) | 686 memind_to_bytind (struct buffer *buf, Memind x) |
679 { | 687 { |
680 #ifdef ERROR_CHECK_BUFPOS | 688 #ifdef ERROR_CHECK_BUFPOS |
681 assert (valid_memind_p (buf, x)); | 689 assert (valid_memind_p (buf, x)); |
682 #endif | 690 #endif |
683 return (Bytind) ((x > (Memind) (buf)->text->gpt) ? | 691 return (Bytind) ((x > (Memind) buf->text->gpt) ? |
684 x - (buf)->text->gap_size : | 692 x - buf->text->gap_size : |
685 x); | 693 x); |
686 } | 694 } |
687 | 695 |
688 #define memind_to_bufpos(buf, x) \ | 696 #define memind_to_bufpos(buf, x) \ |
689 bytind_to_bufpos (buf, memind_to_bytind (buf, x)) | 697 bytind_to_bufpos (buf, memind_to_bytind (buf, x)) |
1028 # define BI_BUF_CHARPTR_COPY_CHAR(buf, pos, str) \ | 1036 # define BI_BUF_CHARPTR_COPY_CHAR(buf, pos, str) \ |
1029 charptr_copy_char (BI_BUF_BYTE_ADDRESS (buf, pos), str) | 1037 charptr_copy_char (BI_BUF_BYTE_ADDRESS (buf, pos), str) |
1030 #define BUF_CHARPTR_COPY_CHAR(buf, pos, str) \ | 1038 #define BUF_CHARPTR_COPY_CHAR(buf, pos, str) \ |
1031 BI_BUF_CHARPTR_COPY_CHAR (buf, bufpos_to_bytind (buf, pos), str) | 1039 BI_BUF_CHARPTR_COPY_CHAR (buf, bufpos_to_bytind (buf, pos), str) |
1032 | 1040 |
1033 | |
1034 | |
1035 | 1041 |
1036 /************************************************************************/ | 1042 /************************************************************************/ |
1037 /* */ | 1043 /* */ |
1038 /* working with externally-formatted data */ | 1044 /* Converting between internal and external format */ |
1039 /* */ | 1045 /* */ |
1040 /************************************************************************/ | 1046 /************************************************************************/ |
1041 | 1047 /* |
1042 /* Sometimes strings need to be converted into one or another | 1048 All client code should use only the two macros |
1043 external format, for passing to a library function. (Note | 1049 |
1044 that we encapsulate and automatically convert the arguments | 1050 TO_EXTERNAL_FORMAT (source_type, source, sink_type, sink, coding_system) |
1045 of some functions, but not others.) At times this conversion | 1051 TO_INTERNAL_FORMAT (source_type, source, sink_type, sink, coding_system) |
1046 also has to go the other way -- i.e. when we get external- | 1052 |
1047 format strings back from a library function. | 1053 Typical use is |
1048 */ | 1054 |
1055 TO_EXTERNAL_FORMAT (DATA, (ptr, len), | |
1056 LISP_BUFFER, buffer, | |
1057 Qfile_name); | |
1058 | |
1059 The source or sink can be specified in one of these ways: | |
1060 | |
1061 DATA, (ptr, len), // input data is a fixed buffer of size len | |
1062 ALLOCA, (ptr, len), // output data is in a alloca()ed buffer of size len | |
1063 MALLOC, (ptr, len), // output data is in a malloc()ed buffer of size len | |
1064 C_STRING_ALLOCA, ptr, // equivalent to ALLOCA (ptr, len_ignored) on output. | |
1065 C_STRING_MALLOC, ptr, // equivalent to MALLOC (ptr, len_ignored) on output. | |
1066 C_STRING, ptr, // equivalent to DATA, (ptr, strlen (ptr) + 1) on input | |
1067 LISP_STRING, string, // input or output is a Lisp_Object of type string | |
1068 LISP_BUFFER, buffer, // output is written to (point) in lisp buffer | |
1069 LISP_LSTREAM, lstream, // input or output is a Lisp_Object of type lstream | |
1070 LISP_OPAQUE, object, // input or output is a Lisp_Object of type opaque | |
1071 | |
1072 When specifying the sink, use lvalues, since the macro will assign to them, | |
1073 except when the sink is an lstream or a lisp buffer. | |
1074 | |
1075 The macros accept the kinds of sources and sinks appropriate for | |
1076 internal and external data representation. See the type_checking_assert | |
1077 macros below for the actual allowed types. | |
1078 | |
1079 Since some sources and sinks use one argument (a Lisp_Object) to | |
1080 specify them, while others take a (pointer, length) pair, we use | |
1081 some C preprocessor trickery to allow pair arguments to be specified | |
1082 by parenthesizing them, as in the examples above. | |
1083 | |
1084 Anything prefixed by dfc_ (`data format conversion') is private. | |
1085 They are only used to implement these macros. | |
1086 | |
1087 Using C_STRING* is appropriate for using with external APIs that take | |
1088 null-terminated strings. For internal data, we should try to be | |
1089 '\0'-clean - i.e. allow arbitrary data to contain embedded '\0'. | |
1090 | |
1091 Sometime in the future we might allow output to C_STRING_ALLOCA or | |
1092 C_STRING_MALLOC _only_ with TO_EXTERNAL_FORMAT(), not | |
1093 TO_INTERNAL_FORMAT(). */ | |
1094 | |
1095 #define TO_EXTERNAL_FORMAT(source_type, source, sink_type, sink, coding_system) \ | |
1096 do { \ | |
1097 dfc_conversion_type dfc_simplified_source_type; \ | |
1098 dfc_conversion_type dfc_simplified_sink_type; \ | |
1099 dfc_conversion_data dfc_source; \ | |
1100 dfc_conversion_data dfc_sink; \ | |
1101 \ | |
1102 type_checking_assert \ | |
1103 ((DFC_TYPE_##source_type == DFC_TYPE_DATA || \ | |
1104 DFC_TYPE_##source_type == DFC_TYPE_C_STRING || \ | |
1105 DFC_TYPE_##source_type == DFC_TYPE_LISP_STRING || \ | |
1106 DFC_TYPE_##source_type == DFC_TYPE_LISP_OPAQUE || \ | |
1107 DFC_TYPE_##source_type == DFC_TYPE_LISP_LSTREAM) \ | |
1108 && \ | |
1109 (DFC_TYPE_##sink_type == DFC_TYPE_ALLOCA || \ | |
1110 DFC_TYPE_##sink_type == DFC_TYPE_MALLOC || \ | |
1111 DFC_TYPE_##sink_type == DFC_TYPE_C_STRING_ALLOCA || \ | |
1112 DFC_TYPE_##sink_type == DFC_TYPE_C_STRING_MALLOC || \ | |
1113 DFC_TYPE_##sink_type == DFC_TYPE_LISP_LSTREAM || \ | |
1114 DFC_TYPE_##sink_type == DFC_TYPE_LISP_OPAQUE)); \ | |
1115 \ | |
1116 DFC_SOURCE_##source_type##_TO_ARGS (source); \ | |
1117 DFC_SINK_##sink_type##_TO_ARGS (sink); \ | |
1118 \ | |
1119 DFC_CONVERT_TO_EXTERNAL_FORMAT (dfc_simplified_source_type, &dfc_source, \ | |
1120 coding_system, \ | |
1121 dfc_simplified_sink_type, &dfc_sink); \ | |
1122 \ | |
1123 DFC_##sink_type##_USE_CONVERTED_DATA (sink); \ | |
1124 } while (0) | |
1125 | |
1126 #define TO_INTERNAL_FORMAT(source_type, source, sink_type, sink, coding_system) \ | |
1127 do { \ | |
1128 dfc_conversion_type dfc_simplified_source_type; \ | |
1129 dfc_conversion_type dfc_simplified_sink_type; \ | |
1130 dfc_conversion_data dfc_source; \ | |
1131 dfc_conversion_data dfc_sink; \ | |
1132 \ | |
1133 type_checking_assert \ | |
1134 ((DFC_TYPE_##source_type == DFC_TYPE_DATA || \ | |
1135 DFC_TYPE_##source_type == DFC_TYPE_C_STRING || \ | |
1136 DFC_TYPE_##source_type == DFC_TYPE_LISP_OPAQUE || \ | |
1137 DFC_TYPE_##source_type == DFC_TYPE_LISP_LSTREAM) \ | |
1138 && \ | |
1139 (DFC_TYPE_##sink_type == DFC_TYPE_ALLOCA || \ | |
1140 DFC_TYPE_##sink_type == DFC_TYPE_MALLOC || \ | |
1141 DFC_TYPE_##sink_type == DFC_TYPE_C_STRING_ALLOCA || \ | |
1142 DFC_TYPE_##sink_type == DFC_TYPE_C_STRING_MALLOC || \ | |
1143 DFC_TYPE_##sink_type == DFC_TYPE_LISP_STRING || \ | |
1144 DFC_TYPE_##sink_type == DFC_TYPE_LISP_LSTREAM || \ | |
1145 DFC_TYPE_##sink_type == DFC_TYPE_LISP_BUFFER)); \ | |
1146 \ | |
1147 DFC_SOURCE_##source_type##_TO_ARGS (source); \ | |
1148 DFC_SINK_##sink_type##_TO_ARGS (sink); \ | |
1149 \ | |
1150 DFC_CONVERT_TO_INTERNAL_FORMAT (dfc_simplified_source_type, &dfc_source, \ | |
1151 coding_system, \ | |
1152 dfc_simplified_sink_type, &dfc_sink); \ | |
1153 \ | |
1154 DFC_##sink_type##_USE_CONVERTED_DATA (sink); \ | |
1155 } while (0) | |
1049 | 1156 |
1050 #ifdef FILE_CODING | 1157 #ifdef FILE_CODING |
1158 #define DFC_CONVERT_TO_EXTERNAL_FORMAT dfc_convert_to_external_format | |
1159 #define DFC_CONVERT_TO_INTERNAL_FORMAT dfc_convert_to_internal_format | |
1160 #else | |
1161 /* ignore coding_system argument */ | |
1162 #define DFC_CONVERT_TO_EXTERNAL_FORMAT(a, b, coding_system, c, d) \ | |
1163 dfc_convert_to_external_format (a, b, c, d) | |
1164 #define DFC_CONVERT_TO_INTERNAL_FORMAT(a, b, coding_system, c, d) \ | |
1165 dfc_convert_to_internal_format (a, b, c, d) | |
1166 #endif | |
1167 | |
1168 typedef union | |
1169 { | |
1170 struct { const void *ptr; size_t len; } data; | |
1171 Lisp_Object lisp_object; | |
1172 } dfc_conversion_data; | |
1173 | |
1174 enum dfc_conversion_type | |
1175 { | |
1176 DFC_TYPE_DATA, | |
1177 DFC_TYPE_ALLOCA, | |
1178 DFC_TYPE_MALLOC, | |
1179 DFC_TYPE_C_STRING, | |
1180 DFC_TYPE_C_STRING_ALLOCA, | |
1181 DFC_TYPE_C_STRING_MALLOC, | |
1182 DFC_TYPE_LISP_STRING, | |
1183 DFC_TYPE_LISP_LSTREAM, | |
1184 DFC_TYPE_LISP_OPAQUE, | |
1185 DFC_TYPE_LISP_BUFFER | |
1186 }; | |
1187 typedef enum dfc_conversion_type dfc_conversion_type; | |
1051 | 1188 |
1052 /* WARNING: These use a static buffer. This can lead to disaster if | 1189 /* WARNING: These use a static buffer. This can lead to disaster if |
1053 these functions are not used *very* carefully. Under normal | 1190 these functions are not used *very* carefully. Another reason to only use |
1054 circumstances, do not call these functions; call the front ends | 1191 TO_EXTERNAL_FORMATf() and TO_INTERNAL_FORMAT(). */ |
1055 below. */ | 1192 void |
1056 | 1193 dfc_convert_to_external_format (dfc_conversion_type source_type, |
1057 Extbyte *convert_to_external_format (CONST Bufbyte *ptr, | 1194 dfc_conversion_data *source, |
1058 Bytecount len, | 1195 #ifdef FILE_CODING |
1059 Extcount *len_out, | 1196 Lisp_Object coding_system, |
1060 enum external_data_format fmt); | 1197 #endif |
1061 Bufbyte *convert_from_external_format (CONST Extbyte *ptr, | 1198 dfc_conversion_type sink_type, |
1062 Extcount len, | 1199 dfc_conversion_data *sink); |
1063 Bytecount *len_out, | 1200 void |
1064 enum external_data_format fmt); | 1201 dfc_convert_to_internal_format (dfc_conversion_type source_type, |
1065 | 1202 dfc_conversion_data *source, |
1066 #else /* ! MULE */ | 1203 #ifdef FILE_CODING |
1067 | 1204 Lisp_Object coding_system, |
1068 #define convert_to_external_format(ptr, len, len_out, fmt) \ | 1205 #endif |
1069 (*(len_out) = (int) (len), (Extbyte *) (ptr)) | 1206 dfc_conversion_type sink_type, |
1070 #define convert_from_external_format(ptr, len, len_out, fmt) \ | 1207 dfc_conversion_data *sink); |
1071 (*(len_out) = (Bytecount) (len), (Bufbyte *) (ptr)) | 1208 /* CPP Trickery */ |
1072 | 1209 #define DFC_CPP_CAR(x,y) (x) |
1073 #endif /* ! MULE */ | 1210 #define DFC_CPP_CDR(x,y) (y) |
1074 | 1211 |
1075 /* In all of the following macros we use the following general principles: | 1212 /* Convert `source' to args for dfc_convert_to_*_format() */ |
1076 | 1213 #define DFC_SOURCE_DATA_TO_ARGS(val) do { \ |
1077 -- Functions that work with charptr's accept two sorts of charptr's: | 1214 dfc_source.data.ptr = DFC_CPP_CAR val; \ |
1078 | 1215 dfc_source.data.len = DFC_CPP_CDR val; \ |
1079 a) Pointers to memory with a length specified. The pointer will be | 1216 dfc_simplified_source_type = DFC_TYPE_DATA; \ |
1080 fundamentally of type `unsigned char *' (although labelled | 1217 } while (0) |
1081 as `Bufbyte *' for internal-format data and `Extbyte *' for | 1218 #define DFC_SOURCE_C_STRING_TO_ARGS(val) do { \ |
1082 external-format data) and the length will be fundamentally of | 1219 dfc_source.data.len = \ |
1083 type `int' (although labelled as `Bytecount' for internal-format | 1220 strlen ((char *) (dfc_source.data.ptr = (val))); \ |
1084 data and `Extcount' for external-format data). The length is | 1221 dfc_simplified_source_type = DFC_TYPE_DATA; \ |
1085 always a count in bytes. | 1222 } while (0) |
1086 b) Zero-terminated pointers; no length specified. The pointer | 1223 #define DFC_SOURCE_LISP_STRING_TO_ARGS(val) do { \ |
1087 is of type `char *', whether the data pointed to is internal-format | 1224 Lisp_Object dfc_slsta = (val); \ |
1088 or external-format. These sorts of pointers are available for | 1225 type_checking_assert (STRINGP (dfc_slsta)); \ |
1089 convenience in working with C library functions and literal | 1226 dfc_source.lisp_object = dfc_slsta; \ |
1090 strings. In general you should use these sorts of pointers only | 1227 dfc_simplified_source_type = DFC_TYPE_LISP_STRING; \ |
1091 to interface to library routines and not for general manipulation, | 1228 } while (0) |
1092 as you are liable to lose embedded nulls and such. This could | 1229 #define DFC_SOURCE_LISP_LSTREAM_TO_ARGS(val) do { \ |
1093 be a big problem for routines that want Unicode-formatted data, | 1230 Lisp_Object dfc_sllta = (val); \ |
1094 which is likely to have lots of embedded nulls in it. | 1231 type_checking_assert (LSTREAMP (dfc_sllta)); \ |
1095 (In the real world, though, external Unicode data will be UTF-8, | 1232 dfc_source.lisp_object = dfc_sllta; \ |
1096 which will not have embedded nulls and is ASCII-compatible - martin) | 1233 dfc_simplified_source_type = DFC_TYPE_LISP_LSTREAM; \ |
1097 | 1234 } while (0) |
1098 -- Functions that work with Lisp strings accept strings as Lisp Objects | 1235 #define DFC_SOURCE_LISP_OPAQUE_TO_ARGS(val) do { \ |
1099 (as opposed to the `struct Lisp_String *' for some of the other | 1236 Lisp_Opaque *dfc_slota = XOPAQUE (val); \ |
1100 string accessors). This is for convenience in working with the | 1237 dfc_source.data.ptr = OPAQUE_DATA (dfc_slota); \ |
1101 functions, as otherwise you will almost always have to call | 1238 dfc_source.data.len = OPAQUE_SIZE (dfc_slota); \ |
1102 XSTRING() on the object. | 1239 dfc_simplified_source_type = DFC_TYPE_DATA; \ |
1103 | 1240 } while (0) |
1104 -- Functions that work with charptr's are not guaranteed to copy | 1241 |
1105 their data into alloca()ed space. Functions that work with | 1242 /* Convert `sink' to args for dfc_convert_to_*_format() */ |
1106 Lisp strings are, however. The reason is that Lisp strings can | 1243 #define DFC_SINK_ALLOCA_TO_ARGS(val) \ |
1107 be relocated any time a GC happens, and it could happen at some | 1244 dfc_simplified_sink_type = DFC_TYPE_DATA |
1108 rather unexpected times. The internal-external conversion is | 1245 #define DFC_SINK_C_STRING_ALLOCA_TO_ARGS(val) \ |
1109 rarely done in time-critical functions, and so the slight | 1246 dfc_simplified_sink_type = DFC_TYPE_DATA |
1110 extra time required for alloca() and copy is well-worth the | 1247 #define DFC_SINK_MALLOC_TO_ARGS(val) \ |
1111 safety of knowing your string data won't be relocated out from | 1248 dfc_simplified_sink_type = DFC_TYPE_DATA |
1112 under you. | 1249 #define DFC_SINK_C_STRING_MALLOC_TO_ARGS(val) \ |
1113 */ | 1250 dfc_simplified_sink_type = DFC_TYPE_DATA |
1114 | 1251 #define DFC_SINK_LISP_STRING_TO_ARGS(val) \ |
1115 | 1252 dfc_simplified_sink_type = DFC_TYPE_DATA |
1116 /* Maybe convert charptr's data into ext-format and store the result in | 1253 #define DFC_SINK_LISP_OPAQUE_TO_ARGS(val) \ |
1117 alloca()'ed space. | 1254 dfc_simplified_sink_type = DFC_TYPE_DATA |
1118 | 1255 #define DFC_SINK_LISP_LSTREAM_TO_ARGS(val) do { \ |
1119 You may wonder why this is written in this fashion and not as a | 1256 Lisp_Object dfc_sllta = (val); \ |
1120 function call. With a little trickery it could certainly be | 1257 type_checking_assert (LSTREAMP (dfc_sllta)); \ |
1121 written this way, but it won't work because of those DAMN GCC WANKERS | 1258 dfc_sink.lisp_object = dfc_sllta; \ |
1122 who couldn't be bothered to handle alloca() properly on the x86 | 1259 dfc_simplified_sink_type = DFC_TYPE_LISP_LSTREAM; \ |
1123 architecture. (If you put a call to alloca() in the argument to | 1260 } while (0) |
1124 a function call, the stack space gets allocated right in the | 1261 #define DFC_SINK_LISP_BUFFER_TO_ARGS(val) do { \ |
1125 middle of the arguments to the function call and you are unbelievably | 1262 struct buffer *dfc_slbta = XBUFFER (val); \ |
1126 hosed.) */ | 1263 dfc_sink.lisp_object = \ |
1127 | 1264 make_lisp_buffer_output_stream \ |
1128 #ifdef MULE | 1265 (dfc_slbta, BUF_PT (dfc_slbta), 0); \ |
1129 | 1266 dfc_simplified_sink_type = DFC_TYPE_LISP_LSTREAM; \ |
1130 #define GET_CHARPTR_EXT_DATA_ALLOCA(ptr, len, fmt, ptr_out, len_out) do \ | 1267 } while (0) |
1131 { \ | 1268 |
1132 Bytecount gceda_len_in = (Bytecount) (len); \ | 1269 /* Assign to the `sink' lvalue(s) using the converted data. */ |
1133 Extcount gceda_len_out; \ | 1270 #define DFC_ALLOCA_USE_CONVERTED_DATA(sink) do { \ |
1134 CONST Bufbyte *gceda_ptr_in = (ptr); \ | 1271 void * dfc_sink_ret = alloca (dfc_sink.data.len + 1); \ |
1135 Extbyte *gceda_ptr_out = \ | 1272 memcpy (dfc_sink_ret, dfc_sink.data.ptr, dfc_sink.data.len + 1); \ |
1136 convert_to_external_format (gceda_ptr_in, gceda_len_in, \ | 1273 (DFC_CPP_CAR sink) = (unsigned char *) dfc_sink_ret; \ |
1137 &gceda_len_out, fmt); \ | 1274 (DFC_CPP_CDR sink) = dfc_sink.data.len; \ |
1138 /* If the new string is identical to the old (will be the case most \ | 1275 } while (0) |
1139 of the time), just return the same string back. This saves \ | 1276 #define DFC_MALLOC_USE_CONVERTED_DATA(sink) do { \ |
1140 on alloca()ing, which can be useful on C alloca() machines and \ | 1277 void * dfc_sink_ret = xmalloc (dfc_sink.data.len + 1); \ |
1141 on stack-space-challenged environments. */ \ | 1278 memcpy (dfc_sink_ret, dfc_sink.data.ptr, dfc_sink.data.len + 1); \ |
1142 \ | 1279 (DFC_CPP_CAR sink) = (unsigned char *) dfc_sink_ret; \ |
1143 if (gceda_len_in == gceda_len_out && \ | 1280 (DFC_CPP_CDR sink) = dfc_sink.data.len; \ |
1144 !memcmp (gceda_ptr_in, gceda_ptr_out, gceda_len_out)) \ | 1281 } while (0) |
1145 { \ | 1282 #define DFC_C_STRING_ALLOCA_USE_CONVERTED_DATA(sink) do { \ |
1146 (ptr_out) = (Extbyte *) gceda_ptr_in; \ | 1283 void * dfc_sink_ret = alloca (dfc_sink.data.len + 1); \ |
1147 } \ | 1284 memcpy (dfc_sink_ret, dfc_sink.data.ptr, dfc_sink.data.len + 1); \ |
1148 else \ | 1285 (sink) = (char *) dfc_sink_ret; \ |
1149 { \ | 1286 } while (0) |
1150 (ptr_out) = (Extbyte *) alloca (1 + gceda_len_out); \ | 1287 #define DFC_C_STRING_MALLOC_USE_CONVERTED_DATA(sink) do { \ |
1151 memcpy ((void *) ptr_out, gceda_ptr_out, 1 + gceda_len_out); \ | 1288 void * dfc_sink_ret = xmalloc (dfc_sink.data.len + 1); \ |
1152 } \ | 1289 memcpy (dfc_sink_ret, dfc_sink.data.ptr, dfc_sink.data.len + 1); \ |
1153 (len_out) = gceda_len_out; \ | 1290 (sink) = (char *) dfc_sink_ret; \ |
1154 } while (0) | 1291 } while (0) |
1155 | 1292 #define DFC_LISP_STRING_USE_CONVERTED_DATA(sink) \ |
1156 #else /* ! MULE */ | 1293 sink = make_string ((Bufbyte *) dfc_sink.data.ptr, dfc_sink.data.len) |
1157 | 1294 #define DFC_LISP_OPAQUE_USE_CONVERTED_DATA(sink) \ |
1158 #define GET_CHARPTR_EXT_DATA_ALLOCA(ptr, len, fmt, ptr_out, len_out) do \ | 1295 sink = make_opaque (dfc_sink.data.ptr, dfc_sink.data.len) |
1159 { \ | 1296 #define DFC_LISP_LSTREAM_USE_CONVERTED_DATA(sink) /* data already used */ |
1160 (ptr_out) = (Extbyte *) (ptr); \ | 1297 #define DFC_LISP_BUFFER_USE_CONVERTED_DATA(sink) \ |
1161 (len_out) = (Extcount) (len); \ | 1298 Lstream_delete (XLSTREAM (dfc_sink.lisp_object)) |
1162 } while (0) | 1299 |
1163 | 1300 /* Someday we might want to distinguish between Qnative and Qfile_name |
1164 #endif /* ! MULE */ | 1301 by using coding-system aliases, but for now it suffices to have |
1165 | 1302 these be identical. Qnative can be used as the coding_system |
1166 #define GET_C_CHARPTR_EXT_DATA_ALLOCA(ptr, fmt, ptr_out) do \ | 1303 argument to TO_EXTERNAL_FORMAT() and TO_INTERNAL_FORMAT(). */ |
1167 { \ | 1304 #define Qnative Qfile_name |
1168 Extcount gcceda_ignored_len; \ | |
1169 CONST Bufbyte *gcceda_ptr_in = (CONST Bufbyte *) (ptr); \ | |
1170 Extbyte *gcceda_ptr_out; \ | |
1171 \ | |
1172 GET_CHARPTR_EXT_DATA_ALLOCA (gcceda_ptr_in, \ | |
1173 strlen ((char *) gcceda_ptr_in), \ | |
1174 fmt, \ | |
1175 gcceda_ptr_out, \ | |
1176 gcceda_ignored_len); \ | |
1177 (ptr_out) = (char *) gcceda_ptr_out; \ | |
1178 } while (0) | |
1179 | |
1180 #define GET_C_CHARPTR_EXT_BINARY_DATA_ALLOCA(ptr, ptr_out) \ | |
1181 GET_C_CHARPTR_EXT_DATA_ALLOCA (ptr, FORMAT_BINARY, ptr_out) | |
1182 #define GET_CHARPTR_EXT_BINARY_DATA_ALLOCA(ptr, len, ptr_out, len_out) \ | |
1183 GET_CHARPTR_EXT_DATA_ALLOCA (ptr, len, FORMAT_BINARY, ptr_out, len_out) | |
1184 | |
1185 #define GET_C_CHARPTR_EXT_FILENAME_DATA_ALLOCA(ptr, ptr_out) \ | |
1186 GET_C_CHARPTR_EXT_DATA_ALLOCA (ptr, FORMAT_FILENAME, ptr_out) | |
1187 #define GET_CHARPTR_EXT_FILENAME_DATA_ALLOCA(ptr, len, ptr_out, len_out) \ | |
1188 GET_CHARPTR_EXT_DATA_ALLOCA (ptr, len, FORMAT_FILENAME, ptr_out, len_out) | |
1189 | |
1190 #define GET_C_CHARPTR_EXT_CTEXT_DATA_ALLOCA(ptr, ptr_out) \ | |
1191 GET_C_CHARPTR_EXT_DATA_ALLOCA (ptr, FORMAT_CTEXT, ptr_out) | |
1192 #define GET_CHARPTR_EXT_CTEXT_DATA_ALLOCA(ptr, len, ptr_out, len_out) \ | |
1193 GET_CHARPTR_EXT_DATA_ALLOCA (ptr, len, FORMAT_CTEXT, ptr_out, len_out) | |
1194 | |
1195 /* Maybe convert external charptr's data into internal format and store | |
1196 the result in alloca()'ed space. | |
1197 | |
1198 You may wonder why this is written in this fashion and not as a | |
1199 function call. With a little trickery it could certainly be | |
1200 written this way, but it won't work because of those DAMN GCC WANKERS | |
1201 who couldn't be bothered to handle alloca() properly on the x86 | |
1202 architecture. (If you put a call to alloca() in the argument to | |
1203 a function call, the stack space gets allocated right in the | |
1204 middle of the arguments to the function call and you are unbelievably | |
1205 hosed.) */ | |
1206 | |
1207 #ifdef MULE | |
1208 | |
1209 #define GET_CHARPTR_INT_DATA_ALLOCA(ptr, len, fmt, ptr_out, len_out) do \ | |
1210 { \ | |
1211 Extcount gcida_len_in = (Extcount) (len); \ | |
1212 Bytecount gcida_len_out; \ | |
1213 CONST Extbyte *gcida_ptr_in = (ptr); \ | |
1214 Bufbyte *gcida_ptr_out = \ | |
1215 convert_from_external_format (gcida_ptr_in, gcida_len_in, \ | |
1216 &gcida_len_out, fmt); \ | |
1217 /* If the new string is identical to the old (will be the case most \ | |
1218 of the time), just return the same string back. This saves \ | |
1219 on alloca()ing, which can be useful on C alloca() machines and \ | |
1220 on stack-space-challenged environments. */ \ | |
1221 \ | |
1222 if (gcida_len_in == gcida_len_out && \ | |
1223 !memcmp (gcida_ptr_in, gcida_ptr_out, gcida_len_out)) \ | |
1224 { \ | |
1225 (ptr_out) = (Bufbyte *) gcida_ptr_in; \ | |
1226 } \ | |
1227 else \ | |
1228 { \ | |
1229 (ptr_out) = (Extbyte *) alloca (1 + gcida_len_out); \ | |
1230 memcpy ((void *) ptr_out, gcida_ptr_out, 1 + gcida_len_out); \ | |
1231 } \ | |
1232 (len_out) = gcida_len_out; \ | |
1233 } while (0) | |
1234 | |
1235 #else /* ! MULE */ | |
1236 | |
1237 #define GET_CHARPTR_INT_DATA_ALLOCA(ptr, len, fmt, ptr_out, len_out) do \ | |
1238 { \ | |
1239 (ptr_out) = (Bufbyte *) (ptr); \ | |
1240 (len_out) = (Bytecount) (len); \ | |
1241 } while (0) | |
1242 | |
1243 #endif /* ! MULE */ | |
1244 | |
1245 #define GET_C_CHARPTR_INT_DATA_ALLOCA(ptr, fmt, ptr_out) do \ | |
1246 { \ | |
1247 Bytecount gccida_ignored_len; \ | |
1248 CONST Extbyte *gccida_ptr_in = (CONST Extbyte *) (ptr); \ | |
1249 Bufbyte *gccida_ptr_out; \ | |
1250 \ | |
1251 GET_CHARPTR_INT_DATA_ALLOCA (gccida_ptr_in, \ | |
1252 strlen ((char *) gccida_ptr_in), \ | |
1253 fmt, \ | |
1254 gccida_ptr_out, \ | |
1255 gccida_ignored_len); \ | |
1256 (ptr_out) = gccida_ptr_out; \ | |
1257 } while (0) | |
1258 | |
1259 #define GET_C_CHARPTR_INT_BINARY_DATA_ALLOCA(ptr, ptr_out) \ | |
1260 GET_C_CHARPTR_INT_DATA_ALLOCA (ptr, FORMAT_BINARY, ptr_out) | |
1261 #define GET_CHARPTR_INT_BINARY_DATA_ALLOCA(ptr, len, ptr_out, len_out) \ | |
1262 GET_CHARPTR_INT_DATA_ALLOCA (ptr, len, FORMAT_BINARY, ptr_out, len_out) | |
1263 | |
1264 #define GET_C_CHARPTR_INT_FILENAME_DATA_ALLOCA(ptr, ptr_out) \ | |
1265 GET_C_CHARPTR_INT_DATA_ALLOCA (ptr, FORMAT_FILENAME, ptr_out) | |
1266 #define GET_CHARPTR_INT_FILENAME_DATA_ALLOCA(ptr, len, ptr_out, len_out) \ | |
1267 GET_CHARPTR_INT_DATA_ALLOCA (ptr, len, FORMAT_FILENAME, ptr_out, len_out) | |
1268 | |
1269 #define GET_C_CHARPTR_INT_CTEXT_DATA_ALLOCA(ptr, ptr_out) \ | |
1270 GET_C_CHARPTR_INT_DATA_ALLOCA (ptr, FORMAT_CTEXT, ptr_out) | |
1271 #define GET_CHARPTR_INT_CTEXT_DATA_ALLOCA(ptr, len, ptr_out, len_out) \ | |
1272 GET_CHARPTR_INT_DATA_ALLOCA (ptr, len, FORMAT_CTEXT, ptr_out, len_out) | |
1273 | |
1274 | |
1275 /* Maybe convert Lisp string's data into ext-format and store the result in | |
1276 alloca()'ed space. | |
1277 | |
1278 You may wonder why this is written in this fashion and not as a | |
1279 function call. With a little trickery it could certainly be | |
1280 written this way, but it won't work because of those DAMN GCC WANKERS | |
1281 who couldn't be bothered to handle alloca() properly on the x86 | |
1282 architecture. (If you put a call to alloca() in the argument to | |
1283 a function call, the stack space gets allocated right in the | |
1284 middle of the arguments to the function call and you are unbelievably | |
1285 hosed.) */ | |
1286 | |
1287 #define GET_STRING_EXT_DATA_ALLOCA(s, fmt, ptr_out, len_out) do \ | |
1288 { \ | |
1289 Extcount gseda_len_out; \ | |
1290 struct Lisp_String *gseda_s = XSTRING (s); \ | |
1291 Extbyte * gseda_ptr_out = \ | |
1292 convert_to_external_format (string_data (gseda_s), \ | |
1293 string_length (gseda_s), \ | |
1294 &gseda_len_out, fmt); \ | |
1295 (ptr_out) = (Extbyte *) alloca (1 + gseda_len_out); \ | |
1296 memcpy ((void *) ptr_out, gseda_ptr_out, 1 + gseda_len_out); \ | |
1297 (len_out) = gseda_len_out; \ | |
1298 } while (0) | |
1299 | |
1300 | |
1301 #define GET_C_STRING_EXT_DATA_ALLOCA(s, fmt, ptr_out) do \ | |
1302 { \ | |
1303 Extcount gcseda_ignored_len; \ | |
1304 Extbyte *gcseda_ptr_out; \ | |
1305 \ | |
1306 GET_STRING_EXT_DATA_ALLOCA (s, fmt, gcseda_ptr_out, \ | |
1307 gcseda_ignored_len); \ | |
1308 (ptr_out) = (char *) gcseda_ptr_out; \ | |
1309 } while (0) | |
1310 | |
1311 #define GET_STRING_BINARY_DATA_ALLOCA(s, ptr_out, len_out) \ | |
1312 GET_STRING_EXT_DATA_ALLOCA (s, FORMAT_BINARY, ptr_out, len_out) | |
1313 #define GET_C_STRING_BINARY_DATA_ALLOCA(s, ptr_out) \ | |
1314 GET_C_STRING_EXT_DATA_ALLOCA (s, FORMAT_BINARY, ptr_out) | |
1315 | |
1316 #define GET_STRING_FILENAME_DATA_ALLOCA(s, ptr_out, len_out) \ | |
1317 GET_STRING_EXT_DATA_ALLOCA (s, FORMAT_FILENAME, ptr_out, len_out) | |
1318 #define GET_C_STRING_FILENAME_DATA_ALLOCA(s, ptr_out) \ | |
1319 GET_C_STRING_EXT_DATA_ALLOCA (s, FORMAT_FILENAME, ptr_out) | |
1320 | |
1321 #define GET_STRING_OS_DATA_ALLOCA(s, ptr_out, len_out) \ | |
1322 GET_STRING_EXT_DATA_ALLOCA (s, FORMAT_OS, ptr_out, len_out) | |
1323 #define GET_C_STRING_OS_DATA_ALLOCA(s, ptr_out) \ | |
1324 GET_C_STRING_EXT_DATA_ALLOCA (s, FORMAT_OS, ptr_out) | |
1325 | |
1326 #define GET_STRING_CTEXT_DATA_ALLOCA(s, ptr_out, len_out) \ | |
1327 GET_STRING_EXT_DATA_ALLOCA (s, FORMAT_CTEXT, ptr_out, len_out) | |
1328 #define GET_C_STRING_CTEXT_DATA_ALLOCA(s, ptr_out) \ | |
1329 GET_C_STRING_EXT_DATA_ALLOCA (s, FORMAT_CTEXT, ptr_out) | |
1330 | |
1331 | 1305 |
1332 | 1306 |
1333 /************************************************************************/ | 1307 /************************************************************************/ |
1334 /* */ | 1308 /* */ |
1335 /* fake charset functions */ | 1309 /* fake charset functions */ |
1431 /* Face changed. */ | 1405 /* Face changed. */ |
1432 #define BUF_FACECHANGE(buf) ((buf)->face_change) | 1406 #define BUF_FACECHANGE(buf) ((buf)->face_change) |
1433 | 1407 |
1434 #define POINT_MARKER_P(marker) \ | 1408 #define POINT_MARKER_P(marker) \ |
1435 (XMARKER (marker)->buffer != 0 && \ | 1409 (XMARKER (marker)->buffer != 0 && \ |
1436 EQ ((marker), XMARKER (marker)->buffer->point_marker)) | 1410 EQ (marker, XMARKER (marker)->buffer->point_marker)) |
1437 | 1411 |
1438 #define BUF_MARKERS(buf) ((buf)->markers) | 1412 #define BUF_MARKERS(buf) ((buf)->markers) |
1439 | 1413 |
1440 /* WARNING: | 1414 /* WARNING: |
1441 | 1415 |
1558 | 1532 |
1559 /* Allocation of buffer data. */ | 1533 /* Allocation of buffer data. */ |
1560 | 1534 |
1561 #ifdef REL_ALLOC | 1535 #ifdef REL_ALLOC |
1562 | 1536 |
1563 char *r_alloc (unsigned char **, unsigned long); | 1537 char *r_alloc (unsigned char **, size_t); |
1564 char *r_re_alloc (unsigned char **, unsigned long); | 1538 char *r_re_alloc (unsigned char **, size_t); |
1565 void r_alloc_free (unsigned char **); | 1539 void r_alloc_free (unsigned char **); |
1566 | 1540 |
1567 #define BUFFER_ALLOC(data, size) \ | 1541 #define BUFFER_ALLOC(data, size) \ |
1568 ((Bufbyte *) r_alloc ((unsigned char **) &data, (size) * sizeof(Bufbyte))) | 1542 ((Bufbyte *) r_alloc ((unsigned char **) &data, (size) * sizeof(Bufbyte))) |
1569 #define BUFFER_REALLOC(data, size) \ | 1543 #define BUFFER_REALLOC(data, size) \ |
1592 int beginning_of_line_p (struct buffer *b, Bufpos pt); | 1566 int beginning_of_line_p (struct buffer *b, Bufpos pt); |
1593 | 1567 |
1594 /* from insdel.c */ | 1568 /* from insdel.c */ |
1595 void set_buffer_point (struct buffer *buf, Bufpos pos, Bytind bipos); | 1569 void set_buffer_point (struct buffer *buf, Bufpos pos, Bytind bipos); |
1596 void find_charsets_in_bufbyte_string (unsigned char *charsets, | 1570 void find_charsets_in_bufbyte_string (unsigned char *charsets, |
1597 CONST Bufbyte *str, | 1571 const Bufbyte *str, |
1598 Bytecount len); | 1572 Bytecount len); |
1599 void find_charsets_in_emchar_string (unsigned char *charsets, | 1573 void find_charsets_in_emchar_string (unsigned char *charsets, |
1600 CONST Emchar *str, | 1574 const Emchar *str, |
1601 Charcount len); | 1575 Charcount len); |
1602 int bufbyte_string_displayed_columns (CONST Bufbyte *str, Bytecount len); | 1576 int bufbyte_string_displayed_columns (const Bufbyte *str, Bytecount len); |
1603 int emchar_string_displayed_columns (CONST Emchar *str, Charcount len); | 1577 int emchar_string_displayed_columns (const Emchar *str, Charcount len); |
1604 void convert_bufbyte_string_into_emchar_dynarr (CONST Bufbyte *str, | 1578 void convert_bufbyte_string_into_emchar_dynarr (const Bufbyte *str, |
1605 Bytecount len, | 1579 Bytecount len, |
1606 Emchar_dynarr *dyn); | 1580 Emchar_dynarr *dyn); |
1607 Charcount convert_bufbyte_string_into_emchar_string (CONST Bufbyte *str, | 1581 Charcount convert_bufbyte_string_into_emchar_string (const Bufbyte *str, |
1608 Bytecount len, | 1582 Bytecount len, |
1609 Emchar *arr); | 1583 Emchar *arr); |
1610 void convert_emchar_string_into_bufbyte_dynarr (Emchar *arr, int nels, | 1584 void convert_emchar_string_into_bufbyte_dynarr (Emchar *arr, int nels, |
1611 Bufbyte_dynarr *dyn); | 1585 Bufbyte_dynarr *dyn); |
1612 Bufbyte *convert_emchar_string_into_malloced_string (Emchar *arr, int nels, | 1586 Bufbyte *convert_emchar_string_into_malloced_string (Emchar *arr, int nels, |
1698 string_char (XSTRING (table), (Charcount) ch) | 1672 string_char (XSTRING (table), (Charcount) ch) |
1699 # define SET_TRT_TABLE_CHAR_1(table, ch1, ch2) \ | 1673 # define SET_TRT_TABLE_CHAR_1(table, ch1, ch2) \ |
1700 set_string_char (XSTRING (table), (Charcount) ch1, ch2) | 1674 set_string_char (XSTRING (table), (Charcount) ch1, ch2) |
1701 | 1675 |
1702 #ifdef MULE | 1676 #ifdef MULE |
1703 # define MAKE_MIRROR_TRT_TABLE() make_opaque (256, 0) | 1677 # define MAKE_MIRROR_TRT_TABLE() make_opaque (OPAQUE_CLEAR, 256) |
1704 # define MIRROR_TRT_TABLE_AS_STRING(table) ((Bufbyte *) XOPAQUE_DATA (table)) | 1678 # define MIRROR_TRT_TABLE_AS_STRING(table) ((Bufbyte *) XOPAQUE_DATA (table)) |
1705 # define MIRROR_TRT_TABLE_CHAR_1(table, ch) \ | 1679 # define MIRROR_TRT_TABLE_CHAR_1(table, ch) \ |
1706 ((Emchar) (MIRROR_TRT_TABLE_AS_STRING (table)[ch])) | 1680 ((Emchar) (MIRROR_TRT_TABLE_AS_STRING (table)[ch])) |
1707 # define SET_MIRROR_TRT_TABLE_CHAR_1(table, ch1, ch2) \ | 1681 # define SET_MIRROR_TRT_TABLE_CHAR_1(table, ch1, ch2) \ |
1708 (MIRROR_TRT_TABLE_AS_STRING (table)[ch1] = (Bufbyte) (ch2)) | 1682 (MIRROR_TRT_TABLE_AS_STRING (table)[ch1] = (Bufbyte) (ch2)) |
1784 | 1758 |
1785 /* Downcase a character, or make no change if that cannot be done. */ | 1759 /* Downcase a character, or make no change if that cannot be done. */ |
1786 | 1760 |
1787 #define DOWNCASE(buf, ch) DOWNCASE_TABLE_OF (buf, ch) | 1761 #define DOWNCASE(buf, ch) DOWNCASE_TABLE_OF (buf, ch) |
1788 | 1762 |
1789 #endif /* _XEMACS_BUFFER_H_ */ | 1763 #endif /* INCLUDED_buffer_h_ */ |