=================================================================== RCS file: /cvs/mandoc/roff.c,v retrieving revision 1.142 retrieving revision 1.145 diff -u -p -r1.142 -r1.145 --- mandoc/roff.c 2011/05/26 11:58:25 1.142 +++ mandoc/roff.c 2011/07/12 21:32:43 1.145 @@ -1,4 +1,4 @@ -/* $Id: roff.c,v 1.142 2011/05/26 11:58:25 kristaps Exp $ */ +/* $Id: roff.c,v 1.145 2011/07/12 21:32:43 kristaps Exp $ */ /* * Copyright (c) 2010, 2011 Kristaps Dzonsons * Copyright (c) 2010, 2011 Ingo Schwarze @@ -347,8 +347,12 @@ roff_free1(struct roff *r) void roff_reset(struct roff *r) { + int i; roff_free1(r); + + for (i = 0; i < PREDEFS_MAX; i++) + roff_setstr(r, predefs[i].name, predefs[i].str, 0); } @@ -592,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); @@ -878,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; @@ -1153,7 +1179,7 @@ roff_EQ(ROFF_ARGS) struct eqn_node *e; assert(NULL == r->eqn); - e = eqn_alloc(ppos, ln); + e = eqn_alloc(ppos, ln, r->parse); if (r->last_eqn) r->last_eqn->next = e;