Mercurial > hg > xemacs-beta
comparison src/buffer.h @ 826:6728e641994e
[xemacs-hg @ 2002-05-05 11:30:15 by ben]
syntax cache, 8-bit-format, lots of code cleanup
README.packages: Update info about --package-path.
i.c: Create an inheritable event and pass it on to XEmacs, so that ^C
can be handled properly. Intercept ^C and signal the event.
"Stop Build" in VC++ now works.
bytecomp-runtime.el: Doc string changes.
compat.el: Some attempts to redo this to
make it truly useful and fix the "multiple versions interacting
with each other" problem. Not yet done. Currently doesn't work.
files.el: Use with-obsolete-variable to avoid warnings in new revert-buffer code.
xemacs.mak: Split up CFLAGS into a version without flags specifying the C
library. The problem seems to be that minitar depends on zlib,
which depends specifically on libc.lib, not on any of the other C
libraries. Unless you compile with libc.lib, you get errors --
specifically, no _errno in the other libraries, which must make it
something other than an int. (#### But this doesn't seem to obtain
in XEmacs, which also uses zlib, and can be linked with any of the
C libraries. Maybe zlib is used differently and doesn't need
errno, or maybe XEmacs provides an int errno; ... I don't
understand.
Makefile.in.in: Fix so that packages are around when testing.
abbrev.c, alloc.c, buffer.c, buffer.h, bytecode.c, callint.c, casefiddle.c, casetab.c, casetab.h, charset.h, chartab.c, chartab.h, cmds.c, console-msw.h, console-stream.c, console-x.c, console.c, console.h, data.c, device-msw.c, device.c, device.h, dialog-msw.c, dialog-x.c, dired-msw.c, dired.c, doc.c, doprnt.c, dumper.c, editfns.c, elhash.c, emacs.c, eval.c, event-Xt.c, event-gtk.c, event-msw.c, event-stream.c, events.c, events.h, extents.c, extents.h, faces.c, file-coding.c, file-coding.h, fileio.c, fns.c, font-lock.c, frame-gtk.c, frame-msw.c, frame-x.c, frame.c, frame.h, glade.c, glyphs-gtk.c, glyphs-msw.c, glyphs-msw.h, glyphs-x.c, glyphs.c, glyphs.h, gui-msw.c, gui-x.c, gui.h, gutter.h, hash.h, indent.c, insdel.c, intl-win32.c, intl.c, keymap.c, lisp-disunion.h, lisp-union.h, lisp.h, lread.c, lrecord.h, lstream.c, lstream.h, marker.c, menubar-gtk.c, menubar-msw.c, menubar-x.c, menubar.c, minibuf.c, mule-ccl.c, mule-charset.c, mule-coding.c, mule-wnnfns.c, nas.c, objects-msw.c, objects-x.c, opaque.c, postgresql.c, print.c, process-nt.c, process-unix.c, process.c, process.h, profile.c, rangetab.c, redisplay-gtk.c, redisplay-msw.c, redisplay-output.c, redisplay-x.c, redisplay.c, redisplay.h, regex.c, regex.h, scrollbar-msw.c, search.c, select-x.c, specifier.c, specifier.h, symbols.c, symsinit.h, syntax.c, syntax.h, syswindows.h, tests.c, text.c, text.h, tooltalk.c, ui-byhand.c, ui-gtk.c, unicode.c, win32.c, window.c: Another big Ben patch.
-- FUNCTIONALITY CHANGES:
add partial support for 8-bit-fixed, 16-bit-fixed, and
32-bit-fixed formats. not quite done yet. (in particular, needs
functions to actually convert the buffer.) NOTE: lots of changes
to regex.c here. also, many new *_fmt() inline funs that take an
Internal_Format argument.
redo syntax cache code. make the cache per-buffer; keep the cache
valid across calls to functions that use it. also keep it valid
across insertions/deletions and extent changes, as much as is
possible. eliminate the junky regex-reentrancy code by passing in
the relevant lisp info to the regex routines as local vars.
add general mechanism in extents code for signalling extent changes.
fix numerous problems with the case-table implementation; yoshiki
never properly transferred many algorithms from old-style to
new-style case tables.
redo char tables to support a default argument, so that mapping
only occurs over changed args. change many chartab functions to
accept Lisp_Object instead of Lisp_Char_Table *.
comment out the code in font-lock.c by default, because
font-lock.el no longer uses it. we should consider eliminating it
entirely.
Don't output bell as ^G in console-stream when not a TTY.
add -mswindows-termination-handle to interface with i.c, so we can
properly kill a build.
add more error-checking to buffer/string macros.
add some additional buffer_or_string_() funs.
-- INTERFACE CHANGES AFFECTING MORE CODE:
switch the arguments of write_c_string and friends to be
consistent with write_fmt_string, which must have printcharfun
first.
change BI_* macros to BYTE_* for increased clarity; similarly for
bi_* local vars.
change VOID_TO_LISP to be a one-argument function. eliminate
no-longer-needed CVOID_TO_LISP.
-- char/string macro changes:
rename MAKE_CHAR() to make_emchar() for slightly less confusion
with make_char(). (The former generates an Emchar, the latter a
Lisp object. Conceivably we should rename make_char() -> wrap_char()
and similarly for make_int(), make_float().)
Similar changes for other *CHAR* macros -- we now consistently use
names with `emchar' whenever we are working with Emchars. Any
remaining name with just `char' always refers to a Lisp object.
rename macros with XSTRING_* to string_* except for those that
reference actual fields in the Lisp_String object, following
conventions used elsewhere.
rename set_string_{data,length} macros (the only ones to work with
a Lisp_String_* instead of a Lisp_Object) to set_lispstringp_*
to make the difference clear.
try to be consistent about caps vs. lowercase in macro/inline-fun
names for chars and such, which wasn't the case before. we now
reserve caps either for XFOO_ macros that reference object fields
(e.g. XSTRING_DATA) or for things that have non-function semantics,
e.g. directly modifying an arg (BREAKUP_EMCHAR) or evaluating an
arg (any arg) more than once. otherwise, use lowercase.
here is a summary of most of the macros/inline funs changed by all
of the above changes:
BYTE_*_P -> byte_*_p
XSTRING_BYTE -> string_byte
set_string_data/length -> set_lispstringp_data/length
XSTRING_CHAR_LENGTH -> string_char_length
XSTRING_CHAR -> string_emchar
INTBYTE_FIRST_BYTE_P -> intbyte_first_byte_p
INTBYTE_LEADING_BYTE_P -> intbyte_leading_byte_p
charptr_copy_char -> charptr_copy_emchar
LEADING_BYTE_* -> leading_byte_*
CHAR_* -> EMCHAR_*
*_CHAR_* -> *_EMCHAR_*
*_CHAR -> *_EMCHAR
CHARSET_BY_ -> charset_by_*
BYTE_SHIFT_JIS* -> byte_shift_jis*
BYTE_BIG5* -> byte_big5*
REP_BYTES_BY_FIRST_BYTE -> rep_bytes_by_first_byte
char_to_unicode -> emchar_to_unicode
valid_char_p -> valid_emchar_p
Change intbyte_strcmp -> qxestrcmp_c (duplicated functionality).
-- INTERFACE CHANGES AFFECTING LESS CODE:
use DECLARE_INLINE_HEADER in various places.
remove '#ifdef emacs' from XEmacs-only files.
eliminate CHAR_TABLE_VALUE(), which duplicated the functionality
of get_char_table().
add BUFFER_TEXT_LOOP to simplify iterations over buffer text.
define typedefs for signed and unsigned types of fixed sizes
(INT_32_BIT, UINT_32_BIT, etc.).
create ALIGN_FOR_TYPE as a higher-level interface onto ALIGN_SIZE;
fix code to use it.
add charptr_emchar_len to return the text length of the character
pointed to by a ptr; use it in place of
charcount_to_bytecount(..., 1). add emchar_len to return the text
length of a given character.
add types Bytexpos and Charxpos to generalize Bytebpos/Bytecount
and Charbpos/Charcount, in code (particularly, the extents code
and redisplay code) that works with either kind of index. rename
redisplay struct params with names such as `charbpos' to
e.g. `charpos' when they are e.g. a Charxpos, not a Charbpos.
eliminate xxDEFUN in place of DEFUN; no longer necessary with
changes awhile back to doc.c.
split up big ugly combined list of EXFUNs in lisp.h on a
file-by-file basis, since other prototypes are similarly split.
rewrite some "*_UNSAFE" macros as inline funs and eliminate the
_UNSAFE suffix.
move most string code from lisp.h to text.h; the string code and
text.h code is now intertwined in such a fashion that they need
to be in the same place and partially interleaved. (you can't
create forward references for inline funs)
automated/lisp-tests.el, automated/symbol-tests.el, automated/test-harness.el: Fix test harness to output FAIL messages to stderr when in
batch mode.
Fix up some problems in lisp-tests/symbol-tests that were
causing spurious failures.
author | ben |
---|---|
date | Sun, 05 May 2002 11:33:57 +0000 |
parents | a634e3b7acc8 |
children | 804517e16990 |
comparison
equal
deleted
inserted
replaced
825:eb3bc15a6e0f | 826:6728e641994e |
---|---|
101 /* And we also cache 16 positions for fairly fast access near those | 101 /* And we also cache 16 positions for fairly fast access near those |
102 positions. */ | 102 positions. */ |
103 Charbpos mule_charbpos_cache[16]; | 103 Charbpos mule_charbpos_cache[16]; |
104 Bytebpos mule_bytebpos_cache[16]; | 104 Bytebpos mule_bytebpos_cache[16]; |
105 | 105 |
106 int entirely_ascii_p; | 106 /* True if all chars fit into one byte; |
107 == (format == FORMAT_8_BIT_FIXED || | |
108 (format == FORMAT_DEFAULT && num_ascii_chars == bufz - 1)) | |
109 kept around to speed up (slightly?) the byte-char conversion routines. */ | |
110 int entirely_one_byte_p; | |
111 /* Number of ASCII chars in buffer (0 - 127) */ | |
112 Charcount num_ascii_chars; | |
113 /* Number of chars in buffer that would fit in an 8-bit-fixed buffer. */ | |
114 Charcount num_8_bit_fixed_chars; | |
115 /* Number of chars in buffer that would fit in an 16-bit-fixed buffer. */ | |
116 Charcount num_16_bit_fixed_chars; | |
117 | |
118 /* Currently we only handle 8 bit fixed and default */ | |
119 Internal_Format format; | |
107 #endif | 120 #endif |
108 | 121 |
109 /* Similar to the above, we keep track of positions for which line | 122 /* Similar to the above, we keep track of positions for which line |
110 number has last been calculated. See line-number.c. */ | 123 number has last been calculated. See line-number.c. */ |
111 Lisp_Object line_number_cache; | 124 Lisp_Object line_number_cache; |
176 | 189 |
177 /* The buffer's extent info. This is its own type, an extent-info | 190 /* The buffer's extent info. This is its own type, an extent-info |
178 object (done this way for ease in marking / finalizing). */ | 191 object (done this way for ease in marking / finalizing). */ |
179 Lisp_Object extent_info; | 192 Lisp_Object extent_info; |
180 | 193 |
194 /* The buffer's syntax cache. This caches a known region where the | |
195 `syntax-table' property is unchanged, for quick lookup in the routines | |
196 that scan a buffer looking for a particular syntax (regex routines, | |
197 parse-partial-sexp, etc.). */ | |
198 struct syntax_cache *syntax_cache; | |
199 | |
181 /* ----------------------------------------------------------------- */ | 200 /* ----------------------------------------------------------------- */ |
182 /* All the stuff above this line is the responsibility of insdel.c, | 201 /* All the stuff above this line is the responsibility of insdel.c, |
183 with some help from marker.c and extents.c. | 202 with some help from marker.c, extents.c and syntax.c. |
184 All the stuff below this line is the responsibility of buffer.c. */ | 203 All the stuff below this line is the responsibility of buffer.c. */ |
185 | 204 |
186 /* In an indirect buffer, this points to the base buffer. | 205 /* In an indirect buffer, this points to the base buffer. |
187 In an ordinary buffer, it is 0. | 206 In an ordinary buffer, it is 0. |
188 We DO mark through this slot. */ | 207 We DO mark through this slot. */ |
259 && (mps_bufvar = XBUFFER (XCAR (mps_bufcons)), 1) \ | 278 && (mps_bufvar = XBUFFER (XCAR (mps_bufcons)), 1) \ |
260 && (mps_bufcons = XCDR (mps_bufcons), 1)); \ | 279 && (mps_bufcons = XCDR (mps_bufcons), 1)); \ |
261 ) | 280 ) |
262 | 281 |
263 | 282 |
283 /* All macros below follow the three golden rules of macros (see text.h), | |
284 with the following exception: | |
285 | |
286 -- 'struct buffer *' arguments can be evaluated more than once. | |
287 */ | |
288 | |
264 /*----------------------------------------------------------------------*/ | 289 /*----------------------------------------------------------------------*/ |
265 /* Accessor macros for important positions in a buffer */ | 290 /* Accessor macros for important positions in a buffer */ |
266 /*----------------------------------------------------------------------*/ | 291 /*----------------------------------------------------------------------*/ |
267 | 292 |
268 /* We put them here because some stuff below wants them before the | 293 /* We put them here because some stuff below wants them before the |
270 | 295 |
271 /* None of these are lvalues. Use the settor macros below to change | 296 /* None of these are lvalues. Use the settor macros below to change |
272 the positions. */ | 297 the positions. */ |
273 | 298 |
274 /* Beginning of buffer. */ | 299 /* Beginning of buffer. */ |
275 #define BI_BUF_BEG(buf) ((Bytebpos) 1) | 300 #define BYTE_BUF_BEG(buf) ((Bytebpos) 1) |
276 #define BUF_BEG(buf) ((Charbpos) 1) | 301 #define BUF_BEG(buf) ((Charbpos) 1) |
277 | 302 |
278 /* Beginning of accessible range of buffer. */ | 303 /* Beginning of accessible range of buffer. */ |
279 #define BI_BUF_BEGV(buf) ((buf)->begv + 0) | 304 #define BYTE_BUF_BEGV(buf) ((buf)->begv + 0) |
280 #define BUF_BEGV(buf) ((buf)->bufbegv + 0) | 305 #define BUF_BEGV(buf) ((buf)->bufbegv + 0) |
281 | 306 |
282 /* End of accessible range of buffer. */ | 307 /* End of accessible range of buffer. */ |
283 #define BI_BUF_ZV(buf) ((buf)->zv + 0) | 308 #define BYTE_BUF_ZV(buf) ((buf)->zv + 0) |
284 #define BUF_ZV(buf) ((buf)->bufzv + 0) | 309 #define BUF_ZV(buf) ((buf)->bufzv + 0) |
285 | 310 |
286 /* End of buffer. */ | 311 /* End of buffer. */ |
287 #define BI_BUF_Z(buf) ((buf)->text->z + 0) | 312 #define BYTE_BUF_Z(buf) ((buf)->text->z + 0) |
288 #define BUF_Z(buf) ((buf)->text->bufz + 0) | 313 #define BUF_Z(buf) ((buf)->text->bufz + 0) |
289 | 314 |
290 /* Point. */ | 315 /* Point. */ |
291 #define BI_BUF_PT(buf) ((buf)->pt + 0) | 316 #define BYTE_BUF_PT(buf) ((buf)->pt + 0) |
292 #define BUF_PT(buf) ((buf)->bufpt + 0) | 317 #define BUF_PT(buf) ((buf)->bufpt + 0) |
293 | 318 |
294 /*----------------------------------------------------------------------*/ | 319 /* Internal format of buffer. */ |
295 /* Converting between positions and addresses */ | 320 #ifdef MULE |
296 /*----------------------------------------------------------------------*/ | 321 #define BUF_FORMAT(buf) ((buf)->text->format) |
297 | 322 #else |
298 /* Convert the address of a byte in the buffer into a position. */ | 323 #define BUF_FORMAT(buf) FORMAT_DEFAULT |
299 INLINE_HEADER Bytebpos BI_BUF_PTR_BYTE_POS (struct buffer *buf, Intbyte *ptr); | 324 #endif |
300 INLINE_HEADER Bytebpos | 325 |
301 BI_BUF_PTR_BYTE_POS (struct buffer *buf, Intbyte *ptr) | 326 /*----------------------------------------------------------------------*/ |
302 { | 327 /* Validating byte positions */ |
303 return (ptr - buf->text->beg + 1 | 328 /*----------------------------------------------------------------------*/ |
304 - ((ptr - buf->text->beg + 1) > buf->text->gpt | 329 |
305 ? buf->text->gap_size : (Bytebpos) 0)); | 330 /* Address of byte at position POS in buffer, no error checking. */ |
306 } | 331 DECLARE_INLINE_HEADER ( |
307 | 332 Intbyte * |
308 #define BUF_PTR_BYTE_POS(buf, ptr) \ | 333 BYTE_BUF_BYTE_ADDRESS_NO_VERIFY (struct buffer *buf, Bytebpos pos) |
309 bytebpos_to_charbpos (buf, BI_BUF_PTR_BYTE_POS (buf, ptr)) | 334 ) |
310 | |
311 /* Address of byte at position POS in buffer. */ | |
312 INLINE_HEADER Intbyte * BI_BUF_BYTE_ADDRESS (struct buffer *buf, Bytebpos pos); | |
313 INLINE_HEADER Intbyte * | |
314 BI_BUF_BYTE_ADDRESS (struct buffer *buf, Bytebpos pos) | |
315 { | 335 { |
316 return (buf->text->beg + | 336 return (buf->text->beg + |
317 ((pos >= buf->text->gpt ? (pos + buf->text->gap_size) : pos) | 337 ((pos >= buf->text->gpt ? (pos + buf->text->gap_size) : pos) |
318 - 1)); | 338 - 1)); |
319 } | 339 } |
320 | 340 |
321 #define BUF_BYTE_ADDRESS(buf, pos) \ | 341 /* Given a byte position, does it point to the beginning of a character? |
322 BI_BUF_BYTE_ADDRESS (buf, charbpos_to_bytebpos (buf, pos)) | 342 */ |
323 | |
324 /* Address of byte before position POS in buffer. */ | |
325 INLINE_HEADER Intbyte * BI_BUF_BYTE_ADDRESS_BEFORE (struct buffer *buf, Bytebpos pos); | |
326 INLINE_HEADER Intbyte * | |
327 BI_BUF_BYTE_ADDRESS_BEFORE (struct buffer *buf, Bytebpos pos) | |
328 { | |
329 return (buf->text->beg + | |
330 ((pos > buf->text->gpt ? (pos + buf->text->gap_size) : pos) | |
331 - 2)); | |
332 } | |
333 | |
334 #define BUF_BYTE_ADDRESS_BEFORE(buf, pos) \ | |
335 BI_BUF_BYTE_ADDRESS_BEFORE (buf, charbpos_to_bytebpos (buf, pos)) | |
336 | |
337 /*----------------------------------------------------------------------*/ | |
338 /* Converting between byte indices and memory indices */ | |
339 /*----------------------------------------------------------------------*/ | |
340 | |
341 INLINE_HEADER int valid_membpos_p (struct buffer *buf, Membpos x); | |
342 INLINE_HEADER int | |
343 valid_membpos_p (struct buffer *buf, Membpos x) | |
344 { | |
345 return ((x >= 1 && x <= (Membpos) buf->text->gpt) || | |
346 (x > (Membpos) (buf->text->gpt + buf->text->gap_size) && | |
347 x <= (Membpos) (buf->text->z + buf->text->gap_size))); | |
348 } | |
349 | |
350 INLINE_HEADER Membpos bytebpos_to_membpos (struct buffer *buf, Bytebpos x); | |
351 INLINE_HEADER Membpos | |
352 bytebpos_to_membpos (struct buffer *buf, Bytebpos x) | |
353 { | |
354 return (Membpos) ((x > buf->text->gpt) ? (x + buf->text->gap_size) : x); | |
355 } | |
356 | |
357 | |
358 INLINE_HEADER Bytebpos membpos_to_bytebpos (struct buffer *buf, Membpos x); | |
359 INLINE_HEADER Bytebpos | |
360 membpos_to_bytebpos (struct buffer *buf, Membpos x) | |
361 { | |
362 #ifdef ERROR_CHECK_TEXT | |
363 assert (valid_membpos_p (buf, x)); | |
364 #endif | |
365 return (Bytebpos) ((x > (Membpos) buf->text->gpt) ? | |
366 x - buf->text->gap_size : | |
367 x); | |
368 } | |
369 | |
370 #define membpos_to_charbpos(buf, x) \ | |
371 bytebpos_to_charbpos (buf, membpos_to_bytebpos (buf, x)) | |
372 #define charbpos_to_membpos(buf, x) \ | |
373 bytebpos_to_membpos (buf, charbpos_to_bytebpos (buf, x)) | |
374 | |
375 /* These macros generalize many standard buffer-position functions to | |
376 either a buffer or a string. */ | |
377 | |
378 /* Converting between Membposs and Bytebposs, for a buffer-or-string. | |
379 For strings, this is a no-op. For buffers, this resolves | |
380 to the standard membpos<->bytebpos converters. */ | |
381 | |
382 #define buffer_or_string_bytebpos_to_membpos(obj, ind) \ | |
383 (BUFFERP (obj) ? bytebpos_to_membpos (XBUFFER (obj), ind) : (Membpos) ind) | |
384 | |
385 #define buffer_or_string_membpos_to_bytebpos(obj, ind) \ | |
386 (BUFFERP (obj) ? membpos_to_bytebpos (XBUFFER (obj), ind) : (Bytebpos) ind) | |
387 | |
388 /* Converting between Charbpos's and Bytebposs, for a buffer-or-string. | |
389 For strings, this maps to the bytecount<->charcount converters. */ | |
390 | |
391 #define buffer_or_string_charbpos_to_bytebpos(obj, pos) \ | |
392 (BUFFERP (obj) ? charbpos_to_bytebpos (XBUFFER (obj), pos) : \ | |
393 (Bytebpos) string_index_char_to_byte (obj, pos)) | |
394 | |
395 #define buffer_or_string_bytebpos_to_charbpos(obj, ind) \ | |
396 (BUFFERP (obj) ? bytebpos_to_charbpos (XBUFFER (obj), ind) : \ | |
397 (Charbpos) string_index_byte_to_char (obj, ind)) | |
398 | |
399 /* Similar for Charbpos's and Membposs. */ | |
400 | |
401 #define buffer_or_string_charbpos_to_membpos(obj, pos) \ | |
402 (BUFFERP (obj) ? charbpos_to_membpos (XBUFFER (obj), pos) : \ | |
403 (Membpos) string_index_char_to_byte (obj, pos)) | |
404 | |
405 #define buffer_or_string_membpos_to_charbpos(obj, ind) \ | |
406 (BUFFERP (obj) ? membpos_to_charbpos (XBUFFER (obj), ind) : \ | |
407 (Charbpos) string_index_byte_to_char (obj, ind)) | |
408 | |
409 /************************************************************************/ | |
410 /* */ | |
411 /* working with buffer-level data */ | |
412 /* */ | |
413 /************************************************************************/ | |
414 | |
415 /* | |
416 | |
417 (A) Working with byte indices: | |
418 ------------------------------ | |
419 | |
420 VALID_BYTEBPOS_P(buf, bi): | |
421 Given a byte index, does it point to the beginning of a character? | |
422 | |
423 ASSERT_VALID_BYTEBPOS_UNSAFE(buf, bi): | |
424 If error-checking is enabled, assert that the given byte index | |
425 is within range and points to the beginning of a character | |
426 or to the end of the buffer. Otherwise, do nothing. | |
427 | |
428 ASSERT_VALID_BYTEBPOS_BACKWARD_UNSAFE(buf, bi): | |
429 If error-checking is enabled, assert that the given byte index | |
430 is within range and satisfies ASSERT_VALID_BYTEBPOS() and also | |
431 does not refer to the beginning of the buffer. (i.e. movement | |
432 backwards is OK.) Otherwise, do nothing. | |
433 | |
434 ASSERT_VALID_BYTEBPOS_FORWARD_UNSAFE(buf, bi): | |
435 If error-checking is enabled, assert that the given byte index | |
436 is within range and satisfies ASSERT_VALID_BYTEBPOS() and also | |
437 does not refer to the end of the buffer. (i.e. movement | |
438 forwards is OK.) Otherwise, do nothing. | |
439 | |
440 VALIDATE_BYTEBPOS_BACKWARD(buf, bi): | |
441 Make sure that the given byte index is pointing to the beginning | |
442 of a character. If not, back up until this is the case. Note | |
443 that there are not too many places where it is legitimate to do | |
444 this sort of thing. It's an error if you're passed an "invalid" | |
445 byte index. | |
446 | |
447 VALIDATE_BYTEBPOS_FORWARD(buf, bi): | |
448 Make sure that the given byte index is pointing to the beginning | |
449 of a character. If not, move forward until this is the case. | |
450 Note that there are not too many places where it is legitimate | |
451 to do this sort of thing. It's an error if you're passed an | |
452 "invalid" byte index. | |
453 | |
454 INC_BYTEBPOS(buf, bi): | |
455 Given a byte index (assumed to point at the beginning of a | |
456 character), modify that value so it points to the beginning | |
457 of the next character. | |
458 | |
459 DEC_BYTEBPOS(buf, bi): | |
460 Given a byte index (assumed to point at the beginning of a | |
461 character), modify that value so it points to the beginning | |
462 of the previous character. Unlike for DEC_CHARPTR(), we can | |
463 do all the assert()s because there are sentinels at the | |
464 beginning of the gap and the end of the buffer. | |
465 | |
466 BYTEBPOS_INVALID: | |
467 A constant representing an invalid Bytebpos. Valid Bytebposs | |
468 can never have this value. | |
469 | |
470 | |
471 (B) Converting between Charbpos's and Bytebposs: | |
472 -------------------------------------------- | |
473 | |
474 charbpos_to_bytebpos(buf, bu): | |
475 Given a Charbpos, return the equivalent Bytebpos. | |
476 | |
477 bytebpos_to_charbpos(buf, bi): | |
478 Given a Bytebpos, return the equivalent Charbpos. | |
479 | |
480 make_charbpos(buf, bi): | |
481 Given a Bytebpos, return the equivalent Charbpos as a Lisp Object. | |
482 */ | |
483 | |
484 | |
485 /*----------------------------------------------------------------------*/ | |
486 /* working with byte indices */ | |
487 /*----------------------------------------------------------------------*/ | |
488 | |
489 #ifdef MULE | 343 #ifdef MULE |
490 # define VALID_BYTEBPOS_P(buf, x) \ | 344 DECLARE_INLINE_HEADER ( |
491 INTBYTE_FIRST_BYTE_P (*BI_BUF_BYTE_ADDRESS (buf, x)) | 345 int |
346 VALID_BYTEBPOS_P (struct buffer *buf, Bytebpos x) | |
347 ) | |
348 { | |
349 switch (BUF_FORMAT (buf)) | |
350 { | |
351 case FORMAT_DEFAULT: | |
352 return intbyte_first_byte_p (*BYTE_BUF_BYTE_ADDRESS_NO_VERIFY (buf, x)); | |
353 case FORMAT_16_BIT_FIXED: | |
354 return ((x - 1) & 1) == 0; | |
355 case FORMAT_32_BIT_FIXED: | |
356 return ((x - 1) & 3) == 0; | |
357 default: | |
358 return 1; | |
359 } | |
360 } | |
492 #else | 361 #else |
493 # define VALID_BYTEBPOS_P(buf, x) 1 | 362 # define VALID_BYTEBPOS_P(buf, x) 1 |
494 #endif | 363 #endif |
495 | 364 |
496 #ifdef ERROR_CHECK_TEXT | 365 /* If error-checking is enabled, assert that the given char position is |
497 | 366 within range. Otherwise, do nothing. |
498 # define ASSERT_VALID_BYTEBPOS_UNSAFE(buf, x) do { \ | 367 */ |
499 assert (BUFFER_LIVE_P (buf)); \ | 368 # define ASSERT_VALID_CHARBPOS_UNSAFE(buf, x) do { \ |
500 assert ((x) >= BI_BUF_BEG (buf) && x <= BI_BUF_Z (buf)); \ | 369 text_checking_assert (BUFFER_LIVE_P (buf)); \ |
501 assert (VALID_BYTEBPOS_P (buf, x)); \ | 370 text_checking_assert ((x) >= BUF_BEG (buf) && x <= BUF_Z (buf)); \ |
502 } while (0) | 371 } while (0) |
503 # define ASSERT_VALID_BYTEBPOS_BACKWARD_UNSAFE(buf, x) do { \ | 372 |
504 assert (BUFFER_LIVE_P (buf)); \ | 373 /* If error-checking is enabled, assert that the given byte position is |
505 assert ((x) > BI_BUF_BEG (buf) && x <= BI_BUF_Z (buf)); \ | 374 within range and points to the beginning of a character or to the end of |
506 assert (VALID_BYTEBPOS_P (buf, x)); \ | 375 the buffer. Otherwise, do nothing. |
507 } while (0) | 376 */ |
508 # define ASSERT_VALID_BYTEBPOS_FORWARD_UNSAFE(buf, x) do { \ | 377 # define ASSERT_VALID_BYTEBPOS_UNSAFE(buf, x) do { \ |
509 assert (BUFFER_LIVE_P (buf)); \ | 378 text_checking_assert (BUFFER_LIVE_P (buf)); \ |
510 assert ((x) >= BI_BUF_BEG (buf) && x < BI_BUF_Z (buf)); \ | 379 text_checking_assert ((x) >= BYTE_BUF_BEG (buf) && x <= BYTE_BUF_Z (buf)); \ |
511 assert (VALID_BYTEBPOS_P (buf, x)); \ | 380 text_checking_assert (VALID_BYTEBPOS_P (buf, x)); \ |
512 } while (0) | 381 } while (0) |
513 | 382 |
514 #else /* not ERROR_CHECK_TEXT */ | 383 /* If error-checking is enabled, assert that the given byte position is |
515 # define ASSERT_VALID_BYTEBPOS_UNSAFE(buf, x) | 384 within range and satisfies ASSERT_VALID_BYTEBPOS() and also does not |
516 # define ASSERT_VALID_BYTEBPOS_BACKWARD_UNSAFE(buf, x) | 385 refer to the beginning of the buffer. (i.e. movement backwards is OK.) |
517 # define ASSERT_VALID_BYTEBPOS_FORWARD_UNSAFE(buf, x) | 386 Otherwise, do nothing. |
518 | 387 */ |
519 #endif /* not ERROR_CHECK_TEXT */ | 388 # define ASSERT_VALID_BYTEBPOS_BACKWARD_UNSAFE(buf, x) do { \ |
520 | 389 text_checking_assert (BUFFER_LIVE_P (buf)); \ |
521 /* Note that, although the Mule version will work fine for non-Mule | 390 text_checking_assert ((x) > BYTE_BUF_BEG (buf) && x <= BYTE_BUF_Z (buf)); \ |
522 as well (it should reduce down to nothing), we provide a separate | 391 text_checking_assert (VALID_BYTEBPOS_P (buf, x)); \ |
523 version to avoid compilation warnings and possible non-optimal | 392 } while (0) |
524 results with stupid compilers. */ | 393 |
394 /* If error-checking is enabled, assert that the given byte position is | |
395 within range and satisfies ASSERT_VALID_BYTEBPOS() and also does not | |
396 refer to the end of the buffer. (i.e. movement forwards is OK.) | |
397 Otherwise, do nothing. | |
398 */ | |
399 # define ASSERT_VALID_BYTEBPOS_FORWARD_UNSAFE(buf, x) do { \ | |
400 text_checking_assert (BUFFER_LIVE_P (buf)); \ | |
401 text_checking_assert ((x) >= BYTE_BUF_BEG (buf) && x < BYTE_BUF_Z (buf)); \ | |
402 text_checking_assert (VALID_BYTEBPOS_P (buf, x)); \ | |
403 } while (0) | |
525 | 404 |
526 #ifdef MULE | 405 #ifdef MULE |
527 # define VALIDATE_BYTEBPOS_BACKWARD(buf, x) do { \ | 406 /* Make sure that the given byte position is pointing to the beginning of a |
528 Intbyte *VBB_ptr = BI_BUF_BYTE_ADDRESS (buf, x); \ | 407 character. If not, back up until this is the case. Note that there are |
529 while (!INTBYTE_FIRST_BYTE_P (*VBB_ptr)) \ | 408 not too many places where it is legitimate to do this sort of thing. |
530 VBB_ptr--, (x)--; \ | 409 It's an error if you're passed an "invalid" byte position. |
410 */ | |
411 # define VALIDATE_BYTEBPOS_BACKWARD(buf, x) do { \ | |
412 switch (BUF_FORMAT (buf)) \ | |
413 { \ | |
414 case FORMAT_DEFAULT: \ | |
415 { \ | |
416 Intbyte *VBB_ptr = BYTE_BUF_BYTE_ADDRESS_NO_VERIFY (buf, x); \ | |
417 while (!intbyte_first_byte_p (*VBB_ptr)) \ | |
418 VBB_ptr--, (x)--; \ | |
419 } \ | |
420 break; \ | |
421 case FORMAT_16_BIT_FIXED: \ | |
422 if (((x - 1) & 1) != 0) \ | |
423 x--; \ | |
424 break; \ | |
425 case FORMAT_32_BIT_FIXED: \ | |
426 while (((x - 1) & 3) != 0) \ | |
427 x--; \ | |
428 break; \ | |
429 default: \ | |
430 break; \ | |
431 } \ | |
531 } while (0) | 432 } while (0) |
532 #else | 433 #else |
533 # define VALIDATE_BYTEBPOS_BACKWARD(buf, x) | 434 # define VALIDATE_BYTEBPOS_BACKWARD(buf, x) |
534 #endif | 435 #endif |
535 | 436 |
536 /* Note that, although the Mule version will work fine for non-Mule | |
537 as well (it should reduce down to nothing), we provide a separate | |
538 version to avoid compilation warnings and possible non-optimal | |
539 results with stupid compilers. */ | |
540 | |
541 #ifdef MULE | 437 #ifdef MULE |
542 # define VALIDATE_BYTEBPOS_FORWARD(buf, x) do { \ | 438 /* Make sure that the given byte position is pointing to the beginning of a |
543 Intbyte *VBF_ptr = BI_BUF_BYTE_ADDRESS (buf, x); \ | 439 character. If not, move forward until this is the case. Note that |
544 while (!INTBYTE_FIRST_BYTE_P (*VBF_ptr)) \ | 440 there are not too many places where it is legitimate to do this sort of |
545 VBF_ptr++, (x)++; \ | 441 thing. It's an error if you're passed an "invalid" byte position. |
442 */ | |
443 # define VALIDATE_BYTEBPOS_FORWARD(buf, x) do { \ | |
444 switch (BUF_FORMAT (buf)) \ | |
445 { \ | |
446 case FORMAT_DEFAULT: \ | |
447 { \ | |
448 Intbyte *VBF_ptr = BYTE_BUF_BYTE_ADDRESS_NO_VERIFY (buf, x); \ | |
449 while (!intbyte_first_byte_p (*VBF_ptr)) \ | |
450 VBF_ptr++, (x)++; \ | |
451 } \ | |
452 break; \ | |
453 case FORMAT_16_BIT_FIXED: \ | |
454 if (((x - 1) & 1) != 0) \ | |
455 x++; \ | |
456 break; \ | |
457 case FORMAT_32_BIT_FIXED: \ | |
458 while (((x - 1) & 3) != 0) \ | |
459 x++; \ | |
460 break; \ | |
461 default: \ | |
462 break; \ | |
463 } \ | |
546 } while (0) | 464 } while (0) |
547 #else | 465 #else |
548 # define VALIDATE_BYTEBPOS_FORWARD(buf, x) | 466 # define VALIDATE_BYTEBPOS_FORWARD(buf, x) |
549 #endif | 467 #endif |
550 | 468 |
551 /* Note that in the simplest case (no MULE, no ERROR_CHECK_TEXT), | 469 /*----------------------------------------------------------------------*/ |
552 this crap reduces down to simply (x)++. */ | 470 /* Working with byte positions */ |
471 /*----------------------------------------------------------------------*/ | |
472 | |
473 | |
474 /* Given a byte position (assumed to point at the beginning of a | |
475 character), modify that value so it points to the beginning of the next | |
476 character. | |
477 | |
478 Note that in the simplest case (no MULE, no ERROR_CHECK_TEXT), | |
479 this crap reduces down to simply (x)++. */ | |
553 | 480 |
554 #define INC_BYTEBPOS(buf, x) do \ | 481 #define INC_BYTEBPOS(buf, x) do \ |
555 { \ | 482 { \ |
556 ASSERT_VALID_BYTEBPOS_FORWARD_UNSAFE (buf, x); \ | 483 ASSERT_VALID_BYTEBPOS_FORWARD_UNSAFE (buf, x); \ |
557 /* Note that we do the increment first to \ | 484 /* Note that we do the increment first to \ |
558 make sure that the pointer in \ | 485 make sure that the pointer in \ |
559 VALIDATE_BYTEBPOS_FORWARD() ends up on \ | 486 VALIDATE_BYTEBPOS_FORWARD() ends up on \ |
560 the correct side of the gap */ \ | 487 the correct side of the gap */ \ |
561 (x)++; \ | 488 (x)++; \ |
562 VALIDATE_BYTEBPOS_FORWARD (buf, x); \ | 489 VALIDATE_BYTEBPOS_FORWARD (buf, x); \ |
563 } while (0) | 490 } while (0) |
564 | 491 |
565 /* Note that in the simplest case (no MULE, no ERROR_CHECK_TEXT), | 492 /* Given a byte position (assumed to point at the beginning of a |
566 this crap reduces down to simply (x)--. */ | 493 character), modify that value so it points to the beginning of the |
494 previous character. Unlike for DEC_CHARPTR(), we can do all the | |
495 assert()s because there are sentinels at the beginning of the gap and | |
496 the end of the buffer. | |
497 | |
498 Note that in the simplest case (no MULE, no ERROR_CHECK_TEXT), this | |
499 crap reduces down to simply (x)--. */ | |
567 | 500 |
568 #define DEC_BYTEBPOS(buf, x) do \ | 501 #define DEC_BYTEBPOS(buf, x) do \ |
569 { \ | 502 { \ |
570 ASSERT_VALID_BYTEBPOS_BACKWARD_UNSAFE (buf, x); \ | 503 ASSERT_VALID_BYTEBPOS_BACKWARD_UNSAFE (buf, x); \ |
571 /* Note that we do the decrement first to \ | 504 /* Note that we do the decrement first to \ |
574 the correct side of the gap */ \ | 507 the correct side of the gap */ \ |
575 (x)--; \ | 508 (x)--; \ |
576 VALIDATE_BYTEBPOS_BACKWARD (buf, x); \ | 509 VALIDATE_BYTEBPOS_BACKWARD (buf, x); \ |
577 } while (0) | 510 } while (0) |
578 | 511 |
579 INLINE_HEADER Bytebpos prev_bytebpos (struct buffer *buf, Bytebpos x); | 512 DECLARE_INLINE_HEADER ( |
580 INLINE_HEADER Bytebpos | 513 Bytebpos |
581 prev_bytebpos (struct buffer *buf, Bytebpos x) | 514 prev_bytebpos (struct buffer *buf, Bytebpos x) |
515 ) | |
582 { | 516 { |
583 DEC_BYTEBPOS (buf, x); | 517 DEC_BYTEBPOS (buf, x); |
584 return x; | 518 return x; |
585 } | 519 } |
586 | 520 |
587 INLINE_HEADER Bytebpos next_bytebpos (struct buffer *buf, Bytebpos x); | 521 DECLARE_INLINE_HEADER ( |
588 INLINE_HEADER Bytebpos | 522 Bytebpos |
589 next_bytebpos (struct buffer *buf, Bytebpos x) | 523 next_bytebpos (struct buffer *buf, Bytebpos x) |
524 ) | |
590 { | 525 { |
591 INC_BYTEBPOS (buf, x); | 526 INC_BYTEBPOS (buf, x); |
592 return x; | 527 return x; |
593 } | 528 } |
594 | 529 |
530 /* A constant representing an invalid Bytebpos. Valid Bytebposes | |
531 can never have this value. */ | |
532 | |
595 #define BYTEBPOS_INVALID ((Bytebpos) -1) | 533 #define BYTEBPOS_INVALID ((Bytebpos) -1) |
596 | 534 |
597 /*----------------------------------------------------------------------*/ | 535 /*----------------------------------------------------------------------*/ |
598 /* Converting between buffer positions and byte indices */ | 536 /* Converting between byte and character positions */ |
599 /*----------------------------------------------------------------------*/ | 537 /*----------------------------------------------------------------------*/ |
600 | 538 |
601 #ifdef MULE | 539 #ifdef MULE |
602 | |
603 Bytebpos charbpos_to_bytebpos_func (struct buffer *buf, Charbpos x); | |
604 Charbpos bytebpos_to_charbpos_func (struct buffer *buf, Bytebpos x); | |
605 | 540 |
606 /* The basic algorithm we use is to keep track of a known region of | 541 /* The basic algorithm we use is to keep track of a known region of |
607 characters in each buffer, all of which are of the same width. We keep | 542 characters in each buffer, all of which are of the same width. We keep |
608 track of the boundaries of the region in both Charbpos and Bytebpos | 543 track of the boundaries of the region in both Charbpos and Bytebpos |
609 coordinates and also keep track of the char width, which is 1 - 4 bytes. | 544 coordinates and also keep track of the char width, which is 1 - 4 bytes. |
663 !!#### We should investigate the algorithm in GNU Emacs. I think it | 598 !!#### We should investigate the algorithm in GNU Emacs. I think it |
664 does something similar, but it may differ in some details, and it's | 599 does something similar, but it may differ in some details, and it's |
665 worth seeing if anything can be gleaned. | 600 worth seeing if anything can be gleaned. |
666 */ | 601 */ |
667 | 602 |
603 Bytebpos charbpos_to_bytebpos_func (struct buffer *buf, Charbpos x); | |
604 Charbpos bytebpos_to_charbpos_func (struct buffer *buf, Bytebpos x); | |
668 extern short three_to_one_table[]; | 605 extern short three_to_one_table[]; |
669 | 606 |
670 INLINE_HEADER Bytebpos real_charbpos_to_bytebpos (struct buffer *buf, Charbpos x); | 607 #endif /* MULE */ |
671 INLINE_HEADER Bytebpos | 608 |
672 real_charbpos_to_bytebpos (struct buffer *buf, Charbpos x) | 609 /* Given a Charbpos, return the equivalent Bytebpos. */ |
673 { | 610 |
674 if (buf->text->entirely_ascii_p) | 611 DECLARE_INLINE_HEADER ( |
675 return (Bytebpos) x; | 612 Bytebpos |
676 if (x >= buf->text->mule_bufmin && x <= buf->text->mule_bufmax) | 613 charbpos_to_bytebpos (struct buffer *buf, Charbpos x) |
677 return (buf->text->mule_bytmin + | 614 ) |
615 { | |
616 Bytebpos retval; | |
617 ASSERT_VALID_CHARBPOS_UNSAFE (buf, x); | |
618 #ifdef MULE | |
619 if (buf->text->entirely_one_byte_p) | |
620 retval = (Bytebpos) x; | |
621 else if (BUF_FORMAT (buf) == FORMAT_16_BIT_FIXED) | |
622 retval = (Bytebpos) (x << 1); | |
623 else if (BUF_FORMAT (buf) == FORMAT_32_BIT_FIXED) | |
624 retval = (Bytebpos) (x << 2); | |
625 else if (x >= buf->text->mule_bufmin && x <= buf->text->mule_bufmax) | |
626 retval = (buf->text->mule_bytmin + | |
678 ((x - buf->text->mule_bufmin) << buf->text->mule_shifter) + | 627 ((x - buf->text->mule_bufmin) << buf->text->mule_shifter) + |
679 (buf->text->mule_three_p ? (x - buf->text->mule_bufmin) : | 628 (buf->text->mule_three_p ? (x - buf->text->mule_bufmin) : |
680 (Bytebpos) 0)); | 629 (Bytebpos) 0)); |
681 else | 630 else |
682 return charbpos_to_bytebpos_func (buf, x); | 631 retval = charbpos_to_bytebpos_func (buf, x); |
683 } | 632 #else |
684 | 633 retval = (Bytebpos) x; |
685 INLINE_HEADER Charbpos real_bytebpos_to_charbpos (struct buffer *buf, Bytebpos x); | 634 #endif |
686 INLINE_HEADER Charbpos | 635 ASSERT_VALID_BYTEBPOS_UNSAFE (buf, retval); |
687 real_bytebpos_to_charbpos (struct buffer *buf, Bytebpos x) | 636 return retval; |
688 { | 637 } |
689 if (buf->text->entirely_ascii_p) | 638 |
690 return (Charbpos) x; | 639 /* Given a Bytebpos, return the equivalent Charbpos. */ |
691 if (x >= buf->text->mule_bytmin && x <= buf->text->mule_bytmax) | 640 |
692 return (buf->text->mule_bufmin + | 641 DECLARE_INLINE_HEADER ( |
693 ((buf->text->mule_three_p | 642 Charbpos |
694 ? three_to_one_table[x - buf->text->mule_bytmin] | 643 bytebpos_to_charbpos (struct buffer *buf, Bytebpos x) |
695 : (x - buf->text->mule_bytmin) >> buf->text->mule_shifter))); | 644 ) |
645 { | |
646 Charbpos retval; | |
647 ASSERT_VALID_BYTEBPOS_UNSAFE (buf, x); | |
648 #ifdef MULE | |
649 if (buf->text->entirely_one_byte_p) | |
650 retval = (Charbpos) x; | |
651 else if (BUF_FORMAT (buf) == FORMAT_16_BIT_FIXED) | |
652 retval = (Charbpos) (x >> 1); | |
653 else if (BUF_FORMAT (buf) == FORMAT_32_BIT_FIXED) | |
654 retval = (Charbpos) (x >> 2); | |
655 else if (x >= buf->text->mule_bytmin && x <= buf->text->mule_bytmax) | |
656 retval = (buf->text->mule_bufmin + | |
657 ((buf->text->mule_three_p | |
658 ? three_to_one_table[x - buf->text->mule_bytmin] | |
659 : (x - buf->text->mule_bytmin) >> buf->text->mule_shifter))); | |
696 else | 660 else |
697 return bytebpos_to_charbpos_func (buf, x); | 661 retval = bytebpos_to_charbpos_func (buf, x); |
698 } | 662 #else |
699 | 663 retval = (Charbpos) x; |
700 #else /* not MULE */ | 664 #endif |
701 | 665 ASSERT_VALID_CHARBPOS_UNSAFE (buf, retval); |
702 # define real_charbpos_to_bytebpos(buf, x) ((Bytebpos) x) | 666 return retval; |
703 # define real_bytebpos_to_charbpos(buf, x) ((Charbpos) x) | 667 } |
704 | 668 |
705 #endif /* not MULE */ | 669 /* Given a Bytebpos, return the equivalent Charbpos as a Lisp Object. */ |
706 | |
707 #ifdef ERROR_CHECK_TEXT | |
708 | |
709 Bytebpos charbpos_to_bytebpos (struct buffer *buf, Charbpos x); | |
710 Charbpos bytebpos_to_charbpos (struct buffer *buf, Bytebpos x); | |
711 | |
712 #else /* not ERROR_CHECK_TEXT */ | |
713 | |
714 #define charbpos_to_bytebpos real_charbpos_to_bytebpos | |
715 #define bytebpos_to_charbpos real_bytebpos_to_charbpos | |
716 | |
717 #endif /* not ERROR_CHECK_TEXT */ | |
718 | 670 |
719 #define make_charbpos(buf, ind) make_int (bytebpos_to_charbpos (buf, ind)) | 671 #define make_charbpos(buf, ind) make_int (bytebpos_to_charbpos (buf, ind)) |
720 | 672 |
721 /*----------------------------------------------------------------------*/ | 673 /*----------------------------------------------------------------------*/ |
674 /* Converting between byte and memory positions */ | |
675 /*----------------------------------------------------------------------*/ | |
676 | |
677 DECLARE_INLINE_HEADER ( | |
678 int | |
679 valid_membpos_p (struct buffer *buf, Membpos x) | |
680 ) | |
681 { | |
682 return ((x >= 1 && x <= (Membpos) buf->text->gpt) || | |
683 (x > (Membpos) (buf->text->gpt + buf->text->gap_size) && | |
684 x <= (Membpos) (buf->text->z + buf->text->gap_size))); | |
685 } | |
686 | |
687 DECLARE_INLINE_HEADER ( | |
688 Membpos | |
689 bytebpos_to_membpos (struct buffer *buf, Bytebpos x) | |
690 ) | |
691 { | |
692 ASSERT_VALID_BYTEBPOS_UNSAFE (buf, x); | |
693 return (Membpos) ((x > buf->text->gpt) ? (x + buf->text->gap_size) : x); | |
694 } | |
695 | |
696 | |
697 DECLARE_INLINE_HEADER ( | |
698 Bytebpos | |
699 membpos_to_bytebpos (struct buffer *buf, Membpos x) | |
700 ) | |
701 { | |
702 Bytebpos retval; | |
703 text_checking_assert (valid_membpos_p (buf, x)); | |
704 retval = (Bytebpos) ((x > (Membpos) buf->text->gpt) ? | |
705 x - buf->text->gap_size : | |
706 x); | |
707 ASSERT_VALID_BYTEBPOS_UNSAFE (buf, retval); | |
708 return retval; | |
709 } | |
710 | |
711 DECLARE_INLINE_HEADER ( | |
712 Charbpos | |
713 membpos_to_charbpos (struct buffer *buf, Membpos x) | |
714 ) | |
715 { | |
716 return bytebpos_to_charbpos (buf, membpos_to_bytebpos (buf, x)); | |
717 } | |
718 | |
719 DECLARE_INLINE_HEADER ( | |
720 Membpos | |
721 charbpos_to_membpos (struct buffer *buf, Charbpos x) | |
722 ) | |
723 { | |
724 return bytebpos_to_membpos (buf, charbpos_to_bytebpos (buf, x)); | |
725 } | |
726 | |
727 /*----------------------------------------------------------------------*/ | |
728 /* Generalized buffer/string position convertors */ | |
729 /*----------------------------------------------------------------------*/ | |
730 | |
731 /* These macros generalize many standard buffer-position functions to | |
732 either a buffer or a string. */ | |
733 | |
734 /* Converting between Memxpos's and Bytexpos's, for a buffer-or-string. | |
735 For strings, this is a no-op. For buffers, this resolves | |
736 to the standard membpos<->bytebpos converters. */ | |
737 | |
738 DECLARE_INLINE_HEADER ( | |
739 Memxpos buffer_or_string_bytexpos_to_memxpos (Lisp_Object obj, Bytexpos pos) | |
740 ) | |
741 { | |
742 return (BUFFERP (obj) ? bytebpos_to_membpos (XBUFFER (obj), pos) : | |
743 (Memxpos) pos); | |
744 } | |
745 | |
746 DECLARE_INLINE_HEADER ( | |
747 Bytexpos buffer_or_string_memxpos_to_bytexpos (Lisp_Object obj, Memxpos pos) | |
748 ) | |
749 { | |
750 return (BUFFERP (obj) ? membpos_to_bytebpos (XBUFFER (obj), pos) : | |
751 (Bytexpos) pos); | |
752 } | |
753 | |
754 /* Converting between Charxpos's and Bytexpos's, for a buffer-or-string. | |
755 For strings, this maps to the bytecount<->charcount converters. */ | |
756 | |
757 DECLARE_INLINE_HEADER ( | |
758 Bytexpos buffer_or_string_charxpos_to_bytexpos (Lisp_Object obj, Charxpos pos) | |
759 ) | |
760 { | |
761 return (BUFFERP (obj) ? charbpos_to_bytebpos (XBUFFER (obj), pos) : | |
762 (Bytexpos) string_index_char_to_byte (obj, pos)); | |
763 } | |
764 | |
765 DECLARE_INLINE_HEADER ( | |
766 Charxpos buffer_or_string_bytexpos_to_charxpos (Lisp_Object obj, Bytexpos pos) | |
767 ) | |
768 { | |
769 return (BUFFERP (obj) ? bytebpos_to_charbpos (XBUFFER (obj), pos) : | |
770 (Charxpos) string_index_byte_to_char (obj, pos)); | |
771 } | |
772 | |
773 /* Similar for Charxpos's and Memxpos's. */ | |
774 | |
775 DECLARE_INLINE_HEADER ( | |
776 Memxpos buffer_or_string_charxpos_to_memxpos (Lisp_Object obj, Charxpos pos) | |
777 ) | |
778 { | |
779 return (BUFFERP (obj) ? charbpos_to_membpos (XBUFFER (obj), pos) : | |
780 (Memxpos) string_index_char_to_byte (obj, pos)); | |
781 } | |
782 | |
783 DECLARE_INLINE_HEADER ( | |
784 Charxpos buffer_or_string_memxpos_to_charxpos (Lisp_Object obj, Memxpos pos) | |
785 ) | |
786 { | |
787 return (BUFFERP (obj) ? membpos_to_charbpos (XBUFFER (obj), pos) : | |
788 (Charxpos) string_index_byte_to_char (obj, pos)); | |
789 } | |
790 | |
791 DECLARE_INLINE_HEADER ( | |
792 Internal_Format buffer_or_other_internal_format (Lisp_Object obj) | |
793 ) | |
794 { | |
795 return BUFFERP (obj) ? BUF_FORMAT (XBUFFER (obj)) : FORMAT_DEFAULT; | |
796 } | |
797 | |
798 /* Return the index to the character before the one at X, | |
799 in a buffer or string. */ | |
800 | |
801 DECLARE_INLINE_HEADER ( | |
802 Bytebpos | |
803 prev_bytexpos (Lisp_Object obj, Bytebpos x) | |
804 ) | |
805 { | |
806 return BUFFERP (obj) ? prev_bytebpos (XBUFFER (obj), x) : | |
807 prev_string_index (obj, x); | |
808 } | |
809 | |
810 /* Return the index to the character after the one at X, | |
811 in a buffer or string. */ | |
812 | |
813 DECLARE_INLINE_HEADER ( | |
814 Bytebpos | |
815 next_bytexpos (Lisp_Object obj, Bytebpos x) | |
816 ) | |
817 { | |
818 return BUFFERP (obj) ? next_bytebpos (XBUFFER (obj), x) : | |
819 next_string_index (obj, x); | |
820 } | |
821 | |
822 /*----------------------------------------------------------------------*/ | |
823 /* Converting between positions and addresses */ | |
824 /*----------------------------------------------------------------------*/ | |
825 | |
826 /* Convert the address of a byte in the buffer into a position. */ | |
827 DECLARE_INLINE_HEADER ( | |
828 Bytebpos | |
829 BYTE_BUF_PTR_BYTE_POS (struct buffer *buf, Intbyte *ptr) | |
830 ) | |
831 { | |
832 Bytebpos retval = (ptr - buf->text->beg + 1 | |
833 - ((ptr - buf->text->beg + 1) > buf->text->gpt | |
834 ? buf->text->gap_size : (Bytebpos) 0)); | |
835 ASSERT_VALID_BYTEBPOS_UNSAFE (buf, retval); | |
836 return retval; | |
837 } | |
838 | |
839 #define BUF_PTR_BYTE_POS(buf, ptr) \ | |
840 bytebpos_to_charbpos (buf, BYTE_BUF_PTR_BYTE_POS (buf, ptr)) | |
841 | |
842 /* Address of byte at position POS in buffer. */ | |
843 DECLARE_INLINE_HEADER ( | |
844 Intbyte * | |
845 BYTE_BUF_BYTE_ADDRESS (struct buffer *buf, Bytebpos pos) | |
846 ) | |
847 { | |
848 ASSERT_VALID_BYTEBPOS_UNSAFE (buf, pos); | |
849 return BYTE_BUF_BYTE_ADDRESS_NO_VERIFY (buf, pos); | |
850 } | |
851 | |
852 #define BUF_BYTE_ADDRESS(buf, pos) \ | |
853 BYTE_BUF_BYTE_ADDRESS (buf, charbpos_to_bytebpos (buf, pos)) | |
854 | |
855 /* Address of byte before position POS in buffer. */ | |
856 DECLARE_INLINE_HEADER ( | |
857 Intbyte * | |
858 BYTE_BUF_BYTE_ADDRESS_BEFORE (struct buffer *buf, Bytebpos pos) | |
859 ) | |
860 { | |
861 ASSERT_VALID_BYTEBPOS_UNSAFE (buf, pos); | |
862 return (buf->text->beg + | |
863 ((pos > buf->text->gpt ? (pos + buf->text->gap_size) : pos) | |
864 - 2)); | |
865 } | |
866 | |
867 #define BUF_BYTE_ADDRESS_BEFORE(buf, pos) \ | |
868 BYTE_BUF_BYTE_ADDRESS_BEFORE (buf, charbpos_to_bytebpos (buf, pos)) | |
869 | |
870 /*----------------------------------------------------------------------*/ | |
722 /* Converting between buffer bytes and Emacs characters */ | 871 /* Converting between buffer bytes and Emacs characters */ |
723 /*----------------------------------------------------------------------*/ | 872 /*----------------------------------------------------------------------*/ |
724 | 873 |
725 /* The character at position POS in buffer. */ | 874 /* The character at position POS in buffer. */ |
726 #define BI_BUF_FETCH_CHAR(buf, pos) \ | 875 |
727 charptr_emchar (BI_BUF_BYTE_ADDRESS (buf, pos)) | 876 #define BYTE_BUF_FETCH_CHAR(buf, pos) \ |
877 charptr_emchar_fmt (BYTE_BUF_BYTE_ADDRESS (buf, pos), BUF_FORMAT (buf), \ | |
878 wrap_buffer (buf)) | |
728 #define BUF_FETCH_CHAR(buf, pos) \ | 879 #define BUF_FETCH_CHAR(buf, pos) \ |
729 BI_BUF_FETCH_CHAR (buf, charbpos_to_bytebpos (buf, pos)) | 880 BYTE_BUF_FETCH_CHAR (buf, charbpos_to_bytebpos (buf, pos)) |
881 | |
882 /* The "raw value" of the character at position POS in buffer. | |
883 See emchar_to_raw(). */ | |
884 | |
885 #define BYTE_BUF_FETCH_CHAR_RAW(buf, pos) \ | |
886 charptr_emchar_raw_fmt (BYTE_BUF_BYTE_ADDRESS (buf, pos), BUF_FORMAT (buf)) | |
887 #define BUF_FETCH_CHAR_RAW(buf, pos) \ | |
888 BYTE_BUF_FETCH_CHAR_RAW (buf, charbpos_to_bytebpos (buf, pos)) | |
730 | 889 |
731 /* The character at position POS in buffer, as a string. This is | 890 /* The character at position POS in buffer, as a string. This is |
732 equivalent to set_charptr_emchar (str, BUF_FETCH_CHAR (buf, pos)) | 891 equivalent to set_charptr_emchar (str, BUF_FETCH_CHAR (buf, pos)) |
733 but is faster for Mule. */ | 892 but is faster for Mule. */ |
734 | 893 |
735 # define BI_BUF_CHARPTR_COPY_CHAR(buf, pos, str) \ | 894 # define BYTE_BUF_CHARPTR_COPY_EMCHAR(buf, pos, str) \ |
736 charptr_copy_char (BI_BUF_BYTE_ADDRESS (buf, pos), str) | 895 (BUF_FORMAT (buf) == FORMAT_DEFAULT ? \ |
737 #define BUF_CHARPTR_COPY_CHAR(buf, pos, str) \ | 896 charptr_copy_emchar (BYTE_BUF_BYTE_ADDRESS (buf, pos), str) : \ |
738 BI_BUF_CHARPTR_COPY_CHAR (buf, charbpos_to_bytebpos (buf, pos), str) | 897 set_charptr_emchar (str, BYTE_BUF_FETCH_CHAR (buf, pos))) |
898 #define BUF_CHARPTR_COPY_EMCHAR(buf, pos, str) \ | |
899 BYTE_BUF_CHARPTR_COPY_EMCHAR (buf, charbpos_to_bytebpos (buf, pos), str) | |
739 | 900 |
740 | 901 |
741 /************************************************************************/ | 902 /************************************************************************/ |
742 /* */ | 903 /* */ |
743 /* higher-level buffer-position functions */ | 904 /* higher-level buffer-position functions */ |
747 /*----------------------------------------------------------------------*/ | 908 /*----------------------------------------------------------------------*/ |
748 /* Settor macros for important positions in a buffer */ | 909 /* Settor macros for important positions in a buffer */ |
749 /*----------------------------------------------------------------------*/ | 910 /*----------------------------------------------------------------------*/ |
750 | 911 |
751 /* Set beginning of accessible range of buffer. */ | 912 /* Set beginning of accessible range of buffer. */ |
752 #define SET_BOTH_BUF_BEGV(buf, val, bival) \ | 913 #define SET_BOTH_BUF_BEGV(buf, val, bpval) \ |
753 do \ | 914 do \ |
754 { \ | 915 { \ |
755 (buf)->begv = (bival); \ | 916 (buf)->begv = (bpval); \ |
756 (buf)->bufbegv = (val); \ | 917 (buf)->bufbegv = (val); \ |
757 } while (0) | 918 } while (0) |
758 | 919 |
759 /* Set end of accessible range of buffer. */ | 920 /* Set end of accessible range of buffer. */ |
760 #define SET_BOTH_BUF_ZV(buf, val, bival) \ | 921 #define SET_BOTH_BUF_ZV(buf, val, bpval) \ |
761 do \ | 922 do \ |
762 { \ | 923 { \ |
763 (buf)->zv = (bival); \ | 924 (buf)->zv = (bpval); \ |
764 (buf)->bufzv = (val); \ | 925 (buf)->bufzv = (val); \ |
765 } while (0) | 926 } while (0) |
766 | 927 |
767 /* Set point. */ | 928 /* Set point. */ |
768 /* Since BEGV and ZV are almost never set, it's reasonable to enforce | 929 /* Since BEGV and ZV are almost never set, it's reasonable to enforce |
769 the restriction that the Charbpos and Bytebpos values must both be | 930 the restriction that the Charbpos and Bytebpos values must both be |
770 specified. However, point is set in lots and lots of places. So | 931 specified. However, point is set in lots and lots of places. So |
771 we provide the ability to specify both (for efficiency) or just | 932 we provide the ability to specify both (for efficiency) or just |
772 one. */ | 933 one. */ |
773 #define BOTH_BUF_SET_PT(buf, val, bival) set_buffer_point (buf, val, bival) | 934 #define BOTH_BUF_SET_PT(buf, val, bpval) set_buffer_point (buf, val, bpval) |
774 #define BI_BUF_SET_PT(buf, bival) \ | 935 #define BYTE_BUF_SET_PT(buf, bpval) \ |
775 BOTH_BUF_SET_PT (buf, bytebpos_to_charbpos (buf, bival), bival) | 936 do \ |
776 #define BUF_SET_PT(buf, value) \ | 937 { \ |
777 BOTH_BUF_SET_PT (buf, value, charbpos_to_bytebpos (buf, value)) | 938 Bytebpos __bpbsp_bpval = (bpval); \ |
939 BOTH_BUF_SET_PT (buf, bytebpos_to_charbpos (buf, __bpbsp_bpval), \ | |
940 __bpbsp_bpval); \ | |
941 } while (0) | |
942 #define BUF_SET_PT(buf, value) \ | |
943 do \ | |
944 { \ | |
945 Bytebpos __bsp_val = (value); \ | |
946 BOTH_BUF_SET_PT (buf, __bsp_val, charbpos_to_bytebpos (buf, __bsp_val)); \ | |
947 } while (0) | |
778 | 948 |
779 | 949 |
780 #if 0 /* FSFmacs */ | 950 #if 0 /* FSFmacs */ |
781 /* These macros exist in FSFmacs because SET_PT() in FSFmacs incorrectly | 951 /* These macros exist in FSFmacs because SET_PT() in FSFmacs incorrectly |
782 does too much stuff, such as moving out of invisible extents. */ | 952 does too much stuff, such as moving out of invisible extents. */ |
791 /* Number of characters in buffer */ | 961 /* Number of characters in buffer */ |
792 #define BUF_SIZE(buf) (BUF_Z (buf) - BUF_BEG (buf)) | 962 #define BUF_SIZE(buf) (BUF_Z (buf) - BUF_BEG (buf)) |
793 | 963 |
794 /* Is this buffer narrowed? */ | 964 /* Is this buffer narrowed? */ |
795 #define BUF_NARROWED(buf) \ | 965 #define BUF_NARROWED(buf) \ |
796 ((BI_BUF_BEGV (buf) != BI_BUF_BEG (buf)) || \ | 966 ((BYTE_BUF_BEGV (buf) != BYTE_BUF_BEG (buf)) || \ |
797 (BI_BUF_ZV (buf) != BI_BUF_Z (buf))) | 967 (BYTE_BUF_ZV (buf) != BYTE_BUF_Z (buf))) |
798 | 968 |
799 /* Modification count. */ | 969 /* Modification count */ |
800 #define BUF_MODIFF(buf) ((buf)->text->modiff) | 970 #define BUF_MODIFF(buf) ((buf)->text->modiff) |
801 | 971 |
802 /* Saved modification count. */ | 972 /* Saved modification count */ |
803 #define BUF_SAVE_MODIFF(buf) ((buf)->text->save_modiff) | 973 #define BUF_SAVE_MODIFF(buf) ((buf)->text->save_modiff) |
804 | 974 |
805 /* Face changed. */ | 975 /* Face changed. */ |
806 #define BUF_FACECHANGE(buf) ((buf)->face_change) | 976 #define BUF_FACECHANGE(buf) ((buf)->face_change) |
807 | 977 |
808 #define POINT_MARKER_P(marker) \ | 978 DECLARE_INLINE_HEADER ( |
809 (XMARKER (marker)->buffer != 0 && \ | 979 int |
810 EQ (marker, XMARKER (marker)->buffer->point_marker)) | 980 POINT_MARKER_P (Lisp_Object marker) |
981 ) | |
982 { | |
983 return (XMARKER (marker)->buffer != 0 && | |
984 EQ (marker, XMARKER (marker)->buffer->point_marker)); | |
985 } | |
811 | 986 |
812 #define BUF_MARKERS(buf) ((buf)->markers) | 987 #define BUF_MARKERS(buf) ((buf)->markers) |
988 | |
989 #ifdef MULE | |
990 | |
991 DECLARE_INLINE_HEADER ( | |
992 Lisp_Object | |
993 BUFFER_CATEGORY_TABLE (struct buffer *buf) | |
994 ) | |
995 { | |
996 return buf ? buf->category_table : Vstandard_category_table; | |
997 } | |
998 | |
999 #endif /* MULE */ | |
1000 | |
1001 DECLARE_INLINE_HEADER ( | |
1002 Lisp_Object | |
1003 BUFFER_SYNTAX_TABLE (struct buffer *buf) | |
1004 ) | |
1005 { | |
1006 return buf ? buf->syntax_table : Vstandard_syntax_table; | |
1007 } | |
1008 | |
1009 DECLARE_INLINE_HEADER ( | |
1010 Lisp_Object | |
1011 BUFFER_MIRROR_SYNTAX_TABLE (struct buffer *buf) | |
1012 ) | |
1013 { | |
1014 return buf ? buf->mirror_syntax_table : | |
1015 XCHAR_TABLE (Vstandard_syntax_table)->mirror_table; | |
1016 } | |
813 | 1017 |
814 /* WARNING: | 1018 /* WARNING: |
815 | 1019 |
816 The new definitions of CEILING_OF() and FLOOR_OF() differ semantically | 1020 The new definitions of CEILING_OF() and FLOOR_OF() differ semantically |
817 from the old ones (in FSF Emacs and XEmacs 19.11 and before). | 1021 from the old ones (in FSF Emacs and XEmacs 19.11 and before). |
818 Conversion is as follows: | 1022 Conversion is as follows: |
819 | 1023 |
820 OLD_BI_CEILING_OF(n) = NEW_BI_CEILING_OF(n) - 1 | 1024 OLD_BYTE_CEILING_OF(n) = NEW_BYTE_CEILING_OF(n) - 1 |
821 OLD_BI_FLOOR_OF(n) = NEW_BI_FLOOR_OF(n + 1) | 1025 OLD_BYTE_FLOOR_OF(n) = NEW_BYTE_FLOOR_OF(n + 1) |
822 | 1026 |
823 The definitions were changed because the new definitions are more | 1027 The definitions were changed because the new definitions are more |
824 consistent with the way everything else works in XEmacs. | 1028 consistent with the way everything else works in XEmacs. |
825 */ | 1029 */ |
826 | 1030 |
827 /* Properties of CEILING_OF and FLOOR_OF (also apply to BI_ variants): | 1031 /* Properties of CEILING_OF and FLOOR_OF (also apply to BYTE_ variants): |
828 | 1032 |
829 1) FLOOR_OF (CEILING_OF (n)) = n | 1033 1) FLOOR_OF (CEILING_OF (n)) = n |
830 CEILING_OF (FLOOR_OF (n)) = n | 1034 CEILING_OF (FLOOR_OF (n)) = n |
831 | 1035 |
832 2) CEILING_OF (n) = n if and only if n = ZV | 1036 2) CEILING_OF (n) = n if and only if n = ZV |
851 { | 1055 { |
852 Bytebpos pos = from; | 1056 Bytebpos pos = from; |
853 | 1057 |
854 while (pos < to) | 1058 while (pos < to) |
855 { | 1059 { |
856 Bytebpos ceil; | 1060 Bytebpos ceil = BYTE_BUF_CEILING_OF (buf, pos); |
857 | |
858 ceil = BI_BUF_CEILING_OF (buf, pos); | |
859 ceil = min (to, ceil); | 1061 ceil = min (to, ceil); |
860 process_intbyte_string (BI_BUF_BYTE_ADDRESS (buf, pos), ceil - pos); | 1062 process_intbyte_string (BYTE_BUF_BYTE_ADDRESS (buf, pos), ceil - pos); |
861 pos = ceil; | 1063 pos = ceil; |
862 } | 1064 } |
863 } | 1065 } |
864 | 1066 |
865 Currently there will be at most two iterations in the loop, but it is | 1067 Currently there will be at most two iterations in the loop, but it is |
866 written in such a way that it will still work if the buffer | 1068 written in such a way that it will still work if the buffer |
867 representation is changed to have multiple gaps in it. | 1069 representation is changed to have multiple gaps in it. |
868 */ | 1070 */ |
869 | 1071 |
870 | 1072 |
871 /* Return the maximum index in the buffer it is safe to scan forwards | 1073 /* Return the maximum position in the buffer it is safe to scan forwards |
872 past N to. This is used to prevent buffer scans from running into | 1074 past N to. This is used to prevent buffer scans from running into |
873 the gap (e.g. search.c). All characters between N and CEILING_OF(N) | 1075 the gap (e.g. search.c). All characters between N and CEILING_OF(N) |
874 are located contiguous in memory. Note that the character *at* | 1076 are located contiguous in memory. Note that the character *at* |
875 CEILING_OF(N) is not contiguous in memory. */ | 1077 CEILING_OF(N) is not contiguous in memory. */ |
876 #define BI_BUF_CEILING_OF(b, n) \ | 1078 #define BYTE_BUF_CEILING_OF(b, n) \ |
877 ((n) < (b)->text->gpt && (b)->text->gpt < BI_BUF_ZV (b) ? \ | 1079 ((n) < (b)->text->gpt && (b)->text->gpt < BYTE_BUF_ZV (b) ? \ |
878 (b)->text->gpt : BI_BUF_ZV (b)) | 1080 (b)->text->gpt : BYTE_BUF_ZV (b)) |
879 #define BUF_CEILING_OF(b, n) \ | 1081 #define BUF_CEILING_OF(b, n) \ |
880 bytebpos_to_charbpos (b, BI_BUF_CEILING_OF (b, charbpos_to_bytebpos (b, n))) | 1082 bytebpos_to_charbpos (b, BYTE_BUF_CEILING_OF (b, charbpos_to_bytebpos (b, n))) |
881 | 1083 |
882 /* Return the minimum index in the buffer it is safe to scan backwards | 1084 /* Return the minimum position in the buffer it is safe to scan backwards |
883 past N to. All characters between FLOOR_OF(N) and N are located | 1085 past N to. All characters between FLOOR_OF(N) and N are located |
884 contiguous in memory. Note that the character *at* N may not be | 1086 contiguous in memory. Note that the character *at* N may not be |
885 contiguous in memory. */ | 1087 contiguous in memory. */ |
886 #define BI_BUF_FLOOR_OF(b, n) \ | 1088 #define BYTE_BUF_FLOOR_OF(b, n) \ |
887 (BI_BUF_BEGV (b) < (b)->text->gpt && (b)->text->gpt < (n) ? \ | 1089 (BYTE_BUF_BEGV (b) < (b)->text->gpt && (b)->text->gpt < (n) ? \ |
888 (b)->text->gpt : BI_BUF_BEGV (b)) | 1090 (b)->text->gpt : BYTE_BUF_BEGV (b)) |
889 #define BUF_FLOOR_OF(b, n) \ | 1091 #define BUF_FLOOR_OF(b, n) \ |
890 bytebpos_to_charbpos (b, BI_BUF_FLOOR_OF (b, charbpos_to_bytebpos (b, n))) | 1092 bytebpos_to_charbpos (b, BYTE_BUF_FLOOR_OF (b, charbpos_to_bytebpos (b, n))) |
891 | 1093 |
892 #define BI_BUF_CEILING_OF_IGNORE_ACCESSIBLE(b, n) \ | 1094 #define BYTE_BUF_CEILING_OF_IGNORE_ACCESSIBLE(b, n) \ |
893 ((n) < (b)->text->gpt && (b)->text->gpt < BI_BUF_Z (b) ? \ | 1095 ((n) < (b)->text->gpt && (b)->text->gpt < BYTE_BUF_Z (b) ? \ |
894 (b)->text->gpt : BI_BUF_Z (b)) | 1096 (b)->text->gpt : BYTE_BUF_Z (b)) |
895 #define BUF_CEILING_OF_IGNORE_ACCESSIBLE(b, n) \ | 1097 #define BUF_CEILING_OF_IGNORE_ACCESSIBLE(b, n) \ |
896 bytebpos_to_charbpos \ | 1098 bytebpos_to_charbpos \ |
897 (b, BI_BUF_CEILING_OF_IGNORE_ACCESSIBLE (b, charbpos_to_bytebpos (b, n))) | 1099 (b, BYTE_BUF_CEILING_OF_IGNORE_ACCESSIBLE (b, charbpos_to_bytebpos (b, n))) |
898 | 1100 |
899 #define BI_BUF_FLOOR_OF_IGNORE_ACCESSIBLE(b, n) \ | 1101 #define BYTE_BUF_FLOOR_OF_IGNORE_ACCESSIBLE(b, n) \ |
900 (BI_BUF_BEG (b) < (b)->text->gpt && (b)->text->gpt < (n) ? \ | 1102 (BYTE_BUF_BEG (b) < (b)->text->gpt && (b)->text->gpt < (n) ? \ |
901 (b)->text->gpt : BI_BUF_BEG (b)) | 1103 (b)->text->gpt : BYTE_BUF_BEG (b)) |
902 #define BUF_FLOOR_OF_IGNORE_ACCESSIBLE(b, n) \ | 1104 #define BUF_FLOOR_OF_IGNORE_ACCESSIBLE(b, n) \ |
903 bytebpos_to_charbpos \ | 1105 bytebpos_to_charbpos \ |
904 (b, BI_BUF_FLOOR_OF_IGNORE_ACCESSIBLE (b, charbpos_to_bytebpos (b, n))) | 1106 (b, BYTE_BUF_FLOOR_OF_IGNORE_ACCESSIBLE (b, charbpos_to_bytebpos (b, n))) |
1107 | |
1108 /* Iterate over contiguous chunks of text in buffer BUF, starting at POS, | |
1109 of length LEN. Evaluates POS and LEN only once, but BUF multiply. In | |
1110 each iteration, store the current chunk into RUNPTR/RUNLEN, which will | |
1111 be automatically declared (don't declare them yourself). This does not | |
1112 respect the limits of accessibility (BUF_BEGV/BUF_ZV); if you want these | |
1113 limits respected, you need to impose them yourself. | |
1114 | |
1115 NOTE: This must be surrounded with braces! */ | |
1116 | |
1117 #define BUFFER_TEXT_LOOP(buf, pos, len, runptr, runlen) \ | |
1118 Intbyte *runptr; \ | |
1119 Bytecount runlen; \ | |
1120 Bytebpos BTL_pos = (pos); \ | |
1121 Bytebpos BTL_len = (len); \ | |
1122 for (runptr = BYTE_BUF_BYTE_ADDRESS (buf, BTL_pos), \ | |
1123 runlen = BYTE_BUF_CEILING_OF_IGNORE_ACCESSIBLE (buf, BTL_pos) - BTL_pos, \ | |
1124 runlen = min (BTL_len, runlen); \ | |
1125 BTL_len > 0; \ | |
1126 BTL_pos += runlen, \ | |
1127 BTL_len -= runlen, \ | |
1128 runptr = BYTE_BUF_BYTE_ADDRESS (buf, BTL_pos), \ | |
1129 runlen = BYTE_BUF_CEILING_OF_IGNORE_ACCESSIBLE (buf, BTL_pos) - BTL_pos, \ | |
1130 runlen = min (BTL_len, runlen)) | |
905 | 1131 |
906 /* This structure marks which slots in a buffer have corresponding | 1132 /* This structure marks which slots in a buffer have corresponding |
907 default values in Vbuffer_defaults. | 1133 default values in Vbuffer_defaults. |
908 Each such slot has a nonzero value in this structure. | 1134 Each such slot has a nonzero value in this structure. |
909 The value has only one nonzero bit. | 1135 The value has only one nonzero bit. |
950 /************************************************************************/ | 1176 /************************************************************************/ |
951 /* Case conversion */ | 1177 /* Case conversion */ |
952 /************************************************************************/ | 1178 /************************************************************************/ |
953 | 1179 |
954 /* A "trt" table is a mapping from characters to other characters, | 1180 /* A "trt" table is a mapping from characters to other characters, |
955 typically used to convert between uppercase and lowercase. For | 1181 typically used to convert between uppercase and lowercase. |
956 compatibility reasons, trt tables are currently in the form of | |
957 a Lisp string of 256 characters, specifying the conversion for each | |
958 of the first 256 Emacs characters (i.e. the 256 Latin-1 characters). | |
959 This should be generalized at some point to support conversions for | |
960 all of the allowable Mule characters. | |
961 */ | 1182 */ |
962 | 1183 |
963 /* The _1 macros are named as such because they assume that you have | 1184 /* The _1 macros are named as such because they assume that you have |
964 already guaranteed that the character values are all in the range | 1185 already guaranteed that the character values are all in the range |
965 0 - 255. Bad lossage will happen otherwise. */ | 1186 0 - 255. Bad lossage will happen otherwise. */ |
966 | 1187 |
967 #define MAKE_TRT_TABLE() Fmake_char_table (Qgeneric) | 1188 #define MAKE_TRT_TABLE() Fmake_char_table (Qgeneric) |
968 INLINE_HEADER Emchar TRT_TABLE_CHAR_1 (Lisp_Object table, Emchar c); | 1189 DECLARE_INLINE_HEADER ( |
969 INLINE_HEADER Emchar | 1190 Emchar |
970 TRT_TABLE_CHAR_1 (Lisp_Object table, Emchar ch) | 1191 TRT_TABLE_OF (Lisp_Object table, Emchar ch) |
1192 ) | |
971 { | 1193 { |
972 Lisp_Object TRT_char; | 1194 Lisp_Object TRT_char; |
973 TRT_char = get_char_table (ch, XCHAR_TABLE (table)); | 1195 TRT_char = get_char_table (ch, table); |
974 if (NILP (TRT_char)) | 1196 if (NILP (TRT_char)) |
975 return ch; | 1197 return ch; |
976 else | 1198 else |
977 return XCHAR (TRT_char); | 1199 return XCHAR (TRT_char); |
978 } | 1200 } |
979 #define SET_TRT_TABLE_CHAR_1(table, ch1, ch2) \ | 1201 #define SET_TRT_TABLE_OF(table, ch1, ch2) \ |
980 Fput_char_table (make_char (ch1), make_char (ch2), table); | 1202 Fput_char_table (make_char (ch1), make_char (ch2), table) |
981 | 1203 |
982 INLINE_HEADER Emchar TRT_TABLE_OF (Lisp_Object trt, Emchar c); | 1204 DECLARE_INLINE_HEADER ( |
983 INLINE_HEADER Emchar | 1205 Lisp_Object |
984 TRT_TABLE_OF (Lisp_Object trt, Emchar c) | |
985 { | |
986 return TRT_TABLE_CHAR_1 (trt, c); | |
987 } | |
988 | |
989 INLINE_HEADER Lisp_Object BUFFER_CASE_TABLE (struct buffer *buf); | |
990 INLINE_HEADER Lisp_Object | |
991 BUFFER_CASE_TABLE (struct buffer *buf) | 1206 BUFFER_CASE_TABLE (struct buffer *buf) |
1207 ) | |
992 { | 1208 { |
993 return buf ? buf->case_table : Vstandard_case_table; | 1209 return buf ? buf->case_table : Vstandard_case_table; |
994 } | 1210 } |
995 | 1211 |
996 /* Macros used below. */ | 1212 /* Macros used below. */ |
999 #define UPCASE_TABLE_OF(buf, c) \ | 1215 #define UPCASE_TABLE_OF(buf, c) \ |
1000 TRT_TABLE_OF (XCASE_TABLE_UPCASE (BUFFER_CASE_TABLE (buf)), c) | 1216 TRT_TABLE_OF (XCASE_TABLE_UPCASE (BUFFER_CASE_TABLE (buf)), c) |
1001 | 1217 |
1002 /* 1 if CH is upper case. */ | 1218 /* 1 if CH is upper case. */ |
1003 | 1219 |
1004 INLINE_HEADER int UPPERCASEP (struct buffer *buf, Emchar ch); | 1220 DECLARE_INLINE_HEADER ( |
1005 INLINE_HEADER int | 1221 int |
1006 UPPERCASEP (struct buffer *buf, Emchar ch) | 1222 UPPERCASEP (struct buffer *buf, Emchar ch) |
1223 ) | |
1007 { | 1224 { |
1008 return DOWNCASE_TABLE_OF (buf, ch) != ch; | 1225 return DOWNCASE_TABLE_OF (buf, ch) != ch; |
1009 } | 1226 } |
1010 | 1227 |
1011 /* 1 if CH is lower case. */ | 1228 /* 1 if CH is lower case. */ |
1012 | 1229 |
1013 INLINE_HEADER int LOWERCASEP (struct buffer *buf, Emchar ch); | 1230 DECLARE_INLINE_HEADER ( |
1014 INLINE_HEADER int | 1231 int |
1015 LOWERCASEP (struct buffer *buf, Emchar ch) | 1232 LOWERCASEP (struct buffer *buf, Emchar ch) |
1233 ) | |
1016 { | 1234 { |
1017 return (UPCASE_TABLE_OF (buf, ch) != ch && | 1235 return (UPCASE_TABLE_OF (buf, ch) != ch && |
1018 DOWNCASE_TABLE_OF (buf, ch) == ch); | 1236 DOWNCASE_TABLE_OF (buf, ch) == ch); |
1019 } | 1237 } |
1020 | 1238 |
1021 /* 1 if CH is neither upper nor lower case. */ | 1239 /* 1 if CH is neither upper nor lower case. */ |
1022 | 1240 |
1023 INLINE_HEADER int NOCASEP (struct buffer *buf, Emchar ch); | 1241 DECLARE_INLINE_HEADER ( |
1024 INLINE_HEADER int | 1242 int |
1025 NOCASEP (struct buffer *buf, Emchar ch) | 1243 NOCASEP (struct buffer *buf, Emchar ch) |
1244 ) | |
1026 { | 1245 { |
1027 return UPCASE_TABLE_OF (buf, ch) == ch; | 1246 return UPCASE_TABLE_OF (buf, ch) == ch; |
1028 } | 1247 } |
1029 | 1248 |
1030 /* Upcase a character, or make no change if that cannot be done. */ | 1249 /* Upcase a character, or make no change if that cannot be done. */ |
1031 | 1250 |
1032 INLINE_HEADER Emchar UPCASE (struct buffer *buf, Emchar ch); | 1251 DECLARE_INLINE_HEADER ( |
1033 INLINE_HEADER Emchar | 1252 Emchar |
1034 UPCASE (struct buffer *buf, Emchar ch) | 1253 UPCASE (struct buffer *buf, Emchar ch) |
1254 ) | |
1035 { | 1255 { |
1036 return (DOWNCASE_TABLE_OF (buf, ch) == ch) ? UPCASE_TABLE_OF (buf, ch) : ch; | 1256 return (DOWNCASE_TABLE_OF (buf, ch) == ch) ? UPCASE_TABLE_OF (buf, ch) : ch; |
1037 } | 1257 } |
1038 | 1258 |
1039 /* Upcase a character known to be not upper case. Unused. */ | 1259 /* Upcase a character known to be not upper case. Unused. */ |