]> git.cameronkatri.com Git - mandoc.git/blobdiff - mdoc_man.c
The st_size member of struct stat is off_t, which is signed,
[mandoc.git] / mdoc_man.c
index f329cd98e0895c9c87b8da6c42f0de566a79a87f..9c086a576c4ed261252d7ecacdb3583582e969c0 100644 (file)
@@ -1,4 +1,4 @@
-/*     $Id: mdoc_man.c,v 1.83 2015/01/28 17:32:07 schwarze Exp $ */
+/*     $Id: mdoc_man.c,v 1.88 2015/02/17 20:37:17 schwarze Exp $ */
 /*
  * Copyright (c) 2011-2015 Ingo Schwarze <schwarze@openbsd.org>
  *
@@ -29,8 +29,7 @@
 #include "mdoc.h"
 #include "main.h"
 
-#define        DECL_ARGS const struct mdoc_meta *meta, \
-                 const struct mdoc_node *n
+#define        DECL_ARGS const struct mdoc_meta *meta, struct mdoc_node *n
 
 struct manact {
        int             (*cond)(DECL_ARGS); /* DON'T run actions */
@@ -186,8 +185,8 @@ static      const struct manact manacts[MDOC_MAX + 1] = {
        { NULL, pre_bx, NULL, NULL, NULL }, /* Bx */
        { NULL, pre_skip, NULL, NULL, NULL }, /* Db */
        { NULL, NULL, NULL, NULL, NULL }, /* Dc */
-       { cond_body, pre_enc, post_enc, "\\(lq", "\\(rq" }, /* Do */
-       { cond_body, pre_enc, post_enc, "\\(lq", "\\(rq" }, /* Dq */
+       { cond_body, pre_enc, post_enc, "\\(Lq", "\\(Rq" }, /* Do */
+       { cond_body, pre_enc, post_enc, "\\(Lq", "\\(Rq" }, /* Dq */
        { NULL, NULL, NULL, NULL, NULL }, /* Ec */
        { NULL, NULL, NULL, NULL, NULL }, /* Ef */
        { NULL, pre_em, post_font, NULL, NULL }, /* Em */
@@ -548,10 +547,10 @@ void
 man_mdoc(void *arg, const struct mdoc *mdoc)
 {
        const struct mdoc_meta *meta;
-       const struct mdoc_node *n;
+       struct mdoc_node *n;
 
        meta = mdoc_meta(mdoc);
-       n = mdoc_node(mdoc);
+       n = mdoc_node(mdoc)->child;
 
        printf(".TH \"%s\" \"%s\" \"%s\" \"%s\" \"%s\"\n",
            meta->title,
@@ -567,15 +566,18 @@ man_mdoc(void *arg, const struct mdoc *mdoc)
                fontqueue.head = fontqueue.tail = mandoc_malloc(8);
                *fontqueue.tail = 'R';
        }
-       print_node(meta, n);
+       while (n != NULL) {
+               print_node(meta, n);
+               n = n->next;
+       }
        putchar('\n');
 }
 
 static void
 print_node(DECL_ARGS)
 {
-       const struct mdoc_node  *sub;
        const struct manact     *act;
+       struct mdoc_node        *sub;
        int                      cond, do_sub;
 
        /*
@@ -588,6 +590,7 @@ print_node(DECL_ARGS)
        act = NULL;
        cond = 0;
        do_sub = 1;
+       n->flags &= ~MDOC_ENDED;
 
        if (MDOC_TEXT == n->type) {
                /*
@@ -635,7 +638,7 @@ print_node(DECL_ARGS)
                (*act->post)(meta, n);
 
        if (ENDBODY_NOT != n->end)
-               n->pending->flags |= MDOC_ENDED;
+               n->body->flags |= MDOC_ENDED;
 
        if (ENDBODY_NOSPACE == n->end)
                outflags &= ~(MMAN_spc | MMAN_nl);
@@ -1134,16 +1137,37 @@ static int
 pre_eo(DECL_ARGS)
 {
 
-       outflags &= ~(MMAN_spc | MMAN_nl);
+       if (n->end == ENDBODY_NOT &&
+           n->parent->head->child == NULL &&
+           n->child != NULL &&
+           n->child->end != ENDBODY_NOT)
+               print_word("\\&");
+       else if (n->end != ENDBODY_NOT ? n->child != NULL :
+           n->parent->head->child != NULL && (n->child != NULL ||
+           (n->parent->tail != NULL && n->parent->tail->child != NULL)))
+               outflags &= ~(MMAN_spc | MMAN_nl);
        return(1);
 }
 
 static void
 post_eo(DECL_ARGS)
 {
+       int      body, tail;
 
-       if (n->end != ENDBODY_SPACE)
+       if (n->end != ENDBODY_NOT) {
+               outflags |= MMAN_spc;
+               return;
+       }
+
+       body = n->child != NULL || n->parent->head->child != NULL;
+       tail = n->parent->tail != NULL && n->parent->tail->child != NULL;
+
+       if (body && tail)
                outflags &= ~MMAN_spc;
+       else if ( ! (body || tail))
+               print_word("\\&");
+       else if ( ! tail)
+               outflags |= MMAN_spc;
 }
 
 static int
@@ -1262,12 +1286,14 @@ pre_fo(DECL_ARGS)
                pre_syn(n);
                break;
        case MDOC_HEAD:
+               if (n->child == NULL)
+                       return(0);
                if (MDOC_SYNPRETTY & n->flags)
                        print_block(".HP 4n", MMAN_nl);
                font_push('B');
                break;
        case MDOC_BODY:
-               outflags &= ~MMAN_spc;
+               outflags &= ~(MMAN_spc | MMAN_nl);
                print_word("(");
                outflags &= ~MMAN_spc;
                break;
@@ -1283,7 +1309,8 @@ post_fo(DECL_ARGS)
 
        switch (n->type) {
        case MDOC_HEAD:
-               font_pop();
+               if (n->child != NULL)
+                       font_pop();
                break;
        case MDOC_BODY:
                post_fn(meta, n);