summaryrefslogtreecommitdiff
path: root/usr.bin
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@cvs.openbsd.org>2017-04-17 13:26:31 +0000
committerIngo Schwarze <schwarze@cvs.openbsd.org>2017-04-17 13:26:31 +0000
commite02667a1b11e0c760d0be44433afa5a0efb40922 (patch)
tree9ad7c95731c9414fb2b8da2301e73c87b688fa6e /usr.bin
parentce74b70fa6a67050cda0b1da46c78c2217e62b0e (diff)
implement display of long .Lk URIs to match -Tascii
Diffstat (limited to 'usr.bin')
-rw-r--r--usr.bin/mandoc/mdoc_man.c63
1 files changed, 58 insertions, 5 deletions
diff --git a/usr.bin/mandoc/mdoc_man.c b/usr.bin/mandoc/mdoc_man.c
index 0c3e097269d..cf67f199150 100644
--- a/usr.bin/mandoc/mdoc_man.c
+++ b/usr.bin/mandoc/mdoc_man.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mdoc_man.c,v 1.105 2017/04/17 12:52:00 schwarze Exp $ */
+/* $OpenBSD: mdoc_man.c,v 1.106 2017/04/17 13:26:30 schwarze Exp $ */
/*
* Copyright (c) 2011-2017 Ingo Schwarze <schwarze@openbsd.org>
*
@@ -42,6 +42,7 @@ static int cond_body(DECL_ARGS);
static int cond_head(DECL_ARGS);
static void font_push(char);
static void font_pop(void);
+static int man_strlen(const char *);
static void mid_it(void);
static void post__t(DECL_ARGS);
static void post_aq(DECL_ARGS);
@@ -272,6 +273,49 @@ static struct {
} fontqueue;
+static int
+man_strlen(const char *cp)
+{
+ size_t rsz;
+ int skip, sz;
+
+ sz = 0;
+ skip = 0;
+ for (;;) {
+ rsz = strcspn(cp, "\\");
+ if (rsz) {
+ cp += rsz;
+ if (skip) {
+ skip = 0;
+ rsz--;
+ }
+ sz += rsz;
+ }
+ if ('\0' == *cp)
+ break;
+ cp++;
+ switch (mandoc_escape(&cp, NULL, NULL)) {
+ case ESCAPE_ERROR:
+ return sz;
+ case ESCAPE_UNICODE:
+ case ESCAPE_NUMBERED:
+ case ESCAPE_SPECIAL:
+ case ESCAPE_OVERSTRIKE:
+ if (skip)
+ skip = 0;
+ else
+ sz++;
+ break;
+ case ESCAPE_SKIPCHAR:
+ skip = 1;
+ break;
+ default:
+ break;
+ }
+ }
+ return sz;
+}
+
static void
font_push(char newfont)
{
@@ -445,7 +489,7 @@ print_offs(const char *v, int keywords)
return;
}
} else
- sz = strlen(v);
+ sz = man_strlen(v);
/*
* We are inside an enclosing list.
@@ -483,13 +527,13 @@ print_width(const struct mdoc_bl *bl, const struct roff_node *child)
numeric = 0;
}
} else
- sz = strlen(bl->width);
+ sz = man_strlen(bl->width);
/* XXX Rough estimation, might have multiple parts. */
if (bl->type == LIST_enum)
chsz = (bl->count > 8) + 1;
else if (child != NULL && child->type == ROFFT_TEXT)
- chsz = strlen(child->string);
+ chsz = man_strlen(child->string);
else
chsz = 0;
@@ -1462,6 +1506,7 @@ static int
pre_lk(DECL_ARGS)
{
const struct roff_node *link, *descr;
+ int display;
if ((link = n->child) == NULL)
return 0;
@@ -1478,6 +1523,12 @@ pre_lk(DECL_ARGS)
}
/* Link target. */
+ display = man_strlen(link->string) >= 26;
+ if (display) {
+ print_line(".RS", MMAN_Bk_susp);
+ print_word("6n");
+ outflags |= MMAN_nl;
+ }
font_push('B');
print_word(link->string);
font_pop();
@@ -1487,6 +1538,8 @@ pre_lk(DECL_ARGS)
print_word(descr->string);
descr = descr->next;
}
+ if (display)
+ print_line(".RE", MMAN_nl);
return 0;
}
@@ -1524,7 +1577,7 @@ pre_nm(DECL_ARGS)
if (NULL == n->parent->prev)
outflags |= MMAN_sp;
print_block(".HP", 0);
- printf(" %zun", strlen(name) + 1);
+ printf(" %dn", man_strlen(name) + 1);
outflags |= MMAN_nl;
}
font_push('B');