=================================================================== RCS file: /cvs/mandoc/man.c,v retrieving revision 1.141 retrieving revision 1.143 diff -u -p -r1.141 -r1.143 --- mandoc/man.c 2014/10/20 15:50:24 1.141 +++ mandoc/man.c 2014/11/19 03:08:17 1.143 @@ -1,4 +1,4 @@ -/* $Id: man.c,v 1.141 2014/10/20 15:50:24 schwarze Exp $ */ +/* $Id: man.c,v 1.143 2014/11/19 03:08:17 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2013, 2014 Ingo Schwarze @@ -315,6 +315,21 @@ man_word_alloc(struct man *man, int line, int pos, con return(1); } +void +man_word_append(struct man *man, const char *word) +{ + struct man_node *n; + char *addstr, *newstr; + + n = man->last; + addstr = roff_strdup(man->roff, word); + mandoc_asprintf(&newstr, "%s %s", n->string, addstr); + free(addstr); + free(n->string); + n->string = newstr; + man->next = MAN_NEXT_SIBLING; +} + /* * Free all of the resources held by a node. This does NOT unlink a * node from its context; for that, see man_node_unlink(). @@ -468,35 +483,50 @@ man_ptext(struct man *man, int line, char *buf, int of static int man_pmacro(struct man *man, int ln, char *buf, int offs) { - char mac[5]; struct man_node *n; + const char *cp; enum mant tok; int i, ppos; int bline; + char mac[5]; ppos = offs; /* * Copy the first word into a nil-terminated buffer. - * Stop copying when a tab, space, or eoln is encountered. + * Stop when a space, tab, escape, or eoln is encountered. */ i = 0; - while (i < 4 && '\0' != buf[offs] && ' ' != buf[offs] && - '\t' != buf[offs]) + while (i < 4 && strchr(" \t\\", buf[offs]) == NULL) mac[i++] = buf[offs++]; mac[i] = '\0'; tok = (i > 0 && i < 4) ? man_hash_find(mac) : MAN_MAX; - if (MAN_MAX == tok) { + if (tok == MAN_MAX) { mandoc_msg(MANDOCERR_MACRO, man->parse, ln, ppos, buf + ppos - 1); return(1); } - /* The macro is sane. Jump to the next word. */ + /* Skip a leading escape sequence or tab. */ + + switch (buf[offs]) { + case '\\': + cp = buf + offs + 1; + mandoc_escape(&cp, NULL, NULL); + offs = cp - buf; + break; + case '\t': + offs++; + break; + default: + break; + } + + /* Jump to the next non-whitespace word. */ while (buf[offs] && ' ' == buf[offs]) offs++;