=================================================================== RCS file: /cvs/mandoc/Attic/apropos_db.c,v retrieving revision 1.32 retrieving revision 1.32.2.6 diff -u -p -r1.32 -r1.32.2.6 --- mandoc/Attic/apropos_db.c 2012/03/25 00:48:47 1.32 +++ mandoc/Attic/apropos_db.c 2014/04/23 21:31:38 1.32.2.6 @@ -1,7 +1,7 @@ -/* $Id: apropos_db.c,v 1.32 2012/03/25 00:48:47 kristaps Exp $ */ +/* $Id: apropos_db.c,v 1.32.2.6 2014/04/23 21:31:38 schwarze Exp $ */ /* * Copyright (c) 2011, 2012 Kristaps Dzonsons - * Copyright (c) 2011 Ingo Schwarze + * Copyright (c) 2011, 2014 Ingo Schwarze * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above @@ -30,12 +30,18 @@ #include #include -#if defined(__linux__) +#if defined(__APPLE__) +# include +#elif defined(__linux__) # include +#elif defined(__sun) +# include +#else +# include +#endif + +#if defined(__linux__) || defined(__sun) # include -#elif defined(__APPLE__) -# include -# include #else # include #endif @@ -43,6 +49,7 @@ #include "mandocdb.h" #include "apropos_db.h" #include "mandoc.h" +#include "mandoc_aux.h" #define RESFREE(_x) \ do { \ @@ -253,8 +260,8 @@ norm_string(const char *val, const struct mchars *mc, const char *seq, *cpp; int len, u, pos; enum mandoc_esc esc; - static const char res[] = { '\\', '\t', - ASCII_NBRSP, ASCII_HYPH, '\0' }; + static const char res[] = { '\\', '\t', ASCII_NBRSP, + ASCII_HYPH, ASCII_BREAK, '\0' }; /* Pre-allocate by the length of the input */ @@ -274,16 +281,24 @@ norm_string(const char *val, const struct mchars *mc, val += (int)sz; } - if (ASCII_HYPH == *val) { + switch (*val) { + case (ASCII_HYPH): (*buf)[pos++] = '-'; val++; continue; - } else if ('\t' == *val || ASCII_NBRSP == *val) { + case ('\t'): + /* FALLTHROUGH */ + case (ASCII_NBRSP): (*buf)[pos++] = ' '; val++; + /* FALLTHROUGH */ + case (ASCII_BREAK): continue; - } else if ('\\' != *val) + default: break; + } + if ('\\' != *val) + break; /* Read past the slash. */ @@ -413,11 +428,10 @@ apropos_search(int pathsz, char **paths, const struct { struct rectree tree; struct mchars *mc; - int i, rc; + int i; memset(&tree, 0, sizeof(struct rectree)); - rc = 0; mc = mchars_alloc(); *sz = 0; *resp = NULL; @@ -541,8 +555,8 @@ single_search(struct rectree *tree, const struct opts if (strcasecmp(opts->arch, r.arch)) continue; - tree->node = rs = mandoc_realloc - (rs, (tree->len + 1) * sizeof(struct res)); + tree->node = rs = mandoc_reallocarray(rs, + tree->len + 1, sizeof(struct res)); memcpy(&rs[tree->len], &r, sizeof(struct res)); memset(&r, 0, sizeof(struct res));