Print this page
9083 replace regex implementation with tre

@@ -1,7 +1,6 @@
 /*
- * 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

@@ -30,24 +29,25 @@
  * 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 "file64.h"
+
 #include <sys/types.h>
-#include <stdio.h>
-#include <string.h>
+
 #include <limits.h>
-#include <stdlib.h>
 #include <regex.h>
+#include <stdlib.h>
+#include <string.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;

@@ -64,86 +64,43 @@
         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"),
+        RERR(REG_ILLSEQ,        "illegal byte sequence"),
         {0,     "",             "*** unknown regexp error code ***"}
 };
 
 
 /*
- * regerror - the interface to error numbers
+ * 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)
+                if (r->code == errcode)
                                 break;
                 }
 
-                if (errcode&REG_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 != 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';
+                        (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);
 }