From e1e595a649d55a304416c1e8e23f99e0df58a452 Mon Sep 17 00:00:00 2001 From: Corinna Vinschen Date: Thu, 4 Feb 2010 12:35:49 +0000 Subject: Replace regex files with multibyte-aware version from FreeBSD. * Makefile.in (install-headers): Remove extra command to install regex.h. (uninstall-headers): Remove extra command to uninstall regex.h. * nlsfuncs.cc (collate_lcid): Make externally available to allow access to collation internals from regex functions. (collate_charset): Ditto. * wchar.h: Add __cplusplus guards to make C-clean. * include/regex.h: New file, replacing regex/regex.h. Remove UCB advertising clause. * regex/COPYRIGHT: Accommodate BSD license. Remove UCB advertising clause. * regex/cclass.h: Remove. * regex/cname.h: New file from FreeBSD. * regex/engine.c: Ditto. (NONCHAR): Tweak for Cygwin. * regex/engine.ih: Remove. * regex/mkh: Remove. * regex/regcomp.c: New file from FreeBSD. Tweak slightly for Cygwin. Import required collate internals from nlsfunc.cc. (p_ere_exp): Add GNU-specific \< and \> handling for word boundaries. (p_simp_re): Ditto. (__collate_range_cmp): Define. (p_b_term): Use Cygwin-specific collate internals. (findmust): Ditto. * regex/regcomp.ih: Remove. * regex/regerror.c: New file from FreeBSD. Fix a few compiler warnings. * regex/regerror.ih: Remove. * regex/regex.7: New file from FreeBSD. Remove UCB advertising clause. * regex/regex.h: Remove. Replaced by include/regex.h. * regex/regexec.c: New file from FreeBSD. Fix a few compiler warnings. * regex/regfree.c: New file from FreeBSD. * regex/tests: Remove. * regex/utils.h: New file from FreeBSD. --- winsup/cygwin/regex/regerror.c | 113 ++++++++++++++++++++++++++++++++--------- 1 file changed, 88 insertions(+), 25 deletions(-) (limited to 'winsup/cygwin/regex/regerror.c') diff --git a/winsup/cygwin/regex/regerror.c b/winsup/cygwin/regex/regerror.c index 42b045bae..7e88be5cb 100644 --- a/winsup/cygwin/regex/regerror.c +++ b/winsup/cygwin/regex/regerror.c @@ -1,17 +1,66 @@ -#include "winsup.h" +/*- + * Copyright (c) 1992, 1993, 1994 Henry Spencer. + * Copyright (c) 1992, 1993, 1994 + * The Regents of the University of California. All rights reserved. + * + * This code is derived from software contributed to Berkeley by + * Henry Spencer. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 4. Neither the name of the University nor the names of its contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * @(#)regerror.c 8.4 (Berkeley) 3/20/94 + */ + +#if defined(LIBC_SCCS) && !defined(lint) +static char sccsid[] = "@(#)regerror.c 8.4 (Berkeley) 3/20/94"; +#endif /* LIBC_SCCS and not lint */ +#include +__FBSDID("$FreeBSD: src/lib/libc/regex/regerror.c,v 1.11 2007/06/11 03:05:54 delphij Exp $"); + #include #include #include -#include #include #include -#include "regex.h" +#include #include "utils.h" -#include "regerror.ih" +/* ========= begin header generated by ./mkh ========= */ +#ifdef __cplusplus +extern "C" { +#endif + +/* === regerror.c === */ +static char *regatoi(const regex_t *preg, char *localbuf); + +#ifdef __cplusplus +} +#endif +/* ========= end header generated by ./mkh ========= */ /* - = #define REG_OKAY 0 = #define REG_NOMATCH 1 = #define REG_BADPAT 2 = #define REG_ECOLLATE 3 @@ -28,15 +77,20 @@ = #define REG_EMPTY 14 = #define REG_ASSERT 15 = #define REG_INVARG 16 + = #define REG_ILLSEQ 17 = #define REG_ATOI 255 // convert name to number (!) = #define REG_ITOA 0400 // convert number to name (!) */ static struct rerr { int code; +#ifdef __CYGWIN__ /* Avoid whining compiler */ const char *name; const char *explain; +#else + char *name; + char *explain; +#endif } rerrs[] = { - {REG_OKAY, "REG_OKAY", "no errors detected"}, {REG_NOMATCH, "REG_NOMATCH", "regexec() failed to match"}, {REG_BADPAT, "REG_BADPAT", "invalid regular expression"}, {REG_ECOLLATE, "REG_ECOLLATE", "invalid collating element"}, @@ -53,7 +107,8 @@ static struct rerr { {REG_EMPTY, "REG_EMPTY", "empty (sub)expression"}, {REG_ASSERT, "REG_ASSERT", "\"can't happen\" -- you found a bug"}, {REG_INVARG, "REG_INVARG", "invalid argument to regex routine"}, - {-1, "", "*** unknown regexp error code ***"}, + {REG_ILLSEQ, "REG_ILLSEQ", "illegal byte sequence"}, + {0, "", "*** unknown regexp error code ***"} }; /* @@ -62,27 +117,30 @@ static struct rerr { */ /* ARGSUSED */ size_t -regerror(errcode, preg, errbuf, errbuf_size) -int errcode; -const regex_t *preg; -char *errbuf; -size_t errbuf_size; +regerror(int errcode, + const regex_t * __restrict preg, + char * __restrict errbuf, + size_t errbuf_size) { - register struct rerr *r; - register size_t len; - register int target = errcode &~ REG_ITOA; - register const char *s; + struct rerr *r; + size_t len; + int target = errcode &~ REG_ITOA; +#ifdef __CYGWIN__ /* Avoid whining compiler */ + const char *s; +#else + char *s; +#endif char convbuf[50]; if (errcode == REG_ATOI) s = regatoi(preg, convbuf); else { - for (r = rerrs; r->code >= 0; r++) + for (r = rerrs; r->code != 0; r++) if (r->code == target) break; if (errcode®_ITOA) { - if (r->code >= 0) + if (r->code != 0) (void) strcpy(convbuf, r->name); else sprintf(convbuf, "REG_0x%x", target); @@ -109,18 +167,23 @@ size_t errbuf_size; - regatoi - internal routine to implement REG_ATOI == static char *regatoi(const regex_t *preg, char *localbuf); */ -static const char * -regatoi(preg, localbuf) -const regex_t *preg; -char *localbuf; +static char * +regatoi(const regex_t *preg, char *localbuf) { - register struct rerr *r; + struct rerr *r; - for (r = rerrs; r->code >= 0; r++) + for (r = rerrs; r->code != 0; r++) if (strcmp(r->name, preg->re_endp) == 0) break; - if (r->code < 0) + if (r->code == 0) +#ifdef __CYGWIN__ /* Avoid whining compiler */ + { + static const char null[] = "0"; + return null; + } +#else return("0"); +#endif sprintf(localbuf, "%d", r->code); return(localbuf); -- cgit v1.2.3