Mercurial > hg > xemacs-beta
diff src/search.c @ 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 | b39c14581166 |
children | a307f9a2021d |
line wrap: on
line diff
--- a/src/search.c Tue Sep 18 05:06:57 2001 +0000 +++ b/src/search.c Thu Sep 20 06:31:11 2001 +0000 @@ -84,7 +84,7 @@ able to free or re-allocate it properly. */ /* Note: things get trickier under Mule because the values returned from - the regexp routines are in Bytinds but we need them to be in Bufpos's. + the regexp routines are in Bytebposs but we need them to be in Charbpos's. We take the easy way out for the moment and just convert them immediately. We could be more clever by not converting them until necessary, but that gets real ugly real fast since the buffer might have changed and @@ -109,17 +109,17 @@ /* range table for use with skip_chars. Only needed for Mule. */ Lisp_Object Vskip_chars_range_table; -static void set_search_regs (struct buffer *buf, Bufpos beg, Charcount len); +static void set_search_regs (struct buffer *buf, Charbpos beg, Charcount len); static void save_search_regs (void); -static Bufpos simple_search (struct buffer *buf, Bufbyte *base_pat, - Bytecount len, Bytind pos, Bytind lim, +static Charbpos simple_search (struct buffer *buf, Intbyte *base_pat, + Bytecount len, Bytebpos pos, Bytebpos lim, EMACS_INT n, Lisp_Object trt); -static Bufpos boyer_moore (struct buffer *buf, Bufbyte *base_pat, - Bytecount len, Bytind pos, Bytind lim, +static Charbpos boyer_moore (struct buffer *buf, Intbyte *base_pat, + Bytecount len, Bytebpos pos, Bytebpos lim, EMACS_INT n, Lisp_Object trt, Lisp_Object inverse_trt, int charset_base); -static Bufpos search_buffer (struct buffer *buf, Lisp_Object str, - Bufpos bufpos, Bufpos buflim, EMACS_INT n, int RE, +static Charbpos search_buffer (struct buffer *buf, Lisp_Object str, + Charbpos charbpos, Charbpos buflim, EMACS_INT n, int RE, Lisp_Object trt, Lisp_Object inverse_trt, int posix); @@ -229,13 +229,13 @@ return Qnil; /* Not reached. */ } -/* Convert the search registers from Bytinds to Bufpos's. Needs to be +/* Convert the search registers from Bytebposs to Charbpos's. Needs to be done after each regexp match that uses the search regs. We could get a potential speedup by not converting the search registers until it's really necessary, e.g. when match-data or replace-match is called. However, this complexifies the code a lot (e.g. the buffer - could have changed and the Bytinds stored might be invalid) and is + could have changed and the Bytebposs stored might be invalid) and is probably not a great time-saver. */ static void @@ -247,9 +247,9 @@ for (i = 0; i < num_regs; i++) { if (search_regs.start[i] >= 0) - search_regs.start[i] = bytind_to_bufpos (buf, search_regs.start[i]); + search_regs.start[i] = bytebpos_to_charbpos (buf, search_regs.start[i]); if (search_regs.end[i] >= 0) - search_regs.end[i] = bytind_to_bufpos (buf, search_regs.end[i]); + search_regs.end[i] = bytebpos_to_charbpos (buf, search_regs.end[i]); } } @@ -290,7 +290,7 @@ { /* This function has been Mule-ized, except for the trt table handling. */ Lisp_Object val; - Bytind p1, p2; + Bytebpos p1, p2; Bytecount s1, s2; REGISTER int i; struct re_pattern_buffer *bufp; @@ -458,14 +458,14 @@ This does not clobber the match data. */ Bytecount -fast_string_match (Lisp_Object regexp, const Bufbyte *nonreloc, +fast_string_match (Lisp_Object regexp, const Intbyte *nonreloc, Lisp_Object reloc, Bytecount offset, Bytecount length, int case_fold_search, Error_Behavior errb, int no_quit) { /* This function has been Mule-ized, except for the trt table handling. */ Bytecount val; - Bufbyte *newnonreloc = (Bufbyte *) nonreloc; + Intbyte *newnonreloc = (Intbyte *) nonreloc; struct re_pattern_buffer *bufp; bufp = compile_pattern (regexp, 0, @@ -491,7 +491,7 @@ /* QUIT could relocate RELOC. Therefore we must alloca() and copy. No way around this except some serious rewriting of re_search(). */ - newnonreloc = (Bufbyte *) alloca (length); + newnonreloc = (Intbyte *) alloca (length); memcpy (newnonreloc, XSTRING_DATA (reloc), length); } } @@ -561,12 +561,12 @@ If ALLOW_QUIT is non-zero, call QUIT periodically. */ -static Bytind -bi_scan_buffer (struct buffer *buf, Emchar target, Bytind st, Bytind en, +static Bytebpos +bi_scan_buffer (struct buffer *buf, Emchar target, Bytebpos st, Bytebpos en, EMACS_INT count, EMACS_INT *shortage, int allow_quit) { /* This function has been Mule-ized. */ - Bytind lim = en > 0 ? en : + Bytebpos lim = en > 0 ? en : ((count > 0) ? BI_BUF_ZV (buf) : BI_BUF_BEGV (buf)); /* #### newline cache stuff in this function not yet ported */ @@ -590,7 +590,7 @@ { if (BI_BUF_FETCH_CHAR (buf, st) == target) count--; - INC_BYTIND (buf, st); + INC_BYTEBPOS (buf, st); } } else @@ -598,12 +598,12 @@ { while (st < lim && count > 0) { - Bytind ceil; - Bufbyte *bufptr; + Bytebpos ceil; + Intbyte *bufptr; ceil = BI_BUF_CEILING_OF (buf, st); ceil = min (lim, ceil); - bufptr = (Bufbyte *) memchr (BI_BUF_BYTE_ADDRESS (buf, st), + bufptr = (Intbyte *) memchr (BI_BUF_BYTE_ADDRESS (buf, st), (int) target, ceil - st); if (bufptr) { @@ -628,7 +628,7 @@ { while (st > lim && count < 0) { - DEC_BYTIND (buf, st); + DEC_BYTEBPOS (buf, st); if (BI_BUF_FETCH_CHAR (buf, st) == target) count++; } @@ -638,9 +638,9 @@ { while (st > lim && count < 0) { - Bytind floor; - Bufbyte *bufptr; - Bufbyte *floorptr; + Bytebpos floor; + Intbyte *bufptr; + Intbyte *floorptr; floor = BI_BUF_FLOOR_OF (buf, st); floor = max (lim, floor); @@ -674,54 +674,54 @@ /* We found the character we were looking for; we have to return the position *after* it due to the strange way that the return value is defined. */ - INC_BYTIND (buf, st); + INC_BYTEBPOS (buf, st); return st; } } } -Bufpos -scan_buffer (struct buffer *buf, Emchar target, Bufpos start, Bufpos end, +Charbpos +scan_buffer (struct buffer *buf, Emchar target, Charbpos start, Charbpos end, EMACS_INT count, EMACS_INT *shortage, int allow_quit) { - Bytind bi_retval; - Bytind bi_start, bi_end; - - bi_start = bufpos_to_bytind (buf, start); + Bytebpos bi_retval; + Bytebpos bi_start, bi_end; + + bi_start = charbpos_to_bytebpos (buf, start); if (end) - bi_end = bufpos_to_bytind (buf, end); + bi_end = charbpos_to_bytebpos (buf, end); else bi_end = 0; bi_retval = bi_scan_buffer (buf, target, bi_start, bi_end, count, shortage, allow_quit); - return bytind_to_bufpos (buf, bi_retval); + return bytebpos_to_charbpos (buf, bi_retval); } -Bytind -bi_find_next_newline_no_quit (struct buffer *buf, Bytind from, int count) +Bytebpos +bi_find_next_newline_no_quit (struct buffer *buf, Bytebpos from, int count) { return bi_scan_buffer (buf, '\n', from, 0, count, 0, 0); } -Bufpos -find_next_newline_no_quit (struct buffer *buf, Bufpos from, int count) +Charbpos +find_next_newline_no_quit (struct buffer *buf, Charbpos from, int count) { return scan_buffer (buf, '\n', from, 0, count, 0, 0); } -Bufpos -find_next_newline (struct buffer *buf, Bufpos from, int count) +Charbpos +find_next_newline (struct buffer *buf, Charbpos from, int count) { return scan_buffer (buf, '\n', from, 0, count, 0, 1); } -Bytind -bi_find_next_emchar_in_string (Lisp_String* str, Emchar target, Bytind st, +Bytebpos +bi_find_next_emchar_in_string (Lisp_String* str, Emchar target, Bytebpos st, EMACS_INT count) { /* This function has been Mule-ized. */ - Bytind lim = string_length (str) -1; - Bufbyte* s = string_data (str); + Bytebpos lim = string_length (str) -1; + Intbyte* s = string_data (str); assert (count >= 0); @@ -737,7 +737,7 @@ { if (string_char (str, st) == target) count--; - INC_CHARBYTIND (s, st); + INC_CHARBYTEBPOS (s, st); } } else @@ -745,12 +745,12 @@ { while (st < lim && count > 0) { - Bufbyte *bufptr = (Bufbyte *) memchr (charptr_n_addr (s, st), + Intbyte *bufptr = (Intbyte *) memchr (charptr_n_addr (s, st), (int) target, lim - st); if (bufptr) { count--; - st = (Bytind)(bufptr - s) + 1; + st = (Bytebpos)(bufptr - s) + 1; } else st = lim; @@ -762,11 +762,11 @@ /* Like find_next_newline, but returns position before the newline, not after, and only search up to TO. This isn't just find_next_newline (...)-1, because you might hit TO. */ -Bufpos -find_before_next_newline (struct buffer *buf, Bufpos from, Bufpos to, int count) +Charbpos +find_before_next_newline (struct buffer *buf, Charbpos from, Charbpos to, int count) { EMACS_INT shortage; - Bufpos pos = scan_buffer (buf, '\n', from, to, count, &shortage, 1); + Charbpos pos = scan_buffer (buf, '\n', from, to, count, &shortage, 1); if (shortage == 0) pos--; @@ -779,7 +779,7 @@ Lisp_Object string, Lisp_Object lim) { /* This function has been Mule-ized. */ - REGISTER Bufbyte *p, *pend; + REGISTER Intbyte *p, *pend; REGISTER Emchar c; /* We store the first 256 chars in an array here and the rest in a range table. */ @@ -789,7 +789,7 @@ #ifndef emacs Lisp_Char_Table *syntax_table = XCHAR_TABLE (buf->mirror_syntax_table); #endif - Bufpos limit; + Charbpos limit; if (NILP (lim)) limit = forwardp ? BUF_ZV (buf) : BUF_BEGV (buf); @@ -880,7 +880,7 @@ fastmap[i] ^= 1; { - Bufpos start_point = BUF_PT (buf); + Charbpos start_point = BUF_PT (buf); if (syntaxp) { @@ -1017,8 +1017,8 @@ int RE, int posix) { /* This function has been Mule-ized, except for the trt table handling. */ - REGISTER Bufpos np; - Bufpos lim; + REGISTER Charbpos np; + Charbpos lim; EMACS_INT n = direction; struct buffer *buf; @@ -1085,7 +1085,7 @@ { /* This function has been Mule-ized. */ Bytecount len = XSTRING_LENGTH (regexp); - Bufbyte *s = XSTRING_DATA (regexp); + Intbyte *s = XSTRING_DATA (regexp); while (--len >= 0) { switch (*s++) @@ -1114,14 +1114,14 @@ } /* Search for the n'th occurrence of STRING in BUF, - starting at position BUFPOS and stopping at position BUFLIM, + starting at position CHARBPOS and stopping at position BUFLIM, treating PAT as a literal string if RE is false or as a regular expression if RE is true. If N is positive, searching is forward and BUFLIM must be greater - than BUFPOS. + than CHARBPOS. If N is negative, searching is backward and BUFLIM must be less - than BUFPOS. + than CHARBPOS. Returns -x if only N-x occurrences found (x > 0), or else the position at the beginning of the Nth occurrence @@ -1129,18 +1129,18 @@ POSIX is nonzero if we want full backtracking (POSIX style) for this pattern. 0 means backtrack only enough to get a valid match. */ -static Bufpos -search_buffer (struct buffer *buf, Lisp_Object string, Bufpos bufpos, - Bufpos buflim, EMACS_INT n, int RE, Lisp_Object trt, +static Charbpos +search_buffer (struct buffer *buf, Lisp_Object string, Charbpos charbpos, + Charbpos buflim, EMACS_INT n, int RE, Lisp_Object trt, Lisp_Object inverse_trt, int posix) { /* This function has been Mule-ized, except for the trt table handling. */ Bytecount len = XSTRING_LENGTH (string); - Bufbyte *base_pat = XSTRING_DATA (string); + Intbyte *base_pat = XSTRING_DATA (string); REGISTER EMACS_INT i, j; - Bytind p1, p2; + Bytebpos p1, p2; Bytecount s1, s2; - Bytind pos, lim; + Bytebpos pos, lim; if (running_asynch_code) save_search_regs (); @@ -1148,16 +1148,16 @@ /* Null string is found at starting position. */ if (len == 0) { - set_search_regs (buf, bufpos, 0); - return bufpos; + set_search_regs (buf, charbpos, 0); + return charbpos; } /* Searching 0 times means don't move. */ if (n == 0) - return bufpos; - - pos = bufpos_to_bytind (buf, bufpos); - lim = bufpos_to_bytind (buf, buflim); + return charbpos; + + pos = charbpos_to_bytebpos (buf, charbpos); + lim = charbpos_to_bytebpos (buf, buflim); if (RE && !trivial_regexp_p (string)) { struct re_pattern_buffer *bufp; @@ -1203,8 +1203,8 @@ /* Set pos to the new position. */ pos = search_regs.start[0]; fixup_search_regs_for_buffer (buf); - /* And bufpos too. */ - bufpos = search_regs.start[0]; + /* And charbpos too. */ + charbpos = search_regs.start[0]; } else { @@ -1240,8 +1240,8 @@ /* Set pos to the new position. */ pos = search_regs.end[0]; fixup_search_regs_for_buffer (buf); - /* And bufpos too. */ - bufpos = search_regs.end[0]; + /* And charbpos too. */ + charbpos = search_regs.end[0]; } else { @@ -1249,19 +1249,19 @@ } n--; } - return bufpos; + return charbpos; } else /* non-RE case */ { int charset_base = -1; int boyer_moore_ok = 1; - Bufbyte *pat = 0; - Bufbyte *patbuf = alloca_array (Bufbyte, len * MAX_EMCHAR_LEN); + Intbyte *pat = 0; + Intbyte *patbuf = alloca_array (Intbyte, len * MAX_EMCHAR_LEN); pat = patbuf; #ifdef MULE while (len > 0) { - Bufbyte tmp_str[MAX_EMCHAR_LEN]; + Intbyte tmp_str[MAX_EMCHAR_LEN]; Emchar c, translated, inverse; Bytecount orig_bytelen, new_bytelen, inv_bytelen; @@ -1337,9 +1337,9 @@ regardless of what is in TRT. It is used in cases where boyer_moore cannot work. */ -static Bufpos -simple_search (struct buffer *buf, Bufbyte *base_pat, Bytecount len_byte, - Bytind idx, Bytind lim, EMACS_INT n, Lisp_Object trt) +static Charbpos +simple_search (struct buffer *buf, Intbyte *base_pat, Bytecount len_byte, + Bytebpos idx, Bytebpos lim, EMACS_INT n, Lisp_Object trt) { int forward = n > 0; Bytecount buf_len = 0; /* Shut up compiler. */ @@ -1350,8 +1350,8 @@ while (1) { Bytecount this_len = len_byte; - Bytind this_idx = idx; - Bufbyte *p = base_pat; + Bytebpos this_idx = idx; + Intbyte *p = base_pat; if (idx >= lim) goto stop; @@ -1371,7 +1371,7 @@ pat_len = charcount_to_bytecount (p, 1); p += pat_len; this_len -= pat_len; - INC_BYTIND (buf, this_idx); + INC_BYTEBPOS (buf, this_idx); } if (this_len == 0) { @@ -1379,7 +1379,7 @@ idx = this_idx; break; } - INC_BYTIND (buf, idx); + INC_BYTEBPOS (buf, idx); } n--; } @@ -1389,8 +1389,8 @@ while (1) { Bytecount this_len = len_byte; - Bytind this_idx = idx; - Bufbyte *p; + Bytebpos this_idx = idx; + Intbyte *p; if (idx <= lim) goto stop; p = base_pat + len_byte; @@ -1400,7 +1400,7 @@ Emchar pat_ch, buf_ch; DEC_CHARPTR (p); - DEC_BYTIND (buf, this_idx); + DEC_BYTEBPOS (buf, this_idx); pat_ch = charptr_emchar (p); buf_ch = BI_BUF_FETCH_CHAR (buf, this_idx); @@ -1417,23 +1417,23 @@ idx = this_idx; break; } - DEC_BYTIND (buf, idx); + DEC_BYTEBPOS (buf, idx); } n++; } stop: if (n == 0) { - Bufpos beg, end, retval; + Charbpos beg, end, retval; if (forward) { - beg = bytind_to_bufpos (buf, idx - buf_len); - retval = end = bytind_to_bufpos (buf, idx); + beg = bytebpos_to_charbpos (buf, idx - buf_len); + retval = end = bytebpos_to_charbpos (buf, idx); } else { - retval = beg = bytind_to_bufpos (buf, idx); - end = bytind_to_bufpos (buf, idx + buf_len); + retval = beg = bytebpos_to_charbpos (buf, idx); + end = bytebpos_to_charbpos (buf, idx + buf_len); } set_search_regs (buf, beg, end - beg); @@ -1458,9 +1458,9 @@ If that criterion is not satisfied, do not call this function. */ -static Bufpos -boyer_moore (struct buffer *buf, Bufbyte *base_pat, Bytecount len, - Bytind pos, Bytind lim, EMACS_INT n, Lisp_Object trt, +static Charbpos +boyer_moore (struct buffer *buf, Intbyte *base_pat, Bytecount len, + Bytebpos pos, Bytebpos lim, EMACS_INT n, Lisp_Object trt, Lisp_Object inverse_trt, int charset_base) { /* #### Someone really really really needs to comment the workings @@ -1496,16 +1496,16 @@ EMACS_INT *BM_tab_base; REGISTER Bytecount dirlen; EMACS_INT infinity; - Bytind limit; + Bytebpos limit; Bytecount stride_for_teases = 0; REGISTER EMACS_INT i, j; - Bufbyte *pat, *pat_end; - REGISTER Bufbyte *cursor, *p_limit, *ptr2; - Bufbyte simple_translate[0400]; + Intbyte *pat, *pat_end; + REGISTER Intbyte *cursor, *p_limit, *ptr2; + Intbyte simple_translate[0400]; REGISTER int direction = ((n > 0) ? 1 : -1); #ifdef MULE - Bufbyte translate_prev_byte = 0; - Bufbyte translate_anteprev_byte = 0; + Intbyte translate_prev_byte = 0; + Intbyte translate_anteprev_byte = 0; #endif #ifdef C_ALLOCA EMACS_INT BM_tab_space[0400]; @@ -1566,11 +1566,11 @@ in the pattern. Others don't matter anyway! */ xzero (simple_translate); for (i = 0; i < 0400; i++) - simple_translate[i] = (Bufbyte) i; + simple_translate[i] = (Intbyte) i; i = 0; while (i != infinity) { - Bufbyte *ptr = base_pat + i; + Intbyte *ptr = base_pat + i; i += direction; if (i == dirlen) i = infinity; @@ -1581,19 +1581,19 @@ int this_translated = 1; /* Is *PTR the last byte of a character? */ - if (pat_end - ptr == 1 || BUFBYTE_FIRST_BYTE_P (ptr[1])) + if (pat_end - ptr == 1 || INTBYTE_FIRST_BYTE_P (ptr[1])) { - Bufbyte *charstart = ptr; - while (!BUFBYTE_FIRST_BYTE_P (*charstart)) + Intbyte *charstart = ptr; + while (!INTBYTE_FIRST_BYTE_P (*charstart)) charstart--; untranslated = charptr_emchar (charstart); if (charset_base == (untranslated & ~CHAR_FIELD3_MASK)) { ch = TRANSLATE (trt, untranslated); - if (!BUFBYTE_FIRST_BYTE_P (*ptr)) + if (!INTBYTE_FIRST_BYTE_P (*ptr)) { translate_prev_byte = ptr[-1]; - if (!BUFBYTE_FIRST_BYTE_P (translate_prev_byte)) + if (!INTBYTE_FIRST_BYTE_P (translate_prev_byte)) translate_anteprev_byte = ptr[-2]; } } @@ -1651,7 +1651,7 @@ while ((j = TRANSLATE (inverse_trt, j)) != k) { - simple_translate[j] = (Bufbyte) k; + simple_translate[j] = (Intbyte) k; BM_tab[j] = dirlen - i; } #endif @@ -1676,8 +1676,8 @@ reverse) of pattern would align in a possible match. */ while (n != 0) { - Bytind tail_end; - Bufbyte *tail_end_ptr; + Bytebpos tail_end; + Intbyte *tail_end_ptr; /* It's been reported that some (broken) compiler thinks that Boolean expressions in an arithmetic context are unsigned. Using an explicit ?1:0 prevents this. */ @@ -1762,10 +1762,10 @@ cursor -= direction; /* Translate only the last byte of a character. */ if ((cursor == tail_end_ptr - || BUFBYTE_FIRST_BYTE_P (cursor[1])) - && (BUFBYTE_FIRST_BYTE_P (cursor[0]) + || INTBYTE_FIRST_BYTE_P (cursor[1])) + && (INTBYTE_FIRST_BYTE_P (cursor[0]) || (translate_prev_byte == cursor[-1] - && (BUFBYTE_FIRST_BYTE_P (translate_prev_byte) + && (INTBYTE_FIRST_BYTE_P (translate_prev_byte) || translate_anteprev_byte == cursor[-2])))) ch = simple_translate[*cursor]; else @@ -1790,11 +1790,11 @@ cursor -= direction; { - Bytind bytstart = (pos + cursor - ptr2 + + Bytebpos bytstart = (pos + cursor - ptr2 + ((direction > 0) ? 1 - len : 0)); - Bufpos bufstart = bytind_to_bufpos (buf, bytstart); - Bufpos bufend = bytind_to_bufpos (buf, bytstart + len); + Charbpos bufstart = bytebpos_to_charbpos (buf, bytstart); + Charbpos bufend = bytebpos_to_charbpos (buf, bytstart + len); set_search_regs (buf, bufstart, bufend - bufstart); } @@ -1846,16 +1846,16 @@ { #ifdef MULE Emchar ch; - Bufbyte *ptr; + Intbyte *ptr; #endif pos -= direction; #ifdef MULE ptr = BI_BUF_BYTE_ADDRESS (buf, pos); if ((ptr == tail_end_ptr - || BUFBYTE_FIRST_BYTE_P (ptr[1])) - && (BUFBYTE_FIRST_BYTE_P (ptr[0]) + || INTBYTE_FIRST_BYTE_P (ptr[1])) + && (INTBYTE_FIRST_BYTE_P (ptr[0]) || (translate_prev_byte == ptr[-1] - && (BUFBYTE_FIRST_BYTE_P (translate_prev_byte) + && (INTBYTE_FIRST_BYTE_P (translate_prev_byte) || translate_anteprev_byte == ptr[-2])))) ch = simple_translate[*ptr]; else @@ -1879,11 +1879,11 @@ pos -= direction; { - Bytind bytstart = (pos + + Bytebpos bytstart = (pos + ((direction > 0) ? 1 - len : 0)); - Bufpos bufstart = bytind_to_bufpos (buf, bytstart); - Bufpos bufend = bytind_to_bufpos (buf, bytstart + len); + Charbpos bufstart = bytebpos_to_charbpos (buf, bytstart); + Charbpos bufend = bytebpos_to_charbpos (buf, bytstart + len); set_search_regs (buf, bufstart, bufend - bufstart); } @@ -1902,14 +1902,14 @@ if ((lim - pos) * direction < 0) return (0 - n) * direction; } - return bytind_to_bufpos (buf, pos); + return bytebpos_to_charbpos (buf, pos); } /* Record beginning BEG and end BEG + LEN for a match just found in the current buffer. */ static void -set_search_regs (struct buffer *buf, Bufpos beg, Charcount len) +set_search_regs (struct buffer *buf, Charbpos beg, Charcount len) { /* This function has been Mule-ized. */ /* Make sure we have registers in which to store @@ -1957,10 +1957,10 @@ { /* The following value is an upper bound on the amount of storage we need. In non-Mule, it is exact. */ - Bufbyte *storage = - (Bufbyte *) alloca (XSTRING_LENGTH (string) - punct_count + + Intbyte *storage = + (Intbyte *) alloca (XSTRING_LENGTH (string) - punct_count + 5 * (word_count - 1) + 4); - Bufbyte *o = storage; + Intbyte *o = storage; *o++ = '\\'; *o++ = 'b'; @@ -2259,7 +2259,7 @@ /* This function has been Mule-ized. */ /* This function can GC */ enum { nochange, all_caps, cap_initial } case_action; - Bufpos pos, last; + Charbpos pos, last; int some_multiletter_word; int some_lowercase; int some_uppercase; @@ -2648,7 +2648,7 @@ in the replacement string. */ if (ul_pos_dynarr) { - Bufpos eend = BUF_PT (buf); + Charbpos eend = BUF_PT (buf); int i = 0; int cur_action = 'E'; @@ -2756,7 +2756,7 @@ len = -1; for (i = 0; i < search_regs.num_regs; i++) { - Bufpos start = search_regs.start[i]; + Charbpos start = search_regs.start[i]; if (start >= 0) { if (EQ (last_thing_searched, Qt) @@ -2933,12 +2933,12 @@ */ (string)) { - REGISTER Bufbyte *in, *out, *end; - REGISTER Bufbyte *temp; + REGISTER Intbyte *in, *out, *end; + REGISTER Intbyte *temp; CHECK_STRING (string); - temp = (Bufbyte *) alloca (XSTRING_LENGTH (string) * 2); + temp = (Intbyte *) alloca (XSTRING_LENGTH (string) * 2); /* Now copy the data into the new string, inserting escapes. */