summaryrefslogtreecommitdiffstats
path: root/roff.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2014-10-28 17:36:19 +0000
committerIngo Schwarze <schwarze@openbsd.org>2014-10-28 17:36:19 +0000
commite140259c6ca1889b0dddef8b075524723b147cfe (patch)
tree351a20004d594caa3735ca29afb581ace2b8ea76 /roff.c
parent9a3f7e6d544fc2f5c114c480cb724e44cfac1ea9 (diff)
downloadmandoc-e140259c6ca1889b0dddef8b075524723b147cfe.tar.gz
Make the character table available to libroff so it can check the
validity of character escape names and warn about unknown ones. This requires mchars_spec2cp() to report unknown names again. Fortunately, that doesn't require changing the calling code because according to groff, invalid character escapes should not produce output anyway, and now that we warn about them, that's fine.
Diffstat (limited to 'roff.c')
-rw-r--r--roff.c11
1 files changed, 9 insertions, 2 deletions
diff --git a/roff.c b/roff.c
index ecf7dc68..238f84e4 100644
--- a/roff.c
+++ b/roff.c
@@ -107,6 +107,7 @@ struct roffreg {
struct roff {
struct mparse *parse; /* parse point */
+ const struct mchars *mchars; /* character table */
struct roffnode *last; /* leaf of stack */
int *rstack; /* stack of inverted `ie' values */
struct roffreg *regtab; /* number registers */
@@ -476,12 +477,13 @@ roff_free(struct roff *r)
}
struct roff *
-roff_alloc(struct mparse *parse, int options)
+roff_alloc(struct mparse *parse, const struct mchars *mchars, int options)
{
struct roff *r;
r = mandoc_calloc(1, sizeof(struct roff));
r->parse = parse;
+ r->mchars = mchars;
r->options = options;
r->format = options & (MPARSE_MDOC | MPARSE_MAN);
r->rstackpos = -1;
@@ -508,6 +510,8 @@ roff_res(struct roff *r, char **bufp, size_t *szp, int ln, int pos)
char *nbuf; /* new buffer to copy bufp to */
size_t maxl; /* expected length of the escape name */
size_t naml; /* actual length of the escape name */
+ enum mandoc_esc esc; /* type of the escape sequence */
+ int inaml; /* length returned from mandoc_escape() */
int expand_count; /* to avoid infinite loops */
int npos; /* position in numeric expression */
int arg_complete; /* argument not interrupted by eol */
@@ -551,7 +555,10 @@ roff_res(struct roff *r, char **bufp, size_t *szp, int ln, int pos)
res = ubuf;
break;
default:
- if (ESCAPE_ERROR == mandoc_escape(&cp, NULL, NULL))
+ esc = mandoc_escape(&cp, &stnam, &inaml);
+ if (esc == ESCAPE_ERROR ||
+ (esc == ESCAPE_SPECIAL &&
+ mchars_spec2cp(r->mchars, stnam, inaml) < 0))
mandoc_vmsg(MANDOCERR_ESC_BAD,
r->parse, ln, (int)(stesc - *bufp),
"%.*s", (int)(cp - stesc), stesc);