Mercurial > hg > xemacs-beta
comparison src/buffer.h @ 380:8626e4521993 r21-2-5
Import from CVS: tag r21-2-5
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:07:10 +0200 |
parents | 6240c7796c7a |
children | 4af0ddfb7c5b |
comparison
equal
deleted
inserted
replaced
379:76b7d63099ad | 380:8626e4521993 |
---|---|
235 CONCHECK_BUFFER (x); \ | 235 CONCHECK_BUFFER (x); \ |
236 if (!BUFFER_LIVE_P (XBUFFER (x))) \ | 236 if (!BUFFER_LIVE_P (XBUFFER (x))) \ |
237 x = wrong_type_argument (Qbuffer_live_p, (x)); \ | 237 x = wrong_type_argument (Qbuffer_live_p, (x)); \ |
238 } while (0) | 238 } while (0) |
239 | 239 |
240 | |
240 #define BUFFER_BASE_BUFFER(b) ((b)->base_buffer ? (b)->base_buffer : (b)) | 241 #define BUFFER_BASE_BUFFER(b) ((b)->base_buffer ? (b)->base_buffer : (b)) |
241 | 242 |
242 /* Map over buffers sharing the same text as MPS_BUF. MPS_BUFVAR is a | 243 /* Map over buffers sharing the same text as MPS_BUF. MPS_BUFVAR is a |
243 variable that gets the buffer values (beginning with the base | 244 variable that gets the buffer values (beginning with the base |
244 buffer, then the children), and MPS_BUFCONS should be a temporary | 245 buffer, then the children), and MPS_BUFCONS should be a temporary |
253 && (mps_bufvar = XBUFFER (XCAR (mps_bufcons)), 1) \ | 254 && (mps_bufvar = XBUFFER (XCAR (mps_bufcons)), 1) \ |
254 && (mps_bufcons = XCDR (mps_bufcons), 1)); \ | 255 && (mps_bufcons = XCDR (mps_bufcons), 1)); \ |
255 ) | 256 ) |
256 | 257 |
257 | 258 |
259 | |
260 /************************************************************************/ | |
261 /* */ | |
262 /* working with raw internal-format data */ | |
263 /* */ | |
264 /************************************************************************/ | |
265 | |
258 /* NOTE: In all the following macros, we follow these rules concerning | 266 /* NOTE: In all the following macros, we follow these rules concerning |
259 multiple evaluation of the arguments: | 267 multiple evaluation of the arguments: |
260 | 268 |
261 1) Anything that's an lvalue can be evaluated more than once. | 269 1) Anything that's an lvalue can be evaluated more than once. |
262 2) Anything that's a Lisp Object can be evaluated more than once. | 270 2) Anything that's a Lisp Object can be evaluated more than once. |
268 5) An exception to (4) is that there are some macros below that | 276 5) An exception to (4) is that there are some macros below that |
269 may evaluate their arguments more than once. They are all | 277 may evaluate their arguments more than once. They are all |
270 denoted with the word "unsafe" in their name and are generally | 278 denoted with the word "unsafe" in their name and are generally |
271 meant to be called only by other macros that have already | 279 meant to be called only by other macros that have already |
272 stored the calling values in temporary variables. | 280 stored the calling values in temporary variables. |
273 */ | 281 |
274 | 282 |
275 /************************************************************************/ | 283 Use the following functions/macros on contiguous strings of data. |
276 /* */ | 284 If the text you're operating on is known to come from a buffer, use |
277 /* working with raw internal-format data */ | 285 the buffer-level functions below -- they know about the gap and may |
278 /* */ | 286 be more efficient. |
279 /************************************************************************/ | 287 |
280 | 288 |
281 /* Use these on contiguous strings of data. If the text you're | 289 (A) For working with charptr's (pointers to internally-formatted text): |
282 operating on is known to come from a buffer, use the buffer-level | 290 ----------------------------------------------------------------------- |
283 functions below -- they know about the gap and may be more | 291 |
284 efficient. */ | 292 VALID_CHARPTR_P (ptr): |
285 | |
286 /* Functions are as follows: | |
287 | |
288 | |
289 (A) For working with charptr's (pointers to internally-formatted text): | |
290 ----------------------------------------------------------------------- | |
291 | |
292 VALID_CHARPTR_P(ptr): | |
293 Given a charptr, does it point to the beginning of a character? | 293 Given a charptr, does it point to the beginning of a character? |
294 | 294 |
295 ASSERT_VALID_CHARPTR(ptr): | 295 ASSERT_VALID_CHARPTR (ptr): |
296 If error-checking is enabled, assert that the given charptr | 296 If error-checking is enabled, assert that the given charptr |
297 points to the beginning of a character. Otherwise, do nothing. | 297 points to the beginning of a character. Otherwise, do nothing. |
298 | 298 |
299 INC_CHARPTR(ptr): | 299 INC_CHARPTR (ptr): |
300 Given a charptr (assumed to point at the beginning of a character), | 300 Given a charptr (assumed to point at the beginning of a character), |
301 modify that pointer so it points to the beginning of the next | 301 modify that pointer so it points to the beginning of the next |
302 character. | 302 character. |
303 | 303 |
304 DEC_CHARPTR(ptr): | 304 DEC_CHARPTR (ptr): |
305 Given a charptr (assumed to point at the beginning of a | 305 Given a charptr (assumed to point at the beginning of a |
306 character or at the very end of the text), modify that pointer | 306 character or at the very end of the text), modify that pointer |
307 so it points to the beginning of the previous character. | 307 so it points to the beginning of the previous character. |
308 | 308 |
309 VALIDATE_CHARPTR_BACKWARD(ptr): | 309 VALIDATE_CHARPTR_BACKWARD (ptr): |
310 Make sure that PTR is pointing to the beginning of a character. | 310 Make sure that PTR is pointing to the beginning of a character. |
311 If not, back up until this is the case. Note that there are not | 311 If not, back up until this is the case. Note that there are not |
312 too many places where it is legitimate to do this sort of thing. | 312 too many places where it is legitimate to do this sort of thing. |
313 It's an error if you're passed an "invalid" char * pointer. | 313 It's an error if you're passed an "invalid" char * pointer. |
314 NOTE: PTR *must* be pointing to a valid part of the string (i.e. | 314 NOTE: PTR *must* be pointing to a valid part of the string (i.e. |
315 not the very end, unless the string is zero-terminated or | 315 not the very end, unless the string is zero-terminated or |
316 something) in order for this function to not cause crashes. | 316 something) in order for this function to not cause crashes. |
317 | 317 |
318 VALIDATE_CHARPTR_FORWARD(ptr): | 318 VALIDATE_CHARPTR_FORWARD (ptr): |
319 Make sure that PTR is pointing to the beginning of a character. | 319 Make sure that PTR is pointing to the beginning of a character. |
320 If not, move forward until this is the case. Note that there | 320 If not, move forward until this is the case. Note that there |
321 are not too many places where it is legitimate to do this sort | 321 are not too many places where it is legitimate to do this sort |
322 of thing. It's an error if you're passed an "invalid" char * | 322 of thing. It's an error if you're passed an "invalid" char * |
323 pointer. | 323 pointer. |
325 | 325 |
326 (B) For working with the length (in bytes and characters) of a | 326 (B) For working with the length (in bytes and characters) of a |
327 section of internally-formatted text: | 327 section of internally-formatted text: |
328 -------------------------------------------------------------- | 328 -------------------------------------------------------------- |
329 | 329 |
330 bytecount_to_charcount(ptr, nbi): | 330 bytecount_to_charcount (ptr, nbi): |
331 Given a pointer to a text string and a length in bytes, | 331 Given a pointer to a text string and a length in bytes, |
332 return the equivalent length in characters. | 332 return the equivalent length in characters. |
333 | 333 |
334 charcount_to_bytecount(ptr, nch): | 334 charcount_to_bytecount (ptr, nch): |
335 Given a pointer to a text string and a length in characters, | 335 Given a pointer to a text string and a length in characters, |
336 return the equivalent length in bytes. | 336 return the equivalent length in bytes. |
337 | 337 |
338 charptr_n_addr(ptr, n): | 338 charptr_n_addr (ptr, n): |
339 Return a pointer to the beginning of the character offset N | 339 Return a pointer to the beginning of the character offset N |
340 (in characters) from PTR. | 340 (in characters) from PTR. |
341 | 341 |
342 charptr_length(ptr): | |
343 Given a zero-terminated pointer to Emacs characters, | |
344 return the number of Emacs characters contained within. | |
345 | |
346 | 342 |
347 (C) For retrieving or changing the character pointed to by a charptr: | 343 (C) For retrieving or changing the character pointed to by a charptr: |
348 --------------------------------------------------------------------- | 344 --------------------------------------------------------------------- |
349 | 345 |
350 charptr_emchar(ptr): | 346 charptr_emchar (ptr): |
351 Retrieve the character pointed to by PTR as an Emchar. | 347 Retrieve the character pointed to by PTR as an Emchar. |
352 | 348 |
353 charptr_emchar_n(ptr, n): | 349 charptr_emchar_n (ptr, n): |
354 Retrieve the character at offset N (in characters) from PTR, | 350 Retrieve the character at offset N (in characters) from PTR, |
355 as an Emchar. | 351 as an Emchar. |
356 | 352 |
357 set_charptr_emchar(ptr, ch): | 353 set_charptr_emchar (ptr, ch): |
358 Store the character CH (an Emchar) as internally-formatted | 354 Store the character CH (an Emchar) as internally-formatted |
359 text starting at PTR. Return the number of bytes stored. | 355 text starting at PTR. Return the number of bytes stored. |
360 | 356 |
361 charptr_copy_char(ptr, ptr2): | 357 charptr_copy_char (ptr, ptr2): |
362 Retrieve the character pointed to by PTR and store it as | 358 Retrieve the character pointed to by PTR and store it as |
363 internally-formatted text in PTR2. | 359 internally-formatted text in PTR2. |
364 | 360 |
365 | 361 |
366 (D) For working with Emchars: | 362 (D) For working with Emchars: |
368 | 364 |
369 [Note that there are other functions/macros for working with Emchars | 365 [Note that there are other functions/macros for working with Emchars |
370 in mule-charset.h, for retrieving the charset of an Emchar | 366 in mule-charset.h, for retrieving the charset of an Emchar |
371 and such. These are only valid when MULE is defined.] | 367 and such. These are only valid when MULE is defined.] |
372 | 368 |
373 valid_char_p(ch): | 369 valid_char_p (ch): |
374 Return whether the given Emchar is valid. | 370 Return whether the given Emchar is valid. |
375 | 371 |
376 CHARP(ch): | 372 CHARP (ch): |
377 Return whether the given Lisp_Object is a valid character. | 373 Return whether the given Lisp_Object is a character. |
378 This is approximately the same as saying the Lisp_Object is | 374 |
379 an int whose value is a valid Emchar. (But not exactly | 375 CHECK_CHAR_COERCE_INT (ch): |
380 because when MULE is not defined, we allow arbitrary values | 376 Signal an error if CH is not a valid character or integer Lisp_Object. |
381 in all but the lowest 8 bits and mask them off, for backward | 377 If CH is an integer Lisp_Object, convert it to a character Lisp_Object, |
382 compatibility.) | 378 but merely by repackaging, without performing tests for char validity. |
383 | |
384 CHECK_CHAR_COERCE_INT(ch): | |
385 Signal an error if CH is not a valid character as per CHARP(). | |
386 Also canonicalize the value into a valid Emchar, as necessary. | |
387 (This only means anything when MULE is not defined.) | |
388 | |
389 COERCE_CHAR(ch): | |
390 Coerce an object that is known to satisfy CHARP() into a | |
391 valid Emchar. | |
392 | 379 |
393 MAX_EMCHAR_LEN: | 380 MAX_EMCHAR_LEN: |
394 Maximum number of buffer bytes per Emacs character. | 381 Maximum number of buffer bytes per Emacs character. |
395 | 382 |
396 */ | 383 */ |
417 trick of looking for a valid first byte because it might run off | 404 trick of looking for a valid first byte because it might run off |
418 the end of the string. DEC_CHARPTR() can't use the INC_CHARPTR() | 405 the end of the string. DEC_CHARPTR() can't use the INC_CHARPTR() |
419 method because it doesn't have easy access to the first byte of | 406 method because it doesn't have easy access to the first byte of |
420 the character it's moving over. */ | 407 the character it's moving over. */ |
421 | 408 |
422 #define real_inc_charptr_fun(ptr) \ | 409 #define REAL_INC_CHARPTR(ptr) \ |
423 ((ptr) += REP_BYTES_BY_FIRST_BYTE (* (unsigned char *) (ptr))) | 410 ((void) ((ptr) += REP_BYTES_BY_FIRST_BYTE (* (unsigned char *) (ptr)))) |
411 | |
412 #define REAL_DEC_CHARPTR(ptr) do { \ | |
413 (ptr)--; \ | |
414 } while (!VALID_CHARPTR_P (ptr)) | |
415 | |
424 #ifdef ERROR_CHECK_BUFPOS | 416 #ifdef ERROR_CHECK_BUFPOS |
425 #define inc_charptr_fun(ptr) (ASSERT_VALID_CHARPTR (ptr), \ | |
426 real_inc_charptr_fun (ptr)) | |
427 #else | |
428 #define inc_charptr_fun(ptr) real_inc_charptr_fun (ptr) | |
429 #endif | |
430 | |
431 #define REAL_INC_CHARPTR(ptr) ((void) (real_inc_charptr_fun (ptr))) | |
432 | |
433 #define INC_CHARPTR(ptr) do { \ | 417 #define INC_CHARPTR(ptr) do { \ |
434 ASSERT_VALID_CHARPTR (ptr); \ | 418 ASSERT_VALID_CHARPTR (ptr); \ |
435 REAL_INC_CHARPTR (ptr); \ | 419 REAL_INC_CHARPTR (ptr); \ |
436 } while (0) | 420 } while (0) |
437 | 421 |
438 #define REAL_DEC_CHARPTR(ptr) do { \ | 422 #define DEC_CHARPTR(ptr) do { \ |
439 (ptr)--; \ | 423 CONST Bufbyte *dc_ptr1 = (ptr); \ |
440 } while (!VALID_CHARPTR_P (ptr)) | 424 CONST Bufbyte *dc_ptr2 = dc_ptr1; \ |
441 | 425 REAL_DEC_CHARPTR (dc_ptr2); \ |
442 #ifdef ERROR_CHECK_BUFPOS | 426 assert (dc_ptr1 - dc_ptr2 == \ |
443 #define DEC_CHARPTR(ptr) do { \ | 427 REP_BYTES_BY_FIRST_BYTE (*dc_ptr2)); \ |
444 CONST Bufbyte *__dcptr__ = (ptr); \ | 428 (ptr) = dc_ptr2; \ |
445 CONST Bufbyte *__dcptr2__ = __dcptr__; \ | 429 } while (0) |
446 REAL_DEC_CHARPTR (__dcptr2__); \ | 430 |
447 assert (__dcptr__ - __dcptr2__ == \ | 431 #else /* ! ERROR_CHECK_BUFPOS */ |
448 REP_BYTES_BY_FIRST_BYTE (*__dcptr2__)); \ | 432 #define INC_CHARPTR(ptr) REAL_INC_CHARPTR (ptr) |
449 (ptr) = __dcptr2__; \ | |
450 } while (0) | |
451 #else | |
452 #define DEC_CHARPTR(ptr) REAL_DEC_CHARPTR (ptr) | 433 #define DEC_CHARPTR(ptr) REAL_DEC_CHARPTR (ptr) |
453 #endif | 434 #endif /* ! ERROR_CHECK_BUFPOS */ |
454 | 435 |
455 #ifdef MULE | 436 #ifdef MULE |
456 | 437 |
457 #define VALIDATE_CHARPTR_BACKWARD(ptr) do { \ | 438 #define VALIDATE_CHARPTR_BACKWARD(ptr) do { \ |
458 while (!VALID_CHARPTR_P (ptr)) ptr--; \ | 439 while (!VALID_CHARPTR_P (ptr)) ptr--; \ |
460 | 441 |
461 /* This needs to be trickier to avoid the possibility of running off | 442 /* This needs to be trickier to avoid the possibility of running off |
462 the end of the string. */ | 443 the end of the string. */ |
463 | 444 |
464 #define VALIDATE_CHARPTR_FORWARD(ptr) do { \ | 445 #define VALIDATE_CHARPTR_FORWARD(ptr) do { \ |
465 Bufbyte *__vcfptr__ = (ptr); \ | 446 Bufbyte *vcf_ptr = (ptr); \ |
466 VALIDATE_CHARPTR_BACKWARD (__vcfptr__); \ | 447 VALIDATE_CHARPTR_BACKWARD (vcf_ptr); \ |
467 if (__vcfptr__ != (ptr)) \ | 448 if (vcf_ptr != (ptr)) \ |
468 { \ | 449 { \ |
469 (ptr) = __vcfptr__; \ | 450 (ptr) = vcf_ptr; \ |
470 INC_CHARPTR (ptr); \ | 451 INC_CHARPTR (ptr); \ |
471 } \ | 452 } \ |
472 } while (0) | 453 } while (0) |
473 | 454 |
474 #else /* not MULE */ | 455 #else /* not MULE */ |
486 charptr_n_addr (CONST Bufbyte *ptr, Charcount offset) | 467 charptr_n_addr (CONST Bufbyte *ptr, Charcount offset) |
487 { | 468 { |
488 return ptr + charcount_to_bytecount (ptr, offset); | 469 return ptr + charcount_to_bytecount (ptr, offset); |
489 } | 470 } |
490 | 471 |
491 INLINE Charcount charptr_length (CONST Bufbyte *ptr); | |
492 INLINE Charcount | |
493 charptr_length (CONST Bufbyte *ptr) | |
494 { | |
495 return bytecount_to_charcount (ptr, strlen ((CONST char *) ptr)); | |
496 } | |
497 | |
498 | |
499 /* -------------------------------------------------------------------- */ | 472 /* -------------------------------------------------------------------- */ |
500 /* (C) For retrieving or changing the character pointed to by a charptr */ | 473 /* (C) For retrieving or changing the character pointed to by a charptr */ |
501 /* -------------------------------------------------------------------- */ | 474 /* -------------------------------------------------------------------- */ |
502 | 475 |
503 #define simple_charptr_emchar(ptr) ((Emchar) (ptr)[0]) | 476 #define simple_charptr_emchar(ptr) ((Emchar) (ptr)[0]) |
559 | 532 |
560 INLINE int valid_char_p (Emchar ch); | 533 INLINE int valid_char_p (Emchar ch); |
561 INLINE int | 534 INLINE int |
562 valid_char_p (Emchar ch) | 535 valid_char_p (Emchar ch) |
563 { | 536 { |
564 return (ch >= 0 && ch <= 255) || non_ascii_valid_char_p (ch); | 537 return ((unsigned int) (ch) <= 0xff) || non_ascii_valid_char_p (ch); |
565 } | 538 } |
566 | 539 |
567 #else /* not MULE */ | 540 #else /* not MULE */ |
568 | 541 |
569 #define valid_char_p(ch) ((unsigned int) (ch) <= 255) | 542 #define valid_char_p(ch) ((unsigned int) (ch) <= 0xff) |
570 | 543 |
571 #endif /* not MULE */ | 544 #endif /* not MULE */ |
572 | 545 |
573 #define CHAR_INTP(x) (INTP (x) && valid_char_p (XINT (x))) | 546 #define CHAR_INTP(x) (INTP (x) && valid_char_p (XINT (x))) |
574 | 547 |
867 as well (it should reduce down to nothing), we provide a separate | 840 as well (it should reduce down to nothing), we provide a separate |
868 version to avoid compilation warnings and possible non-optimal | 841 version to avoid compilation warnings and possible non-optimal |
869 results with stupid compilers. */ | 842 results with stupid compilers. */ |
870 | 843 |
871 #ifdef MULE | 844 #ifdef MULE |
872 # define VALIDATE_BYTIND_BACKWARD(buf, x) do \ | 845 # define VALIDATE_BYTIND_BACKWARD(buf, x) do { \ |
873 { \ | 846 Bufbyte *VBB_ptr = BI_BUF_BYTE_ADDRESS (buf, x); \ |
874 Bufbyte *__ibptr = BI_BUF_BYTE_ADDRESS (buf, x); \ | 847 while (!BUFBYTE_FIRST_BYTE_P (*VBB_ptr)) \ |
875 while (!BUFBYTE_FIRST_BYTE_P (*__ibptr)) \ | 848 VBB_ptr--, (x)--; \ |
876 __ibptr--, (x)--; \ | |
877 } while (0) | 849 } while (0) |
878 #else | 850 #else |
879 # define VALIDATE_BYTIND_BACKWARD(buf, x) | 851 # define VALIDATE_BYTIND_BACKWARD(buf, x) |
880 #endif | 852 #endif |
881 | 853 |
883 as well (it should reduce down to nothing), we provide a separate | 855 as well (it should reduce down to nothing), we provide a separate |
884 version to avoid compilation warnings and possible non-optimal | 856 version to avoid compilation warnings and possible non-optimal |
885 results with stupid compilers. */ | 857 results with stupid compilers. */ |
886 | 858 |
887 #ifdef MULE | 859 #ifdef MULE |
888 # define VALIDATE_BYTIND_FORWARD(buf, x) do \ | 860 # define VALIDATE_BYTIND_FORWARD(buf, x) do { \ |
889 { \ | 861 Bufbyte *VBF_ptr = BI_BUF_BYTE_ADDRESS (buf, x); \ |
890 Bufbyte *__ibptr = BI_BUF_BYTE_ADDRESS (buf, x); \ | 862 while (!BUFBYTE_FIRST_BYTE_P (*VBF_ptr)) \ |
891 while (!BUFBYTE_FIRST_BYTE_P (*__ibptr)) \ | 863 VBF_ptr++, (x)++; \ |
892 __ibptr++, (x)++; \ | |
893 } while (0) | 864 } while (0) |
894 #else | 865 #else |
895 # define VALIDATE_BYTIND_FORWARD(buf, x) | 866 # define VALIDATE_BYTIND_FORWARD(buf, x) |
896 #endif | 867 #endif |
897 | 868 |
1160 { \ | 1131 { \ |
1161 Bytecount gceda_len_in = (Bytecount) (len); \ | 1132 Bytecount gceda_len_in = (Bytecount) (len); \ |
1162 Extcount gceda_len_out; \ | 1133 Extcount gceda_len_out; \ |
1163 CONST Bufbyte *gceda_ptr_in = (ptr); \ | 1134 CONST Bufbyte *gceda_ptr_in = (ptr); \ |
1164 Extbyte *gceda_ptr_out = \ | 1135 Extbyte *gceda_ptr_out = \ |
1165 convert_to_external_format (gceda_ptr_in, gceda_len_in, \ | 1136 convert_to_external_format (gceda_ptr_in, gceda_len_in, \ |
1166 &gceda_len_out, fmt); \ | 1137 &gceda_len_out, fmt); \ |
1167 /* If the new string is identical to the old (will be the case most \ | 1138 /* If the new string is identical to the old (will be the case most \ |
1168 of the time), just return the same string back. This saves \ | 1139 of the time), just return the same string back. This saves \ |
1169 on alloca()ing, which can be useful on C alloca() machines and \ | 1140 on alloca()ing, which can be useful on C alloca() machines and \ |
1170 on stack-space-challenged environments. */ \ | 1141 on stack-space-challenged environments. */ \ |
1171 \ | 1142 \ |
1172 if (gceda_len_in == gceda_len_out && \ | 1143 if (gceda_len_in == gceda_len_out && \ |
1173 !memcmp (gceda_ptr_in, gceda_ptr_out, gceda_len_out)) \ | 1144 !memcmp (gceda_ptr_in, gceda_ptr_out, gceda_len_out)) \ |
1174 { \ | 1145 { \ |
1175 (ptr_out) = (Extbyte *) gceda_ptr_in; \ | 1146 (ptr_out) = (Extbyte *) gceda_ptr_in; \ |
1176 (len_out) = (Extcount) gceda_len_in; \ | |
1177 } \ | 1147 } \ |
1178 else \ | 1148 else \ |
1179 { \ | 1149 { \ |
1180 (ptr_out) = (Extbyte *) alloca (1 + gceda_len_out); \ | 1150 (ptr_out) = (Extbyte *) alloca (1 + gceda_len_out); \ |
1181 memcpy ((void *) ptr_out, gceda_ptr_out, 1 + gceda_len_out); \ | 1151 memcpy ((void *) ptr_out, gceda_ptr_out, 1 + gceda_len_out); \ |
1182 (len_out) = (Extcount) gceda_len_out; \ | |
1183 } \ | 1152 } \ |
1153 (len_out) = gceda_len_out; \ | |
1184 } while (0) | 1154 } while (0) |
1185 | 1155 |
1186 #else /* ! MULE */ | 1156 #else /* ! MULE */ |
1187 | 1157 |
1188 #define GET_CHARPTR_EXT_DATA_ALLOCA(ptr, len, fmt, ptr_out, len_out) do \ | 1158 #define GET_CHARPTR_EXT_DATA_ALLOCA(ptr, len, fmt, ptr_out, len_out) do \ |
1238 | 1208 |
1239 #define GET_CHARPTR_INT_DATA_ALLOCA(ptr, len, fmt, ptr_out, len_out) do \ | 1209 #define GET_CHARPTR_INT_DATA_ALLOCA(ptr, len, fmt, ptr_out, len_out) do \ |
1240 { \ | 1210 { \ |
1241 Extcount gcida_len_in = (Extcount) (len); \ | 1211 Extcount gcida_len_in = (Extcount) (len); \ |
1242 Bytecount gcida_len_out; \ | 1212 Bytecount gcida_len_out; \ |
1243 CONST Extbyte *gcida_ptr_in = (ptr); \ | 1213 CONST Extbyte *gcida_ptr_in = (ptr); \ |
1244 Bufbyte *gcida_ptr_out = \ | 1214 Bufbyte *gcida_ptr_out = \ |
1245 convert_from_external_format (gcida_ptr_in, gcida_len_in, \ | 1215 convert_from_external_format (gcida_ptr_in, gcida_len_in, \ |
1246 &gcida_len_out, fmt); \ | 1216 &gcida_len_out, fmt); \ |
1247 /* If the new string is identical to the old (will be the case most \ | 1217 /* If the new string is identical to the old (will be the case most \ |
1248 of the time), just return the same string back. This saves \ | 1218 of the time), just return the same string back. This saves \ |
1249 on alloca()ing, which can be useful on C alloca() machines and \ | 1219 on alloca()ing, which can be useful on C alloca() machines and \ |
1250 on stack-space-challenged environments. */ \ | 1220 on stack-space-challenged environments. */ \ |
1251 \ | 1221 \ |
1252 if (gcida_len_in == gcida_len_out && \ | 1222 if (gcida_len_in == gcida_len_out && \ |
1253 !memcmp (gcida_ptr_in, gcida_ptr_out, gcida_len_out)) \ | 1223 !memcmp (gcida_ptr_in, gcida_ptr_out, gcida_len_out)) \ |
1254 { \ | 1224 { \ |
1255 (ptr_out) = (Bufbyte *) gcida_ptr_in; \ | 1225 (ptr_out) = (Bufbyte *) gcida_ptr_in; \ |
1256 (len_out) = (Bytecount) gcida_len_in; \ | |
1257 } \ | 1226 } \ |
1258 else \ | 1227 else \ |
1259 { \ | 1228 { \ |
1260 (ptr_out) = (Extbyte *) alloca (1 + gcida_len_out); \ | 1229 (ptr_out) = (Extbyte *) alloca (1 + gcida_len_out); \ |
1261 memcpy ((void *) ptr_out, gcida_ptr_out, 1 + gcida_len_out); \ | 1230 memcpy ((void *) ptr_out, gcida_ptr_out, 1 + gcida_len_out); \ |
1262 (len_out) = gcida_len_out; \ | |
1263 } \ | 1231 } \ |
1232 (len_out) = gcida_len_out; \ | |
1264 } while (0) | 1233 } while (0) |
1265 | 1234 |
1266 #else /* ! MULE */ | 1235 #else /* ! MULE */ |
1267 | 1236 |
1268 #define GET_CHARPTR_INT_DATA_ALLOCA(ptr, len, fmt, ptr_out, len_out) do \ | 1237 #define GET_CHARPTR_INT_DATA_ALLOCA(ptr, len, fmt, ptr_out, len_out) do \ |
1602 #define R_ALLOC_DECLARE(var,data) r_alloc_declare (&(var), data) | 1571 #define R_ALLOC_DECLARE(var,data) r_alloc_declare (&(var), data) |
1603 | 1572 |
1604 #else /* !REL_ALLOC */ | 1573 #else /* !REL_ALLOC */ |
1605 | 1574 |
1606 #define BUFFER_ALLOC(data,size)\ | 1575 #define BUFFER_ALLOC(data,size)\ |
1607 ((void) (data = xnew_array (Bufbyte, size))) | 1576 (data = xnew_array (Bufbyte, size)) |
1608 #define BUFFER_REALLOC(data,size)\ | 1577 #define BUFFER_REALLOC(data,size)\ |
1609 ((Bufbyte *) xrealloc (data, (size) * sizeof(Bufbyte))) | 1578 ((Bufbyte *) xrealloc (data, (size) * sizeof(Bufbyte))) |
1610 /* Avoid excess parentheses, or syntax errors may rear their heads. */ | 1579 /* Avoid excess parentheses, or syntax errors may rear their heads. */ |
1611 #define BUFFER_FREE(data) xfree (data) | 1580 #define BUFFER_FREE(data) xfree (data) |
1612 #define R_ALLOC_DECLARE(var,data) | 1581 #define R_ALLOC_DECLARE(var,data) |
1632 int bufbyte_string_displayed_columns (CONST Bufbyte *str, Bytecount len); | 1601 int bufbyte_string_displayed_columns (CONST Bufbyte *str, Bytecount len); |
1633 int emchar_string_displayed_columns (CONST Emchar *str, Charcount len); | 1602 int emchar_string_displayed_columns (CONST Emchar *str, Charcount len); |
1634 void convert_bufbyte_string_into_emchar_dynarr (CONST Bufbyte *str, | 1603 void convert_bufbyte_string_into_emchar_dynarr (CONST Bufbyte *str, |
1635 Bytecount len, | 1604 Bytecount len, |
1636 Emchar_dynarr *dyn); | 1605 Emchar_dynarr *dyn); |
1637 int convert_bufbyte_string_into_emchar_string (CONST Bufbyte *str, | 1606 Charcount convert_bufbyte_string_into_emchar_string (CONST Bufbyte *str, |
1638 Bytecount len, | 1607 Bytecount len, |
1639 Emchar *arr); | 1608 Emchar *arr); |
1640 void convert_emchar_string_into_bufbyte_dynarr (Emchar *arr, int nels, | 1609 void convert_emchar_string_into_bufbyte_dynarr (Emchar *arr, int nels, |
1641 Bufbyte_dynarr *dyn); | 1610 Bufbyte_dynarr *dyn); |
1642 Bufbyte *convert_emchar_string_into_malloced_string (Emchar *arr, int nels, | 1611 Bufbyte *convert_emchar_string_into_malloced_string (Emchar *arr, int nels, |
1643 Bytecount *len_out); | 1612 Bytecount *len_out); |
1644 /* from marker.c */ | 1613 /* from marker.c */ |
1711 | 1680 |
1712 /* A "trt" table is a mapping from characters to other characters, | 1681 /* A "trt" table is a mapping from characters to other characters, |
1713 typically used to convert between uppercase and lowercase. For | 1682 typically used to convert between uppercase and lowercase. For |
1714 compatibility reasons, trt tables are currently in the form of | 1683 compatibility reasons, trt tables are currently in the form of |
1715 a Lisp string of 256 characters, specifying the conversion for each | 1684 a Lisp string of 256 characters, specifying the conversion for each |
1716 of the first 256 Emacs characters (i.e. the 256 extended-ASCII | 1685 of the first 256 Emacs characters (i.e. the 256 Latin-1 characters). |
1717 characters). This should be generalized at some point to support | 1686 This should be generalized at some point to support conversions for |
1718 conversions for all of the allowable Mule characters. | 1687 all of the allowable Mule characters. |
1719 */ | 1688 */ |
1720 | 1689 |
1721 /* The _1 macros are named as such because they assume that you have | 1690 /* The _1 macros are named as such because they assume that you have |
1722 already guaranteed that the character values are all in the range | 1691 already guaranteed that the character values are all in the range |
1723 0 - 255. Bad lossage will happen otherwise. */ | 1692 0 - 255. Bad lossage will happen otherwise. */ |
1806 UPCASE (struct buffer *buf, Emchar ch) | 1775 UPCASE (struct buffer *buf, Emchar ch) |
1807 { | 1776 { |
1808 return (DOWNCASE_TABLE_OF (buf, ch) == ch) ? UPCASE_TABLE_OF (buf, ch) : ch; | 1777 return (DOWNCASE_TABLE_OF (buf, ch) == ch) ? UPCASE_TABLE_OF (buf, ch) : ch; |
1809 } | 1778 } |
1810 | 1779 |
1811 /* Upcase a character known to be not upper case. */ | 1780 /* Upcase a character known to be not upper case. Unused. */ |
1812 | 1781 |
1813 #define UPCASE1(buf, ch) UPCASE_TABLE_OF (buf, ch) | 1782 #define UPCASE1(buf, ch) UPCASE_TABLE_OF (buf, ch) |
1814 | 1783 |
1815 /* Downcase a character, or make no change if that cannot be done. */ | 1784 /* Downcase a character, or make no change if that cannot be done. */ |
1816 | 1785 |