diff options
author | Kristaps Dzonsons <kristaps@bsd.lv> | 2011-07-08 09:28:33 +0000 |
---|---|---|
committer | Kristaps Dzonsons <kristaps@bsd.lv> | 2011-07-08 09:28:33 +0000 |
commit | 0503d4ab5439538f2ea58eb07dfb2d741db3c1a2 (patch) | |
tree | 950bedd8de59a239270c5ea09257257685e65cf5 /roff.c | |
parent | 205237feaaf479c37cd4bc509f72d3021dbd69a5 (diff) | |
download | mandoc-0503d4ab5439538f2ea58eb07dfb2d741db3c1a2.tar.gz |
Fix two issues: the first, where a `.\}' wasn't being interpreted as a
proper macro in some conditions, resulting in strange parse errors. The
second, where `\}' was being re-written as `\&'. Instead, we re-write
this as two spaces OR nothing at all, if at the end of line. This isn't
exactly what groff does (who knows...) but is a much safer and better
way than how I was doing it before.
Diffstat (limited to 'roff.c')
-rw-r--r-- | roff.c | 28 |
1 files changed, 25 insertions, 3 deletions
@@ -596,11 +596,18 @@ roff_parse(struct roff *r, const char *buf, int *pos) size_t maclen; enum rofft t; - if ('\0' == buf[*pos] || '"' == buf[*pos]) + if ('\0' == buf[*pos] || '"' == buf[*pos] || + '\t' == buf[*pos] || ' ' == buf[*pos]) return(ROFF_MAX); + /* + * We stop the macro parse at an escape, tab, space, or nil. + * However, `\}' is also a valid macro, so make sure we don't + * clobber it by seeing the `\' as the end of token. + */ + mac = buf + *pos; - maclen = strcspn(mac, " \\\t\0"); + maclen = strcspn(mac + 1, " \\\t\0") + 1; t = (r->current_string = roff_getstrn(r, mac, maclen)) ? ROFF_USERDEF : roff_hash_find(mac, maclen); @@ -882,7 +889,22 @@ roff_cond_sub(ROFF_ARGS) ep++; if ('}' != *ep) continue; - *ep = '&'; + + /* + * Make the \} go away. + * This is a little haphazard, as it's not quite + * clear how nroff does this. + * If we're at the end of line, then just chop + * off the \} and resize the buffer. + * If we aren't, then conver it to spaces. + */ + + if ('\0' == *(ep + 1)) { + *--ep = '\0'; + *szp -= 2; + } else + *(ep - 1) = *ep = ' '; + roff_ccond(r, ROFF_ccond, bufp, szp, ln, pos, pos + 2, offs); break; |