version 1.106, 2010/12/02 10:53:03 |
version 1.108, 2010/12/21 01:46:44 |
Line 346 roff_alloc(struct regset *regs, void *data, const mand |
|
Line 346 roff_alloc(struct regset *regs, void *data, const mand |
|
static int |
static int |
roff_res(struct roff *r, char **bufp, size_t *szp, int pos) |
roff_res(struct roff *r, char **bufp, size_t *szp, int pos) |
{ |
{ |
const char *cp, *cpp, *st, *res; |
const char *stesc; /* start of an escape sequence ('\\') */ |
|
const char *stnam; /* start of the name, after "[(*" */ |
|
const char *cp; /* end of the name, e.g. before ']' */ |
|
const char *res; /* the string to be substituted */ |
int i, maxl; |
int i, maxl; |
size_t nsz; |
size_t nsz; |
char *n; |
char *n; |
|
|
/* LINTED */ |
/* Search for a leading backslash and save a pointer to it. */ |
for (cp = &(*bufp)[pos]; (cpp = strstr(cp, "\\*")); cp++) { |
|
cp = cpp + 2; |
cp = *bufp + pos; |
|
while (NULL != (cp = strchr(cp, '\\'))) { |
|
stesc = cp++; |
|
|
|
/* |
|
* The second character must be an asterisk. |
|
* If it isn't, skip it anyway: It is escaped, |
|
* so it can't start another escape sequence. |
|
*/ |
|
|
|
if ('\0' == *cp) |
|
return(1); |
|
if ('*' != *cp++) |
|
continue; |
|
|
|
/* |
|
* The third character decides the length |
|
* of the name of the string. |
|
* Save a pointer to the name. |
|
*/ |
|
|
switch (*cp) { |
switch (*cp) { |
|
case ('\0'): |
|
return(1); |
case ('('): |
case ('('): |
cp++; |
cp++; |
maxl = 2; |
maxl = 2; |
Line 367 roff_res(struct roff *r, char **bufp, size_t *szp, int |
|
Line 392 roff_res(struct roff *r, char **bufp, size_t *szp, int |
|
maxl = 1; |
maxl = 1; |
break; |
break; |
} |
} |
|
stnam = cp; |
|
|
st = cp; |
/* Advance to the end of the name. */ |
|
|
for (i = 0; 0 == maxl || i < maxl; i++, cp++) { |
for (i = 0; 0 == maxl || i < maxl; i++, cp++) { |
if ('\0' == *cp) |
if ('\0' == *cp) |
Line 377 roff_res(struct roff *r, char **bufp, size_t *szp, int |
|
Line 403 roff_res(struct roff *r, char **bufp, size_t *szp, int |
|
break; |
break; |
} |
} |
|
|
res = roff_getstrn(r, st, (size_t)i); |
/* |
|
* Retrieve the replacement string; if it is |
|
* undefined, resume searching for escapes. |
|
*/ |
|
|
|
res = roff_getstrn(r, stnam, (size_t)i); |
|
|
if (NULL == res) { |
if (NULL == res) { |
cp -= maxl ? 1 : 0; |
cp -= maxl ? 1 : 0; |
continue; |
continue; |
} |
} |
|
|
|
/* Replace the escape sequence by the string. */ |
|
|
ROFF_DEBUG("roff: splicing reserved: [%.*s]\n", i, st); |
ROFF_DEBUG("roff: splicing reserved: [%.*s]\n", i, st); |
|
|
nsz = *szp + strlen(res) + 1; |
nsz = *szp + strlen(res) + 1; |
n = mandoc_malloc(nsz); |
n = mandoc_malloc(nsz); |
|
|
*n = '\0'; |
strlcpy(n, *bufp, (size_t)(stesc - *bufp + 1)); |
|
|
strlcat(n, *bufp, (size_t)(cpp - *bufp + 1)); |
|
strlcat(n, res, nsz); |
strlcat(n, res, nsz); |
strlcat(n, cp + (maxl ? 0 : 1), nsz); |
strlcat(n, cp + (maxl ? 0 : 1), nsz); |
|
|
Line 463 roff_parseln(struct roff *r, int ln, char **bufp, |
|
Line 494 roff_parseln(struct roff *r, int ln, char **bufp, |
|
if (ROFF_MAX == (t = roff_parse(r, *bufp, &pos))) |
if (ROFF_MAX == (t = roff_parse(r, *bufp, &pos))) |
return(ROFF_CONT); |
return(ROFF_CONT); |
|
|
ROFF_DEBUG("roff: intercept new-scope: %s, [%s]\n", |
ROFF_DEBUG("roff: intercept new-scope: [%s], [%s]\n", |
roffs[t].name, &(*bufp)[pos]); |
ROFF_USERDEF == t ? r->current_string : roffs[t].name, |
|
&(*bufp)[pos]); |
|
|
assert(roffs[t].proc); |
assert(roffs[t].proc); |
return((*roffs[t].proc) |
return((*roffs[t].proc) |
(r, t, bufp, szp, |
(r, t, bufp, szp, |
Line 561 roff_cblock(ROFF_ARGS) |
|
Line 594 roff_cblock(ROFF_ARGS) |
|
case (ROFF_am1): |
case (ROFF_am1): |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
case (ROFF_de): |
case (ROFF_de): |
|
/* ROFF_de1 is remapped to ROFF_de in roff_block(). */ |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
case (ROFF_dei): |
case (ROFF_dei): |
/* FALLTHROUGH */ |
/* FALLTHROUGH */ |
Line 650 roff_block(ROFF_ARGS) |
|
Line 684 roff_block(ROFF_ARGS) |
|
(*r->msg)(MANDOCERR_NOARGS, r->data, ln, ppos, NULL); |
(*r->msg)(MANDOCERR_NOARGS, r->data, ln, ppos, NULL); |
return(ROFF_IGN); |
return(ROFF_IGN); |
} |
} |
|
|
|
/* |
|
* Re-write `de1', since we don't really care about |
|
* groff's strange compatibility mode, into `de'. |
|
*/ |
|
|
if (ROFF_de1 == tok) |
if (ROFF_de1 == tok) |
tok = ROFF_de; |
tok = ROFF_de; |
if (ROFF_de == tok) |
if (ROFF_de == tok) |
Line 657 roff_block(ROFF_ARGS) |
|
Line 697 roff_block(ROFF_ARGS) |
|
else |
else |
(*r->msg)(MANDOCERR_REQUEST, r->data, ln, ppos, |
(*r->msg)(MANDOCERR_REQUEST, r->data, ln, ppos, |
roffs[tok].name); |
roffs[tok].name); |
|
|
while ((*bufp)[pos] && ' ' != (*bufp)[pos]) |
while ((*bufp)[pos] && ' ' != (*bufp)[pos]) |
pos++; |
pos++; |
|
|
while (' ' == (*bufp)[pos]) |
while (' ' == (*bufp)[pos]) |
(*bufp)[pos++] = '\0'; |
(*bufp)[pos++] = '\0'; |
} |
} |
Line 670 roff_block(ROFF_ARGS) |
|
Line 712 roff_block(ROFF_ARGS) |
|
* with the same name, if there is one. New content will be |
* with the same name, if there is one. New content will be |
* added from roff_block_text() in multiline mode. |
* added from roff_block_text() in multiline mode. |
*/ |
*/ |
|
|
if (ROFF_de == tok) |
if (ROFF_de == tok) |
roff_setstr(r, name, "", 0); |
roff_setstr(r, name, "", 0); |
|
|
if ('\0' == (*bufp)[pos]) |
if ('\0' == (*bufp)[pos]) |
return(ROFF_IGN); |
return(ROFF_IGN); |
|
|
|
/* If present, process the custom end-of-line marker. */ |
|
|
sv = pos; |
sv = pos; |
while ((*bufp)[pos] && ' ' != (*bufp)[pos] && |
while ((*bufp)[pos] && |
|
' ' != (*bufp)[pos] && |
'\t' != (*bufp)[pos]) |
'\t' != (*bufp)[pos]) |
pos++; |
pos++; |
|
|
Line 699 roff_block(ROFF_ARGS) |
|
Line 745 roff_block(ROFF_ARGS) |
|
r->last->end[(int)sz] = '\0'; |
r->last->end[(int)sz] = '\0'; |
|
|
if ((*bufp)[pos]) |
if ((*bufp)[pos]) |
if ( ! (*r->msg)(MANDOCERR_ARGSLOST, r->data, ln, pos, NULL)) |
(*r->msg)(MANDOCERR_ARGSLOST, r->data, ln, pos, NULL); |
return(ROFF_ERR); |
|
|
|
return(ROFF_IGN); |
return(ROFF_IGN); |
} |
} |
Line 933 roff_cond(ROFF_ARGS) |
|
Line 978 roff_cond(ROFF_ARGS) |
|
*/ |
*/ |
|
|
if ('\0' == (*bufp)[pos] && sv != pos) { |
if ('\0' == (*bufp)[pos] && sv != pos) { |
if ((*r->msg)(MANDOCERR_NOARGS, r->data, ln, ppos, NULL)) |
(*r->msg)(MANDOCERR_NOARGS, r->data, ln, ppos, NULL); |
return(ROFF_IGN); |
return(ROFF_IGN); |
return(ROFF_ERR); |
|
} |
} |
|
|
roffnode_push(r, tok, NULL, ln, ppos); |
roffnode_push(r, tok, NULL, ln, ppos); |