-/* $Id: mdoc_html.c,v 1.41 2009/10/28 05:08:17 kristaps Exp $ */
+/* $Id: mdoc_html.c,v 1.52 2010/01/01 17:14:29 kristaps Exp $ */
/*
* Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se>
*
* ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
* OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
+#ifdef HAVE_CONFIG_H
+#include "config.h"
+#endif
+
#include <sys/types.h>
-#include <sys/param.h>
#include <assert.h>
#include <ctype.h>
-#include <err.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
const struct mdoc_node *n, \
struct html *h
+#ifndef MIN
+#define MIN(a,b) ((/*CONSTCOND*/(a)<(b))?(a):(b))
+#endif
+
struct htmlmdoc {
int (*pre)(MDOC_ARGS);
void (*post)(MDOC_ARGS);
static int mdoc_xr_pre(MDOC_ARGS);
static int mdoc_xx_pre(MDOC_ARGS);
-#ifdef __linux__
-extern size_t strlcpy(char *, const char *, size_t);
-extern size_t strlcat(char *, const char *, size_t);
-#endif
-
static const struct htmlmdoc mdocs[MDOC_MAX] = {
{mdoc_ap_pre, NULL}, /* Ap */
{NULL, NULL}, /* Dd */
break;
case (MDOC_TEXT):
print_text(h, n->string);
- break;
+ return;
default:
if (mdocs[n->tok].pre)
child = (*mdocs[n->tok].pre)(m, n, h);
case (MDOC_ROOT):
mdoc_root_post(m, n, h);
break;
- case (MDOC_TEXT):
- break;
default:
if (mdocs[n->tok].post)
(*mdocs[n->tok].post)(m, n, h);
return(1);
}
- html_idcpy(buf, "id_", BUFSIZ);
+ buf[0] = '\0';
for (nn = n->child; nn; nn = nn->next) {
html_idcat(buf, nn->string, BUFSIZ);
if (nn->next)
- html_idcat(buf, "_", BUFSIZ);
+ html_idcat(buf, " ", BUFSIZ);
}
/*
/* TODO: see note in mdoc_sh_pre() about duplicates. */
- html_idcpy(buf, "id_", BUFSIZ);
+ buf[0] = '\0';
for (nn = n->child; nn; nn = nn->next) {
html_idcat(buf, nn->string, BUFSIZ);
if (nn->next)
- html_idcat(buf, "_", BUFSIZ);
+ html_idcat(buf, " ", BUFSIZ);
}
SCALE_HS_INIT(&su, INDENT - HALFINDENT);
PAIR_CLASS_INIT(&tag, "flag");
print_otag(h, TAG_SPAN, 1, &tag);
- if (MDOC_Fl == n->tok) {
- print_text(h, "\\-");
+
+ /* `Cm' has no leading hyphen. */
+
+ if (MDOC_Cm == n->tok)
+ return(1);
+
+ print_text(h, "\\-");
+
+ /* A blank `Fl' should incur a subsequent space. */
+
+ if (n->child)
h->flags |= HTML_NOSPACE;
- }
+
return(1);
}
{
struct htmlpair tag;
- if ( ! (HTML_NEWLINE & h->flags))
- if (SEC_SYNOPSIS == n->sec) {
- bufcat_style(h, "clear", "both");
- PAIR_STYLE_INIT(&tag, h);
- print_otag(h, TAG_BR, 1, &tag);
- }
+ if (SEC_SYNOPSIS == n->sec && n->prev) {
+ bufcat_style(h, "clear", "both");
+ PAIR_STYLE_INIT(&tag, h);
+ print_otag(h, TAG_BR, 1, &tag);
+ }
PAIR_CLASS_INIT(&tag, "name");
print_otag(h, TAG_SPAN, 1, &tag);
pp = "BSDI BSD/OS";
break;
case (MDOC_Dx):
- pp = "DragonFlyBSD";
+ pp = "DragonFly";
break;
case (MDOC_Fx):
pp = "FreeBSD";
switch (type) {
case (MDOC_Item):
- /* FALLTHROUGH */
+ return(0);
case (MDOC_Ohang):
- print_otag(h, TAG_DIV, 0, NULL);
- break;
+ print_otag(h, TAG_DIV, 0, &tag);
+ return(1);
case (MDOC_Column):
bufcat_su(h, "min-width", width);
bufcat_style(h, "clear", "none");
/* Override width in some cases. */
switch (type) {
+ case (MDOC_Ohang):
+ /* FALLTHROUGH */
case (MDOC_Item):
/* FALLTHROUGH */
case (MDOC_Inset):
return(1);
ord = malloc(sizeof(struct ord));
- if (NULL == ord)
- err(EXIT_FAILURE, "malloc");
+ if (NULL == ord) {
+ perror(NULL);
+ exit(EXIT_FAILURE);
+ }
ord->cookie = n;
ord->pos = 1;
ord->next = h->ords.head;
/* FIXME: duplicates? */
strlcpy(buf, "#", BUFSIZ);
- html_idcat(buf, "id_", BUFSIZ);
for (nn = n->child; nn; nn = nn->next) {
html_idcat(buf, nn->string, BUFSIZ);
if (nn->next)
- html_idcat(buf, "_", BUFSIZ);
+ html_idcat(buf, " ", BUFSIZ);
}
PAIR_CLASS_INIT(&tag[0], "link-sec");
struct roffsu su;
if (SEC_SYNOPSIS == n->sec) {
- if (n->next && MDOC_Vt != n->next->tok) {
+ if (n->prev && MDOC_Vt != n->prev->tok) {
SCALE_VS_INIT(&su, 1);
- bufcat_su(h, "margin-bottom", &su);
+ bufcat_su(h, "margin-top", &su);
PAIR_STYLE_INIT(&tag, h);
print_otag(h, TAG_DIV, 1, &tag);
} else
bufcat_su(h, "height", &su);
PAIR_STYLE_INIT(&tag, h);
print_otag(h, TAG_DIV, 1, &tag);
- return(1);
+ /* So the div isn't empty: */
+ print_text(h, "\\~");
+
+ return(0);
}