]> git.cameronkatri.com Git - mandoc.git/blobdiff - mdoc_html.c
Various improvements related to .Ex and .Rv:
[mandoc.git] / mdoc_html.c
index 2dc15c53c04dc6c258eb64a473458ca5a7d92c94..fcde3658312191e889eb5ace0236873e0053ed4b 100644 (file)
@@ -1,4 +1,4 @@
-/*     $Id: mdoc_html.c,v 1.190 2014/04/23 16:08:33 schwarze Exp $ */
+/*     $Id: mdoc_html.c,v 1.193 2014/07/30 00:19:16 schwarze Exp $ */
 /*
  * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
  * Copyright (c) 2014 Ingo Schwarze <schwarze@openbsd.org>
@@ -97,7 +97,6 @@ static        int               mdoc_it_pre(MDOC_ARGS);
 static int               mdoc_lb_pre(MDOC_ARGS);
 static int               mdoc_li_pre(MDOC_ARGS);
 static int               mdoc_lk_pre(MDOC_ARGS);
-static int               mdoc_ll_pre(MDOC_ARGS);
 static int               mdoc_mt_pre(MDOC_ARGS);
 static int               mdoc_ms_pre(MDOC_ARGS);
 static int               mdoc_nd_pre(MDOC_ARGS);
@@ -111,6 +110,7 @@ static      int               mdoc_quote_pre(MDOC_ARGS);
 static int               mdoc_rs_pre(MDOC_ARGS);
 static int               mdoc_rv_pre(MDOC_ARGS);
 static int               mdoc_sh_pre(MDOC_ARGS);
+static int               mdoc_skip_pre(MDOC_ARGS);
 static int               mdoc_sm_pre(MDOC_ARGS);
 static int               mdoc_sp_pre(MDOC_ARGS);
 static int               mdoc_ss_pre(MDOC_ARGS);
@@ -157,7 +157,7 @@ static      const struct htmlmdoc mdocs[MDOC_MAX] = {
        {mdoc_nd_pre, NULL}, /* Nd */
        {mdoc_nm_pre, NULL}, /* Nm */
        {mdoc_quote_pre, mdoc_quote_post}, /* Op */
-       {NULL, NULL}, /* Ot */
+       {mdoc_ft_pre, NULL}, /* Ot */
        {mdoc_pa_pre, NULL}, /* Pa */
        {mdoc_rv_pre, NULL}, /* Rv */
        {NULL, NULL}, /* St */
@@ -227,7 +227,7 @@ static      const struct htmlmdoc mdocs[MDOC_MAX] = {
        {NULL, NULL}, /* Ek */
        {mdoc_bt_pre, NULL}, /* Bt */
        {NULL, NULL}, /* Hf */
-       {NULL, NULL}, /* Fr */
+       {mdoc_em_pre, NULL}, /* Fr */
        {mdoc_ud_pre, NULL}, /* Ud */
        {mdoc_lb_pre, NULL}, /* Lb */
        {mdoc_pp_pre, NULL}, /* Lp */
@@ -237,15 +237,15 @@ static    const struct htmlmdoc mdocs[MDOC_MAX] = {
        {mdoc_quote_pre, mdoc_quote_post}, /* Bro */
        {NULL, NULL}, /* Brc */
        {mdoc__x_pre, mdoc__x_post}, /* %C */
-       {NULL, NULL}, /* Es */  /* TODO */
-       {NULL, NULL}, /* En */  /* TODO */
+       {mdoc_skip_pre, NULL}, /* Es */
+       {mdoc_quote_pre, mdoc_quote_post}, /* En */
        {mdoc_xx_pre, NULL}, /* Dx */
        {mdoc__x_pre, mdoc__x_post}, /* %Q */
        {mdoc_sp_pre, NULL}, /* br */
        {mdoc_sp_pre, NULL}, /* sp */
        {mdoc__x_pre, mdoc__x_post}, /* %U */
        {NULL, NULL}, /* Ta */
-       {mdoc_ll_pre, NULL}, /* ll */
+       {mdoc_skip_pre, NULL}, /* ll */
 };
 
 static const char * const lists[LIST_MAX] = {
@@ -1069,11 +1069,11 @@ mdoc_ex_pre(MDOC_ARGS)
        }
 
        if (nchild > 1)
-               print_text(h, "utilities exit");
+               print_text(h, "utilities exit\\~0");
        else
-               print_text(h, "utility exits");
+               print_text(h, "utility exits\\~0");
 
-       print_text(h, "0 on success, and >0 if an error occurs.");
+       print_text(h, "on success, and\\~>0 if an error occurs.");
        return(0);
 }
 
