version 1.192, 2017/07/20 14:36:36 |
version 1.197, 2018/08/23 14:29:38 |
|
|
/* $Id$ */ |
/* $Id$ */ |
/* |
/* |
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> |
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> |
* Copyright (c) 2010-2017 Ingo Schwarze <schwarze@openbsd.org> |
* Copyright (c) 2010-2018 Ingo Schwarze <schwarze@openbsd.org> |
* Copyright (c) 2010, 2012 Joerg Sonnenberger <joerg@netbsd.org> |
* Copyright (c) 2010, 2012 Joerg Sonnenberger <joerg@netbsd.org> |
* |
* |
* Permission to use, copy, modify, and distribute this software for any |
* Permission to use, copy, modify, and distribute this software for any |
|
|
|
|
static void choose_parser(struct mparse *); |
static void choose_parser(struct mparse *); |
static void resize_buf(struct buf *, size_t); |
static void resize_buf(struct buf *, size_t); |
static int mparse_buf_r(struct mparse *, struct buf, size_t, int); |
static enum rofferr mparse_buf_r(struct mparse *, struct buf, size_t, int); |
static int read_whole_file(struct mparse *, const char *, int, |
static int read_whole_file(struct mparse *, const char *, int, |
struct buf *, int *); |
struct buf *, int *); |
static void mparse_end(struct mparse *); |
static void mparse_end(struct mparse *); |
Line 94 static const char * const mandocerrs[MANDOCERR_MAX] = |
|
Line 94 static const char * const mandocerrs[MANDOCERR_MAX] = |
|
"generic style suggestion", |
"generic style suggestion", |
|
|
"legacy man(7) date format", |
"legacy man(7) date format", |
|
"normalizing date format to", |
"lower case character in document title", |
"lower case character in document title", |
"duplicate RCS id", |
"duplicate RCS id", |
"typo in section name", |
"possible typo in section name", |
"unterminated quoted argument", |
"unterminated quoted argument", |
"useless macro", |
"useless macro", |
"consider using OS macro", |
"consider using OS macro", |
Line 106 static const char * const mandocerrs[MANDOCERR_MAX] = |
|
Line 107 static const char * const mandocerrs[MANDOCERR_MAX] = |
|
"no blank before trailing delimiter", |
"no blank before trailing delimiter", |
"fill mode already enabled, skipping", |
"fill mode already enabled, skipping", |
"fill mode already disabled, skipping", |
"fill mode already disabled, skipping", |
|
"verbatim \"--\", maybe consider using \\(em", |
"function name without markup", |
"function name without markup", |
"whitespace at end of input line", |
"whitespace at end of input line", |
"bad comment style", |
"bad comment style", |
Line 231 static const char * const mandocerrs[MANDOCERR_MAX] = |
|
Line 233 static const char * const mandocerrs[MANDOCERR_MAX] = |
|
"input stack limit exceeded, infinite loop?", |
"input stack limit exceeded, infinite loop?", |
"skipping bad character", |
"skipping bad character", |
"skipping unknown macro", |
"skipping unknown macro", |
|
"ignoring request outside macro", |
"skipping insecure request", |
"skipping insecure request", |
"skipping item outside list", |
"skipping item outside list", |
"skipping column outside column list", |
"skipping column outside column list", |
Line 241 static const char * const mandocerrs[MANDOCERR_MAX] = |
|
Line 244 static const char * const mandocerrs[MANDOCERR_MAX] = |
|
|
|
/* related to request and macro arguments */ |
/* related to request and macro arguments */ |
"escaped character not allowed in a name", |
"escaped character not allowed in a name", |
|
"using macro argument outside macro", |
|
"argument number is not numeric", |
"NOT IMPLEMENTED: Bd -file", |
"NOT IMPLEMENTED: Bd -file", |
"skipping display without arguments", |
"skipping display without arguments", |
"missing list type, using -item", |
"missing list type, using -item", |
Line 249 static const char * const mandocerrs[MANDOCERR_MAX] = |
|
Line 254 static const char * const mandocerrs[MANDOCERR_MAX] = |
|
"uname(3) system call failed, using UNKNOWN", |
"uname(3) system call failed, using UNKNOWN", |
"unknown standard specifier", |
"unknown standard specifier", |
"skipping request without numeric argument", |
"skipping request without numeric argument", |
|
"excessive shift", |
"NOT IMPLEMENTED: .so with absolute path or \"..\"", |
"NOT IMPLEMENTED: .so with absolute path or \"..\"", |
".so request failed", |
".so request failed", |
"skipping all arguments", |
"skipping all arguments", |
Line 336 choose_parser(struct mparse *curp) |
|
Line 342 choose_parser(struct mparse *curp) |
|
* macros, inline equations, and input line traps) |
* macros, inline equations, and input line traps) |
* and indirectly (for .so file inclusion). |
* and indirectly (for .so file inclusion). |
*/ |
*/ |
static int |
static enum rofferr |
mparse_buf_r(struct mparse *curp, struct buf blk, size_t i, int start) |
mparse_buf_r(struct mparse *curp, struct buf blk, size_t i, int start) |
{ |
{ |
struct buf ln; |
struct buf ln; |
const char *save_file; |
const char *save_file; |
char *cp; |
char *cp; |
size_t pos; /* byte number in the ln buffer */ |
size_t pos; /* byte number in the ln buffer */ |
enum rofferr rr; |
enum rofferr line_result, sub_result; |
int of; |
int of; |
int lnn; /* line number in the real file */ |
int lnn; /* line number in the real file */ |
int fd; |
int fd; |
Line 466 mparse_buf_r(struct mparse *curp, struct buf blk, size |
|
Line 472 mparse_buf_r(struct mparse *curp, struct buf blk, size |
|
[curp->secondary->sz] = '\0'; |
[curp->secondary->sz] = '\0'; |
} |
} |
rerun: |
rerun: |
rr = roff_parseln(curp->roff, curp->line, &ln, &of); |
line_result = roff_parseln(curp->roff, curp->line, &ln, &of); |
|
|
switch (rr) { |
switch (line_result) { |
case ROFF_REPARSE: |
case ROFF_REPARSE: |
if (++curp->reparse_count > REPARSE_LIMIT) |
case ROFF_USERCALL: |
|
if (++curp->reparse_count > REPARSE_LIMIT) { |
|
sub_result = ROFF_IGN; |
mandoc_msg(MANDOCERR_ROFFLOOP, curp, |
mandoc_msg(MANDOCERR_ROFFLOOP, curp, |
curp->line, pos, NULL); |
curp->line, pos, NULL); |
else if (mparse_buf_r(curp, ln, of, 0) == 1 || |
} else { |
start == 1) { |
sub_result = mparse_buf_r(curp, ln, of, 0); |
|
if (line_result == ROFF_USERCALL) { |
|
if (sub_result == ROFF_USERRET) |
|
sub_result = ROFF_CONT; |
|
roff_userret(curp->roff); |
|
} |
|
if (start || sub_result == ROFF_CONT) { |
|
pos = 0; |
|
continue; |
|
} |
|
} |
|
free(ln.buf); |
|
return sub_result; |
|
case ROFF_USERRET: |
|
if (start) { |
pos = 0; |
pos = 0; |
continue; |
continue; |
} |
} |
free(ln.buf); |
free(ln.buf); |
return 0; |
return ROFF_USERRET; |
case ROFF_APPEND: |
case ROFF_APPEND: |
pos = strlen(ln.buf); |
pos = strlen(ln.buf); |
continue; |
continue; |
|
|
(i >= blk.sz || blk.buf[i] == '\0')) { |
(i >= blk.sz || blk.buf[i] == '\0')) { |
curp->sodest = mandoc_strdup(ln.buf + of); |
curp->sodest = mandoc_strdup(ln.buf + of); |
free(ln.buf); |
free(ln.buf); |
return 1; |
return ROFF_CONT; |
} |
} |
/* |
/* |
* We remove `so' clauses from our lookaside |
* We remove `so' clauses from our lookaside |
|
|
} |
} |
|
|
free(ln.buf); |
free(ln.buf); |
return 1; |
return ROFF_CONT; |
} |
} |
|
|
static int |
static int |
Line 556 read_whole_file(struct mparse *curp, const char *file, |
|
Line 578 read_whole_file(struct mparse *curp, const char *file, |
|
gzFile gz; |
gzFile gz; |
size_t off; |
size_t off; |
ssize_t ssz; |
ssize_t ssz; |
|
int gzerrnum, retval; |
|
|
if (fstat(fd, &st) == -1) { |
if (fstat(fd, &st) == -1) { |
mandoc_vmsg(MANDOCERR_FILE, curp, 0, 0, |
mandoc_vmsg(MANDOCERR_FILE, curp, 0, 0, |
Line 583 read_whole_file(struct mparse *curp, const char *file, |
|
Line 606 read_whole_file(struct mparse *curp, const char *file, |
|
} |
} |
|
|
if (curp->gzip) { |
if (curp->gzip) { |
|
/* |
|
* Duplicating the file descriptor is required |
|
* because we will have to call gzclose(3) |
|
* to free memory used internally by zlib, |
|
* but that will also close the file descriptor, |
|
* which this function must not do. |
|
*/ |
|
if ((fd = dup(fd)) == -1) { |
|
mandoc_vmsg(MANDOCERR_FILE, curp, 0, 0, |
|
"dup: %s", strerror(errno)); |
|
return 0; |
|
} |
if ((gz = gzdopen(fd, "rb")) == NULL) { |
if ((gz = gzdopen(fd, "rb")) == NULL) { |
mandoc_vmsg(MANDOCERR_FILE, curp, 0, 0, |
mandoc_vmsg(MANDOCERR_FILE, curp, 0, 0, |
"gzdopen: %s", strerror(errno)); |
"gzdopen: %s", strerror(errno)); |
|
close(fd); |
return 0; |
return 0; |
} |
} |
} else |
} else |
Line 598 read_whole_file(struct mparse *curp, const char *file, |
|
Line 634 read_whole_file(struct mparse *curp, const char *file, |
|
|
|
*with_mmap = 0; |
*with_mmap = 0; |
off = 0; |
off = 0; |
|
retval = 0; |
fb->sz = 0; |
fb->sz = 0; |
fb->buf = NULL; |
fb->buf = NULL; |
for (;;) { |
for (;;) { |
Line 614 read_whole_file(struct mparse *curp, const char *file, |
|
Line 651 read_whole_file(struct mparse *curp, const char *file, |
|
read(fd, fb->buf + (int)off, fb->sz - off); |
read(fd, fb->buf + (int)off, fb->sz - off); |
if (ssz == 0) { |
if (ssz == 0) { |
fb->sz = off; |
fb->sz = off; |
return 1; |
retval = 1; |
|
break; |
} |
} |
if (ssz == -1) { |
if (ssz == -1) { |
mandoc_vmsg(MANDOCERR_FILE, curp, 0, 0, |
if (curp->gzip) |
"read: %s", strerror(errno)); |
(void)gzerror(gz, &gzerrnum); |
|
mandoc_vmsg(MANDOCERR_FILE, curp, 0, 0, "read: %s", |
|
curp->gzip && gzerrnum != Z_ERRNO ? |
|
zError(gzerrnum) : strerror(errno)); |
break; |
break; |
} |
} |
off += (size_t)ssz; |
off += (size_t)ssz; |
} |
} |
|
|
free(fb->buf); |
if (curp->gzip && (gzerrnum = gzclose(gz)) != Z_OK) |
fb->buf = NULL; |
mandoc_vmsg(MANDOCERR_FILE, curp, 0, 0, "gzclose: %s", |
return 0; |
gzerrnum == Z_ERRNO ? strerror(errno) : |
|
zError(gzerrnum)); |
|
if (retval == 0) { |
|
free(fb->buf); |
|
fb->buf = NULL; |
|
} |
|
return retval; |
} |
} |
|
|
static void |
static void |