=================================================================== RCS file: /cvs/mandoc/manpath.c,v retrieving revision 1.1 retrieving revision 1.4 diff -u -p -r1.1 -r1.4 --- mandoc/manpath.c 2011/11/23 09:47:38 1.1 +++ mandoc/manpath.c 2011/11/26 22:38:11 1.4 @@ -1,4 +1,4 @@ -/* $Id: manpath.c,v 1.1 2011/11/23 09:47:38 kristaps Exp $ */ +/* $Id: manpath.c,v 1.4 2011/11/26 22:38:11 schwarze Exp $ */ /* * Copyright (c) 2011 Ingo Schwarze * Copyright (c) 2011 Kristaps Dzonsons @@ -19,6 +19,7 @@ #include "config.h" #endif +#include #include #include #include @@ -35,25 +36,25 @@ static void manpath_add(struct manpaths *, const char *); void -manpath_parse(struct manpaths *dirs, char *defp, char *auxp) +manpath_parse(struct manpaths *dirs, char *defp, char *auxp) { - if (NULL != getenv("MANPATH")) + manpath_parseline(dirs, auxp); + + if (NULL == defp) defp = getenv("MANPATH"); if (NULL == defp) manpath_parseconf(dirs); else manpath_parseline(dirs, defp); - - manpath_parseline(dirs, auxp); } /* * Parse a FULL pathname from a colon-separated list of arrays. */ void -manpath_parseline(struct manpaths *dirs, char *path) +manpath_parseline(struct manpaths *dirs, char *path) { char *dir; @@ -69,7 +70,7 @@ manpath_parseline(struct manpaths *dirs, char *path) * Grow the array one-by-one for simplicity's sake. */ static void -manpath_add(struct manpaths *dirs, const char *dir) +manpath_add(struct manpaths *dirs, const char *dir) { char buf[PATH_MAX]; char *cp; @@ -83,7 +84,7 @@ manpath_add(struct manpaths *dirs, const char *dir) return; dirs->paths = mandoc_realloc - (dirs->paths, + (dirs->paths, ((size_t)dirs->sz + 1) * sizeof(char *)); dirs->paths[dirs->sz++] = mandoc_strdup(cp); @@ -92,8 +93,8 @@ manpath_add(struct manpaths *dirs, const char *dir) void manpath_parseconf(struct manpaths *dirs) { - FILE *stream; #ifdef USE_MANPATH + FILE *stream; char *buf; size_t sz, bsz; @@ -123,13 +124,32 @@ manpath_parseconf(struct manpaths *dirs) free(buf); pclose(stream); #else + manpath_manconf(MAN_CONF_FILE, dirs); +#endif +} + +void +manpath_free(struct manpaths *p) +{ + int i; + + for (i = 0; i < p->sz; i++) + free(p->paths[i]); + + free(p->paths); +} + +void +manpath_manconf(const char *file, struct manpaths *dirs) +{ + FILE *stream; char *p, *q; - size_t len, keysz; + size_t len, keysz; keysz = strlen(MAN_CONF_KEY); assert(keysz > 0); - if (NULL == (stream = fopen(MAN_CONF_FILE, "r"))) + if (NULL == (stream = fopen(file, "r"))) return; while (NULL != (p = fgetln(stream, &len))) { @@ -152,16 +172,4 @@ manpath_parseconf(struct manpaths *dirs) } fclose(stream); -#endif -} - -void -manpath_free(struct manpaths *p) -{ - int i; - - for (i = 0; i < p->sz; i++) - free(p->paths[i]); - - free(p->paths); }