version 1.2, 2011/11/24 10:43:55 |
version 1.5, 2011/12/12 02:00:49 |
|
|
#include "config.h" |
#include "config.h" |
#endif |
#endif |
|
|
|
#include <sys/types.h> |
#include <assert.h> |
#include <assert.h> |
#include <ctype.h> |
#include <ctype.h> |
#include <limits.h> |
#include <limits.h> |
|
|
static void manpath_add(struct manpaths *, const char *); |
static void manpath_add(struct manpaths *, const char *); |
|
|
void |
void |
manpath_parse(struct manpaths *dirs, char *defp, char *auxp) |
manpath_parse(struct manpaths *dirs, const char *file, |
|
char *defp, char *auxp) |
{ |
{ |
|
|
if (NULL != getenv("MANPATH")) |
manpath_parseline(dirs, auxp); |
|
|
|
if (NULL == defp) |
defp = getenv("MANPATH"); |
defp = getenv("MANPATH"); |
|
|
if (NULL == defp) |
if (NULL == defp) |
manpath_parseconf(dirs); |
manpath_parseconf(dirs, file); |
else |
else |
manpath_parseline(dirs, defp); |
manpath_parseline(dirs, defp); |
|
|
manpath_parseline(dirs, auxp); |
|
} |
} |
|
|
/* |
/* |
* Parse a FULL pathname from a colon-separated list of arrays. |
* Parse a FULL pathname from a colon-separated list of arrays. |
*/ |
*/ |
void |
void |
manpath_parseline(struct manpaths *dirs, char *path) |
manpath_parseline(struct manpaths *dirs, char *path) |
{ |
{ |
char *dir; |
char *dir; |
|
|
Line 69 manpath_parseline(struct manpaths *dirs, char *path) |
|
Line 71 manpath_parseline(struct manpaths *dirs, char *path) |
|
* Grow the array one-by-one for simplicity's sake. |
* Grow the array one-by-one for simplicity's sake. |
*/ |
*/ |
static void |
static void |
manpath_add(struct manpaths *dirs, const char *dir) |
manpath_add(struct manpaths *dirs, const char *dir) |
{ |
{ |
char buf[PATH_MAX]; |
char buf[PATH_MAX]; |
char *cp; |
char *cp; |
Line 83 manpath_add(struct manpaths *dirs, const char *dir) |
|
Line 85 manpath_add(struct manpaths *dirs, const char *dir) |
|
return; |
return; |
|
|
dirs->paths = mandoc_realloc |
dirs->paths = mandoc_realloc |
(dirs->paths, |
(dirs->paths, |
((size_t)dirs->sz + 1) * sizeof(char *)); |
((size_t)dirs->sz + 1) * sizeof(char *)); |
|
|
dirs->paths[dirs->sz++] = mandoc_strdup(cp); |
dirs->paths[dirs->sz++] = mandoc_strdup(cp); |
} |
} |
|
|
void |
void |
manpath_parseconf(struct manpaths *dirs) |
manpath_parseconf(struct manpaths *dirs, const char *file) |
{ |
{ |
#ifdef USE_MANPATH |
#ifdef USE_MANPATH |
FILE *stream; |
FILE *stream; |
Line 123 manpath_parseconf(struct manpaths *dirs) |
|
Line 125 manpath_parseconf(struct manpaths *dirs) |
|
free(buf); |
free(buf); |
pclose(stream); |
pclose(stream); |
#else |
#else |
manpath_manconf(dirs); |
manpath_manconf(dirs, file ? file : MAN_CONF_FILE); |
#endif |
#endif |
} |
} |
|
|
Line 139 manpath_free(struct manpaths *p) |
|
Line 141 manpath_free(struct manpaths *p) |
|
} |
} |
|
|
void |
void |
manpath_manconf(struct manpaths *dirs) |
manpath_manconf(struct manpaths *dirs, const char *file) |
{ |
{ |
FILE *stream; |
FILE *stream; |
char *p, *q; |
char *p, *q; |
size_t len, keysz; |
size_t len, keysz; |
|
|
keysz = strlen(MAN_CONF_KEY); |
keysz = strlen(MAN_CONF_KEY); |
assert(keysz > 0); |
assert(keysz > 0); |
|
|
if (NULL == (stream = fopen(MAN_CONF_FILE, "r"))) |
if (NULL == (stream = fopen(file, "r"))) |
return; |
return; |
|
|
while (NULL != (p = fgetln(stream, &len))) { |
while (NULL != (p = fgetln(stream, &len))) { |