diff options
-rw-r--r-- | TODO | 6 | ||||
-rwxr-xr-x | configure | 6 | ||||
-rw-r--r-- | mansearch.c | 7 | ||||
-rw-r--r-- | test-rewb-bsd.c | 26 | ||||
-rw-r--r-- | test-rewb-sysv.c | 26 |
5 files changed, 65 insertions, 6 deletions
@@ -527,12 +527,6 @@ are mere guesses, and some may be wrong. * portability ************************************************************************ -- word boundaries in regular expressions for whatis(1) - set up config tests to use [[:<:]], \<, or nothing - Svyatoslav Mishyn Wed, 17 Dec 2014 11:07:10 +0200 - reminded by Peter Bray Fri, 03 Apr 2015 23:02:16 +1100 - loc * exist * algo * size * imp * - - systems having UTF-8 but not en_US.UTF-8 call locale(1) from ./configure, select a UTF-8-locale, and use that for test-wchar.c and term_ascii.c @@ -53,6 +53,8 @@ HAVE_MMAP= HAVE_PLEDGE= HAVE_PROGNAME= HAVE_REALLOCARRAY= +HAVE_REWB_BSD= +HAVE_REWB_SYSV= HAVE_STRCASESTR= HAVE_STRINGLIST= HAVE_STRLCAT= @@ -184,6 +186,8 @@ runtest mmap MMAP || true runtest pledge PLEDGE || true runtest progname PROGNAME || true runtest reallocarray REALLOCARRAY || true +runtest rewb-bsd REWB_BSD || true +runtest rewb-sysv REWB_SYSV || true runtest strcasestr STRCASESTR || true runtest stringlist STRINGLIST || true runtest strlcat STRLCAT || true @@ -306,6 +310,8 @@ cat << __HEREDOC__ #define HAVE_PLEDGE ${HAVE_PLEDGE} #define HAVE_PROGNAME ${HAVE_PROGNAME} #define HAVE_REALLOCARRAY ${HAVE_REALLOCARRAY} +#define HAVE_REWB_BSD ${HAVE_REWB_BSD} +#define HAVE_REWB_SYSV ${HAVE_REWB_SYSV} #define HAVE_STRCASESTR ${HAVE_STRCASESTR} #define HAVE_STRINGLIST ${HAVE_STRINGLIST} #define HAVE_STRLCAT ${HAVE_STRLCAT} diff --git a/mansearch.c b/mansearch.c index e825c13b..1b37abf1 100644 --- a/mansearch.c +++ b/mansearch.c @@ -766,7 +766,14 @@ exprterm(const struct mansearch *search, char *buf, int cs) if (search->argmode == ARG_WORD) { e->bits = TYPE_Nm; e->substr = NULL; +#if HAVE_REWB_BSD mandoc_asprintf(&val, "[[:<:]]%s[[:>:]]", buf); +#elif HAVE_REWB_SYSV + mandoc_asprintf(&val, "\\<%s\\>", buf); +#else + mandoc_asprintf(&val, + "(^|[^a-zA-Z01-9_])%s([^a-zA-Z01-9_]|$)", buf); +#endif cs = 0; } else if ((val = strpbrk(buf, "=~")) == NULL) { e->bits = TYPE_Nm | TYPE_Nd; diff --git a/test-rewb-bsd.c b/test-rewb-bsd.c new file mode 100644 index 00000000..88d3d357 --- /dev/null +++ b/test-rewb-bsd.c @@ -0,0 +1,26 @@ +#include <sys/types.h> +#include <regex.h> + +int +main(void) +{ + regex_t re; + + if (regcomp(&re, "[[:<:]]word[[:>:]]", REG_EXTENDED | REG_NOSUB)) + return 1; + if (regexec(&re, "the word is here", 0, NULL, 0)) + return 2; + if (regexec(&re, "same word", 0, NULL, 0)) + return 3; + if (regexec(&re, "word again", 0, NULL, 0)) + return 4; + if (regexec(&re, "word", 0, NULL, 0)) + return 5; + if (regexec(&re, "wordy", 0, NULL, 0) != REG_NOMATCH) + return 6; + if (regexec(&re, "sword", 0, NULL, 0) != REG_NOMATCH) + return 7; + if (regexec(&re, "reworded", 0, NULL, 0) != REG_NOMATCH) + return 8; + return 0; +} diff --git a/test-rewb-sysv.c b/test-rewb-sysv.c new file mode 100644 index 00000000..cb35c544 --- /dev/null +++ b/test-rewb-sysv.c @@ -0,0 +1,26 @@ +#include <sys/types.h> +#include <regex.h> + +int +main(void) +{ + regex_t re; + + if (regcomp(&re, "\\<word\\>", REG_EXTENDED | REG_NOSUB)) + return 1; + if (regexec(&re, "the word is here", 0, NULL, 0)) + return 2; + if (regexec(&re, "same word", 0, NULL, 0)) + return 3; + if (regexec(&re, "word again", 0, NULL, 0)) + return 4; + if (regexec(&re, "word", 0, NULL, 0)) + return 5; + if (regexec(&re, "wordy", 0, NULL, 0) != REG_NOMATCH) + return 6; + if (regexec(&re, "sword", 0, NULL, 0) != REG_NOMATCH) + return 7; + if (regexec(&re, "reworded", 0, NULL, 0) != REG_NOMATCH) + return 8; + return 0; +} |