comparison src/buffer.h @ 665:fdefd0186b75

[xemacs-hg @ 2001-09-20 06:28:42 by ben] The great integral types renaming. The purpose of this is to rationalize the names used for various integral types, so that they match their intended uses and follow consist conventions, and eliminate types that were not semantically different from each other. The conventions are: -- All integral types that measure quantities of anything are signed. Some people disagree vociferously with this, but their arguments are mostly theoretical, and are vastly outweighed by the practical headaches of mixing signed and unsigned values, and more importantly by the far increased likelihood of inadvertent bugs: Because of the broken "viral" nature of unsigned quantities in C (operations involving mixed signed/unsigned are done unsigned, when exactly the opposite is nearly always wanted), even a single error in declaring a quantity unsigned that should be signed, or even the even more subtle error of comparing signed and unsigned values and forgetting the necessary cast, can be catastrophic, as comparisons will yield wrong results. -Wsign-compare is turned on specifically to catch this, but this tends to result in a great number of warnings when mixing signed and unsigned, and the casts are annoying. More has been written on this elsewhere. -- All such quantity types just mentioned boil down to EMACS_INT, which is 32 bits on 32-bit machines and 64 bits on 64-bit machines. This is guaranteed to be the same size as Lisp objects of type `int', and (as far as I can tell) of size_t (unsigned!) and ssize_t. The only type below that is not an EMACS_INT is Hashcode, which is an unsigned value of the same size as EMACS_INT. -- Type names should be relatively short (no more than 10 characters or so), with the first letter capitalized and no underscores if they can at all be avoided. -- "count" == a zero-based measurement of some quantity. Includes sizes, offsets, and indexes. -- "bpos" == a one-based measurement of a position in a buffer. "Charbpos" and "Bytebpos" count text in the buffer, rather than bytes in memory; thus Bytebpos does not directly correspond to the memory representation. Use "Membpos" for this. -- "Char" refers to internal-format characters, not to the C type "char", which is really a byte. -- For the actual name changes, see the script below. I ran the following script to do the conversion. (NOTE: This script is idempotent. You can safely run it multiple times and it will not screw up previous results -- in fact, it will do nothing if nothing has changed. Thus, it can be run repeatedly as necessary to handle patches coming in from old workspaces, or old branches.) There are two tags, just before and just after the change: `pre-integral-type-rename' and `post-integral-type-rename'. When merging code from the main trunk into a branch, the best thing to do is first merge up to `pre-integral-type-rename', then apply the script and associated changes, then merge from `post-integral-type-change' to the present. (Alternatively, just do the merging in one operation; but you may then have a lot of conflicts needing to be resolved by hand.) Script `fixtypes.sh' follows: ----------------------------------- cut ------------------------------------ files="*.[ch] s/*.h m/*.h config.h.in ../configure.in Makefile.in.in ../lib-src/*.[ch] ../lwlib/*.[ch]" gr Memory_Count Bytecount $files gr Lstream_Data_Count Bytecount $files gr Element_Count Elemcount $files gr Hash_Code Hashcode $files gr extcount bytecount $files gr bufpos charbpos $files gr bytind bytebpos $files gr memind membpos $files gr bufbyte intbyte $files gr Extcount Bytecount $files gr Bufpos Charbpos $files gr Bytind Bytebpos $files gr Memind Membpos $files gr Bufbyte Intbyte $files gr EXTCOUNT BYTECOUNT $files gr BUFPOS CHARBPOS $files gr BYTIND BYTEBPOS $files gr MEMIND MEMBPOS $files gr BUFBYTE INTBYTE $files gr MEMORY_COUNT BYTECOUNT $files gr LSTREAM_DATA_COUNT BYTECOUNT $files gr ELEMENT_COUNT ELEMCOUNT $files gr HASH_CODE HASHCODE $files ----------------------------------- cut ------------------------------------ `fixtypes.sh' is a Bourne-shell script; it uses 'gr': ----------------------------------- cut ------------------------------------ #!/bin/sh # Usage is like this: # gr FROM TO FILES ... # globally replace FROM with TO in FILES. FROM and TO are regular expressions. # backup files are stored in the `backup' directory. from="$1" to="$2" shift 2 echo ${1+"$@"} | xargs global-replace "s/$from/$to/g" ----------------------------------- cut ------------------------------------ `gr' in turn uses a Perl script to do its real work, `global-replace', which follows: ----------------------------------- cut ------------------------------------ : #-*- Perl -*- ### global-modify --- modify the contents of a file by a Perl expression ## Copyright (C) 1999 Martin Buchholz. ## Copyright (C) 2001 Ben Wing. ## Authors: Martin Buchholz <martin@xemacs.org>, Ben Wing <ben@xemacs.org> ## Maintainer: Ben Wing <ben@xemacs.org> ## Current Version: 1.0, May 5, 2001 # This program is free software; you can redistribute it and/or modify # it under the terms of the GNU General Public License as published by # the Free Software Foundation; either version 2, or (at your option) # any later version. # # This program is distributed in the hope that it will be useful, but # WITHOUT ANY WARRANTY; without even the implied warranty of # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU # General Public License for more details. # # You should have received a copy of the GNU General Public License # along with XEmacs; see the file COPYING. If not, write to the Free # Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA # 02111-1307, USA. eval 'exec perl -w -S $0 ${1+"$@"}' if 0; use strict; use FileHandle; use Carp; use Getopt::Long; use File::Basename; (my $myName = $0) =~ s@.*/@@; my $usage=" Usage: $myName [--help] [--backup-dir=DIR] [--line-mode] [--hunk-mode] PERLEXPR FILE ... Globally modify a file, either line by line or in one big hunk. Typical usage is like this: [with GNU print, GNU xargs: guaranteed to handle spaces, quotes, etc. in file names] find . -name '*.[ch]' -print0 | xargs -0 $0 's/\bCONST\b/const/g'\n [with non-GNU print, xargs] find . -name '*.[ch]' -print | xargs $0 's/\bCONST\b/const/g'\n The file is read in, either line by line (with --line-mode specified) or in one big hunk (with --hunk-mode specified; it's the default), and the Perl expression is then evalled with \$_ set to the line or hunk of text, including the terminating newline if there is one. It should destructively modify the value there, storing the changed result in \$_. Files in which any modifications are made are backed up to the directory specified using --backup-dir, or to `backup' by default. To disable this, use --backup-dir= with no argument. Hunk mode is the default because it is MUCH MUCH faster than line-by-line. Use line-by-line only when it matters, e.g. you want to do a replacement only once per line (the default without the `g' argument). Conversely, when using hunk mode, *ALWAYS* use `g'; otherwise, you will only make one replacement in the entire file! "; my %options = (); $Getopt::Long::ignorecase = 0; &GetOptions ( \%options, 'help', 'backup-dir=s', 'line-mode', 'hunk-mode', ); die $usage if $options{"help"} or @ARGV <= 1; my $code = shift; die $usage if grep (-d || ! -w, @ARGV); sub SafeOpen { open ((my $fh = new FileHandle), $_[0]); confess "Can't open $_[0]: $!" if ! defined $fh; return $fh; } sub SafeClose { close $_[0] or confess "Can't close $_[0]: $!"; } sub FileContents { my $fh = SafeOpen ("< $_[0]"); my $olddollarslash = $/; local $/ = undef; my $contents = <$fh>; $/ = $olddollarslash; return $contents; } sub WriteStringToFile { my $fh = SafeOpen ("> $_[0]"); binmode $fh; print $fh $_[1] or confess "$_[0]: $!\n"; SafeClose $fh; } foreach my $file (@ARGV) { my $changed_p = 0; my $new_contents = ""; if ($options{"line-mode"}) { my $fh = SafeOpen $file; while (<$fh>) { my $save_line = $_; eval $code; $changed_p = 1 if $save_line ne $_; $new_contents .= $_; } } else { my $orig_contents = $_ = FileContents $file; eval $code; if ($_ ne $orig_contents) { $changed_p = 1; $new_contents = $_; } } if ($changed_p) { my $backdir = $options{"backup-dir"}; $backdir = "backup" if !defined ($backdir); if ($backdir) { my ($name, $path, $suffix) = fileparse ($file, ""); my $backfulldir = $path . $backdir; my $backfile = "$backfulldir/$name"; mkdir $backfulldir, 0755 unless -d $backfulldir; print "modifying $file (original saved in $backfile)\n"; rename $file, $backfile; } WriteStringToFile ($file, $new_contents); } } ----------------------------------- cut ------------------------------------ In addition to those programs, I needed to fix up a few other things, particularly relating to the duplicate definitions of types, now that some types merged with others. Specifically: 1. in lisp.h, removed duplicate declarations of Bytecount. The changed code should now look like this: (In each code snippet below, the first and last lines are the same as the original, as are all lines outside of those lines. That allows you to locate the section to be replaced, and replace the stuff in that section, verifying that there isn't anything new added that would need to be kept.) --------------------------------- snip ------------------------------------- /* Counts of bytes or chars */ typedef EMACS_INT Bytecount; typedef EMACS_INT Charcount; /* Counts of elements */ typedef EMACS_INT Elemcount; /* Hash codes */ typedef unsigned long Hashcode; /* ------------------------ dynamic arrays ------------------- */ --------------------------------- snip ------------------------------------- 2. in lstream.h, removed duplicate declaration of Bytecount. Rewrote the comment about this type. The changed code should now look like this: --------------------------------- snip ------------------------------------- #endif /* The have been some arguments over the what the type should be that specifies a count of bytes in a data block to be written out or read in, using Lstream_read(), Lstream_write(), and related functions. Originally it was long, which worked fine; Martin "corrected" these to size_t and ssize_t on the grounds that this is theoretically cleaner and is in keeping with the C standards. Unfortunately, this practice is horribly error-prone due to design flaws in the way that mixed signed/unsigned arithmetic happens. In fact, by doing this change, Martin introduced a subtle but fatal error that caused the operation of sending large mail messages to the SMTP server under Windows to fail. By putting all values back to be signed, avoiding any signed/unsigned mixing, the bug immediately went away. The type then in use was Lstream_Data_Count, so that it be reverted cleanly if a vote came to that. Now it is Bytecount. Some earlier comments about why the type must be signed: This MUST BE SIGNED, since it also is used in functions that return the number of bytes actually read to or written from in an operation, and these functions can return -1 to signal error. Note that the standard Unix read() and write() functions define the count going in as a size_t, which is UNSIGNED, and the count going out as an ssize_t, which is SIGNED. This is a horrible design flaw. Not only is it highly likely to lead to logic errors when a -1 gets interpreted as a large positive number, but operations are bound to fail in all sorts of horrible ways when a number in the upper-half of the size_t range is passed in -- this number is unrepresentable as an ssize_t, so code that checks to see how many bytes are actually written (which is mandatory if you are dealing with certain types of devices) will get completely screwed up. --ben */ typedef enum lstream_buffering --------------------------------- snip ------------------------------------- 3. in dumper.c, there are four places, all inside of switch() statements, where XD_BYTECOUNT appears twice as a case tag. In each case, the two case blocks contain identical code, and you should *REMOVE THE SECOND* and leave the first.
author ben
date Thu, 20 Sep 2001 06:31:11 +0000
parents 704cb139ec6b
children 943eaba38521
comparison
equal deleted inserted replaced
664:6e99cc8c6ca5 665:fdefd0186b75
43 /* */ 43 /* */
44 /* definition of Lisp buffer object */ 44 /* definition of Lisp buffer object */
45 /* */ 45 /* */
46 /************************************************************************/ 46 /************************************************************************/
47 47
48 /* Note: we keep both Bytind and Bufpos versions of some of the 48 /* Note: we keep both Bytebpos and Charbpos versions of some of the
49 important buffer positions because they are accessed so much. 49 important buffer positions because they are accessed so much.
50 If we didn't do this, we would constantly be invalidating the 50 If we didn't do this, we would constantly be invalidating the
51 bufpos<->bytind cache under Mule. 51 charbpos<->bytebpos cache under Mule.
52 52
53 Note that under non-Mule, both versions will always be the 53 Note that under non-Mule, both versions will always be the
54 same so we don't really need to keep track of them. But it 54 same so we don't really need to keep track of them. But it
55 simplifies the logic to go ahead and do so all the time and 55 simplifies the logic to go ahead and do so all the time and
56 the memory loss is insignificant. */ 56 the memory loss is insignificant. */
77 extent-parent and extent-children. 77 extent-parent and extent-children.
78 */ 78 */
79 79
80 struct buffer_text 80 struct buffer_text
81 { 81 {
82 Bufbyte *beg; /* Actual address of buffer contents. */ 82 Intbyte *beg; /* Actual address of buffer contents. */
83 Bytind gpt; /* Index of gap in buffer. */ 83 Bytebpos gpt; /* Index of gap in buffer. */
84 Bytind z; /* Index of end of buffer. */ 84 Bytebpos z; /* Index of end of buffer. */
85 Bufpos bufz; /* Equivalent as a Bufpos. */ 85 Charbpos bufz; /* Equivalent as a Charbpos. */
86 Memory_Count gap_size;/* Size of buffer's gap */ 86 Bytecount gap_size;/* Size of buffer's gap */
87 Memory_Count end_gap_size;/* Size of buffer's end gap */ 87 Bytecount end_gap_size;/* Size of buffer's end gap */
88 long modiff; /* This counts buffer-modification events 88 long modiff; /* This counts buffer-modification events
89 for this buffer. It is incremented for 89 for this buffer. It is incremented for
90 each such event, and never otherwise 90 each such event, and never otherwise
91 changed. */ 91 changed. */
92 long save_modiff; /* Previous value of modiff, as of last 92 long save_modiff; /* Previous value of modiff, as of last
93 time buffer visited or saved a file. */ 93 time buffer visited or saved a file. */
94 94
95 #ifdef MULE 95 #ifdef MULE
96 /* We keep track of a "known" region for very fast access. 96 /* We keep track of a "known" region for very fast access.
97 This information is text-only so it goes here. */ 97 This information is text-only so it goes here. */
98 Bufpos mule_bufmin, mule_bufmax; 98 Charbpos mule_bufmin, mule_bufmax;
99 Bytind mule_bytmin, mule_bytmax; 99 Bytebpos mule_bytmin, mule_bytmax;
100 int mule_shifter, mule_three_p; 100 int mule_shifter, mule_three_p;
101 101
102 /* And we also cache 16 positions for fairly fast access near those 102 /* And we also cache 16 positions for fairly fast access near those
103 positions. */ 103 positions. */
104 Bufpos mule_bufpos_cache[16]; 104 Charbpos mule_charbpos_cache[16];
105 Bytind mule_bytind_cache[16]; 105 Bytebpos mule_bytebpos_cache[16];
106 #endif 106 #endif
107 107
108 /* Similar to the above, we keep track of positions for which line 108 /* Similar to the above, we keep track of positions for which line
109 number has last been calculated. See line-number.c. */ 109 number has last been calculated. See line-number.c. */
110 Lisp_Object line_number_cache; 110 Lisp_Object line_number_cache;
125 /* This points to the `struct buffer_text' that is used for this buffer. 125 /* This points to the `struct buffer_text' that is used for this buffer.
126 In an ordinary buffer, this is the own_text field above. 126 In an ordinary buffer, this is the own_text field above.
127 In an indirect buffer, this is the own_text field of another buffer. */ 127 In an indirect buffer, this is the own_text field of another buffer. */
128 struct buffer_text *text; 128 struct buffer_text *text;
129 129
130 Bytind pt; /* Position of point in buffer. */ 130 Bytebpos pt; /* Position of point in buffer. */
131 Bufpos bufpt; /* Equivalent as a Bufpos. */ 131 Charbpos bufpt; /* Equivalent as a Charbpos. */
132 Bytind begv; /* Index of beginning of accessible range. */ 132 Bytebpos begv; /* Index of beginning of accessible range. */
133 Bufpos bufbegv; /* Equivalent as a Bufpos. */ 133 Charbpos bufbegv; /* Equivalent as a Charbpos. */
134 Bytind zv; /* Index of end of accessible range. */ 134 Bytebpos zv; /* Index of end of accessible range. */
135 Bufpos bufzv; /* Equivalent as a Bufpos. */ 135 Charbpos bufzv; /* Equivalent as a Charbpos. */
136 136
137 int face_change; /* This is set when a change in how the text should 137 int face_change; /* This is set when a change in how the text should
138 be displayed (e.g., font, color) is made. */ 138 be displayed (e.g., font, color) is made. */
139 139
140 /* Whether buffer specific face is specified. */ 140 /* Whether buffer specific face is specified. */
392 /* ---------------------------------------------------------------------- */ 392 /* ---------------------------------------------------------------------- */
393 /* (A) For working with charptr's (pointers to internally-formatted text) */ 393 /* (A) For working with charptr's (pointers to internally-formatted text) */
394 /* ---------------------------------------------------------------------- */ 394 /* ---------------------------------------------------------------------- */
395 395
396 #ifdef MULE 396 #ifdef MULE
397 # define VALID_CHARPTR_P(ptr) BUFBYTE_FIRST_BYTE_P (* (unsigned char *) ptr) 397 # define VALID_CHARPTR_P(ptr) INTBYTE_FIRST_BYTE_P (* (unsigned char *) ptr)
398 #else 398 #else
399 # define VALID_CHARPTR_P(ptr) 1 399 # define VALID_CHARPTR_P(ptr) 1
400 #endif 400 #endif
401 401
402 #ifdef ERROR_CHECK_BUFPOS 402 #ifdef ERROR_CHECK_CHARBPOS
403 # define ASSERT_VALID_CHARPTR(ptr) assert (VALID_CHARPTR_P (ptr)) 403 # define ASSERT_VALID_CHARPTR(ptr) assert (VALID_CHARPTR_P (ptr))
404 #else 404 #else
405 # define ASSERT_VALID_CHARPTR(ptr) 405 # define ASSERT_VALID_CHARPTR(ptr)
406 #endif 406 #endif
407 407
413 the character it's moving over. */ 413 the character it's moving over. */
414 414
415 #define REAL_INC_CHARPTR(ptr) \ 415 #define REAL_INC_CHARPTR(ptr) \
416 ((void) ((ptr) += REP_BYTES_BY_FIRST_BYTE (* (unsigned char *) (ptr)))) 416 ((void) ((ptr) += REP_BYTES_BY_FIRST_BYTE (* (unsigned char *) (ptr))))
417 417
418 #define REAL_INC_CHARBYTIND(ptr, pos) \ 418 #define REAL_INC_CHARBYTEBPOS(ptr, pos) \
419 (pos += REP_BYTES_BY_FIRST_BYTE (* (unsigned char *) (ptr))) 419 (pos += REP_BYTES_BY_FIRST_BYTE (* (unsigned char *) (ptr)))
420 420
421 #define REAL_DEC_CHARPTR(ptr) do { \ 421 #define REAL_DEC_CHARPTR(ptr) do { \
422 (ptr)--; \ 422 (ptr)--; \
423 } while (!VALID_CHARPTR_P (ptr)) 423 } while (!VALID_CHARPTR_P (ptr))
424 424
425 #ifdef ERROR_CHECK_BUFPOS 425 #ifdef ERROR_CHECK_CHARBPOS
426 #define INC_CHARPTR(ptr) do { \ 426 #define INC_CHARPTR(ptr) do { \
427 ASSERT_VALID_CHARPTR (ptr); \ 427 ASSERT_VALID_CHARPTR (ptr); \
428 REAL_INC_CHARPTR (ptr); \ 428 REAL_INC_CHARPTR (ptr); \
429 } while (0) 429 } while (0)
430 430
431 #define INC_CHARBYTIND(ptr, pos) do { \ 431 #define INC_CHARBYTEBPOS(ptr, pos) do { \
432 ASSERT_VALID_CHARPTR (ptr); \ 432 ASSERT_VALID_CHARPTR (ptr); \
433 REAL_INC_CHARBYTIND (ptr, pos); \ 433 REAL_INC_CHARBYTEBPOS (ptr, pos); \
434 } while (0) 434 } while (0)
435 435
436 #define DEC_CHARPTR(ptr) do { \ 436 #define DEC_CHARPTR(ptr) do { \
437 const Bufbyte *dc_ptr1 = (ptr); \ 437 const Intbyte *dc_ptr1 = (ptr); \
438 const Bufbyte *dc_ptr2 = dc_ptr1; \ 438 const Intbyte *dc_ptr2 = dc_ptr1; \
439 REAL_DEC_CHARPTR (dc_ptr2); \ 439 REAL_DEC_CHARPTR (dc_ptr2); \
440 assert (dc_ptr1 - dc_ptr2 == \ 440 assert (dc_ptr1 - dc_ptr2 == \
441 REP_BYTES_BY_FIRST_BYTE (*dc_ptr2)); \ 441 REP_BYTES_BY_FIRST_BYTE (*dc_ptr2)); \
442 (ptr) = (Bufbyte *) dc_ptr2; \ 442 (ptr) = (Intbyte *) dc_ptr2; \
443 } while (0) 443 } while (0)
444 444
445 #else /* ! ERROR_CHECK_BUFPOS */ 445 #else /* ! ERROR_CHECK_CHARBPOS */
446 #define INC_CHARBYTIND(ptr, pos) REAL_INC_CHARBYTIND (ptr, pos) 446 #define INC_CHARBYTEBPOS(ptr, pos) REAL_INC_CHARBYTEBPOS (ptr, pos)
447 #define INC_CHARPTR(ptr) REAL_INC_CHARPTR (ptr) 447 #define INC_CHARPTR(ptr) REAL_INC_CHARPTR (ptr)
448 #define DEC_CHARPTR(ptr) REAL_DEC_CHARPTR (ptr) 448 #define DEC_CHARPTR(ptr) REAL_DEC_CHARPTR (ptr)
449 #endif /* ! ERROR_CHECK_BUFPOS */ 449 #endif /* ! ERROR_CHECK_CHARBPOS */
450 450
451 #ifdef MULE 451 #ifdef MULE
452 452
453 #define VALIDATE_CHARPTR_BACKWARD(ptr) do { \ 453 #define VALIDATE_CHARPTR_BACKWARD(ptr) do { \
454 while (!VALID_CHARPTR_P (ptr)) ptr--; \ 454 while (!VALID_CHARPTR_P (ptr)) ptr--; \
456 456
457 /* This needs to be trickier to avoid the possibility of running off 457 /* This needs to be trickier to avoid the possibility of running off
458 the end of the string. */ 458 the end of the string. */
459 459
460 #define VALIDATE_CHARPTR_FORWARD(ptr) do { \ 460 #define VALIDATE_CHARPTR_FORWARD(ptr) do { \
461 Bufbyte *vcf_ptr = (ptr); \ 461 Intbyte *vcf_ptr = (ptr); \
462 VALIDATE_CHARPTR_BACKWARD (vcf_ptr); \ 462 VALIDATE_CHARPTR_BACKWARD (vcf_ptr); \
463 if (vcf_ptr != (ptr)) \ 463 if (vcf_ptr != (ptr)) \
464 { \ 464 { \
465 (ptr) = vcf_ptr; \ 465 (ptr) = vcf_ptr; \
466 INC_CHARPTR (ptr); \ 466 INC_CHARPTR (ptr); \
475 /* -------------------------------------------------------------- */ 475 /* -------------------------------------------------------------- */
476 /* (B) For working with the length (in bytes and characters) of a */ 476 /* (B) For working with the length (in bytes and characters) of a */
477 /* section of internally-formatted text */ 477 /* section of internally-formatted text */
478 /* -------------------------------------------------------------- */ 478 /* -------------------------------------------------------------- */
479 479
480 INLINE_HEADER const Bufbyte * 480 INLINE_HEADER const Intbyte *
481 charptr_n_addr (const Bufbyte *ptr, Charcount offset); 481 charptr_n_addr (const Intbyte *ptr, Charcount offset);
482 INLINE_HEADER const Bufbyte * 482 INLINE_HEADER const Intbyte *
483 charptr_n_addr (const Bufbyte *ptr, Charcount offset) 483 charptr_n_addr (const Intbyte *ptr, Charcount offset)
484 { 484 {
485 return ptr + charcount_to_bytecount (ptr, offset); 485 return ptr + charcount_to_bytecount (ptr, offset);
486 } 486 }
487 487
488 /* -------------------------------------------------------------------- */ 488 /* -------------------------------------------------------------------- */
489 /* (C) For retrieving or changing the character pointed to by a charptr */ 489 /* (C) For retrieving or changing the character pointed to by a charptr */
490 /* -------------------------------------------------------------------- */ 490 /* -------------------------------------------------------------------- */
491 491
492 #define simple_charptr_emchar(ptr) ((Emchar) (ptr)[0]) 492 #define simple_charptr_emchar(ptr) ((Emchar) (ptr)[0])
493 #define simple_set_charptr_emchar(ptr, x) ((ptr)[0] = (Bufbyte) (x), 1) 493 #define simple_set_charptr_emchar(ptr, x) ((ptr)[0] = (Intbyte) (x), 1)
494 #define simple_charptr_copy_char(ptr, ptr2) ((ptr2)[0] = *(ptr), 1) 494 #define simple_charptr_copy_char(ptr, ptr2) ((ptr2)[0] = *(ptr), 1)
495 495
496 #ifdef MULE 496 #ifdef MULE
497 497
498 Emchar non_ascii_charptr_emchar (const Bufbyte *ptr); 498 Emchar non_ascii_charptr_emchar (const Intbyte *ptr);
499 Bytecount non_ascii_set_charptr_emchar (Bufbyte *ptr, Emchar c); 499 Bytecount non_ascii_set_charptr_emchar (Intbyte *ptr, Emchar c);
500 Bytecount non_ascii_charptr_copy_char (const Bufbyte *src, Bufbyte *dst); 500 Bytecount non_ascii_charptr_copy_char (const Intbyte *src, Intbyte *dst);
501 501
502 INLINE_HEADER Emchar charptr_emchar (const Bufbyte *ptr); 502 INLINE_HEADER Emchar charptr_emchar (const Intbyte *ptr);
503 INLINE_HEADER Emchar 503 INLINE_HEADER Emchar
504 charptr_emchar (const Bufbyte *ptr) 504 charptr_emchar (const Intbyte *ptr)
505 { 505 {
506 return BYTE_ASCII_P (*ptr) ? 506 return BYTE_ASCII_P (*ptr) ?
507 simple_charptr_emchar (ptr) : 507 simple_charptr_emchar (ptr) :
508 non_ascii_charptr_emchar (ptr); 508 non_ascii_charptr_emchar (ptr);
509 } 509 }
510 510
511 INLINE_HEADER Bytecount set_charptr_emchar (Bufbyte *ptr, Emchar x); 511 INLINE_HEADER Bytecount set_charptr_emchar (Intbyte *ptr, Emchar x);
512 INLINE_HEADER Bytecount 512 INLINE_HEADER Bytecount
513 set_charptr_emchar (Bufbyte *ptr, Emchar x) 513 set_charptr_emchar (Intbyte *ptr, Emchar x)
514 { 514 {
515 return !CHAR_MULTIBYTE_P (x) ? 515 return !CHAR_MULTIBYTE_P (x) ?
516 simple_set_charptr_emchar (ptr, x) : 516 simple_set_charptr_emchar (ptr, x) :
517 non_ascii_set_charptr_emchar (ptr, x); 517 non_ascii_set_charptr_emchar (ptr, x);
518 } 518 }
519 519
520 /* Copy the character pointed to by SRC into DST. 520 /* Copy the character pointed to by SRC into DST.
521 Return the number of bytes copied. */ 521 Return the number of bytes copied. */
522 INLINE_HEADER Bytecount 522 INLINE_HEADER Bytecount
523 charptr_copy_char (const Bufbyte *src, Bufbyte *dst); 523 charptr_copy_char (const Intbyte *src, Intbyte *dst);
524 INLINE_HEADER Bytecount 524 INLINE_HEADER Bytecount
525 charptr_copy_char (const Bufbyte *src, Bufbyte *dst) 525 charptr_copy_char (const Intbyte *src, Intbyte *dst)
526 { 526 {
527 return BYTE_ASCII_P (*src) ? 527 return BYTE_ASCII_P (*src) ?
528 simple_charptr_copy_char (src, dst) : 528 simple_charptr_copy_char (src, dst) :
529 non_ascii_charptr_copy_char (src, dst); 529 non_ascii_charptr_copy_char (src, dst);
530 } 530 }
598 598
599 /* None of these are lvalues. Use the settor macros below to change 599 /* None of these are lvalues. Use the settor macros below to change
600 the positions. */ 600 the positions. */
601 601
602 /* Beginning of buffer. */ 602 /* Beginning of buffer. */
603 #define BI_BUF_BEG(buf) ((Bytind) 1) 603 #define BI_BUF_BEG(buf) ((Bytebpos) 1)
604 #define BUF_BEG(buf) ((Bufpos) 1) 604 #define BUF_BEG(buf) ((Charbpos) 1)
605 605
606 /* Beginning of accessible range of buffer. */ 606 /* Beginning of accessible range of buffer. */
607 #define BI_BUF_BEGV(buf) ((buf)->begv + 0) 607 #define BI_BUF_BEGV(buf) ((buf)->begv + 0)
608 #define BUF_BEGV(buf) ((buf)->bufbegv + 0) 608 #define BUF_BEGV(buf) ((buf)->bufbegv + 0)
609 609
622 /*----------------------------------------------------------------------*/ 622 /*----------------------------------------------------------------------*/
623 /* Converting between positions and addresses */ 623 /* Converting between positions and addresses */
624 /*----------------------------------------------------------------------*/ 624 /*----------------------------------------------------------------------*/
625 625
626 /* Convert the address of a byte in the buffer into a position. */ 626 /* Convert the address of a byte in the buffer into a position. */
627 INLINE_HEADER Bytind BI_BUF_PTR_BYTE_POS (struct buffer *buf, Bufbyte *ptr); 627 INLINE_HEADER Bytebpos BI_BUF_PTR_BYTE_POS (struct buffer *buf, Intbyte *ptr);
628 INLINE_HEADER Bytind 628 INLINE_HEADER Bytebpos
629 BI_BUF_PTR_BYTE_POS (struct buffer *buf, Bufbyte *ptr) 629 BI_BUF_PTR_BYTE_POS (struct buffer *buf, Intbyte *ptr)
630 { 630 {
631 return (ptr - buf->text->beg + 1 631 return (ptr - buf->text->beg + 1
632 - ((ptr - buf->text->beg + 1) > buf->text->gpt 632 - ((ptr - buf->text->beg + 1) > buf->text->gpt
633 ? buf->text->gap_size : 0)); 633 ? buf->text->gap_size : 0));
634 } 634 }
635 635
636 #define BUF_PTR_BYTE_POS(buf, ptr) \ 636 #define BUF_PTR_BYTE_POS(buf, ptr) \
637 bytind_to_bufpos (buf, BI_BUF_PTR_BYTE_POS (buf, ptr)) 637 bytebpos_to_charbpos (buf, BI_BUF_PTR_BYTE_POS (buf, ptr))
638 638
639 /* Address of byte at position POS in buffer. */ 639 /* Address of byte at position POS in buffer. */
640 INLINE_HEADER Bufbyte * BI_BUF_BYTE_ADDRESS (struct buffer *buf, Bytind pos); 640 INLINE_HEADER Intbyte * BI_BUF_BYTE_ADDRESS (struct buffer *buf, Bytebpos pos);
641 INLINE_HEADER Bufbyte * 641 INLINE_HEADER Intbyte *
642 BI_BUF_BYTE_ADDRESS (struct buffer *buf, Bytind pos) 642 BI_BUF_BYTE_ADDRESS (struct buffer *buf, Bytebpos pos)
643 { 643 {
644 return (buf->text->beg + 644 return (buf->text->beg +
645 ((pos >= buf->text->gpt ? (pos + buf->text->gap_size) : pos) 645 ((pos >= buf->text->gpt ? (pos + buf->text->gap_size) : pos)
646 - 1)); 646 - 1));
647 } 647 }
648 648
649 #define BUF_BYTE_ADDRESS(buf, pos) \ 649 #define BUF_BYTE_ADDRESS(buf, pos) \
650 BI_BUF_BYTE_ADDRESS (buf, bufpos_to_bytind (buf, pos)) 650 BI_BUF_BYTE_ADDRESS (buf, charbpos_to_bytebpos (buf, pos))
651 651
652 /* Address of byte before position POS in buffer. */ 652 /* Address of byte before position POS in buffer. */
653 INLINE_HEADER Bufbyte * BI_BUF_BYTE_ADDRESS_BEFORE (struct buffer *buf, Bytind pos); 653 INLINE_HEADER Intbyte * BI_BUF_BYTE_ADDRESS_BEFORE (struct buffer *buf, Bytebpos pos);
654 INLINE_HEADER Bufbyte * 654 INLINE_HEADER Intbyte *
655 BI_BUF_BYTE_ADDRESS_BEFORE (struct buffer *buf, Bytind pos) 655 BI_BUF_BYTE_ADDRESS_BEFORE (struct buffer *buf, Bytebpos pos)
656 { 656 {
657 return (buf->text->beg + 657 return (buf->text->beg +
658 ((pos > buf->text->gpt ? (pos + buf->text->gap_size) : pos) 658 ((pos > buf->text->gpt ? (pos + buf->text->gap_size) : pos)
659 - 2)); 659 - 2));
660 } 660 }
661 661
662 #define BUF_BYTE_ADDRESS_BEFORE(buf, pos) \ 662 #define BUF_BYTE_ADDRESS_BEFORE(buf, pos) \
663 BI_BUF_BYTE_ADDRESS_BEFORE (buf, bufpos_to_bytind (buf, pos)) 663 BI_BUF_BYTE_ADDRESS_BEFORE (buf, charbpos_to_bytebpos (buf, pos))
664 664
665 /*----------------------------------------------------------------------*/ 665 /*----------------------------------------------------------------------*/
666 /* Converting between byte indices and memory indices */ 666 /* Converting between byte indices and memory indices */
667 /*----------------------------------------------------------------------*/ 667 /*----------------------------------------------------------------------*/
668 668
669 INLINE_HEADER int valid_memind_p (struct buffer *buf, Memind x); 669 INLINE_HEADER int valid_membpos_p (struct buffer *buf, Membpos x);
670 INLINE_HEADER int 670 INLINE_HEADER int
671 valid_memind_p (struct buffer *buf, Memind x) 671 valid_membpos_p (struct buffer *buf, Membpos x)
672 { 672 {
673 return ((x >= 1 && x <= (Memind) buf->text->gpt) || 673 return ((x >= 1 && x <= (Membpos) buf->text->gpt) ||
674 (x > (Memind) (buf->text->gpt + buf->text->gap_size) && 674 (x > (Membpos) (buf->text->gpt + buf->text->gap_size) &&
675 x <= (Memind) (buf->text->z + buf->text->gap_size))); 675 x <= (Membpos) (buf->text->z + buf->text->gap_size)));
676 } 676 }
677 677
678 INLINE_HEADER Memind bytind_to_memind (struct buffer *buf, Bytind x); 678 INLINE_HEADER Membpos bytebpos_to_membpos (struct buffer *buf, Bytebpos x);
679 INLINE_HEADER Memind 679 INLINE_HEADER Membpos
680 bytind_to_memind (struct buffer *buf, Bytind x) 680 bytebpos_to_membpos (struct buffer *buf, Bytebpos x)
681 { 681 {
682 return (Memind) ((x > buf->text->gpt) ? (x + buf->text->gap_size) : x); 682 return (Membpos) ((x > buf->text->gpt) ? (x + buf->text->gap_size) : x);
683 } 683 }
684 684
685 685
686 INLINE_HEADER Bytind memind_to_bytind (struct buffer *buf, Memind x); 686 INLINE_HEADER Bytebpos membpos_to_bytebpos (struct buffer *buf, Membpos x);
687 INLINE_HEADER Bytind 687 INLINE_HEADER Bytebpos
688 memind_to_bytind (struct buffer *buf, Memind x) 688 membpos_to_bytebpos (struct buffer *buf, Membpos x)
689 { 689 {
690 #ifdef ERROR_CHECK_BUFPOS 690 #ifdef ERROR_CHECK_CHARBPOS
691 assert (valid_memind_p (buf, x)); 691 assert (valid_membpos_p (buf, x));
692 #endif 692 #endif
693 return (Bytind) ((x > (Memind) buf->text->gpt) ? 693 return (Bytebpos) ((x > (Membpos) buf->text->gpt) ?
694 x - buf->text->gap_size : 694 x - buf->text->gap_size :
695 x); 695 x);
696 } 696 }
697 697
698 #define memind_to_bufpos(buf, x) \ 698 #define membpos_to_charbpos(buf, x) \
699 bytind_to_bufpos (buf, memind_to_bytind (buf, x)) 699 bytebpos_to_charbpos (buf, membpos_to_bytebpos (buf, x))
700 #define bufpos_to_memind(buf, x) \ 700 #define charbpos_to_membpos(buf, x) \
701 bytind_to_memind (buf, bufpos_to_bytind (buf, x)) 701 bytebpos_to_membpos (buf, charbpos_to_bytebpos (buf, x))
702 702
703 /* These macros generalize many standard buffer-position functions to 703 /* These macros generalize many standard buffer-position functions to
704 either a buffer or a string. */ 704 either a buffer or a string. */
705 705
706 /* Converting between Meminds and Bytinds, for a buffer-or-string. 706 /* Converting between Membposs and Bytebposs, for a buffer-or-string.
707 For strings, this is a no-op. For buffers, this resolves 707 For strings, this is a no-op. For buffers, this resolves
708 to the standard memind<->bytind converters. */ 708 to the standard membpos<->bytebpos converters. */
709 709
710 #define buffer_or_string_bytind_to_memind(obj, ind) \ 710 #define buffer_or_string_bytebpos_to_membpos(obj, ind) \
711 (BUFFERP (obj) ? bytind_to_memind (XBUFFER (obj), ind) : (Memind) ind) 711 (BUFFERP (obj) ? bytebpos_to_membpos (XBUFFER (obj), ind) : (Membpos) ind)
712 712
713 #define buffer_or_string_memind_to_bytind(obj, ind) \ 713 #define buffer_or_string_membpos_to_bytebpos(obj, ind) \
714 (BUFFERP (obj) ? memind_to_bytind (XBUFFER (obj), ind) : (Bytind) ind) 714 (BUFFERP (obj) ? membpos_to_bytebpos (XBUFFER (obj), ind) : (Bytebpos) ind)
715 715
716 /* Converting between Bufpos's and Bytinds, for a buffer-or-string. 716 /* Converting between Charbpos's and Bytebposs, for a buffer-or-string.
717 For strings, this maps to the bytecount<->charcount converters. */ 717 For strings, this maps to the bytecount<->charcount converters. */
718 718
719 #define buffer_or_string_bufpos_to_bytind(obj, pos) \ 719 #define buffer_or_string_charbpos_to_bytebpos(obj, pos) \
720 (BUFFERP (obj) ? bufpos_to_bytind (XBUFFER (obj), pos) : \ 720 (BUFFERP (obj) ? charbpos_to_bytebpos (XBUFFER (obj), pos) : \
721 (Bytind) charcount_to_bytecount (XSTRING_DATA (obj), pos)) 721 (Bytebpos) charcount_to_bytecount (XSTRING_DATA (obj), pos))
722 722
723 #define buffer_or_string_bytind_to_bufpos(obj, ind) \ 723 #define buffer_or_string_bytebpos_to_charbpos(obj, ind) \
724 (BUFFERP (obj) ? bytind_to_bufpos (XBUFFER (obj), ind) : \ 724 (BUFFERP (obj) ? bytebpos_to_charbpos (XBUFFER (obj), ind) : \
725 (Bufpos) bytecount_to_charcount (XSTRING_DATA (obj), ind)) 725 (Charbpos) bytecount_to_charcount (XSTRING_DATA (obj), ind))
726 726
727 /* Similar for Bufpos's and Meminds. */ 727 /* Similar for Charbpos's and Membposs. */
728 728
729 #define buffer_or_string_bufpos_to_memind(obj, pos) \ 729 #define buffer_or_string_charbpos_to_membpos(obj, pos) \
730 (BUFFERP (obj) ? bufpos_to_memind (XBUFFER (obj), pos) : \ 730 (BUFFERP (obj) ? charbpos_to_membpos (XBUFFER (obj), pos) : \
731 (Memind) charcount_to_bytecount (XSTRING_DATA (obj), pos)) 731 (Membpos) charcount_to_bytecount (XSTRING_DATA (obj), pos))
732 732
733 #define buffer_or_string_memind_to_bufpos(obj, ind) \ 733 #define buffer_or_string_membpos_to_charbpos(obj, ind) \
734 (BUFFERP (obj) ? memind_to_bufpos (XBUFFER (obj), ind) : \ 734 (BUFFERP (obj) ? membpos_to_charbpos (XBUFFER (obj), ind) : \
735 (Bufpos) bytecount_to_charcount (XSTRING_DATA (obj), ind)) 735 (Charbpos) bytecount_to_charcount (XSTRING_DATA (obj), ind))
736 736
737 /************************************************************************/ 737 /************************************************************************/
738 /* */ 738 /* */
739 /* working with buffer-level data */ 739 /* working with buffer-level data */
740 /* */ 740 /* */
743 /* 743 /*
744 744
745 (A) Working with byte indices: 745 (A) Working with byte indices:
746 ------------------------------ 746 ------------------------------
747 747
748 VALID_BYTIND_P(buf, bi): 748 VALID_BYTEBPOS_P(buf, bi):
749 Given a byte index, does it point to the beginning of a character? 749 Given a byte index, does it point to the beginning of a character?
750 750
751 ASSERT_VALID_BYTIND_UNSAFE(buf, bi): 751 ASSERT_VALID_BYTEBPOS_UNSAFE(buf, bi):
752 If error-checking is enabled, assert that the given byte index 752 If error-checking is enabled, assert that the given byte index
753 is within range and points to the beginning of a character 753 is within range and points to the beginning of a character
754 or to the end of the buffer. Otherwise, do nothing. 754 or to the end of the buffer. Otherwise, do nothing.
755 755
756 ASSERT_VALID_BYTIND_BACKWARD_UNSAFE(buf, bi): 756 ASSERT_VALID_BYTEBPOS_BACKWARD_UNSAFE(buf, bi):
757 If error-checking is enabled, assert that the given byte index 757 If error-checking is enabled, assert that the given byte index
758 is within range and satisfies ASSERT_VALID_BYTIND() and also 758 is within range and satisfies ASSERT_VALID_BYTEBPOS() and also
759 does not refer to the beginning of the buffer. (i.e. movement 759 does not refer to the beginning of the buffer. (i.e. movement
760 backwards is OK.) Otherwise, do nothing. 760 backwards is OK.) Otherwise, do nothing.
761 761
762 ASSERT_VALID_BYTIND_FORWARD_UNSAFE(buf, bi): 762 ASSERT_VALID_BYTEBPOS_FORWARD_UNSAFE(buf, bi):
763 If error-checking is enabled, assert that the given byte index 763 If error-checking is enabled, assert that the given byte index
764 is within range and satisfies ASSERT_VALID_BYTIND() and also 764 is within range and satisfies ASSERT_VALID_BYTEBPOS() and also
765 does not refer to the end of the buffer. (i.e. movement 765 does not refer to the end of the buffer. (i.e. movement
766 forwards is OK.) Otherwise, do nothing. 766 forwards is OK.) Otherwise, do nothing.
767 767
768 VALIDATE_BYTIND_BACKWARD(buf, bi): 768 VALIDATE_BYTEBPOS_BACKWARD(buf, bi):
769 Make sure that the given byte index is pointing to the beginning 769 Make sure that the given byte index is pointing to the beginning
770 of a character. If not, back up until this is the case. Note 770 of a character. If not, back up until this is the case. Note
771 that there are not too many places where it is legitimate to do 771 that there are not too many places where it is legitimate to do
772 this sort of thing. It's an error if you're passed an "invalid" 772 this sort of thing. It's an error if you're passed an "invalid"
773 byte index. 773 byte index.
774 774
775 VALIDATE_BYTIND_FORWARD(buf, bi): 775 VALIDATE_BYTEBPOS_FORWARD(buf, bi):
776 Make sure that the given byte index is pointing to the beginning 776 Make sure that the given byte index is pointing to the beginning
777 of a character. If not, move forward until this is the case. 777 of a character. If not, move forward until this is the case.
778 Note that there are not too many places where it is legitimate 778 Note that there are not too many places where it is legitimate
779 to do this sort of thing. It's an error if you're passed an 779 to do this sort of thing. It's an error if you're passed an
780 "invalid" byte index. 780 "invalid" byte index.
781 781
782 INC_BYTIND(buf, bi): 782 INC_BYTEBPOS(buf, bi):
783 Given a byte index (assumed to point at the beginning of a 783 Given a byte index (assumed to point at the beginning of a
784 character), modify that value so it points to the beginning 784 character), modify that value so it points to the beginning
785 of the next character. 785 of the next character.
786 786
787 DEC_BYTIND(buf, bi): 787 DEC_BYTEBPOS(buf, bi):
788 Given a byte index (assumed to point at the beginning of a 788 Given a byte index (assumed to point at the beginning of a
789 character), modify that value so it points to the beginning 789 character), modify that value so it points to the beginning
790 of the previous character. Unlike for DEC_CHARPTR(), we can 790 of the previous character. Unlike for DEC_CHARPTR(), we can
791 do all the assert()s because there are sentinels at the 791 do all the assert()s because there are sentinels at the
792 beginning of the gap and the end of the buffer. 792 beginning of the gap and the end of the buffer.
793 793
794 BYTIND_INVALID: 794 BYTEBPOS_INVALID:
795 A constant representing an invalid Bytind. Valid Bytinds 795 A constant representing an invalid Bytebpos. Valid Bytebposs
796 can never have this value. 796 can never have this value.
797 797
798 798
799 (B) Converting between Bufpos's and Bytinds: 799 (B) Converting between Charbpos's and Bytebposs:
800 -------------------------------------------- 800 --------------------------------------------
801 801
802 bufpos_to_bytind(buf, bu): 802 charbpos_to_bytebpos(buf, bu):
803 Given a Bufpos, return the equivalent Bytind. 803 Given a Charbpos, return the equivalent Bytebpos.
804 804
805 bytind_to_bufpos(buf, bi): 805 bytebpos_to_charbpos(buf, bi):
806 Given a Bytind, return the equivalent Bufpos. 806 Given a Bytebpos, return the equivalent Charbpos.
807 807
808 make_bufpos(buf, bi): 808 make_charbpos(buf, bi):
809 Given a Bytind, return the equivalent Bufpos as a Lisp Object. 809 Given a Bytebpos, return the equivalent Charbpos as a Lisp Object.
810 */ 810 */
811 811
812 812
813 /*----------------------------------------------------------------------*/ 813 /*----------------------------------------------------------------------*/
814 /* working with byte indices */ 814 /* working with byte indices */
815 /*----------------------------------------------------------------------*/ 815 /*----------------------------------------------------------------------*/
816 816
817 #ifdef MULE 817 #ifdef MULE
818 # define VALID_BYTIND_P(buf, x) \ 818 # define VALID_BYTEBPOS_P(buf, x) \
819 BUFBYTE_FIRST_BYTE_P (*BI_BUF_BYTE_ADDRESS (buf, x)) 819 INTBYTE_FIRST_BYTE_P (*BI_BUF_BYTE_ADDRESS (buf, x))
820 #else 820 #else
821 # define VALID_BYTIND_P(buf, x) 1 821 # define VALID_BYTEBPOS_P(buf, x) 1
822 #endif 822 #endif
823 823
824 #ifdef ERROR_CHECK_BUFPOS 824 #ifdef ERROR_CHECK_CHARBPOS
825 825
826 # define ASSERT_VALID_BYTIND_UNSAFE(buf, x) do { \ 826 # define ASSERT_VALID_BYTEBPOS_UNSAFE(buf, x) do { \
827 assert (BUFFER_LIVE_P (buf)); \ 827 assert (BUFFER_LIVE_P (buf)); \
828 assert ((x) >= BI_BUF_BEG (buf) && x <= BI_BUF_Z (buf)); \ 828 assert ((x) >= BI_BUF_BEG (buf) && x <= BI_BUF_Z (buf)); \
829 assert (VALID_BYTIND_P (buf, x)); \ 829 assert (VALID_BYTEBPOS_P (buf, x)); \
830 } while (0) 830 } while (0)
831 # define ASSERT_VALID_BYTIND_BACKWARD_UNSAFE(buf, x) do { \ 831 # define ASSERT_VALID_BYTEBPOS_BACKWARD_UNSAFE(buf, x) do { \
832 assert (BUFFER_LIVE_P (buf)); \ 832 assert (BUFFER_LIVE_P (buf)); \
833 assert ((x) > BI_BUF_BEG (buf) && x <= BI_BUF_Z (buf)); \ 833 assert ((x) > BI_BUF_BEG (buf) && x <= BI_BUF_Z (buf)); \
834 assert (VALID_BYTIND_P (buf, x)); \ 834 assert (VALID_BYTEBPOS_P (buf, x)); \
835 } while (0) 835 } while (0)
836 # define ASSERT_VALID_BYTIND_FORWARD_UNSAFE(buf, x) do { \ 836 # define ASSERT_VALID_BYTEBPOS_FORWARD_UNSAFE(buf, x) do { \
837 assert (BUFFER_LIVE_P (buf)); \ 837 assert (BUFFER_LIVE_P (buf)); \
838 assert ((x) >= BI_BUF_BEG (buf) && x < BI_BUF_Z (buf)); \ 838 assert ((x) >= BI_BUF_BEG (buf) && x < BI_BUF_Z (buf)); \
839 assert (VALID_BYTIND_P (buf, x)); \ 839 assert (VALID_BYTEBPOS_P (buf, x)); \
840 } while (0) 840 } while (0)
841 841
842 #else /* not ERROR_CHECK_BUFPOS */ 842 #else /* not ERROR_CHECK_CHARBPOS */
843 # define ASSERT_VALID_BYTIND_UNSAFE(buf, x) 843 # define ASSERT_VALID_BYTEBPOS_UNSAFE(buf, x)
844 # define ASSERT_VALID_BYTIND_BACKWARD_UNSAFE(buf, x) 844 # define ASSERT_VALID_BYTEBPOS_BACKWARD_UNSAFE(buf, x)
845 # define ASSERT_VALID_BYTIND_FORWARD_UNSAFE(buf, x) 845 # define ASSERT_VALID_BYTEBPOS_FORWARD_UNSAFE(buf, x)
846 846
847 #endif /* not ERROR_CHECK_BUFPOS */ 847 #endif /* not ERROR_CHECK_CHARBPOS */
848 848
849 /* Note that, although the Mule version will work fine for non-Mule 849 /* Note that, although the Mule version will work fine for non-Mule
850 as well (it should reduce down to nothing), we provide a separate 850 as well (it should reduce down to nothing), we provide a separate
851 version to avoid compilation warnings and possible non-optimal 851 version to avoid compilation warnings and possible non-optimal
852 results with stupid compilers. */ 852 results with stupid compilers. */
853 853
854 #ifdef MULE 854 #ifdef MULE
855 # define VALIDATE_BYTIND_BACKWARD(buf, x) do { \ 855 # define VALIDATE_BYTEBPOS_BACKWARD(buf, x) do { \
856 Bufbyte *VBB_ptr = BI_BUF_BYTE_ADDRESS (buf, x); \ 856 Intbyte *VBB_ptr = BI_BUF_BYTE_ADDRESS (buf, x); \
857 while (!BUFBYTE_FIRST_BYTE_P (*VBB_ptr)) \ 857 while (!INTBYTE_FIRST_BYTE_P (*VBB_ptr)) \
858 VBB_ptr--, (x)--; \ 858 VBB_ptr--, (x)--; \
859 } while (0) 859 } while (0)
860 #else 860 #else
861 # define VALIDATE_BYTIND_BACKWARD(buf, x) 861 # define VALIDATE_BYTEBPOS_BACKWARD(buf, x)
862 #endif 862 #endif
863 863
864 /* Note that, although the Mule version will work fine for non-Mule 864 /* Note that, although the Mule version will work fine for non-Mule
865 as well (it should reduce down to nothing), we provide a separate 865 as well (it should reduce down to nothing), we provide a separate
866 version to avoid compilation warnings and possible non-optimal 866 version to avoid compilation warnings and possible non-optimal
867 results with stupid compilers. */ 867 results with stupid compilers. */
868 868
869 #ifdef MULE 869 #ifdef MULE
870 # define VALIDATE_BYTIND_FORWARD(buf, x) do { \ 870 # define VALIDATE_BYTEBPOS_FORWARD(buf, x) do { \
871 Bufbyte *VBF_ptr = BI_BUF_BYTE_ADDRESS (buf, x); \ 871 Intbyte *VBF_ptr = BI_BUF_BYTE_ADDRESS (buf, x); \
872 while (!BUFBYTE_FIRST_BYTE_P (*VBF_ptr)) \ 872 while (!INTBYTE_FIRST_BYTE_P (*VBF_ptr)) \
873 VBF_ptr++, (x)++; \ 873 VBF_ptr++, (x)++; \
874 } while (0) 874 } while (0)
875 #else 875 #else
876 # define VALIDATE_BYTIND_FORWARD(buf, x) 876 # define VALIDATE_BYTEBPOS_FORWARD(buf, x)
877 #endif 877 #endif
878 878
879 /* Note that in the simplest case (no MULE, no ERROR_CHECK_BUFPOS), 879 /* Note that in the simplest case (no MULE, no ERROR_CHECK_CHARBPOS),
880 this crap reduces down to simply (x)++. */ 880 this crap reduces down to simply (x)++. */
881 881
882 #define INC_BYTIND(buf, x) do \ 882 #define INC_BYTEBPOS(buf, x) do \
883 { \ 883 { \
884 ASSERT_VALID_BYTIND_FORWARD_UNSAFE (buf, x); \ 884 ASSERT_VALID_BYTEBPOS_FORWARD_UNSAFE (buf, x); \
885 /* Note that we do the increment first to \ 885 /* Note that we do the increment first to \
886 make sure that the pointer in \ 886 make sure that the pointer in \
887 VALIDATE_BYTIND_FORWARD() ends up on \ 887 VALIDATE_BYTEBPOS_FORWARD() ends up on \
888 the correct side of the gap */ \ 888 the correct side of the gap */ \
889 (x)++; \ 889 (x)++; \
890 VALIDATE_BYTIND_FORWARD (buf, x); \ 890 VALIDATE_BYTEBPOS_FORWARD (buf, x); \
891 } while (0) 891 } while (0)
892 892
893 /* Note that in the simplest case (no MULE, no ERROR_CHECK_BUFPOS), 893 /* Note that in the simplest case (no MULE, no ERROR_CHECK_CHARBPOS),
894 this crap reduces down to simply (x)--. */ 894 this crap reduces down to simply (x)--. */
895 895
896 #define DEC_BYTIND(buf, x) do \ 896 #define DEC_BYTEBPOS(buf, x) do \
897 { \ 897 { \
898 ASSERT_VALID_BYTIND_BACKWARD_UNSAFE (buf, x); \ 898 ASSERT_VALID_BYTEBPOS_BACKWARD_UNSAFE (buf, x); \
899 /* Note that we do the decrement first to \ 899 /* Note that we do the decrement first to \
900 make sure that the pointer in \ 900 make sure that the pointer in \
901 VALIDATE_BYTIND_BACKWARD() ends up on \ 901 VALIDATE_BYTEBPOS_BACKWARD() ends up on \
902 the correct side of the gap */ \ 902 the correct side of the gap */ \
903 (x)--; \ 903 (x)--; \
904 VALIDATE_BYTIND_BACKWARD (buf, x); \ 904 VALIDATE_BYTEBPOS_BACKWARD (buf, x); \
905 } while (0) 905 } while (0)
906 906
907 INLINE_HEADER Bytind prev_bytind (struct buffer *buf, Bytind x); 907 INLINE_HEADER Bytebpos prev_bytebpos (struct buffer *buf, Bytebpos x);
908 INLINE_HEADER Bytind 908 INLINE_HEADER Bytebpos
909 prev_bytind (struct buffer *buf, Bytind x) 909 prev_bytebpos (struct buffer *buf, Bytebpos x)
910 { 910 {
911 DEC_BYTIND (buf, x); 911 DEC_BYTEBPOS (buf, x);
912 return x; 912 return x;
913 } 913 }
914 914
915 INLINE_HEADER Bytind next_bytind (struct buffer *buf, Bytind x); 915 INLINE_HEADER Bytebpos next_bytebpos (struct buffer *buf, Bytebpos x);
916 INLINE_HEADER Bytind 916 INLINE_HEADER Bytebpos
917 next_bytind (struct buffer *buf, Bytind x) 917 next_bytebpos (struct buffer *buf, Bytebpos x)
918 { 918 {
919 INC_BYTIND (buf, x); 919 INC_BYTEBPOS (buf, x);
920 return x; 920 return x;
921 } 921 }
922 922
923 #define BYTIND_INVALID ((Bytind) -1) 923 #define BYTEBPOS_INVALID ((Bytebpos) -1)
924 924
925 /*----------------------------------------------------------------------*/ 925 /*----------------------------------------------------------------------*/
926 /* Converting between buffer positions and byte indices */ 926 /* Converting between buffer positions and byte indices */
927 /*----------------------------------------------------------------------*/ 927 /*----------------------------------------------------------------------*/
928 928
929 #ifdef MULE 929 #ifdef MULE
930 930
931 Bytind bufpos_to_bytind_func (struct buffer *buf, Bufpos x); 931 Bytebpos charbpos_to_bytebpos_func (struct buffer *buf, Charbpos x);
932 Bufpos bytind_to_bufpos_func (struct buffer *buf, Bytind x); 932 Charbpos bytebpos_to_charbpos_func (struct buffer *buf, Bytebpos x);
933 933
934 /* The basic algorithm we use is to keep track of a known region of 934 /* The basic algorithm we use is to keep track of a known region of
935 characters in each buffer, all of which are of the same width. We 935 characters in each buffer, all of which are of the same width. We
936 keep track of the boundaries of the region in both Bufpos and 936 keep track of the boundaries of the region in both Charbpos and
937 Bytind coordinates and also keep track of the char width, which 937 Bytebpos coordinates and also keep track of the char width, which
938 is 1 - 4 bytes. If the position we're translating is not in 938 is 1 - 4 bytes. If the position we're translating is not in
939 the known region, then we invoke a function to update the known 939 the known region, then we invoke a function to update the known
940 region to surround the position in question. This assumes 940 region to surround the position in question. This assumes
941 locality of reference, which is usually the case. 941 locality of reference, which is usually the case.
942 942
945 For the moment, we don't cache any information, and just move 945 For the moment, we don't cache any information, and just move
946 linearly forward or back from the known region, with a few 946 linearly forward or back from the known region, with a few
947 shortcuts to catch all-ASCII buffers. (Note that this will 947 shortcuts to catch all-ASCII buffers. (Note that this will
948 thrash with bad locality of reference.) A smarter method would 948 thrash with bad locality of reference.) A smarter method would
949 be to keep some sort of pseudo-extent layer over the buffer; 949 be to keep some sort of pseudo-extent layer over the buffer;
950 maybe keep track of the bufpos/bytind correspondence at the 950 maybe keep track of the charbpos/bytebpos correspondence at the
951 beginning of each line, which would allow us to do a binary 951 beginning of each line, which would allow us to do a binary
952 search over the pseudo-extents to narrow things down to the 952 search over the pseudo-extents to narrow things down to the
953 correct line, at which point you could use a linear movement 953 correct line, at which point you could use a linear movement
954 method. This would also mesh well with efficiently 954 method. This would also mesh well with efficiently
955 implementing a line-numbering scheme. 955 implementing a line-numbering scheme.
973 64K for width-three characters. 973 64K for width-three characters.
974 */ 974 */
975 975
976 extern short three_to_one_table[]; 976 extern short three_to_one_table[];
977 977
978 INLINE_HEADER int real_bufpos_to_bytind (struct buffer *buf, Bufpos x); 978 INLINE_HEADER int real_charbpos_to_bytebpos (struct buffer *buf, Charbpos x);
979 INLINE_HEADER int 979 INLINE_HEADER int
980 real_bufpos_to_bytind (struct buffer *buf, Bufpos x) 980 real_charbpos_to_bytebpos (struct buffer *buf, Charbpos x)
981 { 981 {
982 if (x >= buf->text->mule_bufmin && x <= buf->text->mule_bufmax) 982 if (x >= buf->text->mule_bufmin && x <= buf->text->mule_bufmax)
983 return (buf->text->mule_bytmin + 983 return (buf->text->mule_bytmin +
984 ((x - buf->text->mule_bufmin) << buf->text->mule_shifter) + 984 ((x - buf->text->mule_bufmin) << buf->text->mule_shifter) +
985 (buf->text->mule_three_p ? (x - buf->text->mule_bufmin) : 0)); 985 (buf->text->mule_three_p ? (x - buf->text->mule_bufmin) : 0));
986 else 986 else
987 return bufpos_to_bytind_func (buf, x); 987 return charbpos_to_bytebpos_func (buf, x);
988 } 988 }
989 989
990 INLINE_HEADER int real_bytind_to_bufpos (struct buffer *buf, Bytind x); 990 INLINE_HEADER int real_bytebpos_to_charbpos (struct buffer *buf, Bytebpos x);
991 INLINE_HEADER int 991 INLINE_HEADER int
992 real_bytind_to_bufpos (struct buffer *buf, Bytind x) 992 real_bytebpos_to_charbpos (struct buffer *buf, Bytebpos x)
993 { 993 {
994 if (x >= buf->text->mule_bytmin && x <= buf->text->mule_bytmax) 994 if (x >= buf->text->mule_bytmin && x <= buf->text->mule_bytmax)
995 return (buf->text->mule_bufmin + 995 return (buf->text->mule_bufmin +
996 ((buf->text->mule_three_p 996 ((buf->text->mule_three_p
997 ? three_to_one_table[x - buf->text->mule_bytmin] 997 ? three_to_one_table[x - buf->text->mule_bytmin]
998 : (x - buf->text->mule_bytmin) >> buf->text->mule_shifter))); 998 : (x - buf->text->mule_bytmin) >> buf->text->mule_shifter)));
999 else 999 else
1000 return bytind_to_bufpos_func (buf, x); 1000 return bytebpos_to_charbpos_func (buf, x);
1001 } 1001 }
1002 1002
1003 #else /* not MULE */ 1003 #else /* not MULE */
1004 1004
1005 # define real_bufpos_to_bytind(buf, x) ((Bytind) x) 1005 # define real_charbpos_to_bytebpos(buf, x) ((Bytebpos) x)
1006 # define real_bytind_to_bufpos(buf, x) ((Bufpos) x) 1006 # define real_bytebpos_to_charbpos(buf, x) ((Charbpos) x)
1007 1007
1008 #endif /* not MULE */ 1008 #endif /* not MULE */
1009 1009
1010 #ifdef ERROR_CHECK_BUFPOS 1010 #ifdef ERROR_CHECK_CHARBPOS
1011 1011
1012 Bytind bufpos_to_bytind (struct buffer *buf, Bufpos x); 1012 Bytebpos charbpos_to_bytebpos (struct buffer *buf, Charbpos x);
1013 Bufpos bytind_to_bufpos (struct buffer *buf, Bytind x); 1013 Charbpos bytebpos_to_charbpos (struct buffer *buf, Bytebpos x);
1014 1014
1015 #else /* not ERROR_CHECK_BUFPOS */ 1015 #else /* not ERROR_CHECK_CHARBPOS */
1016 1016
1017 #define bufpos_to_bytind real_bufpos_to_bytind 1017 #define charbpos_to_bytebpos real_charbpos_to_bytebpos
1018 #define bytind_to_bufpos real_bytind_to_bufpos 1018 #define bytebpos_to_charbpos real_bytebpos_to_charbpos
1019 1019
1020 #endif /* not ERROR_CHECK_BUFPOS */ 1020 #endif /* not ERROR_CHECK_CHARBPOS */
1021 1021
1022 #define make_bufpos(buf, ind) make_int (bytind_to_bufpos (buf, ind)) 1022 #define make_charbpos(buf, ind) make_int (bytebpos_to_charbpos (buf, ind))
1023 1023
1024 /*----------------------------------------------------------------------*/ 1024 /*----------------------------------------------------------------------*/
1025 /* Converting between buffer bytes and Emacs characters */ 1025 /* Converting between buffer bytes and Emacs characters */
1026 /*----------------------------------------------------------------------*/ 1026 /*----------------------------------------------------------------------*/
1027 1027
1028 /* The character at position POS in buffer. */ 1028 /* The character at position POS in buffer. */
1029 #define BI_BUF_FETCH_CHAR(buf, pos) \ 1029 #define BI_BUF_FETCH_CHAR(buf, pos) \
1030 charptr_emchar (BI_BUF_BYTE_ADDRESS (buf, pos)) 1030 charptr_emchar (BI_BUF_BYTE_ADDRESS (buf, pos))
1031 #define BUF_FETCH_CHAR(buf, pos) \ 1031 #define BUF_FETCH_CHAR(buf, pos) \
1032 BI_BUF_FETCH_CHAR (buf, bufpos_to_bytind (buf, pos)) 1032 BI_BUF_FETCH_CHAR (buf, charbpos_to_bytebpos (buf, pos))
1033 1033
1034 /* The character at position POS in buffer, as a string. This is 1034 /* The character at position POS in buffer, as a string. This is
1035 equivalent to set_charptr_emchar (str, BUF_FETCH_CHAR (buf, pos)) 1035 equivalent to set_charptr_emchar (str, BUF_FETCH_CHAR (buf, pos))
1036 but is faster for Mule. */ 1036 but is faster for Mule. */
1037 1037
1038 # define BI_BUF_CHARPTR_COPY_CHAR(buf, pos, str) \ 1038 # define BI_BUF_CHARPTR_COPY_CHAR(buf, pos, str) \
1039 charptr_copy_char (BI_BUF_BYTE_ADDRESS (buf, pos), str) 1039 charptr_copy_char (BI_BUF_BYTE_ADDRESS (buf, pos), str)
1040 #define BUF_CHARPTR_COPY_CHAR(buf, pos, str) \ 1040 #define BUF_CHARPTR_COPY_CHAR(buf, pos, str) \
1041 BI_BUF_CHARPTR_COPY_CHAR (buf, bufpos_to_bytind (buf, pos), str) 1041 BI_BUF_CHARPTR_COPY_CHAR (buf, charbpos_to_bytebpos (buf, pos), str)
1042 1042
1043 1043
1044 /************************************************************************/ 1044 /************************************************************************/
1045 /* */ 1045 /* */
1046 /* Converting between internal and external format */ 1046 /* Converting between internal and external format */
1167 dfc_convert_to_internal_format (a, b, c, d) 1167 dfc_convert_to_internal_format (a, b, c, d)
1168 #endif 1168 #endif
1169 1169
1170 typedef union 1170 typedef union
1171 { 1171 {
1172 struct { const void *ptr; Memory_Count len; } data; 1172 struct { const void *ptr; Bytecount len; } data;
1173 Lisp_Object lisp_object; 1173 Lisp_Object lisp_object;
1174 } dfc_conversion_data; 1174 } dfc_conversion_data;
1175 1175
1176 enum dfc_conversion_type 1176 enum dfc_conversion_type
1177 { 1177 {
1291 void * dfc_sink_ret = xmalloc (dfc_sink.data.len + 1); \ 1291 void * dfc_sink_ret = xmalloc (dfc_sink.data.len + 1); \
1292 memcpy (dfc_sink_ret, dfc_sink.data.ptr, dfc_sink.data.len + 1); \ 1292 memcpy (dfc_sink_ret, dfc_sink.data.ptr, dfc_sink.data.len + 1); \
1293 ((dfc_aliasing_voidpp) &(sink))->p = dfc_sink_ret; \ 1293 ((dfc_aliasing_voidpp) &(sink))->p = dfc_sink_ret; \
1294 } while (0) 1294 } while (0)
1295 #define DFC_LISP_STRING_USE_CONVERTED_DATA(sink) \ 1295 #define DFC_LISP_STRING_USE_CONVERTED_DATA(sink) \
1296 sink = make_string ((Bufbyte *) dfc_sink.data.ptr, dfc_sink.data.len) 1296 sink = make_string ((Intbyte *) dfc_sink.data.ptr, dfc_sink.data.len)
1297 #define DFC_LISP_OPAQUE_USE_CONVERTED_DATA(sink) \ 1297 #define DFC_LISP_OPAQUE_USE_CONVERTED_DATA(sink) \
1298 sink = make_opaque (dfc_sink.data.ptr, dfc_sink.data.len) 1298 sink = make_opaque (dfc_sink.data.ptr, dfc_sink.data.len)
1299 #define DFC_LISP_LSTREAM_USE_CONVERTED_DATA(sink) /* data already used */ 1299 #define DFC_LISP_LSTREAM_USE_CONVERTED_DATA(sink) /* data already used */
1300 #define DFC_LISP_BUFFER_USE_CONVERTED_DATA(sink) \ 1300 #define DFC_LISP_BUFFER_USE_CONVERTED_DATA(sink) \
1301 Lstream_delete (XLSTREAM (dfc_sink.lisp_object)) 1301 Lstream_delete (XLSTREAM (dfc_sink.lisp_object))
1391 (buf)->bufzv = (val); \ 1391 (buf)->bufzv = (val); \
1392 } while (0) 1392 } while (0)
1393 1393
1394 /* Set point. */ 1394 /* Set point. */
1395 /* Since BEGV and ZV are almost never set, it's reasonable to enforce 1395 /* Since BEGV and ZV are almost never set, it's reasonable to enforce
1396 the restriction that the Bufpos and Bytind values must both be 1396 the restriction that the Charbpos and Bytebpos values must both be
1397 specified. However, point is set in lots and lots of places. So 1397 specified. However, point is set in lots and lots of places. So
1398 we provide the ability to specify both (for efficiency) or just 1398 we provide the ability to specify both (for efficiency) or just
1399 one. */ 1399 one. */
1400 #define BOTH_BUF_SET_PT(buf, val, bival) set_buffer_point (buf, val, bival) 1400 #define BOTH_BUF_SET_PT(buf, val, bival) set_buffer_point (buf, val, bival)
1401 #define BI_BUF_SET_PT(buf, bival) \ 1401 #define BI_BUF_SET_PT(buf, bival) \
1402 BOTH_BUF_SET_PT (buf, bytind_to_bufpos (buf, bival), bival) 1402 BOTH_BUF_SET_PT (buf, bytebpos_to_charbpos (buf, bival), bival)
1403 #define BUF_SET_PT(buf, value) \ 1403 #define BUF_SET_PT(buf, value) \
1404 BOTH_BUF_SET_PT (buf, value, bufpos_to_bytind (buf, value)) 1404 BOTH_BUF_SET_PT (buf, value, charbpos_to_bytebpos (buf, value))
1405 1405
1406 1406
1407 #if 0 /* FSFmacs */ 1407 #if 0 /* FSFmacs */
1408 /* These macros exist in FSFmacs because SET_PT() in FSFmacs incorrectly 1408 /* These macros exist in FSFmacs because SET_PT() in FSFmacs incorrectly
1409 does too much stuff, such as moving out of invisible extents. */ 1409 does too much stuff, such as moving out of invisible extents. */
1481 CEILING_OF(N) is not contiguous in memory. */ 1481 CEILING_OF(N) is not contiguous in memory. */
1482 #define BI_BUF_CEILING_OF(b, n) \ 1482 #define BI_BUF_CEILING_OF(b, n) \
1483 ((n) < (b)->text->gpt && (b)->text->gpt < BI_BUF_ZV (b) ? \ 1483 ((n) < (b)->text->gpt && (b)->text->gpt < BI_BUF_ZV (b) ? \
1484 (b)->text->gpt : BI_BUF_ZV (b)) 1484 (b)->text->gpt : BI_BUF_ZV (b))
1485 #define BUF_CEILING_OF(b, n) \ 1485 #define BUF_CEILING_OF(b, n) \
1486 bytind_to_bufpos (b, BI_BUF_CEILING_OF (b, bufpos_to_bytind (b, n))) 1486 bytebpos_to_charbpos (b, BI_BUF_CEILING_OF (b, charbpos_to_bytebpos (b, n)))
1487 1487
1488 /* Return the minimum index in the buffer it is safe to scan backwards 1488 /* Return the minimum index in the buffer it is safe to scan backwards
1489 past N to. All characters between FLOOR_OF(N) and N are located 1489 past N to. All characters between FLOOR_OF(N) and N are located
1490 contiguous in memory. Note that the character *at* N may not be 1490 contiguous in memory. Note that the character *at* N may not be
1491 contiguous in memory. */ 1491 contiguous in memory. */
1492 #define BI_BUF_FLOOR_OF(b, n) \ 1492 #define BI_BUF_FLOOR_OF(b, n) \
1493 (BI_BUF_BEGV (b) < (b)->text->gpt && (b)->text->gpt < (n) ? \ 1493 (BI_BUF_BEGV (b) < (b)->text->gpt && (b)->text->gpt < (n) ? \
1494 (b)->text->gpt : BI_BUF_BEGV (b)) 1494 (b)->text->gpt : BI_BUF_BEGV (b))
1495 #define BUF_FLOOR_OF(b, n) \ 1495 #define BUF_FLOOR_OF(b, n) \
1496 bytind_to_bufpos (b, BI_BUF_FLOOR_OF (b, bufpos_to_bytind (b, n))) 1496 bytebpos_to_charbpos (b, BI_BUF_FLOOR_OF (b, charbpos_to_bytebpos (b, n)))
1497 1497
1498 #define BI_BUF_CEILING_OF_IGNORE_ACCESSIBLE(b, n) \ 1498 #define BI_BUF_CEILING_OF_IGNORE_ACCESSIBLE(b, n) \
1499 ((n) < (b)->text->gpt && (b)->text->gpt < BI_BUF_Z (b) ? \ 1499 ((n) < (b)->text->gpt && (b)->text->gpt < BI_BUF_Z (b) ? \
1500 (b)->text->gpt : BI_BUF_Z (b)) 1500 (b)->text->gpt : BI_BUF_Z (b))
1501 #define BUF_CEILING_OF_IGNORE_ACCESSIBLE(b, n) \ 1501 #define BUF_CEILING_OF_IGNORE_ACCESSIBLE(b, n) \
1502 bytind_to_bufpos \ 1502 bytebpos_to_charbpos \
1503 (b, BI_BUF_CEILING_OF_IGNORE_ACCESSIBLE (b, bufpos_to_bytind (b, n))) 1503 (b, BI_BUF_CEILING_OF_IGNORE_ACCESSIBLE (b, charbpos_to_bytebpos (b, n)))
1504 1504
1505 #define BI_BUF_FLOOR_OF_IGNORE_ACCESSIBLE(b, n) \ 1505 #define BI_BUF_FLOOR_OF_IGNORE_ACCESSIBLE(b, n) \
1506 (BI_BUF_BEG (b) < (b)->text->gpt && (b)->text->gpt < (n) ? \ 1506 (BI_BUF_BEG (b) < (b)->text->gpt && (b)->text->gpt < (n) ? \
1507 (b)->text->gpt : BI_BUF_BEG (b)) 1507 (b)->text->gpt : BI_BUF_BEG (b))
1508 #define BUF_FLOOR_OF_IGNORE_ACCESSIBLE(b, n) \ 1508 #define BUF_FLOOR_OF_IGNORE_ACCESSIBLE(b, n) \
1509 bytind_to_bufpos \ 1509 bytebpos_to_charbpos \
1510 (b, BI_BUF_FLOOR_OF_IGNORE_ACCESSIBLE (b, bufpos_to_bytind (b, n))) 1510 (b, BI_BUF_FLOOR_OF_IGNORE_ACCESSIBLE (b, charbpos_to_bytebpos (b, n)))
1511 1511
1512 1512
1513 extern struct buffer *current_buffer; 1513 extern struct buffer *current_buffer;
1514 1514
1515 /* This is the initial (startup) directory, as used for the *scratch* buffer. 1515 /* This is the initial (startup) directory, as used for the *scratch* buffer.
1564 char *r_alloc (unsigned char **, size_t); 1564 char *r_alloc (unsigned char **, size_t);
1565 char *r_re_alloc (unsigned char **, size_t); 1565 char *r_re_alloc (unsigned char **, size_t);
1566 void r_alloc_free (unsigned char **); 1566 void r_alloc_free (unsigned char **);
1567 1567
1568 #define BUFFER_ALLOC(data, size) \ 1568 #define BUFFER_ALLOC(data, size) \
1569 ((Bufbyte *) r_alloc ((unsigned char **) &data, (size) * sizeof(Bufbyte))) 1569 ((Intbyte *) r_alloc ((unsigned char **) &data, (size) * sizeof(Intbyte)))
1570 #define BUFFER_REALLOC(data, size) \ 1570 #define BUFFER_REALLOC(data, size) \
1571 ((Bufbyte *) r_re_alloc ((unsigned char **) &data, (size) * sizeof(Bufbyte))) 1571 ((Intbyte *) r_re_alloc ((unsigned char **) &data, (size) * sizeof(Intbyte)))
1572 #define BUFFER_FREE(data) r_alloc_free ((unsigned char **) &(data)) 1572 #define BUFFER_FREE(data) r_alloc_free ((unsigned char **) &(data))
1573 #define R_ALLOC_DECLARE(var,data) r_alloc_declare (&(var), data) 1573 #define R_ALLOC_DECLARE(var,data) r_alloc_declare (&(var), data)
1574 1574
1575 #else /* !REL_ALLOC */ 1575 #else /* !REL_ALLOC */
1576 1576
1577 #define BUFFER_ALLOC(data,size)\ 1577 #define BUFFER_ALLOC(data,size)\
1578 (data = xnew_array (Bufbyte, size)) 1578 (data = xnew_array (Intbyte, size))
1579 #define BUFFER_REALLOC(data,size)\ 1579 #define BUFFER_REALLOC(data,size)\
1580 ((Bufbyte *) xrealloc (data, (size) * sizeof(Bufbyte))) 1580 ((Intbyte *) xrealloc (data, (size) * sizeof(Intbyte)))
1581 /* Avoid excess parentheses, or syntax errors may rear their heads. */ 1581 /* Avoid excess parentheses, or syntax errors may rear their heads. */
1582 #define BUFFER_FREE(data) xfree (data) 1582 #define BUFFER_FREE(data) xfree (data)
1583 #define R_ALLOC_DECLARE(var,data) 1583 #define R_ALLOC_DECLARE(var,data)
1584 1584
1585 #endif /* !REL_ALLOC */ 1585 #endif /* !REL_ALLOC */
1588 void set_buffer_internal (struct buffer *b); 1588 void set_buffer_internal (struct buffer *b);
1589 struct buffer *decode_buffer (Lisp_Object buffer, int allow_string); 1589 struct buffer *decode_buffer (Lisp_Object buffer, int allow_string);
1590 1590
1591 /* from editfns.c */ 1591 /* from editfns.c */
1592 void widen_buffer (struct buffer *b, int no_clip); 1592 void widen_buffer (struct buffer *b, int no_clip);
1593 int beginning_of_line_p (struct buffer *b, Bufpos pt); 1593 int beginning_of_line_p (struct buffer *b, Charbpos pt);
1594 1594
1595 /* from insdel.c */ 1595 /* from insdel.c */
1596 void set_buffer_point (struct buffer *buf, Bufpos pos, Bytind bipos); 1596 void set_buffer_point (struct buffer *buf, Charbpos pos, Bytebpos bipos);
1597 void find_charsets_in_bufbyte_string (unsigned char *charsets, 1597 void find_charsets_in_intbyte_string (unsigned char *charsets,
1598 const Bufbyte *str, 1598 const Intbyte *str,
1599 Bytecount len); 1599 Bytecount len);
1600 void find_charsets_in_emchar_string (unsigned char *charsets, 1600 void find_charsets_in_emchar_string (unsigned char *charsets,
1601 const Emchar *str, 1601 const Emchar *str,
1602 Charcount len); 1602 Charcount len);
1603 int bufbyte_string_displayed_columns (const Bufbyte *str, Bytecount len); 1603 int intbyte_string_displayed_columns (const Intbyte *str, Bytecount len);
1604 int emchar_string_displayed_columns (const Emchar *str, Charcount len); 1604 int emchar_string_displayed_columns (const Emchar *str, Charcount len);
1605 void convert_bufbyte_string_into_emchar_dynarr (const Bufbyte *str, 1605 void convert_intbyte_string_into_emchar_dynarr (const Intbyte *str,
1606 Bytecount len, 1606 Bytecount len,
1607 Emchar_dynarr *dyn); 1607 Emchar_dynarr *dyn);
1608 Charcount convert_bufbyte_string_into_emchar_string (const Bufbyte *str, 1608 Charcount convert_intbyte_string_into_emchar_string (const Intbyte *str,
1609 Bytecount len, 1609 Bytecount len,
1610 Emchar *arr); 1610 Emchar *arr);
1611 void convert_emchar_string_into_bufbyte_dynarr (Emchar *arr, int nels, 1611 void convert_emchar_string_into_intbyte_dynarr (Emchar *arr, int nels,
1612 Bufbyte_dynarr *dyn); 1612 Intbyte_dynarr *dyn);
1613 Bufbyte *convert_emchar_string_into_malloced_string (Emchar *arr, int nels, 1613 Intbyte *convert_emchar_string_into_malloced_string (Emchar *arr, int nels,
1614 Bytecount *len_out); 1614 Bytecount *len_out);
1615 /* from marker.c */ 1615 /* from marker.c */
1616 void init_buffer_markers (struct buffer *b); 1616 void init_buffer_markers (struct buffer *b);
1617 void uninit_buffer_markers (struct buffer *b); 1617 void uninit_buffer_markers (struct buffer *b);
1618 1618
1627 #define GB_COERCE_RANGE (1 << 3) 1627 #define GB_COERCE_RANGE (1 << 3)
1628 #define GB_NO_ERROR_IF_BAD (1 << 4) 1628 #define GB_NO_ERROR_IF_BAD (1 << 4)
1629 #define GB_NEGATIVE_FROM_END (1 << 5) 1629 #define GB_NEGATIVE_FROM_END (1 << 5)
1630 #define GB_HISTORICAL_STRING_BEHAVIOR (GB_NEGATIVE_FROM_END | GB_ALLOW_NIL) 1630 #define GB_HISTORICAL_STRING_BEHAVIOR (GB_NEGATIVE_FROM_END | GB_ALLOW_NIL)
1631 1631
1632 Bufpos get_buffer_pos_char (struct buffer *b, Lisp_Object pos, 1632 Charbpos get_buffer_pos_char (struct buffer *b, Lisp_Object pos,
1633 unsigned int flags); 1633 unsigned int flags);
1634 Bytind get_buffer_pos_byte (struct buffer *b, Lisp_Object pos, 1634 Bytebpos get_buffer_pos_byte (struct buffer *b, Lisp_Object pos,
1635 unsigned int flags); 1635 unsigned int flags);
1636 void get_buffer_range_char (struct buffer *b, Lisp_Object from, Lisp_Object to, 1636 void get_buffer_range_char (struct buffer *b, Lisp_Object from, Lisp_Object to,
1637 Bufpos *from_out, Bufpos *to_out, 1637 Charbpos *from_out, Charbpos *to_out,
1638 unsigned int flags); 1638 unsigned int flags);
1639 void get_buffer_range_byte (struct buffer *b, Lisp_Object from, Lisp_Object to, 1639 void get_buffer_range_byte (struct buffer *b, Lisp_Object from, Lisp_Object to,
1640 Bytind *from_out, Bytind *to_out, 1640 Bytebpos *from_out, Bytebpos *to_out,
1641 unsigned int flags); 1641 unsigned int flags);
1642 Charcount get_string_pos_char (Lisp_Object string, Lisp_Object pos, 1642 Charcount get_string_pos_char (Lisp_Object string, Lisp_Object pos,
1643 unsigned int flags); 1643 unsigned int flags);
1644 Bytecount get_string_pos_byte (Lisp_Object string, Lisp_Object pos, 1644 Bytecount get_string_pos_byte (Lisp_Object string, Lisp_Object pos,
1645 unsigned int flags); 1645 unsigned int flags);
1647 Lisp_Object to, Charcount *from_out, 1647 Lisp_Object to, Charcount *from_out,
1648 Charcount *to_out, unsigned int flags); 1648 Charcount *to_out, unsigned int flags);
1649 void get_string_range_byte (Lisp_Object string, Lisp_Object from, 1649 void get_string_range_byte (Lisp_Object string, Lisp_Object from,
1650 Lisp_Object to, Bytecount *from_out, 1650 Lisp_Object to, Bytecount *from_out,
1651 Bytecount *to_out, unsigned int flags); 1651 Bytecount *to_out, unsigned int flags);
1652 Bufpos get_buffer_or_string_pos_char (Lisp_Object object, Lisp_Object pos, 1652 Charbpos get_buffer_or_string_pos_char (Lisp_Object object, Lisp_Object pos,
1653 unsigned int flags); 1653 unsigned int flags);
1654 Bytind get_buffer_or_string_pos_byte (Lisp_Object object, Lisp_Object pos, 1654 Bytebpos get_buffer_or_string_pos_byte (Lisp_Object object, Lisp_Object pos,
1655 unsigned int flags); 1655 unsigned int flags);
1656 void get_buffer_or_string_range_char (Lisp_Object object, Lisp_Object from, 1656 void get_buffer_or_string_range_char (Lisp_Object object, Lisp_Object from,
1657 Lisp_Object to, Bufpos *from_out, 1657 Lisp_Object to, Charbpos *from_out,
1658 Bufpos *to_out, unsigned int flags); 1658 Charbpos *to_out, unsigned int flags);
1659 void get_buffer_or_string_range_byte (Lisp_Object object, Lisp_Object from, 1659 void get_buffer_or_string_range_byte (Lisp_Object object, Lisp_Object from,
1660 Lisp_Object to, Bytind *from_out, 1660 Lisp_Object to, Bytebpos *from_out,
1661 Bytind *to_out, unsigned int flags); 1661 Bytebpos *to_out, unsigned int flags);
1662 Bufpos buffer_or_string_accessible_begin_char (Lisp_Object object); 1662 Charbpos buffer_or_string_accessible_begin_char (Lisp_Object object);
1663 Bufpos buffer_or_string_accessible_end_char (Lisp_Object object); 1663 Charbpos buffer_or_string_accessible_end_char (Lisp_Object object);
1664 Bytind buffer_or_string_accessible_begin_byte (Lisp_Object object); 1664 Bytebpos buffer_or_string_accessible_begin_byte (Lisp_Object object);
1665 Bytind buffer_or_string_accessible_end_byte (Lisp_Object object); 1665 Bytebpos buffer_or_string_accessible_end_byte (Lisp_Object object);
1666 Bufpos buffer_or_string_absolute_begin_char (Lisp_Object object); 1666 Charbpos buffer_or_string_absolute_begin_char (Lisp_Object object);
1667 Bufpos buffer_or_string_absolute_end_char (Lisp_Object object); 1667 Charbpos buffer_or_string_absolute_end_char (Lisp_Object object);
1668 Bytind buffer_or_string_absolute_begin_byte (Lisp_Object object); 1668 Bytebpos buffer_or_string_absolute_begin_byte (Lisp_Object object);
1669 Bytind buffer_or_string_absolute_end_byte (Lisp_Object object); 1669 Bytebpos buffer_or_string_absolute_end_byte (Lisp_Object object);
1670 void record_buffer (Lisp_Object buf); 1670 void record_buffer (Lisp_Object buf);
1671 Lisp_Object get_buffer (Lisp_Object name, 1671 Lisp_Object get_buffer (Lisp_Object name,
1672 int error_if_deleted_or_does_not_exist); 1672 int error_if_deleted_or_does_not_exist);
1673 int map_over_sharing_buffers (struct buffer *buf, 1673 int map_over_sharing_buffers (struct buffer *buf,
1674 int (*mapfun) (struct buffer *buf, 1674 int (*mapfun) (struct buffer *buf,
1769 /************************************************************************/ 1769 /************************************************************************/
1770 /* Lisp string representation convenience functions */ 1770 /* Lisp string representation convenience functions */
1771 /************************************************************************/ 1771 /************************************************************************/
1772 /* Because the representation of internally formatted data is subject to change, 1772 /* Because the representation of internally formatted data is subject to change,
1773 It's bad style to do something like strcmp (XSTRING_DATA (s), "foo") 1773 It's bad style to do something like strcmp (XSTRING_DATA (s), "foo")
1774 Instead, use the portable: bufbyte_strcmp (XSTRING_DATA (s), "foo") 1774 Instead, use the portable: intbyte_strcmp (XSTRING_DATA (s), "foo")
1775 or bufbyte_memcmp (XSTRING_DATA (s), "foo", 3) */ 1775 or intbyte_memcmp (XSTRING_DATA (s), "foo", 3) */
1776 1776
1777 /* Like strcmp, except first arg points at internally formatted data, 1777 /* Like strcmp, except first arg points at internally formatted data,
1778 while the second points at a string of only ASCII chars. */ 1778 while the second points at a string of only ASCII chars. */
1779 INLINE_HEADER int 1779 INLINE_HEADER int
1780 bufbyte_strcmp (const Bufbyte *bp, const char *ascii_string); 1780 intbyte_strcmp (const Intbyte *bp, const char *ascii_string);
1781 INLINE_HEADER int 1781 INLINE_HEADER int
1782 bufbyte_strcmp (const Bufbyte *bp, const char *ascii_string) 1782 intbyte_strcmp (const Intbyte *bp, const char *ascii_string)
1783 { 1783 {
1784 #ifdef MULE 1784 #ifdef MULE
1785 while (1) 1785 while (1)
1786 { 1786 {
1787 int diff; 1787 int diff;
1788 type_checking_assert (BYTE_ASCII_P (*ascii_string)); 1788 type_checking_assert (BYTE_ASCII_P (*ascii_string));
1789 if ((diff = charptr_emchar (bp) - *(Bufbyte *) ascii_string) != 0) 1789 if ((diff = charptr_emchar (bp) - *(Intbyte *) ascii_string) != 0)
1790 return diff; 1790 return diff;
1791 if (*ascii_string == '\0') 1791 if (*ascii_string == '\0')
1792 return 0; 1792 return 0;
1793 ascii_string++; 1793 ascii_string++;
1794 INC_CHARPTR (bp); 1794 INC_CHARPTR (bp);
1800 1800
1801 1801
1802 /* Like memcmp, except first arg points at internally formatted data, 1802 /* Like memcmp, except first arg points at internally formatted data,
1803 while the second points at a string of only ASCII chars. */ 1803 while the second points at a string of only ASCII chars. */
1804 INLINE_HEADER int 1804 INLINE_HEADER int
1805 bufbyte_memcmp (const Bufbyte *bp, const char *ascii_string, Memory_Count len); 1805 intbyte_memcmp (const Intbyte *bp, const char *ascii_string, Bytecount len);
1806 INLINE_HEADER int 1806 INLINE_HEADER int
1807 bufbyte_memcmp (const Bufbyte *bp, const char *ascii_string, Memory_Count len) 1807 intbyte_memcmp (const Intbyte *bp, const char *ascii_string, Bytecount len)
1808 { 1808 {
1809 #ifdef MULE 1809 #ifdef MULE
1810 while (len--) 1810 while (len--)
1811 { 1811 {
1812 int diff = charptr_emchar (bp) - *(Bufbyte *) ascii_string; 1812 int diff = charptr_emchar (bp) - *(Intbyte *) ascii_string;
1813 type_checking_assert (BYTE_ASCII_P (*ascii_string)); 1813 type_checking_assert (BYTE_ASCII_P (*ascii_string));
1814 if (diff != 0) 1814 if (diff != 0)
1815 return diff; 1815 return diff;
1816 ascii_string++; 1816 ascii_string++;
1817 INC_CHARPTR (bp); 1817 INC_CHARPTR (bp);