0.12. (Implements POSIX draft P1003.2/D11.2, except for some of the
internationalization features.)
- Copyright (C) 1993, 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001,
- 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, 2010
- Free Software Foundation, Inc.
+ Copyright (C) 1993-2011 Free Software Foundation, Inc.
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
even if config.h says that we can. */
# undef REL_ALLOC
-# if defined STDC_HEADERS || defined _LIBC
-# include <stdlib.h>
-# else
-char *malloc ();
-char *realloc ();
-# endif
+# include <unistd.h>
/* When used in Emacs's lib-src, we need xmalloc and xrealloc. */
void *
-xmalloc (size)
- size_t size;
+xmalloc (size_t size)
{
register void *val;
val = (void *) malloc (size);
}
void *
-xrealloc (block, size)
- void *block;
- size_t size;
+xrealloc (void *block, size_t size)
{
register void *val;
/* We must call malloc explicitly when BLOCK is 0, since some
static char re_syntax_table[CHAR_SET_SIZE];
static void
-init_syntax_once ()
+init_syntax_once (void)
{
register int c;
static int done = 0;
do \
{ \
re_wchar_t range_start, range_end; \
- re_char *p; \
+ re_char *rtp; \
re_char *range_table_end \
= CHARSET_RANGE_TABLE_END ((range_table), (count)); \
\
- for (p = (range_table); p < range_table_end; p += 2 * 3) \
+ for (rtp = (range_table); rtp < range_table_end; rtp += 2 * 3) \
{ \
- EXTRACT_CHARACTER (range_start, p); \
- EXTRACT_CHARACTER (range_end, p + 3); \
+ EXTRACT_CHARACTER (range_start, rtp); \
+ EXTRACT_CHARACTER (range_end, rtp + 3); \
\
if (range_start <= (c) && (c) <= range_end) \
{ \
/* Pop a saved register off the stack. */
#define POP_FAILURE_REG_OR_COUNT() \
do { \
- int reg = POP_FAILURE_INT (); \
- if (reg == -1) \
+ int pfreg = POP_FAILURE_INT (); \
+ if (pfreg == -1) \
{ \
/* It's a counter. */ \
/* Here, we discard `const', making re_match non-reentrant. */ \
unsigned char *ptr = (unsigned char*) POP_FAILURE_POINTER (); \
- reg = POP_FAILURE_INT (); \
- STORE_NUMBER (ptr, reg); \
- DEBUG_PRINT3 (" Pop counter %p = %d\n", ptr, reg); \
+ pfreg = POP_FAILURE_INT (); \
+ STORE_NUMBER (ptr, pfreg); \
+ DEBUG_PRINT3 (" Pop counter %p = %d\n", ptr, pfreg); \
} \
else \
{ \
- regend[reg] = POP_FAILURE_POINTER (); \
- regstart[reg] = POP_FAILURE_POINTER (); \
+ regend[pfreg] = POP_FAILURE_POINTER (); \
+ regstart[pfreg] = POP_FAILURE_POINTER (); \
DEBUG_PRINT4 (" Pop reg %d (spanning %p -> %p)\n", \
- reg, regstart[reg], regend[reg]); \
+ pfreg, regstart[pfreg], regend[pfreg]); \
} \
} while (0)
re_wctype_t
re_wctype (const re_char *str)
{
- const char *string = str;
+ const char *string = (const char *) str;
if (STREQ (string, "alnum")) return RECC_ALNUM;
else if (STREQ (string, "alpha")) return RECC_ALPHA;
else if (STREQ (string, "word")) return RECC_WORD;
/* We fetch characters from PATTERN here. */
register re_wchar_t c, c1;
- /* A random temporary spot in PATTERN. */
- re_char *p1;
-
/* Points to the end of the buffer, where we should append. */
register unsigned char *b;
/* If the object matched can contain multibyte characters. */
const boolean multibyte = RE_MULTIBYTE_P (bufp);
- /* If a target of matching can contain multibyte characters. */
- const boolean target_multibyte = RE_TARGET_MULTIBYTE_P (bufp);
-
/* Nonzero if we have pushed down into a subpattern. */
int in_subpattern = 0;
main_pend = pend;
main_pattern = pattern;
p = pattern = whitespace_regexp;
- pend = p + strlen (p);
+ pend = p + strlen ((const char *) p);
break;
}
case '[':
{
+ re_char *p1;
+
CLEAR_RANGE_TABLE_WORK_USED (range_table_work);
if (p == pend) FREE_STACK_RETURN (REG_EBRACK);
{
boolean escaped_char = false;
const unsigned char *p2 = p;
- re_wchar_t ch, c2;
+ re_wchar_t ch;
if (p == pend) FREE_STACK_RETURN (REG_EBRACK);
them). */
if (c == ':' && *p == ']')
{
- re_wctype_t cc;
- int limit;
-
- cc = re_wctype (str);
+ re_wctype_t cc = re_wctype (str);
if (cc == 0)
FREE_STACK_RETURN (REG_ECTYPE);
{
case succeed:
return 1;
- continue;
case duplicate:
/* If the first character has to match a backreference, that means
&& match_any_multibyte_characters == false)
{
/* Set fastmap[I] to 1 where I is a leading code of each
- multibyte characer in the range table. */
+ multibyte character in the range table. */
int c, count;
unsigned char lc1, lc2;
if (multibyte)
{
re_char *p = POS_ADDR_VSTRING (startpos);
- re_char *pend = STOP_ADDR_VSTRING (startpos);
int len = BYTES_BY_CHAR_HEAD (*p);
range -= len;
/* re_match is like re_match_2 except it takes only a single string. */
int
-re_match (bufp, string, size, pos, regs)
- struct re_pattern_buffer *bufp;
- const char *string;
- int size, pos;
- struct re_registers *regs;
+re_match (struct re_pattern_buffer *bufp, const char *string,
+ int size, int pos, struct re_registers *regs)
{
int result = re_match_2_internal (bufp, NULL, 0, (re_char*) string, size,
pos, regs, size);
/* General temporaries. */
int mcnt;
size_t reg;
- boolean not;
/* Just past the end of the corresponding string. */
re_char *end1, *end2;
else
do
{
- int pat_charlen, buf_charlen;
+ int pat_charlen;
int pat_ch, buf_ch;
PREFETCH ();
if (!not) goto fail;
d += len;
- break;
}
+ break;
/* The beginning of a group is represented by start_memory.
case wordbound:
case notwordbound:
- not = (re_opcode_t) *(p - 1) == notwordbound;
- DEBUG_PRINT2 ("EXECUTING %swordbound.\n", not?"not":"");
+ {
+ boolean not = (re_opcode_t) *(p - 1) == notwordbound;
+ DEBUG_PRINT2 ("EXECUTING %swordbound.\n", not?"not":"");
- /* We SUCCEED (or FAIL) in one of the following cases: */
+ /* We SUCCEED (or FAIL) in one of the following cases: */
- /* Case 1: D is at the beginning or the end of string. */
- if (AT_STRINGS_BEG (d) || AT_STRINGS_END (d))
- not = !not;
- else
- {
- /* C1 is the character before D, S1 is the syntax of C1, C2
- is the character at D, and S2 is the syntax of C2. */
- re_wchar_t c1, c2;
- int s1, s2;
- int dummy;
+ /* Case 1: D is at the beginning or the end of string. */
+ if (AT_STRINGS_BEG (d) || AT_STRINGS_END (d))
+ not = !not;
+ else
+ {
+ /* C1 is the character before D, S1 is the syntax of C1, C2
+ is the character at D, and S2 is the syntax of C2. */
+ re_wchar_t c1, c2;
+ int s1, s2;
+ int dummy;
#ifdef emacs
- int offset = PTR_TO_OFFSET (d - 1);
- int charpos = SYNTAX_TABLE_BYTE_TO_CHAR (offset);
- UPDATE_SYNTAX_TABLE (charpos);
+ int offset = PTR_TO_OFFSET (d - 1);
+ int charpos = SYNTAX_TABLE_BYTE_TO_CHAR (offset);
+ UPDATE_SYNTAX_TABLE (charpos);
#endif
- GET_CHAR_BEFORE_2 (c1, d, string1, end1, string2, end2);
- s1 = SYNTAX (c1);
+ GET_CHAR_BEFORE_2 (c1, d, string1, end1, string2, end2);
+ s1 = SYNTAX (c1);
#ifdef emacs
- UPDATE_SYNTAX_TABLE_FORWARD (charpos + 1);
+ UPDATE_SYNTAX_TABLE_FORWARD (charpos + 1);
#endif
- PREFETCH_NOLIMIT ();
- GET_CHAR_AFTER (c2, d, dummy);
- s2 = SYNTAX (c2);
-
- if (/* Case 2: Only one of S1 and S2 is Sword. */
- ((s1 == Sword) != (s2 == Sword))
- /* Case 3: Both of S1 and S2 are Sword, and macro
- WORD_BOUNDARY_P (C1, C2) returns nonzero. */
- || ((s1 == Sword) && WORD_BOUNDARY_P (c1, c2)))
- not = !not;
- }
- if (not)
- break;
- else
- goto fail;
+ PREFETCH_NOLIMIT ();
+ GET_CHAR_AFTER (c2, d, dummy);
+ s2 = SYNTAX (c2);
+
+ if (/* Case 2: Only one of S1 and S2 is Sword. */
+ ((s1 == Sword) != (s2 == Sword))
+ /* Case 3: Both of S1 and S2 are Sword, and macro
+ WORD_BOUNDARY_P (C1, C2) returns nonzero. */
+ || ((s1 == Sword) && WORD_BOUNDARY_P (c1, c2)))
+ not = !not;
+ }
+ if (not)
+ break;
+ else
+ goto fail;
+ }
case wordbeg:
DEBUG_PRINT1 ("EXECUTING wordbeg.\n");
case syntaxspec:
case notsyntaxspec:
- not = (re_opcode_t) *(p - 1) == notsyntaxspec;
- mcnt = *p++;
- DEBUG_PRINT3 ("EXECUTING %ssyntaxspec %d.\n", not?"not":"", mcnt);
- PREFETCH ();
-#ifdef emacs
{
- int offset = PTR_TO_OFFSET (d);
- int pos1 = SYNTAX_TABLE_BYTE_TO_CHAR (offset);
- UPDATE_SYNTAX_TABLE (pos1);
- }
+ boolean not = (re_opcode_t) *(p - 1) == notsyntaxspec;
+ mcnt = *p++;
+ DEBUG_PRINT3 ("EXECUTING %ssyntaxspec %d.\n", not?"not":"", mcnt);
+ PREFETCH ();
+#ifdef emacs
+ {
+ int offset = PTR_TO_OFFSET (d);
+ int pos1 = SYNTAX_TABLE_BYTE_TO_CHAR (offset);
+ UPDATE_SYNTAX_TABLE (pos1);
+ }
#endif
- {
- int len;
- re_wchar_t c;
+ {
+ int len;
+ re_wchar_t c;
- GET_CHAR_AFTER (c, d, len);
- if ((SYNTAX (c) != (enum syntaxcode) mcnt) ^ not)
- goto fail;
- d += len;
+ GET_CHAR_AFTER (c, d, len);
+ if ((SYNTAX (c) != (enum syntaxcode) mcnt) ^ not)
+ goto fail;
+ d += len;
+ }
}
break;
case categoryspec:
case notcategoryspec:
- not = (re_opcode_t) *(p - 1) == notcategoryspec;
- mcnt = *p++;
- DEBUG_PRINT3 ("EXECUTING %scategoryspec %d.\n", not?"not":"", mcnt);
- PREFETCH ();
{
- int len;
- re_wchar_t c;
+ boolean not = (re_opcode_t) *(p - 1) == notcategoryspec;
+ mcnt = *p++;
+ DEBUG_PRINT3 ("EXECUTING %scategoryspec %d.\n",
+ not?"not":"", mcnt);
+ PREFETCH ();
- GET_CHAR_AFTER (c, d, len);
- if ((!CHAR_HAS_CATEGORY (c, mcnt)) ^ not)
- goto fail;
- d += len;
+ {
+ int len;
+ re_wchar_t c;
+ GET_CHAR_AFTER (c, d, len);
+ if ((!CHAR_HAS_CATEGORY (c, mcnt)) ^ not)
+ goto fail;
+ d += len;
+ }
}
break;
the return codes and their meanings.) */
int
-regcomp (preg, pattern, cflags)
- regex_t *__restrict preg;
- const char *__restrict pattern;
- int cflags;
+regcomp (regex_t *__restrict preg, const char *__restrict pattern,
+ int cflags)
{
reg_errcode_t ret;
reg_syntax_t syntax
We return 0 if we find a match and REG_NOMATCH if not. */
int
-regexec (preg, string, nmatch, pmatch, eflags)
- const regex_t *__restrict preg;
- const char *__restrict string;
- size_t nmatch;
- regmatch_t pmatch[__restrict_arr];
- int eflags;
+regexec (const regex_t *__restrict preg, const char *__restrict string,
+ size_t nmatch, regmatch_t pmatch[__restrict_arr], int eflags)
{
int ret;
struct re_registers regs;
error with msvc8 compiler. */
size_t
-regerror (err_code, preg, errbuf, errbuf_size)
- int err_code;
- const regex_t *preg;
- char *errbuf;
- size_t errbuf_size;
+regerror (int err_code, const regex_t *preg, char *errbuf, size_t errbuf_size)
{
const char *msg;
size_t msg_size;
/* Free dynamically allocated space used by PREG. */
void
-regfree (preg)
- regex_t *preg;
+regfree (regex_t *preg)
{
free (preg->buffer);
preg->buffer = NULL;
WEAK_ALIAS (__regfree, regfree)
#endif /* not emacs */
-
-/* arch-tag: 4ffd68ba-2a9e-435b-a21a-018990f9eeb2
- (do not change this comment) */