version 1.42, 2012/03/24 01:46:25 |
version 1.46, 2013/10/11 00:06:48 |
|
|
#include "config.h" |
#include "config.h" |
#endif |
#endif |
|
|
#include <sys/param.h> |
|
#include <sys/wait.h> |
#include <sys/wait.h> |
|
|
#include <assert.h> |
#include <assert.h> |
|
|
#include <string.h> |
#include <string.h> |
#include <unistd.h> |
#include <unistd.h> |
|
|
|
#if defined(__sun) |
|
/* for stat() */ |
|
#include <fcntl.h> |
|
#include <sys/types.h> |
|
#include <sys/stat.h> |
|
#endif |
|
|
#include "apropos_db.h" |
#include "apropos_db.h" |
#include "mandoc.h" |
#include "mandoc.h" |
#include "mdoc.h" |
#include "mdoc.h" |
|
|
#include "manpath.h" |
#include "manpath.h" |
#include "mandocdb.h" |
#include "mandocdb.h" |
|
|
#ifdef __linux__ |
#if defined(__linux__) || defined(__sun) |
# include <db_185.h> |
# include <db_185.h> |
#else |
#else |
# include <db.h> |
# include <db.h> |
Line 726 format(const struct req *req, const char *file) |
|
Line 732 format(const struct req *req, const char *file) |
|
struct man *man; |
struct man *man; |
void *vp; |
void *vp; |
enum mandoclevel rc; |
enum mandoclevel rc; |
char opts[MAXPATHLEN + 128]; |
char opts[PATH_MAX + 128]; |
|
|
if (-1 == (fd = open(file, O_RDONLY, 0))) { |
if (-1 == (fd = open(file, O_RDONLY, 0))) { |
resp_baddb(); |
resp_baddb(); |
return; |
return; |
} |
} |
|
|
mp = mparse_alloc(MPARSE_AUTO, MANDOCLEVEL_FATAL, NULL, NULL); |
mp = mparse_alloc(MPARSE_AUTO, MANDOCLEVEL_FATAL, NULL, NULL, NULL); |
rc = mparse_readfd(mp, fd, file); |
rc = mparse_readfd(mp, fd, file); |
close(fd); |
close(fd); |
|
|
Line 743 format(const struct req *req, const char *file) |
|
Line 749 format(const struct req *req, const char *file) |
|
} |
} |
|
|
snprintf(opts, sizeof(opts), "fragment," |
snprintf(opts, sizeof(opts), "fragment," |
"man=%s/search.html?sec=%%S&expr=%%N," |
"man=%s/search.html?sec=%%S&expr=Nm~^%%N$," |
/*"includes=/cgi-bin/man.cgi/usr/include/%%I"*/, |
/*"includes=/cgi-bin/man.cgi/usr/include/%%I"*/, |
progname); |
progname); |
|
|
Line 777 pg_show(const struct req *req, char *path) |
|
Line 783 pg_show(const struct req *req, char *path) |
|
struct manpaths ps; |
struct manpaths ps; |
size_t sz; |
size_t sz; |
char *sub; |
char *sub; |
char file[MAXPATHLEN]; |
char file[PATH_MAX]; |
const char *cp; |
const char *cp; |
int rc, catm; |
int rc, catm; |
unsigned int vol, rec, mr; |
unsigned int vol, rec, mr; |
Line 831 pg_show(const struct req *req, char *path) |
|
Line 837 pg_show(const struct req *req, char *path) |
|
goto out; |
goto out; |
} |
} |
|
|
sz = strlcpy(file, ps.paths[vol], MAXPATHLEN); |
sz = strlcpy(file, ps.paths[vol], PATH_MAX); |
assert(sz < MAXPATHLEN); |
assert(sz < PATH_MAX); |
strlcat(file, "/", MAXPATHLEN); |
strlcat(file, "/", PATH_MAX); |
strlcat(file, MANDOC_IDX, MAXPATHLEN); |
strlcat(file, MANDOC_IDX, PATH_MAX); |
|
|
/* Open the index recno(3) database. */ |
/* Open the index recno(3) database. */ |
|
|
Line 863 pg_show(const struct req *req, char *path) |
|
Line 869 pg_show(const struct req *req, char *path) |
|
resp_baddb(); |
resp_baddb(); |
else { |
else { |
file[(int)sz] = '\0'; |
file[(int)sz] = '\0'; |
strlcat(file, "/", MAXPATHLEN); |
strlcat(file, "/", PATH_MAX); |
strlcat(file, cp, MAXPATHLEN); |
strlcat(file, cp, PATH_MAX); |
if (catm) |
if (catm) |
catman(req, file); |
catman(req, file); |
else |
else |
|
|
main(void) |
main(void) |
{ |
{ |
int i; |
int i; |
char buf[MAXPATHLEN]; |
char buf[PATH_MAX]; |
DIR *cwd; |
DIR *cwd; |
struct req req; |
struct req req; |
char *p, *path, *subpath; |
char *p, *path, *subpath; |
|
|
|
|
memset(&req, 0, sizeof(struct req)); |
memset(&req, 0, sizeof(struct req)); |
|
|
strlcpy(buf, ".", MAXPATHLEN); |
strlcpy(buf, ".", PATH_MAX); |
pathgen(cwd, buf, &req); |
pathgen(cwd, buf, &req); |
closedir(cwd); |
closedir(cwd); |
|
|
|
|
pathstop(DIR *dir) |
pathstop(DIR *dir) |
{ |
{ |
struct dirent *d; |
struct dirent *d; |
|
#if defined(__sun) |
|
struct stat sb; |
|
#endif |
|
|
while (NULL != (d = readdir(dir))) |
while (NULL != (d = readdir(dir))) { |
|
#if defined(__sun) |
|
stat(d->d_name, &sb); |
|
if (S_IFREG & sb.st_mode) |
|
#else |
if (DT_REG == d->d_type) |
if (DT_REG == d->d_type) |
|
#endif |
if (0 == strcmp(d->d_name, "catman.conf")) |
if (0 == strcmp(d->d_name, "catman.conf")) |
return(1); |
return(1); |
|
} |
|
|
return(0); |
return(0); |
} |
} |
Line 1119 pathgen(DIR *dir, char *path, struct req *req) |
|
Line 1134 pathgen(DIR *dir, char *path, struct req *req) |
|
DIR *cd; |
DIR *cd; |
int rc; |
int rc; |
size_t sz, ssz; |
size_t sz, ssz; |
|
#if defined(__sun) |
|
struct stat sb; |
|
#endif |
|
|
sz = strlcat(path, "/", MAXPATHLEN); |
sz = strlcat(path, "/", PATH_MAX); |
if (sz >= MAXPATHLEN) { |
if (sz >= PATH_MAX) { |
fprintf(stderr, "%s: Path too long", path); |
fprintf(stderr, "%s: Path too long", path); |
return; |
return; |
} |
} |
Line 1134 pathgen(DIR *dir, char *path, struct req *req) |
|
Line 1152 pathgen(DIR *dir, char *path, struct req *req) |
|
|
|
rc = 0; |
rc = 0; |
while (0 == rc && NULL != (d = readdir(dir))) { |
while (0 == rc && NULL != (d = readdir(dir))) { |
if (DT_DIR != d->d_type || strcmp(d->d_name, "etc")) |
#if defined(__sun) |
|
stat(d->d_name, &sb); |
|
if (!(S_IFDIR & sb.st_mode) |
|
#else |
|
if (DT_DIR != d->d_type |
|
#endif |
|
|| strcmp(d->d_name, "etc")) |
continue; |
continue; |
|
|
path[(int)sz] = '\0'; |
path[(int)sz] = '\0'; |
ssz = strlcat(path, d->d_name, MAXPATHLEN); |
ssz = strlcat(path, d->d_name, PATH_MAX); |
|
|
if (ssz >= MAXPATHLEN) { |
if (ssz >= PATH_MAX) { |
fprintf(stderr, "%s: Path too long", path); |
fprintf(stderr, "%s: Path too long", path); |
return; |
return; |
} else if (NULL == (cd = opendir(path))) { |
} else if (NULL == (cd = opendir(path))) { |
Line 1183 pathgen(DIR *dir, char *path, struct req *req) |
|
Line 1207 pathgen(DIR *dir, char *path, struct req *req) |
|
|
|
rewinddir(dir); |
rewinddir(dir); |
while (NULL != (d = readdir(dir))) { |
while (NULL != (d = readdir(dir))) { |
if (DT_DIR != d->d_type || '.' == d->d_name[0]) |
#if defined(__sun) |
|
stat(d->d_name, &sb); |
|
if (!(S_IFDIR & sb.st_mode) |
|
#else |
|
if (DT_DIR != d->d_type |
|
#endif |
|
|| '.' == d->d_name[0]) |
continue; |
continue; |
|
|
path[(int)sz] = '\0'; |
path[(int)sz] = '\0'; |
ssz = strlcat(path, d->d_name, MAXPATHLEN); |
ssz = strlcat(path, d->d_name, PATH_MAX); |
|
|
if (ssz >= MAXPATHLEN) { |
if (ssz >= PATH_MAX) { |
fprintf(stderr, "%s: Path too long", path); |
fprintf(stderr, "%s: Path too long", path); |
return; |
return; |
} else if (NULL == (cd = opendir(path))) { |
} else if (NULL == (cd = opendir(path))) { |