2 |
version 0.12. |
version 0.12. |
3 |
(Implements POSIX draft P1003.2/D11.2, except for some of the |
(Implements POSIX draft P1003.2/D11.2, except for some of the |
4 |
internationalization features.) |
internationalization features.) |
5 |
Copyright (C) 1993-1999, 2000, 2001 Free Software Foundation, Inc. |
Copyright (C) 1993-1999, 2000, 2001, 2002 Free Software Foundation, Inc. |
6 |
This file is part of the GNU C Library. |
This file is part of the GNU C Library. |
7 |
|
|
8 |
The GNU C Library is free software; you can redistribute it and/or |
The GNU C Library is free software; you can redistribute it and/or |
25 |
routines with an "x" prefix so they do not collide with the native regex |
routines with an "x" prefix so they do not collide with the native regex |
26 |
routines or with other components regex routines. */ |
routines or with other components regex routines. */ |
27 |
/* AIX requires this to be the first thing in the file. */ |
/* AIX requires this to be the first thing in the file. */ |
28 |
#if defined _AIX && !defined REGEX_MALLOC |
#if defined _AIX && !defined __GNUC__ && !defined REGEX_MALLOC |
29 |
#pragma alloca |
#pragma alloca |
30 |
#endif |
#endif |
31 |
|
|
32 |
#undef _GNU_SOURCE |
#undef _GNU_SOURCE |
33 |
#define _GNU_SOURCE |
#define _GNU_SOURCE |
34 |
|
|
35 |
#ifdef HAVE_CONFIG_H |
#ifndef INSIDE_RECURSION |
36 |
# include <config.h> |
# ifdef HAVE_CONFIG_H |
37 |
|
# include <config.h> |
38 |
|
# endif |
39 |
#endif |
#endif |
40 |
|
|
41 |
|
#include <ansidecl.h> |
42 |
|
|
43 |
#ifndef PARAMS |
#ifndef PARAMS |
44 |
# if defined __GNUC__ || (defined __STDC__ && __STDC__) |
# if defined __GNUC__ || (defined __STDC__ && __STDC__) |
45 |
# define PARAMS(args) args |
# define PARAMS(args) args |
1377 |
POSIX doesn't require that we do anything for REG_NOERROR, |
POSIX doesn't require that we do anything for REG_NOERROR, |
1378 |
but why not be nice? */ |
but why not be nice? */ |
1379 |
|
|
1380 |
static const char re_error_msgid[] = |
static const char *re_error_msgid[] = |
1381 |
{ |
{ |
1382 |
# define REG_NOERROR_IDX 0 |
gettext_noop ("Success"), /* REG_NOERROR */ |
1383 |
gettext_noop ("Success") /* REG_NOERROR */ |
gettext_noop ("No match"), /* REG_NOMATCH */ |
1384 |
"\0" |
gettext_noop ("Invalid regular expression"), /* REG_BADPAT */ |
1385 |
# define REG_NOMATCH_IDX (REG_NOERROR_IDX + sizeof "Success") |
gettext_noop ("Invalid collation character"), /* REG_ECOLLATE */ |
1386 |
gettext_noop ("No match") /* REG_NOMATCH */ |
gettext_noop ("Invalid character class name"), /* REG_ECTYPE */ |
1387 |
"\0" |
gettext_noop ("Trailing backslash"), /* REG_EESCAPE */ |
1388 |
# define REG_BADPAT_IDX (REG_NOMATCH_IDX + sizeof "No match") |
gettext_noop ("Invalid back reference"), /* REG_ESUBREG */ |
1389 |
gettext_noop ("Invalid regular expression") /* REG_BADPAT */ |
gettext_noop ("Unmatched [ or [^"), /* REG_EBRACK */ |
1390 |
"\0" |
gettext_noop ("Unmatched ( or \\("), /* REG_EPAREN */ |
1391 |
# define REG_ECOLLATE_IDX (REG_BADPAT_IDX + sizeof "Invalid regular expression") |
gettext_noop ("Unmatched \\{"), /* REG_EBRACE */ |
1392 |
gettext_noop ("Invalid collation character") /* REG_ECOLLATE */ |
gettext_noop ("Invalid content of \\{\\}"), /* REG_BADBR */ |
1393 |
"\0" |
gettext_noop ("Invalid range end"), /* REG_ERANGE */ |
1394 |
# define REG_ECTYPE_IDX (REG_ECOLLATE_IDX + sizeof "Invalid collation character") |
gettext_noop ("Memory exhausted"), /* REG_ESPACE */ |
1395 |
gettext_noop ("Invalid character class name") /* REG_ECTYPE */ |
gettext_noop ("Invalid preceding regular expression"), /* REG_BADRPT */ |
1396 |
"\0" |
gettext_noop ("Premature end of regular expression"), /* REG_EEND */ |
1397 |
# define REG_EESCAPE_IDX (REG_ECTYPE_IDX + sizeof "Invalid character class name") |
gettext_noop ("Regular expression too big"), /* REG_ESIZE */ |
|
gettext_noop ("Trailing backslash") /* REG_EESCAPE */ |
|
|
"\0" |
|
|
# define REG_ESUBREG_IDX (REG_EESCAPE_IDX + sizeof "Trailing backslash") |
|
|
gettext_noop ("Invalid back reference") /* REG_ESUBREG */ |
|
|
"\0" |
|
|
# define REG_EBRACK_IDX (REG_ESUBREG_IDX + sizeof "Invalid back reference") |
|
|
gettext_noop ("Unmatched [ or [^") /* REG_EBRACK */ |
|
|
"\0" |
|
|
# define REG_EPAREN_IDX (REG_EBRACK_IDX + sizeof "Unmatched [ or [^") |
|
|
gettext_noop ("Unmatched ( or \\(") /* REG_EPAREN */ |
|
|
"\0" |
|
|
# define REG_EBRACE_IDX (REG_EPAREN_IDX + sizeof "Unmatched ( or \\(") |
|
|
gettext_noop ("Unmatched \\{") /* REG_EBRACE */ |
|
|
"\0" |
|
|
# define REG_BADBR_IDX (REG_EBRACE_IDX + sizeof "Unmatched \\{") |
|
|
gettext_noop ("Invalid content of \\{\\}") /* REG_BADBR */ |
|
|
"\0" |
|
|
# define REG_ERANGE_IDX (REG_BADBR_IDX + sizeof "Invalid content of \\{\\}") |
|
|
gettext_noop ("Invalid range end") /* REG_ERANGE */ |
|
|
"\0" |
|
|
# define REG_ESPACE_IDX (REG_ERANGE_IDX + sizeof "Invalid range end") |
|
|
gettext_noop ("Memory exhausted") /* REG_ESPACE */ |
|
|
"\0" |
|
|
# define REG_BADRPT_IDX (REG_ESPACE_IDX + sizeof "Memory exhausted") |
|
|
gettext_noop ("Invalid preceding regular expression") /* REG_BADRPT */ |
|
|
"\0" |
|
|
# define REG_EEND_IDX (REG_BADRPT_IDX + sizeof "Invalid preceding regular expression") |
|
|
gettext_noop ("Premature end of regular expression") /* REG_EEND */ |
|
|
"\0" |
|
|
# define REG_ESIZE_IDX (REG_EEND_IDX + sizeof "Premature end of regular expression") |
|
|
gettext_noop ("Regular expression too big") /* REG_ESIZE */ |
|
|
"\0" |
|
|
# define REG_ERPAREN_IDX (REG_ESIZE_IDX + sizeof "Regular expression too big") |
|
1398 |
gettext_noop ("Unmatched ) or \\)") /* REG_ERPAREN */ |
gettext_noop ("Unmatched ) or \\)") /* REG_ERPAREN */ |
1399 |
}; |
}; |
|
|
|
|
static const size_t re_error_msgid_idx[] = |
|
|
{ |
|
|
REG_NOERROR_IDX, |
|
|
REG_NOMATCH_IDX, |
|
|
REG_BADPAT_IDX, |
|
|
REG_ECOLLATE_IDX, |
|
|
REG_ECTYPE_IDX, |
|
|
REG_EESCAPE_IDX, |
|
|
REG_ESUBREG_IDX, |
|
|
REG_EBRACK_IDX, |
|
|
REG_EPAREN_IDX, |
|
|
REG_EBRACE_IDX, |
|
|
REG_BADBR_IDX, |
|
|
REG_ERANGE_IDX, |
|
|
REG_ESPACE_IDX, |
|
|
REG_BADRPT_IDX, |
|
|
REG_EEND_IDX, |
|
|
REG_ESIZE_IDX, |
|
|
REG_ERPAREN_IDX |
|
|
}; |
|
1400 |
|
|
1401 |
#endif /* INSIDE_RECURSION */ |
#endif /* INSIDE_RECURSION */ |
1402 |
|
|
4652 |
|
|
4653 |
while (1) |
while (1) |
4654 |
{ |
{ |
4655 |
if (p == pend || *p == succeed) |
if (p == pend || *p == (UCHAR_T) succeed) |
4656 |
{ |
{ |
4657 |
/* We have reached the (effective) end of pattern. */ |
/* We have reached the (effective) end of pattern. */ |
4658 |
if (!FAIL_STACK_EMPTY ()) |
if (!FAIL_STACK_EMPTY ()) |
7894 |
|
|
7895 |
if (!ret) |
if (!ret) |
7896 |
return NULL; |
return NULL; |
7897 |
return gettext (re_error_msgid + re_error_msgid_idx[(int) ret]); |
return gettext (re_error_msgid[(int) ret]); |
7898 |
} |
} |
7899 |
#ifdef _LIBC |
#ifdef _LIBC |
7900 |
weak_alias (__re_compile_pattern, re_compile_pattern) |
weak_alias (__re_compile_pattern, re_compile_pattern) |
7931 |
{ |
{ |
7932 |
re_comp_buf.buffer = (unsigned char *) malloc (200); |
re_comp_buf.buffer = (unsigned char *) malloc (200); |
7933 |
if (re_comp_buf.buffer == NULL) |
if (re_comp_buf.buffer == NULL) |
7934 |
return (char *) gettext (re_error_msgid |
return (char *) gettext (re_error_msgid[(int) REG_ESPACE]); |
|
+ re_error_msgid_idx[(int) REG_ESPACE]); |
|
7935 |
re_comp_buf.allocated = 200; |
re_comp_buf.allocated = 200; |
7936 |
|
|
7937 |
re_comp_buf.fastmap = (char *) malloc (1 << BYTEWIDTH); |
re_comp_buf.fastmap = (char *) malloc (1 << BYTEWIDTH); |
7938 |
if (re_comp_buf.fastmap == NULL) |
if (re_comp_buf.fastmap == NULL) |
7939 |
return (char *) gettext (re_error_msgid |
return (char *) gettext (re_error_msgid[(int) REG_ESPACE]); |
|
+ re_error_msgid_idx[(int) REG_ESPACE]); |
|
7940 |
} |
} |
7941 |
|
|
7942 |
/* Since `re_exec' always passes NULL for the `regs' argument, we |
/* Since `re_exec' always passes NULL for the `regs' argument, we |
7956 |
return NULL; |
return NULL; |
7957 |
|
|
7958 |
/* Yes, we're discarding `const' here if !HAVE_LIBINTL. */ |
/* Yes, we're discarding `const' here if !HAVE_LIBINTL. */ |
7959 |
return (char *) gettext (re_error_msgid + re_error_msgid_idx[(int) ret]); |
return (char *) gettext (re_error_msgid[(int) ret]); |
7960 |
} |
} |
7961 |
|
|
7962 |
|
|
8044 |
|
|
8045 |
/* Map uppercase characters to corresponding lowercase ones. */ |
/* Map uppercase characters to corresponding lowercase ones. */ |
8046 |
for (i = 0; i < CHAR_SET_SIZE; i++) |
for (i = 0; i < CHAR_SET_SIZE; i++) |
8047 |
preg->translate[i] = ISUPPER (i) ? TOLOWER (i) : i; |
preg->translate[i] = ISUPPER (i) ? TOLOWER (i) : (int) i; |
8048 |
} |
} |
8049 |
else |
else |
8050 |
preg->translate = NULL; |
preg->translate = NULL; |
8179 |
size_t |
size_t |
8180 |
regerror (errcode, preg, errbuf, errbuf_size) |
regerror (errcode, preg, errbuf, errbuf_size) |
8181 |
int errcode; |
int errcode; |
8182 |
const regex_t *preg; |
const regex_t *preg ATTRIBUTE_UNUSED; |
8183 |
char *errbuf; |
char *errbuf; |
8184 |
size_t errbuf_size; |
size_t errbuf_size; |
8185 |
{ |
{ |
8187 |
size_t msg_size; |
size_t msg_size; |
8188 |
|
|
8189 |
if (errcode < 0 |
if (errcode < 0 |
8190 |
|| errcode >= (int) (sizeof (re_error_msgid_idx) |
|| errcode >= (int) (sizeof (re_error_msgid) |
8191 |
/ sizeof (re_error_msgid_idx[0]))) |
/ sizeof (re_error_msgid[0]))) |
8192 |
/* Only error codes returned by the rest of the code should be passed |
/* Only error codes returned by the rest of the code should be passed |
8193 |
to this routine. If we are given anything else, or if other regex |
to this routine. If we are given anything else, or if other regex |
8194 |
code generates an invalid error code, then the program has a bug. |
code generates an invalid error code, then the program has a bug. |
8195 |
Dump core so we can fix it. */ |
Dump core so we can fix it. */ |
8196 |
abort (); |
abort (); |
8197 |
|
|
8198 |
msg = gettext (re_error_msgid + re_error_msgid_idx[errcode]); |
msg = gettext (re_error_msgid[errcode]); |
8199 |
|
|
8200 |
msg_size = strlen (msg) + 1; /* Includes the null. */ |
msg_size = strlen (msg) + 1; /* Includes the null. */ |
8201 |
|
|
8204 |
if (msg_size > errbuf_size) |
if (msg_size > errbuf_size) |
8205 |
{ |
{ |
8206 |
#if defined HAVE_MEMPCPY || defined _LIBC |
#if defined HAVE_MEMPCPY || defined _LIBC |
8207 |
*((char *) __mempcpy (errbuf, msg, errbuf_size - 1)) = '\0'; |
*((char *) mempcpy (errbuf, msg, errbuf_size - 1)) = '\0'; |
8208 |
#else |
#else |
8209 |
memcpy (errbuf, msg, errbuf_size - 1); |
memcpy (errbuf, msg, errbuf_size - 1); |
8210 |
errbuf[errbuf_size - 1] = 0; |
errbuf[errbuf_size - 1] = 0; |