=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/mandoc/mansearch.c,v retrieving revision 1.32 retrieving revision 1.33 diff -c -r1.32 -r1.33 *** src/usr.bin/mandoc/mansearch.c 2014/08/21 20:27:03 1.32 --- src/usr.bin/mandoc/mansearch.c 2014/08/27 00:06:08 1.33 *************** *** 1,4 **** ! /* $Id: mansearch.c,v 1.32 2014/08/21 20:27:03 schwarze Exp $ */ /* * Copyright (c) 2012 Kristaps Dzonsons * Copyright (c) 2013, 2014 Ingo Schwarze --- 1,4 ---- ! /* $OpenBSD: mansearch.c,v 1.33 2014/08/27 00:06:08 schwarze Exp $ */ /* * Copyright (c) 2012 Kristaps Dzonsons * Copyright (c) 2013, 2014 Ingo Schwarze *************** *** 15,21 **** --- 15,24 ---- * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ + #include + #include + #include #include #include *************** *** 148,154 **** mansearch(const struct mansearch *search, const struct manpaths *paths, int argc, char *argv[], - const char *outkey, struct manpage **res, size_t *sz) { int fd, rc, c, indexbit; --- 151,156 ---- *************** *** 184,194 **** goto out; outbit = 0; ! if (NULL != outkey) { for (indexbit = 0, iterbit = 1; indexbit < mansearch_keymax; indexbit++, iterbit <<= 1) { ! if (0 == strcasecmp(outkey, mansearch_keynames[indexbit])) { outbit = iterbit; break; --- 186,196 ---- goto out; outbit = 0; ! if (NULL != search->outkey) { for (indexbit = 0, iterbit = 1; indexbit < mansearch_keymax; indexbit++, iterbit <<= 1) { ! if (0 == strcasecmp(search->outkey, mansearch_keynames[indexbit])) { outbit = iterbit; break; *************** *** 356,361 **** --- 358,376 ---- return(rc); } + void + mansearch_free(struct manpage *res, size_t sz) + { + size_t i; + + for (i = 0; i < sz; i++) { + free(res[i].file); + free(res[i].names); + free(res[i].output); + } + free(res); + } + static int manpage_compare(const void *vp1, const void *vp2) { *************** *** 728,762 **** e = mandoc_calloc(1, sizeof(struct expr)); ! if (MANSEARCH_MAN & search->flags) { ! e->bits = search->deftype; e->substr = buf; e->equal = 1; return(e); } /* ! * Look for an '=' or '~' operator, ! * unless forced to some fixed macro keys. */ ! if (MANSEARCH_WHATIS & search->flags) ! val = NULL; ! else ! val = strpbrk(buf, "=~"); ! ! if (NULL == val) { ! e->bits = search->deftype; e->substr = buf; - - /* - * Found an operator. - * Regexp search is requested by !e->substr. - */ - } else { if (val == buf) ! e->bits = search->deftype; if ('=' == *val) e->substr = val + 1; *val++ = '\0'; --- 743,772 ---- e = mandoc_calloc(1, sizeof(struct expr)); ! if (search->argmode == ARG_NAME) { ! e->bits = TYPE_Nm; e->substr = buf; e->equal = 1; return(e); } /* ! * Separate macro keys from search string. ! * If needed, request regular expression handling ! * by setting e->substr to NULL. */ ! if (search->argmode == ARG_WORD) { ! e->bits = TYPE_Nm; ! e->substr = NULL; ! mandoc_asprintf(&val, "[[:<:]]%s[[:>:]]", buf); ! cs = 0; ! } else if ((val = strpbrk(buf, "=~")) == NULL) { ! e->bits = TYPE_Nm | TYPE_Nd; e->substr = buf; } else { if (val == buf) ! e->bits = TYPE_Nm | TYPE_Nd; if ('=' == *val) e->substr = val + 1; *val++ = '\0'; *************** *** 766,781 **** /* Compile regular expressions. */ - if (MANSEARCH_WHATIS & search->flags) { - e->substr = NULL; - mandoc_asprintf(&val, "[[:<:]]%s[[:>:]]", buf); - cs = 0; - } - if (NULL == e->substr) { irc = regcomp(&e->regexp, val, REG_EXTENDED | REG_NOSUB | (cs ? 0 : REG_ICASE)); ! if (MANSEARCH_WHATIS & search->flags) free(val); if (irc) { regerror(irc, &e->regexp, errbuf, sizeof(errbuf)); --- 776,785 ---- /* Compile regular expressions. */ if (NULL == e->substr) { irc = regcomp(&e->regexp, val, REG_EXTENDED | REG_NOSUB | (cs ? 0 : REG_ICASE)); ! if (search->argmode == ARG_WORD) free(val); if (irc) { regerror(irc, &e->regexp, errbuf, sizeof(errbuf));