version 1.215, 2014/07/01 00:32:29 |
version 1.232, 2014/10/20 02:33:06 |
|
|
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF |
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. |
*/ |
*/ |
#ifdef HAVE_CONFIG_H |
|
#include "config.h" |
#include "config.h" |
#endif |
|
|
|
|
#include <sys/types.h> |
|
|
#include <assert.h> |
#include <assert.h> |
#include <ctype.h> |
#include <ctype.h> |
#include <stdio.h> |
#include <stdio.h> |
|
|
|
|
#include "mandoc.h" |
#include "mandoc.h" |
#include "mandoc_aux.h" |
#include "mandoc_aux.h" |
#include "libroff.h" |
|
#include "libmandoc.h" |
#include "libmandoc.h" |
|
#include "libroff.h" |
|
|
/* Maximum number of nested if-else conditionals. */ |
/* Maximum number of nested if-else conditionals. */ |
#define RSTACK_MAX 128 |
#define RSTACK_MAX 128 |
|
|
ROFF_nh, |
ROFF_nh, |
ROFF_nr, |
ROFF_nr, |
ROFF_ns, |
ROFF_ns, |
|
ROFF_pl, |
ROFF_ps, |
ROFF_ps, |
ROFF_rm, |
ROFF_rm, |
ROFF_rr, |
ROFF_rr, |
Line 106 struct roffreg { |
|
Line 107 struct roffreg { |
|
|
|
struct roff { |
struct roff { |
struct mparse *parse; /* parse point */ |
struct mparse *parse; /* parse point */ |
int options; /* parse options */ |
|
struct roffnode *last; /* leaf of stack */ |
struct roffnode *last; /* leaf of stack */ |
int rstack[RSTACK_MAX]; /* stack of !`ie' rules */ |
int *rstack; /* stack of inverted `ie' values */ |
char control; /* control character */ |
|
int rstackpos; /* position in rstack */ |
|
struct roffreg *regtab; /* number registers */ |
struct roffreg *regtab; /* number registers */ |
struct roffkv *strtab; /* user-defined strings & macros */ |
struct roffkv *strtab; /* user-defined strings & macros */ |
struct roffkv *xmbtab; /* multi-byte trans table (`tr') */ |
struct roffkv *xmbtab; /* multi-byte trans table (`tr') */ |
|
|
struct eqn_node *last_eqn; /* last equation parsed */ |
struct eqn_node *last_eqn; /* last equation parsed */ |
struct eqn_node *first_eqn; /* first equation parsed */ |
struct eqn_node *first_eqn; /* first equation parsed */ |
struct eqn_node *eqn; /* current equation being parsed */ |
struct eqn_node *eqn; /* current equation being parsed */ |
|
int eqn_inline; /* current equation is inline */ |
|
int options; /* parse options */ |
|
int rstacksz; /* current size limit of rstack */ |
|
int rstackpos; /* position in rstack */ |
|
int format; /* current file in mdoc or man format */ |
|
char control; /* control character */ |
}; |
}; |
|
|
struct roffnode { |
struct roffnode { |
Line 180 static enum rofferr roff_cond(ROFF_ARGS); |
|
Line 184 static enum rofferr roff_cond(ROFF_ARGS); |
|
static enum rofferr roff_cond_text(ROFF_ARGS); |
static enum rofferr roff_cond_text(ROFF_ARGS); |
static enum rofferr roff_cond_sub(ROFF_ARGS); |
static enum rofferr roff_cond_sub(ROFF_ARGS); |
static enum rofferr roff_ds(ROFF_ARGS); |
static enum rofferr roff_ds(ROFF_ARGS); |
|
static enum rofferr roff_eqndelim(struct roff *, |
|
char **, size_t *, int); |
static int roff_evalcond(const char *, int *); |
static int roff_evalcond(const char *, int *); |
static int roff_evalnum(const char *, int *, int *, int); |
static int roff_evalnum(const char *, int *, int *, int); |
static int roff_evalpar(const char *, int *, int *); |
static int roff_evalpar(const char *, int *, int *); |
Line 254 static struct roffmac roffs[ROFF_MAX] = { |
|
Line 260 static struct roffmac roffs[ROFF_MAX] = { |
|
{ "nh", roff_line_ignore, NULL, NULL, 0, NULL }, |
{ "nh", roff_line_ignore, NULL, NULL, 0, NULL }, |
{ "nr", roff_nr, NULL, NULL, 0, NULL }, |
{ "nr", roff_nr, NULL, NULL, 0, NULL }, |
{ "ns", roff_line_ignore, NULL, NULL, 0, NULL }, |
{ "ns", roff_line_ignore, NULL, NULL, 0, NULL }, |
|
{ "pl", roff_line_ignore, NULL, NULL, 0, NULL }, |
{ "ps", roff_line_ignore, NULL, NULL, 0, NULL }, |
{ "ps", roff_line_ignore, NULL, NULL, 0, NULL }, |
{ "rm", roff_rm, NULL, NULL, 0, NULL }, |
{ "rm", roff_rm, NULL, NULL, 0, NULL }, |
{ "rr", roff_rr, NULL, NULL, 0, NULL }, |
{ "rr", roff_rr, NULL, NULL, 0, NULL }, |
Line 420 roff_free1(struct roff *r) |
|
Line 427 roff_free1(struct roff *r) |
|
r->first_tbl = tbl->next; |
r->first_tbl = tbl->next; |
tbl_free(tbl); |
tbl_free(tbl); |
} |
} |
|
|
r->first_tbl = r->last_tbl = r->tbl = NULL; |
r->first_tbl = r->last_tbl = r->tbl = NULL; |
|
|
while (NULL != (e = r->first_eqn)) { |
while (NULL != (e = r->first_eqn)) { |
r->first_eqn = e->next; |
r->first_eqn = e->next; |
eqn_free(e); |
eqn_free(e); |
} |
} |
|
|
r->first_eqn = r->last_eqn = r->eqn = NULL; |
r->first_eqn = r->last_eqn = r->eqn = NULL; |
|
|
while (r->last) |
while (r->last) |
roffnode_pop(r); |
roffnode_pop(r); |
|
|
roff_freestr(r->strtab); |
free (r->rstack); |
roff_freestr(r->xmbtab); |
r->rstack = NULL; |
|
r->rstacksz = 0; |
|
r->rstackpos = -1; |
|
|
r->strtab = r->xmbtab = NULL; |
|
|
|
roff_freereg(r->regtab); |
roff_freereg(r->regtab); |
|
|
r->regtab = NULL; |
r->regtab = NULL; |
|
|
|
roff_freestr(r->strtab); |
|
roff_freestr(r->xmbtab); |
|
r->strtab = r->xmbtab = NULL; |
|
|
if (r->xtab) |
if (r->xtab) |
for (i = 0; i < 128; i++) |
for (i = 0; i < 128; i++) |
free(r->xtab[i].p); |
free(r->xtab[i].p); |
|
|
free(r->xtab); |
free(r->xtab); |
r->xtab = NULL; |
r->xtab = NULL; |
} |
} |
Line 455 roff_reset(struct roff *r) |
|
Line 462 roff_reset(struct roff *r) |
|
{ |
{ |
|
|
roff_free1(r); |
roff_free1(r); |
|
r->format = r->options & (MPARSE_MDOC | MPARSE_MAN); |
r->control = 0; |
r->control = 0; |
} |
} |
|
|
Line 474 roff_alloc(struct mparse *parse, int options) |
|
Line 482 roff_alloc(struct mparse *parse, int options) |
|
r = mandoc_calloc(1, sizeof(struct roff)); |
r = mandoc_calloc(1, sizeof(struct roff)); |
r->parse = parse; |
r->parse = parse; |
r->options = options; |
r->options = options; |
|
r->format = options & (MPARSE_MDOC | MPARSE_MAN); |
r->rstackpos = -1; |
r->rstackpos = -1; |
|
|
roffhash_init(); |
roffhash_init(); |
Line 500 roff_res(struct roff *r, char **bufp, size_t *szp, int |
|
Line 509 roff_res(struct roff *r, char **bufp, size_t *szp, int |
|
size_t naml; /* actual length of the escape name */ |
size_t naml; /* actual length of the escape name */ |
int expand_count; /* to avoid infinite loops */ |
int expand_count; /* to avoid infinite loops */ |
int npos; /* position in numeric expression */ |
int npos; /* position in numeric expression */ |
int irc; /* return code from roff_evalnum() */ |
int arg_complete; /* argument not interrupted by eol */ |
char term; /* character terminating the escape */ |
char term; /* character terminating the escape */ |
|
|
expand_count = 0; |
expand_count = 0; |
Line 542 roff_res(struct roff *r, char **bufp, size_t *szp, int |
|
Line 551 roff_res(struct roff *r, char **bufp, size_t *szp, int |
|
break; |
break; |
default: |
default: |
if (ESCAPE_ERROR == mandoc_escape(&cp, NULL, NULL)) |
if (ESCAPE_ERROR == mandoc_escape(&cp, NULL, NULL)) |
mandoc_msg(MANDOCERR_BADESCAPE, r->parse, |
mandoc_vmsg(MANDOCERR_ESC_BAD, |
ln, (int)(stesc - *bufp), NULL); |
r->parse, ln, (int)(stesc - *bufp), |
|
"%.*s", (int)(cp - stesc), stesc); |
continue; |
continue; |
} |
} |
|
|
Line 585 roff_res(struct roff *r, char **bufp, size_t *szp, int |
|
Line 595 roff_res(struct roff *r, char **bufp, size_t *szp, int |
|
|
|
/* Advance to the end of the name. */ |
/* Advance to the end of the name. */ |
|
|
|
arg_complete = 1; |
for (naml = 0; 0 == maxl || naml < maxl; naml++, cp++) { |
for (naml = 0; 0 == maxl || naml < maxl; naml++, cp++) { |
if ('\0' == *cp) { |
if ('\0' == *cp) { |
mandoc_msg(MANDOCERR_BADESCAPE, r->parse, |
mandoc_msg(MANDOCERR_ESC_BAD, r->parse, |
ln, (int)(stesc - *bufp), NULL); |
ln, (int)(stesc - *bufp), stesc); |
|
arg_complete = 0; |
break; |
break; |
} |
} |
if (0 == maxl && *cp == term) { |
if (0 == maxl && *cp == term) { |
Line 604 roff_res(struct roff *r, char **bufp, size_t *szp, int |
|
Line 616 roff_res(struct roff *r, char **bufp, size_t *szp, int |
|
|
|
switch (stesc[1]) { |
switch (stesc[1]) { |
case '*': |
case '*': |
res = roff_getstrn(r, stnam, naml); |
if (arg_complete) |
|
res = roff_getstrn(r, stnam, naml); |
break; |
break; |
case 'B': |
case 'B': |
npos = 0; |
npos = 0; |
irc = roff_evalnum(stnam, &npos, NULL, 0); |
ubuf[0] = arg_complete && |
ubuf[0] = irc && stnam + npos + 1 == cp |
roff_evalnum(stnam, &npos, NULL, 0) && |
? '1' : '0'; |
stnam + npos + 1 == cp ? '1' : '0'; |
ubuf[1] = '\0'; |
ubuf[1] = '\0'; |
break; |
break; |
case 'n': |
case 'n': |
(void)snprintf(ubuf, sizeof(ubuf), "%d", |
if (arg_complete) |
roff_getregn(r, stnam, naml)); |
(void)snprintf(ubuf, sizeof(ubuf), "%d", |
|
roff_getregn(r, stnam, naml)); |
|
else |
|
ubuf[0] = '\0'; |
break; |
break; |
case 'w': |
case 'w': |
|
/* use even incomplete args */ |
(void)snprintf(ubuf, sizeof(ubuf), "%d", |
(void)snprintf(ubuf, sizeof(ubuf), "%d", |
24 * (int)naml); |
24 * (int)naml); |
break; |
break; |
} |
} |
|
|
if (NULL == res) { |
if (NULL == res) { |
mandoc_msg(MANDOCERR_BADESCAPE, r->parse, |
mandoc_vmsg(MANDOCERR_STR_UNDEF, |
ln, (int)(stesc - *bufp), NULL); |
r->parse, ln, (int)(stesc - *bufp), |
|
"%.*s", (int)naml, stnam); |
res = ""; |
res = ""; |
} |
} |
|
|
Line 709 roff_parseln(struct roff *r, int ln, char **bufp, |
|
Line 727 roff_parseln(struct roff *r, int ln, char **bufp, |
|
enum rofferr e; |
enum rofferr e; |
int ppos, ctl; |
int ppos, ctl; |
|
|
/* |
/* Handle in-line equation delimiters. */ |
* Run the reserved-word filter only if we have some reserved |
|
* words to fill in. |
|
*/ |
|
|
|
|
if (r->last_eqn != NULL && r->last_eqn->delim && |
|
(r->eqn == NULL || r->eqn_inline)) { |
|
e = roff_eqndelim(r, bufp, szp, pos); |
|
if (e == ROFF_REPARSE) |
|
return(e); |
|
assert(e == ROFF_CONT); |
|
} |
|
|
|
/* Expand some escape sequences. */ |
|
|
e = roff_res(r, bufp, szp, ln, pos); |
e = roff_res(r, bufp, szp, ln, pos); |
if (ROFF_IGN == e) |
if (ROFF_IGN == e) |
return(e); |
return(e); |
Line 746 roff_parseln(struct roff *r, int ln, char **bufp, |
|
Line 771 roff_parseln(struct roff *r, int ln, char **bufp, |
|
return(roff_parsetext(bufp, szp, pos, offs)); |
return(roff_parsetext(bufp, szp, pos, offs)); |
} |
} |
|
|
|
/* Skip empty request lines. */ |
|
|
|
if ((*bufp)[pos] == '"') { |
|
mandoc_msg(MANDOCERR_COMMENT_BAD, r->parse, |
|
ln, pos, NULL); |
|
return(ROFF_IGN); |
|
} else if ((*bufp)[pos] == '\0') |
|
return(ROFF_IGN); |
|
|
/* |
/* |
* If a scope is open, go to the child handler for that macro, |
* If a scope is open, go to the child handler for that macro, |
* as it may want to preprocess before doing anything with it. |
* as it may want to preprocess before doing anything with it. |
Line 777 roff_endparse(struct roff *r) |
|
Line 811 roff_endparse(struct roff *r) |
|
{ |
{ |
|
|
if (r->last) |
if (r->last) |
mandoc_msg(MANDOCERR_SCOPEEXIT, r->parse, |
mandoc_msg(MANDOCERR_BLK_NOEND, r->parse, |
r->last->line, r->last->col, NULL); |
r->last->line, r->last->col, |
|
roffs[r->last->tok].name); |
|
|
if (r->eqn) { |
if (r->eqn) { |
mandoc_msg(MANDOCERR_SCOPEEXIT, r->parse, |
mandoc_msg(MANDOCERR_BLK_NOEND, r->parse, |
r->eqn->eqn.ln, r->eqn->eqn.pos, NULL); |
r->eqn->eqn.ln, r->eqn->eqn.pos, "EQ"); |
eqn_end(&r->eqn); |
eqn_end(&r->eqn); |
} |
} |
|
|
if (r->tbl) { |
if (r->tbl) { |
mandoc_msg(MANDOCERR_SCOPEEXIT, r->parse, |
mandoc_msg(MANDOCERR_BLK_NOEND, r->parse, |
r->tbl->line, r->tbl->pos, NULL); |
r->tbl->line, r->tbl->pos, "TS"); |
tbl_end(&r->tbl); |
tbl_end(&r->tbl); |
} |
} |
} |
} |
Line 832 roff_cblock(ROFF_ARGS) |
|
Line 867 roff_cblock(ROFF_ARGS) |
|
*/ |
*/ |
|
|
if (NULL == r->last) { |
if (NULL == r->last) { |
mandoc_msg(MANDOCERR_NOSCOPE, r->parse, ln, ppos, NULL); |
mandoc_msg(MANDOCERR_BLK_NOTOPEN, r->parse, |
|
ln, ppos, ".."); |
return(ROFF_IGN); |
return(ROFF_IGN); |
} |
} |
|
|
switch (r->last->tok) { |
switch (r->last->tok) { |
case ROFF_am: |
case ROFF_am: |
|
/* ROFF_am1 is remapped to ROFF_am in roff_block(). */ |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
case ROFF_ami: |
case ROFF_ami: |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
case ROFF_am1: |
|
/* FALLTHROUGH */ |
|
case ROFF_de: |
case ROFF_de: |
/* ROFF_de1 is remapped to ROFF_de in roff_block(). */ |
/* ROFF_de1 is remapped to ROFF_de in roff_block(). */ |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
Line 851 roff_cblock(ROFF_ARGS) |
|
Line 886 roff_cblock(ROFF_ARGS) |
|
case ROFF_ig: |
case ROFF_ig: |
break; |
break; |
default: |
default: |
mandoc_msg(MANDOCERR_NOSCOPE, r->parse, ln, ppos, NULL); |
mandoc_msg(MANDOCERR_BLK_NOTOPEN, r->parse, |
|
ln, ppos, ".."); |
return(ROFF_IGN); |
return(ROFF_IGN); |
} |
} |
|
|
if ((*bufp)[pos]) |
if ((*bufp)[pos]) |
mandoc_msg(MANDOCERR_ARGSLOST, r->parse, ln, pos, NULL); |
mandoc_vmsg(MANDOCERR_ARG_SKIP, r->parse, ln, pos, |
|
".. %s", *bufp + pos); |
|
|
roffnode_pop(r); |
roffnode_pop(r); |
roffnode_cleanscope(r); |
roffnode_cleanscope(r); |
Line 880 roff_ccond(struct roff *r, int ln, int ppos) |
|
Line 917 roff_ccond(struct roff *r, int ln, int ppos) |
|
{ |
{ |
|
|
if (NULL == r->last) { |
if (NULL == r->last) { |
mandoc_msg(MANDOCERR_NOSCOPE, r->parse, ln, ppos, NULL); |
mandoc_msg(MANDOCERR_BLK_NOTOPEN, r->parse, |
|
ln, ppos, "\\}"); |
return; |
return; |
} |
} |
|
|
Line 892 roff_ccond(struct roff *r, int ln, int ppos) |
|
Line 930 roff_ccond(struct roff *r, int ln, int ppos) |
|
case ROFF_if: |
case ROFF_if: |
break; |
break; |
default: |
default: |
mandoc_msg(MANDOCERR_NOSCOPE, r->parse, ln, ppos, NULL); |
mandoc_msg(MANDOCERR_BLK_NOTOPEN, r->parse, |
|
ln, ppos, "\\}"); |
return; |
return; |
} |
} |
|
|
if (r->last->endspan > -1) { |
if (r->last->endspan > -1) { |
mandoc_msg(MANDOCERR_NOSCOPE, r->parse, ln, ppos, NULL); |
mandoc_msg(MANDOCERR_BLK_NOTOPEN, r->parse, |
|
ln, ppos, "\\}"); |
return; |
return; |
} |
} |
|
|
Line 909 roff_ccond(struct roff *r, int ln, int ppos) |
|
Line 949 roff_ccond(struct roff *r, int ln, int ppos) |
|
static enum rofferr |
static enum rofferr |
roff_block(ROFF_ARGS) |
roff_block(ROFF_ARGS) |
{ |
{ |
char *name, *cp; |
const char *name; |
|
char *iname, *cp; |
size_t namesz; |
size_t namesz; |
|
|
name = cp = *bufp + pos; |
/* Ignore groff compatibility mode for now. */ |
namesz = 0; |
|
|
|
if (ROFF_ig != tok) { |
if (ROFF_de1 == tok) |
if ('\0' == *cp) { |
tok = ROFF_de; |
mandoc_msg(MANDOCERR_NOARGS, r->parse, ln, ppos, NULL); |
else if (ROFF_am1 == tok) |
return(ROFF_IGN); |
tok = ROFF_am; |
} |
|
|
|
/* |
/* Parse the macro name argument. */ |
* Re-write `de1', since we don't really care about |
|
* groff's strange compatibility mode, into `de'. |
|
*/ |
|
|
|
if (ROFF_de1 == tok) |
cp = *bufp + pos; |
tok = ROFF_de; |
if (ROFF_ig == tok) { |
else if (ROFF_de != tok) |
iname = NULL; |
mandoc_msg(MANDOCERR_REQUEST, r->parse, ln, ppos, |
namesz = 0; |
roffs[tok].name); |
} else { |
|
iname = cp; |
namesz = roff_getname(r, &cp, ln, ppos); |
namesz = roff_getname(r, &cp, ln, ppos); |
name[namesz] = '\0'; |
iname[namesz] = '\0'; |
|
} |
|
|
|
/* Resolve the macro name argument if it is indirect. */ |
|
|
|
if (namesz && (ROFF_dei == tok || ROFF_ami == tok)) { |
|
if (NULL == (name = roff_getstrn(r, iname, namesz))) { |
|
mandoc_vmsg(MANDOCERR_STR_UNDEF, |
|
r->parse, ln, (int)(iname - *bufp), |
|
"%.*s", (int)namesz, iname); |
|
namesz = 0; |
|
} else |
|
namesz = strlen(name); |
} else |
} else |
name = NULL; |
name = iname; |
|
|
|
if (0 == namesz && ROFF_ig != tok) { |
|
mandoc_msg(MANDOCERR_REQ_EMPTY, r->parse, |
|
ln, ppos, roffs[tok].name); |
|
return(ROFF_IGN); |
|
} |
|
|
roffnode_push(r, tok, name, ln, ppos); |
roffnode_push(r, tok, name, ln, ppos); |
|
|
/* |
/* |
Line 945 roff_block(ROFF_ARGS) |
|
Line 999 roff_block(ROFF_ARGS) |
|
* appended from roff_block_text() in multiline mode. |
* appended from roff_block_text() in multiline mode. |
*/ |
*/ |
|
|
if (namesz && ROFF_de == tok) |
if (ROFF_de == tok || ROFF_dei == tok) |
roff_setstrn(&r->strtab, name, namesz, "", 0, 0); |
roff_setstrn(&r->strtab, name, namesz, "", 0, 0); |
|
|
if ('\0' == *cp) |
if ('\0' == *cp) |
return(ROFF_IGN); |
return(ROFF_IGN); |
|
|
/* If present, process the custom end-of-line marker. */ |
/* Get the custom end marker. */ |
|
|
name = cp; |
iname = cp; |
namesz = roff_getname(r, &cp, ln, ppos); |
namesz = roff_getname(r, &cp, ln, ppos); |
|
|
|
/* Resolve the end marker if it is indirect. */ |
|
|
|
if (namesz && (ROFF_dei == tok || ROFF_ami == tok)) { |
|
if (NULL == (name = roff_getstrn(r, iname, namesz))) { |
|
mandoc_vmsg(MANDOCERR_STR_UNDEF, |
|
r->parse, ln, (int)(iname - *bufp), |
|
"%.*s", (int)namesz, iname); |
|
namesz = 0; |
|
} else |
|
namesz = strlen(name); |
|
} else |
|
name = iname; |
|
|
if (namesz) |
if (namesz) |
r->last->end = mandoc_strndup(name, namesz); |
r->last->end = mandoc_strndup(name, namesz); |
|
|
if ('\0' != *cp) |
if ('\0' != *cp) |
mandoc_msg(MANDOCERR_ARGSLOST, r->parse, ln, pos, NULL); |
mandoc_vmsg(MANDOCERR_ARG_EXCESS, r->parse, |
|
ln, pos, ".%s ... %s", roffs[tok].name, cp); |
|
|
return(ROFF_IGN); |
return(ROFF_IGN); |
} |
} |
Line 1008 roff_block_sub(ROFF_ARGS) |
|
Line 1077 roff_block_sub(ROFF_ARGS) |
|
|
|
t = roff_parse(r, *bufp, &pos, ln, ppos); |
t = roff_parse(r, *bufp, &pos, ln, ppos); |
|
|
/* |
|
* Macros other than block-end are only significant |
|
* in `de' blocks; elsewhere, simply throw them away. |
|
*/ |
|
if (ROFF_cblock != t) { |
if (ROFF_cblock != t) { |
if (ROFF_de == tok) |
if (ROFF_ig != tok) |
roff_setstr(r, r->last->name, *bufp + ppos, 2); |
roff_setstr(r, r->last->name, *bufp + ppos, 2); |
return(ROFF_IGN); |
return(ROFF_IGN); |
} |
} |
Line 1026 static enum rofferr |
|
Line 1091 static enum rofferr |
|
roff_block_text(ROFF_ARGS) |
roff_block_text(ROFF_ARGS) |
{ |
{ |
|
|
if (ROFF_de == tok) |
if (ROFF_ig != tok) |
roff_setstr(r, r->last->name, *bufp + pos, 2); |
roff_setstr(r, r->last->name, *bufp + pos, 2); |
|
|
return(ROFF_IGN); |
return(ROFF_IGN); |
Line 1243 roff_cond(ROFF_ARGS) |
|
Line 1308 roff_cond(ROFF_ARGS) |
|
*/ |
*/ |
|
|
if (ROFF_ie == tok) { |
if (ROFF_ie == tok) { |
if (r->rstackpos == RSTACK_MAX - 1) { |
if (r->rstackpos + 1 == r->rstacksz) { |
mandoc_msg(MANDOCERR_MEM, |
r->rstacksz += 16; |
r->parse, ln, ppos, NULL); |
r->rstack = mandoc_reallocarray(r->rstack, |
return(ROFF_ERR); |
r->rstacksz, sizeof(int)); |
} |
} |
r->rstack[++r->rstackpos] = !r->last->rule; |
r->rstack[++r->rstackpos] = !r->last->rule; |
} |
} |
Line 1285 roff_cond(ROFF_ARGS) |
|
Line 1350 roff_cond(ROFF_ARGS) |
|
*/ |
*/ |
|
|
if ('\0' == (*bufp)[pos]) |
if ('\0' == (*bufp)[pos]) |
mandoc_msg(MANDOCERR_NOARGS, r->parse, ln, ppos, NULL); |
mandoc_msg(MANDOCERR_COND_EMPTY, r->parse, |
|
ln, ppos, roffs[tok].name); |
|
|
r->last->endspan = 1; |
r->last->endspan = 1; |
|
|
Line 1717 roff_it(ROFF_ARGS) |
|
Line 1783 roff_it(ROFF_ARGS) |
|
len = strcspn(cp, " \t"); |
len = strcspn(cp, " \t"); |
cp[len] = '\0'; |
cp[len] = '\0'; |
if ((iv = mandoc_strntoi(cp, len, 10)) <= 0) { |
if ((iv = mandoc_strntoi(cp, len, 10)) <= 0) { |
mandoc_msg(MANDOCERR_NUMERIC, r->parse, |
mandoc_msg(MANDOCERR_IT_NONUM, r->parse, |
ln, ppos, *bufp + 1); |
ln, ppos, *bufp + 1); |
return(ROFF_IGN); |
return(ROFF_IGN); |
} |
} |
Line 1734 roff_Dd(ROFF_ARGS) |
|
Line 1800 roff_Dd(ROFF_ARGS) |
|
{ |
{ |
const char *const *cp; |
const char *const *cp; |
|
|
if (0 == ((MPARSE_MDOC | MPARSE_QUICK) & r->options)) |
if ((r->options & (MPARSE_MDOC | MPARSE_QUICK)) == 0) |
for (cp = __mdoc_reserved; *cp; cp++) |
for (cp = __mdoc_reserved; *cp; cp++) |
roff_setstr(r, *cp, NULL, 0); |
roff_setstr(r, *cp, NULL, 0); |
|
|
|
if (r->format == 0) |
|
r->format = MPARSE_MDOC; |
|
|
return(ROFF_CONT); |
return(ROFF_CONT); |
} |
} |
|
|
Line 1746 roff_TH(ROFF_ARGS) |
|
Line 1815 roff_TH(ROFF_ARGS) |
|
{ |
{ |
const char *const *cp; |
const char *const *cp; |
|
|
if (0 == (MPARSE_QUICK & r->options)) |
if ((r->options & MPARSE_QUICK) == 0) |
for (cp = __man_reserved; *cp; cp++) |
for (cp = __man_reserved; *cp; cp++) |
roff_setstr(r, *cp, NULL, 0); |
roff_setstr(r, *cp, NULL, 0); |
|
|
|
if (r->format == 0) |
|
r->format = MPARSE_MAN; |
|
|
return(ROFF_CONT); |
return(ROFF_CONT); |
} |
} |
|
|
Line 1758 roff_TE(ROFF_ARGS) |
|
Line 1830 roff_TE(ROFF_ARGS) |
|
{ |
{ |
|
|
if (NULL == r->tbl) |
if (NULL == r->tbl) |
mandoc_msg(MANDOCERR_NOSCOPE, r->parse, ln, ppos, NULL); |
mandoc_msg(MANDOCERR_BLK_NOTOPEN, r->parse, |
|
ln, ppos, "TE"); |
else |
else |
tbl_end(&r->tbl); |
tbl_end(&r->tbl); |
|
|
Line 1770 roff_T_(ROFF_ARGS) |
|
Line 1843 roff_T_(ROFF_ARGS) |
|
{ |
{ |
|
|
if (NULL == r->tbl) |
if (NULL == r->tbl) |
mandoc_msg(MANDOCERR_NOSCOPE, r->parse, ln, ppos, NULL); |
mandoc_msg(MANDOCERR_BLK_NOTOPEN, r->parse, |
|
ln, ppos, "T&"); |
else |
else |
tbl_restart(ppos, ln, r->tbl); |
tbl_restart(ppos, ln, r->tbl); |
|
|
return(ROFF_IGN); |
return(ROFF_IGN); |
} |
} |
|
|
#if 0 |
/* |
static int |
* Handle in-line equation delimiters. |
roff_closeeqn(struct roff *r) |
*/ |
|
static enum rofferr |
|
roff_eqndelim(struct roff *r, char **bufp, size_t *szp, int pos) |
{ |
{ |
|
char *cp1, *cp2; |
|
|
return(r->eqn && ROFF_EQN == eqn_end(&r->eqn) ? 1 : 0); |
/* |
|
* Outside equations, look for an opening delimiter. |
|
* If we are inside an equation, we already know it is |
|
* in-line, or this function wouldn't have been called; |
|
* so look for a closing delimiter. |
|
*/ |
|
|
|
cp1 = *bufp + pos; |
|
cp2 = strchr(cp1, r->eqn == NULL ? |
|
r->last_eqn->odelim : r->last_eqn->cdelim); |
|
if (cp2 == NULL) |
|
return(ROFF_CONT); |
|
|
|
/* Replace the delimiter with an equation macro. */ |
|
|
|
*cp2++ = '\0'; |
|
*szp = mandoc_asprintf(&cp1, "%s%s%s", *bufp, |
|
r->eqn == NULL ? "\\&\n.EQ\n" : "\n.EN\n\\&", cp2) + 1; |
|
free(*bufp); |
|
*bufp = cp1; |
|
|
|
/* Toggle the in-line state of the eqn subsystem. */ |
|
|
|
r->eqn_inline = r->eqn == NULL; |
|
return(ROFF_REPARSE); |
} |
} |
#endif |
|
|
|
static void |
static void |
roff_openeqn(struct roff *r, const char *name, int line, |
roff_openeqn(struct roff *r, const char *name, int line, |
Line 1796 roff_openeqn(struct roff *r, const char *name, int lin |
|
Line 1896 roff_openeqn(struct roff *r, const char *name, int lin |
|
assert(NULL == r->eqn); |
assert(NULL == r->eqn); |
e = eqn_alloc(name, offs, line, r->parse); |
e = eqn_alloc(name, offs, line, r->parse); |
|
|
if (r->last_eqn) |
if (r->last_eqn) { |
r->last_eqn->next = e; |
r->last_eqn->next = e; |
else |
e->delim = r->last_eqn->delim; |
|
e->odelim = r->last_eqn->odelim; |
|
e->cdelim = r->last_eqn->cdelim; |
|
} else |
r->first_eqn = r->last_eqn = e; |
r->first_eqn = r->last_eqn = e; |
|
|
r->eqn = r->last_eqn = e; |
r->eqn = r->last_eqn = e; |
Line 1821 static enum rofferr |
|
Line 1924 static enum rofferr |
|
roff_EN(ROFF_ARGS) |
roff_EN(ROFF_ARGS) |
{ |
{ |
|
|
mandoc_msg(MANDOCERR_NOSCOPE, r->parse, ln, ppos, NULL); |
mandoc_msg(MANDOCERR_BLK_NOTOPEN, r->parse, ln, ppos, "EN"); |
return(ROFF_IGN); |
return(ROFF_IGN); |
} |
} |
|
|
Line 1831 roff_TS(ROFF_ARGS) |
|
Line 1934 roff_TS(ROFF_ARGS) |
|
struct tbl_node *tbl; |
struct tbl_node *tbl; |
|
|
if (r->tbl) { |
if (r->tbl) { |
mandoc_msg(MANDOCERR_SCOPEBROKEN, r->parse, ln, ppos, NULL); |
mandoc_msg(MANDOCERR_BLK_BROKEN, r->parse, |
|
ln, ppos, "TS breaks TS"); |
tbl_end(&r->tbl); |
tbl_end(&r->tbl); |
} |
} |
|
|
Line 1883 roff_tr(ROFF_ARGS) |
|
Line 1987 roff_tr(ROFF_ARGS) |
|
if ('\\' == *first) { |
if ('\\' == *first) { |
esc = mandoc_escape(&p, NULL, NULL); |
esc = mandoc_escape(&p, NULL, NULL); |
if (ESCAPE_ERROR == esc) { |
if (ESCAPE_ERROR == esc) { |
mandoc_msg(MANDOCERR_BADESCAPE, |
mandoc_msg(MANDOCERR_ESC_BAD, r->parse, |
r->parse, ln, |
ln, (int)(p - *bufp), first); |
(int)(p - *bufp), NULL); |
|
return(ROFF_IGN); |
return(ROFF_IGN); |
} |
} |
fsz = (size_t)(p - first); |
fsz = (size_t)(p - first); |
Line 1895 roff_tr(ROFF_ARGS) |
|
Line 1998 roff_tr(ROFF_ARGS) |
|
if ('\\' == *second) { |
if ('\\' == *second) { |
esc = mandoc_escape(&p, NULL, NULL); |
esc = mandoc_escape(&p, NULL, NULL); |
if (ESCAPE_ERROR == esc) { |
if (ESCAPE_ERROR == esc) { |
mandoc_msg(MANDOCERR_BADESCAPE, |
mandoc_msg(MANDOCERR_ESC_BAD, r->parse, |
r->parse, ln, |
ln, (int)(p - *bufp), second); |
(int)(p - *bufp), NULL); |
|
return(ROFF_IGN); |
return(ROFF_IGN); |
} |
} |
ssz = (size_t)(p - second); |
ssz = (size_t)(p - second); |
Line 1932 roff_so(ROFF_ARGS) |
|
Line 2034 roff_so(ROFF_ARGS) |
|
char *name; |
char *name; |
|
|
name = *bufp + pos; |
name = *bufp + pos; |
mandoc_vmsg(MANDOCERR_SO, r->parse, ln, ppos, ".so %s", name); |
mandoc_vmsg(MANDOCERR_SO, r->parse, ln, ppos, "so %s", name); |
|
|
/* |
/* |
* Handle `so'. Be EXTREMELY careful, as we shouldn't be |
* Handle `so'. Be EXTREMELY careful, as we shouldn't be |
Line 2024 roff_getname(struct roff *r, char **cpp, int ln, int p |
|
Line 2126 roff_getname(struct roff *r, char **cpp, int ln, int p |
|
cp++; |
cp++; |
if ('\\' == *cp) |
if ('\\' == *cp) |
continue; |
continue; |
mandoc_msg(MANDOCERR_NAMESC, r->parse, ln, pos, NULL); |
mandoc_vmsg(MANDOCERR_NAMESC, r->parse, ln, pos, |
|
"%.*s", (int)(cp - name + 1), name); |
mandoc_escape((const char **)&cp, NULL, NULL); |
mandoc_escape((const char **)&cp, NULL, NULL); |
break; |
break; |
} |
} |
Line 2261 roff_strdup(const struct roff *r, const char *p) |
|
Line 2364 roff_strdup(const struct roff *r, const char *p) |
|
|
|
res[(int)ssz] = '\0'; |
res[(int)ssz] = '\0'; |
return(res); |
return(res); |
|
} |
|
|
|
int |
|
roff_getformat(const struct roff *r) |
|
{ |
|
|
|
return(r->format); |
} |
} |
|
|
/* |
/* |