=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/mandoc/man.c,v retrieving revision 1.126 retrieving revision 1.127 diff -c -r1.126 -r1.127 *** src/usr.bin/mandoc/man.c 2018/08/23 19:32:03 1.126 --- src/usr.bin/mandoc/man.c 2018/08/25 12:28:52 1.127 *************** *** 1,4 **** ! /* $OpenBSD: man.c,v 1.126 2018/08/23 19:32:03 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2013,2014,2015,2017,2018 Ingo Schwarze --- 1,4 ---- ! /* $OpenBSD: man.c,v 1.127 2018/08/25 12:28:52 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2013,2014,2015,2017,2018 Ingo Schwarze *************** *** 33,39 **** #include "roff_int.h" #include "libman.h" ! static void man_descope(struct roff_man *, int, int); static int man_ptext(struct roff_man *, int, char *, int); static int man_pmacro(struct roff_man *, int, char *, int); --- 33,40 ---- #include "roff_int.h" #include "libman.h" ! static void man_descope(struct roff_man *, int, int, char *); ! static char *man_hasc(char *); static int man_ptext(struct roff_man *, int, char *, int); static int man_pmacro(struct roff_man *, int, char *, int); *************** *** 50,58 **** man_ptext(man, ln, buf, offs); } static void ! man_descope(struct roff_man *man, int line, int offs) { /* * Co-ordinate what happens with having a next-line scope open: * first close out the element scope (if applicable), then close --- 51,82 ---- man_ptext(man, ln, buf, offs); } + /* + * If the string ends with \c, return a pointer to the backslash. + * Otherwise, return NULL. + */ + static char * + man_hasc(char *start) + { + char *cp, *ep; + + ep = strchr(start, '\0') - 2; + if (ep < start || ep[0] != '\\' || ep[1] != 'c') + return NULL; + for (cp = ep; cp > start; cp--) + if (cp[-1] != '\\') + break; + return (ep - cp) % 2 ? NULL : ep; + } + static void ! man_descope(struct roff_man *man, int line, int offs, char *start) { + /* Trailing \c keeps next-line scope open. */ + + if (man_hasc(start) != NULL) + return; + /* * Co-ordinate what happens with having a next-line scope open: * first close out the element scope (if applicable), then close *************** *** 74,87 **** man_ptext(struct roff_man *man, int line, char *buf, int offs) { int i; - const char *cp, *sp; char *ep; /* Literal free-form text whitespace is preserved. */ if (man->flags & MAN_LITERAL) { roff_word_alloc(man, line, offs, buf + offs); ! man_descope(man, line, offs); return 1; } --- 98,110 ---- man_ptext(struct roff_man *man, int line, char *buf, int offs) { int i; char *ep; /* Literal free-form text whitespace is preserved. */ if (man->flags & MAN_LITERAL) { roff_word_alloc(man, line, offs, buf + offs); ! man_descope(man, line, offs, buf + offs); return 1; } *************** *** 102,121 **** } if (man->last->tok == MAN_SH || man->last->tok == MAN_SS) return 1; ! switch (man->last->type) { ! case ROFFT_TEXT: ! sp = man->last->string; ! cp = ep = strchr(sp, '\0') - 2; ! if (cp < sp || cp[0] != '\\' || cp[1] != 'c') ! break; ! while (cp > sp && cp[-1] == '\\') ! cp--; ! if ((ep - cp) % 2) ! break; *ep = '\0'; return 1; - default: - break; } roff_elem_alloc(man, line, offs, ROFF_sp); man->next = ROFF_NEXT_SIBLING; --- 125,134 ---- } if (man->last->tok == MAN_SH || man->last->tok == MAN_SS) return 1; ! if (man->last->type == ROFFT_TEXT && ! ((ep = man_hasc(man->last->string)) != NULL)) { *ep = '\0'; return 1; } roff_elem_alloc(man, line, offs, ROFF_sp); man->next = ROFF_NEXT_SIBLING; *************** *** 155,161 **** if (mandoc_eos(buf, (size_t)i)) man->last->flags |= NODE_EOS; ! man_descope(man, line, offs); return 1; } --- 168,174 ---- if (mandoc_eos(buf, (size_t)i)) man->last->flags |= NODE_EOS; ! man_descope(man, line, offs, buf + offs); return 1; }