Module Name: othersrc
Committed By: agc
Date: Fri Feb 24 19:01:11 UTC 2023
Modified Files:
othersrc/external/bsd/agcre/bin: Makefile
othersrc/external/bsd/agcre/dist: agcre.c agcre.h
othersrc/external/bsd/agcre/dist/tests: 54.expected 62.expected
othersrc/external/bsd/agcre/lib: Makefile
Added Files:
othersrc/external/bsd/agcre: namespace.mk
Log Message:
Update agcre (yet another regexp library) to version 20230224
+ revamp the reverse searching functionality
+ bug fixes
+ don't terminate searches too early
+ update namespace protection to just use simple definitions
+ bump version to 20230224
To generate a diff of this commit:
cvs rdiff -u -r0 -r1.1 othersrc/external/bsd/agcre/namespace.mk
cvs rdiff -u -r1.1 -r1.2 othersrc/external/bsd/agcre/bin/Makefile
cvs rdiff -u -r1.2 -r1.3 othersrc/external/bsd/agcre/dist/agcre.c
cvs rdiff -u -r1.4 -r1.5 othersrc/external/bsd/agcre/dist/agcre.h
cvs rdiff -u -r1.3 -r1.4 othersrc/external/bsd/agcre/dist/tests/54.expected
cvs rdiff -u -r1.2 -r1.3 othersrc/external/bsd/agcre/dist/tests/62.expected
cvs rdiff -u -r1.3 -r1.4 othersrc/external/bsd/agcre/lib/Makefile
Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.
Modified files:
Index: othersrc/external/bsd/agcre/bin/Makefile
diff -u othersrc/external/bsd/agcre/bin/Makefile:1.1 othersrc/external/bsd/agcre/bin/Makefile:1.2
--- othersrc/external/bsd/agcre/bin/Makefile:1.1 Wed Aug 16 23:38:13 2017
+++ othersrc/external/bsd/agcre/bin/Makefile Fri Feb 24 19:01:10 2023
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.1 2017/08/16 23:38:13 agc Exp $
+# $NetBSD: Makefile,v 1.2 2023/02/24 19:01:10 agc Exp $
.include <bsd.own.mk>
@@ -9,6 +9,8 @@ CPPFLAGS+= -I${DIST}
MAN= agcre.1
WARNS= 5
+.sinclude "../namespace.mk"
+
DIST= ${.CURDIR}/../dist
.PATH: ${DIST}
Index: othersrc/external/bsd/agcre/dist/agcre.c
diff -u othersrc/external/bsd/agcre/dist/agcre.c:1.2 othersrc/external/bsd/agcre/dist/agcre.c:1.3
--- othersrc/external/bsd/agcre/dist/agcre.c:1.2 Sat Dec 4 01:54:51 2021
+++ othersrc/external/bsd/agcre/dist/agcre.c Fri Feb 24 19:01:10 2023
@@ -223,6 +223,7 @@ static int unicode_isOther_Uppercase(uin
static int unicode_isPattern_White_Space(uint32_t /*ch*/);
static int unicode_isalnum(uint32_t /*ch*/);
static int unicode_isalpha(uint32_t /*ch*/);
+static int unicode_ispunct2(uint32_t /*ch*/);
static int unicode_isblank(uint32_t /*ch*/);
static int unicode_iscntrl(uint32_t /*ch*/);
static int unicode_isdigit(uint32_t /*ch*/);
@@ -233,7 +234,7 @@ static int unicode_ispunct(uint32_t /*ch
static int unicode_isspace(uint32_t /*ch*/);
static int unicode_isupper(uint32_t /*ch*/);
static int unicode_isxdigit(uint32_t /*ch*/);
-static int unicode_isident(uint32_t /*ch*/);
+static int unicode_isword(uint32_t /*ch*/);
static uint32_t unicode_tolower(uint32_t /*ch*/);
static uint32_t unicode_toupper(uint32_t /*ch*/);
@@ -417,7 +418,7 @@ emit(re_t *re, retoken_t *tok)
(tok->ch == 'd' || tok->ch == 'D') ? unicode_isdigit :
(tok->ch == 'p' || tok->ch == 'P') ? unicode_isprint :
(tok->ch == 's' || tok->ch == 'S') ? unicode_isspace :
- unicode_isident,
+ unicode_isword,
unicode_isupper(tok->ch));
re->pc++;
return 1;
@@ -1169,16 +1170,16 @@ isendline(re_t *re, input_t *in)
static inline int
isbegword(re_t *re, input_t *in)
{
- return (isbegline(re, in) || !unicode_isident(in->prevch)) &&
- unicode_isident(in->ch);
+ return (isbegline(re, in) || !unicode_isword(in->prevch)) &&
+ unicode_isword(in->ch);
}
/* return 1 at end of words */
static inline int
isendword(re_t *re, input_t *in)
{
- return (isendline(re, in) || (in->c > in->so && unicode_isident(in->prevch))) &&
- (!unicode_isident(in->ch));
+ return (isendline(re, in) || (in->c > in->so && unicode_isword(in->prevch))) &&
+ (!unicode_isword(in->ch));
}
/* do the chars match? */
@@ -1577,10 +1578,6 @@ rec_posix_class(input_t *in, set_t *set)
set_add_callback(set, unicode_isgraph, 0);
in->c += 8;
return 1;
- case /* ":ident:]" */ 0x8a1572f1:
- set_add_callback(set, unicode_isident, 0);
- in->c += 8;
- return 1;
case /* ":lower:]" */ 0x8bfc6af8:
set_add_callback(set, unicode_islower, 0);
in->c += 8;
@@ -1593,6 +1590,10 @@ rec_posix_class(input_t *in, set_t *set)
set_add_callback(set, unicode_ispunct, 0);
in->c += 8;
return 1;
+ case /* ":punct2:]" */ 0xf09af6aa:
+ set_add_callback(set, unicode_ispunct2, 0);
+ in->c += 9;
+ return 1;
case /* ":space:]" */ 0xa876bcf2:
set_add_callback(set, unicode_isspace, 0);
in->c += 8;
@@ -1605,6 +1606,10 @@ rec_posix_class(input_t *in, set_t *set)
set_add_callback(set, unicode_isxdigit, 0);
in->c += 9;
return 1;
+ case /* ":word:]" */ 0x96b11914:
+ set_add_callback(set, unicode_isword, 0);
+ in->c += 7;
+ return 1;
default:
return 0;
}
@@ -1661,7 +1666,7 @@ rec_set(input_t *in)
(token->ch == 'd' || token->ch == 'D') ? unicode_isdigit :
(token->ch == 'p' || token->ch == 'P') ? unicode_isprint :
(token->ch == 's' || token->ch == 'S') ? unicode_isspace :
- unicode_isident,
+ unicode_isword,
unicode_isupper((uint8_t)token->ch));
break;
}
@@ -2612,11 +2617,20 @@ unicode_isxdigit(uint32_t ch)
}
static int
-unicode_isident(uint32_t ch)
+unicode_isword(uint32_t ch)
{
return unicode_isalnum(ch) || ch == '_';
}
+static int
+unicode_ispunct2(uint32_t ch)
+{
+ if (!unicode_isprint(ch) || unicode_isspace(ch) || unicode_isword(ch)) {
+ return 0;
+ }
+ return 1;
+}
+
static uint32_t
unicode_tolower(uint32_t ch)
{
@@ -2658,14 +2672,14 @@ growspace(char **buf, size_t *size, size
/***********************************************************/
/* allocate a new structure and return it */
-AGCRE_EXPORT agcre_regex_t *
+agcre_regex_t *
agcre_new(void)
{
return calloc(1, sizeof(agcre_regex_t));
}
/* compile regular expression */
-AGCRE_EXPORT int
+int
agcre_regcomp(agcre_regex_t *agcre, const void *vs, uint32_t flags)
{
retoken_t *tok;
@@ -2737,7 +2751,7 @@ agcre_regcomp(agcre_regex_t *agcre, cons
#endif
/* format the error nicely */
-AGCRE_EXPORT size_t
+size_t
agcre_regerror(int errcode, const agcre_regex_t *agcre, char *errbuf, size_t size)
{
re_t *re;
@@ -2751,7 +2765,7 @@ agcre_regerror(int errcode, const agcre_
}
/* execute the regular expression */
-AGCRE_EXPORT int
+int
agcre_regexec(agcre_regex_t *agcre, const void *vs, size_t matchc, agcre_regmatch_t *m, uint32_t flags)
{
threadlist_t *current;
@@ -2917,14 +2931,16 @@ break_for:
}
/* execute the regular expression backwards */
-AGCRE_EXPORT int
+int
agcre_rev_regexec(agcre_regex_t *agcre, const void *vs, size_t matchc, agcre_regmatch_t *m, uint32_t flags)
{
- int64_t from;
- int64_t to;
- int64_t i;
- int found;
- int this;
+ uint32_t revflags;
+ uint32_t bolflags;
+ int64_t from;
+ int64_t to;
+ int64_t i;
+ int found;
+ int lastmatch;
if (flags & AGCRE_REG_STARTEND) {
from = m[0].rm_so;
@@ -2933,23 +2949,36 @@ agcre_rev_regexec(agcre_regex_t *agcre,
from = 0;
to = strlen(vs);
}
- flags |= (AGCRE_REG_STARTEND | AGCRE_REG_ANCHOR);
+ /* initialise here or final regexec doesn't work for "^$" */
+ lastmatch = 0;
+ m[0].rm_so = from;
+ m[0].rm_eo = to;
+ /* quick check to see if we have anything */
+ if (agcre_regexec(agcre, vs, matchc, m, flags | AGCRE_REG_STARTEND) != 0) {
+ lastmatch = m[0].rm_so;
+ return AGCRE_REG_FAILURE;
+ }
+ revflags = (AGCRE_REG_STARTEND | AGCRE_REG_ANCHOR);
for (found = 0, i = to - 1 ; i >= from ; --i) {
m[0].rm_so = i;
m[0].rm_eo = to;
- if ((this = agcre_regexec(agcre, vs, matchc, m, flags)) == 0) {
+ bolflags = (i > 0) ? AGCRE_REG_NOTBOL : 0;
+ if (agcre_regexec(agcre, vs, matchc, m, flags | revflags | bolflags) == 0) {
found += 1;
+ lastmatch = i;
} else if (found > 0) {
- m[0].rm_so = i + 1;
- m[0].rm_eo = to;
- return agcre_regexec(agcre, vs, matchc, m, flags);
+ break;
}
}
- return AGCRE_REG_FAILURE;
+ /* just do 1 final forward search to load m array */
+ m[0].rm_so = lastmatch;
+ m[0].rm_eo = to;
+ bolflags = (lastmatch > 0) ? AGCRE_REG_NOTBOL : 0;
+ return agcre_regexec(agcre, vs, matchc, m, flags | revflags | bolflags);
}
/* free the regular expression */
-AGCRE_EXPORT void
+void
agcre_regfree(agcre_regex_t *agcre)
{
uint32_t i;
@@ -2969,7 +2998,7 @@ agcre_regfree(agcre_regex_t *agcre)
}
/* do regexp sed-style substitution */
-AGCRE_EXPORT ssize_t
+ssize_t
agcre_regnsub(char *buf, size_t size, const char *repl, const agcre_regmatch_t *rm, const char *str)
{
const char *i;
@@ -3022,7 +3051,7 @@ agcre_regnsub(char *buf, size_t size, co
}
/* do regexp sed-style substitution */
-AGCRE_EXPORT ssize_t
+ssize_t
agcre_regasub(char **buf, const char *repl, const agcre_regmatch_t *rm, const char *str)
{
const char *i;
Index: othersrc/external/bsd/agcre/dist/agcre.h
diff -u othersrc/external/bsd/agcre/dist/agcre.h:1.4 othersrc/external/bsd/agcre/dist/agcre.h:1.5
--- othersrc/external/bsd/agcre/dist/agcre.h:1.4 Sat Dec 4 03:40:29 2021
+++ othersrc/external/bsd/agcre/dist/agcre.h Fri Feb 24 19:01:10 2023
@@ -1,5 +1,5 @@
/*
- * Copyright (c) 2013,2017,2020,2021 Alistair Crooks. All Rights reserved.
+ * Copyright (c) 2013,2017,2020,2021,2022,2023 Alistair Crooks. All Rights reserved.
* Copyright (c) 2007-2009 Russ Cox, Google Inc. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
@@ -29,7 +29,7 @@
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#ifndef AGCRE_VERSION
-#define AGCRE_VERSION 20211001
+#define AGCRE_VERSION 20230224
#include <inttypes.h>
@@ -95,6 +95,22 @@
#define AGCRE_MAX_SUBEXPR 100
#define AGCRE_MAX_EXPR_LENGTH 1024
+#ifdef LIB_NAMESPACE
+#define AGCRE_CONCAT(x, y) x##y
+#define AGCRE_NAMESPACE(x, y) AGCRE_CONCAT(x, y)
+#define agcre_regex_t AGCRE_NAMESPACE(LIB_NAMESPACE, agcre_regex_t)
+#define agcre_regoff_t AGCRE_NAMESPACE(LIB_NAMESPACE, agcre_regoff_t)
+#define agcre_regmatch_t AGCRE_NAMESPACE(LIB_NAMESPACE, agcre_regmatch_t)
+#define agcre_regex_new AGCRE_NAMESPACE(LIB_NAMESPACE, agcre_regex_new)
+#define agcre_regcomp AGCRE_NAMESPACE(LIB_NAMESPACE, agcre_regcomp)
+#define agcre_regexec AGCRE_NAMESPACE(LIB_NAMESPACE, agcre_regexec)
+#define agcre_rev_regexec AGCRE_NAMESPACE(LIB_NAMESPACE, agcre_rev_regexec)
+#define agcre_regfree AGCRE_NAMESPACE(LIB_NAMESPACE, agcre_regfree)
+#define agcre_regerror AGCRE_NAMESPACE(LIB_NAMESPACE, agcre_regerror)
+#define agcre_regnsub AGCRE_NAMESPACE(LIB_NAMESPACE, agcre_regnsub)
+#define agcre_regasub AGCRE_NAMESPACE(LIB_NAMESPACE, agcre_regasub)
+#endif
+
typedef int64_t agcre_regoff_t;
/* a match structure */
@@ -111,37 +127,6 @@ typedef struct agcre_regex_t {
void *re_g; /* internals */
} agcre_regex_t;
-#ifndef USE_VISIBILITY
-# if defined(__GNUC__)
-# if __GNUC__ >= 4
-# define USE_VISIBILITY 1
-# else
-# define USE_VISIBILITY 0
-# endif
-# else
-# define USE_VISIBILITY 0
-# endif
-#endif
-
-#if USE_VISIBILITY
-# define DLL_PUBLIC __attribute__ ((visibility ("default")))
-# define DLL_LOCAL __attribute__ ((visibility ("hidden")))
-#else
-# define DLL_PUBLIC
-# define DLL_LOCAL
-#endif
-
-/* by default, don't hide external symbols */
-#ifndef HIDE_AGCRE
-#define HIDE_AGCRE 0
-#endif
-
-#if HIDE_AGCRE
-#define AGCRE_EXPORT DLL_LOCAL
-#else
-#define AGCRE_EXPORT DLL_PUBLIC
-#endif
-
#ifndef __BEGIN_DECLS
# if defined(__cplusplus)
# define __BEGIN_DECLS extern "C" {
@@ -154,18 +139,18 @@ typedef struct agcre_regex_t {
__BEGIN_DECLS
-AGCRE_EXPORT agcre_regex_t *agcre_new(void);
-AGCRE_EXPORT int agcre_regcomp(agcre_regex_t */*re*/, const void */*s*/, uint32_t /*flags*/);
-AGCRE_EXPORT int agcre_regexec(agcre_regex_t */*re*/, const void */*vs*/, size_t /*mc*/,
+agcre_regex_t *agcre_new(void);
+int agcre_regcomp(agcre_regex_t */*re*/, const void */*s*/, uint32_t /*flags*/);
+int agcre_regexec(agcre_regex_t */*re*/, const void */*vs*/, size_t /*mc*/,
agcre_regmatch_t */*m*/, uint32_t /*flags*/);
-AGCRE_EXPORT int agcre_rev_regexec(agcre_regex_t */*agcre*/, const void */*vs*/,
+int agcre_rev_regexec(agcre_regex_t */*agcre*/, const void */*vs*/,
size_t /*matchc*/, agcre_regmatch_t */*m*/, uint32_t /*flags*/);
-AGCRE_EXPORT void agcre_regfree(agcre_regex_t */*re*/);
-AGCRE_EXPORT size_t agcre_regerror(int /*errcode*/, const agcre_regex_t */*agcre*/,
+void agcre_regfree(agcre_regex_t */*re*/);
+size_t agcre_regerror(int /*errcode*/, const agcre_regex_t */*agcre*/,
char */*errbuf*/, size_t /*size*/);
-AGCRE_EXPORT ssize_t agcre_regnsub(char */*buf*/, size_t /*size*/, const char */*repl*/,
+ssize_t agcre_regnsub(char */*buf*/, size_t /*size*/, const char */*repl*/,
const agcre_regmatch_t */*rm*/, const char */*str*/);
-AGCRE_EXPORT ssize_t agcre_regasub(char **/*buf*/, const char */*repl*/,
+ssize_t agcre_regasub(char **/*buf*/, const char */*repl*/,
const agcre_regmatch_t */*rm*/, const char */*str*/);
__END_DECLS
Index: othersrc/external/bsd/agcre/dist/tests/54.expected
diff -u othersrc/external/bsd/agcre/dist/tests/54.expected:1.3 othersrc/external/bsd/agcre/dist/tests/54.expected:1.4
--- othersrc/external/bsd/agcre/dist/tests/54.expected:1.3 Tue Oct 5 01:23:39 2021
+++ othersrc/external/bsd/agcre/dist/tests/54.expected Fri Feb 24 19:01:11 2023
@@ -2,5 +2,5 @@
/usr/include/dev/ic/nvmeio.h:192: for (i = 0; i < __arraycount(identify->psd); i++)
/usr/include/rump/rumpuser_port.h:260:#ifndef __arraycount
/usr/include/rump/rumpuser_port.h:261:#define __arraycount(_ar_) (sizeof(_ar_)/sizeof(_ar_[0]))
-/usr/include/sys/bitops.h:324: for (__i = 0; __i < __arraycount(__v->_b); __i++) \
-/usr/include/sys/cdefs.h:636:#define __arraycount(__x) (sizeof(__x) / sizeof(__x[0]))
+/usr/include/sys/bitops.h:324: for (__i = 0; __i < __arraycount((__v)->_b); __i++) \
+/usr/include/sys/cdefs.h:644:#define __arraycount(__x) (sizeof(__x) / sizeof(__x[0]))
Index: othersrc/external/bsd/agcre/dist/tests/62.expected
diff -u othersrc/external/bsd/agcre/dist/tests/62.expected:1.2 othersrc/external/bsd/agcre/dist/tests/62.expected:1.3
--- othersrc/external/bsd/agcre/dist/tests/62.expected:1.2 Tue Oct 5 01:23:39 2021
+++ othersrc/external/bsd/agcre/dist/tests/62.expected Fri Feb 24 19:01:11 2023
@@ -1 +1 @@
-agcre 20211001
+agcre 20230224
Index: othersrc/external/bsd/agcre/lib/Makefile
diff -u othersrc/external/bsd/agcre/lib/Makefile:1.3 othersrc/external/bsd/agcre/lib/Makefile:1.4
--- othersrc/external/bsd/agcre/lib/Makefile:1.3 Tue Oct 5 22:17:15 2021
+++ othersrc/external/bsd/agcre/lib/Makefile Fri Feb 24 19:01:11 2023
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile,v 1.3 2021/10/05 22:17:15 agc Exp $
+# $NetBSD: Makefile,v 1.4 2023/02/24 19:01:11 agc Exp $
LIB= agcre
SRCS+= agcre.c
@@ -14,6 +14,8 @@ WARNS= 5
CPPFLAGS+= -I${DIST}
+.sinclude "../namespace.mk"
+
.ifndef PRODUCTION
CPPFLAGS+= -g -O0
LDFLAGS+= -g -O0
Added files:
Index: othersrc/external/bsd/agcre/namespace.mk
diff -u /dev/null othersrc/external/bsd/agcre/namespace.mk:1.1
--- /dev/null Fri Feb 24 19:01:11 2023
+++ othersrc/external/bsd/agcre/namespace.mk Fri Feb 24 19:01:10 2023
@@ -0,0 +1 @@
+CPPFLAGS+= -DLIB_NAMESPACE="agcre_"