]> git.cameronkatri.com Git - mandoc.git/blobdiff - manpath.c
This one needs config.h too, if only for __BEGIN_DECLS.
[mandoc.git] / manpath.c
index e7451597b7b71a2734bff6fe12b807b3c0b7e83e..9446ea6971a42cc81e477b6161e107ae02215848 100644 (file)
--- a/manpath.c
+++ b/manpath.c
@@ -1,4 +1,4 @@
-/*     $Id: manpath.c,v 1.23 2015/03/27 17:37:25 schwarze Exp $        */
+/*     $Id: manpath.c,v 1.25 2015/05/07 12:08:13 schwarze Exp $        */
 /*
  * Copyright (c) 2011, 2014, 2015 Ingo Schwarze <schwarze@openbsd.org>
  * Copyright (c) 2011 Kristaps Dzonsons <kristaps@bsd.lv>
@@ -78,13 +78,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 +103,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;
        }
 
@@ -210,13 +207,14 @@ 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;
 
        if ((stream = fopen(file, "r")) == NULL)
-               return;
+               goto out;
 
        while ((cp = fgetln(stream, &len)) != NULL) {
                ep = cp + len;
@@ -250,6 +248,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,8 +257,11 @@ manconf_file(struct manconf *conf, const char *file)
                        break;
                }
        }
-
        fclose(stream);
+
+out:
+       if (*manpath_default != '\0')
+               manpath_parseline(&conf->manpath, manpath_default, 0);
 }
 
 void