Mercurial > hg > xemacs-beta
comparison src/insdel.c @ 398:74fd4e045ea6 r21-2-29
Import from CVS: tag r21-2-29
author | cvs |
---|---|
date | Mon, 13 Aug 2007 11:13:30 +0200 |
parents | 8626e4521993 |
children | a86b2b5e0111 |
comparison
equal
deleted
inserted
replaced
397:f4aeb21a5bad | 398:74fd4e045ea6 |
---|---|
302 | 302 |
303 /* Given a pointer to a text string and a length in bytes, return | 303 /* Given a pointer to a text string and a length in bytes, return |
304 the equivalent length in characters. */ | 304 the equivalent length in characters. */ |
305 | 305 |
306 Charcount | 306 Charcount |
307 bytecount_to_charcount (CONST Bufbyte *ptr, Bytecount len) | 307 bytecount_to_charcount (const Bufbyte *ptr, Bytecount len) |
308 { | 308 { |
309 Charcount count = 0; | 309 Charcount count = 0; |
310 CONST Bufbyte *end = ptr + len; | 310 const Bufbyte *end = ptr + len; |
311 | 311 |
312 #if (LONGBITS == 32 || LONGBITS == 64) | 312 #if (LONGBITS == 32 || LONGBITS == 64) |
313 | 313 |
314 # if (LONGBITS == 32) | 314 # if (LONGBITS == 32) |
315 # define LONG_BYTES 4 | 315 # define LONG_BYTES 4 |
329 if (len >= 12) | 329 if (len >= 12) |
330 { | 330 { |
331 /* Determine the section in the middle of the string that's | 331 /* Determine the section in the middle of the string that's |
332 amenable to this treatment. Everything has to be aligned | 332 amenable to this treatment. Everything has to be aligned |
333 on CPU word boundaries. */ | 333 on CPU word boundaries. */ |
334 CONST Bufbyte *aligned_ptr = | 334 const Bufbyte *aligned_ptr = |
335 (CONST Bufbyte *) (((unsigned long) (ptr + LONG_BYTES - 1)) & | 335 (const Bufbyte *) (((unsigned long) (ptr + LONG_BYTES - 1)) & |
336 ALIGN_MASK); | 336 ALIGN_MASK); |
337 CONST Bufbyte *aligned_end = | 337 const Bufbyte *aligned_end = |
338 (CONST Bufbyte *) (((unsigned long) end) & ALIGN_MASK); | 338 (const Bufbyte *) (((unsigned long) end) & ALIGN_MASK); |
339 | 339 |
340 /* Handle unaligned stuff at the beginning. */ | 340 /* Handle unaligned stuff at the beginning. */ |
341 while (ptr < aligned_ptr) | 341 while (ptr < aligned_ptr) |
342 { | 342 { |
343 if (!BYTE_ASCII_P (*ptr)) | 343 if (!BYTE_ASCII_P (*ptr)) |
376 | 376 |
377 /* Given a pointer to a text string and a length in characters, return | 377 /* Given a pointer to a text string and a length in characters, return |
378 the equivalent length in bytes. */ | 378 the equivalent length in bytes. */ |
379 | 379 |
380 Bytecount | 380 Bytecount |
381 charcount_to_bytecount (CONST Bufbyte *ptr, Charcount len) | 381 charcount_to_bytecount (const Bufbyte *ptr, Charcount len) |
382 { | 382 { |
383 CONST Bufbyte *newptr = ptr; | 383 const Bufbyte *newptr = ptr; |
384 | 384 |
385 while (len > 0) | 385 while (len > 0) |
386 { | 386 { |
387 INC_CHARPTR (newptr); | 387 INC_CHARPTR (newptr); |
388 len--; | 388 len--; |
1603 | 1603 |
1604 static void | 1604 static void |
1605 adjust_markers (struct buffer *buf, Memind from, Memind to, | 1605 adjust_markers (struct buffer *buf, Memind from, Memind to, |
1606 Bytecount amount) | 1606 Bytecount amount) |
1607 { | 1607 { |
1608 struct Lisp_Marker *m; | 1608 Lisp_Marker *m; |
1609 | 1609 |
1610 for (m = BUF_MARKERS (buf); m; m = marker_next (m)) | 1610 for (m = BUF_MARKERS (buf); m; m = marker_next (m)) |
1611 m->memind = do_marker_adjustment (m->memind, from, to, amount); | 1611 m->memind = do_marker_adjustment (m->memind, from, to, amount); |
1612 } | 1612 } |
1613 | 1613 |
1615 for an insertion of AMOUNT characters at POS. */ | 1615 for an insertion of AMOUNT characters at POS. */ |
1616 | 1616 |
1617 static void | 1617 static void |
1618 adjust_markers_for_insert (struct buffer *buf, Memind ind, Bytecount amount) | 1618 adjust_markers_for_insert (struct buffer *buf, Memind ind, Bytecount amount) |
1619 { | 1619 { |
1620 struct Lisp_Marker *m; | 1620 Lisp_Marker *m; |
1621 | 1621 |
1622 for (m = BUF_MARKERS (buf); m; m = marker_next (m)) | 1622 for (m = BUF_MARKERS (buf); m; m = marker_next (m)) |
1623 { | 1623 { |
1624 if (m->insertion_type && m->memind == ind) | 1624 if (m->insertion_type && m->memind == ind) |
1625 m->memind += amount; | 1625 m->memind += amount; |
1628 | 1628 |
1629 | 1629 |
1630 /************************************************************************/ | 1630 /************************************************************************/ |
1631 /* Routines for dealing with the gap */ | 1631 /* Routines for dealing with the gap */ |
1632 /************************************************************************/ | 1632 /************************************************************************/ |
1633 | |
1634 /* XEmacs requires an ANSI C compiler, and it damn well better have a | |
1635 working memmove() */ | |
1636 #define GAP_USE_BCOPY | |
1637 #ifdef BCOPY_UPWARD_SAFE | |
1638 # undef BCOPY_UPWARD_SAFE | |
1639 #endif | |
1640 #ifdef BCOPY_DOWNWARD_SAFE | |
1641 # undef BCOPY_DOWNWARD_SAFE | |
1642 #endif | |
1643 #define BCOPY_UPWARD_SAFE 1 | |
1644 #define BCOPY_DOWNWARD_SAFE 1 | |
1645 | 1633 |
1646 /* maximum amount of memory moved in a single chunk. Increasing this | 1634 /* maximum amount of memory moved in a single chunk. Increasing this |
1647 value improves gap-motion efficiency but decreases QUIT responsiveness | 1635 value improves gap-motion efficiency but decreases QUIT responsiveness |
1648 time. Was 32000 but today's processors are faster and files are | 1636 time. Was 32000 but today's processors are faster and files are |
1649 bigger. --ben */ | 1637 bigger. --ben */ |
1681 break; | 1669 break; |
1682 } | 1670 } |
1683 /* Move at most GAP_MOVE_CHUNK chars before checking again for a quit. */ | 1671 /* Move at most GAP_MOVE_CHUNK chars before checking again for a quit. */ |
1684 if (i > GAP_MOVE_CHUNK) | 1672 if (i > GAP_MOVE_CHUNK) |
1685 i = GAP_MOVE_CHUNK; | 1673 i = GAP_MOVE_CHUNK; |
1686 #ifdef GAP_USE_BCOPY | 1674 |
1687 if (i >= 128 | 1675 if (i >= 128) |
1688 /* bcopy is safe if the two areas of memory do not overlap | 1676 { |
1689 or on systems where bcopy is always safe for moving upward. */ | |
1690 && (BCOPY_UPWARD_SAFE | |
1691 || to - from >= 128)) | |
1692 { | |
1693 /* If overlap is not safe, avoid it by not moving too many | |
1694 characters at once. */ | |
1695 if (!BCOPY_UPWARD_SAFE && i > to - from) | |
1696 i = to - from; | |
1697 new_s1 -= i; | 1677 new_s1 -= i; |
1698 from -= i, to -= i; | 1678 from -= i; |
1679 to -= i; | |
1699 memmove (to, from, i); | 1680 memmove (to, from, i); |
1700 } | 1681 } |
1701 else | 1682 else |
1702 #endif | |
1703 { | 1683 { |
1704 new_s1 -= i; | 1684 new_s1 -= i; |
1705 while (--i >= 0) | 1685 while (--i >= 0) |
1706 *--to = *--from; | 1686 *--to = *--from; |
1707 } | 1687 } |
1760 break; | 1740 break; |
1761 } | 1741 } |
1762 /* Move at most GAP_MOVE_CHUNK chars before checking again for a quit. */ | 1742 /* Move at most GAP_MOVE_CHUNK chars before checking again for a quit. */ |
1763 if (i > GAP_MOVE_CHUNK) | 1743 if (i > GAP_MOVE_CHUNK) |
1764 i = GAP_MOVE_CHUNK; | 1744 i = GAP_MOVE_CHUNK; |
1765 #ifdef GAP_USE_BCOPY | 1745 |
1766 if (i >= 128 | 1746 if (i >= 128) |
1767 /* bcopy is safe if the two areas of memory do not overlap | 1747 { |
1768 or on systems where bcopy is always safe for moving downward. */ | |
1769 && (BCOPY_DOWNWARD_SAFE | |
1770 || from - to >= 128)) | |
1771 { | |
1772 /* If overlap is not safe, avoid it by not moving too many | |
1773 characters at once. */ | |
1774 if (!BCOPY_DOWNWARD_SAFE && i > from - to) | |
1775 i = from - to; | |
1776 new_s1 += i; | 1748 new_s1 += i; |
1777 memmove (to, from, i); | 1749 memmove (to, from, i); |
1778 from += i, to += i; | 1750 from += i; |
1751 to += i; | |
1779 } | 1752 } |
1780 else | 1753 else |
1781 #endif | |
1782 { | 1754 { |
1783 new_s1 += i; | 1755 new_s1 += i; |
1784 while (--i >= 0) | 1756 while (--i >= 0) |
1785 *to++ = *from++; | 1757 *to++ = *from++; |
1786 } | 1758 } |
2055 with the correct arguments. The after-change region is calculated | 2027 with the correct arguments. The after-change region is calculated |
2056 automatically, however, and if changes somehow or other happen outside | 2028 automatically, however, and if changes somehow or other happen outside |
2057 of the specified region, that will also be handled correctly. | 2029 of the specified region, that will also be handled correctly. |
2058 | 2030 |
2059 begin_multiple_change() returns a number (actually a specpdl depth) | 2031 begin_multiple_change() returns a number (actually a specpdl depth) |
2060 that you must pass to end_multiple_change() when you are done. */ | 2032 that you must pass to end_multiple_change() when you are done. |
2033 | |
2034 FSF Emacs 20 implements a similar feature, accessible from Lisp | |
2035 through a `combine-after-change-calls' special form, which is | |
2036 essentially equivalent to this function. We should consider | |
2037 whether we want to introduce a similar Lisp form. */ | |
2061 | 2038 |
2062 int | 2039 int |
2063 begin_multiple_change (struct buffer *buf, Bufpos start, Bufpos end) | 2040 begin_multiple_change (struct buffer *buf, Bufpos start, Bufpos end) |
2064 { | 2041 { |
2065 /* This function can GC */ | 2042 /* This function can GC */ |
2103 change_function_restore (Lisp_Object buffer) | 2080 change_function_restore (Lisp_Object buffer) |
2104 { | 2081 { |
2105 /* We should first reset the variable and then change the buffer, | 2082 /* We should first reset the variable and then change the buffer, |
2106 because Fset_buffer() can throw. */ | 2083 because Fset_buffer() can throw. */ |
2107 inside_change_hook = 0; | 2084 inside_change_hook = 0; |
2108 Fset_buffer (buffer); | 2085 if (XBUFFER (buffer) != current_buffer) |
2086 Fset_buffer (buffer); | |
2109 return Qnil; | 2087 return Qnil; |
2110 } | 2088 } |
2111 | 2089 |
2112 static int in_first_change; | 2090 static int in_first_change; |
2113 | 2091 |
2153 Lisp_Object bufcons; | 2131 Lisp_Object bufcons; |
2154 | 2132 |
2155 if (!inside_change_hook) | 2133 if (!inside_change_hook) |
2156 { | 2134 { |
2157 Lisp_Object buffer; | 2135 Lisp_Object buffer; |
2136 int speccount; | |
2158 | 2137 |
2159 /* Are we in a multiple-change session? */ | 2138 /* Are we in a multiple-change session? */ |
2160 if (buf->text->changes->in_multiple_change && | 2139 if (buf->text->changes->in_multiple_change && |
2161 buf->text->changes->mc_begin != 0) | 2140 buf->text->changes->mc_begin != 0) |
2162 { | 2141 { |
2190 signal_first_change (mbuf); | 2169 signal_first_change (mbuf); |
2191 } | 2170 } |
2192 } | 2171 } |
2193 | 2172 |
2194 /* Now in any case run the before-change-functions if any. */ | 2173 /* Now in any case run the before-change-functions if any. */ |
2174 speccount = specpdl_depth (); | |
2175 record_unwind_protect (change_function_restore, Fcurrent_buffer ()); | |
2176 inside_change_hook = 1; | |
2195 | 2177 |
2196 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons) | 2178 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons) |
2197 { | 2179 { |
2198 XSETBUFFER (buffer, mbuf); | 2180 XSETBUFFER (buffer, mbuf); |
2199 if (!NILP (symbol_value_in_buffer (Qbefore_change_functions, buffer)) | 2181 if (!NILP (symbol_value_in_buffer (Qbefore_change_functions, buffer)) |
2200 /* Obsolete, for compatibility */ | 2182 /* Obsolete, for compatibility */ |
2201 || !NILP (symbol_value_in_buffer (Qbefore_change_function, buffer))) | 2183 || !NILP (symbol_value_in_buffer (Qbefore_change_function, buffer))) |
2202 { | 2184 { |
2203 int speccount = specpdl_depth (); | |
2204 record_unwind_protect (change_function_restore, Fcurrent_buffer ()); | |
2205 set_buffer_internal (buf); | 2185 set_buffer_internal (buf); |
2206 inside_change_hook = 1; | |
2207 va_run_hook_with_args (Qbefore_change_functions, 2, | 2186 va_run_hook_with_args (Qbefore_change_functions, 2, |
2208 make_int (start), make_int (end)); | 2187 make_int (start), make_int (end)); |
2209 /* Obsolete, for compatibility */ | 2188 /* Obsolete, for compatibility */ |
2210 va_run_hook_with_args (Qbefore_change_function, 2, | 2189 va_run_hook_with_args (Qbefore_change_function, 2, |
2211 make_int (start), make_int (end)); | 2190 make_int (start), make_int (end)); |
2212 unbind_to (speccount, Qnil); | |
2213 } | 2191 } |
2214 } | 2192 } |
2215 | 2193 |
2194 /* Make sure endpoints remain valid. before-change-functions | |
2195 might have modified the buffer. */ | |
2196 if (start < BUF_BEGV (buf)) start = BUF_BEGV (buf); | |
2197 if (start > BUF_ZV (buf)) start = BUF_ZV (buf); | |
2198 if (end < BUF_BEGV (buf)) end = BUF_BEGV (buf); | |
2199 if (end > BUF_ZV (buf)) end = BUF_ZV (buf); | |
2200 | |
2216 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons) | 2201 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons) |
2217 { | 2202 { |
2218 XSETBUFFER (buffer, mbuf); | 2203 XSETBUFFER (buffer, mbuf); |
2219 report_extent_modification (buffer, start, end, | 2204 report_extent_modification (buffer, start, end, 0); |
2220 &inside_change_hook, 0); | 2205 } |
2221 } | 2206 unbind_to (speccount, Qnil); |
2222 | 2207 |
2223 /* Only now do we indicate that the before-change-functions have | 2208 /* Only now do we indicate that the before-change-functions have |
2224 been called, in case some function throws out. */ | 2209 been called, in case some function throws out. */ |
2225 buf->text->changes->mc_begin_signaled = 1; | 2210 buf->text->changes->mc_begin_signaled = 1; |
2226 } | 2211 } |
2253 } | 2238 } |
2254 | 2239 |
2255 if (!inside_change_hook) | 2240 if (!inside_change_hook) |
2256 { | 2241 { |
2257 Lisp_Object buffer; | 2242 Lisp_Object buffer; |
2243 int speccount; | |
2258 | 2244 |
2259 if (buf->text->changes->in_multiple_change && | 2245 if (buf->text->changes->in_multiple_change && |
2260 buf->text->changes->mc_begin != 0) | 2246 buf->text->changes->mc_begin != 0) |
2261 { | 2247 { |
2262 assert (start >= buf->text->changes->mc_begin && | 2248 assert (start >= buf->text->changes->mc_begin && |
2265 orig_end <= buf->text->changes->mc_new_end); | 2251 orig_end <= buf->text->changes->mc_new_end); |
2266 buf->text->changes->mc_new_end += new_end - orig_end; | 2252 buf->text->changes->mc_new_end += new_end - orig_end; |
2267 return; /* after-change-functions signalled when all changes done */ | 2253 return; /* after-change-functions signalled when all changes done */ |
2268 } | 2254 } |
2269 | 2255 |
2256 speccount = specpdl_depth (); | |
2257 record_unwind_protect (change_function_restore, Fcurrent_buffer ()); | |
2258 inside_change_hook = 1; | |
2270 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons) | 2259 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons) |
2271 { | 2260 { |
2272 XSETBUFFER (buffer, mbuf); | 2261 XSETBUFFER (buffer, mbuf); |
2273 | 2262 |
2274 if (!NILP (symbol_value_in_buffer (Qafter_change_functions, buffer)) | 2263 if (!NILP (symbol_value_in_buffer (Qafter_change_functions, buffer)) |
2275 /* Obsolete, for compatibility */ | 2264 /* Obsolete, for compatibility */ |
2276 || !NILP (symbol_value_in_buffer (Qafter_change_function, buffer))) | 2265 || !NILP (symbol_value_in_buffer (Qafter_change_function, buffer))) |
2277 { | 2266 { |
2278 int speccount = specpdl_depth (); | |
2279 record_unwind_protect (change_function_restore, Fcurrent_buffer ()); | |
2280 set_buffer_internal (buf); | 2267 set_buffer_internal (buf); |
2281 inside_change_hook = 1; | |
2282 /* The actual after-change functions take slightly | 2268 /* The actual after-change functions take slightly |
2283 different arguments than what we were passed. */ | 2269 different arguments than what we were passed. */ |
2284 va_run_hook_with_args (Qafter_change_functions, 3, | 2270 va_run_hook_with_args (Qafter_change_functions, 3, |
2285 make_int (start), make_int (new_end), | 2271 make_int (start), make_int (new_end), |
2286 make_int (orig_end - start)); | 2272 make_int (orig_end - start)); |
2287 /* Obsolete, for compatibility */ | 2273 /* Obsolete, for compatibility */ |
2288 va_run_hook_with_args (Qafter_change_function, 3, | 2274 va_run_hook_with_args (Qafter_change_function, 3, |
2289 make_int (start), make_int (new_end), | 2275 make_int (start), make_int (new_end), |
2290 make_int (orig_end - start)); | 2276 make_int (orig_end - start)); |
2291 unbind_to (speccount, Qnil); | |
2292 } | 2277 } |
2293 } | 2278 } |
2294 | 2279 |
2280 /* Make sure endpoints remain valid. after-change-functions | |
2281 might have modified the buffer. */ | |
2282 if (start < BUF_BEGV (buf)) start = BUF_BEGV (buf); | |
2283 if (start > BUF_ZV (buf)) start = BUF_ZV (buf); | |
2284 if (new_end < BUF_BEGV (buf)) new_end = BUF_BEGV (buf); | |
2285 if (new_end > BUF_ZV (buf)) new_end = BUF_ZV (buf); | |
2286 if (orig_end < BUF_BEGV (buf)) orig_end = BUF_BEGV (buf); | |
2287 if (orig_end > BUF_ZV (buf)) orig_end = BUF_ZV (buf); | |
2288 | |
2295 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons) | 2289 MAP_INDIRECT_BUFFERS (buf, mbuf, bufcons) |
2296 { | 2290 { |
2297 XSETBUFFER (buffer, mbuf); | 2291 XSETBUFFER (buffer, mbuf); |
2298 report_extent_modification (buffer, start, new_end, | 2292 report_extent_modification (buffer, start, new_end, 1); |
2299 &inside_change_hook, 1); | 2293 } |
2300 } | 2294 unbind_to (speccount, Qnil); /* sets inside_change_hook back to 0 */ |
2301 } | 2295 } |
2302 } | 2296 } |
2303 | 2297 |
2304 /* Call this if you're about to change the region of BUFFER from START | 2298 /* Call this if you're about to change the region of BUFFER from START |
2305 to END. This checks the read-only properties of the region, calls | 2299 to END. This checks the read-only properties of the region, calls |
2375 /************************************************************************/ | 2369 /************************************************************************/ |
2376 /* Insertion of strings */ | 2370 /* Insertion of strings */ |
2377 /************************************************************************/ | 2371 /************************************************************************/ |
2378 | 2372 |
2379 void | 2373 void |
2380 fixup_internal_substring (CONST Bufbyte *nonreloc, Lisp_Object reloc, | 2374 fixup_internal_substring (const Bufbyte *nonreloc, Lisp_Object reloc, |
2381 Bytecount offset, Bytecount *len) | 2375 Bytecount offset, Bytecount *len) |
2382 { | 2376 { |
2383 assert ((nonreloc && NILP (reloc)) || (!nonreloc && STRINGP (reloc))); | 2377 assert ((nonreloc && NILP (reloc)) || (!nonreloc && STRINGP (reloc))); |
2384 | 2378 |
2385 if (*len < 0) | 2379 if (*len < 0) |
2386 { | 2380 { |
2387 if (nonreloc) | 2381 if (nonreloc) |
2388 *len = strlen ((CONST char *) nonreloc) - offset; | 2382 *len = strlen ((const char *) nonreloc) - offset; |
2389 else | 2383 else |
2390 *len = XSTRING_LENGTH (reloc) - offset; | 2384 *len = XSTRING_LENGTH (reloc) - offset; |
2391 } | 2385 } |
2392 #ifdef ERROR_CHECK_BUFPOS | 2386 #ifdef ERROR_CHECK_BUFPOS |
2393 assert (*len >= 0); | 2387 assert (*len >= 0); |
2417 before modifying a buffer. Similar checks were already done | 2411 before modifying a buffer. Similar checks were already done |
2418 in the higher-level Lisp functions calling insert-file-contents. */ | 2412 in the higher-level Lisp functions calling insert-file-contents. */ |
2419 | 2413 |
2420 Charcount | 2414 Charcount |
2421 buffer_insert_string_1 (struct buffer *buf, Bufpos pos, | 2415 buffer_insert_string_1 (struct buffer *buf, Bufpos pos, |
2422 CONST Bufbyte *nonreloc, Lisp_Object reloc, | 2416 const Bufbyte *nonreloc, Lisp_Object reloc, |
2423 Bytecount offset, Bytecount length, | 2417 Bytecount offset, Bytecount length, |
2424 int flags) | 2418 int flags) |
2425 { | 2419 { |
2426 /* This function can GC */ | 2420 /* This function can GC */ |
2427 struct gcpro gcpro1; | 2421 struct gcpro gcpro1; |
2582 to take place. (If POS is -1, text is inserted at point and point | 2576 to take place. (If POS is -1, text is inserted at point and point |
2583 moves forward past the text.) FLAGS is as above. */ | 2577 moves forward past the text.) FLAGS is as above. */ |
2584 | 2578 |
2585 Charcount | 2579 Charcount |
2586 buffer_insert_raw_string_1 (struct buffer *buf, Bufpos pos, | 2580 buffer_insert_raw_string_1 (struct buffer *buf, Bufpos pos, |
2587 CONST Bufbyte *nonreloc, Bytecount length, | 2581 const Bufbyte *nonreloc, Bytecount length, |
2588 int flags) | 2582 int flags) |
2589 { | 2583 { |
2590 /* This function can GC */ | 2584 /* This function can GC */ |
2591 return buffer_insert_string_1 (buf, pos, nonreloc, Qnil, 0, length, | 2585 return buffer_insert_string_1 (buf, pos, nonreloc, Qnil, 0, length, |
2592 flags); | 2586 flags); |
2606 } | 2600 } |
2607 | 2601 |
2608 /* Insert the null-terminated string S (in external format). */ | 2602 /* Insert the null-terminated string S (in external format). */ |
2609 | 2603 |
2610 Charcount | 2604 Charcount |
2611 buffer_insert_c_string_1 (struct buffer *buf, Bufpos pos, CONST char *s, | 2605 buffer_insert_c_string_1 (struct buffer *buf, Bufpos pos, const char *s, |
2612 int flags) | 2606 int flags) |
2613 { | 2607 { |
2614 /* This function can GC */ | 2608 /* This function can GC */ |
2615 CONST char *translated = GETTEXT (s); | 2609 const char *translated = GETTEXT (s); |
2616 return buffer_insert_string_1 (buf, pos, (CONST Bufbyte *) translated, Qnil, | 2610 return buffer_insert_string_1 (buf, pos, (const Bufbyte *) translated, Qnil, |
2617 0, strlen (translated), flags); | 2611 0, strlen (translated), flags); |
2618 } | 2612 } |
2619 | 2613 |
2620 Charcount | 2614 Charcount |
2621 buffer_insert_emacs_char_1 (struct buffer *buf, Bufpos pos, Emchar ch, | 2615 buffer_insert_emacs_char_1 (struct buffer *buf, Bufpos pos, Emchar ch, |
3077 iro); | 3071 iro); |
3078 } | 3072 } |
3079 } | 3073 } |
3080 | 3074 |
3081 void | 3075 void |
3082 find_charsets_in_bufbyte_string (unsigned char *charsets, CONST Bufbyte *str, | 3076 find_charsets_in_bufbyte_string (unsigned char *charsets, const Bufbyte *str, |
3083 Bytecount len) | 3077 Bytecount len) |
3084 { | 3078 { |
3085 #ifndef MULE | 3079 #ifndef MULE |
3086 /* Telescope this. */ | 3080 /* Telescope this. */ |
3087 charsets[0] = 1; | 3081 charsets[0] = 1; |
3088 #else | 3082 #else |
3089 CONST Bufbyte *strend = str + len; | 3083 const Bufbyte *strend = str + len; |
3090 memset (charsets, 0, NUM_LEADING_BYTES); | 3084 memset (charsets, 0, NUM_LEADING_BYTES); |
3091 | 3085 |
3092 while (str < strend) | 3086 while (str < strend) |
3093 { | 3087 { |
3094 charsets[CHAR_LEADING_BYTE (charptr_emchar (str)) - 128] = 1; | 3088 charsets[CHAR_LEADING_BYTE (charptr_emchar (str)) - 128] = 1; |
3096 } | 3090 } |
3097 #endif | 3091 #endif |
3098 } | 3092 } |
3099 | 3093 |
3100 void | 3094 void |
3101 find_charsets_in_emchar_string (unsigned char *charsets, CONST Emchar *str, | 3095 find_charsets_in_emchar_string (unsigned char *charsets, const Emchar *str, |
3102 Charcount len) | 3096 Charcount len) |
3103 { | 3097 { |
3104 #ifndef MULE | 3098 #ifndef MULE |
3105 /* Telescope this. */ | 3099 /* Telescope this. */ |
3106 charsets[0] = 1; | 3100 charsets[0] = 1; |
3114 } | 3108 } |
3115 #endif | 3109 #endif |
3116 } | 3110 } |
3117 | 3111 |
3118 int | 3112 int |
3119 bufbyte_string_displayed_columns (CONST Bufbyte *str, Bytecount len) | 3113 bufbyte_string_displayed_columns (const Bufbyte *str, Bytecount len) |
3120 { | 3114 { |
3121 int cols = 0; | 3115 int cols = 0; |
3122 CONST Bufbyte *end = str + len; | 3116 const Bufbyte *end = str + len; |
3123 | 3117 |
3124 while (str < end) | 3118 while (str < end) |
3125 { | 3119 { |
3126 #ifdef MULE | 3120 #ifdef MULE |
3127 Emchar ch = charptr_emchar (str); | 3121 Emchar ch = charptr_emchar (str); |
3134 | 3128 |
3135 return cols; | 3129 return cols; |
3136 } | 3130 } |
3137 | 3131 |
3138 int | 3132 int |
3139 emchar_string_displayed_columns (CONST Emchar *str, Charcount len) | 3133 emchar_string_displayed_columns (const Emchar *str, Charcount len) |
3140 { | 3134 { |
3141 #ifdef MULE | 3135 #ifdef MULE |
3142 int cols = 0; | 3136 int cols = 0; |
3143 int i; | 3137 int i; |
3144 | 3138 |
3152 } | 3146 } |
3153 | 3147 |
3154 /* NOTE: Does not reset the Dynarr. */ | 3148 /* NOTE: Does not reset the Dynarr. */ |
3155 | 3149 |
3156 void | 3150 void |
3157 convert_bufbyte_string_into_emchar_dynarr (CONST Bufbyte *str, Bytecount len, | 3151 convert_bufbyte_string_into_emchar_dynarr (const Bufbyte *str, Bytecount len, |
3158 Emchar_dynarr *dyn) | 3152 Emchar_dynarr *dyn) |
3159 { | 3153 { |
3160 CONST Bufbyte *strend = str + len; | 3154 const Bufbyte *strend = str + len; |
3161 | 3155 |
3162 while (str < strend) | 3156 while (str < strend) |
3163 { | 3157 { |
3164 Emchar ch = charptr_emchar (str); | 3158 Emchar ch = charptr_emchar (str); |
3165 Dynarr_add (dyn, ch); | 3159 Dynarr_add (dyn, ch); |
3166 INC_CHARPTR (str); | 3160 INC_CHARPTR (str); |
3167 } | 3161 } |
3168 } | 3162 } |
3169 | 3163 |
3170 Charcount | 3164 Charcount |
3171 convert_bufbyte_string_into_emchar_string (CONST Bufbyte *str, Bytecount len, | 3165 convert_bufbyte_string_into_emchar_string (const Bufbyte *str, Bytecount len, |
3172 Emchar *arr) | 3166 Emchar *arr) |
3173 { | 3167 { |
3174 CONST Bufbyte *strend = str + len; | 3168 const Bufbyte *strend = str + len; |
3175 Charcount newlen = 0; | 3169 Charcount newlen = 0; |
3176 while (str < strend) | 3170 while (str < strend) |
3177 { | 3171 { |
3178 Emchar ch = charptr_emchar (str); | 3172 Emchar ch = charptr_emchar (str); |
3179 arr[newlen++] = ch; | 3173 arr[newlen++] = ch; |
3232 /************************************************************************/ | 3226 /************************************************************************/ |
3233 /* initialization */ | 3227 /* initialization */ |
3234 /************************************************************************/ | 3228 /************************************************************************/ |
3235 | 3229 |
3236 void | 3230 void |
3237 vars_of_insdel (void) | 3231 reinit_vars_of_insdel (void) |
3238 { | 3232 { |
3239 int i; | 3233 int i; |
3240 | 3234 |
3241 inside_change_hook = 0; | 3235 inside_change_hook = 0; |
3242 in_first_change = 0; | 3236 in_first_change = 0; |
3243 | 3237 |
3244 for (i = 0; i <= MAX_BYTIND_GAP_SIZE_3; i++) | 3238 for (i = 0; i <= MAX_BYTIND_GAP_SIZE_3; i++) |
3245 three_to_one_table[i] = i / 3; | 3239 three_to_one_table[i] = i / 3; |
3240 } | |
3241 | |
3242 void | |
3243 vars_of_insdel (void) | |
3244 { | |
3245 reinit_vars_of_insdel (); | |
3246 } | 3246 } |
3247 | 3247 |
3248 void | 3248 void |
3249 init_buffer_text (struct buffer *b) | 3249 init_buffer_text (struct buffer *b) |
3250 { | 3250 { |