From a5cf99ba0ce655c79f97727aa85c3afd804f98c9 Mon Sep 17 00:00:00 2001 From: Ingo Schwarze Date: Wed, 22 Jan 2014 20:58:39 +0000 Subject: 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 . --- chars.c | 4 ++-- chars.in | 20 ++++++++++++-------- html.c | 12 +++++++++--- mandoc.h | 3 ++- mandocdb.c | 21 +++++++++++++++------ mdoc_man.c | 7 +++++-- term.c | 14 ++++++++++---- 7 files changed, 55 insertions(+), 26 deletions(-) diff --git a/chars.c b/chars.c index 3ad1f574..35046202 100644 --- a/chars.c +++ b/chars.c @@ -1,4 +1,4 @@ -/* $Id: chars.c,v 1.54 2013/06/20 22:39:30 schwarze Exp $ */ +/* $Id: chars.c,v 1.55 2014/01/22 20:58:39 schwarze Exp $ */ /* * Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons * Copyright (c) 2011 Ingo Schwarze @@ -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 cc6549e7..5c686ff0 100644 --- a/chars.in +++ b/chars.in @@ -1,6 +1,7 @@ -/* $Id: chars.in,v 1.43 2013/06/20 22:39:30 schwarze Exp $ */ +/* $Id: chars.in,v 1.44 2014/01/22 20:58:39 schwarze Exp $ */ /* * Copyright (c) 2009, 2010, 2011 Kristaps Dzonsons + * Copyright (c) 2014 Ingo Schwarze * * 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 30ed53e4..bbc9ec5b 100644 --- a/html.c +++ b/html.c @@ -1,7 +1,7 @@ -/* $Id: html.c,v 1.153 2014/01/05 19:10:56 joerg Exp $ */ +/* $Id: html.c,v 1.154 2014/01/22 20:58:39 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons - * Copyright (c) 2011, 2012, 2013 Ingo Schwarze + * Copyright (c) 2011, 2012, 2013, 2014 Ingo Schwarze * * 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("&"); 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 9c209ee3..99b1ff81 100644 --- a/mandoc.h +++ b/mandoc.h @@ -1,4 +1,4 @@ -/* $Id: mandoc.h,v 1.114 2014/01/05 20:26:36 schwarze Exp $ */ +/* $Id: mandoc.h,v 1.115 2014/01/22 20:58:39 schwarze Exp $ */ /* * Copyright (c) 2010, 2011 Kristaps Dzonsons * Copyright (c) 2012, 2013, 2014 Ingo Schwarze @@ -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 e7963859..eea9ab1c 100644 --- a/mandocdb.c +++ b/mandocdb.c @@ -1,4 +1,4 @@ -/* $Id: mandocdb.c,v 1.113 2014/01/19 22:48:16 schwarze Exp $ */ +/* $Id: mandocdb.c,v 1.114 2014/01/22 20:58:39 schwarze Exp $ */ /* * Copyright (c) 2011, 2012 Kristaps Dzonsons * Copyright (c) 2011, 2012, 2013, 2014 Ingo Schwarze @@ -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 6ee8b3ab..a6517df5 100644 --- a/mdoc_man.c +++ b/mdoc_man.c @@ -1,6 +1,6 @@ -/* $Id: mdoc_man.c,v 1.57 2013/12/25 22:00:45 schwarze Exp $ */ +/* $Id: mdoc_man.c,v 1.58 2014/01/22 20:58:39 schwarze Exp $ */ /* - * Copyright (c) 2011, 2012, 2013 Ingo Schwarze + * Copyright (c) 2011, 2012, 2013, 2014 Ingo Schwarze * * 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 79a39ff2..0d5eafd8 100644 --- a/term.c +++ b/term.c @@ -1,7 +1,7 @@ -/* $Id: term.c,v 1.215 2013/12/31 18:07:42 schwarze Exp $ */ +/* $Id: term.c,v 1.216 2014/01/22 20:58:39 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons - * Copyright (c) 2010, 2011, 2012, 2013 Ingo Schwarze + * Copyright (c) 2010-2014 Ingo Schwarze * * 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; -- cgit v1.2.3-56-ge451