comparison src/buffer.h @ 272:c5d627a313b1 r21-0b34

Import from CVS: tag r21-0b34
author cvs
date Mon, 13 Aug 2007 10:28:48 +0200
parents 11cf20601dec
children 7df0dd720c89
comparison
equal deleted inserted replaced
271:c7b7086b0a39 272:c5d627a313b1
218 #define GC_BUFFERP(x) GC_RECORDP (x, buffer) 218 #define GC_BUFFERP(x) GC_RECORDP (x, buffer)
219 #define CHECK_BUFFER(x) CHECK_RECORD (x, buffer) 219 #define CHECK_BUFFER(x) CHECK_RECORD (x, buffer)
220 #define CONCHECK_BUFFER(x) CONCHECK_RECORD (x, buffer) 220 #define CONCHECK_BUFFER(x) CONCHECK_RECORD (x, buffer)
221 221
222 #define BUFFER_LIVE_P(b) (!NILP ((b)->name)) 222 #define BUFFER_LIVE_P(b) (!NILP ((b)->name))
223 extern Lisp_Object Qbuffer_live_p; 223
224 #define CHECK_LIVE_BUFFER(x) \ 224 #define CHECK_LIVE_BUFFER(x) do { \
225 do { CHECK_BUFFER (x); \ 225 CHECK_BUFFER (x); \
226 if (!BUFFER_LIVE_P (XBUFFER (x))) \ 226 if (!BUFFER_LIVE_P (XBUFFER (x))) \
227 dead_wrong_type_argument (Qbuffer_live_p, (x)); \ 227 dead_wrong_type_argument (Qbuffer_live_p, (x)); \
228 } while (0) 228 } while (0)
229 #define CONCHECK_LIVE_BUFFER(x) \ 229
230 do { CONCHECK_BUFFER (x); \ 230 #define CONCHECK_LIVE_BUFFER(x) do { \
231 if (!BUFFER_LIVE_P (XBUFFER (x))) \ 231 CONCHECK_BUFFER (x); \
232 x = wrong_type_argument (Qbuffer_live_p, (x)); \ 232 if (!BUFFER_LIVE_P (XBUFFER (x))) \
233 } while (0) 233 x = wrong_type_argument (Qbuffer_live_p, (x)); \
234 234 } while (0)
235 #define BUFFER_OR_STRING_P(x) (BUFFERP (x) || STRINGP (x))
236
237 extern Lisp_Object Qbuffer_or_string_p;
238 #define CHECK_BUFFER_OR_STRING(x) \
239 do { if (!BUFFER_OR_STRING_P (x)) \
240 dead_wrong_type_argument (Qbuffer_or_string_p, (x)); \
241 } while (0)
242 #define CONCHECK_BUFFER_OR_STRING(x) \
243 do { if (!BUFFER_OR_STRING_P (x)) \
244 x = wrong_type_argument (Qbuffer_or_string_p, (x)); \
245 } while (0)
246
247 #define CHECK_LIVE_BUFFER_OR_STRING(x) \
248 do { CHECK_BUFFER_OR_STRING (x); \
249 if (BUFFERP (x)) \
250 CHECK_LIVE_BUFFER (x); \
251 } while (0)
252 #define CONCHECK_LIVE_BUFFER_OR_STRING(x) \
253 do { CONCHECK_BUFFER_OR_STRING (x); \
254 if (BUFFERP (x)) \
255 CONCHECK_LIVE_BUFFER (x); \
256 } while (0)
257
258 235
259 236
260 /* NOTE: In all the following macros, we follow these rules concerning 237 /* NOTE: In all the following macros, we follow these rules concerning
261 multiple evaluation of the arguments: 238 multiple evaluation of the arguments:
262 239
263 1) Anything that's an lvalue can be evaluated more than once. 240 1) Anything that's an lvalue can be evaluated more than once.
264 2) Anything that's a Lisp Object can be evaluated more than once. 241 2) Anything that's a Lisp Object can be evaluated more than once.
265 This should probably be changed, but this follows the way 242 This should probably be changed, but this follows the way
266 that all the macros in lisp.h do things. 243 that all the macros in lisp.h do things.
267 3) 'struct buffer *' arguments can be evaluated more than once. 244 3) 'struct buffer *' arguments can be evaluated more than once.
268 4) Nothing else can be evaluated more than once. Use MTxx 245 4) Nothing else can be evaluated more than once. Use inline
269 variables to prevent multiple evaluation. 246 functions, if necessary, to prevent multiple evaluation.
270 5) An exception to (4) is that there are some macros below that 247 5) An exception to (4) is that there are some macros below that
271 may evaluate their arguments more than once. They are all 248 may evaluate their arguments more than once. They are all
272 denoted with the word "unsafe" in their name and are generally 249 denoted with the word "unsafe" in their name and are generally
273 meant to be called only by other macros that have already 250 meant to be called only by other macros that have already
274 stored the calling values in temporary variables. 251 stored the calling values in temporary variables.
275
276 */ 252 */
277 253
278 /************************************************************************/ 254 /************************************************************************/
279 /* */ 255 /* */
280 /* working with raw internal-format data */ 256 /* working with raw internal-format data */
281 /* */ 257 /* */
282 /************************************************************************/ 258 /************************************************************************/
283 259
284 /* Use these on contiguous strings of data. If the text you're 260 /* Use these on contiguous strings of data. If the text you're
285 operating on is known to come from a buffer, use the buffer-level 261 operating on is known to come from a buffer, use the buffer-level
286 functions below -- they know about the gap and may be more 262 functions below -- they know about the gap and may be more
429 real_inc_charptr_fun (ptr)) 405 real_inc_charptr_fun (ptr))
430 #else 406 #else
431 #define inc_charptr_fun(ptr) real_inc_charptr_fun (ptr) 407 #define inc_charptr_fun(ptr) real_inc_charptr_fun (ptr)
432 #endif 408 #endif
433 409
434 #define REAL_INC_CHARPTR(ptr) do \ 410 #define REAL_INC_CHARPTR(ptr) ((void) (real_inc_charptr_fun (ptr)))
435 { \ 411
436 real_inc_charptr_fun (ptr); \ 412 #define INC_CHARPTR(ptr) do { \
437 } while (0) 413 ASSERT_VALID_CHARPTR (ptr); \
438 414 REAL_INC_CHARPTR (ptr); \
439 #define INC_CHARPTR(ptr) do \ 415 } while (0)
440 { \ 416
441 ASSERT_VALID_CHARPTR (ptr); \ 417 #define REAL_DEC_CHARPTR(ptr) do { \
442 REAL_INC_CHARPTR (ptr); \ 418 (ptr)--; \
443 } while (0)
444
445 #define REAL_DEC_CHARPTR(ptr) do \
446 { \
447 (ptr)--; \
448 } while (!VALID_CHARPTR_P (ptr)) 419 } while (!VALID_CHARPTR_P (ptr))
449 420
450 #ifdef ERROR_CHECK_BUFPOS 421 #ifdef ERROR_CHECK_BUFPOS
451 #define DEC_CHARPTR(ptr) do \ 422 #define DEC_CHARPTR(ptr) do { \
452 { \
453 CONST Bufbyte *__dcptr__ = (ptr); \ 423 CONST Bufbyte *__dcptr__ = (ptr); \
454 CONST Bufbyte *__dcptr2__ = __dcptr__; \ 424 CONST Bufbyte *__dcptr2__ = __dcptr__; \
455 REAL_DEC_CHARPTR (__dcptr2__); \ 425 REAL_DEC_CHARPTR (__dcptr2__); \
456 assert (__dcptr__ - __dcptr2__ == \ 426 assert (__dcptr__ - __dcptr2__ == \
457 REP_BYTES_BY_FIRST_BYTE (*__dcptr2__)); \ 427 REP_BYTES_BY_FIRST_BYTE (*__dcptr2__)); \
461 #define DEC_CHARPTR(ptr) REAL_DEC_CHARPTR (ptr) 431 #define DEC_CHARPTR(ptr) REAL_DEC_CHARPTR (ptr)
462 #endif 432 #endif
463 433
464 #ifdef MULE 434 #ifdef MULE
465 435
466 #define VALIDATE_CHARPTR_BACKWARD(ptr) do \ 436 #define VALIDATE_CHARPTR_BACKWARD(ptr) do { \
467 { \
468 while (!VALID_CHARPTR_P (ptr)) ptr--; \ 437 while (!VALID_CHARPTR_P (ptr)) ptr--; \
469 } while (0) 438 } while (0)
470 439
471 /* This needs to be trickier to avoid the possibility of running off 440 /* This needs to be trickier to avoid the possibility of running off
472 the end of the string. */ 441 the end of the string. */
473 442
474 #define VALIDATE_CHARPTR_FORWARD(ptr) do \ 443 #define VALIDATE_CHARPTR_FORWARD(ptr) do { \
475 { \
476 Bufbyte *__vcfptr__ = (ptr); \ 444 Bufbyte *__vcfptr__ = (ptr); \
477 VALIDATE_CHARPTR_BACKWARD (__vcfptr__); \ 445 VALIDATE_CHARPTR_BACKWARD (__vcfptr__); \
478 if (__vcfptr__ != (ptr)) \ 446 if (__vcfptr__ != (ptr)) \
479 { \ 447 { \
480 (ptr) = __vcfptr__; \ 448 (ptr) = __vcfptr__; \
606 ; \ 574 ; \
607 else if (CHAR_INTP (x)) \ 575 else if (CHAR_INTP (x)) \
608 x = make_char (XINT (x)); \ 576 x = make_char (XINT (x)); \
609 else \ 577 else \
610 x = wrong_type_argument (Qcharacterp, x); \ 578 x = wrong_type_argument (Qcharacterp, x); \
611 } while (0) 579 } while (0)
612 580
613 #ifdef MULE 581 #ifdef MULE
614 # define MAX_EMCHAR_LEN 4 582 # define MAX_EMCHAR_LEN 4
615 #else 583 #else
616 # define MAX_EMCHAR_LEN 1 584 # define MAX_EMCHAR_LEN 1
617 #endif 585 #endif
618 586
619 587
620 /*----------------------------------------------------------------------*/ 588 /*----------------------------------------------------------------------*/
621 /* Accessor macros for important positions in a buffer */ 589 /* Accessor macros for important positions in a buffer */
622 /*----------------------------------------------------------------------*/ 590 /*----------------------------------------------------------------------*/
623 591
624 /* We put them here because some stuff below wants them before the 592 /* We put them here because some stuff below wants them before the
625 place where we would normally put them. */ 593 place where we would normally put them. */
626 594
646 /* Point. */ 614 /* Point. */
647 #define BI_BUF_PT(buf) ((buf)->pt + 0) 615 #define BI_BUF_PT(buf) ((buf)->pt + 0)
648 #define BUF_PT(buf) ((buf)->bufpt + 0) 616 #define BUF_PT(buf) ((buf)->bufpt + 0)
649 617
650 /*----------------------------------------------------------------------*/ 618 /*----------------------------------------------------------------------*/
651 /* Converting between positions and addresses */ 619 /* Converting between positions and addresses */
652 /*----------------------------------------------------------------------*/ 620 /*----------------------------------------------------------------------*/
653 621
654 /* Convert the address of a byte in the buffer into a position. */ 622 /* Convert the address of a byte in the buffer into a position. */
655 INLINE Bytind BI_BUF_PTR_BYTE_POS (struct buffer *buf, Bufbyte *ptr); 623 INLINE Bytind BI_BUF_PTR_BYTE_POS (struct buffer *buf, Bufbyte *ptr);
656 INLINE Bytind 624 INLINE Bytind
689 657
690 #define BUF_BYTE_ADDRESS_BEFORE(buf, pos) \ 658 #define BUF_BYTE_ADDRESS_BEFORE(buf, pos) \
691 BI_BUF_BYTE_ADDRESS_BEFORE (buf, bufpos_to_bytind (buf, pos)) 659 BI_BUF_BYTE_ADDRESS_BEFORE (buf, bufpos_to_bytind (buf, pos))
692 660
693 /*----------------------------------------------------------------------*/ 661 /*----------------------------------------------------------------------*/
694 /* Converting between byte indices and memory indices */ 662 /* Converting between byte indices and memory indices */
695 /*----------------------------------------------------------------------*/ 663 /*----------------------------------------------------------------------*/
696 664
697 INLINE int valid_memind_p (struct buffer *buf, Memind x); 665 INLINE int valid_memind_p (struct buffer *buf, Memind x);
698 INLINE int 666 INLINE int
699 valid_memind_p (struct buffer *buf, Memind x) 667 valid_memind_p (struct buffer *buf, Memind x)
708 bytind_to_memind (struct buffer *buf, Bytind x) 676 bytind_to_memind (struct buffer *buf, Bytind x)
709 { 677 {
710 return (Memind) ((x > (buf)->text->gpt) ? (x + (buf)->text->gap_size) : x); 678 return (Memind) ((x > (buf)->text->gpt) ? (x + (buf)->text->gap_size) : x);
711 } 679 }
712 680
713 #ifdef ERROR_CHECK_BUFPOS
714 681
715 INLINE Bytind memind_to_bytind (struct buffer *buf, Memind x); 682 INLINE Bytind memind_to_bytind (struct buffer *buf, Memind x);
716 INLINE Bytind 683 INLINE Bytind
717 memind_to_bytind (struct buffer *buf, Memind x) 684 memind_to_bytind (struct buffer *buf, Memind x)
718 { 685 {
686 #ifdef ERROR_CHECK_BUFPOS
719 assert (valid_memind_p (buf, x)); 687 assert (valid_memind_p (buf, x));
688 #endif
720 return (Bytind) ((x > (Memind) (buf)->text->gpt) ? 689 return (Bytind) ((x > (Memind) (buf)->text->gpt) ?
721 x - (buf)->text->gap_size : 690 x - (buf)->text->gap_size :
722 x); 691 x);
723 } 692 }
724 693
725 #else 694 #define memind_to_bufpos(buf, x) \
726
727 INLINE Bytind memind_to_bytind (struct buffer *buf, Memind x);
728 INLINE Bytind
729 memind_to_bytind (struct buffer *buf, Memind x)
730 {
731 return (Bytind) ((x > (Memind) (buf)->text->gpt) ?
732 x - (buf)->text->gap_size :
733 x);
734 }
735
736 #endif
737
738 #define memind_to_bufpos(buf, x) \
739 bytind_to_bufpos (buf, memind_to_bytind (buf, x)) 695 bytind_to_bufpos (buf, memind_to_bytind (buf, x))
740 #define bufpos_to_memind(buf, x) \ 696 #define bufpos_to_memind(buf, x) \
741 bytind_to_memind (buf, bufpos_to_bytind (buf, x)) 697 bytind_to_memind (buf, bufpos_to_bytind (buf, x))
742 698
743 /* These macros generalize many standard buffer-position functions to 699 /* These macros generalize many standard buffer-position functions to
744 either a buffer or a string. */ 700 either a buffer or a string. */
745 701
754 (BUFFERP (obj) ? memind_to_bytind (XBUFFER (obj), ind) : (Bytind) ind) 710 (BUFFERP (obj) ? memind_to_bytind (XBUFFER (obj), ind) : (Bytind) ind)
755 711
756 /* Converting between Bufpos's and Bytinds, for a buffer-or-string. 712 /* Converting between Bufpos's and Bytinds, for a buffer-or-string.
757 For strings, this maps to the bytecount<->charcount converters. */ 713 For strings, this maps to the bytecount<->charcount converters. */
758 714
759 #define buffer_or_string_bufpos_to_bytind(obj, pos) \ 715 #define buffer_or_string_bufpos_to_bytind(obj, pos) \
760 (BUFFERP (obj) ? bufpos_to_bytind (XBUFFER (obj), pos) : \ 716 (BUFFERP (obj) ? bufpos_to_bytind (XBUFFER (obj), pos) : \
761 (Bytind) charcount_to_bytecount (XSTRING_DATA (obj), pos)) 717 (Bytind) charcount_to_bytecount (XSTRING_DATA (obj), pos))
762 718
763 #define buffer_or_string_bytind_to_bufpos(obj, ind) \ 719 #define buffer_or_string_bytind_to_bufpos(obj, ind) \
764 (BUFFERP (obj) ? bytind_to_bufpos (XBUFFER (obj), ind) : \ 720 (BUFFERP (obj) ? bytind_to_bufpos (XBUFFER (obj), ind) : \
765 (Bufpos) bytecount_to_charcount (XSTRING_DATA (obj), ind)) 721 (Bufpos) bytecount_to_charcount (XSTRING_DATA (obj), ind))
766 722
767 /* Similar for Bufpos's and Meminds. */ 723 /* Similar for Bufpos's and Meminds. */
768 724
769 #define buffer_or_string_bufpos_to_memind(obj, pos) \ 725 #define buffer_or_string_bufpos_to_memind(obj, pos) \
770 (BUFFERP (obj) ? bufpos_to_memind (XBUFFER (obj), pos) : \ 726 (BUFFERP (obj) ? bufpos_to_memind (XBUFFER (obj), pos) : \
771 (Memind) charcount_to_bytecount (XSTRING_DATA (obj), pos)) 727 (Memind) charcount_to_bytecount (XSTRING_DATA (obj), pos))
772 728
773 #define buffer_or_string_memind_to_bufpos(obj, ind) \ 729 #define buffer_or_string_memind_to_bufpos(obj, ind) \
774 (BUFFERP (obj) ? memind_to_bufpos (XBUFFER (obj), ind) : \ 730 (BUFFERP (obj) ? memind_to_bufpos (XBUFFER (obj), ind) : \
775 (Bufpos) bytecount_to_charcount (XSTRING_DATA (obj), ind)) 731 (Bufpos) bytecount_to_charcount (XSTRING_DATA (obj), ind))
776 732
777 /************************************************************************/ 733 /************************************************************************/
778 /* */ 734 /* */
779 /* working with buffer-level data */ 735 /* working with buffer-level data */
849 Given a Bytind, return the equivalent Bufpos as a Lisp Object. 805 Given a Bytind, return the equivalent Bufpos as a Lisp Object.
850 */ 806 */
851 807
852 808
853 /*----------------------------------------------------------------------*/ 809 /*----------------------------------------------------------------------*/
854 /* working with byte indices */ 810 /* working with byte indices */
855 /*----------------------------------------------------------------------*/ 811 /*----------------------------------------------------------------------*/
856 812
857 #ifdef MULE 813 #ifdef MULE
858 # define VALID_BYTIND_P(buf, x) \ 814 # define VALID_BYTIND_P(buf, x) \
859 BUFBYTE_FIRST_BYTE_P (*BI_BUF_BYTE_ADDRESS (buf, x)) 815 BUFBYTE_FIRST_BYTE_P (*BI_BUF_BYTE_ADDRESS (buf, x))
861 # define VALID_BYTIND_P(buf, x) 1 817 # define VALID_BYTIND_P(buf, x) 1
862 #endif 818 #endif
863 819
864 #ifdef ERROR_CHECK_BUFPOS 820 #ifdef ERROR_CHECK_BUFPOS
865 821
866 # define ASSERT_VALID_BYTIND_UNSAFE(buf, x) do \ 822 # define ASSERT_VALID_BYTIND_UNSAFE(buf, x) do { \
867 { \
868 assert (BUFFER_LIVE_P (buf)); \ 823 assert (BUFFER_LIVE_P (buf)); \
869 assert ((x) >= BI_BUF_BEG (buf) && x <= BI_BUF_Z (buf)); \ 824 assert ((x) >= BI_BUF_BEG (buf) && x <= BI_BUF_Z (buf)); \
870 assert (VALID_BYTIND_P (buf, x)); \ 825 assert (VALID_BYTIND_P (buf, x)); \
871 } while (0) 826 } while (0)
872 # define ASSERT_VALID_BYTIND_BACKWARD_UNSAFE(buf, x) do \ 827 # define ASSERT_VALID_BYTIND_BACKWARD_UNSAFE(buf, x) do { \
873 { \
874 assert (BUFFER_LIVE_P (buf)); \ 828 assert (BUFFER_LIVE_P (buf)); \
875 assert ((x) > BI_BUF_BEG (buf) && x <= BI_BUF_Z (buf)); \ 829 assert ((x) > BI_BUF_BEG (buf) && x <= BI_BUF_Z (buf)); \
876 assert (VALID_BYTIND_P (buf, x)); \ 830 assert (VALID_BYTIND_P (buf, x)); \
877 } while (0) 831 } while (0)
878 # define ASSERT_VALID_BYTIND_FORWARD_UNSAFE(buf, x) do \ 832 # define ASSERT_VALID_BYTIND_FORWARD_UNSAFE(buf, x) do { \
879 { \
880 assert (BUFFER_LIVE_P (buf)); \ 833 assert (BUFFER_LIVE_P (buf)); \
881 assert ((x) >= BI_BUF_BEG (buf) && x < BI_BUF_Z (buf)); \ 834 assert ((x) >= BI_BUF_BEG (buf) && x < BI_BUF_Z (buf)); \
882 assert (VALID_BYTIND_P (buf, x)); \ 835 assert (VALID_BYTIND_P (buf, x)); \
883 } while (0) 836 } while (0)
884 837
966 } 919 }
967 920
968 #define BYTIND_INVALID ((Bytind) -1) 921 #define BYTIND_INVALID ((Bytind) -1)
969 922
970 /*----------------------------------------------------------------------*/ 923 /*----------------------------------------------------------------------*/
971 /* Converting between buffer positions and byte indices */ 924 /* Converting between buffer positions and byte indices */
972 /*----------------------------------------------------------------------*/ 925 /*----------------------------------------------------------------------*/
973 926
974 #ifdef MULE 927 #ifdef MULE
975 928
976 Bytind bufpos_to_bytind_func (struct buffer *buf, Bufpos x); 929 Bytind bufpos_to_bytind_func (struct buffer *buf, Bufpos x);
1087 1040
1088 1041
1089 1042
1090 1043
1091 /************************************************************************/ 1044 /************************************************************************/
1092 /* */ 1045 /* */
1093 /* working with externally-formatted data */ 1046 /* working with externally-formatted data */
1094 /* */ 1047 /* */
1095 /************************************************************************/ 1048 /************************************************************************/
1096 1049
1097 /* Sometimes strings need to be converted into one or another 1050 /* Sometimes strings need to be converted into one or another
1098 external format, for passing to a library function. (Note 1051 external format, for passing to a library function. (Note
1099 that we encapsulate and automatically convert the arguments 1052 that we encapsulate and automatically convert the arguments
1107 /* WARNING: These use a static buffer. This can lead to disaster if 1060 /* WARNING: These use a static buffer. This can lead to disaster if
1108 these functions are not used *very* carefully. Under normal 1061 these functions are not used *very* carefully. Under normal
1109 circumstances, do not call these functions; call the front ends 1062 circumstances, do not call these functions; call the front ends
1110 below. */ 1063 below. */
1111 1064
1112 CONST Extbyte *convert_to_external_format (CONST Bufbyte *ptr, 1065 Extbyte *convert_to_external_format (CONST Bufbyte *ptr,
1113 Bytecount len, 1066 Bytecount len,
1114 Extcount *len_out, 1067 Extcount *len_out,
1115 enum external_data_format fmt); 1068 enum external_data_format fmt);
1116 CONST Bufbyte *convert_from_external_format (CONST Extbyte *ptr, 1069 Bufbyte *convert_from_external_format (CONST Extbyte *ptr,
1117 Extcount len, 1070 Extcount len,
1118 Bytecount *len_out, 1071 Bytecount *len_out,
1119 enum external_data_format fmt); 1072 enum external_data_format fmt);
1120 1073
1121 #else /* ! MULE */ 1074 #else /* ! MULE */
1122 1075
1123 #define convert_to_external_format(ptr, len, len_out, fmt) \ 1076 #define convert_to_external_format(ptr, len, len_out, fmt) \
1124 (*(len_out) = (int) (len), (CONST Extbyte *) (ptr)) 1077 (*(len_out) = (int) (len), (Extbyte *) (ptr))
1125 #define convert_from_external_format(ptr, len, len_out, fmt) \ 1078 #define convert_from_external_format(ptr, len, len_out, fmt) \
1126 (*(len_out) = (Bytecount) (len), (CONST Bufbyte *) (ptr)) 1079 (*(len_out) = (Bytecount) (len), (Bufbyte *) (ptr))
1127 1080
1128 #endif /* ! MULE */ 1081 #endif /* ! MULE */
1129 1082
1130 /* In all of the following macros we use the following general principles: 1083 /* In all of the following macros we use the following general principles:
1131 1084
1145 strings. In general you should use these sorts of pointers only 1098 strings. In general you should use these sorts of pointers only
1146 to interface to library routines and not for general manipulation, 1099 to interface to library routines and not for general manipulation,
1147 as you are liable to lose embedded nulls and such. This could 1100 as you are liable to lose embedded nulls and such. This could
1148 be a big problem for routines that want Unicode-formatted data, 1101 be a big problem for routines that want Unicode-formatted data,
1149 which is likely to have lots of embedded nulls in it. 1102 which is likely to have lots of embedded nulls in it.
1103 (In the real world, though, external Unicode data will be UTF-8,
1104 which will not have embedded nulls and is ASCII-compatible - martin)
1150 1105
1151 -- Functions that work with Lisp strings accept strings as Lisp Objects 1106 -- Functions that work with Lisp strings accept strings as Lisp Objects
1152 (as opposed to the `struct Lisp_String *' for some of the other 1107 (as opposed to the `struct Lisp_String *' for some of the other
1153 string accessors). This is for convenience in working with the 1108 string accessors). This is for convenience in working with the
1154 functions, as otherwise you will almost always have to call 1109 functions, as otherwise you will almost always have to call
1178 middle of the arguments to the function call and you are unbelievably 1133 middle of the arguments to the function call and you are unbelievably
1179 hosed.) */ 1134 hosed.) */
1180 1135
1181 #ifdef MULE 1136 #ifdef MULE
1182 1137
1183 #define GET_CHARPTR_EXT_DATA_ALLOCA(ptr, len, fmt, stick_value_here, stick_len_here) \ 1138 #define GET_CHARPTR_EXT_DATA_ALLOCA(ptr, len, fmt, ptr_out, len_out) do \
1184 do \
1185 { \ 1139 { \
1186 Bytecount __gceda_len_in__ = (len); \ 1140 Bytecount gceda_len_in = (Bytecount) (len); \
1187 Extcount __gceda_len_out__; \ 1141 Extcount gceda_len_out; \
1188 CONST Bufbyte *__gceda_ptr_in__ = (ptr); \ 1142 CONST Bufbyte *gceda_ptr_in = (ptr); \
1189 CONST Extbyte *__gceda_ptr_out__; \ 1143 Extbyte *gceda_ptr_out = \
1190 \ 1144 convert_to_external_format (gceda_ptr_in, gceda_len_in, \
1191 __gceda_ptr_out__ = \ 1145 &gceda_len_out, fmt); \
1192 convert_to_external_format (__gceda_ptr_in__, __gceda_len_in__, \
1193 &__gceda_len_out__, fmt); \
1194 /* If the new string is identical to the old (will be the case most \ 1146 /* If the new string is identical to the old (will be the case most \
1195 of the time), just return the same string back. This saves \ 1147 of the time), just return the same string back. This saves \
1196 on alloca()ing, which can be useful on C alloca() machines and \ 1148 on alloca()ing, which can be useful on C alloca() machines and \
1197 on stack-space-challenged environments. */ \ 1149 on stack-space-challenged environments. */ \
1198 \ 1150 \
1199 if (__gceda_len_in__ == __gceda_len_out__ && \ 1151 if (gceda_len_in == gceda_len_out && \
1200 !memcmp (__gceda_ptr_in__, __gceda_ptr_out__, __gceda_len_out__)) \ 1152 !memcmp (gceda_ptr_in, gceda_ptr_out, gceda_len_out)) \
1201 { \ 1153 { \
1202 (stick_value_here) = (CONST Extbyte *) __gceda_ptr_in__; \ 1154 (ptr_out) = (Extbyte *) gceda_ptr_in; \
1203 (stick_len_here) = (Extcount) __gceda_len_in__; \ 1155 (len_out) = (Extcount) gceda_len_in; \
1204 } \ 1156 } \
1205 else \ 1157 else \
1206 { \ 1158 { \
1207 (stick_value_here) = (CONST Extbyte *) alloca(1 + __gceda_len_out__);\ 1159 (ptr_out) = (Extbyte *) alloca (1 + gceda_len_out); \
1208 memcpy ((Extbyte *) stick_value_here, __gceda_ptr_out__, \ 1160 memcpy ((void *) ptr_out, gceda_ptr_out, 1 + gceda_len_out); \
1209 1 + __gceda_len_out__); \ 1161 (len_out) = (Extcount) gceda_len_out; \
1210 (stick_len_here) = (Extcount) __gceda_len_out__; \
1211 } \ 1162 } \
1212 } while (0) 1163 } while (0)
1213 1164
1214 #else /* ! MULE */ 1165 #else /* ! MULE */
1215 1166
1216 #define GET_CHARPTR_EXT_DATA_ALLOCA(ptr, len, fmt, stick_value_here, stick_len_here)\ 1167 #define GET_CHARPTR_EXT_DATA_ALLOCA(ptr, len, fmt, ptr_out, len_out) do \
1217 do \ 1168 { \
1169 (ptr_out) = (Extbyte *) (ptr); \
1170 (len_out) = (Extcount) (len); \
1171 } while (0)
1172
1173 #endif /* ! MULE */
1174
1175 #define GET_C_CHARPTR_EXT_DATA_ALLOCA(ptr, fmt, ptr_out) do \
1218 { \ 1176 { \
1219 (stick_value_here) = (CONST Extbyte *) (ptr); \ 1177 Extcount gcceda_ignored_len; \
1220 (stick_len_here) = (Extcount) (len); \ 1178 CONST Bufbyte *gcceda_ptr_in = (CONST Bufbyte *) (ptr); \
1221 } while (0) 1179 Extbyte *gcceda_ptr_out; \
1222 1180 \
1223 #endif /* ! MULE */ 1181 GET_CHARPTR_EXT_DATA_ALLOCA (gcceda_ptr_in, \
1224 1182 strlen ((char *) gcceda_ptr_in), \
1225 #define GET_C_CHARPTR_EXT_DATA_ALLOCA(ptr, fmt, stick_value_here) \ 1183 fmt, \
1226 do \ 1184 gcceda_ptr_out, \
1227 { \ 1185 gcceda_ignored_len); \
1228 Extcount __gcceda_ignored_len__; \ 1186 (ptr_out) = (char *) gcceda_ptr_out; \
1229 CONST char *__gcceda_ptr_in__; \ 1187 } while (0)
1230 CONST Extbyte *__gcceda_ptr_out__; \ 1188
1231 \ 1189 #define GET_C_CHARPTR_EXT_BINARY_DATA_ALLOCA(ptr, ptr_out) \
1232 __gcceda_ptr_in__ = ptr; \ 1190 GET_C_CHARPTR_EXT_DATA_ALLOCA (ptr, FORMAT_BINARY, ptr_out)
1233 GET_CHARPTR_EXT_DATA_ALLOCA ((CONST Extbyte *) __gcceda_ptr_in__, \ 1191 #define GET_CHARPTR_EXT_BINARY_DATA_ALLOCA(ptr, len, ptr_out, len_out) \
1234 strlen (__gcceda_ptr_in__), fmt, \ 1192 GET_CHARPTR_EXT_DATA_ALLOCA (ptr, len, FORMAT_BINARY, ptr_out, len_out)
1235 __gcceda_ptr_out__, \ 1193
1236 __gcceda_ignored_len__); \ 1194 #define GET_C_CHARPTR_EXT_FILENAME_DATA_ALLOCA(ptr, ptr_out) \
1237 (stick_value_here) = (CONST char *) __gcceda_ptr_out__; \ 1195 GET_C_CHARPTR_EXT_DATA_ALLOCA (ptr, FORMAT_FILENAME, ptr_out)
1238 } while (0) 1196 #define GET_CHARPTR_EXT_FILENAME_DATA_ALLOCA(ptr, len, ptr_out, len_out) \
1239 1197 GET_CHARPTR_EXT_DATA_ALLOCA (ptr, len, FORMAT_FILENAME, ptr_out, len_out)
1240 #define GET_C_CHARPTR_EXT_BINARY_DATA_ALLOCA(ptr, stick_value_here) \ 1198
1241 GET_C_CHARPTR_EXT_DATA_ALLOCA (ptr, FORMAT_BINARY, stick_value_here) 1199 #define GET_C_CHARPTR_EXT_CTEXT_DATA_ALLOCA(ptr, ptr_out) \
1242 #define GET_CHARPTR_EXT_BINARY_DATA_ALLOCA(ptr, len, stick_value_here, stick_len_here) \ 1200 GET_C_CHARPTR_EXT_DATA_ALLOCA (ptr, FORMAT_CTEXT, ptr_out)
1243 GET_CHARPTR_EXT_DATA_ALLOCA (ptr, len, FORMAT_BINARY, stick_value_here, \ 1201 #define GET_CHARPTR_EXT_CTEXT_DATA_ALLOCA(ptr, len, ptr_out, len_out) \
1244 stick_len_here) 1202 GET_CHARPTR_EXT_DATA_ALLOCA (ptr, len, FORMAT_CTEXT, ptr_out, len_out)
1245
1246 #define GET_C_CHARPTR_EXT_FILENAME_DATA_ALLOCA(ptr, stick_value_here) \
1247 GET_C_CHARPTR_EXT_DATA_ALLOCA (ptr, FORMAT_FILENAME, stick_value_here)
1248 #define GET_CHARPTR_EXT_FILENAME_DATA_ALLOCA(ptr, len, stick_value_here, stick_len_here) \
1249 GET_CHARPTR_EXT_DATA_ALLOCA (ptr, len, FORMAT_FILENAME, stick_value_here, \
1250 stick_len_here)
1251
1252 #define GET_C_CHARPTR_EXT_CTEXT_DATA_ALLOCA(ptr, stick_value_here) \
1253 GET_C_CHARPTR_EXT_DATA_ALLOCA (ptr, FORMAT_CTEXT, stick_value_here)
1254 #define GET_CHARPTR_EXT_CTEXT_DATA_ALLOCA(ptr, len, stick_value_here, stick_len_here) \
1255 GET_CHARPTR_EXT_DATA_ALLOCA (ptr, len, FORMAT_CTEXT, stick_value_here, \
1256 stick_len_here)
1257 1203
1258 /* Maybe convert external charptr's data into internal format and store 1204 /* Maybe convert external charptr's data into internal format and store
1259 the result in alloca()'ed space. 1205 the result in alloca()'ed space.
1260 1206
1261 You may wonder why this is written in this fashion and not as a 1207 You may wonder why this is written in this fashion and not as a
1267 middle of the arguments to the function call and you are unbelievably 1213 middle of the arguments to the function call and you are unbelievably
1268 hosed.) */ 1214 hosed.) */
1269 1215
1270 #ifdef MULE 1216 #ifdef MULE
1271 1217
1272 #define GET_CHARPTR_INT_DATA_ALLOCA(ptr, len, fmt, stick_value_here, stick_len_here)\ 1218 #define GET_CHARPTR_INT_DATA_ALLOCA(ptr, len, fmt, ptr_out, len_out) do \
1273 do \
1274 { \ 1219 { \
1275 Extcount __gcida_len_in__ = (len); \ 1220 Extcount gcida_len_in = (Extcount) (len); \
1276 Bytecount __gcida_len_out__; \ 1221 Bytecount gcida_len_out; \
1277 CONST Extbyte *__gcida_ptr_in__ = (ptr); \ 1222 CONST Extbyte *gcida_ptr_in = (ptr); \
1278 CONST Bufbyte *__gcida_ptr_out__; \ 1223 Bufbyte *gcida_ptr_out = \
1279 \ 1224 convert_from_external_format (gcida_ptr_in, gcida_len_in, \
1280 __gcida_ptr_out__ = \ 1225 &gcida_len_out, fmt); \
1281 convert_from_external_format (__gcida_ptr_in__, __gcida_len_in__, \
1282 &__gcida_len_out__, fmt); \
1283 /* If the new string is identical to the old (will be the case most \ 1226 /* If the new string is identical to the old (will be the case most \
1284 of the time), just return the same string back. This saves \ 1227 of the time), just return the same string back. This saves \
1285 on alloca()ing, which can be useful on C alloca() machines and \ 1228 on alloca()ing, which can be useful on C alloca() machines and \
1286 on stack-space-challenged environments. */ \ 1229 on stack-space-challenged environments. */ \
1287 \ 1230 \
1288 if (__gcida_len_in__ == __gcida_len_out__ && \ 1231 if (gcida_len_in == gcida_len_out && \
1289 !memcmp (__gcida_ptr_in__, __gcida_ptr_out__, __gcida_len_out__)) \ 1232 !memcmp (gcida_ptr_in, gcida_ptr_out, gcida_len_out)) \
1290 { \ 1233 { \
1291 (stick_value_here) = (CONST Bufbyte *) __gcida_ptr_in__; \ 1234 (ptr_out) = (Bufbyte *) gcida_ptr_in; \
1292 (stick_len_here) = (Bytecount) __gcida_len_in__; \ 1235 (len_out) = (Bytecount) gcida_len_in; \
1293 } \ 1236 } \
1294 else \ 1237 else \
1295 { \ 1238 { \
1296 (stick_value_here) = (CONST Extbyte *) alloca (1 + __gcida_len_out__); \ 1239 (ptr_out) = (Extbyte *) alloca (1 + gcida_len_out); \
1297 memcpy ((Bufbyte *) stick_value_here, __gcida_ptr_out__, \ 1240 memcpy ((void *) ptr_out, gcida_ptr_out, 1 + gcida_len_out); \
1298 1 + __gcida_len_out__); \ 1241 (len_out) = gcida_len_out; \
1299 (stick_len_here) = __gcida_len_out__; \
1300 } \ 1242 } \
1301 } while (0) 1243 } while (0)
1302 1244
1303 #else /* ! MULE */ 1245 #else /* ! MULE */
1304 1246
1305 #define GET_CHARPTR_INT_DATA_ALLOCA(ptr, len, fmt, stick_value_here, stick_len_here)\ 1247 #define GET_CHARPTR_INT_DATA_ALLOCA(ptr, len, fmt, ptr_out, len_out) do \
1306 do \ 1248 { \
1307 { \ 1249 (ptr_out) = (Bufbyte *) (ptr); \
1308 (stick_value_here) = (CONST Bufbyte *) (ptr); \ 1250 (len_out) = (Bytecount) (len); \
1309 (stick_len_here) = (Bytecount) (len); \
1310 } while (0) 1251 } while (0)
1311 1252
1312 #endif /* ! MULE */ 1253 #endif /* ! MULE */
1313 1254
1314 #define GET_C_CHARPTR_INT_DATA_ALLOCA(ptr, fmt, stick_value_here) \ 1255 #define GET_C_CHARPTR_INT_DATA_ALLOCA(ptr, fmt, ptr_out) do \
1315 do \ 1256 { \
1316 { \ 1257 Bytecount gccida_ignored_len; \
1317 Bytecount __gccida_ignored_len__; \ 1258 CONST Extbyte *gccida_ptr_in = (CONST Extbyte *) (ptr); \
1318 CONST char *__gccida_ptr_in__; \ 1259 Bufbyte *gccida_ptr_out; \
1319 CONST Bufbyte *__gccida_ptr_out__; \ 1260 \
1320 \ 1261 GET_CHARPTR_INT_DATA_ALLOCA (gccida_ptr_in, \
1321 __gccida_ptr_in__ = ptr; \ 1262 strlen ((char *) gccida_ptr_in), \
1322 GET_CHARPTR_INT_DATA_ALLOCA ((CONST Extbyte *) __gccida_ptr_in__, \ 1263 fmt, \
1323 strlen (__gccida_ptr_in__), fmt, \ 1264 gccida_ptr_out, \
1324 __gccida_ptr_out__, \ 1265 gccida_ignored_len); \
1325 __gccida_ignored_len__); \ 1266 (ptr_out) = gccida_ptr_out; \
1326 (stick_value_here) = (CONST char *) __gccida_ptr_out__; \ 1267 } while (0)
1327 } while (0) 1268
1328 1269 #define GET_C_CHARPTR_INT_BINARY_DATA_ALLOCA(ptr, ptr_out) \
1329 #define GET_C_CHARPTR_INT_BINARY_DATA_ALLOCA(ptr, stick_value_here) \ 1270 GET_C_CHARPTR_INT_DATA_ALLOCA (ptr, FORMAT_BINARY, ptr_out)
1330 GET_C_CHARPTR_INT_DATA_ALLOCA (ptr, FORMAT_BINARY, stick_value_here) 1271 #define GET_CHARPTR_INT_BINARY_DATA_ALLOCA(ptr, len, ptr_out, len_out) \
1331 #define GET_CHARPTR_INT_BINARY_DATA_ALLOCA(ptr, len, stick_value_here, stick_len_here) \ 1272 GET_CHARPTR_INT_DATA_ALLOCA (ptr, len, FORMAT_BINARY, ptr_out, len_out)
1332 GET_CHARPTR_INT_DATA_ALLOCA (ptr, len, FORMAT_BINARY, stick_value_here, \ 1273
1333 stick_len_here) 1274 #define GET_C_CHARPTR_INT_FILENAME_DATA_ALLOCA(ptr, ptr_out) \
1334 1275 GET_C_CHARPTR_INT_DATA_ALLOCA (ptr, FORMAT_FILENAME, ptr_out)
1335 #define GET_C_CHARPTR_INT_FILENAME_DATA_ALLOCA(ptr, stick_value_here) \ 1276 #define GET_CHARPTR_INT_FILENAME_DATA_ALLOCA(ptr, len, ptr_out, len_out) \
1336 GET_C_CHARPTR_INT_DATA_ALLOCA (ptr, FORMAT_FILENAME, stick_value_here) 1277 GET_CHARPTR_INT_DATA_ALLOCA (ptr, len, FORMAT_FILENAME, ptr_out, len_out)
1337 #define GET_CHARPTR_INT_FILENAME_DATA_ALLOCA(ptr, len, stick_value_here, stick_len_here) \ 1278
1338 GET_CHARPTR_INT_DATA_ALLOCA (ptr, len, FORMAT_FILENAME, stick_value_here, \ 1279 #define GET_C_CHARPTR_INT_CTEXT_DATA_ALLOCA(ptr, ptr_out) \
1339 stick_len_here) 1280 GET_C_CHARPTR_INT_DATA_ALLOCA (ptr, FORMAT_CTEXT, ptr_out)
1340 1281 #define GET_CHARPTR_INT_CTEXT_DATA_ALLOCA(ptr, len, ptr_out, len_out) \
1341 #define GET_C_CHARPTR_INT_CTEXT_DATA_ALLOCA(ptr, stick_value_here) \ 1282 GET_CHARPTR_INT_DATA_ALLOCA (ptr, len, FORMAT_CTEXT, ptr_out, len_out)
1342 GET_C_CHARPTR_INT_DATA_ALLOCA (ptr, FORMAT_CTEXT, stick_value_here)
1343 #define GET_CHARPTR_INT_CTEXT_DATA_ALLOCA(ptr, len, stick_value_here, stick_len_here) \
1344 GET_CHARPTR_INT_DATA_ALLOCA (ptr, len, FORMAT_CTEXT, stick_value_here, \
1345 stick_len_here)
1346 1283
1347 1284
1348 /* Maybe convert Lisp string's data into ext-format and store the result in 1285 /* Maybe convert Lisp string's data into ext-format and store the result in
1349 alloca()'ed space. 1286 alloca()'ed space.
1350 1287
1355 architecture. (If you put a call to alloca() in the argument to 1292 architecture. (If you put a call to alloca() in the argument to
1356 a function call, the stack space gets allocated right in the 1293 a function call, the stack space gets allocated right in the
1357 middle of the arguments to the function call and you are unbelievably 1294 middle of the arguments to the function call and you are unbelievably
1358 hosed.) */ 1295 hosed.) */
1359 1296
1360 #define GET_STRING_EXT_DATA_ALLOCA(s, fmt, stick_value_here, stick_len_here)\ 1297 #define GET_STRING_EXT_DATA_ALLOCA(s, fmt, ptr_out, len_out) do \
1361 do \
1362 { \
1363 Extcount __gseda_len__; \
1364 CONST Extbyte *__gseda_ptr__; \
1365 struct Lisp_String *__gseda_s__ = XSTRING (s); \
1366 \
1367 __gseda_ptr__ = convert_to_external_format (string_data (__gseda_s__), \
1368 string_length (__gseda_s__), \
1369 &__gseda_len__, fmt); \
1370 (stick_value_here) = (CONST Extbyte *) alloca (1 + __gseda_len__); \
1371 memcpy ((Extbyte *) stick_value_here, __gseda_ptr__, 1 + __gseda_len__); \
1372 (stick_len_here) = __gseda_len__; \
1373 } while (0)
1374
1375
1376 #define GET_C_STRING_EXT_DATA_ALLOCA(s, fmt, stick_value_here) \
1377 do \
1378 { \ 1298 { \
1379 Extcount __gcseda_ignored_len__; \ 1299 Extcount gseda_len_out; \
1380 CONST Extbyte *__gcseda_ptr__; \ 1300 struct Lisp_String *gseda_s = XSTRING (s); \
1301 Extbyte * gseda_ptr_out = \
1302 convert_to_external_format (string_data (gseda_s), \
1303 string_length (gseda_s), \
1304 &gseda_len_out, fmt); \
1305 (ptr_out) = (Extbyte *) alloca (1 + gseda_len_out); \
1306 memcpy ((void *) ptr_out, gseda_ptr_out, 1 + gseda_len_out); \
1307 (len_out) = gseda_len_out; \
1308 } while (0)
1309
1310
1311 #define GET_C_STRING_EXT_DATA_ALLOCA(s, fmt, ptr_out) do \
1312 { \
1313 Extcount gcseda_ignored_len; \
1314 Extbyte *gcseda_ptr_out; \
1381 \ 1315 \
1382 GET_STRING_EXT_DATA_ALLOCA (s, fmt, __gcseda_ptr__, \ 1316 GET_STRING_EXT_DATA_ALLOCA (s, fmt, gcseda_ptr_out, \
1383 __gcseda_ignored_len__); \ 1317 gcseda_ignored_len); \
1384 (stick_value_here) = (CONST char *) __gcseda_ptr__; \ 1318 (ptr_out) = (char *) gcseda_ptr_out; \
1385 } while (0) 1319 } while (0)
1386 1320
1387 #define GET_STRING_BINARY_DATA_ALLOCA(s, stick_value_here, stick_len_here) \ 1321 #define GET_STRING_BINARY_DATA_ALLOCA(s, ptr_out, len_out) \
1388 GET_STRING_EXT_DATA_ALLOCA (s, FORMAT_BINARY, stick_value_here, \ 1322 GET_STRING_EXT_DATA_ALLOCA (s, FORMAT_BINARY, ptr_out, len_out)
1389 stick_len_here) 1323 #define GET_C_STRING_BINARY_DATA_ALLOCA(s, ptr_out) \
1390 #define GET_C_STRING_BINARY_DATA_ALLOCA(s, stick_value_here) \ 1324 GET_C_STRING_EXT_DATA_ALLOCA (s, FORMAT_BINARY, ptr_out)
1391 GET_C_STRING_EXT_DATA_ALLOCA (s, FORMAT_BINARY, stick_value_here) 1325
1392 1326 #define GET_STRING_FILENAME_DATA_ALLOCA(s, ptr_out, len_out) \
1393 #define GET_STRING_FILENAME_DATA_ALLOCA(s, stick_value_here, stick_len_here) \ 1327 GET_STRING_EXT_DATA_ALLOCA (s, FORMAT_FILENAME, ptr_out, len_out)
1394 GET_STRING_EXT_DATA_ALLOCA (s, FORMAT_FILENAME, stick_value_here, \ 1328 #define GET_C_STRING_FILENAME_DATA_ALLOCA(s, ptr_out) \
1395 stick_len_here) 1329 GET_C_STRING_EXT_DATA_ALLOCA (s, FORMAT_FILENAME, ptr_out)
1396 #define GET_C_STRING_FILENAME_DATA_ALLOCA(s, stick_value_here) \ 1330
1397 GET_C_STRING_EXT_DATA_ALLOCA (s, FORMAT_FILENAME, stick_value_here) 1331 #define GET_STRING_OS_DATA_ALLOCA(s, ptr_out, len_out) \
1398 1332 GET_STRING_EXT_DATA_ALLOCA (s, FORMAT_OS, ptr_out, len_out)
1399 #define GET_STRING_OS_DATA_ALLOCA(s, stick_value_here, stick_len_here) \ 1333 #define GET_C_STRING_OS_DATA_ALLOCA(s, ptr_out) \
1400 GET_STRING_EXT_DATA_ALLOCA (s, FORMAT_OS, stick_value_here, \ 1334 GET_C_STRING_EXT_DATA_ALLOCA (s, FORMAT_OS, ptr_out)
1401 stick_len_here) 1335
1402 #define GET_C_STRING_OS_DATA_ALLOCA(s, stick_value_here) \ 1336 #define GET_STRING_CTEXT_DATA_ALLOCA(s, ptr_out, len_out) \
1403 GET_C_STRING_EXT_DATA_ALLOCA (s, FORMAT_OS, stick_value_here) 1337 GET_STRING_EXT_DATA_ALLOCA (s, FORMAT_CTEXT, ptr_out, len_out)
1404 1338 #define GET_C_STRING_CTEXT_DATA_ALLOCA(s, ptr_out) \
1405 #define GET_STRING_CTEXT_DATA_ALLOCA(s, stick_value_here, stick_len_here) \ 1339 GET_C_STRING_EXT_DATA_ALLOCA (s, FORMAT_CTEXT, ptr_out)
1406 GET_STRING_EXT_DATA_ALLOCA (s, FORMAT_CTEXT, stick_value_here, \
1407 stick_len_here)
1408 #define GET_C_STRING_CTEXT_DATA_ALLOCA(s, stick_value_here) \
1409 GET_C_STRING_EXT_DATA_ALLOCA (s, FORMAT_CTEXT, stick_value_here)
1410 1340
1411 1341
1412 1342
1413 /************************************************************************/ 1343 /************************************************************************/
1414 /* */ 1344 /* */
1433 #define XCHARSET_LEADING_BYTE(cs) LEADING_BYTE_ASCII 1363 #define XCHARSET_LEADING_BYTE(cs) LEADING_BYTE_ASCII
1434 #define XCHARSET_GRAPHIC(cs) -1 1364 #define XCHARSET_GRAPHIC(cs) -1
1435 #define XCHARSET_COLUMNS(cs) 1 1365 #define XCHARSET_COLUMNS(cs) 1
1436 #define XCHARSET_DIMENSION(cs) 1 1366 #define XCHARSET_DIMENSION(cs) 1
1437 #define REP_BYTES_BY_FIRST_BYTE(fb) 1 1367 #define REP_BYTES_BY_FIRST_BYTE(fb) 1
1438 #define BREAKUP_CHAR(ch, charset, byte1, byte2)\ 1368 #define BREAKUP_CHAR(ch, charset, byte1, byte2) do { \
1439 do \ 1369 (charset) = Vcharset_ascii; \
1440 { \ 1370 (byte1) = (ch); \
1441 (charset) = Vcharset_ascii; \ 1371 (byte2) = 0; \
1442 (byte1) = (ch); \
1443 (byte2) = 0; \
1444 } while (0) 1372 } while (0)
1445 #define BYTE_ASCII_P(byte) 1 1373 #define BYTE_ASCII_P(byte) 1
1446 1374
1447 #endif /* ! MULE */ 1375 #endif /* ! MULE */
1448 1376
1589 #define BUF_FLOOR_OF_IGNORE_ACCESSIBLE(b, n) \ 1517 #define BUF_FLOOR_OF_IGNORE_ACCESSIBLE(b, n) \
1590 bytind_to_bufpos \ 1518 bytind_to_bufpos \
1591 (b, BI_BUF_FLOOR_OF_IGNORE_ACCESSIBLE (b, bufpos_to_bytind (b, n))) 1519 (b, BI_BUF_FLOOR_OF_IGNORE_ACCESSIBLE (b, bufpos_to_bytind (b, n)))
1592 1520
1593 1521
1594
1595
1596 extern struct buffer *current_buffer; 1522 extern struct buffer *current_buffer;
1597 1523
1598 /* This structure holds the default values of the buffer-local variables 1524 EXFUN (Fbuffer_disable_undo, 1);
1599 defined with DEFVAR_BUFFER_LOCAL, that have special slots in each buffer. 1525 EXFUN (Fbuffer_modified_p, 1);
1600 The default value occupies the same slot in this structure 1526 EXFUN (Fbuffer_name, 1);
1601 as an individual buffer's value occupies in that buffer. 1527 EXFUN (Fcurrent_buffer, 0);
1602 Setting the default value also goes through the alist of buffers 1528 EXFUN (Ferase_buffer, 1);
1603 and stores into each buffer that does not say it has a local value. */ 1529 EXFUN (Fget_buffer, 1);
1604 1530 EXFUN (Fget_buffer_create, 1);
1605 extern Lisp_Object Vbuffer_defaults; 1531 EXFUN (Fget_file_buffer, 1);
1532 EXFUN (Fkill_buffer, 1);
1533 EXFUN (Fother_buffer, 3);
1534 EXFUN (Frecord_buffer, 1);
1535 EXFUN (Fset_buffer, 1);
1536 EXFUN (Fset_buffer_modified_p, 2);
1537
1538 extern Lisp_Object QSscratch, Qafter_change_function, Qafter_change_functions;
1539 extern Lisp_Object Qbefore_change_function, Qbefore_change_functions;
1540 extern Lisp_Object Qbuffer_or_string_p, Qdefault_directory, Qfirst_change_hook;
1541 extern Lisp_Object Qpermanent_local, Vafter_change_function;
1542 extern Lisp_Object Vafter_change_functions, Vbefore_change_function;
1543 extern Lisp_Object Vbefore_change_functions, Vbuffer_alist, Vbuffer_defaults;
1544 extern Lisp_Object Vinhibit_read_only, Vtransient_mark_mode;
1606 1545
1607 /* This structure marks which slots in a buffer have corresponding 1546 /* This structure marks which slots in a buffer have corresponding
1608 default values in buffer_defaults. 1547 default values in Vbuffer_defaults.
1609 Each such slot has a nonzero value in this structure. 1548 Each such slot has a nonzero value in this structure.
1610 The value has only one nonzero bit. 1549 The value has only one nonzero bit.
1611 1550
1612 When a buffer has its own local value for a slot, 1551 When a buffer has its own local value for a slot,
1613 the bit for that slot (found in the same slot in this structure) 1552 the bit for that slot (found in the same slot in this structure)
1614 is turned on in the buffer's local_var_flags slot. 1553 is turned on in the buffer's local_var_flags slot.
1615 1554
1616 If a slot in this structure is zero, then even though there may 1555 If a slot in this structure is zero, then even though there may
1617 be a DEFVAR_BUFFER_LOCAL for the slot, there is no default value for it; 1556 be a DEFVAR_BUFFER_LOCAL for the slot, there is no default value for it;
1618 and the corresponding slot in buffer_defaults is not used. */ 1557 and the corresponding slot in Vbuffer_defaults is not used. */
1619 1558
1620 extern struct buffer buffer_local_flags; 1559 extern struct buffer buffer_local_flags;
1621 1560
1622 1561
1623 /* Allocation of buffer data. */ 1562 /* Allocation of buffer data. */
1673 Emchar *arr); 1612 Emchar *arr);
1674 void convert_emchar_string_into_bufbyte_dynarr (Emchar *arr, int nels, 1613 void convert_emchar_string_into_bufbyte_dynarr (Emchar *arr, int nels,
1675 Bufbyte_dynarr *dyn); 1614 Bufbyte_dynarr *dyn);
1676 Bufbyte *convert_emchar_string_into_malloced_string (Emchar *arr, int nels, 1615 Bufbyte *convert_emchar_string_into_malloced_string (Emchar *arr, int nels,
1677 Bytecount *len_out); 1616 Bytecount *len_out);
1617 /* from marker.c */
1618 void init_buffer_markers (struct buffer *b);
1619 void uninit_buffer_markers (struct buffer *b);
1678 1620
1679 /* flags for get_buffer_pos_char(), get_buffer_range_char(), etc. */ 1621 /* flags for get_buffer_pos_char(), get_buffer_range_char(), etc. */
1680 /* At most one of GB_COERCE_RANGE and GB_NO_ERROR_IF_BAD should be 1622 /* At most one of GB_COERCE_RANGE and GB_NO_ERROR_IF_BAD should be
1681 specified. At most one of GB_NEGATIVE_FROM_END and GB_NO_ERROR_IF_BAD 1623 specified. At most one of GB_NEGATIVE_FROM_END and GB_NO_ERROR_IF_BAD
1682 should be specified. */ 1624 should be specified. */
1767 ((Emchar) (MIRROR_TRT_TABLE_AS_STRING (table)[ch])) 1709 ((Emchar) (MIRROR_TRT_TABLE_AS_STRING (table)[ch]))
1768 # define SET_MIRROR_TRT_TABLE_CHAR_1(table, ch1, ch2) \ 1710 # define SET_MIRROR_TRT_TABLE_CHAR_1(table, ch1, ch2) \
1769 (MIRROR_TRT_TABLE_AS_STRING (table)[ch1] = (Bufbyte) (ch2)) 1711 (MIRROR_TRT_TABLE_AS_STRING (table)[ch1] = (Bufbyte) (ch2))
1770 #endif 1712 #endif
1771 1713
1772 # define IN_TRT_TABLE_DOMAIN(c) (((unsigned EMACS_INT) (c)) <= 255) 1714 # define IN_TRT_TABLE_DOMAIN(c) (((EMACS_UINT) (c)) <= 255)
1773 1715
1774 #ifdef MULE 1716 #ifdef MULE
1775 #define MIRROR_DOWNCASE_TABLE_AS_STRING(buf) \ 1717 #define MIRROR_DOWNCASE_TABLE_AS_STRING(buf) \
1776 MIRROR_TRT_TABLE_AS_STRING (buf->mirror_downcase_table) 1718 MIRROR_TRT_TABLE_AS_STRING (buf->mirror_downcase_table)
1777 #define MIRROR_UPCASE_TABLE_AS_STRING(buf) \ 1719 #define MIRROR_UPCASE_TABLE_AS_STRING(buf) \