aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/html.c
diff options
context:
space:
mode:
authorIngo Schwarze <schwarze@openbsd.org>2012-05-31 22:29:13 +0000
committerIngo Schwarze <schwarze@openbsd.org>2012-05-31 22:29:13 +0000
commit202b7e8f93f2d7b52432ac7b359f9df32d46f683 (patch)
treeb0a7dae1cafcea499730ab4b4aa45acde007b42c /html.c
parentf2888f84e20ae452a6382db6d6f0888b1da41ef5 (diff)
downloadmandoc-202b7e8f93f2d7b52432ac7b359f9df32d46f683.tar.gz
mandoc-202b7e8f93f2d7b52432ac7b359f9df32d46f683.tar.zst
mandoc-202b7e8f93f2d7b52432ac7b359f9df32d46f683.zip
Implement the roff \z escape sequence, intended to output the next
character without advancing the cursor position; implement it to simply skip the next character, as it will usually be overwritten. With this change, the pod2man(1) preamble user-defined string \*:, intended to render as a diaeresis or umlaut diacritic above the preceding character, is rendered in a slightly less ugly way, though still not correctly. It was rendered as "z.." and is now rendered as ".". Given that the definition of \*: uses elaborate manual \h positioning, there is little chance for mandoc(1) to ever render it correctly, but at least we can refrain from printing out a spurious "z", and we can make the \z do something semi-reasonable for easier cases. "just commit" kristaps@
Diffstat (limited to 'html.c')
-rw-r--r--html.c83
1 files changed, 58 insertions, 25 deletions
diff --git a/html.c b/html.c
index 326df035..115b79a0 100644
--- a/html.c
+++ b/html.c
@@ -1,7 +1,7 @@
-/* $Id: html.c,v 1.150 2011/10/05 21:35:17 kristaps Exp $ */
+/* $Id: html.c,v 1.151 2012/05/31 22:29:13 schwarze Exp $ */
/*
* Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
- * Copyright (c) 2011 Ingo Schwarze <schwarze@openbsd.org>
+ * Copyright (c) 2011, 2012 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
@@ -262,8 +262,8 @@ print_metaf(struct html *h, enum mandoc_esc deco)
int
html_strlen(const char *cp)
{
- int ssz, sz;
- const char *seq, *p;
+ size_t rsz;
+ int skip, sz;
/*
* Account for escaped sequences within string length
@@ -274,10 +274,21 @@ html_strlen(const char *cp)
*/
sz = 0;
- while (NULL != (p = strchr(cp, '\\'))) {
- sz += (int)(p - cp);
- ++cp;
- switch (mandoc_escape(&cp, &seq, &ssz)) {
+ skip = 0;
+ while (1) {
+ 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):
@@ -285,15 +296,19 @@ html_strlen(const char *cp)
case (ESCAPE_NUMBERED):
/* FALLTHROUGH */
case (ESCAPE_SPECIAL):
- sz++;
+ if (skip)
+ skip = 0;
+ else
+ sz++;
+ break;
+ case (ESCAPE_SKIPCHAR):
+ skip = 1;
break;
default:
break;
}
}
-
- assert(sz >= 0);
- return(sz + strlen(cp));
+ return(sz);
}
static int
@@ -308,6 +323,12 @@ print_encode(struct html *h, const char *p, int norecurse)
nospace = 0;
while ('\0' != *p) {
+ if (HTML_SKIPCHAR & h->flags && '\\' != *p) {
+ h->flags &= ~HTML_SKIPCHAR;
+ p++;
+ continue;
+ }
+
sz = strcspn(p, rejs);
fwrite(p, 1, sz, stdout);
@@ -338,6 +359,31 @@ print_encode(struct html *h, const char *p, int norecurse)
break;
switch (esc) {
+ case (ESCAPE_FONT):
+ /* FALLTHROUGH */
+ case (ESCAPE_FONTPREV):
+ /* FALLTHROUGH */
+ case (ESCAPE_FONTBOLD):
+ /* FALLTHROUGH */
+ case (ESCAPE_FONTITALIC):
+ /* FALLTHROUGH */
+ case (ESCAPE_FONTROMAN):
+ if (0 == norecurse)
+ print_metaf(h, esc);
+ continue;
+ case (ESCAPE_SKIPCHAR):
+ h->flags |= HTML_SKIPCHAR;
+ continue;
+ default:
+ break;
+ }
+
+ if (h->flags & HTML_SKIPCHAR) {
+ h->flags &= ~HTML_SKIPCHAR;
+ continue;
+ }
+
+ switch (esc) {
case (ESCAPE_UNICODE):
/* Skip passed "u" header. */
c = mchars_num2uc(seq + 1, len - 1);
@@ -356,19 +402,6 @@ print_encode(struct html *h, const char *p, int norecurse)
else if (-1 == c && 1 == len)
putchar((int)*seq);
break;
- case (ESCAPE_FONT):
- /* FALLTHROUGH */
- case (ESCAPE_FONTPREV):
- /* FALLTHROUGH */
- case (ESCAPE_FONTBOLD):
- /* FALLTHROUGH */
- case (ESCAPE_FONTITALIC):
- /* FALLTHROUGH */
- case (ESCAPE_FONTROMAN):
- if (norecurse)
- break;
- print_metaf(h, esc);
- break;
case (ESCAPE_NOSPACE):
if ('\0' == *p)
nospace = 1;