version 1.214, 2014/06/29 23:26:00 |
version 1.220, 2014/07/07 11:35:06 |
Line 500 roff_res(struct roff *r, char **bufp, size_t *szp, int |
|
Line 500 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 542 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 586 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 607 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 838 roff_cblock(ROFF_ARGS) |
|
Line 847 roff_cblock(ROFF_ARGS) |
|
|
|
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 856 roff_cblock(ROFF_ARGS) |
|
Line 864 roff_cblock(ROFF_ARGS) |
|
} |
} |
|
|
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 909 roff_ccond(struct roff *r, int ln, int ppos) |
|
Line 918 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 968 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 1046 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 1060 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 1285 roff_cond(ROFF_ARGS) |
|
Line 1319 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 1883 roff_tr(ROFF_ARGS) |
|
Line 1918 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 1929 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 2018 roff_getname(struct roff *r, char **cpp, int ln, int p |
|
Line 2051 roff_getname(struct roff *r, char **cpp, int ln, int p |
|
} |
} |
if ('\\' != *cp) |
if ('\\' != *cp) |
continue; |
continue; |
|
namesz = cp - name; |
|
if ('{' == cp[1] || '}' == cp[1]) |
|
break; |
cp++; |
cp++; |
if ('\\' == *cp) |
if ('\\' == *cp) |
continue; |
continue; |
namesz = cp - name - 1; |
|
mandoc_msg(MANDOCERR_NAMESC, r->parse, ln, pos, NULL); |
mandoc_msg(MANDOCERR_NAMESC, r->parse, ln, pos, NULL); |
mandoc_escape((const char **)&cp, NULL, NULL); |
mandoc_escape((const char **)&cp, NULL, NULL); |
break; |
break; |