summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorschwarze <schwarze@openbsd.org>2017-01-28 22:36:17 +0000
committerschwarze <schwarze@openbsd.org>2017-01-28 22:36:17 +0000
commit1e98cf61f98f6da0078e79fa811335d59d2af32d (patch)
tree98e54051f88ee774db695c87180c4a9117f09702
parent.Bl -column with zero columns is legal, so don't segfalt on it. (diff)
downloadwireguard-openbsd-1e98cf61f98f6da0078e79fa811335d59d2af32d.tar.xz
wireguard-openbsd-1e98cf61f98f6da0078e79fa811335d59d2af32d.zip
Simplify usage of print_otag() even more:
accept NULL to skip the attribute or format.
-rw-r--r--usr.bin/mandoc/html.c84
-rw-r--r--usr.bin/mandoc/mdoc_html.c69
2 files changed, 72 insertions, 81 deletions
diff --git a/usr.bin/mandoc/html.c b/usr.bin/mandoc/html.c
index 21a9b6ce2f2..0c17ac5d8db 100644
--- a/usr.bin/mandoc/html.c
+++ b/usr.bin/mandoc/html.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: html.c,v 1.72 2017/01/26 18:28:04 schwarze Exp $ */
+/* $OpenBSD: html.c,v 1.73 2017/01/28 22:36:17 schwarze Exp $ */
/*
* Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2011-2015, 2017 Ingo Schwarze <schwarze@openbsd.org>
@@ -447,7 +447,7 @@ print_otag(struct html *h, enum htmltag tag, const char *fmt, ...)
char numbuf[16];
struct tag *t;
const char *attr;
- char *s;
+ char *arg1, *arg2;
double v;
int i, have_style, tflags;
@@ -492,12 +492,14 @@ print_otag(struct html *h, enum htmltag tag, const char *fmt, ...)
have_style = 0;
while (*fmt != '\0') {
if (*fmt == 's') {
- print_word(h, " style=\"");
have_style = 1;
fmt++;
break;
}
- s = va_arg(ap, char *);
+
+ /* Parse a non-style attribute and its arguments. */
+
+ arg1 = va_arg(ap, char *);
switch (*fmt++) {
case 'c':
attr = "class";
@@ -509,23 +511,31 @@ print_otag(struct html *h, enum htmltag tag, const char *fmt, ...)
attr = "id";
break;
case '?':
- attr = s;
- s = va_arg(ap, char *);
+ attr = arg1;
+ arg1 = va_arg(ap, char *);
break;
default:
abort();
}
+ arg2 = NULL;
+ if (*fmt == 'M')
+ arg2 = va_arg(ap, char *);
+ if (arg1 == NULL)
+ continue;
+
+ /* Print the non-style attributes. */
+
print_byte(h, ' ');
print_word(h, attr);
print_byte(h, '=');
print_byte(h, '"');
switch (*fmt) {
case 'M':
- print_href(h, s, va_arg(ap, char *), 1);
+ print_href(h, arg1, arg2, 1);
fmt++;
break;
case 'I':
- print_href(h, s, NULL, 0);
+ print_href(h, arg1, NULL, 0);
fmt++;
break;
case 'R':
@@ -533,7 +543,7 @@ print_otag(struct html *h, enum htmltag tag, const char *fmt, ...)
fmt++;
/* FALLTHROUGH */
default:
- print_encode(h, s, NULL, 1);
+ print_encode(h, arg1, NULL, 1);
break;
}
print_byte(h, '"');
@@ -541,31 +551,35 @@ print_otag(struct html *h, enum htmltag tag, const char *fmt, ...)
/* Print out styles. */
- s = NULL;
- su = &mysu;
while (*fmt != '\0') {
+ arg1 = NULL;
+ su = NULL;
/* First letter: input argument type. */
switch (*fmt++) {
case 'h':
i = va_arg(ap, int);
+ su = &mysu;
SCALE_HS_INIT(su, i);
break;
case 's':
- s = va_arg(ap, char *);
+ arg1 = va_arg(ap, char *);
break;
case 'u':
su = va_arg(ap, struct roffsu *);
break;
case 'v':
i = va_arg(ap, int);
+ su = &mysu;
SCALE_VS_INIT(su, i);
break;
case 'w':
case 'W':
- s = va_arg(ap, char *);
- a2width(s, su);
+ if ((arg2 = va_arg(ap, char *)) == NULL)
+ break;
+ su = &mysu;
+ a2width(arg2, su);
if (fmt[-1] == 'W')
su->scale *= -1.0;
break;
@@ -598,33 +612,37 @@ print_otag(struct html *h, enum htmltag tag, const char *fmt, ...)
attr = "min-width";
break;
case '?':
- print_word(h, s);
- print_byte(h, ':');
- print_byte(h, ' ');
- print_word(h, va_arg(ap, char *));
- print_byte(h, ';');
- if (*fmt != '\0')
- print_byte(h, ' ');
- continue;
+ attr = arg1;
+ arg1 = va_arg(ap, char *);
+ break;
default:
abort();
}
- v = su->scale;
- if (su->unit == SCALE_MM && (v /= 100.0) == 0.0)
- v = 1.0;
- else if (su->unit == SCALE_BU)
- v /= 24.0;
+ if (su == NULL && arg1 == NULL)
+ continue;
+
+ if (have_style == 1)
+ print_word(h, " style=\"");
+ else
+ print_byte(h, ' ');
print_word(h, attr);
print_byte(h, ':');
print_byte(h, ' ');
- (void)snprintf(numbuf, sizeof(numbuf), "%.2f", v);
- print_word(h, numbuf);
- print_word(h, roffscales[su->unit]);
+ if (su != NULL) {
+ v = su->scale;
+ if (su->unit == SCALE_MM && (v /= 100.0) == 0.0)
+ v = 1.0;
+ else if (su->unit == SCALE_BU)
+ v /= 24.0;
+ (void)snprintf(numbuf, sizeof(numbuf), "%.2f", v);
+ print_word(h, numbuf);
+ print_word(h, roffscales[su->unit]);
+ } else
+ print_word(h, arg1);
print_byte(h, ';');
- if (*fmt != '\0')
- print_byte(h, ' ');
+ have_style = 2;
}
- if (have_style)
+ if (have_style == 2)
print_byte(h, '"');
va_end(ap);
diff --git a/usr.bin/mandoc/mdoc_html.c b/usr.bin/mandoc/mdoc_html.c
index ef86051b0c1..f8bd1239bc2 100644
--- a/usr.bin/mandoc/mdoc_html.c
+++ b/usr.bin/mandoc/mdoc_html.c
@@ -1,4 +1,4 @@
-/* $OpenBSD: mdoc_html.c,v 1.137 2017/01/28 18:42:10 schwarze Exp $ */
+/* $OpenBSD: mdoc_html.c,v 1.138 2017/01/28 22:36:17 schwarze Exp $ */
/*
* Copyright (c) 2008-2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv>
* Copyright (c) 2014, 2015, 2016, 2017 Ingo Schwarze <schwarze@openbsd.org>
@@ -505,22 +505,18 @@ mdoc_sh_pre(MDOC_ARGS)
char *id;
switch (n->type) {
- case ROFFT_BLOCK:
- return 1;
+ case ROFFT_HEAD:
+ id = make_id(n);
+ print_otag(h, TAG_H1, "ci", "Sh", id);
+ free(id);
+ break;
case ROFFT_BODY:
if (n->sec == SEC_AUTHORS)
h->flags &= ~(HTML_SPLIT|HTML_NOSPLIT);
- return 1;
+ break;
default:
break;
}
-
- if ((id = make_id(n)) != NULL) {
- print_otag(h, TAG_H1, "ci", "Sh", id);
- free(id);
- } else
- print_otag(h, TAG_H1, "c", "Sh");
-
return 1;
}
@@ -532,12 +528,9 @@ mdoc_ss_pre(MDOC_ARGS)
if (n->type != ROFFT_HEAD)
return 1;
- if ((id = make_id(n)) != NULL) {
- print_otag(h, TAG_H2, "ci", "Ss", id);
- free(id);
- } else
- print_otag(h, TAG_H2, "c", "Ss");
-
+ id = make_id(n);
+ print_otag(h, TAG_H2, "ci", "Ss", id);
+ free(id);
return 1;
}
@@ -747,11 +740,8 @@ mdoc_it_pre(MDOC_ARGS)
print_otag(h, TAG_B, "c", cattr);
break;
case ROFFT_BODY:
- if (bl->norm->Bl.width == NULL)
- print_otag(h, TAG_DD, "c", cattr);
- else
- print_otag(h, TAG_DD, "cswl", cattr,
- bl->norm->Bl.width);
+ print_otag(h, TAG_DD, "cswl", cattr,
+ bl->norm->Bl.width);
break;
default:
break;
@@ -763,22 +753,16 @@ mdoc_it_pre(MDOC_ARGS)
if (h->style != NULL && !bl->norm->Bl.comp &&
(n->parent->prev == NULL ||
n->parent->prev->body->child != NULL)) {
- if (bl->norm->Bl.width == NULL)
- t = print_otag(h, TAG_DT, "c", cattr);
- else
- t = print_otag(h, TAG_DT, "csWl",
- cattr, bl->norm->Bl.width);
+ t = print_otag(h, TAG_DT, "csWl",
+ cattr, bl->norm->Bl.width);
print_text(h, "\\ ");
print_tagq(h, t);
t = print_otag(h, TAG_DD, "c", cattr);
print_text(h, "\\ ");
print_tagq(h, t);
}
- if (bl->norm->Bl.width == NULL)
- print_otag(h, TAG_DT, "c", cattr);
- else
- print_otag(h, TAG_DT, "csWl", cattr,
- bl->norm->Bl.width);
+ print_otag(h, TAG_DT, "csWl", cattr,
+ bl->norm->Bl.width);
break;
case ROFFT_BODY:
if (n->child == NULL) {
@@ -883,10 +867,7 @@ mdoc_bl_pre(MDOC_ARGS)
cattr = "Bl-tag";
if (bl->offs)
print_otag(h, TAG_DIV, "cswl", cattr, bl->offs);
- if (bl->width == NULL)
- print_otag(h, TAG_DL, "c", cattr);
- else
- print_otag(h, TAG_DL, "cswl", cattr, bl->width);
+ print_otag(h, TAG_DL, "cswl", cattr, bl->width);
return 1;
case LIST_column:
elemtype = TAG_TABLE;
@@ -895,12 +876,7 @@ mdoc_bl_pre(MDOC_ARGS)
default:
abort();
}
-
- if (bl->offs)
- print_otag(h, elemtype, "cswl", cattr, bl->offs);
- else
- print_otag(h, elemtype, "c", cattr);
-
+ print_otag(h, elemtype, "cswl", cattr, bl->offs);
return 1;
}
@@ -938,12 +914,9 @@ mdoc_sx_pre(MDOC_ARGS)
{
char *id;
- if ((id = make_id(n)) != NULL) {
- print_otag(h, TAG_A, "chR", "Sx", id);
- free(id);
- } else
- print_otag(h, TAG_A, "c", "Sx");
-
+ id = make_id(n);
+ print_otag(h, TAG_A, "chR", "Sx", id);
+ free(id);
return 1;
}