- if (NULL == (v = strpbrk(buf, "=~"))) {
- e->substr = buf;
- e->bits = search->deftype;
- return(e);
- } else if (v == buf)
- e->bits = search->deftype;
-
- if ('~' == *v++) {
- if (0 != (irc = regcomp(&e->regexp, v,
- REG_EXTENDED | REG_NOSUB | (cs ? 0 : REG_ICASE)))) {
- regerror(irc, &e->regexp, errbuf, sizeof(errbuf));
- fprintf(stderr, "regcomp: %s\n", errbuf);
+ if (search->argmode == ARG_WORD) {
+ e->bits = TYPE_Nm;
+ e->match.type = DBM_REGEX;
+#if HAVE_REWB_BSD
+ mandoc_asprintf(&val, "[[:<:]]%s[[:>:]]", argv[*argi]);
+#elif HAVE_REWB_SYSV
+ mandoc_asprintf(&val, "\\<%s\\>", argv[*argi]);
+#else
+ mandoc_asprintf(&val,
+ "(^|[^a-zA-Z01-9_])%s([^a-zA-Z01-9_]|$)", argv[*argi]);
+#endif
+ cs = 0;
+ } else if ((val = strpbrk(argv[*argi], "=~")) == NULL) {
+ e->bits = TYPE_Nm | TYPE_Nd;
+ e->match.type = DBM_SUB;
+ e->match.str = argv[*argi];
+ } else {
+ if (val == argv[*argi])
+ e->bits = TYPE_Nm | TYPE_Nd;
+ if (*val == '=') {
+ e->match.type = DBM_SUB;
+ e->match.str = val + 1;
+ } else
+ e->match.type = DBM_REGEX;
+ *val++ = '\0';
+ if (strstr(argv[*argi], "arch") != NULL)
+ cs = 0;
+ }
+
+ /* Compile regular expressions. */
+
+ if (e->match.type == DBM_REGEX) {
+ e->match.re = mandoc_malloc(sizeof(*e->match.re));
+ irc = regcomp(e->match.re, val,
+ REG_EXTENDED | REG_NOSUB | (cs ? 0 : REG_ICASE));
+ if (irc) {
+ regerror(irc, e->match.re, errbuf, sizeof(errbuf));
+ warnx("regcomp /%s/: %s", val, errbuf);
+ }
+ if (search->argmode == ARG_WORD)
+ free(val);
+ if (irc) {
+ free(e->match.re);