]> git.cameronkatri.com Git - mandoc.git/blobdiff - mdoc_term.c
Switch to autogenerated dependency rules; they are less error-prone.
[mandoc.git] / mdoc_term.c
index 4629e43a7ed876e91d30796f46856315e638ff96..42deb3ac4966d4d30c8f3ad2499f95ce88440800 100644 (file)
@@ -1,4 +1,4 @@
-/*     $Id: mdoc_term.c,v 1.271 2014/07/07 15:03:43 schwarze Exp $ */
+/*     $Id: mdoc_term.c,v 1.274 2014/07/30 17:06:26 schwarze Exp $ */
 /*
  * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv>
  * Copyright (c) 2010, 2012, 2013, 2014 Ingo Schwarze <schwarze@openbsd.org>
@@ -1167,33 +1167,42 @@ termp_rv_pre(DECL_ARGS)
        int              nchild;
 
        term_newln(p);
-       term_word(p, "The");
 
        nchild = n->nchild;
-       for (n = n->child; n; n = n->next) {
-               term_fontpush(p, TERMFONT_BOLD);
-               term_word(p, n->string);
-               term_fontpop(p);
+       if (nchild > 0) {
+               term_word(p, "The");
 
-               p->flags |= TERMP_NOSPACE;
-               term_word(p, "()");
+               for (n = n->child; n; n = n->next) {
+                       term_fontpush(p, TERMFONT_BOLD);
+                       term_word(p, n->string);
+                       term_fontpop(p);
 
-               if (nchild > 2 && n->next) {
                        p->flags |= TERMP_NOSPACE;
-                       term_word(p, ",");
+                       term_word(p, "()");
+
+                       if (n->next == NULL)
+                               continue;
+
+                       if (nchild > 2) {
+                               p->flags |= TERMP_NOSPACE;
+                               term_word(p, ",");
+                       }
+                       if (n->next->next == NULL)
+                               term_word(p, "and");
                }
 
-               if (n->next && NULL == n->next->next)
-                       term_word(p, "and");
-       }
+               if (nchild > 1)
+                       term_word(p, "functions return");
+               else
+                       term_word(p, "function returns");
 
-       if (nchild > 1)
-               term_word(p, "functions return");
-       else
-               term_word(p, "function returns");
+               term_word(p, "the value\\~0 if successful;");
+       } else
+               term_word(p, "Upon successful completion,"
+                   " the value\\~0 is returned;");
 
-       term_word(p, "the value 0 if successful; otherwise the "
-           "value -1 is returned and the global variable");
+       term_word(p, "otherwise the value\\~\\-1 is returned"
+           " and the global variable");
 
        term_fontpush(p, TERMFONT_UNDER);
        term_word(p, "errno");
@@ -1229,11 +1238,11 @@ termp_ex_pre(DECL_ARGS)
        }
 
        if (nchild > 1)
-               term_word(p, "utilities exit");
+               term_word(p, "utilities exit\\~0");
        else
-               term_word(p, "utility exits");
+               term_word(p, "utility exits\\~0");
 
-       term_word(p, "0 on success, and >0 if an error occurs.");
+       term_word(p, "on success, and\\~>0 if an error occurs.");
 
        p->flags |= TERMP_SENTENCE;
        return(0);
@@ -1571,7 +1580,7 @@ termp_fa_pre(DECL_ARGS)
 static int
 termp_bd_pre(DECL_ARGS)
 {
-       size_t                   tabwidth, rm, rmax;
+       size_t                   tabwidth, lm, len, rm, rmax;
        struct mdoc_node        *nn;
 
        if (MDOC_BLOCK == n->type) {
@@ -1592,18 +1601,29 @@ termp_bd_pre(DECL_ARGS)
         */
 
        if (DISP_literal != n->norm->Bd.type &&
-           DISP_unfilled != n->norm->Bd.type)
+           DISP_unfilled != n->norm->Bd.type &&
+           DISP_centered != n->norm->Bd.type)
                return(1);
 
        tabwidth = p->tabwidth;
        if (DISP_literal == n->norm->Bd.type)
                p->tabwidth = term_len(p, 8);
 
+       lm = p->offset;
        rm = p->rmargin;
        rmax = p->maxrmargin;
        p->rmargin = p->maxrmargin = TERM_MAXMARGIN;
 
        for (nn = n->child; nn; nn = nn->next) {
+               if (DISP_centered == n->norm->Bd.type) {
+                       if (MDOC_TEXT == nn->type) {
+                               len = term_strlen(p, nn->string);
+                               p->offset = len >= rm ? 0 :
+                                   lm + len >= rm ? rm - len :
+                                   (lm + rm - len) / 2;
+                       } else
+                               p->offset = lm;
+               }
                print_mdoc_node(p, pair, meta, nn);
                /*
                 * If the printed node flushes its own line, then we
@@ -1750,6 +1770,9 @@ termp_ss_pre(DECL_ARGS)
                term_fontpush(p, TERMFONT_BOLD);
                p->offset = term_len(p, (p->defindent+1)/2);
                break;
+       case MDOC_BODY:
+               p->offset = term_len(p, p->defindent);
+               break;
        default:
                break;
        }
@@ -1761,7 +1784,7 @@ static void
 termp_ss_post(DECL_ARGS)
 {
 
-       if (MDOC_HEAD == n->type)
+       if (n->type == MDOC_HEAD || n->type == MDOC_BODY)
                term_newln(p);
 }