comparison src/insdel.c @ 272:c5d627a313b1 r21-0b34

Import from CVS: tag r21-0b34
author cvs
date Mon, 13 Aug 2007 10:28:48 +0200
parents 966663fcf606
children ca9a9ec9c1c1
comparison
equal deleted inserted replaced
271:c7b7086b0a39 272:c5d627a313b1
198 Working with the various representations: 198 Working with the various representations:
199 ========================================= */ 199 ========================================= */
200 200
201 #include <config.h> 201 #include <config.h>
202 #include "lisp.h" 202 #include "lisp.h"
203 #include <limits.h>
203 204
204 #include "buffer.h" 205 #include "buffer.h"
205 #include "device.h" 206 #include "device.h"
206 #include "frame.h" 207 #include "frame.h"
207 #include "extents.h" 208 #include "extents.h"
1272 { 1273 {
1273 if (flags & GB_CHECK_ORDER) 1274 if (flags & GB_CHECK_ORDER)
1274 signal_simple_error_2 ("start greater than end", from, to); 1275 signal_simple_error_2 ("start greater than end", from, to);
1275 else 1276 else
1276 { 1277 {
1277 Bufpos temp; 1278 Bufpos temp = *from_out;
1278
1279 temp = *from_out;
1280 *from_out = *to_out; 1279 *from_out = *to_out;
1281 *to_out = temp; 1280 *to_out = temp;
1282 } 1281 }
1283 } 1282 }
1284 } 1283 }
1330 1329
1331 Charcount 1330 Charcount
1332 get_string_pos_char (Lisp_Object string, Lisp_Object pos, unsigned int flags) 1331 get_string_pos_char (Lisp_Object string, Lisp_Object pos, unsigned int flags)
1333 { 1332 {
1334 return get_string_pos_char_1 (string, pos, flags, 1333 return get_string_pos_char_1 (string, pos, flags,
1335 string_char_length (XSTRING (string))); 1334 XSTRING_CHAR_LENGTH (string));
1336 } 1335 }
1337 1336
1338 Bytecount 1337 Bytecount
1339 get_string_pos_byte (Lisp_Object string, Lisp_Object pos, unsigned int flags) 1338 get_string_pos_byte (Lisp_Object string, Lisp_Object pos, unsigned int flags)
1340 { 1339 {
1348 get_string_range_char (Lisp_Object string, Lisp_Object from, Lisp_Object to, 1347 get_string_range_char (Lisp_Object string, Lisp_Object from, Lisp_Object to,
1349 Charcount *from_out, Charcount *to_out, 1348 Charcount *from_out, Charcount *to_out,
1350 unsigned int flags) 1349 unsigned int flags)
1351 { 1350 {
1352 Charcount min_allowed = 0; 1351 Charcount min_allowed = 0;
1353 Charcount max_allowed = string_char_length (XSTRING (string)); 1352 Charcount max_allowed = XSTRING_CHAR_LENGTH (string);
1354 1353
1355 if (NILP (from) && (flags & GB_ALLOW_NIL)) 1354 if (NILP (from) && (flags & GB_ALLOW_NIL))
1356 *from_out = min_allowed; 1355 *from_out = min_allowed;
1357 else 1356 else
1358 *from_out = get_string_pos_char_1 (string, from, 1357 *from_out = get_string_pos_char_1 (string, from,
1373 { 1372 {
1374 if (flags & GB_CHECK_ORDER) 1373 if (flags & GB_CHECK_ORDER)
1375 signal_simple_error_2 ("start greater than end", from, to); 1374 signal_simple_error_2 ("start greater than end", from, to);
1376 else 1375 else
1377 { 1376 {
1378 Bufpos temp; 1377 Bufpos temp = *from_out;
1379
1380 temp = *from_out;
1381 *from_out = *to_out; 1378 *from_out = *to_out;
1382 *to_out = temp; 1379 *to_out = temp;
1383 } 1380 }
1384 } 1381 }
1385 } 1382 }
1451 1448
1452 Bufpos 1449 Bufpos
1453 buffer_or_string_accessible_end_char (Lisp_Object object) 1450 buffer_or_string_accessible_end_char (Lisp_Object object)
1454 { 1451 {
1455 return STRINGP (object) ? 1452 return STRINGP (object) ?
1456 string_char_length (XSTRING (object)) : BUF_ZV (XBUFFER (object)); 1453 XSTRING_CHAR_LENGTH (object) : BUF_ZV (XBUFFER (object));
1457 } 1454 }
1458 1455
1459 Bytind 1456 Bytind
1460 buffer_or_string_accessible_begin_byte (Lisp_Object object) 1457 buffer_or_string_accessible_begin_byte (Lisp_Object object)
1461 { 1458 {
1477 1474
1478 Bufpos 1475 Bufpos
1479 buffer_or_string_absolute_end_char (Lisp_Object object) 1476 buffer_or_string_absolute_end_char (Lisp_Object object)
1480 { 1477 {
1481 return STRINGP (object) ? 1478 return STRINGP (object) ?
1482 string_char_length (XSTRING (object)) : BUF_Z (XBUFFER (object)); 1479 XSTRING_CHAR_LENGTH (object) : BUF_Z (XBUFFER (object));
1483 } 1480 }
1484 1481
1485 Bytind 1482 Bytind
1486 buffer_or_string_absolute_begin_byte (Lisp_Object object) 1483 buffer_or_string_absolute_begin_byte (Lisp_Object object)
1487 { 1484 {
1875 /* Don't allow a buffer size that won't fit in an int 1872 /* Don't allow a buffer size that won't fit in an int
1876 even if it will fit in a Lisp integer. 1873 even if it will fit in a Lisp integer.
1877 That won't work because so many places use `int'. */ 1874 That won't work because so many places use `int'. */
1878 1875
1879 if (BUF_Z (buf) - BUF_BEG (buf) + BUF_GAP_SIZE (buf) + increment 1876 if (BUF_Z (buf) - BUF_BEG (buf) + BUF_GAP_SIZE (buf) + increment
1880 >= ((unsigned) 1 << (min (INTBITS, VALBITS) - 1))) 1877 > (int) EMACS_INT_MAX)
1881 error ("Buffer exceeds maximum size"); 1878 error ("Maximum buffer size exceeded");
1882 1879
1883 result = BUFFER_REALLOC (buf->text->beg, 1880 result = BUFFER_REALLOC (buf->text->beg,
1884 BI_BUF_Z (buf) - BI_BUF_BEG (buf) + 1881 BI_BUF_Z (buf) - BI_BUF_BEG (buf) +
1885 BUF_GAP_SIZE (buf) + increment + 1882 BUF_GAP_SIZE (buf) + increment +
1886 BUF_END_SENTINEL_SIZE); 1883 BUF_END_SENTINEL_SIZE);
2389 as translatable, then Fgettext() should be called on obj if it 2386 as translatable, then Fgettext() should be called on obj if it
2390 is a string. */ 2387 is a string. */
2391 #endif 2388 #endif
2392 2389
2393 /* Make sure that point-max won't exceed the size of an emacs int. */ 2390 /* Make sure that point-max won't exceed the size of an emacs int. */
2394 { 2391 if ((length + BUF_Z (buf)) > (int) EMACS_INT_MAX)
2395 Lisp_Object temp; 2392 error ("Maximum buffer size exceeded");
2396
2397 XSETINT (temp, (int) (length + BUF_Z (buf)));
2398 if ((int) (length + BUF_Z (buf)) != XINT (temp))
2399 error ("maximum buffer size exceeded");
2400 }
2401 2393
2402 /* theoretically not necessary -- caller should GCPRO */ 2394 /* theoretically not necessary -- caller should GCPRO */
2403 GCPRO1 (reloc); 2395 GCPRO1 (reloc);
2404 2396
2405 prepare_to_modify_buffer (buf, pos, pos, !(flags & INSDEL_NO_LOCKING)); 2397 prepare_to_modify_buffer (buf, pos, pos, !(flags & INSDEL_NO_LOCKING));
2579 /* This function can GC */ 2571 /* This function can GC */
2580 Charcount numdel; 2572 Charcount numdel;
2581 Bytind bi_from, bi_to; 2573 Bytind bi_from, bi_to;
2582 Bytecount bc_numdel; 2574 Bytecount bc_numdel;
2583 int shortage; 2575 int shortage;
2584 Lisp_Object bufobj = Qnil; 2576 Lisp_Object bufobj;
2585 2577
2586 /* Defensive steps just in case a buffer gets deleted and a calling 2578 /* Defensive steps just in case a buffer gets deleted and a calling
2587 function doesn't notice it. */ 2579 function doesn't notice it. */
2588 if (!BUFFER_LIVE_P (buf)) 2580 if (!BUFFER_LIVE_P (buf))
2589 return; 2581 return;
2639 BUF_MODIFF (buf)++; 2631 BUF_MODIFF (buf)++;
2640 MARK_BUFFERS_CHANGED; 2632 MARK_BUFFERS_CHANGED;
2641 2633
2642 /* ### Point used to be modified here, but this causes problems with MULE, 2634 /* ### Point used to be modified here, but this causes problems with MULE,
2643 as point is used to calculate bytinds, and if the offset in bc_numdel causes 2635 as point is used to calculate bytinds, and if the offset in bc_numdel causes
2644 point to move to a non first-byte location, causing some other function to 2636 point to move to a non first-byte location, causing some other function to
2645 throw an assertion in ASSERT_VALID_BYTIND. I've moved the code to right after 2637 throw an assertion in ASSERT_VALID_BYTIND. I've moved the code to right after
2646 the other movements and adjustments, but before the gap is moved. 2638 the other movements and adjustments, but before the gap is moved.
2647 -- jh 970813 */ 2639 -- jh 970813 */
2648 2640
2649 /* Detach any extents that are completely within the range [FROM, TO], 2641 /* Detach any extents that are completely within the range [FROM, TO],
2898 } 2890 }
2899 2891
2900 void 2892 void
2901 barf_if_buffer_read_only (struct buffer *buf, Bufpos from, Bufpos to) 2893 barf_if_buffer_read_only (struct buffer *buf, Bufpos from, Bufpos to)
2902 { 2894 {
2903 Lisp_Object buffer = Qnil; 2895 Lisp_Object buffer;
2904 Lisp_Object iro; 2896 Lisp_Object iro;
2905 2897
2906 XSETBUFFER (buffer, buf); 2898 XSETBUFFER (buffer, buf);
2907 back: 2899 back:
2908 iro = (buf == current_buffer ? Vinhibit_read_only : 2900 iro = (buf == current_buffer ? Vinhibit_read_only :
2909 symbol_value_in_buffer (Qinhibit_read_only, buffer)); 2901 symbol_value_in_buffer (Qinhibit_read_only, buffer));
2910 if (!NILP (iro) && !CONSP (iro)) 2902 if (!LISTP (iro))
2911 return; 2903 return;
2912 if (NILP (iro) && !NILP (buf->read_only)) 2904 if (NILP (iro) && !NILP (buf->read_only))
2913 { 2905 {
2914 Fsignal (Qbuffer_read_only, (list1 (buffer))); 2906 Fsignal (Qbuffer_read_only, (list1 (buffer)));
2915 goto back; 2907 goto back;
2983 } 2975 }
2984 2976
2985 int 2977 int
2986 emchar_string_displayed_columns (CONST Emchar *str, Charcount len) 2978 emchar_string_displayed_columns (CONST Emchar *str, Charcount len)
2987 { 2979 {
2980 #ifdef MULE
2988 int cols = 0; 2981 int cols = 0;
2989 int i; 2982 int i;
2990 2983
2991 for (i = 0; i < len; i++) 2984 for (i = 0; i < len; i++)
2992
2993 cols += XCHARSET_COLUMNS (CHAR_CHARSET (str[i])); 2985 cols += XCHARSET_COLUMNS (CHAR_CHARSET (str[i]));
2994 2986
2995 return cols; 2987 return cols;
2988 #else /* not MULE */
2989 return len;
2990 #endif
2996 } 2991 }
2997 2992
2998 /* NOTE: Does not reset the Dynarr. */ 2993 /* NOTE: Does not reset the Dynarr. */
2999 2994
3000 void 2995 void