version 1.1, 2011/11/23 09:47:38 |
version 1.4, 2011/11/26 22:38:11 |
|
|
#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, 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); |
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 70 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 84 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); |
Line 92 manpath_add(struct manpaths *dirs, const char *dir) |
|
Line 93 manpath_add(struct manpaths *dirs, const char *dir) |
|
void |
void |
manpath_parseconf(struct manpaths *dirs) |
manpath_parseconf(struct manpaths *dirs) |
{ |
{ |
FILE *stream; |
|
#ifdef USE_MANPATH |
#ifdef USE_MANPATH |
|
FILE *stream; |
char *buf; |
char *buf; |
size_t sz, bsz; |
size_t sz, bsz; |
|
|
Line 123 manpath_parseconf(struct manpaths *dirs) |
|
Line 124 manpath_parseconf(struct manpaths *dirs) |
|
free(buf); |
free(buf); |
pclose(stream); |
pclose(stream); |
#else |
#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; |
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))) { |
Line 152 manpath_parseconf(struct manpaths *dirs) |
|
Line 172 manpath_parseconf(struct manpaths *dirs) |
|
} |
} |
|
|
fclose(stream); |
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); |
|
} |
} |