@@ -1524,28 +1524,21 @@ static int
 mdoc_sm_pre(MDOC_ARGS)
 {
 
-       assert(n->child && MDOC_TEXT == n->child->type);
-       if (0 == strcmp("on", n->child->string)) {
-               /*
-                * FIXME: no p->col to check.  Thus, if we have
-                *  .Bd -literal
-                *  .Sm off
-                *  1 2
-                *  .Sm on
-                *  3
-                *  .Ed
-                * the "3" is preceded by a space.
-                */
-               h->flags &= ~HTML_NOSPACE;
+       if (NULL == n->child)
+               h->flags ^= HTML_NONOSPACE;
+       else if (0 == strcmp("on", n->child->string))
                h->flags &= ~HTML_NONOSPACE;
-       else
+       else
                h->flags |= HTML_NONOSPACE;
 
+       if ( ! (HTML_NONOSPACE & h->flags))
+               h->flags &= ~HTML_NOSPACE;
+
        return(0);
 }
 
 static int
-mdoc_ll_pre(MDOC_ARGS)
+mdoc_skip_pre(MDOC_ARGS)
 {
 
        return(0);
@@ -1751,35 +1744,41 @@ mdoc_rv_pre(MDOC_ARGS)
 
        PAIR_CLASS_INIT(&tag, "fname");
 
-       print_text(h, "The");
-
        nchild = n->nchild;
-       for (n = n->child; n; n = n->next) {
-               assert(MDOC_TEXT == n->type);
+       if (nchild > 0) {
+               print_text(h, "The");
 
-               t = print_otag(h, TAG_B, 1, &tag);
-               print_text(h, n->string);
-               print_tagq(h, t);
-
-               h->flags |= HTML_NOSPACE;
-               print_text(h, "()");
+               for (n = n->child; n; n = n->next) {
+                       t = print_otag(h, TAG_B, 1, &tag);
+                       print_text(h, n->string);
+                       print_tagq(h, t);
 
-               if (nchild > 2 && n->next) {
                        h->flags |= HTML_NOSPACE;
-                       print_text(h, ",");
+                       print_text(h, "()");
+
+                       if (n->next == NULL)
+                               continue;
+
+                       if (nchild > 2) {
+                               h->flags |= HTML_NOSPACE;
+                               print_text(h, ",");
+                       }
+                       if (n->next->next == NULL)
+                               print_text(h, "and");
                }
 
-               if (n->next && NULL == n->next->next)
-                       print_text(h, "and");
-       }
+               if (nchild > 1)
+                       print_text(h, "functions return");
+               else
+                       print_text(h, "function returns");
 
-       if (nchild > 1)
-               print_text(h, "functions return");
-       else
-               print_text(h, "function returns");
+               print_text(h, "the value\\~0 if successful;");
+       } else
+               print_text(h, "Upon successful completion,"
+                    " the value\\~0 is returned;");
 
-       print_text(h, "the value 0 if successful; otherwise the "
-           "value -1 is returned and the global variable");
+       print_text(h, "otherwise the value\\~\\-1 is returned"
+          " and the global variable");
 
        PAIR_CLASS_INIT(&tag, "var");
        t = print_otag(h, TAG_B, 1, &tag);
@@ -2085,6 +2084,12 @@ mdoc_quote_pre(MDOC_ARGS)
                PAIR_CLASS_INIT(&tag, "opt");
                print_otag(h, TAG_SPAN, 1, &tag);
                break;
+       case MDOC_En:
+               if (NULL == n->norm->Es ||
+                   NULL == n->norm->Es->child)
+                       return(1);
+               print_text(h, n->norm->Es->child->string);
+               break;
        case MDOC_Eo:
                break;
        case MDOC_Do:
@@ -2128,7 +2133,8 @@ mdoc_quote_post(MDOC_ARGS)
        if (MDOC_BODY != n->type)
                return;
 
-       h->flags |= HTML_NOSPACE;
+       if (MDOC_En != n->tok)
+               h->flags |= HTML_NOSPACE;
 
        switch (n->tok) {
        case MDOC_Ao:
@@ -2150,6 +2156,14 @@ mdoc_quote_post(MDOC_ARGS)
        case MDOC_Bq:
                print_text(h, "\\(rB");
                break;
+       case MDOC_En:
+               if (NULL != n->norm->Es &&
+                   NULL != n->norm->Es->child &&
+                   NULL != n->norm->Es->child->next) {
+                       h->flags |= HTML_NOSPACE;
+                       print_text(h, n->norm->Es->child->next->string);
+               }
+               break;
        case MDOC_Eo:
                break;
        case MDOC_Qo: