=================================================================== RCS file: /cvs/mandoc/manpath.c,v retrieving revision 1.23 retrieving revision 1.29 diff -u -p -r1.23 -r1.29 --- mandoc/manpath.c 2015/03/27 17:37:25 1.23 +++ mandoc/manpath.c 2015/11/07 17:58:55 1.29 @@ -1,4 +1,4 @@ -/* $Id: manpath.c,v 1.23 2015/03/27 17:37:25 schwarze Exp $ */ +/* $Id: manpath.c,v 1.29 2015/11/07 17:58:55 schwarze Exp $ */ /* * Copyright (c) 2011, 2014, 2015 Ingo Schwarze * Copyright (c) 2011 Kristaps Dzonsons @@ -21,6 +21,9 @@ #include #include +#if HAVE_ERR +#include +#endif #include #include #include @@ -29,7 +32,9 @@ #include "mandoc_aux.h" #include "manconf.h" +#if !HAVE_MANPATH static void manconf_file(struct manconf *, const char *); +#endif static void manpath_add(struct manpaths *, const char *, int); static void manpath_parseline(struct manpaths *, char *, int); @@ -78,13 +83,12 @@ manconf_parse(struct manconf *conf, const char *file, if ( ! ferror(stream) && feof(stream) && bsz && '\n' == buf[bsz - 1]) { buf[bsz - 1] = '\0'; - manpath_parseline(dirs, buf, 1); + manpath_parseline(&conf->manpath, buf, 1); } free(buf); pclose(stream); #else - char manpath_default[] = MANPATH_DEFAULT; char *insert; /* Always prepend -m. */ @@ -104,8 +108,6 @@ manconf_parse(struct manconf *conf, const char *file, /* No MANPATH; use man.conf(5) only. */ if (NULL == defp || '\0' == defp[0]) { manconf_file(conf, file); - if (conf->manpath.sz == 0) - manpath_parseline(&conf->manpath, manpath_default, 0); return; } @@ -166,10 +168,8 @@ manpath_add(struct manpaths *dirs, const char *dir, in size_t i; if (NULL == (cp = realpath(dir, buf))) { - if (complain) { - fputs("manpath: ", stderr); - perror(dir); - } + if (complain) + warn("manpath: %s", dir); return; } @@ -178,10 +178,8 @@ manpath_add(struct manpaths *dirs, const char *dir, in return; if (stat(cp, &sb) == -1) { - if (complain) { - fputs("manpath: ", stderr); - perror(dir); - } + if (complain) + warn("manpath: %s", dir); return; } @@ -206,20 +204,27 @@ manconf_free(struct manconf *conf) free(conf->output.style); } +#if !HAVE_MANPATH static void manconf_file(struct manconf *conf, const char *file) { const char *const toks[] = { "manpath", "output", "_whatdb" }; + char manpath_default[] = MANPATH_DEFAULT; FILE *stream; - char *cp, *ep; - size_t len, tok; + char *line, *cp, *ep; + size_t linesz, tok, toklen; + ssize_t linelen; if ((stream = fopen(file, "r")) == NULL) - return; + goto out; - while ((cp = fgetln(stream, &len)) != NULL) { - ep = cp + len; + line = NULL; + linesz = 0; + + while ((linelen = getline(&line, &linesz, stream)) != -1) { + cp = line; + ep = cp + linelen; if (ep[-1] != '\n') break; *--ep = '\0'; @@ -229,11 +234,11 @@ manconf_file(struct manconf *conf, const char *file) continue; 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; + toklen = strlen(toks[tok]); + if (cp + toklen < ep && + isspace((unsigned char)cp[toklen]) && + strncmp(cp, toks[tok], toklen) == 0) { + cp += toklen; while (isspace((unsigned char)*cp)) cp++; break; @@ -250,6 +255,7 @@ manconf_file(struct manconf *conf, const char *file) /* FALLTHROUGH */ case 0: /* manpath */ manpath_add(&conf->manpath, cp, 0); + *manpath_default = '\0'; break; case 1: /* output */ manconf_output(&conf->output, cp); @@ -258,9 +264,14 @@ manconf_file(struct manconf *conf, const char *file) break; } } - + free(line); fclose(stream); + +out: + if (*manpath_default != '\0') + manpath_parseline(&conf->manpath, manpath_default, 0); } +#endif void manconf_output(struct manoutput *conf, const char *cp)