update from glibc

This commit is contained in:
Jim Meyering 1998-08-07 12:54:51 +00:00
parent 2fe9a639e5
commit 26abcd14d2
2 changed files with 138 additions and 26 deletions

View File

@ -59,6 +59,31 @@
# include <wctype.h> # include <wctype.h>
#endif #endif
#ifdef _LIBC
/* We have to keep the namespace clean. */
# define regfree(preg) __regfree (preg)
# define regexec(pr, st, nm, pm, ef) __regexec (pr, st, nm, pm, ef)
# define regcomp(preg, pattern, cflags) __regcomp (preg, pattern, cflags)
# define regerror(errcode, preg, errbuf, errbuf_size) \
__regerror(errcode, preg, errbuf, errbuf_size)
# define re_set_registers(bu, re, nu, st, en) \
__re_set_registers (bu, re, nu, st, en)
# define re_match_2(bufp, string1, size1, string2, size2, pos, regs, stop) \
__re_match_2 (bufp, string1, size1, string2, size2, pos, regs, stop)
# define re_match(bufp, string, size, pos, regs) \
__re_match (bufp, string, size, pos, regs)
# define re_search(bufp, string, size, startpos, range, regs) \
__re_search (bufp, string, size, startpos, range, regs)
# define re_compile_pattern(pattern, length, bufp) \
__re_compile_pattern (pattern, length, bufp)
# define re_set_syntax(syntax) __re_set_syntax (syntax)
# define re_search_2(bufp, st1, s1, st2, s2, startpos, range, regs, stop) \
__re_search_2 (bufp, st1, s1, st2, s2, startpos, range, regs, stop)
# define re_compile_fastmap(bufp) __re_compile_fastmap (bufp)
#define btowc __btowc
#endif
/* This is for other GNU distributions with internationalized messages. */ /* This is for other GNU distributions with internationalized messages. */
#if HAVE_LIBINTL_H || defined _LIBC #if HAVE_LIBINTL_H || defined _LIBC
# include <libintl.h> # include <libintl.h>
@ -110,8 +135,12 @@ char *realloc ();
# ifndef INHIBIT_STRING_HEADER # ifndef INHIBIT_STRING_HEADER
# if defined HAVE_STRING_H || defined STDC_HEADERS || defined _LIBC # if defined HAVE_STRING_H || defined STDC_HEADERS || defined _LIBC
# include <string.h> # include <string.h>
# if !defined bzero && !defined _LIBC # ifndef bzero
# define bzero(s, n) (memset (s, '\0', n), (s)) # ifndef _LIBC
# define bzero(s, n) (memset (s, '\0', n), (s))
# else
# define bzero(s, n) __bzero (s, n)
# endif
# endif # endif
# else # else
# include <strings.h> # include <strings.h>
@ -195,7 +224,8 @@ init_syntax_once ()
STDC_HEADERS is defined, then autoconf has verified that the ctype STDC_HEADERS is defined, then autoconf has verified that the ctype
macros don't need to be guarded with references to isascii. ... macros don't need to be guarded with references to isascii. ...
Defining isascii to 1 should let any compiler worth its salt Defining isascii to 1 should let any compiler worth its salt
eliminate the && through constant folding." */ eliminate the && through constant folding."
Solaris defines some of these symbols so we must undefine them first. */
#undef ISASCII #undef ISASCII
#if defined STDC_HEADERS || (!defined isascii && !defined HAVE_ISASCII) #if defined STDC_HEADERS || (!defined isascii && !defined HAVE_ISASCII)
@ -971,6 +1001,9 @@ re_set_syntax (syntax)
#endif /* DEBUG */ #endif /* DEBUG */
return ret; return ret;
} }
#ifdef _LIBC
weak_alias (__re_set_syntax, re_set_syntax)
#endif
/* This table gives an error message for each of the error codes listed /* This table gives an error message for each of the error codes listed
in regex.h. Obviously the order here has to be same as there. in regex.h. Obviously the order here has to be same as there.
@ -1699,7 +1732,11 @@ typedef struct
# define CHAR_CLASS_MAX_LENGTH 256 # define CHAR_CLASS_MAX_LENGTH 256
# endif # endif
# define IS_CHAR_CLASS(string) wctype (string) # ifdef _LIBC
# define IS_CHAR_CLASS(string) __wctype (string)
# else
# define IS_CHAR_CLASS(string) wctype (string)
# endif
#else #else
# define CHAR_CLASS_MAX_LENGTH 6 /* Namely, `xdigit'. */ # define CHAR_CLASS_MAX_LENGTH 6 /* Namely, `xdigit'. */
@ -2176,14 +2213,14 @@ regex_compile (pattern, size, syntax, bufp)
for (;;) for (;;)
{ {
PATFETCH (c); PATFETCH (c);
if (c == ':' || c == ']' || p == pend if ((c == ':' && *p == ']') || p == pend
|| c1 == CHAR_CLASS_MAX_LENGTH) || c1 == CHAR_CLASS_MAX_LENGTH)
break; break;
str[c1++] = c; str[c1++] = c;
} }
str[c1] = '\0'; str[c1] = '\0';
/* If isn't a word bracketed by `[:' and:`]': /* If isn't a word bracketed by `[:' and `:]':
undo the ending character, the letters, and leave undo the ending character, the letters, and leave
the leading `:' and `[' (but set bits for them). */ the leading `:' and `[' (but set bits for them). */
if (c == ':' && *p == ']') if (c == ':' && *p == ']')
@ -2194,7 +2231,7 @@ regex_compile (pattern, size, syntax, bufp)
wctype_t wt; wctype_t wt;
int ch; int ch;
wt = wctype (str); wt = IS_CHAR_CLASS (str);
if (wt == 0) if (wt == 0)
FREE_STACK_RETURN (REG_ECTYPE); FREE_STACK_RETURN (REG_ECTYPE);
@ -2206,8 +2243,13 @@ regex_compile (pattern, size, syntax, bufp)
for (ch = 0; ch < 1 << BYTEWIDTH; ++ch) for (ch = 0; ch < 1 << BYTEWIDTH; ++ch)
{ {
# ifdef _LIBC
if (__iswctype (__btowc (ch), wt))
SET_LIST_BIT (ch);
#else
if (iswctype (btowc (ch), wt)) if (iswctype (btowc (ch), wt))
SET_LIST_BIT (ch); SET_LIST_BIT (ch);
#endif
if (translate && (is_upper || is_lower) if (translate && (is_upper || is_lower)
&& (ISUPPER (ch) || ISLOWER (ch))) && (ISUPPER (ch) || ISLOWER (ch)))
@ -2691,7 +2733,7 @@ regex_compile (pattern, size, syntax, bufp)
case 'w': case 'w':
if (re_syntax_options & RE_NO_GNU_OPS) if (syntax & RE_NO_GNU_OPS)
goto normal_char; goto normal_char;
laststart = b; laststart = b;
BUF_PUSH (wordchar); BUF_PUSH (wordchar);
@ -2699,7 +2741,7 @@ regex_compile (pattern, size, syntax, bufp)
case 'W': case 'W':
if (re_syntax_options & RE_NO_GNU_OPS) if (syntax & RE_NO_GNU_OPS)
goto normal_char; goto normal_char;
laststart = b; laststart = b;
BUF_PUSH (notwordchar); BUF_PUSH (notwordchar);
@ -2707,37 +2749,37 @@ regex_compile (pattern, size, syntax, bufp)
case '<': case '<':
if (re_syntax_options & RE_NO_GNU_OPS) if (syntax & RE_NO_GNU_OPS)
goto normal_char; goto normal_char;
BUF_PUSH (wordbeg); BUF_PUSH (wordbeg);
break; break;
case '>': case '>':
if (re_syntax_options & RE_NO_GNU_OPS) if (syntax & RE_NO_GNU_OPS)
goto normal_char; goto normal_char;
BUF_PUSH (wordend); BUF_PUSH (wordend);
break; break;
case 'b': case 'b':
if (re_syntax_options & RE_NO_GNU_OPS) if (syntax & RE_NO_GNU_OPS)
goto normal_char; goto normal_char;
BUF_PUSH (wordbound); BUF_PUSH (wordbound);
break; break;
case 'B': case 'B':
if (re_syntax_options & RE_NO_GNU_OPS) if (syntax & RE_NO_GNU_OPS)
goto normal_char; goto normal_char;
BUF_PUSH (notwordbound); BUF_PUSH (notwordbound);
break; break;
case '`': case '`':
if (re_syntax_options & RE_NO_GNU_OPS) if (syntax & RE_NO_GNU_OPS)
goto normal_char; goto normal_char;
BUF_PUSH (begbuf); BUF_PUSH (begbuf);
break; break;
case '\'': case '\'':
if (re_syntax_options & RE_NO_GNU_OPS) if (syntax & RE_NO_GNU_OPS)
goto normal_char; goto normal_char;
BUF_PUSH (endbuf); BUF_PUSH (endbuf);
break; break;
@ -3375,6 +3417,9 @@ re_compile_fastmap (bufp)
RESET_FAIL_STACK (); RESET_FAIL_STACK ();
return 0; return 0;
} /* re_compile_fastmap */ } /* re_compile_fastmap */
#ifdef _LIBC
weak_alias (__re_compile_fastmap, re_compile_fastmap)
#endif
/* Set REGS to hold NUM_REGS registers, storing them in STARTS and /* Set REGS to hold NUM_REGS registers, storing them in STARTS and
ENDS. Subsequent matches using PATTERN_BUFFER and REGS will use ENDS. Subsequent matches using PATTERN_BUFFER and REGS will use
@ -3410,6 +3455,9 @@ re_set_registers (bufp, regs, num_regs, starts, ends)
regs->start = regs->end = (regoff_t *) 0; regs->start = regs->end = (regoff_t *) 0;
} }
} }
#ifdef _LIBC
weak_alias (__re_set_registers, re_set_registers)
#endif
/* Searching routines. */ /* Searching routines. */
@ -3426,6 +3474,9 @@ re_search (bufp, string, size, startpos, range, regs)
return re_search_2 (bufp, NULL, 0, string, size, startpos, range, return re_search_2 (bufp, NULL, 0, string, size, startpos, range,
regs, size); regs, size);
} }
#ifdef _LIBC
weak_alias (__re_search, re_search)
#endif
/* Using the compiled pattern in BUFP->buffer, first tries to match the /* Using the compiled pattern in BUFP->buffer, first tries to match the
@ -3479,7 +3530,11 @@ re_search_2 (bufp, string1, size1, string2, size2, startpos, range, regs, stop)
/* If the search isn't to be a backwards one, don't waste time in a /* If the search isn't to be a backwards one, don't waste time in a
search for a pattern that must be anchored. */ search for a pattern that must be anchored. */
if (bufp->used > 0 && (re_opcode_t) bufp->buffer[0] == begbuf && range > 0) if (bufp->used > 0 && range > 0
&& ((re_opcode_t) bufp->buffer[0] == begbuf
/* `begline' is like `begbuf' if it cannot match at newlines. */
|| ((re_opcode_t) bufp->buffer[0] == begline
&& !bufp->newline_anchor)))
{ {
if (startpos > 0) if (startpos > 0)
return -1; return -1;
@ -3582,6 +3637,9 @@ re_search_2 (bufp, string1, size1, string2, size2, startpos, range, regs, stop)
} }
return -1; return -1;
} /* re_search_2 */ } /* re_search_2 */
#ifdef _LIBC
weak_alias (__re_search_2, re_search_2)
#endif
/* This converts PTR, a pointer into one of the search strings `string1' /* This converts PTR, a pointer into one of the search strings `string1'
and `string2' into an offset from the beginning of that string. */ and `string2' into an offset from the beginning of that string. */
@ -3683,6 +3741,9 @@ re_match (bufp, string, size, pos, regs)
# endif # endif
return result; return result;
} }
# ifdef _LIBC
weak_alias (__re_match, re_match)
# endif
#endif /* not emacs */ #endif /* not emacs */
static boolean group_match_null_string_p _RE_ARGS ((unsigned char **p, static boolean group_match_null_string_p _RE_ARGS ((unsigned char **p,
@ -3728,6 +3789,9 @@ re_match_2 (bufp, string1, size1, string2, size2, pos, regs, stop)
#endif #endif
return result; return result;
} }
#ifdef _LIBC
weak_alias (__re_match_2, re_match_2)
#endif
/* This is a separate function so that we can force an alloca cleanup /* This is a separate function so that we can force an alloca cleanup
afterwards. */ afterwards. */
@ -5421,6 +5485,9 @@ re_compile_pattern (pattern, length, bufp)
return NULL; return NULL;
return gettext (re_error_msgid[(int) ret]); return gettext (re_error_msgid[(int) ret]);
} }
#ifdef _LIBC
weak_alias (__re_compile_pattern, re_compile_pattern)
#endif
/* Entry points compatible with 4.2 BSD regex library. We don't define /* Entry points compatible with 4.2 BSD regex library. We don't define
them unless specifically requested. */ them unless specifically requested. */
@ -5453,12 +5520,12 @@ re_comp (s)
{ {
re_comp_buf.buffer = (unsigned char *) malloc (200); re_comp_buf.buffer = (unsigned char *) malloc (200);
if (re_comp_buf.buffer == NULL) if (re_comp_buf.buffer == NULL)
return gettext (re_error_msgid[(int) REG_ESPACE]); return (char *) gettext (re_error_msgid[(int) REG_ESPACE]);
re_comp_buf.allocated = 200; re_comp_buf.allocated = 200;
re_comp_buf.fastmap = (char *) malloc (1 << BYTEWIDTH); re_comp_buf.fastmap = (char *) malloc (1 << BYTEWIDTH);
if (re_comp_buf.fastmap == NULL) if (re_comp_buf.fastmap == NULL)
return gettext (re_error_msgid[(int) REG_ESPACE]); return (char *) gettext (re_error_msgid[(int) REG_ESPACE]);
} }
/* Since `re_exec' always passes NULL for the `regs' argument, we /* Since `re_exec' always passes NULL for the `regs' argument, we
@ -5591,6 +5658,9 @@ regcomp (preg, pattern, cflags)
return (int) ret; return (int) ret;
} }
#ifdef _LIBC
weak_alias (__regcomp, regcomp)
#endif
/* regexec searches for a given pattern, specified by PREG, in the /* regexec searches for a given pattern, specified by PREG, in the
@ -5667,6 +5737,9 @@ regexec (preg, string, nmatch, pmatch, eflags)
/* We want zero return to mean success, unlike `re_search'. */ /* We want zero return to mean success, unlike `re_search'. */
return ret >= 0 ? (int) REG_NOERROR : (int) REG_NOMATCH; return ret >= 0 ? (int) REG_NOERROR : (int) REG_NOMATCH;
} }
#ifdef _LIBC
weak_alias (__regexec, regexec)
#endif
/* Returns a message corresponding to an error code, ERRCODE, returned /* Returns a message corresponding to an error code, ERRCODE, returned
@ -5712,6 +5785,9 @@ regerror (errcode, preg, errbuf, errbuf_size)
return msg_size; return msg_size;
} }
#ifdef _LIBC
weak_alias (__regerror, regerror)
#endif
/* Free dynamically allocated space used by PREG. */ /* Free dynamically allocated space used by PREG. */
@ -5736,5 +5812,8 @@ regfree (preg)
free (preg->translate); free (preg->translate);
preg->translate = NULL; preg->translate = NULL;
} }
#ifdef _LIBC
weak_alias (__regfree, regfree)
#endif
#endif /* not emacs */ #endif /* not emacs */

