Partial implementation of \h (horizontal line drawing function).
authorschwarze <schwarze@openbsd.org>
Fri, 2 Jun 2017 19:21:03 +0000 (19:21 +0000)
committerschwarze <schwarze@openbsd.org>
Fri, 2 Jun 2017 19:21:03 +0000 (19:21 +0000)
A full implementation would require access to output device properties
and state variables (both only available after the main parser has
finalized the parse tree) before numerical expansions in the roff
preprocessor (i.e., before the main parser is even started).

Not trying to pull that stunt right now because the static-width
implementation committed here is sufficient for tcl-style manual pages
and already more complicated than i would have suspected.

share/man/man7/roff.7
usr.bin/mandoc/mandoc.c
usr.bin/mandoc/mandoc.h
usr.bin/mandoc/term.c

index 352da64..c3e710d 100644 (file)
@@ -1,4 +1,4 @@
-.\"    $OpenBSD: roff.7,v 1.61 2017/06/01 19:05:15 schwarze Exp $
+.\"    $OpenBSD: roff.7,v 1.62 2017/06/02 19:21:03 schwarze Exp $
 .\"
 .\" Copyright (c) 2010, 2011, 2012 Kristaps Dzonsons <kristaps@bsd.lv>
 .\" Copyright (c) 2010,2011,2013-2015,2017 Ingo Schwarze <schwarze@openbsd.org>
@@ -15,7 +15,7 @@
 .\" ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 .\" OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 .\"
-.Dd $Mdocdate: June 1 2017 $
+.Dd $Mdocdate: June 2 2017 $
 .Dt ROFF 7
 .Os
 .Sh NAME
@@ -1937,9 +1937,11 @@ and
 .Ss \eL\(aq Ns Ar number Ns Oo Ar c Oc Ns \(aq
 Vertical line drawing function; ignored by
 .Xr mandoc 1 .
-.Ss \el\(aq Ns Ar number Ns Oo Ar c Oc Ns \(aq
-Horizontal line drawing function; ignored by
-.Xr mandoc 1 .
+.Ss \el\(aq Ns Ar width Ns Oo Ar c Oc Ns \(aq
+Draw a horizontal line of
+.Ar width
+using the glyph
+.Ar c .
 .Ss \eM[ Ns Ar name ]
 Set fill (background) color (groff extension); ignored by
 .Xr mandoc 1 .
index 012d6bd..f667c59 100644 (file)
@@ -1,7 +1,7 @@
-/*     $OpenBSD: mandoc.c,v 1.67 2017/06/01 19:05:15 schwarze Exp $ */
+/*     $OpenBSD: mandoc.c,v 1.68 2017/06/02 19:21:03 schwarze Exp $ */
 /*
  * Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2011-2015 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2011-2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
  *
  * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
@@ -173,7 +173,17 @@ mandoc_escape(const char **end, const char **start, int *sz)
                                ++*end;
                        return ESCAPE_ERROR;
                }
-               gly = (*start)[-1] == 'h' ? ESCAPE_HORIZ : ESCAPE_IGNORE;
+               switch ((*start)[-1]) {
+               case 'h':
+                       gly = ESCAPE_HORIZ;
+                       break;
+               case 'l':
+                       gly = ESCAPE_HLINE;
+                       break;
+               default:
+                       gly = ESCAPE_IGNORE;
+                       break;
+               }
                term = **start;
                *start = ++*end;
                break;
index 7a682b1..83e49f0 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: mandoc.h,v 1.162 2017/06/01 19:05:15 schwarze Exp $ */
+/*     $OpenBSD: mandoc.h,v 1.163 2017/06/02 19:21:03 schwarze Exp $ */
 /*
  * Copyright (c) 2010, 2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
  * Copyright (c) 2010-2017 Ingo Schwarze <schwarze@openbsd.org>
@@ -412,6 +412,7 @@ enum        mandoc_esc {
        ESCAPE_UNICODE, /* a unicode codepoint */
        ESCAPE_NOSPACE, /* suppress space if the last on a line */
        ESCAPE_HORIZ, /* horizontal movement */
+       ESCAPE_HLINE, /* horizontal line drawing */
        ESCAPE_SKIPCHAR, /* skip the next character */
        ESCAPE_OVERSTRIKE /* overstrike all chars in the argument */
 };
index adc1754..107243c 100644 (file)
@@ -1,4 +1,4 @@
-/*     $OpenBSD: term.c,v 1.121 2017/06/01 19:05:15 schwarze Exp $ */
+/*     $OpenBSD: term.c,v 1.122 2017/06/02 19:21:03 schwarze Exp $ */
 /*
  * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
  * Copyright (c) 2010-2017 Ingo Schwarze <schwarze@openbsd.org>
@@ -402,7 +402,7 @@ term_word(struct termp *p, const char *word)
        const char       nbrsp[2] = { ASCII_NBRSP, 0 };
        const char      *seq, *cp;
        int              sz, uc;
-       size_t           ssz;
+       size_t           csz, lsz, ssz;
        enum mandoc_esc  esc;
 
        if ( ! (TERMP_NOSPACE & p->flags)) {
@@ -508,6 +508,62 @@ term_word(struct termp *p, const char *word)
                                }
                        }
                        continue;
+               case ESCAPE_HLINE:
+                       if (a2roffsu(seq, &su, SCALE_EM) == 0)
+                               continue;
+                       uc = term_hspan(p, &su) / 24;
+                       if (uc <= 0) {
+                               if (p->rmargin <= p->offset)
+                                       continue;
+                               lsz = p->rmargin - p->offset;
+                       } else
+                               lsz = uc;
+                       while (sz &&
+                           strchr(" %&()*+-./0123456789:<=>", *seq)) {
+                               seq++;
+                               sz--;
+                       }
+                       if (sz && strchr("cifMmnPpuv", *seq)) {
+                               seq++;
+                               sz--;
+                       }
+                       if (sz == 0)
+                               uc = -1;
+                       else if (*seq == '\\') {
+                               seq++;
+                               esc = mandoc_escape(&seq, &cp, &sz);
+                               switch (esc) {
+                               case ESCAPE_UNICODE:
+                                       uc = mchars_num2uc(cp + 1, sz - 1);
+                                       break;
+                               case ESCAPE_NUMBERED:
+                                       uc = mchars_num2char(cp, sz);
+                                       break;
+                               case ESCAPE_SPECIAL:
+                                       uc = mchars_spec2cp(cp, sz);
+                                       break;
+                               default:
+                                       uc = -1;
+                                       break;
+                               }
+                       } else
+                               uc = *seq;
+                       if (uc < 0x20 || (uc > 0x7E && uc < 0xA0))
+                               uc = '_';
+                       if (p->enc == TERMENC_ASCII) {
+                               cp = ascii_uc2str(uc);
+                               csz = term_strlen(p, cp);
+                               ssz = strlen(cp);
+                       } else
+                               csz = (*p->width)(p, uc);
+                       while (lsz >= csz) {
+                               if (p->enc == TERMENC_ASCII)
+                                       encode(p, cp, ssz);
+                               else
+                                       encode1(p, uc);
+                               lsz -= csz;
+                       }
+                       continue;
                case ESCAPE_SKIPCHAR:
                        p->flags |= TERMP_BACKAFTER;
                        continue;