#include <config.h>
#include "lisp.h"
-#include "syntax.h"
#include "category.h"
#include "character.h"
#include "buffer.h"
+#include "syntax.h"
#include "charset.h"
#include "region-cache.h"
#include "commands.h"
Lisp_Object syntax_table;
struct re_pattern_buffer buf;
char fastmap[0400];
- /* Nonzero means regexp was compiled to do full POSIX backtracking. */
- char posix;
+ /* True means regexp was compiled to do full POSIX backtracking. */
+ bool posix;
};
/* The instances of that struct. */
ptrdiff_t, int);
static EMACS_INT search_buffer (Lisp_Object, ptrdiff_t, ptrdiff_t,
ptrdiff_t, ptrdiff_t, EMACS_INT, int,
- Lisp_Object, Lisp_Object, int);
+ Lisp_Object, Lisp_Object, bool);
static _Noreturn void
matcher_overflow (void)
PATTERN is the pattern to compile.
CP is the place to put the result.
TRANSLATE is a translation table for ignoring case, or nil for none.
- POSIX is nonzero if we want full backtracking (POSIX style)
- for this pattern. 0 means backtrack only enough to get a valid match.
+ POSIX is true if we want full backtracking (POSIX style) for this pattern.
+ False means backtrack only enough to get a valid match.
The behavior also depends on Vsearch_spaces_regexp. */
static void
-compile_pattern_1 (struct regexp_cache *cp, Lisp_Object pattern, Lisp_Object translate, int posix)
+compile_pattern_1 (struct regexp_cache *cp, Lisp_Object pattern,
+ Lisp_Object translate, bool posix)
{
char *val;
reg_syntax_t old;
values that will result from matching this pattern.
If it is 0, we should compile the pattern not to record any
subexpression bounds.
- POSIX is nonzero if we want full backtracking (POSIX style)
- for this pattern. 0 means backtrack only enough to get a valid match. */
+ POSIX is true if we want full backtracking (POSIX style) for this pattern.
+ False means backtrack only enough to get a valid match. */
struct re_pattern_buffer *
compile_pattern (Lisp_Object pattern, struct re_registers *regp,
- Lisp_Object translate, int posix, bool multibyte)
+ Lisp_Object translate, bool posix, bool multibyte)
{
struct regexp_cache *cp, **cpp;
\f
static Lisp_Object
-looking_at_1 (Lisp_Object string, int posix)
+looking_at_1 (Lisp_Object string, bool posix)
{
Lisp_Object val;
unsigned char *p1, *p2;
if (i == -2)
matcher_overflow ();
- val = (0 <= i ? Qt : Qnil);
+ val = (i >= 0 ? Qt : Qnil);
if (NILP (Vinhibit_changing_match_data) && i >= 0)
+ {
for (i = 0; i < search_regs.num_regs; i++)
if (search_regs.start[i] >= 0)
{
search_regs.start[i]
= BYTE_TO_CHAR (search_regs.start[i] + BEGV_BYTE);
- search_regs.end[i]
- = BYTE_TO_CHAR (search_regs.end[i] + BEGV_BYTE);
- }
-
- /* Set last_thing_searched only when match data is changed. */
- if (NILP (Vinhibit_changing_match_data))
+ search_regs.end[i]
+ = BYTE_TO_CHAR (search_regs.end[i] + BEGV_BYTE);
+ }
+ /* Set last_thing_searched only when match data is changed. */
XSETBUFFER (last_thing_searched, current_buffer);
+ }
return val;
}
}
\f
static Lisp_Object
-string_match_1 (Lisp_Object regexp, Lisp_Object string, Lisp_Object start, int posix)
+string_match_1 (Lisp_Object regexp, Lisp_Object string, Lisp_Object start,
+ bool posix)
{
ptrdiff_t val;
struct re_pattern_buffer *bufp;
}
\f
-/* Search for COUNT newlines between START and END.
+/* Search for COUNT newlines between START/START_BYTE and END/END_BYTE.
If COUNT is positive, search forwards; END must be >= START.
If COUNT is negative, search backwards for the -COUNTth instance;
except when inside redisplay. */
ptrdiff_t
-find_newline (ptrdiff_t start, ptrdiff_t end, ptrdiff_t count,
- ptrdiff_t *shortage, ptrdiff_t *bytepos, bool allow_quit)
+find_newline (ptrdiff_t start, ptrdiff_t start_byte, ptrdiff_t end,
+ ptrdiff_t end_byte, ptrdiff_t count, ptrdiff_t *shortage,
+ ptrdiff_t *bytepos, bool allow_quit)
{
struct region_cache *newline_cache;
- ptrdiff_t start_byte = -1, end_byte = -1;
int direction;
if (count > 0)
next_change is the position of the next known region. */
ceiling_byte = min (CHAR_TO_BYTE (next_change) - 1, ceiling_byte);
}
- else
+ else if (start_byte == -1)
start_byte = CHAR_TO_BYTE (start);
/* The dumb loop can only scan text stored in contiguous
next_change is the position of the next known region. */
ceiling_byte = max (CHAR_TO_BYTE (next_change), ceiling_byte);
}
- else
+ else if (start_byte == -1)
start_byte = CHAR_TO_BYTE (start);
/* Stop scanning before the gap. */
return count * direction;
}
+/* Like find_newline, but doesn't allow QUITting and doesn't return
+ SHORTAGE. */
ptrdiff_t
-find_next_newline_no_quit (ptrdiff_t from, ptrdiff_t cnt, ptrdiff_t *bytepos)
+find_newline_no_quit (ptrdiff_t from, ptrdiff_t frombyte,
+ ptrdiff_t cnt, ptrdiff_t *bytepos)
{
- return find_newline (from, 0, cnt, NULL, bytepos, 0);
+ return find_newline (from, frombyte, 0, -1, cnt, NULL, bytepos, 0);
}
-/* 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. */
+/* Like find_newline, but returns position before the newline, not
+ after, and only search up to TO.
+ This isn't just find_newline_no_quit (...)-1, because you might hit TO. */
ptrdiff_t
find_before_next_newline (ptrdiff_t from, ptrdiff_t to,
ptrdiff_t cnt, ptrdiff_t *bytepos)
{
ptrdiff_t shortage;
- ptrdiff_t pos = find_newline (from, to, cnt, &shortage, bytepos, 1);
+ ptrdiff_t pos = find_newline (from, -1, to, -1, cnt, &shortage, bytepos, 1);
if (shortage == 0)
{
static Lisp_Object
search_command (Lisp_Object string, Lisp_Object bound, Lisp_Object noerror,
- Lisp_Object count, int direction, int RE, int posix)
+ Lisp_Object count, int direction, int RE, bool posix)
{
- register EMACS_INT np;
+ EMACS_INT np;
EMACS_INT lim;
ptrdiff_t lim_byte;
EMACS_INT n = direction;
return make_number (np);
}
\f
-/* Return 1 if REGEXP it matches just one constant string. */
+/* Return true if REGEXP it matches just one constant string. */
-static int
+static bool
trivial_regexp_p (Lisp_Object regexp)
{
ptrdiff_t len = SBYTES (regexp);
static EMACS_INT
search_buffer (Lisp_Object string, ptrdiff_t pos, ptrdiff_t pos_byte,
ptrdiff_t lim, ptrdiff_t lim_byte, EMACS_INT n,
- int RE, Lisp_Object trt, Lisp_Object inverse_trt, int posix)
+ int RE, Lisp_Object trt, Lisp_Object inverse_trt, bool posix)
{
ptrdiff_t len = SCHARS (string);
ptrdiff_t len_byte = SBYTES (string);
/* Set to positive if we find a non-ASCII char that need
translation. Otherwise set to zero later. */
int char_base = -1;
- int boyer_moore_ok = 1;
+ bool boyer_moore_ok = 1;
/* MULTIBYTE says whether the text to be searched is multibyte.
We must convert PATTERN to match that, or we will not really
(Lisp_Object newtext, Lisp_Object fixedcase, Lisp_Object literal, Lisp_Object string, Lisp_Object subexp)
{
enum { nochange, all_caps, cap_initial } case_action;
- register ptrdiff_t pos, pos_byte;
- int some_multiletter_word;
- int some_lowercase;
- int some_uppercase;
- int some_nonuppercase_initial;
- register int c, prevc;
+ ptrdiff_t pos, pos_byte;
+ bool some_multiletter_word;
+ bool some_lowercase;
+ bool some_uppercase;
+ bool some_nonuppercase_initial;
+ int c, prevc;
ptrdiff_t sub;
ptrdiff_t opoint, newpoint;
{
ptrdiff_t substart = -1;
ptrdiff_t subend = 0;
- int delbackslash = 0;
+ bool delbackslash = 0;
FETCH_STRING_CHAR_ADVANCE (c, newtext, pos, pos_byte);
else if (c >= '1' && c <= '9')
{
if (c - '0' < search_regs.num_regs
- && 0 <= search_regs.start[c - '0'])
+ && search_regs.start[c - '0'] >= 0)
{
substart = search_regs.start[c - '0'];
subend = search_regs.end[c - '0'];
ptrdiff_t substed_alloc_size, substed_len;
bool buf_multibyte = !NILP (BVAR (current_buffer, enable_multibyte_characters));
bool str_multibyte = STRING_MULTIBYTE (newtext);
- int really_changed = 0;
+ bool really_changed = 0;
- substed_alloc_size = ((STRING_BYTES_BOUND - 100) / 2 < length
- ? STRING_BYTES_BOUND
- : length * 2 + 100);
+ substed_alloc_size = (length <= (STRING_BYTES_BOUND - 100) / 2
+ ? length * 2 + 100
+ : STRING_BYTES_BOUND);
substed = xmalloc (substed_alloc_size);
substed_len = 0;
}
\f
static Lisp_Object
-match_limit (Lisp_Object num, int beginningp)
+match_limit (Lisp_Object num, bool beginningp)
{
EMACS_INT n;
return Qnil;
}
-/* If non-zero the match data have been saved in saved_search_regs
+/* If true the match data have been saved in saved_search_regs
during the execution of a sentinel or filter. */
-static int search_regs_saved;
+static bool search_regs_saved;
static struct re_registers saved_search_regs;
static Lisp_Object saved_last_thing_searched;
}
}
-static Lisp_Object
+static void
unwind_set_match_data (Lisp_Object list)
{
/* It is NOT ALWAYS safe to free (evaporate) the markers immediately. */
- return Fset_match_data (list, Qt);
+ Fset_match_data (list, Qt);
}
/* Called to unwind protect the match data. */
doc: /* Return a regexp string which matches exactly STRING and nothing else. */)
(Lisp_Object string)
{
- register char *in, *out, *end;
- register char *temp;
- int backslashes_added = 0;
+ char *in, *out, *end;
+ char *temp;
+ ptrdiff_t backslashes_added = 0;
CHECK_STRING (string);