From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from localhost (fantadrom.bsd.lv [local]) by fantadrom.bsd.lv (OpenSMTPD) with ESMTPA id 41d237b5 for ; Sat, 25 Aug 2018 07:33:06 -0500 (EST) Date: Sat, 25 Aug 2018 07:33:06 -0500 (EST) X-Mailinglist: mandoc-source Reply-To: source@mandoc.bsd.lv MIME-Version: 1.0 From: schwarze@mandoc.bsd.lv To: source@mandoc.bsd.lv Subject: mandoc: If man(7) next-line scope is open and the line ends with \c, the X-Mailer: activitymail 1.26, http://search.cpan.org/dist/activitymail/ Content-Type: text/plain; charset=utf-8 Message-Id: Log Message: ----------- If man(7) next-line scope is open and the line ends with \c, the scope remains open. Needed for example for groff_man(7). Modified Files: -------------- mandoc: man.c mandoc/regress/roff/esc: c_man.in c_man.out_ascii Revision Data ------------- Index: man.c =================================================================== RCS file: /home/cvs/mandoc/mandoc/man.c,v retrieving revision 1.178 retrieving revision 1.179 diff -Lman.c -Lman.c -u -p -r1.178 -r1.179 --- man.c +++ man.c @@ -35,7 +35,8 @@ #include "roff_int.h" #include "libman.h" -static void man_descope(struct roff_man *, int, int); +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); @@ -52,9 +53,32 @@ man_parseln(struct roff_man *man, int ln 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) +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 @@ -76,14 +100,13 @@ static int 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); + man_descope(man, line, offs, buf + offs); return 1; } @@ -104,20 +127,10 @@ man_ptext(struct roff_man *man, int line } 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; + if (man->last->type == ROFFT_TEXT && + ((ep = man_hasc(man->last->string)) != NULL)) { *ep = '\0'; return 1; - default: - break; } roff_elem_alloc(man, line, offs, ROFF_sp); man->next = ROFF_NEXT_SIBLING; @@ -157,7 +170,7 @@ man_ptext(struct roff_man *man, int line if (mandoc_eos(buf, (size_t)i)) man->last->flags |= NODE_EOS; - man_descope(man, line, offs); + man_descope(man, line, offs, buf + offs); return 1; } Index: c_man.out_ascii =================================================================== RCS file: /home/cvs/mandoc/mandoc/regress/roff/esc/c_man.out_ascii,v retrieving revision 1.2 retrieving revision 1.3 diff -Lregress/roff/esc/c_man.out_ascii -Lregress/roff/esc/c_man.out_ascii -u -p -r1.2 -r1.3 --- regress/roff/esc/c_man.out_ascii +++ regress/roff/esc/c_man.out_ascii @@ -7,12 +7,23 @@ NNAAMMEE DDEESSCCRRIIPPTTIIOONN No space between "one" and "word": oneword + + The same in no-fill mode: oneword + Blank line after \c: one word one word + + In next-line element scope: oonneewwoorrdd + + In next-line block scope: + + oneword + list body + final text -OpenBSD December 2, 2014 ESC-C_MAN(1) +OpenBSD August 25, 2018 ESC-C_MAN(1) Index: c_man.in =================================================================== RCS file: /home/cvs/mandoc/mandoc/regress/roff/esc/c_man.in,v retrieving revision 1.3 retrieving revision 1.4 diff -Lregress/roff/esc/c_man.in -Lregress/roff/esc/c_man.in -u -p -r1.3 -r1.4 --- regress/roff/esc/c_man.in +++ regress/roff/esc/c_man.in @@ -1,15 +1,18 @@ -.\" $OpenBSD: c_man.in,v 1.3 2017/07/04 14:53:27 schwarze Exp $ -.TH ESC-C_MAN 1 "December 2, 2014" +.\" $OpenBSD: c_man.in,v 1.4 2018/08/25 12:28:52 schwarze Exp $ +.TH ESC-C_MAN 1 "August 25, 2018" .SH NAME esc-c_man \- the roff escape c sequence: remove trailing space .SH DESCRIPTION No space between "one" and "word": one\c word +.PP +The same in no-fill mode: .nf one\c word .fi +.PP Blank line after \ec: one\c @@ -19,4 +22,16 @@ one\c word .fi +.PP +In next-line element scope: +.B +one\c +word +.PP +In next-line block scope: +.TP +one\c +word +list body +.PP final text -- To unsubscribe send an email to source+unsubscribe@mandoc.bsd.lv