comparison src/buffer.h @ 70:131b0175ea99 r20-0b30

Import from CVS: tag r20-0b30
author cvs
date Mon, 13 Aug 2007 09:02:59 +0200
parents 0293115a14e9
children 6a378aca36af
comparison
equal deleted inserted replaced
69:804d1389bcd6 70:131b0175ea99
30 */ 30 */
31 31
32 #ifndef _XEMACS_BUFFER_H_ 32 #ifndef _XEMACS_BUFFER_H_
33 #define _XEMACS_BUFFER_H_ 33 #define _XEMACS_BUFFER_H_
34 34
35 #ifdef MULE
36 #include "mule-charset.h"
37 #endif
35 38
36 /************************************************************************/ 39 /************************************************************************/
37 /* */ 40 /* */
38 /* definition of Lisp buffer object */ 41 /* definition of Lisp buffer object */
39 /* */ 42 /* */
83 each such event, and never otherwise 86 each such event, and never otherwise
84 changed. */ 87 changed. */
85 int save_modiff; /* Previous value of modiff, as of last 88 int save_modiff; /* Previous value of modiff, as of last
86 time buffer visited or saved a file. */ 89 time buffer visited or saved a file. */
87 90
91 #ifdef MULE
92 /* We keep track of a "known" region for very fast access.
93 This information is text-only so it goes here. */
94 Bufpos mule_bufmin, mule_bufmax;
95 Bytind mule_bytmin, mule_bytmax;
96 int mule_shifter, mule_three_p;
97
98 /* And we also cache 16 positions for fairly fast access near those
99 positions. */
100 Bufpos mule_bufpos_cache[16];
101 Bytind mule_bytind_cache[16];
102 #endif
88 103
89 /* Change data that goes with the text. */ 104 /* Change data that goes with the text. */
90 struct buffer_text_change_data *changes; 105 struct buffer_text_change_data *changes;
91 106
92 }; 107 };
352 367
353 368
354 (D) For working with Emchars: 369 (D) For working with Emchars:
355 ----------------------------- 370 -----------------------------
356 371
372 [Note that there are other functions/macros for working with Emchars
373 in mule-charset.h, for retrieving the charset of an Emchar
374 and such. These are only valid when MULE is defined.]
375
357 valid_char_p(ch): 376 valid_char_p(ch):
358 Return whether the given Emchar is valid. 377 Return whether the given Emchar is valid.
359 378
360 CHARP(ch): 379 CHARP(ch):
361 Return whether the given Lisp_Object is a valid character. 380 Return whether the given Lisp_Object is a valid character.
382 401
383 /* ---------------------------------------------------------------------- */ 402 /* ---------------------------------------------------------------------- */
384 /* (A) For working with charptr's (pointers to internally-formatted text) */ 403 /* (A) For working with charptr's (pointers to internally-formatted text) */
385 /* ---------------------------------------------------------------------- */ 404 /* ---------------------------------------------------------------------- */
386 405
406 #ifdef MULE
407 # define VALID_CHARPTR_P(ptr) BUFBYTE_FIRST_BYTE_P (* (unsigned char *) ptr)
408 #else
387 # define VALID_CHARPTR_P(ptr) 1 409 # define VALID_CHARPTR_P(ptr) 1
410 #endif
388 411
389 #ifdef ERROR_CHECK_BUFPOS 412 #ifdef ERROR_CHECK_BUFPOS
390 # define ASSERT_VALID_CHARPTR(ptr) assert (VALID_CHARPTR_P (ptr)) 413 # define ASSERT_VALID_CHARPTR(ptr) assert (VALID_CHARPTR_P (ptr))
391 #else 414 #else
392 # define ASSERT_VALID_CHARPTR(ptr) 415 # define ASSERT_VALID_CHARPTR(ptr)
436 } while (0) 459 } while (0)
437 #else 460 #else
438 #define DEC_CHARPTR(ptr) REAL_DEC_CHARPTR (ptr) 461 #define DEC_CHARPTR(ptr) REAL_DEC_CHARPTR (ptr)
439 #endif 462 #endif
440 463
464 #ifdef MULE
465
466 #define VALIDATE_CHARPTR_BACKWARD(ptr) do \
467 { \
468 while (!VALID_CHARPTR_P (ptr)) ptr--; \
469 } while (0)
470
471 /* This needs to be trickier to avoid the possibility of running off
472 the end of the string. */
473
474 #define VALIDATE_CHARPTR_FORWARD(ptr) do \
475 { \
476 Bufbyte *__vcfptr__ = (ptr); \
477 VALIDATE_CHARPTR_BACKWARD (__vcfptr__); \
478 if (__vcfptr__ != (ptr)) \
479 { \
480 (ptr) = __vcfptr__; \
481 INC_CHARPTR (ptr); \
482 } \
483 } while (0)
484
485 #else /* not MULE */
441 #define VALIDATE_CHARPTR_BACKWARD(ptr) 486 #define VALIDATE_CHARPTR_BACKWARD(ptr)
442 #define VALIDATE_CHARPTR_FORWARD(ptr) 487 #define VALIDATE_CHARPTR_FORWARD(ptr)
488 #endif /* not MULE */
443 489
444 /* -------------------------------------------------------------- */ 490 /* -------------------------------------------------------------- */
445 /* (B) For working with the length (in bytes and characters) of a */ 491 /* (B) For working with the length (in bytes and characters) of a */
446 /* section of internally-formatted text */ 492 /* section of internally-formatted text */
447 /* -------------------------------------------------------------- */ 493 /* -------------------------------------------------------------- */
467 513
468 #define simple_charptr_emchar(ptr) ((Emchar) (ptr)[0]) 514 #define simple_charptr_emchar(ptr) ((Emchar) (ptr)[0])
469 #define simple_set_charptr_emchar(ptr, x) ((ptr)[0] = (Bufbyte) (x), 1) 515 #define simple_set_charptr_emchar(ptr, x) ((ptr)[0] = (Bufbyte) (x), 1)
470 #define simple_charptr_copy_char(ptr, ptr2) ((ptr2)[0] = *(ptr), 1) 516 #define simple_charptr_copy_char(ptr, ptr2) ((ptr2)[0] = *(ptr), 1)
471 517
518 #ifdef MULE
519
520 Emchar non_ascii_charptr_emchar (CONST Bufbyte *ptr);
521 Bytecount non_ascii_set_charptr_emchar (Bufbyte *ptr, Emchar c);
522 Bytecount non_ascii_charptr_copy_char (CONST Bufbyte *ptr,
523 Bufbyte *ptr2);
524
525 INLINE Emchar charptr_emchar (CONST Bufbyte *ptr);
526 INLINE Emchar
527 charptr_emchar (CONST Bufbyte *ptr)
528 {
529 if (BYTE_ASCII_P (*ptr))
530 return simple_charptr_emchar (ptr);
531 else
532 return non_ascii_charptr_emchar (ptr);
533 }
534
535 INLINE Bytecount set_charptr_emchar (Bufbyte *ptr, Emchar x);
536 INLINE Bytecount
537 set_charptr_emchar (Bufbyte *ptr, Emchar x)
538 {
539 if (!CHAR_MULTIBYTE_P (x))
540 return simple_set_charptr_emchar (ptr, x);
541 else
542 return non_ascii_set_charptr_emchar (ptr, x);
543 }
544
545 INLINE Bytecount charptr_copy_char (CONST Bufbyte *ptr, Bufbyte *ptr2);
546 INLINE Bytecount
547 charptr_copy_char (CONST Bufbyte *ptr, Bufbyte *ptr2)
548 {
549 if (BYTE_ASCII_P (*ptr))
550 return simple_charptr_copy_char (ptr, ptr2);
551 else
552 return non_ascii_charptr_copy_char (ptr, ptr2);
553 }
554
555 #else /* not MULE */
556
472 # define charptr_emchar(ptr) simple_charptr_emchar (ptr) 557 # define charptr_emchar(ptr) simple_charptr_emchar (ptr)
473 # define set_charptr_emchar(ptr, x) simple_set_charptr_emchar (ptr, x) 558 # define set_charptr_emchar(ptr, x) simple_set_charptr_emchar (ptr, x)
474 # define charptr_copy_char(ptr, ptr2) simple_charptr_copy_char (ptr, ptr2) 559 # define charptr_copy_char(ptr, ptr2) simple_charptr_copy_char (ptr, ptr2)
475 560
561 #endif /* not MULE */
562
563
476 #define charptr_emchar_n(ptr, offset) \ 564 #define charptr_emchar_n(ptr, offset) \
477 charptr_emchar (charptr_n_addr (ptr, offset)) 565 charptr_emchar (charptr_n_addr (ptr, offset))
478 566
479 567
480 /* ---------------------------- */ 568 /* ---------------------------- */
481 /* (D) For working with Emchars */ 569 /* (D) For working with Emchars */
482 /* ---------------------------- */ 570 /* ---------------------------- */
483 571
572 #ifdef MULE
573
574 int non_ascii_valid_char_p (Emchar ch);
575
576 INLINE int valid_char_p (Emchar ch);
577 INLINE int
578 valid_char_p (Emchar ch)
579 {
580 if (ch >= 0 && ch < 0400)
581 return 1;
582 else
583 return non_ascii_valid_char_p (ch);
584 }
585
586 #else /* not MULE */
587
484 #define valid_char_p(ch) ((unsigned int) (ch) < 0400) 588 #define valid_char_p(ch) ((unsigned int) (ch) < 0400)
589
590 #endif /* not MULE */
485 591
486 #define CHAR_INTP(x) (INTP (x) && valid_char_p (XINT (x))) 592 #define CHAR_INTP(x) (INTP (x) && valid_char_p (XINT (x)))
487 593
488 #define CHAR_OR_CHAR_INTP(x) (CHARP (x) || CHAR_INTP (x)) 594 #define CHAR_OR_CHAR_INTP(x) (CHARP (x) || CHAR_INTP (x))
489 595
509 else if (CHAR_INTP (x)) \ 615 else if (CHAR_INTP (x)) \
510 x = make_char (XINT (x)); \ 616 x = make_char (XINT (x)); \
511 else \ 617 else \
512 x = wrong_type_argument (Qcharacterp, x); } while (0) 618 x = wrong_type_argument (Qcharacterp, x); } while (0)
513 619
620 #ifdef MULE
621 # define MAX_EMCHAR_LEN 4
622 #else
514 # define MAX_EMCHAR_LEN 1 623 # define MAX_EMCHAR_LEN 1
624 #endif
515 625
516 626
517 /*----------------------------------------------------------------------*/ 627 /*----------------------------------------------------------------------*/
518 /* Accessor macros for important positions in a buffer */ 628 /* Accessor macros for important positions in a buffer */
519 /*----------------------------------------------------------------------*/ 629 /*----------------------------------------------------------------------*/
760 870
761 /*----------------------------------------------------------------------*/ 871 /*----------------------------------------------------------------------*/
762 /* working with byte indices */ 872 /* working with byte indices */
763 /*----------------------------------------------------------------------*/ 873 /*----------------------------------------------------------------------*/
764 874
875 #ifdef MULE
876 # define VALID_BYTIND_P(buf, x) \
877 BUFBYTE_FIRST_BYTE_P (*BI_BUF_BYTE_ADDRESS (buf, x))
878 #else
765 # define VALID_BYTIND_P(buf, x) 1 879 # define VALID_BYTIND_P(buf, x) 1
880 #endif
766 881
767 #ifdef ERROR_CHECK_BUFPOS 882 #ifdef ERROR_CHECK_BUFPOS
768 883
769 # define ASSERT_VALID_BYTIND_UNSAFE(buf, x) do \ 884 # define ASSERT_VALID_BYTIND_UNSAFE(buf, x) do \
770 { \ 885 { \
790 # define ASSERT_VALID_BYTIND_BACKWARD_UNSAFE(buf, x) 905 # define ASSERT_VALID_BYTIND_BACKWARD_UNSAFE(buf, x)
791 # define ASSERT_VALID_BYTIND_FORWARD_UNSAFE(buf, x) 906 # define ASSERT_VALID_BYTIND_FORWARD_UNSAFE(buf, x)
792 907
793 #endif /* not ERROR_CHECK_BUFPOS */ 908 #endif /* not ERROR_CHECK_BUFPOS */
794 909
910 /* Note that, although the Mule version will work fine for non-Mule
911 as well (it should reduce down to nothing), we provide a separate
912 version to avoid compilation warnings and possible non-optimal
913 results with stupid compilers. */
914
915 #ifdef MULE
916 # define VALIDATE_BYTIND_BACKWARD(buf, x) do \
917 { \
918 Bufbyte *__ibptr = BI_BUF_BYTE_ADDRESS (buf, x); \
919 while (!BUFBYTE_FIRST_BYTE_P (*__ibptr)) \
920 __ibptr--, (x)--; \
921 } while (0)
922 #else
795 # define VALIDATE_BYTIND_BACKWARD(buf, x) 923 # define VALIDATE_BYTIND_BACKWARD(buf, x)
796 924 #endif
925
926 /* Note that, although the Mule version will work fine for non-Mule
927 as well (it should reduce down to nothing), we provide a separate
928 version to avoid compilation warnings and possible non-optimal
929 results with stupid compilers. */
930
931 #ifdef MULE
932 # define VALIDATE_BYTIND_FORWARD(buf, x) do \
933 { \
934 Bufbyte *__ibptr = BI_BUF_BYTE_ADDRESS (buf, x); \
935 while (!BUFBYTE_FIRST_BYTE_P (*__ibptr)) \
936 __ibptr++, (x)++; \
937 } while (0)
938 #else
797 # define VALIDATE_BYTIND_FORWARD(buf, x) 939 # define VALIDATE_BYTIND_FORWARD(buf, x)
940 #endif
798 941
799 /* Note that in the simplest case (no MULE, no ERROR_CHECK_BUFPOS), 942 /* Note that in the simplest case (no MULE, no ERROR_CHECK_BUFPOS),
800 this crap reduces down to simply (x)++. */ 943 this crap reduces down to simply (x)++. */
801 944
802 #define INC_BYTIND(buf, x) do \ 945 #define INC_BYTIND(buf, x) do \
844 987
845 /*----------------------------------------------------------------------*/ 988 /*----------------------------------------------------------------------*/
846 /* Converting between buffer positions and byte indices */ 989 /* Converting between buffer positions and byte indices */
847 /*----------------------------------------------------------------------*/ 990 /*----------------------------------------------------------------------*/
848 991
992 #ifdef MULE
993
994 Bytind bufpos_to_bytind_func (struct buffer *buf, Bufpos x);
995 Bufpos bytind_to_bufpos_func (struct buffer *buf, Bytind x);
996
997 /* The basic algorithm we use is to keep track of a known region of
998 characters in each buffer, all of which are of the same width. We
999 keep track of the boundaries of the region in both Bufpos and
1000 Bytind coordinates and also keep track of the char width, which
1001 is 1 - 4 bytes. If the position we're translating is not in
1002 the known region, then we invoke a function to update the known
1003 region to surround the position in question. This assumes
1004 locality of reference, which is usually the case.
1005
1006 Note that the function to update the known region can be simple
1007 or complicated depending on how much information we cache.
1008 For the moment, we don't cache any information, and just move
1009 linearly forward or back from the known region, with a few
1010 shortcuts to catch all-ASCII buffers. (Note that this will
1011 thrash with bad locality of reference.) A smarter method would
1012 be to keep some sort of pseudo-extent layer over the buffer;
1013 maybe keep track of the bufpos/bytind correspondence at the
1014 beginning of each line, which would allow us to do a binary
1015 search over the pseudo-extents to narrow things down to the
1016 correct line, at which point you could use a linear movement
1017 method. This would also mesh well with efficiently
1018 implementing a line-numbering scheme.
1019
1020 Note also that we have to multiply or divide by the char width
1021 in order to convert the positions. We do some tricks to avoid
1022 ever actually having to do a multiply or divide, because that
1023 is typically an expensive operation (esp. divide). Multiplying
1024 or dividing by 1, 2, or 4 can be implemented simply as a
1025 shift left or shift right, and we keep track of a shifter value
1026 (0, 1, or 2) indicating how much to shift. Multiplying by 3
1027 can be implemented by doubling and then adding the original
1028 value. Dividing by 3, alas, cannot be implemented in any
1029 simple shift/subtract method, as far as I know; so we just
1030 do a table lookup. For simplicity, we use a table of size
1031 128K, which indexes the "divide-by-3" values for the first
1032 64K non-negative numbers. (Note that we can increase the
1033 size up to 384K, i.e. indexing the first 192K non-negative
1034 numbers, while still using shorts in the array.) This also
1035 means that the size of the known region can be at most
1036 64K for width-three characters.
1037 */
1038
1039 extern short three_to_one_table[];
1040
1041 INLINE int real_bufpos_to_bytind (struct buffer *buf, Bufpos x);
1042 INLINE int
1043 real_bufpos_to_bytind (struct buffer *buf, Bufpos x)
1044 {
1045 if (x >= buf->text->mule_bufmin && x <= buf->text->mule_bufmax)
1046 return (buf->text->mule_bytmin +
1047 ((x - buf->text->mule_bufmin) << buf->text->mule_shifter) +
1048 (buf->text->mule_three_p ? (x - buf->text->mule_bufmin) : 0));
1049 else
1050 return bufpos_to_bytind_func (buf, x);
1051 }
1052
1053 INLINE int real_bytind_to_bufpos (struct buffer *buf, Bytind x);
1054 INLINE int
1055 real_bytind_to_bufpos (struct buffer *buf, Bytind x)
1056 {
1057 if (x >= buf->text->mule_bytmin && x <= buf->text->mule_bytmax)
1058 return (buf->text->mule_bufmin +
1059 ((buf->text->mule_three_p
1060 ? three_to_one_table[x - buf->text->mule_bytmin]
1061 : (x - buf->text->mule_bytmin) >> buf->text->mule_shifter)));
1062 else
1063 return bytind_to_bufpos_func (buf, x);
1064 }
1065
1066 #else /* not MULE */
1067
849 # define real_bufpos_to_bytind(buf, x) ((Bytind) x) 1068 # define real_bufpos_to_bytind(buf, x) ((Bytind) x)
850 # define real_bytind_to_bufpos(buf, x) ((Bufpos) x) 1069 # define real_bytind_to_bufpos(buf, x) ((Bufpos) x)
1070
1071 #endif /* not MULE */
851 1072
852 #ifdef ERROR_CHECK_BUFPOS 1073 #ifdef ERROR_CHECK_BUFPOS
853 1074
854 Bytind bufpos_to_bytind (struct buffer *buf, Bufpos x); 1075 Bytind bufpos_to_bytind (struct buffer *buf, Bufpos x);
855 Bufpos bytind_to_bufpos (struct buffer *buf, Bytind x); 1076 Bufpos bytind_to_bufpos (struct buffer *buf, Bytind x);
899 of some functions, but not others.) At times this conversion 1120 of some functions, but not others.) At times this conversion
900 also has to go the other way -- i.e. when we get external- 1121 also has to go the other way -- i.e. when we get external-
901 format strings back from a library function. 1122 format strings back from a library function.
902 */ 1123 */
903 1124
1125 #ifdef MULE
1126
1127 /* WARNING: These use a static buffer. This can lead to disaster if
1128 these functions are not used *very* carefully. Under normal
1129 circumstances, do not call these functions; call the front ends
1130 below. */
1131
1132 CONST Extbyte *convert_to_external_format (CONST Bufbyte *ptr,
1133 Bytecount len,
1134 Extcount *len_out,
1135 enum external_data_format fmt);
1136 CONST Bufbyte *convert_from_external_format (CONST Extbyte *ptr,
1137 Extcount len,
1138 Bytecount *len_out,
1139 enum external_data_format fmt);
1140
1141 #else /* ! MULE */
1142
904 #define convert_to_external_format(ptr, len, len_out, fmt) \ 1143 #define convert_to_external_format(ptr, len, len_out, fmt) \
905 (*(len_out) = (int) (len), (CONST Extbyte *) (ptr)) 1144 (*(len_out) = (int) (len), (CONST Extbyte *) (ptr))
906 #define convert_from_external_format(ptr, len, len_out, fmt) \ 1145 #define convert_from_external_format(ptr, len, len_out, fmt) \
907 (*(len_out) = (Bytecount) (len), (CONST Bufbyte *) (ptr)) 1146 (*(len_out) = (Bytecount) (len), (CONST Bufbyte *) (ptr))
908 1147
1148 #endif /* ! MULE */
909 1149
910 /* In all of the following macros we use the following general principles: 1150 /* In all of the following macros we use the following general principles:
911 1151
912 -- Functions that work with charptr's accept two sorts of charptr's: 1152 -- Functions that work with charptr's accept two sorts of charptr's:
913 1153
956 architecture. (If you put a call to alloca() in the argument to 1196 architecture. (If you put a call to alloca() in the argument to
957 a function call, the stack space gets allocated right in the 1197 a function call, the stack space gets allocated right in the
958 middle of the arguments to the function call and you are unbelievably 1198 middle of the arguments to the function call and you are unbelievably
959 hosed.) */ 1199 hosed.) */
960 1200
1201 #ifdef MULE
1202
1203 #define GET_CHARPTR_EXT_DATA_ALLOCA(ptr, len, fmt, stick_value_here, stick_len_here) \
1204 do \
1205 { \
1206 Bytecount __gceda_len_in__ = (len); \
1207 Extcount __gceda_len_out__; \
1208 CONST Bufbyte *__gceda_ptr_in__ = (ptr); \
1209 CONST Extbyte *__gceda_ptr_out__; \
1210 \
1211 __gceda_ptr_out__ = \
1212 convert_to_external_format (__gceda_ptr_in__, __gceda_len_in__, \
1213 &__gceda_len_out__, fmt); \
1214 /* If the new string is identical to the old (will be the case most \
1215 of the time), just return the same string back. This saves \
1216 on alloca()ing, which can be useful on C alloca() machines and \
1217 on stack-space-challenged environments. */ \
1218 \
1219 if (__gceda_len_in__ == __gceda_len_out__ && \
1220 !memcmp (__gceda_ptr_in__, __gceda_ptr_out__, __gceda_len_out__)) \
1221 { \
1222 (stick_value_here) = (CONST Extbyte *) __gceda_ptr_in__; \
1223 (stick_len_here) = (Extcount) __gceda_len_in__; \
1224 } \
1225 else \
1226 { \
1227 (stick_value_here) = (CONST Extbyte *) alloca(1 + __gceda_len_out__);\
1228 memcpy ((Extbyte *) stick_value_here, __gceda_ptr_out__, \
1229 1 + __gceda_len_out__); \
1230 (stick_len_here) = (Extcount) __gceda_len_out__; \
1231 } \
1232 } while (0)
1233
1234 #else /* ! MULE */
1235
961 #define GET_CHARPTR_EXT_DATA_ALLOCA(ptr, len, fmt, stick_value_here, stick_len_here)\ 1236 #define GET_CHARPTR_EXT_DATA_ALLOCA(ptr, len, fmt, stick_value_here, stick_len_here)\
962 do \ 1237 do \
963 { \ 1238 { \
964 (stick_value_here) = (CONST Extbyte *) (ptr); \ 1239 (stick_value_here) = (CONST Extbyte *) (ptr); \
965 (stick_len_here) = (Extcount) (len); \ 1240 (stick_len_here) = (Extcount) (len); \
966 } while (0) 1241 } while (0)
1242
1243 #endif /* ! MULE */
967 1244
968 #define GET_C_CHARPTR_EXT_DATA_ALLOCA(ptr, fmt, stick_value_here) \ 1245 #define GET_C_CHARPTR_EXT_DATA_ALLOCA(ptr, fmt, stick_value_here) \
969 do \ 1246 do \
970 { \ 1247 { \
971 Extcount __gcceda_ignored_len__; \ 1248 Extcount __gcceda_ignored_len__; \
1008 architecture. (If you put a call to alloca() in the argument to 1285 architecture. (If you put a call to alloca() in the argument to
1009 a function call, the stack space gets allocated right in the 1286 a function call, the stack space gets allocated right in the
1010 middle of the arguments to the function call and you are unbelievably 1287 middle of the arguments to the function call and you are unbelievably
1011 hosed.) */ 1288 hosed.) */
1012 1289
1290 #ifdef MULE
1291
1013 #define GET_CHARPTR_INT_DATA_ALLOCA(ptr, len, fmt, stick_value_here, stick_len_here)\ 1292 #define GET_CHARPTR_INT_DATA_ALLOCA(ptr, len, fmt, stick_value_here, stick_len_here)\
1014 do \ 1293 do \
1015 { \ 1294 { \
1016 (stick_value_here) = (CONST Bufbyte *) (ptr); \ 1295 Extcount __gcida_len_in__ = (len); \
1017 (stick_len_here) = (Bytecount) (len); \ 1296 Bytecount __gcida_len_out__; \
1018 } while (0) 1297 CONST Extbyte *__gcida_ptr_in__ = (ptr); \
1298 CONST Bufbyte *__gcida_ptr_out__; \
1299 \
1300 __gcida_ptr_out__ = \
1301 convert_from_external_format (__gcida_ptr_in__, __gcida_len_in__, \
1302 &__gcida_len_out__, fmt); \
1303 /* If the new string is identical to the old (will be the case most \
1304 of the time), just return the same string back. This saves \
1305 on alloca()ing, which can be useful on C alloca() machines and \
1306 on stack-space-challenged environments. */ \
1307 \
1308 if (__gcida_len_in__ == __gcida_len_out__ && \
1309 !memcmp (__gcida_ptr_in__, __gcida_ptr_out__, __gcida_len_out__)) \
1310 { \
1311 (stick_value_here) = (CONST Bufbyte *) __gcida_ptr_in__; \
1312 (stick_len_here) = (Bytecount) __gcida_len_in__; \
1313 } \
1314 else \
1315 { \
1316 (stick_value_here) = alloca (1 + __gcida_len_out__); \
1317 memcpy ((Bufbyte *) stick_value_here, __gcida_ptr_out__, \
1318 1 + __gcida_len_out__); \
1319 (stick_len_here) = __gcida_len_out__; \
1320 } \
1321 } while (0)
1322
1323 #else /* ! MULE */
1324
1325 #define GET_CHARPTR_INT_DATA_ALLOCA(ptr, len, fmt, stick_value_here, stick_len_here)\
1326 do \
1327 { \
1328 (stick_value_here) = (CONST Bufbyte *) (ptr); \
1329 (stick_len_here) = (Bytecount) (len); \
1330 } while (0)
1331
1332 #endif /* ! MULE */
1019 1333
1020 #define GET_C_CHARPTR_INT_DATA_ALLOCA(ptr, fmt, stick_value_here) \ 1334 #define GET_C_CHARPTR_INT_DATA_ALLOCA(ptr, fmt, stick_value_here) \
1021 do \ 1335 do \
1022 { \ 1336 { \
1023 Bytecount __gccida_ignored_len__; \ 1337 Bytecount __gccida_ignored_len__; \
1071 struct Lisp_String *__gseda_s__ = XSTRING (s); \ 1385 struct Lisp_String *__gseda_s__ = XSTRING (s); \
1072 \ 1386 \
1073 __gseda_ptr__ = convert_to_external_format (string_data (__gseda_s__), \ 1387 __gseda_ptr__ = convert_to_external_format (string_data (__gseda_s__), \
1074 string_length (__gseda_s__), \ 1388 string_length (__gseda_s__), \
1075 &__gseda_len__, fmt); \ 1389 &__gseda_len__, fmt); \
1076 (stick_value_here) = (CONST Extbyte *) alloca (1 + __gseda_len__); \ 1390 (stick_value_here) = alloca (1 + __gseda_len__); \
1077 memcpy ((Extbyte *) stick_value_here, __gseda_ptr__, 1 + __gseda_len__); \ 1391 memcpy ((Extbyte *) stick_value_here, __gseda_ptr__, 1 + __gseda_len__); \
1078 (stick_len_here) = __gseda_len__; \ 1392 (stick_len_here) = __gseda_len__; \
1079 } while (0) 1393 } while (0)
1080 1394
1081 1395
1119 /************************************************************************/ 1433 /************************************************************************/
1120 /* */ 1434 /* */
1121 /* fake charset functions */ 1435 /* fake charset functions */
1122 /* */ 1436 /* */
1123 /************************************************************************/ 1437 /************************************************************************/
1438
1439 /* used when MULE is not defined, so that Charset-type stuff can still
1440 be done */
1441
1442 #ifndef MULE
1124 1443
1125 #define Vcharset_ascii Qnil 1444 #define Vcharset_ascii Qnil
1126 1445
1127 #define CHAR_CHARSET(ch) Vcharset_ascii 1446 #define CHAR_CHARSET(ch) Vcharset_ascii
1128 #define CHAR_LEADING_BYTE(ch) LEADING_BYTE_ASCII 1447 #define CHAR_LEADING_BYTE(ch) LEADING_BYTE_ASCII
1142 (charset) = Vcharset_ascii; \ 1461 (charset) = Vcharset_ascii; \
1143 (byte1) = (ch); \ 1462 (byte1) = (ch); \
1144 (byte2) = 0; \ 1463 (byte2) = 0; \
1145 } while (0) 1464 } while (0)
1146 #define BYTE_ASCII_P(byte) 1 1465 #define BYTE_ASCII_P(byte) 1
1466
1467 #endif /* ! MULE */
1147 1468
1148 1469
1149 /************************************************************************/ 1470 /************************************************************************/
1150 /* */ 1471 /* */
1151 /* higher-level buffer-position functions */ 1472 /* higher-level buffer-position functions */
1457 # define TRT_TABLE_CHAR_1(table, ch) \ 1778 # define TRT_TABLE_CHAR_1(table, ch) \
1458 string_char (XSTRING (table), (Charcount) ch) 1779 string_char (XSTRING (table), (Charcount) ch)
1459 # define SET_TRT_TABLE_CHAR_1(table, ch1, ch2) \ 1780 # define SET_TRT_TABLE_CHAR_1(table, ch1, ch2) \
1460 set_string_char (XSTRING (table), (Charcount) ch1, ch2) 1781 set_string_char (XSTRING (table), (Charcount) ch1, ch2)
1461 1782
1783 #ifdef MULE
1784 # define MAKE_MIRROR_TRT_TABLE() make_opaque (256, 0)
1785 # define MIRROR_TRT_TABLE_AS_STRING(table) ((Bufbyte *) XOPAQUE_DATA (table))
1786 # define MIRROR_TRT_TABLE_CHAR_1(table, ch) \
1787 ((Emchar) (MIRROR_TRT_TABLE_AS_STRING (table)[ch]))
1788 # define SET_MIRROR_TRT_TABLE_CHAR_1(table, ch1, ch2) \
1789 (MIRROR_TRT_TABLE_AS_STRING (table)[ch1] = (Bufbyte) (ch2))
1790 #endif
1791
1462 # define IN_TRT_TABLE_DOMAIN(c) (((unsigned EMACS_INT) (c)) < 0400) 1792 # define IN_TRT_TABLE_DOMAIN(c) (((unsigned EMACS_INT) (c)) < 0400)
1463 1793
1794 #ifdef MULE
1795 #define MIRROR_DOWNCASE_TABLE_AS_STRING(buf) \
1796 MIRROR_TRT_TABLE_AS_STRING (buf->mirror_downcase_table)
1797 #define MIRROR_UPCASE_TABLE_AS_STRING(buf) \
1798 MIRROR_TRT_TABLE_AS_STRING (buf->mirror_upcase_table)
1799 #define MIRROR_CANON_TABLE_AS_STRING(buf) \
1800 MIRROR_TRT_TABLE_AS_STRING (buf->mirror_case_canon_table)
1801 #define MIRROR_EQV_TABLE_AS_STRING(buf) \
1802 MIRROR_TRT_TABLE_AS_STRING (buf->mirror_case_eqv_table)
1803 #else
1464 #define MIRROR_DOWNCASE_TABLE_AS_STRING(buf) \ 1804 #define MIRROR_DOWNCASE_TABLE_AS_STRING(buf) \
1465 TRT_TABLE_AS_STRING (buf->downcase_table) 1805 TRT_TABLE_AS_STRING (buf->downcase_table)
1466 #define MIRROR_UPCASE_TABLE_AS_STRING(buf) \ 1806 #define MIRROR_UPCASE_TABLE_AS_STRING(buf) \
1467 TRT_TABLE_AS_STRING (buf->upcase_table) 1807 TRT_TABLE_AS_STRING (buf->upcase_table)
1468 #define MIRROR_CANON_TABLE_AS_STRING(buf) \ 1808 #define MIRROR_CANON_TABLE_AS_STRING(buf) \
1469 TRT_TABLE_AS_STRING (buf->case_canon_table) 1809 TRT_TABLE_AS_STRING (buf->case_canon_table)
1470 #define MIRROR_EQV_TABLE_AS_STRING(buf) \ 1810 #define MIRROR_EQV_TABLE_AS_STRING(buf) \
1471 TRT_TABLE_AS_STRING (buf->case_eqv_table) 1811 TRT_TABLE_AS_STRING (buf->case_eqv_table)
1812 #endif
1472 1813
1473 INLINE Emchar TRT_TABLE_OF (Lisp_Object trt, Emchar c); 1814 INLINE Emchar TRT_TABLE_OF (Lisp_Object trt, Emchar c);
1474 INLINE Emchar 1815 INLINE Emchar
1475 TRT_TABLE_OF (Lisp_Object trt, Emchar c) 1816 TRT_TABLE_OF (Lisp_Object trt, Emchar c)
1476 { 1817 {