- const char *pp;
- struct htmlpair tag;
-
- switch (n->tok) {
- case (MDOC_Bsx):
- pp = "BSDI BSD/OS";
- break;
- case (MDOC_Dx):
- pp = "DragonFlyBSD";
- break;
- case (MDOC_Fx):
- pp = "FreeBSD";
- break;
- case (MDOC_Nx):
- pp = "NetBSD";
- break;
- case (MDOC_Ox):
- pp = "OpenBSD";
- break;
- case (MDOC_Ux):
- pp = "UNIX";
- break;
- default:
- return(1);
- }
-
- tag.key = ATTR_CLASS;
- tag.val = "unix";
-
- print_otag(h, TAG_SPAN, 1, &tag);
- print_text(h, pp);
- return(1);
-}
-
-
-/* ARGSUSED */
-static int
-mdoc_tbl_block_pre(MDOC_ARGS, int t, int w, int o, int c)
-{
- struct htmlpair tag;
-
- switch (t) {
- case (MDOC_Column):
- /* FALLTHROUGH */
- case (MDOC_Item):
- /* FALLTHROUGH */
- case (MDOC_Ohang):
- buffmt("margin-left: %dem; clear: both;", o);
- break;
- default:
- buffmt("margin-left: %dem; clear: both;", w + o);
- break;
- }
-
- if ( ! c && MDOC_Column != t) {
- if (n->prev && n->prev->body->child)
- bufcat("padding-top: 1em;");
- else if (NULL == n->prev)
- bufcat("padding-top: 1em;");
- }
-
- tag.key = ATTR_STYLE;
- tag.val = buf;
- print_otag(h, TAG_DIV, 1, &tag);
- return(1);
-}
-
-
-/* ARGSUSED */
-static int
-mdoc_tbl_body_pre(MDOC_ARGS, int t, int w)
-{
-
- print_otag(h, TAG_DIV, 0, NULL);
- return(1);
-}
-
-
-/* ARGSUSED */
-static int
-mdoc_tbl_head_pre(MDOC_ARGS, int t, int w)
-{
- struct htmlpair tag;
- struct ord *ord;
- char nbuf[BUFSIZ];
-
- switch (t) {
- case (MDOC_Item):
- /* FALLTHROUGH */
- case (MDOC_Ohang):
- print_otag(h, TAG_DIV, 0, NULL);
- break;
- case (MDOC_Column):
- buffmt("min-width: %dem;", w);
- bufcat("clear: none;");
- if (n->next && MDOC_HEAD == n->next->type)
- bufcat("float: left;");
- tag.key = ATTR_STYLE;
- tag.val = buf;
- print_otag(h, TAG_DIV, 1, &tag);
- break;
- default:
- buffmt("margin-left: -%dem;", w);
- bufcat("clear: left;");
- bufcat("float: left;");
- bufcat("padding-right: 1em;");
- tag.key = ATTR_STYLE;
- tag.val = buf;
- print_otag(h, TAG_DIV, 1, &tag);
- break;
- }
-
- switch (t) {
- case (MDOC_Diag):
- tag.key = ATTR_CLASS;
- tag.val = "diag";
- print_otag(h, TAG_SPAN, 1, &tag);
- break;
- case (MDOC_Enum):
- ord = SLIST_FIRST(&h->ords);
- assert(ord);
- nbuf[BUFSIZ - 1] = 0;
- (void)snprintf(nbuf, BUFSIZ - 1, "%d.", ord->pos++);
- print_text(h, nbuf);
- return(0);
- case (MDOC_Dash):
- print_text(h, "\\(en");
- return(0);
- case (MDOC_Hyphen):
- print_text(h, "\\-");
- return(0);
- case (MDOC_Bullet):
- print_text(h, "\\(bu");
- return(0);
- default:
- break;
- }
-
- return(1);
-}
-
-
-static int
-mdoc_tbl_pre(MDOC_ARGS, int type)
-{
- int i, w, o, c, wp;
- const struct mdoc_node *bl, *nn;
-
- bl = n->parent->parent;
- if (MDOC_BLOCK != n->type)
- bl = bl->parent;
-
- /* FIXME: fmt_vspace() equivalent. */
-
- assert(bl->args);
-
- w = o = c = 0;
- wp = -1;
-
- for (i = 0; i < (int)bl->args->argc; i++)
- if (MDOC_Width == bl->args->argv[i].arg) {
- assert(bl->args->argv[i].sz);
- wp = i;
- w = a2width(bl->args->argv[i].value[0]);
- } else if (MDOC_Offset == bl->args->argv[i].arg) {
- assert(bl->args->argv[i].sz);
- o = a2offs(bl->args->argv[i].value[0]);
- } else if (MDOC_Compact == bl->args->argv[i].arg)
- c = 1;
-
- if (MDOC_HEAD == n->type && MDOC_Column == type) {
- nn = n->parent->child;
- assert(nn && MDOC_HEAD == nn->type);
- for (i = 0; nn && nn != n; nn = nn->next, i++)
- /* Counter... */ ;
- assert(nn);
- if (wp >= 0 && i < (int)bl->args[wp].argv->sz)
- w = a2width(bl->args->argv[wp].value[i]);
- }
-
- switch (type) {
- case (MDOC_Enum):
- /* FALLTHROUGH */
- case (MDOC_Dash):
- /* FALLTHROUGH */
- case (MDOC_Hyphen):
- /* FALLTHROUGH */
- case (MDOC_Bullet):
- if (w < 4)
- w = 4;
- break;
- case (MDOC_Inset):
- /* FALLTHROUGH */
- case (MDOC_Diag):
- w = 1;
- break;
- default:
- if (0 == w)
- w = 10;
- break;
- }
-
- switch (n->type) {
- case (MDOC_BLOCK):
- break;
- case (MDOC_HEAD):
- return(mdoc_tbl_head_pre(m, n, h, type, w));
- case (MDOC_BODY):
- return(mdoc_tbl_body_pre(m, n, h, type, w));
- default:
- abort();
- /* NOTREACHED */
- }
-
- return(mdoc_tbl_block_pre(m, n, h, type, w, o, c));
-}
-
-
-/* ARGSUSED */
-static int
-mdoc_bl_pre(MDOC_ARGS)
-{
- struct ord *ord;
-
- if (MDOC_BLOCK != n->type)
- return(1);
- if (MDOC_Enum != a2list(n))
- return(1);
-
- ord = malloc(sizeof(struct ord));
- if (NULL == ord)
- err(EXIT_FAILURE, "malloc");
- ord->cookie = n;
- ord->pos = 1;
- SLIST_INSERT_HEAD(&h->ords, ord, entry);
-
- return(1);
-}
-
-
-/* ARGSUSED */
-static void
-mdoc_bl_post(MDOC_ARGS)
-{
- struct ord *ord;
-
- if (MDOC_BLOCK != n->type)
- return;
- if (MDOC_Enum != a2list(n))
- return;
-
- ord = SLIST_FIRST(&h->ords);
- assert(ord);
- SLIST_REMOVE_HEAD(&h->ords, entry);
- free(ord);
-}
-
-
-static int
-mdoc_it_pre(MDOC_ARGS)
-{
- int type;
-
- if (MDOC_BLOCK == n->type)
- type = a2list(n->parent->parent);
- else
- type = a2list(n->parent->parent->parent);
-
- return(mdoc_tbl_pre(m, n, h, type));
-}
-
-
-/* ARGSUSED */
-static int
-mdoc_ex_pre(MDOC_ARGS)
-{
- const struct mdoc_node *nn;
- struct tag *t;
- struct htmlpair tag;
-
- print_text(h, "The");
-
- tag.key = ATTR_CLASS;
- tag.val = "utility";
-
- for (nn = n->child; nn; nn = nn->next) {
- t = print_otag(h, TAG_SPAN, 1, &tag);
- print_text(h, nn->string);
- print_tagq(h, t);
-
- h->flags |= HTML_NOSPACE;
-
- if (nn->next && NULL == nn->next->next)
- print_text(h, ", and");
- else if (nn->next)
- print_text(h, ",");
- else
- h->flags &= ~HTML_NOSPACE;
- }
-
- if (n->child->next)
- print_text(h, "utilities exit");
- else
- print_text(h, "utility exits");
-
- print_text(h, "0 on success, and >0 if an error occurs.");
- return(0);
-}
-
-
-/* ARGSUSED */
-static int
-mdoc_dq_pre(MDOC_ARGS)
-{
-
- if (MDOC_BODY != n->type)
- return(1);
- print_text(h, "\\(lq");
- h->flags |= HTML_NOSPACE;
- return(1);
-}
-
-
-/* ARGSUSED */
-static void
-mdoc_dq_post(MDOC_ARGS)
-{
-
- if (MDOC_BODY != n->type)
- return;
- h->flags |= HTML_NOSPACE;
- print_text(h, "\\(rq");
-}
-
-
-/* ARGSUSED */
-static int
-mdoc_pq_pre(MDOC_ARGS)
-{
-
- if (MDOC_BODY != n->type)
- return(1);
- print_text(h, "\\&(");
- h->flags |= HTML_NOSPACE;
- return(1);
-}
-
-
-/* ARGSUSED */
-static void
-mdoc_pq_post(MDOC_ARGS)
-{
-
- if (MDOC_BODY != n->type)
- return;
- print_text(h, ")");
-}
-
-
-/* ARGSUSED */
-static int
-mdoc_sq_pre(MDOC_ARGS)
-{
-
- if (MDOC_BODY != n->type)
- return(1);
- print_text(h, "\\(oq");
- h->flags |= HTML_NOSPACE;
- return(1);
-}
-
-
-/* ARGSUSED */
-static void
-mdoc_sq_post(MDOC_ARGS)
-{
-
- if (MDOC_BODY != n->type)
- return;
- h->flags |= HTML_NOSPACE;
- print_text(h, "\\(aq");
-}
-
-
-/* ARGSUSED */
-static int
-mdoc_em_pre(MDOC_ARGS)
-{
- struct htmlpair tag;
-
- tag.key = ATTR_CLASS;
- tag.val = "emph";
-
- print_otag(h, TAG_SPAN, 1, &tag);
- return(1);
-}
-
-
-/* ARGSUSED */
-static int
-mdoc_d1_pre(MDOC_ARGS)
-{
- struct htmlpair tag[2];
-
- if (MDOC_BLOCK != n->type)
- return(1);
-
- buffmt("margin-left: %dem;", INDENT);
-
- tag[0].key = ATTR_CLASS;
- tag[0].val = "lit-block";
- tag[1].key = ATTR_STYLE;
- tag[1].val = buf;
-
- print_otag(h, TAG_DIV, 2, tag);
- return(1);
-}
-
-
-/* ARGSUSED */
-static int
-mdoc_sx_pre(MDOC_ARGS)
-{
- struct htmlpair tag[2];
- const struct mdoc_node *nn;
-
- bufcat("#");
- for (nn = n->child; nn; nn = nn->next) {
- bufcat(nn->string);
- if (nn->next)
- bufcat(" ");
- }
-
- tag[0].key = ATTR_HREF;
- tag[0].val = buf;
- tag[1].key = ATTR_CLASS;
- tag[1].val = "link-sec";
-
- print_otag(h, TAG_A, 2, tag);
- return(1);
-}
-
-
-/* ARGSUSED */
-static int
-mdoc_aq_pre(MDOC_ARGS)
-{
-
- if (MDOC_BODY != n->type)
- return(1);
- print_text(h, "\\(la");
- h->flags |= HTML_NOSPACE;
- return(1);
-}
-
-
-/* ARGSUSED */
-static void
-mdoc_aq_post(MDOC_ARGS)
-{
-
- if (MDOC_BODY != n->type)
- return;
- h->flags |= HTML_NOSPACE;
- print_text(h, "\\(ra");
-}
-
-
-/* ARGSUSED */
-static int
-mdoc_bd_pre(MDOC_ARGS)
-{
- struct htmlpair tag[2];
- int t, c, o, i;
- const struct mdoc_node *bl;
-
- /* FIXME: fmt_vspace() shit. */
-
- if (MDOC_BLOCK == n->type)
- bl = n;
- else if (MDOC_HEAD == n->type)
- return(0);
- else
- bl = n->parent;
-
- t = o = c = 0;
-
- for (i = 0; i < (int)bl->args->argc; i++)
- switch (bl->args->argv[i].arg) {
- case (MDOC_Offset):
- assert(bl->args->argv[i].sz);
- o = a2offs (bl->args->argv[i].value[0]);
- break;
- case (MDOC_Compact):
- c = 1;
- break;
- case (MDOC_Ragged):
- /* FALLTHROUGH */
- case (MDOC_Filled):
- /* FALLTHROUGH */
- case (MDOC_Unfilled):
- /* FALLTHROUGH */
- case (MDOC_Literal):
- t = bl->args->argv[i].arg;
- break;
- }
-
- if (MDOC_BLOCK == n->type) {
- if (o)
- buffmt("margin-left: %dem;", o);
- bufcat("margin-top: 1em;");
- tag[0].key = ATTR_STYLE;
- tag[0].val = buf;
- print_otag(h, TAG_DIV, 1, tag);
- return(1);
- }
-
- switch (t) {
- case (MDOC_Unfilled):
- case (MDOC_Literal):
- break;
- default:
- return(1);
- }
-
- bufcat("white-space: pre;");
- tag[0].key = ATTR_STYLE;
- tag[0].val = buf;
- tag[1].key = ATTR_CLASS;
- tag[1].val = "lit-block";
-
- print_otag(h, TAG_DIV, 2, tag);
-
- for (n = n->child; n; n = n->next) {
- h->flags |= HTML_NOSPACE;
- print_mdoc_node(m, n, h);
- if (n->next)
- print_text(h, "\n");
- }
-
- return(0);
-}
-
-
-/* ARGSUSED */
-static int
-mdoc_pa_pre(MDOC_ARGS)
-{
- struct htmlpair tag;
-
- tag.key = ATTR_CLASS;
- tag.val = "file";
-
- print_otag(h, TAG_SPAN, 1, &tag);
- return(1);
-}
-
-
-/* ARGSUSED */
-static int
-mdoc_qq_pre(MDOC_ARGS)
-{
-
- if (MDOC_BODY != n->type)
- return(1);
- print_text(h, "\\*q");
- h->flags |= HTML_NOSPACE;
- return(1);
-}
-
-
-/* ARGSUSED */
-static void
-mdoc_qq_post(MDOC_ARGS)
-{
-
- if (MDOC_BODY != n->type)
- return;
- h->flags |= HTML_NOSPACE;
- print_text(h, "\\*q");
-}
-
-
-/* ARGSUSED */
-static int
-mdoc_ad_pre(MDOC_ARGS)
-{
- struct htmlpair tag;
-
- tag.key = ATTR_CLASS;
- tag.val = "addr";
- print_otag(h, TAG_SPAN, 1, &tag);
- return(1);
-}
-
-
-/* ARGSUSED */
-static int
-mdoc_an_pre(MDOC_ARGS)
-{
- struct htmlpair tag;
-
- tag.key = ATTR_CLASS;
- tag.val = "author";
- print_otag(h, TAG_SPAN, 1, &tag);
- return(1);
-}
-
-
-/* ARGSUSED */
-static int
-mdoc_cd_pre(MDOC_ARGS)
-{
- struct htmlpair tag;
-
- tag.key = ATTR_CLASS;
- tag.val = "config";
- print_otag(h, TAG_SPAN, 1, &tag);
- return(1);
-}
-
-
-/* ARGSUSED */
-static int
-mdoc_dv_pre(MDOC_ARGS)
-{
- struct htmlpair tag;
-
- tag.key = ATTR_CLASS;
- tag.val = "define";
- print_otag(h, TAG_SPAN, 1, &tag);
- return(1);
-}
-
-
-/* ARGSUSED */
-static int
-mdoc_ev_pre(MDOC_ARGS)
-{
- struct htmlpair tag;
-
- tag.key = ATTR_CLASS;
- tag.val = "env";
- print_otag(h, TAG_SPAN, 1, &tag);
- return(1);
-}
-
-
-/* ARGSUSED */
-static int
-mdoc_er_pre(MDOC_ARGS)
-{
- struct htmlpair tag;
-
- tag.key = ATTR_CLASS;
- tag.val = "errno";
- print_otag(h, TAG_SPAN, 1, &tag);
- return(1);
-}
-
-
-/* ARGSUSED */
-static int
-mdoc_fa_pre(MDOC_ARGS)
-{
- const struct mdoc_node *nn;
- struct htmlpair tag;
- struct tag *t;
-
- tag.key = ATTR_CLASS;
- tag.val = "farg";
-
- if (n->parent->tok != MDOC_Fo) {
- print_otag(h, TAG_SPAN, 1, &tag);
- return(1);
- }
-
- for (nn = n->child; nn; nn = nn->next) {
- t = print_otag(h, TAG_SPAN, 1, &tag);
- print_text(h, nn->string);
- print_tagq(h, t);
- if (nn->next)
- print_text(h, ",");
- }
-
- if (n->child && n->next && n->next->tok == MDOC_Fa)
- print_text(h, ",");
-
- return(0);
-}
-
-
-/* ARGSUSED */
-static int
-mdoc_fd_pre(MDOC_ARGS)
-{
- struct htmlpair tag;
-
- if (SEC_SYNOPSIS == n->sec) {
- if (n->next && MDOC_Fd != n->next->tok) {
- tag.key = ATTR_STYLE;
- tag.val = "margin-bottom: 1em;";
- print_otag(h, TAG_DIV, 1, &tag);
- } else
- print_otag(h, TAG_DIV, 0, NULL);
- }
-
- tag.key = ATTR_CLASS;
- tag.val = "macro";
- print_otag(h, TAG_SPAN, 1, &tag);
- return(1);
-}
-
-
-/* ARGSUSED */
-static int
-mdoc_vt_pre(MDOC_ARGS)
-{
- struct htmlpair tag;
-
- if (SEC_SYNOPSIS == n->sec) {
- if (n->next && MDOC_Vt != n->next->tok) {
- tag.key = ATTR_STYLE;
- tag.val = "margin-bottom: 1em;";
- print_otag(h, TAG_DIV, 1, &tag);
- } else
- print_otag(h, TAG_DIV, 0, NULL);
- }
-
- tag.key = ATTR_CLASS;
- tag.val = "type";
- print_otag(h, TAG_SPAN, 1, &tag);
- return(1);
-}
-
-/* ARGSUSED */
-static int
-mdoc_ft_pre(MDOC_ARGS)
-{
- struct htmlpair tag;
-
- if (SEC_SYNOPSIS == n->sec) {
- if (n->prev && MDOC_Fo == n->prev->tok) {
- tag.key = ATTR_STYLE;
- tag.val = "magin-bottom: 1em;";
- print_otag(h, TAG_DIV, 1, &tag);
- } else
- print_otag(h, TAG_DIV, 0, NULL);
- }
-
- tag.key = ATTR_CLASS;
- tag.val = "type";
- print_otag(h, TAG_SPAN, 1, &tag);
- return(1);
-}
-
-
-/* ARGSUSED */
-static int
-mdoc_fn_pre(MDOC_ARGS)
-{
- struct tag *t;
- struct htmlpair tag;
- const struct mdoc_node *nn;
-
- if (SEC_SYNOPSIS == n->sec) {
- if (n->next) {
- tag.key = ATTR_STYLE;
- tag.val = "margin-bottom: 1em";
- print_otag(h, TAG_DIV, 1, &tag);
- } else
- print_otag(h, TAG_DIV, 0, NULL);
- }
-
- tag.key = ATTR_CLASS;
- tag.val = "type";
-
- t = print_otag(h, TAG_SPAN, 1, &tag);
- print_text(h, n->child->string);
- print_tagq(h, t);
-
- h->flags |= HTML_NOSPACE;
- print_text(h, "(");
-
- for (nn = n->child->next; nn; nn = nn->next) {
- tag.key = ATTR_CLASS;
- tag.val = "farg";
- t = print_otag(h, TAG_SPAN, 1, &tag);
- print_text(h, nn->string);
- print_tagq(h, t);
- if (nn->next)
- print_text(h, ",");
- }
-
- print_text(h, ")");