summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2014-01-22 20:58:39 +0000
committerIngo Schwarze <schwarze@openbsd.org>2014-01-22 20:58:39 +0000
commit654e28baaa103a868af40d8ce155ddd09fe76f98 (patch)
tree061e60883aded25bdcf06071df7bf3b4e00c8548
parent3d40007c4e92346d3e69337fa770e26de69c6ffe (diff)
downloadmandoc-654e28baaa103a868af40d8ce155ddd09fe76f98.tar.gz
Implement the \: (optional line break) escape sequence,
documented in the Ossanna-Kernighan-Ritter troff manual and also supported by groff. Missing feature reported by Steffen Nurpmeso <sdaoden at gmail dot com>.
-rw-r--r--chars.c2
-rw-r--r--chars.in18
-rw-r--r--html.c10
-rw-r--r--mandoc.h1
-rw-r--r--mandocdb.c19
-rw-r--r--mdoc_man.c5
-rw-r--r--term.c12
7 files changed, 48 insertions, 19 deletions
diff --git a/chars.c b/chars.c
index ad3ffd40..6370b219 100644
--- a/chars.c
+++ b/chars.c
@@ -37,7 +37,7 @@ struct ln {
int unicode;
};
-#define LINES_MAX 329
+#define LINES_MAX 330
#define CHAR(in, ch, code) \
{ NULL, (in), (ch), (code) },
diff --git a/chars.in b/chars.in
index 28a37eaa..5b2ba028 100644
--- a/chars.in
+++ b/chars.in
@@ -1,6 +1,7 @@
/* $Id$ */
/*
* Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
+ * Copyright (c) 2014 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
@@ -27,22 +28,25 @@
* XXX - update LINES_MAX if adding more!
*/
-/* Non-breaking, non-collapsing space uses unit separator. */
+/* Special break control characters. */
static const char ascii_nbrsp[2] = { ASCII_NBRSP, '\0' };
+static const char ascii_break[2] = { ASCII_BREAK, '\0' };
CHAR_TBL_START
/* Spacing. */
-CHAR("c", "", 0)
-CHAR("0", " ", 8194)
CHAR(" ", ascii_nbrsp, 160)
CHAR("~", ascii_nbrsp, 160)
-CHAR("%", "", 0)
-CHAR("&", "", 0)
-CHAR("^", "", 0)
+CHAR("0", " ", 8194)
CHAR("|", "", 0)
-CHAR("}", "", 0)
+CHAR("^", "", 0)
+CHAR("&", "", 0)
+CHAR("%", "", 0)
+CHAR(":", ascii_break, 0)
+/* XXX The following three do not really belong into this file. */
CHAR("t", "", 0)
+CHAR("c", "", 0)
+CHAR("}", "", 0)
/* Accents. */
CHAR("a\"", "\"", 779)
diff --git a/html.c b/html.c
index b61e60ac..17976fd4 100644
--- a/html.c
+++ b/html.c
@@ -1,7 +1,7 @@
/* $Id$ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2011, 2012, 2013 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2011, 2012, 2013, 2014 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
@@ -331,7 +331,8 @@ print_encode(struct html *h, const char *p, int norecurse)
int c, len, nospace;
const char *seq;
enum mandoc_esc esc;
- static const char rejs[6] = { '\\', '<', '>', '&', ASCII_HYPH, '\0' };
+ static const char rejs[8] = { '\\', '<', '>', '&',
+ ASCII_NBRSP, ASCII_HYPH, ASCII_BREAK, '\0' };
nospace = 0;
@@ -360,8 +361,13 @@ print_encode(struct html *h, const char *p, int norecurse)
case ('&'):
printf("&amp;");
continue;
+ case (ASCII_NBRSP):
+ putchar('-');
+ continue;
case (ASCII_HYPH):
putchar('-');
+ /* FALLTHROUGH */
+ case (ASCII_BREAK):
continue;
default:
break;
diff --git a/mandoc.h b/mandoc.h
index ab6da9a4..1827ce6d 100644
--- a/mandoc.h
+++ b/mandoc.h
@@ -20,6 +20,7 @@
#define ASCII_NBRSP 31 /* non-breaking space */
#define ASCII_HYPH 30 /* breakable hyphen */
+#define ASCII_BREAK 29 /* breakable zero-width space */
/*
* Status level. This refers to both internal status (i.e., whilst
diff --git a/mandocdb.c b/mandocdb.c
index 8be546b3..4a7dd1f6 100644
--- a/mandocdb.c
+++ b/mandocdb.c
@@ -1664,7 +1664,7 @@ static void
render_key(struct mchars *mc, struct str *key)
{
size_t sz, bsz, pos;
- char utfbuf[7], res[5];
+ char utfbuf[7], res[6];
char *buf;
const char *seq, *cpp, *val;
int len, u;
@@ -1676,7 +1676,8 @@ render_key(struct mchars *mc, struct str *key)
res[1] = '\t';
res[2] = ASCII_NBRSP;
res[3] = ASCII_HYPH;
- res[4] = '\0';
+ res[4] = ASCII_BREAK;
+ res[5] = '\0';
val = key->key;
bsz = strlen(val);
@@ -1707,15 +1708,23 @@ render_key(struct mchars *mc, struct str *key)
val += sz;
}
- if (ASCII_HYPH == *val) {
+ switch (*val) {
+ case (ASCII_HYPH):
buf[pos++] = '-';
val++;
continue;
- } else if ('\t' == *val || ASCII_NBRSP == *val) {
+ case ('\t'):
+ /* FALLTHROUGH */
+ case (ASCII_NBRSP):
buf[pos++] = ' ';
val++;
+ /* FALLTHROUGH */
+ case (ASCII_BREAK):
continue;
- } else if ('\\' != *val)
+ default:
+ break;
+ }
+ if ('\\' != *val)
break;
/* Read past the slash. */
diff --git a/mdoc_man.c b/mdoc_man.c
index 9f7691d9..d1d203e8 100644
--- a/mdoc_man.c
+++ b/mdoc_man.c
@@ -1,6 +1,6 @@
/* $Id$ */
/*
- * Copyright (c) 2011, 2012, 2013 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2011, 2012, 2013, 2014 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
@@ -365,6 +365,9 @@ print_word(const char *s)
case (ASCII_HYPH):
putchar('-');
break;
+ case (ASCII_BREAK):
+ printf("\\:");
+ break;
case (' '):
if (MMAN_nbrword & outflags) {
printf("\\ ");
diff --git a/term.c b/term.c
index 9f59d113..01d6ed60 100644
--- a/term.c
+++ b/term.c
@@ -1,7 +1,7 @@
/* $Id$ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2010, 2011, 2012, 2013 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2010-2014 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
@@ -179,7 +179,8 @@ term_flushln(struct termp *p)
/* Regular word. */
/* Break at the hyphen point if we overrun. */
if (vend > vis && vend < bp &&
- ASCII_HYPH == p->buf[j])
+ (ASCII_HYPH == p->buf[j] ||
+ ASCII_BREAK == p->buf[j]))
jhy = j;
vend += (*p->width)(p, p->buf[j]);
@@ -233,6 +234,8 @@ term_flushln(struct termp *p)
vbl += (*p->width)(p, ' ');
continue;
}
+ if (ASCII_BREAK == p->buf[i])
+ continue;
/*
* Now we definitely know there will be
@@ -644,7 +647,8 @@ term_strlen(const struct termp *p, const char *cp)
int ssz, skip, c;
const char *seq, *rhs;
enum mandoc_esc esc;
- static const char rej[] = { '\\', ASCII_HYPH, ASCII_NBRSP, '\0' };
+ static const char rej[] = { '\\', ASCII_NBRSP, ASCII_HYPH,
+ ASCII_BREAK, '\0' };
/*
* Account for escaped sequences within string length
@@ -732,6 +736,8 @@ term_strlen(const struct termp *p, const char *cp)
case (ASCII_HYPH):
sz += cond_width(p, '-', &skip);
cp++;
+ /* FALLTHROUGH */
+ case (ASCII_BREAK):
break;
default:
break;