version 1.150.2.6, 2017/01/28 23:35:05 |
version 1.161, 2017/02/18 17:29:28 |
|
|
#include "config.h" |
#include "config.h" |
|
|
#include <sys/types.h> |
#include <sys/types.h> |
#if HAVE_MMAP |
|
#include <sys/mman.h> |
#include <sys/mman.h> |
#include <sys/stat.h> |
#include <sys/stat.h> |
#endif |
|
|
|
#include <assert.h> |
#include <assert.h> |
#include <ctype.h> |
#include <ctype.h> |
|
|
#include <errno.h> |
#include <errno.h> |
#include <fcntl.h> |
#include <fcntl.h> |
#include <stdarg.h> |
#include <stdarg.h> |
#include <stdint.h> |
|
#include <stdio.h> |
#include <stdio.h> |
#include <stdlib.h> |
#include <stdlib.h> |
#include <string.h> |
#include <string.h> |
|
|
#define REPARSE_LIMIT 1000 |
#define REPARSE_LIMIT 1000 |
|
|
struct mparse { |
struct mparse { |
struct roff_man *man; /* man parser */ |
|
struct roff *roff; /* roff parser (!NULL) */ |
struct roff *roff; /* roff parser (!NULL) */ |
|
struct roff_man *man; /* man parser */ |
char *sodest; /* filename pointed to by .so */ |
char *sodest; /* filename pointed to by .so */ |
const char *file; /* filename of current input file */ |
const char *file; /* filename of current input file */ |
struct buf *primary; /* buffer currently being parsed */ |
struct buf *primary; /* buffer currently being parsed */ |
|
|
read_whole_file(struct mparse *curp, const char *file, int fd, |
read_whole_file(struct mparse *curp, const char *file, int fd, |
struct buf *fb, int *with_mmap) |
struct buf *fb, int *with_mmap) |
{ |
{ |
|
struct stat st; |
gzFile gz; |
gzFile gz; |
size_t off; |
size_t off; |
ssize_t ssz; |
ssize_t ssz; |
|
|
#if HAVE_MMAP |
|
struct stat st; |
|
|
|
if (fstat(fd, &st) == -1) |
if (fstat(fd, &st) == -1) |
err((int)MANDOCLEVEL_SYSERR, "%s", file); |
err((int)MANDOCLEVEL_SYSERR, "%s", file); |
|
|
Line 633 read_whole_file(struct mparse *curp, const char *file, |
|
Line 628 read_whole_file(struct mparse *curp, const char *file, |
|
if (fb->buf != MAP_FAILED) |
if (fb->buf != MAP_FAILED) |
return 1; |
return 1; |
} |
} |
#endif |
|
|
|
if (curp->gzip) { |
if (curp->gzip) { |
if ((gz = gzdopen(fd, "rb")) == NULL) |
if ((gz = gzdopen(fd, "rb")) == NULL) |
Line 758 mparse_readfd(struct mparse *curp, int fd, const char |
|
Line 752 mparse_readfd(struct mparse *curp, int fd, const char |
|
(MPARSE_UTF8 | MPARSE_LATIN1); |
(MPARSE_UTF8 | MPARSE_LATIN1); |
mparse_parse_buffer(curp, blk, file); |
mparse_parse_buffer(curp, blk, file); |
curp->filenc = save_filenc; |
curp->filenc = save_filenc; |
#if HAVE_MMAP |
|
if (with_mmap) |
if (with_mmap) |
munmap(blk.buf, blk.sz); |
munmap(blk.buf, blk.sz); |
else |
else |
#endif |
|
free(blk.buf); |
free(blk.buf); |
} |
} |
return curp->file_status; |
return curp->file_status; |
Line 836 mparse_reset(struct mparse *curp) |
|
Line 828 mparse_reset(struct mparse *curp) |
|
{ |
{ |
roff_reset(curp->roff); |
roff_reset(curp->roff); |
roff_man_reset(curp->man); |
roff_man_reset(curp->man); |
|
|
|
free(curp->sodest); |
|
curp->sodest = NULL; |
|
|
if (curp->secondary) |
if (curp->secondary) |
curp->secondary->sz = 0; |
curp->secondary->sz = 0; |
|
|
curp->file_status = MANDOCLEVEL_OK; |
curp->file_status = MANDOCLEVEL_OK; |
|
curp->gzip = 0; |
free(curp->sodest); |
|
curp->sodest = NULL; |
|
} |
} |
|
|
void |
void |
Line 850 mparse_free(struct mparse *curp) |
|
Line 844 mparse_free(struct mparse *curp) |
|
{ |
{ |
|
|
roff_man_free(curp->man); |
roff_man_free(curp->man); |
if (curp->roff) |
roff_free(curp->roff); |
roff_free(curp->roff); |
|
if (curp->secondary) |
if (curp->secondary) |
free(curp->secondary->buf); |
free(curp->secondary->buf); |
|
|