=================================================================== RCS file: /cvs/mandoc/manpath.c,v retrieving revision 1.19 retrieving revision 1.22 diff -u -p -r1.19 -r1.22 --- mandoc/manpath.c 2014/11/27 00:30:40 1.19 +++ mandoc/manpath.c 2015/03/26 22:42:32 1.22 @@ -1,15 +1,15 @@ -/* $Id: manpath.c,v 1.19 2014/11/27 00:30:40 schwarze Exp $ */ +/* $Id: manpath.c,v 1.22 2015/03/26 22:42:32 schwarze Exp $ */ /* - * Copyright (c) 2011, 2014 Ingo Schwarze + * Copyright (c) 2011, 2014, 2015 Ingo Schwarze * Copyright (c) 2011 Kristaps Dzonsons * * Permission to use, copy, modify, and distribute this software for any * purpose with or without fee is hereby granted, provided that the above * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHORS DISCLAIM ALL WARRANTIES * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF - * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHORS BE LIABLE FOR * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF @@ -20,7 +20,6 @@ #include #include -#include #include #include #include @@ -31,7 +30,6 @@ #include "manpath.h" #define MAN_CONF_FILE "/etc/man.conf" -#define MAN_CONF_KEY "_whatdb" static void manpath_add(struct manpaths *, const char *, int); static void manpath_parseline(struct manpaths *, char *, int); @@ -86,6 +84,7 @@ manpath_parse(struct manpaths *dirs, const char *file, free(buf); pclose(stream); #else + char manpath_default[] = MANPATH_DEFAULT; char *insert; /* Always prepend -m. */ @@ -105,6 +104,8 @@ manpath_parse(struct manpaths *dirs, const char *file, /* No MANPATH; use man.conf(5) only. */ if (NULL == defp || '\0' == defp[0]) { manpath_manconf(dirs, file); + if (dirs->sz == 0) + manpath_parseline(dirs, manpath_default, 0); return; } @@ -204,33 +205,51 @@ manpath_free(struct manpaths *p) void manpath_manconf(struct manpaths *dirs, const char *file) { + const char *const toks[] = { "manpath", "_whatdb" }; + FILE *stream; - char *p, *q; - size_t len, keysz; + char *cp, *ep; + size_t len, tok; - keysz = strlen(MAN_CONF_KEY); - assert(keysz > 0); - - if (NULL == (stream = fopen(file, "r"))) + if ((stream = fopen(file, "r")) == NULL) return; - while (NULL != (p = fgetln(stream, &len))) { - if (0 == len || '\n' != p[--len]) + while ((cp = fgetln(stream, &len)) != NULL) { + ep = cp + len; + if (ep[-1] != '\n') break; - p[len] = '\0'; - while (isspace((unsigned char)*p)) - p++; - if (strncmp(MAN_CONF_KEY, p, keysz)) + *--ep = '\0'; + while (isspace((unsigned char)*cp)) + cp++; + if (*cp == '#') continue; - p += keysz; - while (isspace((unsigned char)*p)) - p++; - if ('\0' == *p) - continue; - if (NULL == (q = strrchr(p, '/'))) - continue; - *q = '\0'; - manpath_add(dirs, p, 0); + + for (tok = 0; tok < sizeof(toks)/sizeof(toks[0]); tok++) { + len = strlen(toks[tok]); + if (cp + len < ep && + isspace((unsigned char)cp[len]) && + !strncmp(cp, toks[tok], len)) { + cp += len; + while (isspace((unsigned char)*cp)) + cp++; + break; + } + } + + switch (tok) { + case 1: /* _whatdb */ + while (ep > cp && ep[-1] != '/') + ep--; + if (ep == cp) + continue; + *ep = '\0'; + /* FALLTHROUGH */ + case 0: /* manpath */ + manpath_add(dirs, cp, 0); + break; + default: + break; + } } fclose(stream);