Print this page
9083 replace regex implementation with tre
*** 1,7 ****
/*
- * Copyright 2011 Nexenta Systems, Inc. All rights reserved.
* 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
--- 1,6 ----
*** 30,53 ****
* 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.
*/
#include "lint.h"
! #include "file64.h"
#include <sys/types.h>
! #include <stdio.h>
! #include <string.h>
#include <limits.h>
- #include <stdlib.h>
#include <regex.h>
- #include "utils.h"
#include "../gen/_libc_gettext.h"
- static const char *regatoi(const regex_t *preg, char *localbuf);
-
#define RERR(x, msg) { x, #x, msg }
static struct rerr {
int code;
const char *name;
--- 29,53 ----
* 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.
*/
+ /*
+ * Copyright 2018 Nexenta Systems, Inc.
+ */
+
#include "lint.h"
!
#include <sys/types.h>
!
#include <limits.h>
#include <regex.h>
+ #include <stdlib.h>
+ #include <string.h>
#include "../gen/_libc_gettext.h"
#define RERR(x, msg) { x, #x, msg }
static struct rerr {
int code;
const char *name;
*** 64,149 ****
RERR(REG_EBRACE, "braces not balanced"),
RERR(REG_BADBR, "invalid repetition count(s)"),
RERR(REG_ERANGE, "invalid character range"),
RERR(REG_ESPACE, "out of memory"),
RERR(REG_BADRPT, "repetition-operator operand invalid"),
- #ifdef REG_EMPTY
RERR(REG_EMPTY, "empty (sub)expression"),
- #endif
- RERR(REG_EFATAL, "fatal internal error"),
- #ifdef REG_INVARG
RERR(REG_INVARG, "invalid argument to regex routine"),
! #endif
! RERR(REG_ECHAR, "illegal byte sequence"),
! RERR(REG_ENOSYS, "function not supported"),
! RERR(REG_STACK, "backtrack stack overflow"),
! RERR(REG_ENSUB, "more than 9 \\( \\) pairs"),
! RERR(REG_ENEWLINE, "\n found before end of pattern"),
{0, "", "*** unknown regexp error code ***"}
};
/*
! * regerror - the interface to error numbers
*/
/* ARGSUSED */
size_t
regerror(int errcode, const regex_t *_RESTRICT_KYWD preg,
char *_RESTRICT_KYWD errbuf, size_t errbuf_size)
{
struct rerr *r;
size_t len;
- int target = errcode &~ REG_ITOA;
const char *s;
- char convbuf[50];
- if (errcode == REG_ATOI) {
- s = regatoi(preg, convbuf);
- } else {
for (r = rerrs; r->code != 0; r++) {
! if (r->code == target)
break;
}
- if (errcode®_ITOA) {
- if (r->code != 0)
- (void) strcpy(convbuf, r->name);
- else
- (void) sprintf(convbuf, "REG_0x%x", target);
- assert(strlen(convbuf) < sizeof (convbuf));
- s = convbuf;
- } else {
s = _libc_gettext(r->explain);
- }
- }
len = strlen(s) + 1;
! if (errbuf_size > 0) {
if (errbuf_size > len) {
(void) strcpy(errbuf, s);
} else {
! (void) strncpy(errbuf, s, errbuf_size-1);
! errbuf[errbuf_size-1] = '\0';
}
}
return (len);
- }
-
- /*
- * regatoi - internal routine to implement REG_ATOI
- */
- static const char *
- regatoi(const regex_t *preg, char *localbuf)
- {
- struct rerr *r;
-
- for (r = rerrs; r->code != 0; r++) {
- if (strcmp(r->name, preg->re_endp) == 0)
- break;
- }
- if (r->code == 0)
- return ("0");
-
- (void) sprintf(localbuf, "%d", r->code);
- return (localbuf);
}
--- 64,106 ----
RERR(REG_EBRACE, "braces not balanced"),
RERR(REG_BADBR, "invalid repetition count(s)"),
RERR(REG_ERANGE, "invalid character range"),
RERR(REG_ESPACE, "out of memory"),
RERR(REG_BADRPT, "repetition-operator operand invalid"),
RERR(REG_EMPTY, "empty (sub)expression"),
RERR(REG_INVARG, "invalid argument to regex routine"),
! RERR(REG_ILLSEQ, "illegal byte sequence"),
{0, "", "*** unknown regexp error code ***"}
};
/*
! * The interface to error numbers
*/
/* ARGSUSED */
size_t
regerror(int errcode, const regex_t *_RESTRICT_KYWD preg,
char *_RESTRICT_KYWD errbuf, size_t errbuf_size)
{
struct rerr *r;
size_t len;
const char *s;
for (r = rerrs; r->code != 0; r++) {
! if (r->code == errcode)
break;
}
s = _libc_gettext(r->explain);
len = strlen(s) + 1;
! if (errbuf != NULL && errbuf_size > 0) {
if (errbuf_size > len) {
(void) strcpy(errbuf, s);
} else {
! (void) strncpy(errbuf, s, errbuf_size - 1);
! errbuf[errbuf_size - 1] = '\0';
}
}
return (len);
}