View File

@ -442,11 +442,15 @@ typedef struct
/* Sets the current default syntax to SYNTAX, and return the old syntax. /* Sets the current default syntax to SYNTAX, and return the old syntax.
You can also simply assign to the `re_syntax_options' variable. */ You can also simply assign to the `re_syntax_options' variable. */
extern reg_syntax_t __re_set_syntax _RE_ARGS ((reg_syntax_t syntax));
extern reg_syntax_t re_set_syntax _RE_ARGS ((reg_syntax_t syntax)); extern reg_syntax_t re_set_syntax _RE_ARGS ((reg_syntax_t syntax));
/* Compile the regular expression PATTERN, with length LENGTH /* Compile the regular expression PATTERN, with length LENGTH
and syntax given by the global `re_syntax_options', into the buffer and syntax given by the global `re_syntax_options', into the buffer
BUFFER. Return NULL if successful, and an error string if not. */ BUFFER. Return NULL if successful, and an error string if not. */
extern const char *__re_compile_pattern
_RE_ARGS ((const char *pattern, size_t length,
struct re_pattern_buffer *buffer));
extern const char *re_compile_pattern extern const char *re_compile_pattern
_RE_ARGS ((const char *pattern, size_t length, _RE_ARGS ((const char *pattern, size_t length,
struct re_pattern_buffer *buffer)); struct re_pattern_buffer *buffer));
@ -455,6 +459,7 @@ extern const char *re_compile_pattern
/* Compile a fastmap for the compiled pattern in BUFFER; used to /* Compile a fastmap for the compiled pattern in BUFFER; used to
accelerate searches. Return 0 if successful and -2 if was an accelerate searches. Return 0 if successful and -2 if was an
internal error. */ internal error. */
extern int __re_compile_fastmap _RE_ARGS ((struct re_pattern_buffer *buffer));
extern int re_compile_fastmap _RE_ARGS ((struct re_pattern_buffer *buffer)); extern int re_compile_fastmap _RE_ARGS ((struct re_pattern_buffer *buffer));
@ -463,6 +468,9 @@ extern int re_compile_fastmap _RE_ARGS ((struct re_pattern_buffer *buffer));
characters. Return the starting position of the match, -1 for no characters. Return the starting position of the match, -1 for no
match, or -2 for an internal error. Also return register match, or -2 for an internal error. Also return register
information in REGS (if REGS and BUFFER->no_sub are nonzero). */ information in REGS (if REGS and BUFFER->no_sub are nonzero). */
extern int __re_search
_RE_ARGS ((struct re_pattern_buffer *buffer, const char *string,
int length, int start, int range, struct re_registers *regs));
extern int re_search extern int re_search
_RE_ARGS ((struct re_pattern_buffer *buffer, const char *string, _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string,
int length, int start, int range, struct re_registers *regs)); int length, int start, int range, struct re_registers *regs));
@ -470,6 +478,10 @@ extern int re_search
/* Like `re_search', but search in the concatenation of STRING1 and /* Like `re_search', but search in the concatenation of STRING1 and
STRING2. Also, stop searching at index START + STOP. */ STRING2. Also, stop searching at index START + STOP. */
extern int __re_search_2
_RE_ARGS ((struct re_pattern_buffer *buffer, const char *string1,
int length1, const char *string2, int length2,
int start, int range, struct re_registers *regs, int stop));
extern int re_search_2 extern int re_search_2
_RE_ARGS ((struct re_pattern_buffer *buffer, const char *string1, _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string1,
int length1, const char *string2, int length2, int length1, const char *string2, int length2,
@ -478,12 +490,19 @@ extern int re_search_2
/* Like `re_search', but return how many characters in STRING the regexp /* Like `re_search', but return how many characters in STRING the regexp
in BUFFER matched, starting at position START. */ in BUFFER matched, starting at position START. */
extern int __re_match
_RE_ARGS ((struct re_pattern_buffer *buffer, const char *string,
int length, int start, struct re_registers *regs));
extern int re_match extern int re_match
_RE_ARGS ((struct re_pattern_buffer *buffer, const char *string, _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string,
int length, int start, struct re_registers *regs)); int length, int start, struct re_registers *regs));
/* Relates to `re_match' as `re_search_2' relates to `re_search'. */ /* Relates to `re_match' as `re_search_2' relates to `re_search'. */
extern int __re_match_2
_RE_ARGS ((struct re_pattern_buffer *buffer, const char *string1,
int length1, const char *string2, int length2,
int start, struct re_registers *regs, int stop));
extern int re_match_2 extern int re_match_2
_RE_ARGS ((struct re_pattern_buffer *buffer, const char *string1, _RE_ARGS ((struct re_pattern_buffer *buffer, const char *string1,
int length1, const char *string2, int length2, int length1, const char *string2, int length2,
@ -502,6 +521,9 @@ extern int re_match_2
Unless this function is called, the first search or match using Unless this function is called, the first search or match using
PATTERN_BUFFER will allocate its own register data, without PATTERN_BUFFER will allocate its own register data, without
freeing the old data. */ freeing the old data. */
extern void __re_set_registers
_RE_ARGS ((struct re_pattern_buffer *buffer, struct re_registers *regs,
unsigned num_regs, regoff_t *starts, regoff_t *ends));
extern void re_set_registers extern void re_set_registers
_RE_ARGS ((struct re_pattern_buffer *buffer, struct re_registers *regs, _RE_ARGS ((struct re_pattern_buffer *buffer, struct re_registers *regs,
unsigned num_regs, regoff_t *starts, regoff_t *ends)); unsigned num_regs, regoff_t *starts, regoff_t *ends));
@ -515,14 +537,25 @@ extern int re_exec _RE_ARGS ((const char *));
#endif #endif
/* POSIX compatibility. */ /* POSIX compatibility. */
extern int regcomp _RE_ARGS ((regex_t *preg, const char *pattern, int cflags)); extern int __regcomp _RE_ARGS ((regex_t *__preg, const char *__pattern,
extern int regexec int __cflags));
_RE_ARGS ((const regex_t *preg, const char *string, size_t nmatch, extern int regcomp _RE_ARGS ((regex_t *__preg, const char *__pattern,
regmatch_t pmatch[], int eflags)); int __cflags));
extern size_t regerror
_RE_ARGS ((int errcode, const regex_t *preg, char *errbuf, extern int __regexec _RE_ARGS ((const regex_t *__preg,
size_t errbuf_size)); const char *__string, size_t __nmatch,
extern void regfree _RE_ARGS ((regex_t *preg)); regmatch_t __pmatch[], int __eflags));
extern int regexec _RE_ARGS ((const regex_t *__preg,
const char *__string, size_t __nmatch,
regmatch_t __pmatch[], int __eflags));
extern size_t __regerror _RE_ARGS ((int __errcode, const regex_t *__preg,
char *__errbuf, size_t __errbuf_size));
extern size_t regerror _RE_ARGS ((int __errcode, const regex_t *__preg,
char *__errbuf, size_t __errbuf_size));
extern void __regfree _RE_ARGS ((regex_t *__preg));
extern void regfree _RE_ARGS ((regex_t *__preg));
#ifdef __cplusplus #ifdef __cplusplus